From patchwork Tue Jul 7 21:16:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 235023 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp1271783ilg; Tue, 7 Jul 2020 14:16:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzJeRfKsfA9NdcfRLWojHwG9o0XJK8Exs0mcNk3952kdTMroZA8dBPu7IHv7/DNel5lwZKV X-Received: by 2002:a17:906:2e4b:: with SMTP id r11mr48639884eji.227.1594156585263; Tue, 07 Jul 2020 14:16:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594156585; cv=none; d=google.com; s=arc-20160816; b=EiRJI5xqHcB2Wg9JuJAeCQbi1jn1mo8uurhIR1PigoNCu+4INGipmrK87sED3VNybb KGRPONL0GsqbYdkepkqnRs/NLwPkQZwwELQotM4XLHE3nyoTJdtbTqCj6LgSyQ3yQjNS XEQ4mM9CtrzadL+zYT7BgAo5j+nv9wQ/YOF/9gQStOMLfR3h2aC6sR/1n8J+oEVMGjFl mUY9Wh6Pr2yYXW8pL/7gK1G8n2YfWDLQbao9siLQJTLkX97nj3etIC8jWWhxJSVzImgA 4Ao0NNqXre3HBJ/iPN3ZTg7puKzBVemKrGxfFUAk6JrJBCd7X5LO0To4i1TaXdxXSBYG cgSg== 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=1835iqUTvJK28OPSt2IU22DQdTijr9cSJQ/Hi5VHVO4=; b=jbw2m0hsWiOz3CYu6Xn4gb/YRpUY0pCFmMp2Dz/ZL528tLt7wkTLub+YETPg1m2hgF JFreRoH9khjGxd9m3uroERfZp2qgpFro1caJOj3LB4755RiHItaVSJbamXAdZ3ZQIRhG k/yQ+HAUOwPmB9I44o+rtgAbRyWUl5QrheW5aPlZr9rSmYCOQF1LnGOcGIJnDch97otJ Et1+/87SbEPmUBt4VDEl8piOKH1vE50BpWrzZW8FfXYV70KR9hX0vvpz5R83DbizatAG dCP8hYE3vD4mF09UfrZ903oMPV6FdrbMSsJA51JBVHHdORFuDQSsDV8p4Lsc3N99nfw1 WM5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Qhp0YbEJ; 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 b12si13694128edj.296.2020.07.07.14.16.24; Tue, 07 Jul 2020 14:16:25 -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=Qhp0YbEJ; 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 S1729179AbgGGVQY (ORCPT + 9 others); Tue, 7 Jul 2020 17:16:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728184AbgGGVQX (ORCPT ); Tue, 7 Jul 2020 17:16:23 -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 D942FC061755 for ; Tue, 7 Jul 2020 14:16:22 -0700 (PDT) Received: by mail-lj1-x241.google.com with SMTP id f5so35839800ljj.10 for ; Tue, 07 Jul 2020 14:16:22 -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=1835iqUTvJK28OPSt2IU22DQdTijr9cSJQ/Hi5VHVO4=; b=Qhp0YbEJUjt3WOqL1u4dVilD/GG23+3t06E0UcSr32XuMY8D6xRx2lvAdlhGJYHxk6 WHHTlZBm/cl6B0NutNevNyFdUaXYzoztsM5Fs93BaQjby9gkZq5/pkKVAytS6CZ3357y 2u2l2iJELNHWmXCJEe8aQE75hAMcaJ9Zn9F8sph5/tG1h2Xqg1EcvBpzZJ+c4HwcIOtS MYsw+xsAusxHKcDmAjE9KqKZQojS0qZN1adDKtVb9aZs4/Zgj0KMVZlMSJ34Bt71dtHs rXNA38rLpSvReSI5DrDln5ZVv46+m+eQDQih9K3yYdp4mrQSIQ2a8CY0XDYnq7tAWfT6 CKVw== 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=1835iqUTvJK28OPSt2IU22DQdTijr9cSJQ/Hi5VHVO4=; b=oh7BIJNcp4505I+/OfJJri9X59h4hm5O5zIuw+g6VRgdEQWKGTJzbvJ3jYn+0Il7C7 Z/cT5NDmXiQ4ktxtDDKgBK+Y9W4gNjNrsV5k3yh/p9ToeqIu58MsIfK9mrD1a902Va4A /8XlGiWoNH/6DQckRs7nfz8p+9zn9R1H9P0G3+yVFg9iGf3WogzdZ03RCTmO9lJZ3mQf ziXFWazwbhk5MaPlqumQbVl0JFBIhtUoOp3y7/t9M7wecfMaOG/dYcb/6EmHUj2XVRFW Nh/Nh1mAVKdYVoxHlewSbzlOWW2dQB9hY2WLGnq2PP2eSFtByo3TtKjm6YQXhbV8uIzH 8KNQ== X-Gm-Message-State: AOAM530Uxi9AQrw/6KFyvYEatVZSKYeLRknc+xKsEN6eRvoqxdJbemO3 k2QNA8aIemgnjUHYnvTydER0RA== X-Received: by 2002:a2e:b0ed:: with SMTP id h13mr21716445ljl.250.1594156581219; Tue, 07 Jul 2020 14:16:21 -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 u7sm12750493lfi.45.2020.07.07.14.16.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jul 2020 14:16:20 -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/2 v5] net: dsa: tag_rtl4_a: Implement Realtek 4 byte A tag Date: Tue, 7 Jul 2020 23:16:13 +0200 Message-Id: <20200707211614.1217258-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200707211614.1217258-1-linus.walleij@linaro.org> References: <20200707211614.1217258-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 v4->v5: - Split tagging support from the VLAN fix-ups. ChangeLog v3->v4: - Drop an unused variable found with -Wunused-variable 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 | 130 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 140 insertions(+) create mode 100644 net/dsa/tag_rtl4_a.c -- 2.26.2 Reviewed-by: Florian Fainelli 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..36af1f49fd75 --- /dev/null +++ b/net/dsa/tag_rtl4_a.c @@ -0,0 +1,130 @@ +// 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 *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 Tue Jul 7 21:16:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 235024 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp1271821ilg; Tue, 7 Jul 2020 14:16:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxioDrW4+Wl+lbiea+rFGypz9JoMo8FGl9bO0LlK7ODHHGXBcEdfUDuImHFtV5JsM/zYUZs X-Received: by 2002:a05:6402:1ade:: with SMTP id ba30mr3707797edb.231.1594156589087; Tue, 07 Jul 2020 14:16:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594156589; cv=none; d=google.com; s=arc-20160816; b=tPoWXKq3hfq0cMelEngglK3Gnp2crHMgMSubDm19orXeQ6sWZHxDZWrtt3VqdmFWcf mY/wd2CogzBT006GdEwuOd9XDjcwLj8K1jTl5Mzi3JHeTtst+i7H/j12JNxoLD04GM9u 4QmdmOMbUCU7NqiewJAZtuvujsaU6/P0IYR7TToKj742kpH0U8GhJZhnw0necZJCRQ1g 8zpP672HxwPSAYoPWj9adYlmLlOP2/1lxabBpr+9kTWOahKB9LeVVMUrnHbQHwz8P97V nuDC7w7L0N4F/cUELcfBKQu2A9KWeDMjg2Kw7h+nvwiT5R3mTBoPrHY6mBxShhlQB8mJ OspA== 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=oWLf8mA2zVq2KsL68W1eYCkCCoZOvVmx6e/XhqjhW2s=; b=WVqpPe9RIcYY20GYK+6WGKIMV+vcrQ/EdzZutKVtm7ptQHHxrC/JiAzlL4ApbK3w+P q8NXcexb9fSTXtymUa5x+5tu3DV96CyWG55otbvb1lZaPP83kfFd3DgkWZgy07nB837/ Gwilb1hBXmV5V//DGv5izwPkXYAVT6tVbps0BllncRTUnIqP8CGKZF6nJMUVbGMT7Lkc GyXQp6XcCMA+SoGOHAxcpGtKYhENp4ERCyoSgrhHzqMxlXPp+TsBJ6nSA7MFhTgtmskn zA9XuUl5sfTVRNAvbrS1OqqMWaT8VbiB2IMQFwhctWI6Fn+0Si/L4S+ZJuRPUTWMW2y1 2Oiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DrCz4GJO; 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 b12si13694128edj.296.2020.07.07.14.16.28; Tue, 07 Jul 2020 14:16:29 -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=DrCz4GJO; 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 S1729195AbgGGVQ1 (ORCPT + 9 others); Tue, 7 Jul 2020 17:16:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728184AbgGGVQZ (ORCPT ); Tue, 7 Jul 2020 17:16:25 -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 A511FC061755 for ; Tue, 7 Jul 2020 14:16:24 -0700 (PDT) Received: by mail-lj1-x244.google.com with SMTP id q4so15977649lji.2 for ; Tue, 07 Jul 2020 14:16:24 -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=oWLf8mA2zVq2KsL68W1eYCkCCoZOvVmx6e/XhqjhW2s=; b=DrCz4GJONbnM4IVTKuYwTya2u+OuN6nMFK+txwc17z7CiCy0dZH+/KTX19leAGASkP /tmKxjFOJ5z0IkFHJpQekGUNAUFznL/gjPJ3YWzNEOIy4QNFv76aQh/sby5J8gGnOnqE EQyfhJeaZUR1lKlCtoBWHMbhOL2gliynPyiY25/CxJjBRfsdcJ+DUB+aswSjxgXeo0d7 t9cpVbvP60NglSF99/T1OJh0wV3nN5rELXL6oeAP1BleYMfauAmGXLo2eD/DR1kOhL2v v5chYPVLT/eWi8QaiNCwZxCGabbjstOQsZk9ag8Rnd6qv9nOSdf+HJLtR3a8EjMrl5X2 0T+Q== 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=oWLf8mA2zVq2KsL68W1eYCkCCoZOvVmx6e/XhqjhW2s=; b=V+r737rq7S1OlZiydrkgB0jxFczevfSJkyCWgn1vC/rFPiP6JHKJNSYpS8G70mtkbG i5W2+aUTE+e3/RuFh1RZdR0x0kJFlisZEQX4wtF9keGvG7IbEqLPuT6uFk9kWHbK2Sun 97nBmhuYgtBh+TThMCBzyDf2d0+kiVdELnHn9NiGe50/i0SoZBfN+cROXCu+Xrbo83ll DfQTGgCbjXrsf8BCxLnBudJkAeL0GfOJkeWlqFWP9mpelNZLnFeF4lCjF9SMvRmEmjbG wOjZit0Ysgmg5cJWwIbE4bhL/Oxl/e/AtgJ/4U65at+RMX7laCHTU6THCUlff6nu3poK LA0Q== X-Gm-Message-State: AOAM5315Mp0mOCjgJfa/QckR4DVqhGZ2UnT0qQQNOpgkPHQo8VHzMDC1 yCjWGvqsffyl5gsSNOn+WDYBvA== X-Received: by 2002:a2e:95d6:: with SMTP id y22mr23581653ljh.316.1594156583093; Tue, 07 Jul 2020 14:16:23 -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 u7sm12750493lfi.45.2020.07.07.14.16.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jul 2020 14:16:22 -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/2 v5] net: dsa: rtl8366rb: Support the CPU DSA tag Date: Tue, 7 Jul 2020 23:16:14 +0200 Message-Id: <20200707211614.1217258-3-linus.walleij@linaro.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200707211614.1217258-1-linus.walleij@linaro.org> References: <20200707211614.1217258-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 v4->v5: - Split tagging support from the VLAN fix-ups. ChangeLog v3->v4: - Resend with the rest 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 Reviewed-by: Florian Fainelli 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,