From patchwork Sun Jul 5 23:15:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 234833 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp4289976ilg; Sun, 5 Jul 2020 16:16:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw/GB6Tf90pKWUJQNkKVn8TtdM3u7GTSLHL89s6aJhVJEW1bKGgBUg4pci8cJu03DFMKBbA X-Received: by 2002:a50:d55b:: with SMTP id f27mr15087508edj.312.1593990963160; Sun, 05 Jul 2020 16:16:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593990963; cv=none; d=google.com; s=arc-20160816; b=feoEH3i2hZeS/UiNxhdFTElV3wov37GXzOs1xdbv8lUVRg7q5kxRjGVqUGqCQp6AIy Qkyzng54KZvbH7ozPTh+SUWI8yb9ZYTLTfKaoZShCCpWE/6wF0G0d+uml1V42ylowOsU z6nyozPe1moDzcEqycnufUFUc5G98MVJwnW4/G5c+6iTqlcmHLPLMMMhXu/BYQjQyJqY FiwuPJzDaBQr5WwwXVBIjn97jo7Tx6QCmoVf6ngOA+PLjMZSDjxCfRKnXJ+XpVyyNtzs ot2o3CzEKqwCAbX3nLKTV+DctWgegGnuN3zaPX0xelRUWogGvcg8jy5K1a8ufZZL65DJ w+Hg== 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=QTzuJJGM+CMJa97B/Z/XJpydbjxjjYw8mxhRJ7i5Oyc=; b=GntFDpoSYnjFr5/Jh6MCxVmFa1C33jLi6F9dkMqNJ+BTsw8wrzHWlY+ajRba6iR4NG mV+wyjbPFFTyT4DsALWVwOzkRSy+z5RnBe/1g+A+ZXOhdP9IlDj6ucATaq0KNbJxUCEE OALz7mTi1v+AJvuqSPCWrutI8AHbZdi7KXdGRgwlscIlzkmJKFz+kBzJ/4vIyQTRrSdA xTiYbMTVdp9N532F4zCp/pbYo7T0glbWPcmixIJSE1tZ0qVIPD5eD4kbxl+5nsS1eYvk wlt7oEGJEvXWZd+3uLBJWUEcDuduZRcJHVI1ytOumq/CozMwym0Bx8qaNtAySiauawlo vaMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WVvZkZri; 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 s5si10417157ejj.558.2020.07.05.16.16.03; Sun, 05 Jul 2020 16:16:03 -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=WVvZkZri; 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 S1728159AbgGEXP7 (ORCPT + 9 others); Sun, 5 Jul 2020 19:15:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727970AbgGEXP7 (ORCPT ); Sun, 5 Jul 2020 19:15:59 -0400 Received: from mail-lf1-x142.google.com (mail-lf1-x142.google.com [IPv6:2a00:1450:4864:20::142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 939E3C061794 for ; Sun, 5 Jul 2020 16:15:58 -0700 (PDT) Received: by mail-lf1-x142.google.com with SMTP id k15so21554242lfc.4 for ; Sun, 05 Jul 2020 16:15:58 -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=QTzuJJGM+CMJa97B/Z/XJpydbjxjjYw8mxhRJ7i5Oyc=; b=WVvZkZri239Thm/GSsjzj1SMJ8VVOSBKPR0G0R7GUdKrsSOrFSObmIDcY5hplMT8pY SCjuHTD2lSQabI3arRpPzrbimpeSWKILhwK7fEOWuIAljUq90/z+1iC0Zd8dJrAyOlaY TUVPH1DMza30xgFz3R5+gXLla0fqQJIat5UxXzFcYM48mgOPLWeioM9mbo7NY+S57pCK O7i3KAjgNIm2oy+EumAloD2LxmTvIJaUy9Mqhb2IfwLKWzxCZPNG5Fhab0MzBQTPCy44 iwYYNX2/CWYwkoAAK3TU3FR6TKIPQ5MMOpqPxMJivScjidzZV31oRRa8xrRHSrHwEacu H7EA== 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=QTzuJJGM+CMJa97B/Z/XJpydbjxjjYw8mxhRJ7i5Oyc=; b=ay8LZB1l2ir/h1zEmqdRIjZKN87QDlw3CcXYkqTbdzUUyapkO1IizZzuIIGh2gQ61I mCawghyqxSU6t63DwSn1vpTPBnHSeixh0Wo5jRwFfgMHa0kS2ay2c9P/utzqJbEJm4mo pdvIBkXBJ5x26kFt8Zk0b1TmuERihLmrkh0tEvhy0U5hUPKiXytyP+rzs3QEfcyAyA4P ELLEuWZiA5Hu21J8Fi6tVyR0fp7Qxjnv29HWsV4peReRFia0DuAuALfYcIGbNwb1MTjf xWPH3bag9Mm2SkMfaLMdSowi2lbRgxEEcpxQCg1AZ+FOOeoMW6/auNCkA+EmiONSjsbn z+zQ== X-Gm-Message-State: AOAM530LLJAy/X9IZndf8FMndhEhy8/0q9fvzogwsRAbqmNAFmanzvXu WINK6PL9al4maJX3LSo923TvNw== X-Received: by 2002:ac2:5619:: with SMTP id v25mr28652578lfd.117.1593990957031; Sun, 05 Jul 2020 16:15:57 -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 f14sm8439410lfa.35.2020.07.05.16.15.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jul 2020 16:15:56 -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 1/5 v3] net: dsa: tag_rtl4_a: Implement Realtek 4 byte A tag Date: Mon, 6 Jul 2020 01:15:46 +0200 Message-Id: <20200705231550.77946-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200705231550.77946-1-linus.walleij@linaro.org> References: <20200705231550.77946-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 implements the known parts of the Realtek 4 byte tag protocol version 0xA, as found in the RTL8366RB DSA switch. It is designated as protocol version 0xA as a different Realtek 4 byte tag format with protocol version 0x9 is known to exist in the Realtek RTL8306 chips. The tag and switch chip lacks public documentation, so the tag format has been reverse-engineered from packet dumps. As only ingress traffic has been available for analysis an egress tag has not been possible to develop (even using educated guesses about bit fields) so this is as far as it gets. It is not known if the switch even supports egress tagging. Excessive attempts to figure out the egress tag format was made. When nothing else worked, I just tried all bit combinations with 0xannp where a is protocol and p is port. I looped through all values several times trying to get a response from ping, without any positive result. Using just these ingress tags however, the switch functionality is vastly improved and the packets find their way into the destination port without any tricky VLAN configuration. On the D-Link DIR-685 the LAN ports now come up and respond to ping without any command line configuration so this is a real improvement for users. Egress packets need to be restricted to the proper target ports using VLAN, which the RTL8366RB DSA switch driver already sets up. Cc: DENG Qingfang Cc: Mauri Sandberg Reviewed-by: Andrew Lunn Signed-off-by: Linus Walleij --- ChangeLog v2->v3: - Collect Andrew's review tag. ChangeLog v1->v2: - Drop some netdev_dbg() calls that was just littering. - Rebase on v5.8-rc1 --- include/net/dsa.h | 2 + net/dsa/Kconfig | 7 +++ net/dsa/Makefile | 1 + net/dsa/tag_rtl4_a.c | 131 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 141 insertions(+) create mode 100644 net/dsa/tag_rtl4_a.c -- 2.26.2 diff --git a/include/net/dsa.h b/include/net/dsa.h index 50389772c597..2b37943f09a4 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -44,6 +44,7 @@ struct phylink_link_state; #define DSA_TAG_PROTO_KSZ8795_VALUE 14 #define DSA_TAG_PROTO_OCELOT_VALUE 15 #define DSA_TAG_PROTO_AR9331_VALUE 16 +#define DSA_TAG_PROTO_RTL4_A_VALUE 17 enum dsa_tag_protocol { DSA_TAG_PROTO_NONE = DSA_TAG_PROTO_NONE_VALUE, @@ -63,6 +64,7 @@ enum dsa_tag_protocol { DSA_TAG_PROTO_KSZ8795 = DSA_TAG_PROTO_KSZ8795_VALUE, DSA_TAG_PROTO_OCELOT = DSA_TAG_PROTO_OCELOT_VALUE, DSA_TAG_PROTO_AR9331 = DSA_TAG_PROTO_AR9331_VALUE, + DSA_TAG_PROTO_RTL4_A = DSA_TAG_PROTO_RTL4_A_VALUE, }; struct packet_type; diff --git a/net/dsa/Kconfig b/net/dsa/Kconfig index d5bc6ac599ef..1f9b9b11008c 100644 --- a/net/dsa/Kconfig +++ b/net/dsa/Kconfig @@ -86,6 +86,13 @@ config NET_DSA_TAG_KSZ Say Y if you want to enable support for tagging frames for the Microchip 8795/9477/9893 families of switches. +config NET_DSA_TAG_RTL4_A + tristate "Tag driver for Realtek 4 byte protocol A tags" + help + Say Y or M if you want to enable support for tagging frames for the + Realtek switches with 4 byte protocol A tags, sich as found in + the Realtek RTL8366RB. + config NET_DSA_TAG_OCELOT tristate "Tag driver for Ocelot family of switches" select PACKING diff --git a/net/dsa/Makefile b/net/dsa/Makefile index 108486cfdeef..4f47b2025ff5 100644 --- a/net/dsa/Makefile +++ b/net/dsa/Makefile @@ -11,6 +11,7 @@ obj-$(CONFIG_NET_DSA_TAG_DSA) += tag_dsa.o obj-$(CONFIG_NET_DSA_TAG_EDSA) += tag_edsa.o obj-$(CONFIG_NET_DSA_TAG_GSWIP) += tag_gswip.o obj-$(CONFIG_NET_DSA_TAG_KSZ) += tag_ksz.o +obj-$(CONFIG_NET_DSA_TAG_RTL4_A) += tag_rtl4_a.o obj-$(CONFIG_NET_DSA_TAG_LAN9303) += tag_lan9303.o obj-$(CONFIG_NET_DSA_TAG_MTK) += tag_mtk.o obj-$(CONFIG_NET_DSA_TAG_OCELOT) += tag_ocelot.o diff --git a/net/dsa/tag_rtl4_a.c b/net/dsa/tag_rtl4_a.c new file mode 100644 index 000000000000..df82249aa1a7 --- /dev/null +++ b/net/dsa/tag_rtl4_a.c @@ -0,0 +1,131 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Handler for Realtek 4 byte DSA switch tags + * Currently only supports protocol "A" found in RTL8366RB + * Copyright (c) 2020 Linus Walleij + * + * This "proprietary tag" header looks like so: + * + * ------------------------------------------------- + * | MAC DA | MAC SA | 0x8899 | 2 bytes tag | Type | + * ------------------------------------------------- + * + * The 2 bytes tag form a 16 bit big endian word. The exact + * meaning has been guess from packet dumps from ingress + * frames, as no working egress traffic has been available + * we do not know the format of the egress tags or if they + * are even supported. + */ + +#include +#include + +#include "dsa_priv.h" + +#define RTL4_A_HDR_LEN 4 +#define RTL4_A_ETHERTYPE 0x8899 +#define RTL4_A_PROTOCOL_SHIFT 12 +/* + * 0x1 = Realtek Remote Control protocol (RRCP) + * 0x2/0x3 seems to be used for loopback testing + * 0x9 = RTL8306 DSA protocol + * 0xa = RTL8366RB DSA protocol + */ +#define RTL4_A_PROTOCOL_RTL8366RB 0xa + +static struct sk_buff *rtl4a_tag_xmit(struct sk_buff *skb, + struct net_device *dev) +{ + /* + * Just let it pass thru, we don't know if it is possible + * to tag a frame with the 0x8899 ethertype and direct it + * to a specific port, all attempts at reverse-engineering have + * ended up with the frames getting dropped. + * + * The VLAN set-up needs to restrict the frames to the right port. + * + * If you have documentation on the tagging format for RTL8366RB + * (tag type A) then please contribute. + */ + return skb; +} + +static struct sk_buff *rtl4a_tag_rcv(struct sk_buff *skb, + struct net_device *dev, + struct packet_type *pt) +{ + u16 protport; + __be16 *p; + u16 etype; + u8 flags; + u8 *tag; + u8 prot; + u8 port; + + if (unlikely(!pskb_may_pull(skb, RTL4_A_HDR_LEN))) + return NULL; + + /* The RTL4 header has its own custom Ethertype 0x8899 and that + * starts right at the beginning of the packet, after the src + * ethernet addr. Apparantly skb->data always points 2 bytes in, + * behind the Ethertype. + */ + tag = skb->data - 2; + p = (__be16 *)tag; + etype = ntohs(*p); + if (etype != RTL4_A_ETHERTYPE) { + /* Not custom, just pass through */ + netdev_dbg(dev, "non-realtek ethertype 0x%04x\n", etype); + return skb; + } + p = (__be16 *)(tag + 2); + protport = ntohs(*p); + /* The 4 upper bits are the protocol */ + prot = (protport >> RTL4_A_PROTOCOL_SHIFT) & 0x0f; + if (prot != RTL4_A_PROTOCOL_RTL8366RB) { + netdev_err(dev, "unknown realtek protocol 0x%01x\n", prot); + return NULL; + } + port = protport & 0xff; + + /* Remove RTL4 tag and recalculate checksum */ + skb_pull_rcsum(skb, RTL4_A_HDR_LEN); + + /* Move ethernet DA and SA in front of the data */ + memmove(skb->data - ETH_HLEN, + skb->data - ETH_HLEN - RTL4_A_HDR_LEN, + 2 * ETH_ALEN); + + skb->dev = dsa_master_find_slave(dev, 0, port); + if (!skb->dev) { + netdev_dbg(dev, "could not find slave for port %d\n", port); + return NULL; + } + + skb->offload_fwd_mark = 1; + + return skb; +} + +static int rtl4a_tag_flow_dissect(const struct sk_buff *skb, __be16 *proto, + int *offset) +{ + *offset = RTL4_A_HDR_LEN; + /* Skip past the tag and fetch the encapsulated Ethertype */ + *proto = ((__be16 *)skb->data)[1]; + + return 0; +} + +static const struct dsa_device_ops rtl4a_netdev_ops = { + .name = "rtl4a", + .proto = DSA_TAG_PROTO_RTL4_A, + .xmit = rtl4a_tag_xmit, + .rcv = rtl4a_tag_rcv, + .flow_dissect = rtl4a_tag_flow_dissect, + .overhead = RTL4_A_HDR_LEN, +}; +module_dsa_tag_driver(rtl4a_netdev_ops); + +MODULE_LICENSE("GPL"); +MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_RTL4_A); From patchwork Sun Jul 5 23:15:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 234834 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp4289980ilg; Sun, 5 Jul 2020 16:16:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz6xYRhHAUB3oPgcOpuPKmn8iZEUS1YhGY4HbtcIyehAY24ASwzINYQYv1JHY4pYGFBXnhX X-Received: by 2002:aa7:cfc8:: with SMTP id r8mr17636960edy.125.1593990963560; Sun, 05 Jul 2020 16:16:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593990963; cv=none; d=google.com; s=arc-20160816; b=OUqpIK3lfpf3O3wR253YNPI92+gAB9g6UxO5RIEGLtP03kZasKD/4dnfUtCEsKBMIM tyE7cMNeHxGTAxsFpq14jNNFRFIblkCiiZZ/oH1kmKEF1xtZeSpmdIQ9GVA7s/xrEvYO sF+xzYXo/ZSM/LDWlzow2FxwIxTvN1hs7Eiwm6g3qAUWWeAgfbxJ+Ker1Yxe59YyIjxf iu+oVust6VcKfQbLR4RK2VGzkqdW+i7F8xvSPEWNHskSp5MlKgIIYpQdo+gfjh7ek5iT XwcCMHYkd3zQxwpeeIVJESSdKoWZdzjL8LHr83mfvqzqb+bEDqyx+5g1lv7J+DKKFcDw B/dg== 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=9urUuGoORWbCOM0jkz2zh+XTET/vU9d85Qc/lpKrzv0=; b=l1ezrszRRvvWjd8w8QyE/PCoDb98DN0Y6BfqkZHs3j5XpdGAxW06RWx25lONX9IQ91 kj62UGqiE5l7hMyKEBvFrbrc5sOm+46eIXHg9wE0ud2kLPCgWmGjIZ35YYch2Oozuptb 5+Xk3k3oCtFLSgioeHC/fyCQDVOVT35dWQPkBn71dklJ0fyfVmgqAfyq0e18Lj++wR/+ eH+3oTOulCA3vbia7FVXITJ0zFK3yhA4APLN28EZplwRm4COCwoDVXfsDdfqzBG0j8a6 tbYGMpTHVnF+/t1KNeuzcVKcRnMejdo2ShWr8NYbysznD+T9a537fIqwRZ/B+ffMLqVz XYHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bVj34Ewr; 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 s5si10417157ejj.558.2020.07.05.16.16.03; Sun, 05 Jul 2020 16:16:03 -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=bVj34Ewr; 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 S1728175AbgGEXQB (ORCPT + 9 others); Sun, 5 Jul 2020 19:16:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727970AbgGEXQB (ORCPT ); Sun, 5 Jul 2020 19:16:01 -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 A3DC2C061794 for ; Sun, 5 Jul 2020 16:16:00 -0700 (PDT) Received: by mail-lj1-x244.google.com with SMTP id h19so43255884ljg.13 for ; Sun, 05 Jul 2020 16:16:00 -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=9urUuGoORWbCOM0jkz2zh+XTET/vU9d85Qc/lpKrzv0=; b=bVj34Ewr3hMMHRFBbN1An0NJ2uYuqwrTIJWdUYGx/iXXprxElZ6eCdGEYO3jCbVDwN yD3+7m7HdRXjed/v/ix59mxt7xP8YDTM6gPtT7yMJA3pR4RH/jeazq8iGAVOpt3+YcAC gziMSIQM21vdQ/CuItW3U+xhJVQ9WqsjmmI9T0o3fRJhbMZeno9il8iOMcd35Tcm8vEc wvaCzsAr4obbWYu9MHE//xm4Y5QLPTM5apnamzE7KO/y9db7utOMrLQIeZbqSINju3xY 9TUqCSSJGLO1CPz6m3QhR9WXd8VgunoChW0ZFnwNq5uvoQFjD9Zgjl93P9uT5N044kEy PY9w== 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=9urUuGoORWbCOM0jkz2zh+XTET/vU9d85Qc/lpKrzv0=; b=MgEr5hn7ZLzdLGEpeXm9y6aMHIPSIR+9W+hRcqfps2r8HCVlrwQTn/0f42C5nF0fbq +7sYD4lfomQDFPe7aoSboBKyEiUG+17B+BjDVKyXNHdkXYKxznMrol2TJlGGaeXVIvlY 1Kq1kpM0SPNpo2xruIm/hPLI1AHaa4y+AHyTJgrwpmu1gOCIU9h1q9oNb7WyNXg5Xm3M j6MyGMo55GBjplNLe5pBWBl0RSGTPHorx8QIXL9m/CcMkhcA/LtFkZiDzWLG6ayKIMjb 67G0RQw4YHWraXKjAKU+pTyB6MzD8AIlCKdNX3RVKtgb0UAN/cUMXWlyGKNisI0uKeFs rA9Q== X-Gm-Message-State: AOAM531/ymH03nqvbi5AY3XTiaSJSfsVMDQ+eeKP+V7YswkHcPN6zySV aWYCrnOTEnt1ysiiySrI7Gsatg== X-Received: by 2002:a2e:8597:: with SMTP id b23mr9796197lji.338.1593990959162; Sun, 05 Jul 2020 16:15:59 -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 f14sm8439410lfa.35.2020.07.05.16.15.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jul 2020 16:15:58 -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 2/5 v3] net: dsa: rtl8366rb: Support the CPU DSA tag Date: Mon, 6 Jul 2020 01:15:47 +0200 Message-Id: <20200705231550.77946-3-linus.walleij@linaro.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200705231550.77946-1-linus.walleij@linaro.org> References: <20200705231550.77946-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. Bit 15 in register RTL8368RB_CPU_CTRL_REG can be set to 1 to disable the insertion of the CPU tag which is what the code currently does. The bit 15 define calls this setting RTL8368RB_CPU_INSTAG which is confusing since the inverse meaning is implied: programmers may think that setting this bit to 1 will *enable* inserting the tag rather than disabling it, so rename this setting in bit 15 to RTL8368RB_CPU_NO_TAG which is more to the point. After this e.g. ping works out-of-the-box with the RTL8366RB. Cc: DENG Qingfang Cc: Mauri Sandberg Reviewed-by: Andrew Lunn Signed-off-by: Linus Walleij --- ChangeLog v2->v3: - Fix up the commit message. - Collect Andrew's review tag. ChangeLog v1->v2: - Update the commit message to explain why we are renaming bit 15 in RTL8368RB_CPU_CTRL_REG. --- drivers/net/dsa/Kconfig | 1 + drivers/net/dsa/rtl8366rb.c | 31 ++++++++----------------------- 2 files changed, 9 insertions(+), 23 deletions(-) -- 2.26.2 diff --git a/drivers/net/dsa/Kconfig b/drivers/net/dsa/Kconfig index d0024cb30a7b..468b3c4273c5 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 Sun Jul 5 23:15:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 234835 Delivered-To: patch@linaro.org Received: by 2002:a54:3249:0:0:0:0:0 with SMTP id g9csp3789809ecs; Sun, 5 Jul 2020 16:16:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz+q8vywrOqGKHDFL7bhVjzaGyEnYr4kWxbLXDdkcmVE7dlVIHMWPn0mw8ntWTuXMF7x7v0 X-Received: by 2002:a17:906:6847:: with SMTP id a7mr39936396ejs.306.1593990978315; Sun, 05 Jul 2020 16:16:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593990978; cv=none; d=google.com; s=arc-20160816; b=PKTjFoSqiXR2Z3T9qd9SdwKMN9wgOA8z3LxGSi1g2RL6DVIgnvH9MAZHxaAWNGSUYW aJvj5k8tiYtDQUGezArQPS4qtssPsxxGnni0Xc7VXPC4gj3YRupB8awd6JTpEgXVosSa A8LR1OYE+C0OGLedlFBZHeZkNgYjliT83dUVxPUsrIcVi7Tnp10iXxW+IY5jWQi+pxtn cPbDc854f68Qr2P6/FNH6UWAJCRYR+4e4e2M/T80HSpDbrAp+63Yko1IXJY5gXgDCf/9 4+s8+xRkEc8T/GowwzaoZFycBe/cGuhrPg3Fr0rA4ZOWPl3dW6AaW7P8tL4MCEaRcd/s CVwg== 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=AXKexd4MzK1hVboNLLmQky0SOZO0lAu7FfFVMrF6AKM=; b=qm+geS8p3ns/5R/J9ZvQNjSZZPwR5wkLFFQy6JCongr4woJOtn0CfbTK53KzKqUGG9 5h2ccP9HnYqvuNWGTHE4qvl6zAJoQpmCiFX2ZsKFyOCF5A2p4iwcgTNWak0Q6K0XEsSr gcnhLqScYfLz3CYt36pIkUmLpa29Ur5ypbwxrPXxJh0tmjl3wvrlbSHAGua73pWmwQek iacSHLZrujL98DGlNRT2nbWoXAtHYnGnSsTCq9tJXOwPCpg3FLFawARfUHEexJ2a8q69 FS5t8DzIzlVuhWqRx4R/yqRECCcvZX/rIFOSkl1wt7/AGpfSzTN7TMh/Judxs/moyBgi 9SiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Am3Up0ox; 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 dn17si15678910ejc.556.2020.07.05.16.16.15; Sun, 05 Jul 2020 16:16:18 -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=Am3Up0ox; 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 S1728196AbgGEXQE (ORCPT + 9 others); Sun, 5 Jul 2020 19:16:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727970AbgGEXQD (ORCPT ); Sun, 5 Jul 2020 19:16:03 -0400 Received: from mail-lj1-x242.google.com (mail-lj1-x242.google.com [IPv6:2a00:1450:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47BFFC061794 for ; Sun, 5 Jul 2020 16:16:03 -0700 (PDT) Received: by mail-lj1-x242.google.com with SMTP id 9so43188676ljv.5 for ; Sun, 05 Jul 2020 16:16:03 -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=AXKexd4MzK1hVboNLLmQky0SOZO0lAu7FfFVMrF6AKM=; b=Am3Up0oxkIJbITdJ9g1vtgh2GaUCy7ythe+9wquj/EFKRoONwtolQZeI1R9Z1gceGU 7BEH4DS1HrfHZqZVznJxhy12k5udfxBtsPxZU6bboOD9sEKp0gzuA4YyJg4AAmVW1Q1g pOaIUZu+Qj2NpHcAxZVp4+ew8kwab/jTSSEFyeipMb89vn4935l4ZpBVgwf84gttqszw UxsZxikg228VBnaIoJapgJBYIvZ7Dg+hOTQ0Y2AGzzU8+wHHRs8p22kUFz7H/03HZOa1 9A9csEXJ+RIS0sFdtPEFj9TqA1qQ+IQXIyGe/9VmeH5OgOt0bk+idWbkQQEbZgU37B23 GH/A== 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=AXKexd4MzK1hVboNLLmQky0SOZO0lAu7FfFVMrF6AKM=; b=iUTeDvU2Yh9pq79w6wJhCKuGzNBTlelaOE/JTzYU8Y62qwiqxBxypEqU49DtmOujqT AdgEHVbUZ7aXxYzig6PiQH+mUHQTTtkN9vHrpifoVOF8+Oe/Hf/pfKDl4EUxozGhjyOs ax8T2f6sABHw2Vyn7+9EkchgbClnq3vCfICaSvCYqP9L7ZfoFnSMlYnp3DhTEgmz42nU OEPysD6PzKA79ur/L0baq266Jafm/MYhm7UM9ZOv47RW4XxwpTzatx9iMPuCDbRLdMLJ ubCrJe7rbVITU8EpUUlqpCYeDkMJ4st3NjLoIoHFaEClQb/CPsGHyDdI9vwmzstE/Eda fOFg== X-Gm-Message-State: AOAM530pdoeLkq+eyVDCGyh+mwK53wOlt63ec8kM19zSnYFVsq5K4lwU fbHu01GKLsb2WfmEL+PvF9sJog== X-Received: by 2002:a2e:8804:: with SMTP id x4mr25809262ljh.56.1593990961363; Sun, 05 Jul 2020 16:16:01 -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 f14sm8439410lfa.35.2020.07.05.16.16.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jul 2020 16:16: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 v3] net: dsa: rtl8366: Split out default VLAN config Date: Mon, 6 Jul 2020 01:15:48 +0200 Message-Id: <20200705231550.77946-4-linus.walleij@linaro.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200705231550.77946-1-linus.walleij@linaro.org> References: <20200705231550.77946-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 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; } From patchwork Sun Jul 5 23:15:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 234836 Delivered-To: patch@linaro.org Received: by 2002:a54:3249:0:0:0:0:0 with SMTP id g9csp3789812ecs; Sun, 5 Jul 2020 16:16:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz9YZNquU8GmNitZ+YIlhOMf0joTrb0Cp5ntePnUBe3PO8d9/8gqg1qSIq3HjVg3Xj+g15v X-Received: by 2002:a17:906:d78f:: with SMTP id pj15mr43332097ejb.283.1593990978688; Sun, 05 Jul 2020 16:16:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593990978; cv=none; d=google.com; s=arc-20160816; b=hVS428NdtDyWkvw41WPwLwoS/y0U0HilJuNLTdRQ3nCQxwgLEx2vIMUL0cvg7sMWYZ i7HB7hcI3WVB4nDKD5z++qzLANx+36IciH314NWMzgkLF6Yg1arpOH/qZSyVrc+fU80c kQsWEIkW3rIEQWb3cH5sbh9lchzhbK5lHYS3ssYKKxGi12bDgPY6Q9xmBAFDkKkgVxUG 6iL7Uck2tLR9bsBiRXRqcD3UFXSN8OLXIfbtOrL9WqJ0Y3mOQAb3YhT7f19XMA9oXYUA S2nlRDcbWQhCnBzHAyBjw2vDcwsMa6elBXtmULqt6zeSoAVwW33fTWmWdhn1MJNfn/65 KUpg== 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=oRQbxGVGZRD34g3pn9EV0X0GK2Ho/RF1IeE++Md7qkI=; b=nxSGJHsrnlnjub/LdSGTc5FNZWp0ZhtgIXrypRJhlv/zHIcPToU3zV2KRXgzMF3OhJ gU2rMAkj3egapFMAyP0OVaxm9AhGVomupdM93nnPH/LPVJ0o0QS8yH7R3l3R/ke1CdrI bzxOIEANoDYmF1SVbS5zE8iVtvmGLqNGzeYdGY/qLj46jSv1wmshRTG1DPG3taZ2xGre 8e4ibsAc8FRr0gDq4MJpUms4ls/JfnmFSxrmiMaiv6ncwzSWD7UCfh+Z96eo3DskC1qo 86uJLEbyv+VQXo+prYacaTD1DgqF0gmp4f92+ka2dnEQGRk3zpB8MIqJUG9db6G2aCkU fNwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="QP7cfWz/"; 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 dn17si15678910ejc.556.2020.07.05.16.16.18; Sun, 05 Jul 2020 16:16:18 -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="QP7cfWz/"; 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 S1728224AbgGEXQG (ORCPT + 9 others); Sun, 5 Jul 2020 19:16:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727970AbgGEXQF (ORCPT ); Sun, 5 Jul 2020 19:16:05 -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 BD84FC061794 for ; Sun, 5 Jul 2020 16:16:04 -0700 (PDT) Received: by mail-lj1-x241.google.com with SMTP id q7so29994943ljm.1 for ; Sun, 05 Jul 2020 16:16:04 -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=oRQbxGVGZRD34g3pn9EV0X0GK2Ho/RF1IeE++Md7qkI=; b=QP7cfWz/ldEhdIAeGCP3P75O8pe555+s8FMGP+meZ9ys8vIeT7CKdwoLtYE46MMcQt sEV9isfe6GBIcNQqB7lxVTaoF6uA+keLUDPc9+BeHljI7RS61ALlN8D0GukHoKtC3ijP 5+CzMbZ19UN34bySHn+iTe+lz7wJgxkKfrbteuufet9mTjgY0ZkarIZNfdKge12sKk4Q YZA0aOrHMN3sLsXbRIYlepd2LgTDUGVa7A/39IzIOdLGDrT5kdm6/1VihKWc1/wwu66s +z5mQVm9vHjkahkjJVTRvfEDvrRWCOuMrS5kmmEfdrFxgSInu11TIAZ0+JX7eMxnM8CG J2Lw== 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=oRQbxGVGZRD34g3pn9EV0X0GK2Ho/RF1IeE++Md7qkI=; b=VwXnINp/S02J/oJPT+pqfVSrYxef5TKflaPfhO7PKmOOHASUL/FjluNJvMwriknes7 e05+neAcBtuJ/nlKN38zqUOYgi+2v4kaGSTmqxwNKvAELuVeU2ETgEjHOLnXkPnt4y9T hMIfQr3OstArTGEajDze9CAkeS2LXqiAc5Gz4/A0zg/RSTPqhbaMlFAG2dikYKxTIy7F nN6TcUvyYxIroJNbJaVLsKyYWeWECdDMcKvZQMWcSubIuc7Z6SpiFSxFhznMbd/z74LG BMwAHrMKN+k+fOmoXx/q7Azg14FXhGQcZ7tWFhYoVg5GOYnp+e1mLUGVBnfhQD5DWNvC E0Ow== X-Gm-Message-State: AOAM532JShbXRK2Ooqo0ACnJndcpGT63fpWqJyTKjTrXJUDC8w/j4CC/ UV6pId3g94jDHUD7SYrHf77gLw== X-Received: by 2002:a2e:9641:: with SMTP id z1mr22542348ljh.173.1593990963210; Sun, 05 Jul 2020 16:16:03 -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 f14sm8439410lfa.35.2020.07.05.16.16.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jul 2020 16:16:02 -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 4/5 v3] net: dsa: rtl8366: VLAN 0 as disable tagging Date: Mon, 6 Jul 2020 01:15:49 +0200 Message-Id: <20200705231550.77946-5-linus.walleij@linaro.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200705231550.77946-1-linus.walleij@linaro.org> References: <20200705231550.77946-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 Cc: Mauri Sandberg Reviewed-by: Andrew Lunn Signed-off-by: Linus Walleij --- ChangeLog v2->v3: - Collected Andrew's review tag. ChangeLog v1->v2: - Rebased on v5.8-rc1 and other changes. --- drivers/net/dsa/rtl8366.c | 65 +++++++++++++++++++++++++++++++-------- 1 file changed, 52 insertions(+), 13 deletions(-) -- 2.26.2 diff --git a/drivers/net/dsa/rtl8366.c b/drivers/net/dsa/rtl8366.c index b907c0ed9697..a000d458d121 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; From patchwork Sun Jul 5 23:15:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 234837 Delivered-To: patch@linaro.org Received: by 2002:a54:3249:0:0:0:0:0 with SMTP id g9csp3789815ecs; Sun, 5 Jul 2020 16:16:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy03CNSqqTO+dhJiRpQ9uE6aKS2YYNds3BEuiQvWSPK3GtLCjRW22JPOXkIR9dAMZNrsfPs X-Received: by 2002:a05:6402:1250:: with SMTP id l16mr53712941edw.362.1593990979039; Sun, 05 Jul 2020 16:16:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593990979; cv=none; d=google.com; s=arc-20160816; b=ayGsGLwMrN3NMb4Zu+NyD56L7xgKts2n5VRSPj702UlgAVt48f22GP1uaoAM0kwQO5 uDtHG07I5ynpeacDK51mk4F61X/mTYMmgRYUqEFEYHVUvE7m5ErRHXW3ach+qwmcKNrf 5ccmjRIBqU9Nav7VKVyrEkqWSqo5JtXo7YSL5HbzMRi9sFPXAu1eYWUE7is/3DfsNt8I AjYamIQ0FWOmWSVgW5zUl8JRQd6535ADx3Z34fERxJtDzWUOCJENenwpPP6ooCNTmFov SMj+k8qThCMQhgu0uU3RPHq0anlLnYvMxwCoqQbn6U4rqUm9EJH768IhmmIhNgHKB2ti sR5Q== 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=bEnvRIle9ouYWtzoth+BrQzE2gQE9/8+m5/d/sfeHBA=; b=M84MsxCrD72aCMSum3aaEknAoF4VndfrW/XbF4ecpc7gNpkVQJdQ6ByBDpk+cOol9r MwJq0d5OM0HQ3Sxg/e07ov+D14912mky8ewHEquMAYxTqZKNsTTvSmZ19cjEj+lyQB57 qjNUv+2UZVNPSX86ez/Uy/0lXh8YdAXYcnazrBEC7lsZ2ZhZrHf0D8VjkjqJHdoWxeWL rQskLqx8xFqsc3ucEzaktG0mXhaAKzhQw2KdU0p9zKBdy4Go/7RSs9pp/WOU6oN6+tIZ 8NMWKPCCFQt35rr6kZf69SNdkjkbNi14ijQfOE/htxDXOjJARoL4QcMP9x+WQb0cLkUL mebg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TzjSZww2; 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 dn17si15678910ejc.556.2020.07.05.16.16.18; Sun, 05 Jul 2020 16:16:19 -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=TzjSZww2; 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 S1728238AbgGEXQJ (ORCPT + 9 others); Sun, 5 Jul 2020 19:16:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728220AbgGEXQG (ORCPT ); Sun, 5 Jul 2020 19:16:06 -0400 Received: from mail-lf1-x143.google.com (mail-lf1-x143.google.com [IPv6:2a00:1450:4864:20::143]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45FD2C061794 for ; Sun, 5 Jul 2020 16:16:06 -0700 (PDT) Received: by mail-lf1-x143.google.com with SMTP id k15so21554333lfc.4 for ; Sun, 05 Jul 2020 16:16:06 -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=bEnvRIle9ouYWtzoth+BrQzE2gQE9/8+m5/d/sfeHBA=; b=TzjSZww2QTqv2PaavxaJsKSzwDtKnRMVtuXVlJyqgWjSVW8lj5c7cXA3mv8CEEMMw8 4dSo/ymC41Sdhx98vBWE1PI/SuwHkC+zeU5dpfJ3Nc9Rpa4IQS35zzClCv5iNw/kkv76 Ji6lSzGhLSf1t+LLTEsgKBiZDbVLhklV7bdR5STby9/XQ1qYtApqGJnJ58NF58/KSRFN NYTtDs/Tah11mOxkewCAPgpxmAwvgcL6X+nC942zDyCnEdlW1BjeoZlh2m8x5yLZsKO1 RXUd/g2aUfQXL/KtUotM5bF9U4lUhebl/RV/54VZO7OXRKCaDhT/yDUB12xhZEc7nKM3 Pkhw== 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=bEnvRIle9ouYWtzoth+BrQzE2gQE9/8+m5/d/sfeHBA=; b=dglD+tcWqdFUK9+QcyCVbWVffK12TeXfGl+d6DZwJffkViuOiiwR2s6rCGoTZaSIj5 wVAeAcQtpr6tucoao5padhxolUlWVRI1qYrqJ9zUkjqq46BKm0Zz+I4gNfsPI0fM9Ifx cOaEr1aLVYvF90a18zAVqA4iWLL8xkbtq7s35zG/vtL6SD5i7oX+clgjvJOHtBY4D+PC CSe18COqHxY0R5lczr3O2Hs8fO1f2Fb68GIUYsxzCSzwlY9wAZZbcJ/f71fD01wiitPB S6Xy+PiqhF190299m8EYmbJLb+a+KyVbwCFivw4Ez/JV14wKLw0+DZa8DI0mvEFBLh+p vWTQ== X-Gm-Message-State: AOAM531NQ0SJrLLzRc7Vs5bMbXJ41Zg16lhIlAoP0cK53pAy79E4ZE4T Le0lInbEq1XYiTviSvu3FV4Hqw== X-Received: by 2002:ac2:5a5e:: with SMTP id r30mr28480711lfn.30.1593990964759; Sun, 05 Jul 2020 16:16:04 -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 f14sm8439410lfa.35.2020.07.05.16.16.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jul 2020 16:16:04 -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 5/5 v3] net: dsa: rtl8366: Use top VLANs for default Date: Mon, 6 Jul 2020 01:15:50 +0200 Message-Id: <20200705231550.77946-6-linus.walleij@linaro.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200705231550.77946-1-linus.walleij@linaro.org> References: <20200705231550.77946-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 RTL8366 DSA switches will not work unless we set up a default VLAN for each port. We are currently using e.g. VLAN 1..6 for a 5-port switch as default VLANs. This is not very helpful for users, move it to allocate the top VLANs for default instead, for example on RTL8366RB there are 16 VLANs so instead of using VLAN 1..6 as default use VLAN 10..15 so VLAN 1 thru VLAN 9 is available for users. Cc: DENG Qingfang Cc: Mauri Sandberg Reviewed-by: Andrew Lunn Signed-off-by: Linus Walleij --- ChangeLog v2->v3: - Collect Andrew's reviewed-by. ChangeLog v1->v2: - Rebase on v5.8-rc1. --- drivers/net/dsa/rtl8366.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.26.2 diff --git a/drivers/net/dsa/rtl8366.c b/drivers/net/dsa/rtl8366.c index a000d458d121..06adcf68ff8d 100644 --- a/drivers/net/dsa/rtl8366.c +++ b/drivers/net/dsa/rtl8366.c @@ -260,8 +260,8 @@ static int rtl8366_set_default_vlan_and_pvid(struct realtek_smi *smi, u16 vid; int ret; - /* This is the reserved default VLAN for this port */ - vid = port + 1; + /* Use the top VLANs for per-port default VLAN */ + vid = smi->num_vlan_mc - smi->num_ports + port; if (port == smi->cpu_port) /* For the CPU port, make all ports members of this