From nobody Wed Apr 29 09:34:37 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE500C433EF for ; Wed, 15 Jun 2022 22:51:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350550AbiFOWvf (ORCPT ); Wed, 15 Jun 2022 18:51:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350414AbiFOWvb (ORCPT ); Wed, 15 Jun 2022 18:51:31 -0400 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E12F856406 for ; Wed, 15 Jun 2022 15:51:29 -0700 (PDT) Received: by mail-ej1-x632.google.com with SMTP id fu3so25973143ejc.7 for ; Wed, 15 Jun 2022 15:51:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pqrs.dk; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zSzdOiSgxbYWZxXEulfQBrTFa8jqymfNEasGrW3oI+Y=; b=nDXpbxcKOzdVuZicNv5F2+PRhUSKEiINNs+eqhsd5039Cf3uczSQdHcn4hMpLr4htN SPlUe96Ie4d9UdpdL2WOFshK1RHGhks1LECgZ7ivssvVm4ToWloOeGjfchBmf54yC7ru Ic6ZF59aeggWbCSv2XJB1bDtiToDd72Z+x1Vw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zSzdOiSgxbYWZxXEulfQBrTFa8jqymfNEasGrW3oI+Y=; b=2TUGsUmzOk8/8grleEjtA4PWzL1u9jOkyXZHFrYhCAmBdUXHksfZcgqJxK9TVh2FDT y91vKS/bUEgfpTpq/uZxkW9YhyoqFvOcZHCOVO6cmaWUrxr9J6TEQVg6PGNqGhYzkh36 n3hMr7/vQrWCqTN6iua/yM0eiy7dkA2ea6Tw5Zm2xqflJNW6FE/zqMUaSjysGTJST9+l gt/3I2ov+R7T8rwpZzIPifOtdacxr6emrh+nHGKFfo9QbssySzAwkcM6TqmLIvwtCvd1 Pk0hIBZ+HIWj+AjquTG457zmw/cy81c2gyL48GWtlCNAWSUdgWHfkXhYgg1DIs+FlAkz Hu2A== X-Gm-Message-State: AJIora+ya3wwkneOPClkoHJiUyHM29zlqMiAhk2QZjMK06TbW2rK1Q26 7e6M3i/AoCzSgeVal/UdujfDJQ== X-Google-Smtp-Source: AGRyM1sBIJM4d9dE6NYu3F+YuovSCF3q2IZg6I4e2Aisjkqd1z3WeHXXoOP6pexfDH644qGlWTEhjA== X-Received: by 2002:a17:906:9b86:b0:6f8:24e7:af7d with SMTP id dd6-20020a1709069b8600b006f824e7af7dmr1966601ejc.295.1655333488459; Wed, 15 Jun 2022 15:51:28 -0700 (PDT) Received: from localhost.localdomain (80.71.142.18.ipv4.parknet.dk. [80.71.142.18]) by smtp.gmail.com with ESMTPSA id h23-20020aa7c617000000b0042e21f8c412sm371506edq.42.2022.06.15.15.51.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jun 2022 15:51:28 -0700 (PDT) From: =?UTF-8?q?Alvin=20=C5=A0ipraga?= To: hauke@hauke-m.de, Linus Walleij , =?UTF-8?q?Alvin=20=C5=A0ipraga?= , Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Russell King Cc: Luiz Angelo Daros de Luca , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v3 1/5] net: dsa: realtek: rtl8365mb: rename macro RTL8367RB -> RTL8367RB_VB Date: Thu, 16 Jun 2022 00:51:11 +0200 Message-Id: <20220615225116.432283-2-alvin@pqrs.dk> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220615225116.432283-1-alvin@pqrs.dk> References: <20220615225116.432283-1-alvin@pqrs.dk> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alvin =C5=A0ipraga The official name of this switch is RTL8367RB-VB, not RTL8367RB. There is also an RTL8367RB-VC which is rather different. Change the name of the CHIP_ID/_VER macros for reasons of consistency. Signed-off-by: Alvin =C5=A0ipraga Reviewed-by: Luiz Angelo Daros de Luca --- drivers/net/dsa/realtek/rtl8365mb.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/dsa/realtek/rtl8365mb.c b/drivers/net/dsa/realtek/= rtl8365mb.c index 769f672e9128..905056250b88 100644 --- a/drivers/net/dsa/realtek/rtl8365mb.c +++ b/drivers/net/dsa/realtek/rtl8365mb.c @@ -108,8 +108,8 @@ #define RTL8365MB_CHIP_ID_8367S 0x6367 #define RTL8365MB_CHIP_VER_8367S 0x00A0 =20 -#define RTL8365MB_CHIP_ID_8367RB 0x6367 -#define RTL8365MB_CHIP_VER_8367RB 0x0020 +#define RTL8365MB_CHIP_ID_8367RB_VB 0x6367 +#define RTL8365MB_CHIP_VER_8367RB_VB 0x0020 =20 /* Family-specific data and limits */ #define RTL8365MB_PHYADDRMAX 7 @@ -1988,7 +1988,7 @@ static int rtl8365mb_detect(struct realtek_priv *priv) "found an RTL8365MB-VC switch (ver=3D0x%04x)\n", chip_ver); break; - case RTL8365MB_CHIP_VER_8367RB: + case RTL8365MB_CHIP_VER_8367RB_VB: dev_info(priv->dev, "found an RTL8367RB-VB switch (ver=3D0x%04x)\n", chip_ver); --=20 2.36.1 From nobody Wed Apr 29 09:34:37 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 751F1C43334 for ; Wed, 15 Jun 2022 22:51:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350567AbiFOWvh (ORCPT ); Wed, 15 Jun 2022 18:51:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350488AbiFOWvc (ORCPT ); Wed, 15 Jun 2022 18:51:32 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66D8D56406 for ; Wed, 15 Jun 2022 15:51:31 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id s12so26019591ejx.3 for ; Wed, 15 Jun 2022 15:51:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pqrs.dk; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XE/B3EfYYQf1mtimqgsF3ZVDA9bOVjSyLpITpl2gz98=; b=CAAN8l3+EJB/bqURL9Y6xhpSqAw97LvZavrZ6FBByM//joPRSbkhGQni6zU6ykVcWk 4ciGFpFoSsXg5m0xStFX/r9KVDJNckeOxtYXIxLFcx293locPU+LaIOSlYfBiYFdsEwm JqXoAAKaq2ZL7MYjGEDKtEfn5K9G9HV7PDONM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XE/B3EfYYQf1mtimqgsF3ZVDA9bOVjSyLpITpl2gz98=; b=66bjCqwTMbtxrDCUe4mNql/S5bL88UA4m2D8DOL0iiSHXdowHBKGOkEozwY1FmXcxS VrMlfz4+4QEsguovgv2h5k4XLzknXOVqJ7QveiWetB0OLoopXspLYIvxP272ONqOJiMe KJhdpX56A8cYQd/dlu/HJQzZVJikdhZBpCiCNOarHboK+uQhG+CviY763mO4qFDI0+FK mObc/wnOm9u0KvaAVlPjPUPzQ+lnyjmgCD3kKaQtj43D9xu59KHHEE9Effg8Y5hainMt 4rRqdZdydAxpLDqz/cB4ijVu9RIU3SIK05J+UFj0uYeN+JLPIeVgomOkGw2Iy889Ou99 mlvQ== X-Gm-Message-State: AJIora+EEECPDMFMLgy5XzyaTEJG9aZhoQ9eEg3SWvSl1sc7iMWG4qLL kyK7WxazvKxxCGd85dFoqfIEWw== X-Google-Smtp-Source: AGRyM1u/n8oPQZ/PAaY1yIz7bNcJISipoi7XTrNBfYUp8Pz+3ypt2FpQLPAsoP+rXtgzLQ2+TCYh7w== X-Received: by 2002:a17:906:a858:b0:70e:a4d8:1c45 with SMTP id dx24-20020a170906a85800b0070ea4d81c45mr1821800ejb.213.1655333489994; Wed, 15 Jun 2022 15:51:29 -0700 (PDT) Received: from localhost.localdomain (80.71.142.18.ipv4.parknet.dk. [80.71.142.18]) by smtp.gmail.com with ESMTPSA id h23-20020aa7c617000000b0042e21f8c412sm371506edq.42.2022.06.15.15.51.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jun 2022 15:51:29 -0700 (PDT) From: =?UTF-8?q?Alvin=20=C5=A0ipraga?= To: hauke@hauke-m.de, Linus Walleij , =?UTF-8?q?Alvin=20=C5=A0ipraga?= , Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Russell King Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v3 2/5] net: dsa: realtek: rtl8365mb: remove port_mask private data member Date: Thu, 16 Jun 2022 00:51:12 +0200 Message-Id: <20220615225116.432283-3-alvin@pqrs.dk> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220615225116.432283-1-alvin@pqrs.dk> References: <20220615225116.432283-1-alvin@pqrs.dk> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alvin =C5=A0ipraga There is no real need for this variable: the line change interrupt mask is sufficiently masked out when getting linkup_ind and linkdown_ind in the interrupt handler. Signed-off-by: Alvin =C5=A0ipraga --- drivers/net/dsa/realtek/rtl8365mb.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/drivers/net/dsa/realtek/rtl8365mb.c b/drivers/net/dsa/realtek/= rtl8365mb.c index 905056250b88..42afba122bb4 100644 --- a/drivers/net/dsa/realtek/rtl8365mb.c +++ b/drivers/net/dsa/realtek/rtl8365mb.c @@ -564,7 +564,6 @@ struct rtl8365mb_port { * @irq: registered IRQ or zero * @chip_id: chip identifier * @chip_ver: chip silicon revision - * @port_mask: mask of all ports * @learn_limit_max: maximum number of L2 addresses the chip can learn * @cpu: CPU tagging and CPU port configuration for this chip * @mib_lock: prevent concurrent reads of MIB counters @@ -579,7 +578,6 @@ struct rtl8365mb { int irq; u32 chip_id; u32 chip_ver; - u32 port_mask; u32 learn_limit_max; struct rtl8365mb_cpu cpu; struct mutex mib_lock; @@ -1489,13 +1487,10 @@ static irqreturn_t rtl8365mb_irq(int irq, void *dat= a) { struct realtek_priv *priv =3D data; unsigned long line_changes =3D 0; - struct rtl8365mb *mb; u32 stat; int line; int ret; =20 - mb =3D priv->chip_data; - ret =3D rtl8365mb_get_and_clear_status_reg(priv, RTL8365MB_INTR_STATUS_RE= G, &stat); if (ret) @@ -1520,7 +1515,7 @@ static irqreturn_t rtl8365mb_irq(int irq, void *data) =20 linkdown_ind =3D FIELD_GET(RTL8365MB_PORT_LINKDOWN_IND_MASK, val); =20 - line_changes =3D (linkup_ind | linkdown_ind) & mb->port_mask; + line_changes =3D linkup_ind | linkdown_ind; } =20 if (!line_changes) @@ -2009,7 +2004,6 @@ static int rtl8365mb_detect(struct realtek_priv *priv) mb->priv =3D priv; mb->chip_id =3D chip_id; mb->chip_ver =3D chip_ver; - mb->port_mask =3D GENMASK(priv->num_ports - 1, 0); mb->learn_limit_max =3D RTL8365MB_LEARN_LIMIT_MAX; mb->jam_table =3D rtl8365mb_init_jam_8365mb_vc; mb->jam_size =3D ARRAY_SIZE(rtl8365mb_init_jam_8365mb_vc); --=20 2.36.1 From nobody Wed Apr 29 09:34:37 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA9C2C43334 for ; Wed, 15 Jun 2022 22:51:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350744AbiFOWvu (ORCPT ); Wed, 15 Jun 2022 18:51:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350522AbiFOWve (ORCPT ); Wed, 15 Jun 2022 18:51:34 -0400 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 417A456415 for ; Wed, 15 Jun 2022 15:51:33 -0700 (PDT) Received: by mail-ej1-x62a.google.com with SMTP id h23so25963211ejj.12 for ; Wed, 15 Jun 2022 15:51:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pqrs.dk; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TXmIOiKtTji5uvqDZkSqwPGXddUogZT+Gvmhu7MqhdQ=; b=TVX+jPHr+YurZEbSw2Ju/dlh1M5+C97k4A0sYp5OVJWanDOEuDVOa2EkHzN0A691PZ zjKbKTLHR7zaQMlMlZjakkTU14oQrFsnCdc5FAgUSIFyIObWrSoZlMkZ/eSHxta2gMqv Swc43qGqkkf5kbOiQRF5nZe772+0zdPb7I46w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TXmIOiKtTji5uvqDZkSqwPGXddUogZT+Gvmhu7MqhdQ=; b=8KroqiekP+v0s9xNtHeX9vJe0m62vkwNisSol8bcgiHP0lcDbl1TJvt68SGA4DW3Qg BdV+Iaug0GFS1tTt+HI4Bk17Z2PSM+MgC+6CVP5bHwZ3z9PsbgldIvIC2Kyk1yaCPUvw jDjNEZaPM7bC2bEvbSPyapKR3h0sKHn8zDw/3SU4vCTzP4yBU+AmhgD2rkT/tmk1f3v7 pe9AQAby55V94lIFlH6OumUxtIXugk1HZTEf69v4m2uMQRx57aY1v/V1FB2Q5sOZE4tN aD1S+lm7bEUpUpFnQrGIgeWU3C1QZm6nHv7/r//e3885Vr6I73LuNqd1dR/kYEh9fB+S b2rw== X-Gm-Message-State: AJIora+S8cXVAptijIs/h1PnoX5jtqpFXtptvJ+w+K6BRXeOib7gtTTB 9ON2CKEwFaYPX8OgTI5j+ZgxHw== X-Google-Smtp-Source: AGRyM1vHmr4I+TxgXhv9ooyE28pTt2qO4gU18bLAATZW0N6FanBovvFpzj2orl0lAgxZ2YZxhMHg7g== X-Received: by 2002:a17:907:86ac:b0:708:9c4a:c6e9 with SMTP id qa44-20020a17090786ac00b007089c4ac6e9mr1881699ejc.297.1655333491875; Wed, 15 Jun 2022 15:51:31 -0700 (PDT) Received: from localhost.localdomain (80.71.142.18.ipv4.parknet.dk. [80.71.142.18]) by smtp.gmail.com with ESMTPSA id h23-20020aa7c617000000b0042e21f8c412sm371506edq.42.2022.06.15.15.51.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jun 2022 15:51:31 -0700 (PDT) From: =?UTF-8?q?Alvin=20=C5=A0ipraga?= To: hauke@hauke-m.de, Linus Walleij , =?UTF-8?q?Alvin=20=C5=A0ipraga?= , Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Russell King Cc: Luiz Angelo Daros de Luca , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v3 3/5] net: dsa: realtek: rtl8365mb: correct the max number of ports Date: Thu, 16 Jun 2022 00:51:13 +0200 Message-Id: <20220615225116.432283-4-alvin@pqrs.dk> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220615225116.432283-1-alvin@pqrs.dk> References: <20220615225116.432283-1-alvin@pqrs.dk> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alvin =C5=A0ipraga The maximum number of ports is actually 11, according to two observations: 1. The highest port ID used in the vendor driver is 10. Since port IDs are indexed from 0, and since DSA follows the same numbering system, this means up to 11 ports are to be presumed. 2. The registers with port mask fields always amount to a maximum port mask of 0x7FF, corresponding to a maximum 11 ports. In view of this, I also deleted the comment. Signed-off-by: Alvin =C5=A0ipraga Reviewed-by: Luiz Angelo Daros de Luca --- drivers/net/dsa/realtek/rtl8365mb.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/net/dsa/realtek/rtl8365mb.c b/drivers/net/dsa/realtek/= rtl8365mb.c index 42afba122bb4..3599fa5d9f14 100644 --- a/drivers/net/dsa/realtek/rtl8365mb.c +++ b/drivers/net/dsa/realtek/rtl8365mb.c @@ -115,8 +115,7 @@ #define RTL8365MB_PHYADDRMAX 7 #define RTL8365MB_NUM_PHYREGS 32 #define RTL8365MB_PHYREGMAX (RTL8365MB_NUM_PHYREGS - 1) -/* RTL8370MB and RTL8310SR, possibly suportable by this driver, have 10 po= rts */ -#define RTL8365MB_MAX_NUM_PORTS 10 +#define RTL8365MB_MAX_NUM_PORTS 11 #define RTL8365MB_LEARN_LIMIT_MAX 2112 =20 /* valid for all 6-port or less variants */ --=20 2.36.1 From nobody Wed Apr 29 09:34:37 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65A8AC433EF for ; Wed, 15 Jun 2022 22:51:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350706AbiFOWvq (ORCPT ); Wed, 15 Jun 2022 18:51:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350488AbiFOWvi (ORCPT ); Wed, 15 Jun 2022 18:51:38 -0400 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C7555641D for ; Wed, 15 Jun 2022 15:51:35 -0700 (PDT) Received: by mail-ed1-x533.google.com with SMTP id cn20so5816817edb.6 for ; Wed, 15 Jun 2022 15:51:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pqrs.dk; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AareH3Xp+hp4A5FOtY4uNivgTY9OEK29GzGPxmxFOws=; b=kJzpPcYmcX7GoYd5tKK+ollj2PRhF8lAkiyS3JW/xsbBypPJ1S6pWA7AwYOH4o1NNk TxuMrtWli9kiluVbcbl0Si+CK0BVPyD7C/b4zxvVTjOe1bm7iLzSbYQ+c/ZealIYX91u 2BfBxNLumPg8ZjKobTSfjtIDMh1WL/1QFD7hM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AareH3Xp+hp4A5FOtY4uNivgTY9OEK29GzGPxmxFOws=; b=5MCDlX907o3iD9zcFEeM8zQJiUqWjMsbFAq9mhfCVoxazSxM7j+nSKhz9/2sHB1oaJ i7JvT8zm27cvxV04ur60CZA4FNpGKRm48ReE0PWyKPzKcDFMqE3rYsvUSfs8zu/OtVb6 3l8YAMvLY2IPLoWjR4j3Oao71fdUkg412LzM3ZBG1V5sQMxk2xLW3yypw//0yz2CuNNi oGZGmxnPYo8LQoXYurcSJMtfk66Ia44Q8doR2I/nAjjCLu6oH3pnMb0gIp5Q+PpKOFh2 nRSUgBVgdRJaByNkLzLqW1pTSwmn4gVwSvLuH+6ALWa139jx7hAC0pBRMz79kCl6PmPi 9Bug== X-Gm-Message-State: AJIora8yXEnIAU9lo3Kb+NmkhXx5X2+S4KKx+khfN5POVPBKRQIWz7kt 4F3stuM/0Pf6p/RrID+Gy70p9A== X-Google-Smtp-Source: AGRyM1s8HNefBTr6EzDUrhiYqbINKuXkV+4Hc+kGEYoKgOE1r08kg/gFh3kyeRMAURVZ7aQz2TD0vA== X-Received: by 2002:a05:6402:329b:b0:431:3143:5ced with SMTP id f27-20020a056402329b00b0043131435cedmr2648926eda.257.1655333493599; Wed, 15 Jun 2022 15:51:33 -0700 (PDT) Received: from localhost.localdomain (80.71.142.18.ipv4.parknet.dk. [80.71.142.18]) by smtp.gmail.com with ESMTPSA id h23-20020aa7c617000000b0042e21f8c412sm371506edq.42.2022.06.15.15.51.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jun 2022 15:51:33 -0700 (PDT) From: =?UTF-8?q?Alvin=20=C5=A0ipraga?= To: hauke@hauke-m.de, Linus Walleij , =?UTF-8?q?Alvin=20=C5=A0ipraga?= , Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Russell King Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v3 4/5] net: dsa: realtek: rtl8365mb: remove learn_limit_max private data member Date: Thu, 16 Jun 2022 00:51:14 +0200 Message-Id: <20220615225116.432283-5-alvin@pqrs.dk> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220615225116.432283-1-alvin@pqrs.dk> References: <20220615225116.432283-1-alvin@pqrs.dk> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alvin =C5=A0ipraga The variable is just assigned the value of a macro, so it can be removed. Signed-off-by: Alvin =C5=A0ipraga --- drivers/net/dsa/realtek/rtl8365mb.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/drivers/net/dsa/realtek/rtl8365mb.c b/drivers/net/dsa/realtek/= rtl8365mb.c index 3599fa5d9f14..676b88798976 100644 --- a/drivers/net/dsa/realtek/rtl8365mb.c +++ b/drivers/net/dsa/realtek/rtl8365mb.c @@ -563,7 +563,6 @@ struct rtl8365mb_port { * @irq: registered IRQ or zero * @chip_id: chip identifier * @chip_ver: chip silicon revision - * @learn_limit_max: maximum number of L2 addresses the chip can learn * @cpu: CPU tagging and CPU port configuration for this chip * @mib_lock: prevent concurrent reads of MIB counters * @ports: per-port data @@ -577,7 +576,6 @@ struct rtl8365mb { int irq; u32 chip_id; u32 chip_ver; - u32 learn_limit_max; struct rtl8365mb_cpu cpu; struct mutex mib_lock; struct rtl8365mb_port ports[RTL8365MB_MAX_NUM_PORTS]; @@ -1088,15 +1086,13 @@ static void rtl8365mb_port_stp_state_set(struct dsa= _switch *ds, int port, static int rtl8365mb_port_set_learning(struct realtek_priv *priv, int port, bool enable) { - struct rtl8365mb *mb =3D priv->chip_data; - /* Enable/disable learning by limiting the number of L2 addresses the * port can learn. Realtek documentation states that a limit of zero * disables learning. When enabling learning, set it to the chip's * maximum. */ return regmap_write(priv->map, RTL8365MB_LUT_PORT_LEARN_LIMIT_REG(port), - enable ? mb->learn_limit_max : 0); + enable ? RTL8365MB_LEARN_LIMIT_MAX : 0); } =20 static int rtl8365mb_port_set_isolation(struct realtek_priv *priv, int por= t, @@ -2003,7 +1999,6 @@ static int rtl8365mb_detect(struct realtek_priv *priv) mb->priv =3D priv; mb->chip_id =3D chip_id; mb->chip_ver =3D chip_ver; - mb->learn_limit_max =3D RTL8365MB_LEARN_LIMIT_MAX; mb->jam_table =3D rtl8365mb_init_jam_8365mb_vc; mb->jam_size =3D ARRAY_SIZE(rtl8365mb_init_jam_8365mb_vc); =20 --=20 2.36.1 From nobody Wed Apr 29 09:34:37 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3199CC43334 for ; Wed, 15 Jun 2022 22:51:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242547AbiFOWvy (ORCPT ); Wed, 15 Jun 2022 18:51:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350577AbiFOWvj (ORCPT ); Wed, 15 Jun 2022 18:51:39 -0400 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EAA755641E for ; Wed, 15 Jun 2022 15:51:35 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id b8so18189367edj.11 for ; Wed, 15 Jun 2022 15:51:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pqrs.dk; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Hx00/hdrDXBVs5C/Pg+IROj7Mt3zwGokoCBJ8UG16pY=; b=DTFRNZMe7VJ5epr6PgTnqf54EJPwI1NOtleDwLO/DjjvR8QAP1BvYI4Rt0j93MZvCu UCycQCSYmIWQrHeReaJtYEpaCtOHyEd241rPwgqoirnvtmqpth2uaW0eSG5YBkqDoRTn X8d4evudSMLmmgnNheDHSPAHyeHptE4hl8ZOM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Hx00/hdrDXBVs5C/Pg+IROj7Mt3zwGokoCBJ8UG16pY=; b=j2aWusPN+cs+idlB0P3eex+mSsDBogHlSc0RBo84VJt4xa2snNnG2Zr4e6oxDQhqh0 VvBlvwMp9GttXGFQhiCDWQIwM9R15RtSPvYZGBbxvilsdRCIZA97j6aepWd1cYqRjaQl MF7Vdwgvnux33g/La+h3dHu7ovqAQGXAeVN9qFZosNvp4YK8+jb/71ucohdyXhTSrp0I XMoVxtiWRTdGGXQ4QmJNyl1sztaPjhSyPmYdftaPSSyN8+1P3hbf+RCV4wiXuUaqzfcp AVFzwLBh6zRojlxKJT3gEGEQ5Uq/sH2fH/0W3I5AV32AmNcgltEUmmGE2UxM+SXA4VxC W3zw== X-Gm-Message-State: AJIora9X364Mm0dLsbYFwe6tsa78OJ7tpHPaW7roVi026qZlxM/UQWjD JUqWsIMkhc77tfQo4oSi0Is1Mg== X-Google-Smtp-Source: AGRyM1vY4e862TUTG6at0EFYdkLoQR84x4qgHe5h6zlqIXnh/0yu4HNHM9GoX0da7ErgXUiXD6TSJg== X-Received: by 2002:a05:6402:3046:b0:42e:fee1:c2dd with SMTP id bs6-20020a056402304600b0042efee1c2ddmr2686709edb.29.1655333495409; Wed, 15 Jun 2022 15:51:35 -0700 (PDT) Received: from localhost.localdomain (80.71.142.18.ipv4.parknet.dk. [80.71.142.18]) by smtp.gmail.com with ESMTPSA id h23-20020aa7c617000000b0042e21f8c412sm371506edq.42.2022.06.15.15.51.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jun 2022 15:51:34 -0700 (PDT) From: =?UTF-8?q?Alvin=20=C5=A0ipraga?= To: hauke@hauke-m.de, Linus Walleij , =?UTF-8?q?Alvin=20=C5=A0ipraga?= , Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Russell King Cc: Russell King , Luiz Angelo Daros de Luca , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v3 5/5] net: dsa: realtek: rtl8365mb: handle PHY interface modes correctly Date: Thu, 16 Jun 2022 00:51:15 +0200 Message-Id: <20220615225116.432283-6-alvin@pqrs.dk> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220615225116.432283-1-alvin@pqrs.dk> References: <20220615225116.432283-1-alvin@pqrs.dk> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alvin =C5=A0ipraga Realtek switches in the rtl8365mb family always have at least one port with a so-called external interface, supporting PHY interface modes such as RGMII or SGMII. The purpose of this patch is to improve the driver's handling of these ports. A new struct rtl8365mb_chip_info is introduced together with a static array of such structs. An instance of this struct is added for each supported switch, distinguished by its chip ID and version. Embedded in each chip_info struct is an array of struct rtl8365mb_extint, describing the external interfaces available. This is more specific than the old rtl8365mb_extint_port_map, which was only valid for switches with up to 6 ports. The struct rtl8365mb_extint also contains a bitmask of supported PHY interface modes, which allows the driver to distinguish which ports support RGMII. This corrects a previous mistake in the driver whereby it was assumed that any port with an external interface supports RGMII. This is not actually the case: for example, the RTL8367S has two external interfaces, only the second of which supports RGMII. The first supports only SGMII and HSGMII. This new design will make it easier to add support for other interface modes. Finally, rtl8365mb_phylink_get_caps() is fixed up to return supported capabilities based on the external interface properties described above. This addresses Vladimir's point in the linked thread that the capabilities are not actually a function of the DSA port type: Although most typical applications will treat the ports with internal PHY as user ports, there is no actual hardware limitation preventing one from using them as a CPU port. Equally, ports with external interface(s) may well be treated as user ports, even though it is typical to use those ports as CPU ports. Link: https://lore.kernel.org/netdev/20220510192301.5djdt3ghoavxulhl@bang-o= lufsen.dk/ Signed-off-by: Alvin =C5=A0ipraga Acked-by: Russell King (Oracle) Acked-by: Luiz Angelo Daros de Luca --- drivers/net/dsa/realtek/rtl8365mb.c | 281 +++++++++++++++++----------- 1 file changed, 174 insertions(+), 107 deletions(-) diff --git a/drivers/net/dsa/realtek/rtl8365mb.c b/drivers/net/dsa/realtek/= rtl8365mb.c index 676b88798976..da31d8b839ac 100644 --- a/drivers/net/dsa/realtek/rtl8365mb.c +++ b/drivers/net/dsa/realtek/rtl8365mb.c @@ -101,26 +101,14 @@ =20 #include "realtek.h" =20 -/* Chip-specific data and limits */ -#define RTL8365MB_CHIP_ID_8365MB_VC 0x6367 -#define RTL8365MB_CHIP_VER_8365MB_VC 0x0040 - -#define RTL8365MB_CHIP_ID_8367S 0x6367 -#define RTL8365MB_CHIP_VER_8367S 0x00A0 - -#define RTL8365MB_CHIP_ID_8367RB_VB 0x6367 -#define RTL8365MB_CHIP_VER_8367RB_VB 0x0020 - /* Family-specific data and limits */ #define RTL8365MB_PHYADDRMAX 7 #define RTL8365MB_NUM_PHYREGS 32 #define RTL8365MB_PHYREGMAX (RTL8365MB_NUM_PHYREGS - 1) #define RTL8365MB_MAX_NUM_PORTS 11 +#define RTL8365MB_MAX_NUM_EXTINTS 3 #define RTL8365MB_LEARN_LIMIT_MAX 2112 =20 -/* valid for all 6-port or less variants */ -static const int rtl8365mb_extint_port_map[] =3D { -1, -1, -1, -1, -1, -1= , 1, 2, -1, -1}; - /* Chip identification registers */ #define RTL8365MB_CHIP_ID_REG 0x1300 =20 @@ -200,7 +188,7 @@ static const int rtl8365mb_extint_port_map[] =3D { -1,= -1, -1, -1, -1, -1, 1, 2, /* The PHY OCP addresses of PHY registers 0~31 start here */ #define RTL8365MB_PHY_OCP_ADDR_PHYREG_BASE 0xA400 =20 -/* EXT interface port mode values - used in DIGITAL_INTERFACE_SELECT */ +/* External interface port mode values - used in DIGITAL_INTERFACE_SELECT = */ #define RTL8365MB_EXT_PORT_MODE_DISABLE 0 #define RTL8365MB_EXT_PORT_MODE_RGMII 1 #define RTL8365MB_EXT_PORT_MODE_MII_MAC 2 @@ -216,19 +204,7 @@ static const int rtl8365mb_extint_port_map[] =3D { -1= , -1, -1, -1, -1, -1, 1, 2, #define RTL8365MB_EXT_PORT_MODE_1000X 12 #define RTL8365MB_EXT_PORT_MODE_100FX 13 =20 -/* Realtek docs and driver uses logic number as EXT_PORT0=3D16, EXT_PORT1= =3D17, - * EXT_PORT2=3D18, to interact with switch ports. That logic number is int= ernally - * converted to either a physical port number (0..9) or an external interf= ace id (0..2), - * depending on which function was called. The external interface id is ca= lculated as - * (ext_id=3Dlogic_port-15), while the logical to physical map depends on = the chip id/version. - * - * EXT_PORT0 mentioned in datasheets and rtl8367c driver is used in this d= river - * as extid=3D=3D1, EXT_PORT2, mentioned in Realtek rtl8367c driver for 10= -port switches, - * would have an ext_id of 3 (out of range for most extint macros) and ext= _id 0 does - * not seem to be used as well for this family. - */ - -/* EXT interface mode configuration registers 0~1 */ +/* External interface mode configuration registers 0~1 */ #define RTL8365MB_DIGITAL_INTERFACE_SELECT_REG0 0x1305 /* EXT1 */ #define RTL8365MB_DIGITAL_INTERFACE_SELECT_REG1 0x13C3 /* EXT2 */ #define RTL8365MB_DIGITAL_INTERFACE_SELECT_REG(_extint) \ @@ -240,7 +216,7 @@ static const int rtl8365mb_extint_port_map[] =3D { -1,= -1, -1, -1, -1, -1, 1, 2, #define RTL8365MB_DIGITAL_INTERFACE_SELECT_MODE_OFFSET(_extint) \ (((_extint) % 2) * 4) =20 -/* EXT interface RGMII TX/RX delay configuration registers 0~2 */ +/* External interface RGMII TX/RX delay configuration registers 0~2 */ #define RTL8365MB_EXT_RGMXF_REG0 0x1306 /* EXT0 */ #define RTL8365MB_EXT_RGMXF_REG1 0x1307 /* EXT1 */ #define RTL8365MB_EXT_RGMXF_REG2 0x13C5 /* EXT2 */ @@ -257,7 +233,7 @@ static const int rtl8365mb_extint_port_map[] =3D { -1,= -1, -1, -1, -1, -1, 1, 2, #define RTL8365MB_PORT_SPEED_100M 1 #define RTL8365MB_PORT_SPEED_1000M 2 =20 -/* EXT interface force configuration registers 0~2 */ +/* External interface force configuration registers 0~2 */ #define RTL8365MB_DIGITAL_INTERFACE_FORCE_REG0 0x1310 /* EXT0 */ #define RTL8365MB_DIGITAL_INTERFACE_FORCE_REG1 0x1311 /* EXT1 */ #define RTL8365MB_DIGITAL_INTERFACE_FORCE_REG2 0x13C4 /* EXT2 */ @@ -489,6 +465,95 @@ static const struct rtl8365mb_jam_tbl_entry rtl8365mb_= init_jam_common[] =3D { { 0x1D32, 0x0002 }, }; =20 +enum rtl8365mb_phy_interface_mode { + RTL8365MB_PHY_INTERFACE_MODE_INVAL =3D 0, + RTL8365MB_PHY_INTERFACE_MODE_INTERNAL =3D BIT(0), + RTL8365MB_PHY_INTERFACE_MODE_MII =3D BIT(1), + RTL8365MB_PHY_INTERFACE_MODE_TMII =3D BIT(2), + RTL8365MB_PHY_INTERFACE_MODE_RMII =3D BIT(3), + RTL8365MB_PHY_INTERFACE_MODE_RGMII =3D BIT(4), + RTL8365MB_PHY_INTERFACE_MODE_SGMII =3D BIT(5), + RTL8365MB_PHY_INTERFACE_MODE_HSGMII =3D BIT(6), +}; + +/** + * struct rtl8365mb_extint - external interface info + * @port: the port with an external interface + * @id: the external interface ID, which is either 0, 1, or 2 + * @supported_interfaces: a bitmask of supported PHY interface modes + * + * Represents a mapping: port -> { id, supported_interfaces }. To be embed= ded + * in &struct rtl8365mb_chip_info for every port with an external interfac= e. + */ +struct rtl8365mb_extint { + int port; + int id; + unsigned int supported_interfaces; +}; + +/** + * struct rtl8365mb_chip_info - static chip-specific info + * @name: human-readable chip name + * @chip_id: chip identifier + * @chip_ver: chip silicon revision + * @extints: available external interfaces + * @jam_table: chip-specific initialization jam table + * @jam_size: size of the chip's jam table + * + * These data are specific to a given chip in the family of switches suppo= rted + * by this driver. When adding support for another chip in the family, a n= ew + * chip info should be added to the rtl8365mb_chip_infos array. + */ +struct rtl8365mb_chip_info { + const char *name; + u32 chip_id; + u32 chip_ver; + const struct rtl8365mb_extint extints[RTL8365MB_MAX_NUM_EXTINTS]; + const struct rtl8365mb_jam_tbl_entry *jam_table; + size_t jam_size; +}; + +/* Chip info for each supported switch in the family */ +#define PHY_INTF(_mode) (RTL8365MB_PHY_INTERFACE_MODE_ ## _mode) +static const struct rtl8365mb_chip_info rtl8365mb_chip_infos[] =3D { + { + .name =3D "RTL8365MB-VC", + .chip_id =3D 0x6367, + .chip_ver =3D 0x0040, + .extints =3D { + { 6, 1, PHY_INTF(MII) | PHY_INTF(TMII) | + PHY_INTF(RMII) | PHY_INTF(RGMII) }, + }, + .jam_table =3D rtl8365mb_init_jam_8365mb_vc, + .jam_size =3D ARRAY_SIZE(rtl8365mb_init_jam_8365mb_vc), + }, + { + .name =3D "RTL8367S", + .chip_id =3D 0x6367, + .chip_ver =3D 0x00A0, + .extints =3D { + { 6, 1, PHY_INTF(SGMII) | PHY_INTF(HSGMII) }, + { 7, 2, PHY_INTF(MII) | PHY_INTF(TMII) | + PHY_INTF(RMII) | PHY_INTF(RGMII) }, + }, + .jam_table =3D rtl8365mb_init_jam_8365mb_vc, + .jam_size =3D ARRAY_SIZE(rtl8365mb_init_jam_8365mb_vc), + }, + { + .name =3D "RTL8367RB-VB", + .chip_id =3D 0x6367, + .chip_ver =3D 0x0020, + .extints =3D { + { 6, 1, PHY_INTF(MII) | PHY_INTF(TMII) | + PHY_INTF(RMII) | PHY_INTF(RGMII) }, + { 7, 2, PHY_INTF(MII) | PHY_INTF(TMII) | + PHY_INTF(RMII) | PHY_INTF(RGMII) }, + }, + .jam_table =3D rtl8365mb_init_jam_8365mb_vc, + .jam_size =3D ARRAY_SIZE(rtl8365mb_init_jam_8365mb_vc), + }, +}; + enum rtl8365mb_stp_state { RTL8365MB_STP_STATE_DISABLED =3D 0, RTL8365MB_STP_STATE_BLOCKING =3D 1, @@ -558,29 +623,23 @@ struct rtl8365mb_port { }; =20 /** - * struct rtl8365mb - private chip-specific driver data + * struct rtl8365mb - driver private data * @priv: pointer to parent realtek_priv data * @irq: registered IRQ or zero - * @chip_id: chip identifier - * @chip_ver: chip silicon revision + * @chip_info: chip-specific info about the attached switch * @cpu: CPU tagging and CPU port configuration for this chip * @mib_lock: prevent concurrent reads of MIB counters * @ports: per-port data - * @jam_table: chip-specific initialization jam table - * @jam_size: size of the chip's jam table * * Private data for this driver. */ struct rtl8365mb { struct realtek_priv *priv; int irq; - u32 chip_id; - u32 chip_ver; + const struct rtl8365mb_chip_info *chip_info; struct rtl8365mb_cpu cpu; struct mutex mib_lock; struct rtl8365mb_port ports[RTL8365MB_MAX_NUM_PORTS]; - const struct rtl8365mb_jam_tbl_entry *jam_table; - size_t jam_size; }; =20 static int rtl8365mb_phy_poll_busy(struct realtek_priv *priv) @@ -775,6 +834,26 @@ static int rtl8365mb_dsa_phy_write(struct dsa_switch *= ds, int phy, int regnum, return rtl8365mb_phy_write(ds->priv, phy, regnum, val); } =20 +static const struct rtl8365mb_extint * +rtl8365mb_get_port_extint(struct realtek_priv *priv, int port) +{ + struct rtl8365mb *mb =3D priv->chip_data; + int i; + + for (i =3D 0; i < RTL8365MB_MAX_NUM_EXTINTS; i++) { + const struct rtl8365mb_extint *extint =3D + &mb->chip_info->extints[i]; + + if (!extint->supported_interfaces) + continue; + + if (extint->port =3D=3D port) + return extint; + } + + return NULL; +} + static enum dsa_tag_protocol rtl8365mb_get_tag_protocol(struct dsa_switch *ds, int port, enum dsa_tag_protocol mp) @@ -795,20 +874,17 @@ rtl8365mb_get_tag_protocol(struct dsa_switch *ds, int= port, static int rtl8365mb_ext_config_rgmii(struct realtek_priv *priv, int port, phy_interface_t interface) { + const struct rtl8365mb_extint *extint =3D + rtl8365mb_get_port_extint(priv, port); struct device_node *dn; struct dsa_port *dp; int tx_delay =3D 0; int rx_delay =3D 0; - int ext_int; u32 val; int ret; =20 - ext_int =3D rtl8365mb_extint_port_map[port]; - - if (ext_int <=3D 0) { - dev_err(priv->dev, "Port %d is not an external interface port\n", port); - return -EINVAL; - } + if (!extint) + return -ENODEV; =20 dp =3D dsa_to_port(priv->ds, port); dn =3D dp->dn; @@ -842,7 +918,7 @@ static int rtl8365mb_ext_config_rgmii(struct realtek_pr= iv *priv, int port, tx_delay =3D val / 2; else dev_warn(priv->dev, - "EXT interface TX delay must be 0 or 2 ns\n"); + "RGMII TX delay must be 0 or 2 ns\n"); } =20 if (!of_property_read_u32(dn, "rx-internal-delay-ps", &val)) { @@ -852,11 +928,11 @@ static int rtl8365mb_ext_config_rgmii(struct realtek_= priv *priv, int port, rx_delay =3D val; else dev_warn(priv->dev, - "EXT interface RX delay must be 0 to 2.1 ns\n"); + "RGMII RX delay must be 0 to 2.1 ns\n"); } =20 ret =3D regmap_update_bits( - priv->map, RTL8365MB_EXT_RGMXF_REG(ext_int), + priv->map, RTL8365MB_EXT_RGMXF_REG(extint->id), RTL8365MB_EXT_RGMXF_TXDELAY_MASK | RTL8365MB_EXT_RGMXF_RXDELAY_MASK, FIELD_PREP(RTL8365MB_EXT_RGMXF_TXDELAY_MASK, tx_delay) | @@ -865,11 +941,11 @@ static int rtl8365mb_ext_config_rgmii(struct realtek_= priv *priv, int port, return ret; =20 ret =3D regmap_update_bits( - priv->map, RTL8365MB_DIGITAL_INTERFACE_SELECT_REG(ext_int), - RTL8365MB_DIGITAL_INTERFACE_SELECT_MODE_MASK(ext_int), + priv->map, RTL8365MB_DIGITAL_INTERFACE_SELECT_REG(extint->id), + RTL8365MB_DIGITAL_INTERFACE_SELECT_MODE_MASK(extint->id), RTL8365MB_EXT_PORT_MODE_RGMII << RTL8365MB_DIGITAL_INTERFACE_SELECT_MODE_OFFSET( - ext_int)); + extint->id)); if (ret) return ret; =20 @@ -880,21 +956,18 @@ static int rtl8365mb_ext_config_forcemode(struct real= tek_priv *priv, int port, bool link, int speed, int duplex, bool tx_pause, bool rx_pause) { + const struct rtl8365mb_extint *extint =3D + rtl8365mb_get_port_extint(priv, port); u32 r_tx_pause; u32 r_rx_pause; u32 r_duplex; u32 r_speed; u32 r_link; - int ext_int; int val; int ret; =20 - ext_int =3D rtl8365mb_extint_port_map[port]; - - if (ext_int <=3D 0) { - dev_err(priv->dev, "Port %d is not an external interface port\n", port); - return -EINVAL; - } + if (!extint) + return -ENODEV; =20 if (link) { /* Force the link up with the desired configuration */ @@ -942,7 +1015,7 @@ static int rtl8365mb_ext_config_forcemode(struct realt= ek_priv *priv, int port, r_duplex) | FIELD_PREP(RTL8365MB_DIGITAL_INTERFACE_FORCE_SPEED_MASK, r_speed); ret =3D regmap_write(priv->map, - RTL8365MB_DIGITAL_INTERFACE_FORCE_REG(ext_int), + RTL8365MB_DIGITAL_INTERFACE_FORCE_REG(extint->id), val); if (ret) return ret; @@ -953,7 +1026,13 @@ static int rtl8365mb_ext_config_forcemode(struct real= tek_priv *priv, int port, static void rtl8365mb_phylink_get_caps(struct dsa_switch *ds, int port, struct phylink_config *config) { - if (dsa_is_user_port(ds, port)) { + const struct rtl8365mb_extint *extint =3D + rtl8365mb_get_port_extint(ds->priv, port); + + config->mac_capabilities =3D MAC_SYM_PAUSE | MAC_ASYM_PAUSE | + MAC_10 | MAC_100 | MAC_1000FD; + + if (!extint) { __set_bit(PHY_INTERFACE_MODE_INTERNAL, config->supported_interfaces); =20 @@ -962,12 +1041,16 @@ static void rtl8365mb_phylink_get_caps(struct dsa_sw= itch *ds, int port, */ __set_bit(PHY_INTERFACE_MODE_GMII, config->supported_interfaces); - } else if (dsa_is_cpu_port(ds, port)) { - phy_interface_set_rgmii(config->supported_interfaces); + return; } =20 - config->mac_capabilities =3D MAC_SYM_PAUSE | MAC_ASYM_PAUSE | - MAC_10 | MAC_100 | MAC_1000FD; + /* Populate according to the modes supported by _this driver_, + * not necessarily the modes supported by the hardware, some of + * which remain unimplemented. + */ + + if (extint->supported_interfaces & RTL8365MB_PHY_INTERFACE_MODE_RGMII) + phy_interface_set_rgmii(config->supported_interfaces); } =20 static void rtl8365mb_phylink_mac_config(struct dsa_switch *ds, int port, @@ -1782,14 +1865,17 @@ static int rtl8365mb_change_tag_protocol(struct dsa= _switch *ds, static int rtl8365mb_switch_init(struct realtek_priv *priv) { struct rtl8365mb *mb =3D priv->chip_data; + const struct rtl8365mb_chip_info *ci; int ret; int i; =20 + ci =3D mb->chip_info; + /* Do any chip-specific init jam before getting to the common stuff */ - if (mb->jam_table) { - for (i =3D 0; i < mb->jam_size; i++) { - ret =3D regmap_write(priv->map, mb->jam_table[i].reg, - mb->jam_table[i].val); + if (ci->jam_table) { + for (i =3D 0; i < ci->jam_size; i++) { + ret =3D regmap_write(priv->map, ci->jam_table[i].reg, + ci->jam_table[i].val); if (ret) return ret; } @@ -1962,6 +2048,7 @@ static int rtl8365mb_detect(struct realtek_priv *priv) u32 chip_id; u32 chip_ver; int ret; + int i; =20 ret =3D rtl8365mb_get_chip_id_and_ver(priv->map, &chip_id, &chip_ver); if (ret) { @@ -1970,52 +2057,32 @@ static int rtl8365mb_detect(struct realtek_priv *pr= iv) return ret; } =20 - switch (chip_id) { - case RTL8365MB_CHIP_ID_8365MB_VC: - switch (chip_ver) { - case RTL8365MB_CHIP_VER_8365MB_VC: - dev_info(priv->dev, - "found an RTL8365MB-VC switch (ver=3D0x%04x)\n", - chip_ver); - break; - case RTL8365MB_CHIP_VER_8367RB_VB: - dev_info(priv->dev, - "found an RTL8367RB-VB switch (ver=3D0x%04x)\n", - chip_ver); - break; - case RTL8365MB_CHIP_VER_8367S: - dev_info(priv->dev, - "found an RTL8367S switch (ver=3D0x%04x)\n", - chip_ver); + for (i =3D 0; i < ARRAY_SIZE(rtl8365mb_chip_infos); i++) { + const struct rtl8365mb_chip_info *ci =3D &rtl8365mb_chip_infos[i]; + + if (ci->chip_id =3D=3D chip_id && ci->chip_ver =3D=3D chip_ver) { + mb->chip_info =3D ci; break; - default: - dev_err(priv->dev, "unrecognized switch version (ver=3D0x%04x)", - chip_ver); - return -ENODEV; } + } =20 - priv->num_ports =3D RTL8365MB_MAX_NUM_PORTS; - - mb->priv =3D priv; - mb->chip_id =3D chip_id; - mb->chip_ver =3D chip_ver; - mb->jam_table =3D rtl8365mb_init_jam_8365mb_vc; - mb->jam_size =3D ARRAY_SIZE(rtl8365mb_init_jam_8365mb_vc); - - mb->cpu.trap_port =3D RTL8365MB_MAX_NUM_PORTS; - mb->cpu.insert =3D RTL8365MB_CPU_INSERT_TO_ALL; - mb->cpu.position =3D RTL8365MB_CPU_POS_AFTER_SA; - mb->cpu.rx_length =3D RTL8365MB_CPU_RXLEN_64BYTES; - mb->cpu.format =3D RTL8365MB_CPU_FORMAT_8BYTES; - - break; - default: + if (!mb->chip_info) { dev_err(priv->dev, - "found an unknown Realtek switch (id=3D0x%04x, ver=3D0x%04x)\n", - chip_id, chip_ver); + "unrecognized switch (id=3D0x%04x, ver=3D0x%04x)", chip_id, + chip_ver); return -ENODEV; } =20 + dev_info(priv->dev, "found an %s switch\n", mb->chip_info->name); + + priv->num_ports =3D RTL8365MB_MAX_NUM_PORTS; + mb->priv =3D priv; + mb->cpu.trap_port =3D RTL8365MB_MAX_NUM_PORTS; + mb->cpu.insert =3D RTL8365MB_CPU_INSERT_TO_ALL; + mb->cpu.position =3D RTL8365MB_CPU_POS_AFTER_SA; + mb->cpu.rx_length =3D RTL8365MB_CPU_RXLEN_64BYTES; + mb->cpu.format =3D RTL8365MB_CPU_FORMAT_8BYTES; + return 0; } =20 --=20 2.36.1