From patchwork Tue Jun 2 20:54:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 218031 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 202D3C433E1 for ; Tue, 2 Jun 2020 20:55:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EDE0220678 for ; Tue, 2 Jun 2020 20:55:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="CYlPDe5z" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728256AbgFBUz0 (ORCPT ); Tue, 2 Jun 2020 16:55:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727795AbgFBUzZ (ORCPT ); Tue, 2 Jun 2020 16:55:25 -0400 Received: from mail-lf1-x144.google.com (mail-lf1-x144.google.com [IPv6:2a00:1450:4864:20::144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32F8DC08C5C0 for ; Tue, 2 Jun 2020 13:55:25 -0700 (PDT) Received: by mail-lf1-x144.google.com with SMTP id w15so7007018lfe.11 for ; Tue, 02 Jun 2020 13:55:25 -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=mSZdHFH4Bx0kIRim8XPkE3hmIfXGRjFDDYswlMmM/WE=; b=CYlPDe5zKmPnSuADU51Lo9aFvDegDXUS635rDXYbsA3DCd+cbpDubEUrcfwL22O1w2 xC2ng04rB7MZ6O34hCBDQGN4OtNxqKI1jsRtMyQPOZJFhsHt4nBLfs4tAaRy1DUgW40P //3z/GX5op6ky0gMf4OA24WAINxli6zOQMmw4c/fWFBZ6Gsv1x172AMqTwdnWoIk1peM 9Lm158ZFMkFy1TAyXsft3N9sryllo4GzPBHJzHxSm8hB6jlxlVebdb6lfDZw3Srjez3m zq3lIEYRlgGS8994k59X8QhBouaEn/rbFNeYxqLR+Cudv+Fl0xtnsLULz6Fh0i6pjvPh gvhA== 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=mSZdHFH4Bx0kIRim8XPkE3hmIfXGRjFDDYswlMmM/WE=; b=SexbMWH07x5FdvH0AyImd4TbpQ9C2utCgqrtaDS0rE48o+RERzr3TX9sn1D4g1Oq/W N+hmUkyPSpWms6vqE1by2TZ6FIrRn1dl9xRQHDgiqCU/czYYHkQP+KRKu/wN7rvqYl3P 6XxyhfvroZg2BodHarWdDRFjkxUjMHg1JMyAP4Ef+nli/zGDs7mxIS2+UrWyCrFwNv7s 2KntPaE1mSBed5fc+eHB/cCKejxjQ0mLiKPpBqB95H1s2AKnotNOuGS2P8ZMapev4LBY /gkJpcJ4gszZ/cXb16j2OJXol1ndhoxVtbtAccRMyM4mGNiIFdYDPDGFJp0n2FI52oEz KGvQ== X-Gm-Message-State: AOAM531jWkCuD4mkKtPEBdqCUtASiEIfwNKEH+Ht58qd/3kNGBj4WyPr UrJXYxQcrJTOVUaoLUt6JpD21Q== X-Google-Smtp-Source: ABdhPJzgg4vDjuyM1nULWi0wN5qNgf8AWay5c19LIbOMWBOLIltlvAqQ40lH7hz6pMIcCf0ZTCqeLg== X-Received: by 2002:ac2:4a75:: with SMTP id q21mr607210lfp.190.1591131323574; Tue, 02 Jun 2020 13:55:23 -0700 (PDT) Received: from localhost.bredbandsbolaget (c-8cdb225c.014-348-6c756e10.bbcust.telenor.se. [92.34.219.140]) by smtp.gmail.com with ESMTPSA id t5sm41962lff.39.2020.06.02.13.55.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 13:55:22 -0700 (PDT) From: Linus Walleij To: Andrew Lunn , Vivien Didelot , Florian Fainelli Cc: netdev@vger.kernel.org, Linus Walleij , DENG Qingfang Subject: [net-next PATCH 2/5] net: dsa: rtl8366rb: Support the CPU DSA tag Date: Tue, 2 Jun 2020 22:54:53 +0200 Message-Id: <20200602205456.2392024-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200602205456.2392024-1-linus.walleij@linaro.org> References: <20200602205456.2392024-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 This activates the support to use the CPU tag to properly direct ingress traffic to the right port. After this e.g. ping works out-of-the-box with the RTL8366RB. Cc: DENG Qingfang Signed-off-by: Linus Walleij --- drivers/net/dsa/Kconfig | 1 + drivers/net/dsa/rtl8366rb.c | 31 ++++++++----------------------- 2 files changed, 9 insertions(+), 23 deletions(-) diff --git a/drivers/net/dsa/Kconfig b/drivers/net/dsa/Kconfig index 2d38dbc9dd8c..3a4485651f1d 100644 --- a/drivers/net/dsa/Kconfig +++ b/drivers/net/dsa/Kconfig @@ -70,6 +70,7 @@ config NET_DSA_QCA8K config NET_DSA_REALTEK_SMI tristate "Realtek SMI Ethernet switch family support" depends on NET_DSA + select NET_DSA_TAG_RTL4_A select FIXED_PHY select IRQ_DOMAIN select REALTEK_PHY diff --git a/drivers/net/dsa/rtl8366rb.c b/drivers/net/dsa/rtl8366rb.c index fd1977590cb4..48f1ff746799 100644 --- a/drivers/net/dsa/rtl8366rb.c +++ b/drivers/net/dsa/rtl8366rb.c @@ -109,8 +109,8 @@ /* CPU port control reg */ #define RTL8368RB_CPU_CTRL_REG 0x0061 #define RTL8368RB_CPU_PORTS_MSK 0x00FF -/* Enables inserting custom tag length/type 0x8899 */ -#define RTL8368RB_CPU_INSTAG BIT(15) +/* Disables inserting custom tag length/type 0x8899 */ +#define RTL8368RB_CPU_NO_TAG BIT(15) #define RTL8366RB_SMAR0 0x0070 /* bits 0..15 */ #define RTL8366RB_SMAR1 0x0071 /* bits 16..31 */ @@ -844,16 +844,14 @@ static int rtl8366rb_setup(struct dsa_switch *ds) if (ret) return ret; - /* Enable CPU port and enable inserting CPU tag + /* Enable CPU port with custom DSA tag 8899. * - * Disabling RTL8368RB_CPU_INSTAG here will change the behaviour - * of the switch totally and it will start talking Realtek RRCP - * internally. It is probably possible to experiment with this, - * but then the kernel needs to understand and handle RRCP first. + * If you set RTL8368RB_CPU_NO_TAG (bit 15) in this registers + * the custom tag is turned off. */ ret = regmap_update_bits(smi->map, RTL8368RB_CPU_CTRL_REG, 0xFFFF, - RTL8368RB_CPU_INSTAG | BIT(smi->cpu_port)); + BIT(smi->cpu_port)); if (ret) return ret; @@ -967,21 +965,8 @@ static enum dsa_tag_protocol rtl8366_get_tag_protocol(struct dsa_switch *ds, int port, enum dsa_tag_protocol mp) { - /* For now, the RTL switches are handled without any custom tags. - * - * It is possible to turn on "custom tags" by removing the - * RTL8368RB_CPU_INSTAG flag when enabling the port but what it - * does is unfamiliar to DSA: ethernet frames of type 8899, the Realtek - * Remote Control Protocol (RRCP) start to appear on the CPU port of - * the device. So this is not the ordinary few extra bytes in the - * frame. Instead it appears that the switch starts to talk Realtek - * RRCP internally which means a pretty complex RRCP implementation - * decoding and responding the RRCP protocol is needed to exploit this. - * - * The OpenRRCP project (dormant since 2009) have reverse-egineered - * parts of the protocol. - */ - return DSA_TAG_PROTO_NONE; + /* This switch uses the 4 byte protocol A Realtek DSA tag */ + return DSA_TAG_PROTO_RTL4_A; } static void rtl8366rb_adjust_link(struct dsa_switch *ds, int port, From patchwork Tue Jun 2 20:54:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 218030 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5DF87C433E1 for ; Tue, 2 Jun 2020 20:55:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 36AA820678 for ; Tue, 2 Jun 2020 20:55:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="ic1iGGw3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728371AbgFBUzc (ORCPT ); Tue, 2 Jun 2020 16:55:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728344AbgFBUza (ORCPT ); Tue, 2 Jun 2020 16:55:30 -0400 Received: from mail-lf1-x141.google.com (mail-lf1-x141.google.com [IPv6:2a00:1450:4864:20::141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92140C08C5C1 for ; Tue, 2 Jun 2020 13:55:29 -0700 (PDT) Received: by mail-lf1-x141.google.com with SMTP id x27so7026681lfg.9 for ; Tue, 02 Jun 2020 13:55:29 -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=DAGbGvKTFRgsrcbWvEMabetSYmagh9X/tluny71DaEI=; b=ic1iGGw3YK+VZfTt6Cvec421xVeXIIukkEJqi6yfGCu19J6bYL1UHgU5xcoULsdj1q e+ta8yutZwixinlgzNjn+MfT4w7B6omeSUpLDUykcZ2p9FhBaa0Ej61XeSV9Nxpf2ipL wnP03n8OTVVqmhzTenEE8Lxg0r01ieFEZNFvffw0kOAlAzJwooaNlFSc7XSDBwiQRw0X UZeJS63ckco6/0VuJ3lng9tUivoUFKTzv0k57Q0zbFPk6tWipBOd3dib+s5awXzRot/e zom+KFHhTb0C2Ul+UzfXH0Ws21AmHAusKkyVJ5X2r6EKh2Kh99rlF0JM94KcIiTcKNEk dfOQ== 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=DAGbGvKTFRgsrcbWvEMabetSYmagh9X/tluny71DaEI=; b=s48vVm4YEieAYlzEYerNJyNxglWOWB68drG0TqPYeFPI5jQzUfR/8O0Kvt1MdfG02y LSawQaDmWB+2IWSyOT6vPmkDZuCPTY8QUK826APr7Bdqk2K8ZC/owyXxlHj9zaICN0GV sodxxf/xZZ+ORpb5Ngz7om/A0BT/h89pT/gqLG/7rVX42e9Q+3AcMuqM78TnhgDsCDTO r/jI5xq4Mwcd0AfMzrOKaQtDkv8YW7VXelKU0xXXL856FZN5WH4Nh2rSl+H32BcjAJtA qJ6dsFGa5W7PGTeGNtlrd7um7SIMu5WS2wA/9iMksfBQbkxPoVSmX45YFHvY8zCO22MO h4jg== X-Gm-Message-State: AOAM531UtRPGm5H6oWJRbQT5tJV1z6wYpyvZ8nxtTTCWdRomyzKrN+EV iGY0YFuk2klmo71w0l989hikfQ== X-Google-Smtp-Source: ABdhPJyLY5SxKgpXxKFBFP37u12X4ZqV98OZnkLlWvWljVY4M/Q/9fzU2aEZRYZS+IqLqiPumPJ9fg== X-Received: by 2002:ac2:5466:: with SMTP id e6mr592690lfn.175.1591131328012; Tue, 02 Jun 2020 13:55:28 -0700 (PDT) Received: from localhost.bredbandsbolaget (c-8cdb225c.014-348-6c756e10.bbcust.telenor.se. [92.34.219.140]) by smtp.gmail.com with ESMTPSA id t5sm41962lff.39.2020.06.02.13.55.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 13:55:27 -0700 (PDT) From: Linus Walleij To: Andrew Lunn , Vivien Didelot , Florian Fainelli Cc: netdev@vger.kernel.org, Linus Walleij , DENG Qingfang Subject: [net-next PATCH 4/5] net: dsa: rtl8366: VLAN 0 as disable tagging Date: Tue, 2 Jun 2020 22:54:55 +0200 Message-Id: <20200602205456.2392024-4-linus.walleij@linaro.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200602205456.2392024-1-linus.walleij@linaro.org> References: <20200602205456.2392024-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 The code in net/8021q/vlan.c, vlan_device_event() sets VLAN 0 for a VLAN-capable ethernet device when it comes up. Since the RTL8366 DSA switches must have a VLAN and PVID set up for any packets to come through we have already set up default VLAN for each port as part of bringing the switch online. Make sure that setting VLAN 0 has the same effect and does not try to actually tell the hardware to use VLAN 0 on the port because that will not work. Cc: DENG Qingfang Signed-off-by: Linus Walleij --- drivers/net/dsa/rtl8366.c | 65 +++++++++++++++++++++++++++++++-------- 1 file changed, 52 insertions(+), 13 deletions(-) diff --git a/drivers/net/dsa/rtl8366.c b/drivers/net/dsa/rtl8366.c index 66bd1241204c..7f0691a6da13 100644 --- a/drivers/net/dsa/rtl8366.c +++ b/drivers/net/dsa/rtl8366.c @@ -355,15 +355,25 @@ int rtl8366_vlan_prepare(struct dsa_switch *ds, int port, const struct switchdev_obj_port_vlan *vlan) { struct realtek_smi *smi = ds->priv; + u16 vid_begin = vlan->vid_begin; + u16 vid_end = vlan->vid_end; u16 vid; int ret; - for (vid = vlan->vid_begin; vid < vlan->vid_end; vid++) + if (vid_begin == 0) { + dev_info(smi->dev, "prepare VLAN 0 - ignored\n"); + if (vid_end == 0) + return 0; + /* Skip VLAN 0 and start with VLAN 1 */ + vid_begin = 1; + } + + for (vid = vid_begin; vid < vid_end; vid++) if (!smi->ops->is_vlan_valid(smi, vid)) return -EINVAL; dev_info(smi->dev, "prepare VLANs %04x..%04x\n", - vlan->vid_begin, vlan->vid_end); + vid_begin, vid_end); /* Enable VLAN in the hardware * FIXME: what's with this 4k business? @@ -383,27 +393,46 @@ void rtl8366_vlan_add(struct dsa_switch *ds, int port, bool untagged = !!(vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED); bool pvid = !!(vlan->flags & BRIDGE_VLAN_INFO_PVID); struct realtek_smi *smi = ds->priv; + u16 vid_begin = vlan->vid_begin; + u16 vid_end = vlan->vid_end; u32 member = 0; u32 untag = 0; u16 vid; int ret; - for (vid = vlan->vid_begin; vid < vlan->vid_end; vid++) - if (!smi->ops->is_vlan_valid(smi, vid)) + if (vid_begin == 0) { + dev_info(smi->dev, "set VLAN 0 on port %d = default VLAN\n", + port); + /* Set up default tagging */ + ret = rtl8366_set_default_vlan_and_pvid(smi, port); + if (ret) { + dev_err(smi->dev, + "error setting default VLAN on port %d\n", + port); return; + } + if (vid_end == 0) + return; + /* Skip VLAN 0 and start with VLAN 1 */ + vid_begin = 1; + } - dev_info(smi->dev, "add VLAN on port %d, %s, %s\n", - port, - untagged ? "untagged" : "tagged", - pvid ? " PVID" : "no PVID"); + for (vid = vid_begin; vid < vid_end; vid++) + if (!smi->ops->is_vlan_valid(smi, vid)) + return; if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port)) dev_err(smi->dev, "port is DSA or CPU port\n"); - for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) { + for (vid = vid_begin; vid <= vid_end; ++vid) { int pvid_val = 0; - dev_info(smi->dev, "add VLAN %04x\n", vid); + dev_info(smi->dev, "add VLAN %04x to port %d, %s, %s\n", + vid, + port, + untagged ? "untagged" : "tagged", + pvid ? " PVID" : "no PVID"); + member |= BIT(port); if (untagged) @@ -437,15 +466,25 @@ int rtl8366_vlan_del(struct dsa_switch *ds, int port, const struct switchdev_obj_port_vlan *vlan) { struct realtek_smi *smi = ds->priv; + u16 vid_begin = vlan->vid_begin; + u16 vid_end = vlan->vid_end; u16 vid; int ret; - dev_info(smi->dev, "del VLAN on port %d\n", port); + if (vid_begin == 0) { + dev_info(smi->dev, "remove port %d from VLAN 0 (no-op)\n", + port); + if (vid_end == 0) + return 0; + /* Skip VLAN 0 and start with VLAN 1 */ + vid_begin = 1; + } - for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) { + for (vid = vid_begin; vid <= vid_end; ++vid) { int i; - dev_info(smi->dev, "del VLAN %04x\n", vid); + dev_info(smi->dev, "remove VLAN %04x from port %d\n", + vid, port); for (i = 0; i < smi->num_vlan_mc; i++) { struct rtl8366_vlan_mc vlanmc;