From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=66.163.187.32 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796421887; b=ICEcLrTS9St1T4j3TzkQ+O040orqaaTsum5D9nS6UxDeqYCtS3SmijipikiKRwNQ3t1Q B/O5ux7J1T0gEMuSl+EECuHrKYXuuhqPjvYl645HC4pmu2rtdIeXLSIjuSavoYeFufmfd pS6LbE0clmUHUcUaW4dGdB2chw/zS/ZNORwinBMEeBUxyeZicf9z/1xzaHGYqvHlpQaVr b0prMzy5Y7L88Ck3ZwXvju3f/6t/gIDMQbLhxCcydOp03Fjgi+rJHStLSRfiK71NXi6Hc s2bLRU+T6dUL47pBCCar1DvAdJD8APzDiVc4MWnFEVXvhw747qrEl4Io86LKEuelhcQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796421887; h=DMARC-Filter:DKIM-Signature:X-SONIC-DKIM-SIGN:X-YMail-OSG:X-Sonic-MF: X-Sonic-ID:Received:Received:Message-ID:Date:MIME-Version:User-Agent: Subject:To:References:Content-Language:In-Reply-To:From:Content-Type: Content-Transfer-Encoding:X-Mailer; bh=uVeQOGO4N8sNzDQywewiKx1ArU2P3TuVzBcQ5e/8x0U=; b=sjDOMVLrgiWM0S7Lhx3uulastqECvEL5huU+J7x/4U3rcPIvKA0P/adsvvNVVLD87KS+ JFK/jNxaTXbDXUjj92dqoLIJ+FByYvhuKlyGl7ziiQyPkX7YSOP0DV5Pc6PRUK2fVnPcf 4srS22ZXtboN6URgEkwLLG3arqlhTtGN5H8rTQh7FF/hSM5GzmDT9KiM3FavbsgUAuOnF akSPUreowkTM49djVEnZL9I0i1SdF6lBISm8HF2Ld19WHQZa+cDA9dXY4RZDhX70HwhU6 XPH8jRUP6QGBaJ+1UkcyRwFopMUYfjQhg41K/lvCef2DAyMpfJb54g1cjKjm2ptog0Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=yahoo.com; spf=pass smtp.mailfrom=yahoo.com; dkim=pass header.d=yahoo.com header.i=@yahoo.com header.a=rsa-sha256 header.s=s2048 header.b=GCchlCp5; arc=none smtp.remote-ip=66.163.187.32 Received: from sonic308-9.consmr.mail.ne1.yahoo.com (sonic308-9.consmr.mail.ne1.yahoo.com [66.163.187.32]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 63A18606A333 for ; Fri, 4 Dec 2026 22:04:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 63A18606A333 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=yahoo.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=yahoo.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=yahoo.com header.i=@yahoo.com header.a=rsa-sha256 header.s=s2048 header.b=GCchlCp5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1796421885; bh=uVeQOGO4N8sNzDQywewiKx1ArU2P3TuVzBcQ5e/8x0U=; h=Date:Subject:To:References:In-Reply-To:From:Content-Type:From:Subject:Reply-To:Content-Type; b=GCchlCp5Pmr9HW8EMRoTysUagUKvyuT4PqVpjLQX+rCiXtM/MY0QT/MaH30qgpGay2tfQbnrxe6 m1Qki3Wb0mesx9QPTz8oudKPYU6rJ9lESpVJY4QZW5+bNrgW4syRHAUO7Ravy5Jjrmq+WBdF6yKTV y/GgldKZx1wxmnIi0QTuonO9tQSDrXrIOWrdrP2Ta21GZ2YBmsvp8kQfmR+QiKCHjyPz6twdbGPwJ UbDVxqacLqPyG3R+81x4EW75STISbMEJMihO4T4fZTVu5xmv7j3jdWaAWZuXbMj/UYZ9hNczkCDpq LgSvomHzCt3dNvq8NgH/MxPthhHLlSo7lgQA== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1796421885; bh=AMrvxDxhPnZubloD7bMrprukxG/Zwse0vJgW9meezQZ=; h=X-Sonic-MF:Date:Subject:To:From:From:Subject; b=anitn+3yZnOWlFu4htagjqKGYf5 YFvOlleIKqO8XKaVADdVC5vt7pOufyW+kAz3yerPZvkEONdvtSX8avg9ksMwWuXIiCIa/+31kQG0k LwZYbyChshoLWfb8hJ2UAbv9akcB64Jy47Iv2EdMmxAPyex78i97PY+1Jl1n9Aar/MTDgndqpix25 82wUMrME3Rnymxop/NUhSKnG17jPXg7fnC0czd+5bGh816XA0LC9XeXrTb6F83NBGl2FlPo/4yDBG RnJh/t8ecd5adqWAu9BnbwK1WBJ6DSEfWJSpHmoxrSb9TfwkiAWl/FqNmksq5ZYmAa/avbp4XEZ8t NwzIArQ== X-YMail-OSG: ZVcB0J0VM1lx93YhzYoHT70iFWujgZafo0cAYXU_jVl5LWY7bThsCN8sznkYD5C .55NHu.ofqtWw_1za4vVOCCgtQ2fjFJ._rA_UnTVOPdQ.VrL33jqV6.mSrc22uYL2xiIMzbwJfAy CM8ZhBg.E5V1LDnUBc7uHifSEEMZrmMexJf060pEMDPfsqdhFTgUI3XstEsBO8zsMh9.Yul1RUAw eUCvPtbIcYLR_ZcpG8Y_9pd8CLk.2.nVYriURknStyy0Y5uh0RK1OZZpkv9xoI.6XC5da3zKVq16 8PXNyM5hZJZUjt06zvhXN4JjInc8rAyOINhxqkUg.XxUfjwoWGbbzylIDEGMzCsYpwvtBeTBzl_D 4jM7W01hL530rhiIfe0WdwGSPZB7RQZI0otQQh_6mfffwzNH6y.1GqOXxrKVct5Wofk33Cf3nEry eFxx3QYrvwebeanFCApokZlnWr192JoXUSFxqY7BswbUpWlJRgAHUZUnjxlXTNN7lxOtb3qH.hfK x1dKsiCHWyoUmyh3PYHcM9RO9RACcevs2ntrLfW00lne1imZb1HXSRpgahf6.TQelNM2pMsmnf.m n8m0...t3Kkj8Jtl8hXTV9fHKKNE5NTzS4dlugzy00XbR7.2LLGjFB1vLStwj.8CSu7Ay3JMf2wb 3mG53SlaT8y8VwtXEvAeTafWSwZkrljaqmGZH2w6xj16jyyTiYIaIidmhJkYvY9YaeB2vZLz1bQV 7C41PXxCMNGG1yZoYkhqlQ3E8YQMWRQGUYwAQAgdARdxiReT36t5EoNyme21M1tp.xhUzW0emuRR WDGtHW67CNGUvWB9a1cb_53q0ivxKLx22CDDe3Y7GIrAS5fMgFg2CDhnLkGUyJxSozzLrmBZllOW WZA6QQtW42hmwTcHGxFC0AEeNk2R0mv40ANnYgc_ka2Jyjqg_WMx3N4.3e0MRk2fks_8QZEHtOSt CQroQiohFXwe8iJX_v0Vqcf8POhCpzbtQ.nO5Wa31MLq589k.OqBwaVP5UFqwLiVwrNC2YN0gV4f I8sAeQSeSQjAp.3qbKjWZE7c_qcHUc5bSz0hArVmgRr5Yiz9hBuX0VnkFv_5pltci9Vvn8ZLoOyl LD4KsMND4Z42JYoQBLXL3_BYFjs8OI3rpl5.zXG.tMxt1fBGMiGceXjlRR3eP8P6BRHANh1qlSzW qdKuZazlGH.l.kTpVAVW3xG2FMGvse4vdFswn9Rsh3_ujIMyIALPp15FZOpWsPfML4mizSVHCCrO pznCrLm2VEWwVZDJtvkkDTqOua8sITQXphk9wB4orvVs_17YOLCbuvlMgltogAW7KEG6K0iPn9mT 0tVVEJYG3MxThCCiHnWlBoOWhtX59V0.0nm6hxPvMtjVTZaKruSIjxG_E3.VtR2iFBY4Q9._SjWf 3An0C.qDietHO0hlKwSLmGgviwM61AaGQAnGmBiVnRDwz0yl9j9Z8YbzgDz1csaOXyi2wEh4NVeM MpfJvdPEDfqriQA32NQSZamgk63BLslvV7bfhlkK6A_2UzQwecE8ZFL7zKiMYBob5pPhJTFXBXHg WN8fF6bWLaKdEvwVcGNi_NuoyG6UgHvOXStFgF.Isj6IhNMNQJZ.11G2voEBoKTcPNIK1bkwy1D6 17BZLs7HKzrWD5Dwob5pPX3g3BAsxQuFgMBDKde9s12v8.wlnNLKaH_cSroym9IGQlxJTxgUuv_z aMxBD_L3GFseP4.Ix6LOtDWr3u1oeXm5LfC_j2n.zX1v_h8AmNvPkxDVzhpHVo1pyE1MyxxfaFYv 7dT1A0lw.CVywOhdQF7_pWR5pNDucqesqISHPfIYdA8xO9ixG28KzE54QO1edZCydZRdz8gWjKax JXD2vsoezIGxnanLhi_iKbS2Cyv0O72eYsz6tf4xCIJH3yU9Fe06VRbgOqCE2uCcqZhtd7C_tD4H xerzpEjKBdlhYNfRTZEePRU_1NPT5TjeYVGtdQUP8cYn40xlsN9z6YvhnxbCXY0eIvzPenmOEnT4 wB6QQSdHxcJWzS8W2lA9nRQ1oYClOXCeapFlRE5uZUuENaIYH4918pvhir8UTwMpC_K3BD7Bm23g xCfrhs_f7YTqNDYE9t2VdOtlTihixk5ZkliKerTxPF5POTyz8Gx4cSZSKiCNdyeTnpo7ZujYh0ke QspfuFxAT2QBO6coJFCxftbJb0Gn4_xrxbORs7O5cB5WdZEh78840ODLzyD0qPz9VGowbOH.qAPU RU8_wZif9k1Vj0U3_HcDBU2PedESVR44YBE62rjv82YCvXN2XtiCXOuPOwhppPbXtHURU6vN5BTn uTpGsbP51D.DD.A9Bc9aswK.KyAhyPw.MKlnlVqckI5fI7Q-- X-Sonic-MF: X-Sonic-ID: 97457dba-61a6-4fc8-ba79-d80907116a17 Received: from sonic.gate.mail.ne1.yahoo.com by sonic308.consmr.mail.ne1.yahoo.com with HTTP; Fri, 4 Dec 2026 22:04:45 +0000 Received: by hermes--production-ir2-7c4859dc89-vw2vb (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID de3af766082b3ab7fc4b83278806e301; Fri, 04 Dec 2026 22:04:44 +0000 (UTC) Message-ID: <71391a28-8df8-45a8-9705-07f2c5454e85@yahoo.com> Date: Fri, 4 Dec 2026 23:04:42 +0100 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH net-next v20 07/15] net: dsa: realtek: rtl8365mb: add VLAN 4k/IVL for family D To: linusw@kernel.org, andrew@lunn.ch, olteanv@gmail.com, kuba@kernel.org, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com, linux@armlinux.org.uk, luizluca@gmail.com, maxime.chevallier@bootlin.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, alvin.sipraga@analog.com, gusfmora@gmail.com, kuncy7@gmail.com, fabianotassotti@gmail.com, gabonpivovich@gmail.com, contact@c127.dev, o.rempel@pengutronix.de References: <9efcb80a-517c-4413-8261-4f9380e0eb83@yahoo.com> Content-Language: pl In-Reply-To: <9efcb80a-517c-4413-8261-4f9380e0eb83@yahoo.com> From: Mieczyslaw Nalewaj Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Mailer: WebService/1.1.27159 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo The hardware structure of 4K VLAN table entries has changed between silicon families. Family D's CVLAN entry is two 16-bit words rather than three: there is no third word extending member/untag past bit 7, and no priority/meter fields at all. The FID field is restricted to a narrower 2-bit width. The chip itself supports both IVL and SVL. IVL_EN (bit 3, versus bit 14 on family C) follows vlan4k->ivl_en. On family D, rtl8365mb_vlan_4k_port_set() enables it while any user port has VLAN filtering enabled (dsa_port_is_vlan_filtering()), so that static and learned FDB/MDB entries use the same key. Family C keeps IVL always enabled, as before. When a vlan_filtering change flips this switch-wide state, rtl8365mb_d_vlan_4k_refresh_ivl() updates IVL_EN across the active 4K entries, so existing VLANs, including those programmed before filtering was enabled, switch between SVL and IVL immediately. Changes that leave the state as it is do not touch the table. After a successful switch-wide IVL_EN change, flush the dynamically learned L2 entries on every user port, so that none learned with the previous SVL/IVL key remains, whatever the chip does on its own. Such entries must not occupy LUT slots or become visible again after a later toggle. Do not advertise vlan_filtering_is_global: ingress and egress VLAN filtering remain per-port, and only the learning key used by active VLAN entries follows a switch-wide policy. VLAN-unaware traffic is meant to use the SVL key with VID 0, which the L2 patch implements together with port-based FID 1. Because the policy is switch-wide, if a VLAN-aware and a VLAN-unaware bridge share the switch, the VLANs of both use IVL and the learned entries of the VLAN-unaware one no longer match its static VID 0 (SVL) entries (known limitation). The L2 patch limits the switch to one offloaded bridge by rejecting a second bridge with -EOPNOTSUPP. The update visits only the VIDs in use, tracked in the vlan_4k_used bitmap in struct realtek_priv. rtl8365mb_vlan_4k_port_set() keeps it up to date under vlan_lock, so a toggle does not read all 4094 entries over the slow management bus (about 5 s per toggle on an RTL8367S-VB; 20-30 ms with the bitmap). The bitmap covers the entries written by this driver: an entry that was already in the table before the driver loaded is not visited. An entry that loses its last member is written back with IVL_EN cleared, as in its reset state, so that it is not left in IVL after it drops out of the bitmap. The rewrite itself is a separate function, rtl8365mb_d_vlan_4k_set_ivl(), which does a best-effort restore of the previous IVL_EN values if a read or write fails part way through, without flushing L2 entries, and logs any entry it could not restore. Reusing the three-word family C layout on family D would read a third word that does not exist as a distinct table word on family D's die. Whatever data happens to be in that register would be folded into member/untag bits [10:8] on read, and written back on every read-modify-write cycle in rtl8365mb_vlan_4k_port_set(). Give family D its own two-word pack/unpack instead, which matches the vendor switch API for this chip family (it writes only 0x0510/0x0511 for a CVLAN entry): add rtl8365mb_d_vlan_4k_read() and rtl8365mb_d_vlan_4k_write(). The shared code reaches them through the vlan_4k_read and vlan_4k_write pointers in struct rtl8365mb_family_info, so the pack/unpack code needs no is_d() check. Nothing points to them until the family D info is added together with the chip table entry in the last patch. They are non-static and declared in rtl8365mb_vlan.h because struct rtl8365mb_family_info in rtl8365mb_main.c references them. Tested-by: Gustavo Foletto Mora Signed-off-by: Mieczyslaw Nalewaj Reviewed-by: Linus Walleij --- drivers/net/dsa/realtek/realtek.h | 8 + drivers/net/dsa/realtek/rtl8365mb_main.c | 13 ++ drivers/net/dsa/realtek/rtl8365mb_vlan.c | 202 ++++++++++++++++++++++- drivers/net/dsa/realtek/rtl8365mb_vlan.h | 7 + 4 files changed, 228 insertions(+), 2 deletions(-) diff --git a/drivers/net/dsa/realtek/realtek.h b/drivers/net/dsa/realtek/realtek.h index dacb780..fda385e 100644 --- a/drivers/net/dsa/realtek/realtek.h +++ b/drivers/net/dsa/realtek/realtek.h @@ -8,6 +8,8 @@ #ifndef _REALTEK_H #define _REALTEK_H +#include +#include #include #include #include @@ -65,6 +67,12 @@ struct realtek_priv { * deleting port VLAN memberships and PVID configurations. */ struct mutex vlan_lock; + /* VIDs with a non-empty 4K VLAN entry written by rtl8365mb on family + * D (left empty by other chips and drivers), protected by vlan_lock. + * Lets a switch-wide update visit only the entries in use instead of + * reading all 4094 over the slow management bus. + */ + DECLARE_BITMAP(vlan_4k_used, VLAN_N_VID); /* l2_lock is used to prevent concurrent modifications of L2 table * entries while another function is reading it. l2_(add,del)_mc * is an example that first read current table entry and then diff --git a/drivers/net/dsa/realtek/rtl8365mb_main.c b/drivers/net/dsa/realtek/rtl8365mb_main.c index 2e35452..d1f1b4a 100644 --- a/drivers/net/dsa/realtek/rtl8365mb_main.c +++ b/drivers/net/dsa/realtek/rtl8365mb_main.c @@ -2333,8 +2333,21 @@ static int rtl8365mb_port_vlan_filtering(struct dsa_switch *ds, int port, if (ret) goto undo_set_framefilter; + if (rtl8365mb_is_d(priv)) { + mutex_lock(&priv->vlan_lock); + ret = rtl8365mb_d_vlan_4k_refresh_ivl(ds, port, vlan_filtering); + mutex_unlock(&priv->vlan_lock); + if (ret) + goto undo_egress_mode; + } + return ret; +undo_egress_mode: + /* The previous state was the opposite of the new one, see below */ + (void)rtl8365mb_port_set_vlan_egress_mode(priv, port, + vlan_filtering ? RTL8365MB_VLAN_EGRESS_MODE_REAL_KEEP : + RTL8365MB_VLAN_EGRESS_MODE_ORIGINAL); undo_set_framefilter: if (prev_accepted_frame != accepted_frame) rtl8365mb_vlan_port_set_framefilter(priv, port, diff --git a/drivers/net/dsa/realtek/rtl8365mb_vlan.c b/drivers/net/dsa/realtek/rtl8365mb_vlan.c index 566c6bc..ca2815b 100644 --- a/drivers/net/dsa/realtek/rtl8365mb_vlan.c +++ b/drivers/net/dsa/realtek/rtl8365mb_vlan.c @@ -47,14 +47,19 @@ */ #include "rtl8365mb_vlan.h" +#include "rtl83xx.h" #include "rtl8365mb_table.h" #include "rtl8365mb.h" #include +#include #include #include -/* CVLAN (i.e. VLAN4k) table entry layout, u16[3] */ +/* CVLAN (i.e. VLAN4k) table entry layout: u16[3] on family C, u16[2] on + * family D + */ #define RTL8365MB_C_CVLAN_ENTRY_SIZE 3 /* 48-bits */ +#define RTL8365MB_D_CVLAN_ENTRY_SIZE 2 /* 32-bits */ #define RTL8365MB_CVLAN_ENTRY_D0_MBR_MASK GENMASK(7, 0) #define RTL8365MB_CVLAN_MBR_LO_MASK GENMASK(7, 0) #define RTL8365MB_CVLAN_ENTRY_D0_UNTAG_MASK GENMASK(15, 8) @@ -66,6 +71,10 @@ #define RTL8365MB_CVLAN_ENTRY_D1_METERIDX_MASK GENMASK(13, 9) #define RTL8365MB_CVLAN_METERIDX_LO_MASK GENMASK(4, 0) #define RTL8365MB_CVLAN_ENTRY_D1_IVL_SVL_MASK GENMASK(14, 14) +/* Family D CVLAN entry, word 1 (family D has no word 2) */ +#define RTL8365MB_D_CVLAN_ENTRY_D1_IVL_EN_MASK GENMASK(3, 3) +/* FID_MSTI in the vendor API: the same bits hold the FID or the MSTI */ +#define RTL8365MB_D_CVLAN_ENTRY_D1_FID_MASK GENMASK(1, 0) /* extends RTL8365MB_CVLAN_ENTRY_D0_MBR_MASK */ #define RTL8365MB_CVLAN_ENTRY_D2_MBR_EXT_MASK GENMASK(2, 0) #define RTL8365MB_CVLAN_MBR_HI_MASK GENMASK(10, 8) @@ -231,6 +240,45 @@ int rtl8365mb_c_vlan_4k_read(struct realtek_priv *priv, u16 vid, return 0; } +int rtl8365mb_d_vlan_4k_read(struct realtek_priv *priv, u16 vid, + struct rtl8365mb_vlan4k *vlan4k) +{ + u16 data[RTL8365MB_D_CVLAN_ENTRY_SIZE]; + int val; + int ret; + + ret = rtl8365mb_table_query(priv, RTL8365MB_TABLE_CVLAN, + RTL8365MB_TABLE_OP_READ, &vid, 0, 0, + data, RTL8365MB_D_CVLAN_ENTRY_SIZE); + if (ret) + return ret; + + /* Unpack table entry */ + memset(vlan4k, 0, sizeof(*vlan4k)); + vlan4k->vid = vid; + + /* member/untag: d0[7:0]/d0[15:8] on both families. Family C + * extends these into data[2] bits [2:0]/[5:3] for its 9th-11th + * ports; family D represents ports 0-7 in the first word and has + * no third table word, so data[2] must not be read. + */ + val = FIELD_GET(RTL8365MB_CVLAN_ENTRY_D0_MBR_MASK, data[0]); + vlan4k->member = FIELD_PREP(RTL8365MB_CVLAN_MBR_LO_MASK, val); + + val = FIELD_GET(RTL8365MB_CVLAN_ENTRY_D0_UNTAG_MASK, data[0]); + vlan4k->untag = FIELD_PREP(RTL8365MB_CVLAN_UNTAG_LO_MASK, val); + + vlan4k->fid = FIELD_GET(RTL8365MB_D_CVLAN_ENTRY_D1_FID_MASK, + data[1]); + /* Family D has no priority/meter fields in this entry - + * left zeroed by the memset() above. + */ + vlan4k->ivl_en = FIELD_GET(RTL8365MB_D_CVLAN_ENTRY_D1_IVL_EN_MASK, + data[1]); + + return 0; +} + int rtl8365mb_c_vlan_4k_write(struct realtek_priv *priv, const struct rtl8365mb_vlan4k *vlan4k) { @@ -277,6 +325,139 @@ int rtl8365mb_c_vlan_4k_write(struct realtek_priv *priv, data, ARRAY_SIZE(data)); } +int rtl8365mb_d_vlan_4k_write(struct realtek_priv *priv, + const struct rtl8365mb_vlan4k *vlan4k) +{ + /* Bit 2 of word 1 is SVLAN_CHK_IVL_SVL in the vendor API; like + * the other bits not described above, it is written as zero, as + * the vendor API does for this chip family. + */ + u16 data[RTL8365MB_D_CVLAN_ENTRY_SIZE] = { 0 }; + u16 vid; + int val; + + /* Pack table entry value */ + val = FIELD_GET(RTL8365MB_CVLAN_MBR_LO_MASK, vlan4k->member); + data[0] |= FIELD_PREP(RTL8365MB_CVLAN_ENTRY_D0_MBR_MASK, val); + + val = FIELD_GET(RTL8365MB_CVLAN_UNTAG_LO_MASK, vlan4k->untag); + data[0] |= FIELD_PREP(RTL8365MB_CVLAN_ENTRY_D0_UNTAG_MASK, val); + + data[1] |= FIELD_PREP(RTL8365MB_D_CVLAN_ENTRY_D1_IVL_EN_MASK, + vlan4k->ivl_en); + data[1] |= FIELD_PREP(RTL8365MB_D_CVLAN_ENTRY_D1_FID_MASK, + vlan4k->fid); + /* No priority/meter/member-untag-extension fields exist in + * family D's 2-word entry - data[1] and data[0] above are + * the whole entry, and data[2] is not part of it at all. + */ + + vid = vlan4k->vid; + return rtl8365mb_table_query(priv, RTL8365MB_TABLE_CVLAN, + RTL8365MB_TABLE_OP_WRITE, &vid, 0, 0, + data, RTL8365MB_D_CVLAN_ENTRY_SIZE); +} + +/* Family D has no EFID. Use IVL while at least one user port is VLAN + * filtering and SVL otherwise. The family D L2 helpers added later in the + * series use the matching key for static FDB/MDB entries. @port/@filtering + * override the state of the port being changed, giving the target state + * both on normal calls (before DSA updates dp->vlan_filtering) and on + * DSA's error-restore path (before DSA reverts it). The result is + * switch-wide: a VLAN-unaware bridge that shares the switch with a + * VLAN-aware one also gets IVL (known limitation). + */ +static bool rtl8365mb_d_want_ivl(struct dsa_switch *ds, int port, + bool filtering) +{ + struct dsa_port *dp; + + dsa_switch_for_each_user_port(dp, ds) { + if (dp->index == port ? filtering : + dsa_port_is_vlan_filtering(dp)) + return true; + } + + return false; +} + +/* Set IVL_EN of every 4K entry in use to @want_ivl. Callers must use it only + * for a change of the switch-wide state (see + * rtl8365mb_d_vlan_4k_refresh_ivl()), so that every entry in use holds + * !@want_ivl on entry. Must be called with &priv->vlan_lock held. + */ +static int rtl8365mb_d_vlan_4k_set_ivl(struct dsa_switch *ds, bool want_ivl) +{ + const struct rtl8365mb_family_info *fi; + struct realtek_priv *priv = ds->priv; + struct rtl8365mb_vlan4k vlan4k; + struct dsa_port *dp; + unsigned int failed; + unsigned int vid; + int ret; + + lockdep_assert_held(&priv->vlan_lock); + + fi = rtl8365mb_get_family_info(priv); + + for_each_set_bit(vid, priv->vlan_4k_used, VLAN_N_VID) { + ret = fi->vlan_4k_read(priv, vid, &vlan4k); + if (ret) + goto rollback; + if (!vlan4k.member || vlan4k.ivl_en == want_ivl) + continue; + + vlan4k.ivl_en = want_ivl; + ret = fi->vlan_4k_write(priv, &vlan4k); + if (ret) + goto rollback; + } + + dsa_switch_for_each_user_port(dp, ds) + rtl83xx_port_fast_age(ds, dp->index); + + return 0; + +rollback: + /* Best effort: restore IVL_EN on the entries rewritten so far (without + * flushing L2 entries). IVL_EN is switch-wide, so before the scan + * every entry in use had the old value (!want_ivl) and every entry + * below @failed that now has want_ivl was rewritten above. The entry + * that failed is included: its write may have reached the chip before + * the error was reported. + */ + failed = vid + 1; + for_each_set_bit(vid, priv->vlan_4k_used, failed) { + if (fi->vlan_4k_read(priv, vid, &vlan4k)) { + dev_warn(priv->dev, "VID %u: IVL_EN rollback read failed\n", + vid); + continue; + } + if (!vlan4k.member || vlan4k.ivl_en != want_ivl) + continue; + vlan4k.ivl_en = !want_ivl; + if (fi->vlan_4k_write(priv, &vlan4k)) + dev_warn(priv->dev, "VID %u: IVL_EN rollback failed\n", + vid); + } + return ret; +} + +/* Must be called with &priv->vlan_lock held. */ +int rtl8365mb_d_vlan_4k_refresh_ivl(struct dsa_switch *ds, int port, + bool filtering) +{ + bool want_ivl = rtl8365mb_d_want_ivl(ds, port, filtering); + + /* The scan visits every entry in use, so do it only if this + * change flips the switch-wide state, not for each port of a bridge. + */ + if (want_ivl == rtl8365mb_d_want_ivl(ds, -1, false)) + return 0; + + return rtl8365mb_d_vlan_4k_set_ivl(ds, want_ivl); +} + static int rtl8365mb_vlan_4k_port_set(struct dsa_switch *ds, int port, const struct switchdev_obj_port_vlan *vlan, @@ -314,7 +495,21 @@ rtl8365mb_vlan_4k_port_set(struct dsa_switch *ds, int port, vlan4k.untag |= BIT(port); else vlan4k.untag &= ~BIT(port); - vlan4k.ivl_en = true; /* always use Independent VLAN Learning */ + + if (!rtl8365mb_is_d(priv)) + vlan4k.ivl_en = true; + else + /* An emptied entry goes back to its reset state, so that + * it is not left in IVL after it leaves vlan_4k_used. + */ + vlan4k.ivl_en = vlan4k.member && + rtl8365mb_d_want_ivl(ds, -1, false); + + /* The write may reach the chip even if an error is reported, so mark + * a populated entry as used before writing it. + */ + if (rtl8365mb_is_d(priv) && vlan4k.member) + set_bit(vlan->vid, priv->vlan_4k_used); ret = fi->vlan_4k_write(priv, &vlan4k); if (ret) { @@ -322,6 +517,9 @@ rtl8365mb_vlan_4k_port_set(struct dsa_switch *ds, int port, return ret; } + if (rtl8365mb_is_d(priv) && !vlan4k.member) + clear_bit(vlan->vid, priv->vlan_4k_used); + return 0; } diff --git a/drivers/net/dsa/realtek/rtl8365mb_vlan.h b/drivers/net/dsa/realtek/rtl8365mb_vlan.h index 009b127..625d4c1 100644 --- a/drivers/net/dsa/realtek/rtl8365mb_vlan.h +++ b/drivers/net/dsa/realtek/rtl8365mb_vlan.h @@ -24,6 +24,10 @@ int rtl8365mb_c_vlan_4k_read(struct realtek_priv *priv, u16 vid, struct rtl8365mb_vlan4k *vlan4k); int rtl8365mb_c_vlan_4k_write(struct realtek_priv *priv, const struct rtl8365mb_vlan4k *vlan4k); +int rtl8365mb_d_vlan_4k_read(struct realtek_priv *priv, u16 vid, + struct rtl8365mb_vlan4k *vlan4k); +int rtl8365mb_d_vlan_4k_write(struct realtek_priv *priv, + const struct rtl8365mb_vlan4k *vlan4k); int rtl8365mb_vlan_port_get_pvid(struct realtek_priv *priv, int port, u16 *pvid); @@ -43,4 +47,7 @@ int rtl8365mb_vlan_4k_port_del(struct dsa_switch *ds, int port, int rtl8365mb_vlan_pvid_port_set(struct dsa_switch *ds, int port, u16 vid, struct netlink_ext_ack *extack); int rtl8365mb_vlan_pvid_port_clear(struct dsa_switch *ds, int port, u16 vid); + +int rtl8365mb_d_vlan_4k_refresh_ivl(struct dsa_switch *ds, int port, + bool filtering); #endif /* _REALTEK_RTL8365MB_VLAN_H */ -- 2.53.0