From patchwork Thu Aug 31 11:18:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Majewski X-Patchwork-Id: 13371369 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 25C468F74 for ; Thu, 31 Aug 2023 11:18:53 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F1BACF3; Thu, 31 Aug 2023 04:18:52 -0700 (PDT) Received: from localhost.localdomain (85-222-111-42.dynamic.chello.pl [85.222.111.42]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: lukma@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 6BB688656A; Thu, 31 Aug 2023 13:18:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1693480730; bh=A2k/yH77baFCxR56gOAv9ffVsTNiKhB2LNrgnC9TyvU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xteUFZdD8ny2InDi7NrVUCgTtvr9EFCaiIAeLB+Wj229gIkU8dAYsng/o+6aveg+o w11jaKydJkUu+MqFFROSwCgk+3ADQrZHqHEe2vq17RYqDKcJTGPr4tGM4KIFvGpvo/ XIINzkXNuY4lClnrekDwcYqNR5CdgB5dxcwHIt4Pt1W8hTvJrnsUcPefP2a2+ys2hA gaXTREZcqgJvsmfCIzOP4p5WKqUZX8DuwrbwhXvtITX+RF3dBXUmNGvj1zYgZtE+10 +8hpGIl3GuY7q9sYCPJeqVISLZ37Hp0WRlKRbYpUCDBkIXjP52zvHbBpZT5L4Kr/fQ VQC19uM7mxGNw== From: Lukasz Majewski To: Eric Dumazet , Andrew Lunn , davem@davemloft.net, Paolo Abeni , Woojung Huh , Vladimir Oltean Cc: Tristram.Ha@microchip.com, Florian Fainelli , Jakub Kicinski , UNGLinuxDriver@microchip.com, George McCollister , Oleksij Rempel , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Lukasz Majewski Subject: [PATCH v2 1/4] net: dsa: Extend the ksz_device structure to hold info about HSR ports Date: Thu, 31 Aug 2023 13:18:24 +0200 Message-Id: <20230831111827.548118-2-lukma@denx.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230831111827.548118-1-lukma@denx.de> References: <20230831111827.548118-1-lukma@denx.de> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org Information about HSR aware ports in a DSA switch can be helpful when one needs tags to be adjusted before the HSR frame is sent. For example - with ksz9477 switch - the TAG needs to be adjusted to have both HSR ports marked in tag to allow execution of HW based frame duplication. Signed-off-by: Lukasz Majewski --- Changes for v2: - Use struct ksz_device to store hsr_ports variable --- drivers/net/dsa/microchip/ksz_common.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h index a4de58847dea..9fcafff0c01d 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h @@ -158,6 +158,9 @@ struct ksz_device { bool synclko_125; bool synclko_disable; + /* Bitmask indicating ports supporting HSR */ + u16 hsr_ports; + struct vlan_table *vlan_cache; struct ksz_port *ports; From patchwork Thu Aug 31 11:18:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Majewski X-Patchwork-Id: 13371370 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B6F21944F for ; Thu, 31 Aug 2023 11:18:54 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8077CF4; Thu, 31 Aug 2023 04:18:52 -0700 (PDT) Received: from localhost.localdomain (85-222-111-42.dynamic.chello.pl [85.222.111.42]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: lukma@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 058F08656C; Thu, 31 Aug 2023 13:18:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1693480731; bh=Qjprq4rjy8cLXyviY7njAa3McqK5erY6hM62N5dwybA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OlbRS9bx1sJTrwhcHJGmDKye9bXTM3xAjp7vBBIeChSk/w3B5Ti54ueddeovf9FZP XzrnDr5AgDi3S5Hc1z6YOPGyfzZ5EC0mJFTBk1PUW8/u7+U2wElsG/1anLP6+3Rx6q WoyIPnBOJJn5HqCXNFE2oepVg+cjCk80/osqdH+fpzUe+87wWQ6ePL6DGDJrLeRU99 woupNMdPOV4Nl7vHbgK4OPy8fsx2iXM6y9jIRjZkmWS02ef+FqL1+FPeEK7s6WKQku ZMZPxie90y2YzFnC6nJzX6usRe+xJoJTRodHCOyyuRz20VwoLjikHTk+HUS0wZEbKi jNEDKozWeJgVA== From: Lukasz Majewski To: Eric Dumazet , Andrew Lunn , davem@davemloft.net, Paolo Abeni , Woojung Huh , Vladimir Oltean Cc: Tristram.Ha@microchip.com, Florian Fainelli , Jakub Kicinski , UNGLinuxDriver@microchip.com, George McCollister , Oleksij Rempel , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Lukasz Majewski Subject: [PATCH v2 2/4] net: dsa: Extend ksz9477 TAG setup to support HSR frames duplication Date: Thu, 31 Aug 2023 13:18:25 +0200 Message-Id: <20230831111827.548118-3-lukma@denx.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230831111827.548118-1-lukma@denx.de> References: <20230831111827.548118-1-lukma@denx.de> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org The KSZ9477 has support for HSR (High-Availability Seamless Redundancy). One of its offloading (i.e. performed in the switch IC hardware) features is to duplicate received frame to both HSR aware switch ports. To achieve this goal - the tail TAG needs to be modified. To be more specific, both ports must be marked as destination (egress) ones. Moreover, according to AN3474 application note, the lookup bit (10) should not be set in the tail tag. Last but not least - the NETIF_F_HW_HSR_DUP flag indicates that the device supports HSR and assures (in HSR core code) that frame is sent only once from HOST to switch with tail tag indicating both ports. Information about bits to be set in tag is provided via KSZ generic ksz_hsr_get_ports() function. Signed-off-by: Lukasz Majewski --- - Use ksz_hsr_get_ports() to obtain the bits values corresponding to HSR aware ports --- drivers/net/dsa/microchip/ksz_common.c | 12 ++++++++++++ include/linux/dsa/ksz_common.h | 1 + net/dsa/tag_ksz.c | 5 +++++ 3 files changed, 18 insertions(+) diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index d9d843efd111..579fde54d1e1 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -3421,6 +3421,18 @@ static int ksz_setup_tc(struct dsa_switch *ds, int port, } } +u16 ksz_hsr_get_ports(struct dsa_switch *ds) +{ + struct ksz_device *dev = ds->priv; + + switch (dev->chip_id) { + case KSZ9477_CHIP_ID: + return dev->hsr_ports; + } + + return 0; +} + static const struct dsa_switch_ops ksz_switch_ops = { .get_tag_protocol = ksz_get_tag_protocol, .connect_tag_protocol = ksz_connect_tag_protocol, diff --git a/include/linux/dsa/ksz_common.h b/include/linux/dsa/ksz_common.h index 576a99ca698d..fa3d9b0f3a72 100644 --- a/include/linux/dsa/ksz_common.h +++ b/include/linux/dsa/ksz_common.h @@ -50,4 +50,5 @@ ksz_tagger_data(struct dsa_switch *ds) return ds->tagger_data; } +u16 ksz_hsr_get_ports(struct dsa_switch *ds); #endif /* _NET_DSA_KSZ_COMMON_H_ */ diff --git a/net/dsa/tag_ksz.c b/net/dsa/tag_ksz.c index ea100bd25939..903db95c37ee 100644 --- a/net/dsa/tag_ksz.c +++ b/net/dsa/tag_ksz.c @@ -293,6 +293,11 @@ static struct sk_buff *ksz9477_xmit(struct sk_buff *skb, if (is_link_local_ether_addr(hdr->h_dest)) val |= KSZ9477_TAIL_TAG_OVERRIDE; + if (dev->features & NETIF_F_HW_HSR_DUP) { + val &= ~KSZ9477_TAIL_TAG_LOOKUP; + val |= ksz_hsr_get_ports(dp->ds); + } + *tag = cpu_to_be16(val); return ksz_defer_xmit(dp, skb); From patchwork Thu Aug 31 11:18:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Majewski X-Patchwork-Id: 13371371 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0C3249460 for ; Thu, 31 Aug 2023 11:18:54 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CFDDCF9; Thu, 31 Aug 2023 04:18:53 -0700 (PDT) Received: from localhost.localdomain (85-222-111-42.dynamic.chello.pl [85.222.111.42]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: lukma@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 93EBF86570; Thu, 31 Aug 2023 13:18:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1693480732; bh=meOgs1Mb/Os2fOhdPwvTwxQdUYzf9FYU8GOgmJkH5tU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ojJmTi+/COJOX555gkcu3LzK+cxfvKeSj616KtpzZenYXGowYQ7syh7rE9iK1ugVc zks4D1p4CPTZjScN0Nz8meQD1+sLNQN9CJSTwiUVW4Gn+fTyFKOz1B4Wj495rwjtcJ YEE51G2MQkxPtYVVGQVQPyQhsssJwMlP/LsB8+lWnwNfc8y21gVgduEJDWLo/jtJDS 2sGJptdkbeORYCxJ+ctmtD4Kju95xPJD4lSxyfvqoemUNtpTm5wjCGiuPx0IfxATKv 60Q6KZlY9bXbgLTikk9RbalkIadd0vUlmgsxoqdwzICeOQ8xAqSnRQnQ7srJZv3M9I HfocmCims9yGw== From: Lukasz Majewski To: Eric Dumazet , Andrew Lunn , davem@davemloft.net, Paolo Abeni , Woojung Huh , Vladimir Oltean Cc: Tristram.Ha@microchip.com, Florian Fainelli , Jakub Kicinski , UNGLinuxDriver@microchip.com, George McCollister , Oleksij Rempel , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Lukasz Majewski Subject: [PATCH v2 3/4] net: dsa: hsr: Enable in KSZ9477 switch HW HSR offloading Date: Thu, 31 Aug 2023 13:18:26 +0200 Message-Id: <20230831111827.548118-4-lukma@denx.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230831111827.548118-1-lukma@denx.de> References: <20230831111827.548118-1-lukma@denx.de> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org This patch adds functions for providing in KSZ9477 switch HSR (High-availability Seamless Redundancy) hardware offloading. According to AN3474 application note following features are provided: - TX packet duplication from host to switch (NETIF_F_HW_HSR_DUP) - RX packet duplication discarding - Prevention of packet loop For last two ones - there is a probability that some packets will not be filtered in HW (in some special cases). Hence, the HSR core code shall be used to discard those not caught frames. Moreover, some switch registers adjustments are required - like setting MAC address of HSR network interface. Signed-off-by: Lukasz Majewski --- Changes for v2: - Use struct ksz_device to store hsr ports information (not struct dsa) --- drivers/net/dsa/microchip/ksz9477.c | 96 +++++++++++++++++++++++++++++ drivers/net/dsa/microchip/ksz9477.h | 4 ++ 2 files changed, 100 insertions(+) diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c index 83b7f2d5c1ea..c446eb44ead7 100644 --- a/drivers/net/dsa/microchip/ksz9477.c +++ b/drivers/net/dsa/microchip/ksz9477.c @@ -1141,6 +1141,102 @@ int ksz9477_tc_cbs_set_cinc(struct ksz_device *dev, int port, u32 val) return ksz_pwrite16(dev, port, REG_PORT_MTI_CREDIT_INCREMENT, val); } +/* The KSZ9477 provides following HW features to accelerate + * HSR frames handling: + * + * 1. TX PACKET DUPLICATION FROM HOST TO SWITCH + * 2. RX PACKET DUPLICATION DISCARDING + * 3. PREVENTING PACKET LOOP IN THE RING BY SELF-ADDRESS FILTERING + * + * Only one from point 1. has the NETIF_F* flag available. + * + * Ones from point 2 and 3 are "best effort" - i.e. those will + * work correctly most of the time, but it may happen that some + * frames will not be caught. Hence, the SW needs to handle those + * special cases. However, the speed up gain is considerable when + * above features are used. + */ +#define KSZ9477_SUPPORTED_HSR_FEATURES NETIF_F_HW_HSR_DUP + +int ksz9477_hsr_join(struct dsa_switch *ds, int port, struct net_device *hsr, + struct dsa_port *partner) +{ + struct ksz_device *dev = ds->priv; + struct net_device *slave; + u8 i, data; + int ret; + + /* Program which ports shall support HSR */ + dev->hsr_ports = BIT(port) | BIT(partner->index); + ksz_write32(dev, REG_HSR_PORT_MAP__4, dev->hsr_ports); + + /* Enable discarding of received HSR frames */ + ksz_read8(dev, REG_HSR_ALU_CTRL_0__1, &data); + data |= HSR_DUPLICATE_DISCARD; + data &= ~HSR_NODE_UNICAST; + ksz_write8(dev, REG_HSR_ALU_CTRL_0__1, data); + + /* Self MAC address filtering for HSR frames to avoid + * traverse of the HSR ring more than once. + * + * The HSR port (i.e. hsr0) MAC address is used. + */ + if (!is_valid_ether_addr(hsr->dev_addr)) { + dev_err(dev->dev, + "Set valid MAC address to %s for HSR operation!", + hsr->name); + return -EINVAL; + } + + for (i = 0; i < ETH_ALEN; i++) { + ret = ksz_write8(dev, REG_SW_MAC_ADDR_0 + i, hsr->dev_addr[i]); + if (ret) + return ret; + } + + /* Enable global self-address filtering if not yet done during switch + * start + */ + ksz_read8(dev, REG_SW_LUE_CTRL_1, &data); + if (!(data & SW_SRC_ADDR_FILTER)) { + data |= SW_SRC_ADDR_FILTER; + ksz_write8(dev, REG_SW_LUE_CTRL_1, data); + } + + /* Enable per port self-address filtering */ + ksz_port_cfg(dev, port, REG_PORT_LUE_CTRL, PORT_SRC_ADDR_FILTER, true); + ksz_port_cfg(dev, partner->index, REG_PORT_LUE_CTRL, + PORT_SRC_ADDR_FILTER, true); + + /* Setup HW supported features for lan HSR ports */ + slave = dsa_to_port(ds, port)->slave; + slave->features |= KSZ9477_SUPPORTED_HSR_FEATURES; + + slave = dsa_to_port(ds, partner->index)->slave; + slave->features |= KSZ9477_SUPPORTED_HSR_FEATURES; + + pr_debug("%s: HSR join port: %d partner: %d port_map: 0x%x\n", __func__, + port, partner->index, dev->hsr_ports); + + return 0; +} + +int ksz9477_hsr_leave(struct dsa_switch *ds, int port, struct net_device *hsr, + struct dsa_port *partner) +{ + struct ksz_device *dev = ds->priv; + + /* Clear ports HSR support */ + ksz_write32(dev, REG_HSR_PORT_MAP__4, 0); + + /* Disable per port self-address filtering */ + ksz_port_cfg(dev, port, REG_PORT_LUE_CTRL, PORT_SRC_ADDR_FILTER, false); + ksz_port_cfg(dev, partner->index, REG_PORT_LUE_CTRL, + PORT_SRC_ADDR_FILTER, false); + + return 0; +} + int ksz9477_switch_init(struct ksz_device *dev) { u8 data8; diff --git a/drivers/net/dsa/microchip/ksz9477.h b/drivers/net/dsa/microchip/ksz9477.h index b6f7e3c46e3f..634262efb73c 100644 --- a/drivers/net/dsa/microchip/ksz9477.h +++ b/drivers/net/dsa/microchip/ksz9477.h @@ -58,5 +58,9 @@ int ksz9477_dsa_init(struct ksz_device *dev); int ksz9477_switch_init(struct ksz_device *dev); void ksz9477_switch_exit(struct ksz_device *dev); void ksz9477_port_queue_split(struct ksz_device *dev, int port); +int ksz9477_hsr_join(struct dsa_switch *ds, int port, struct net_device *hsr, + struct dsa_port *partner); +int ksz9477_hsr_leave(struct dsa_switch *ds, int port, struct net_device *hsr, + struct dsa_port *partner); #endif From patchwork Thu Aug 31 11:18:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Majewski X-Patchwork-Id: 13371372 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A6C1FC2FD for ; Thu, 31 Aug 2023 11:18:55 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7441ACE4; Thu, 31 Aug 2023 04:18:54 -0700 (PDT) Received: from localhost.localdomain (85-222-111-42.dynamic.chello.pl [85.222.111.42]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: lukma@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 3097686572; Thu, 31 Aug 2023 13:18:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1693480732; bh=Oh6+2Og4JNes230QX3F+ylAvYwPth7/wlwN9Q1c/94U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FmMSDZ9mZ5CFNV1LNupGDeIr3YAF85e+bEV0ZY3P1NeODZBIm0gZP9bzOiZFqtQ+d HvoSSpTejq/HCXFbaS+lPeAJVDGlZH/95/8fW5yCvJ3m6/23a5B0QEDJzqKors/s0d JTBooF2BVyLe5LIKpfgXxNwaM2dEAt7LoKUxamkRYHud7XTEO4z57abV/z3l+6HLj0 qgRk91XE4zP2ONkiw/aRCILwcXKmc0ytdoPwhOpKNFVObBxCsfxrSqC7+3xGvMqSG4 sRVaUqPxzHgMmmyF903HDxviVI/2O28P9KdE/71K43GvI6SmP8SKUvk5qvetDqLbg6 RGcFLDQs4Jtvw== From: Lukasz Majewski To: Eric Dumazet , Andrew Lunn , davem@davemloft.net, Paolo Abeni , Woojung Huh , Vladimir Oltean Cc: Tristram.Ha@microchip.com, Florian Fainelli , Jakub Kicinski , UNGLinuxDriver@microchip.com, George McCollister , Oleksij Rempel , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Lukasz Majewski Subject: [PATCH v2 4/4] net: dsa: hsr: Provide generic HSR ksz_hsr_{join|leave} functions Date: Thu, 31 Aug 2023 13:18:27 +0200 Message-Id: <20230831111827.548118-5-lukma@denx.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230831111827.548118-1-lukma@denx.de> References: <20230831111827.548118-1-lukma@denx.de> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org This patch provides the common KSZ (i.e. Microchip) DSA code with support for HSR aware devices. To be more specific - generic ksz_hsr_{join|leave} functions are provided, now only supporting KSZ9477 IC. Signed-off-by: Lukasz Majewski --- Changes for v2: - None --- drivers/net/dsa/microchip/ksz_common.c | 69 ++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index 579fde54d1e1..853f9fe60758 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -3433,6 +3434,72 @@ u16 ksz_hsr_get_ports(struct dsa_switch *ds) return 0; } +static int ksz_hsr_join(struct dsa_switch *ds, int port, struct net_device *hsr) +{ + struct dsa_port *partner = NULL, *dp; + struct ksz_device *dev = ds->priv; + enum hsr_version ver; + int ret; + + ret = hsr_get_version(hsr, &ver); + if (ret) + return ret; + + switch (dev->chip_id) { + case KSZ9477_CHIP_ID: + if (ver == PRP_V1) + return -EOPNOTSUPP; + } + + /* We can't enable redundancy on the switch until both + * redundant ports have signed up. + */ + dsa_hsr_foreach_port(dp, ds, hsr) { + if (dp->index != port) { + partner = dp; + break; + } + } + + if (!partner) + return 0; + + switch (dev->chip_id) { + case KSZ9477_CHIP_ID: + return ksz9477_hsr_join(ds, port, hsr, partner); + default: + return -EOPNOTSUPP; + } + + return 0; +} + +static int ksz_hsr_leave(struct dsa_switch *ds, int port, + struct net_device *hsr) +{ + struct dsa_port *partner = NULL, *dp; + struct ksz_device *dev = ds->priv; + + dsa_hsr_foreach_port(dp, ds, hsr) { + if (dp->index != port) { + partner = dp; + break; + } + } + + if (!partner) + return 0; + + switch (dev->chip_id) { + case KSZ9477_CHIP_ID: + return ksz9477_hsr_leave(ds, port, hsr, partner); + default: + return -EOPNOTSUPP; + } + + return 0; +} + static const struct dsa_switch_ops ksz_switch_ops = { .get_tag_protocol = ksz_get_tag_protocol, .connect_tag_protocol = ksz_connect_tag_protocol, @@ -3452,6 +3519,8 @@ static const struct dsa_switch_ops ksz_switch_ops = { .get_sset_count = ksz_sset_count, .port_bridge_join = ksz_port_bridge_join, .port_bridge_leave = ksz_port_bridge_leave, + .port_hsr_join = ksz_hsr_join, + .port_hsr_leave = ksz_hsr_leave, .port_stp_state_set = ksz_port_stp_state_set, .port_pre_bridge_flags = ksz_port_pre_bridge_flags, .port_bridge_flags = ksz_port_bridge_flags,