net: dsa: microchip: Add support for KSZ8995XA/KS8995XA
Subsystems (5)
v6 cover net: dsa: microchip: Add support for KSZ8995XA/KS8995XA
This series breaks with the dated attempt to polish the old KS8995 driver, and instead implement support for the KS8995XA in the KSZ driver, and after that delete the old KS8995 driver.
The hardware clearly has the same ancestry, the KSZ8995XA is just a rebrand of the much older Micrel KX8995XA switch.
The old drivers referce to "KS8995" was actually KS8995XA only, it never supported the sibling devices KS8995E or KS8995MA. This is reflected in this patch set.
Add new compatibles, add special code paths for the KSZ8995XA and add a new tagger for the special front tag found in the KSZ8995XA.
The patches were tested with the Actiontec MI424WR rev D (which has the KS8995XA) and OpenWrt as userspace.
---
Changes in v6:
- Provide a prompt along with the transition symbol NET_DSA_KS8995
so that oldconfig works.
- Clarify in commit message that the platform data probe path is
unused in the kernel and it is fine to delete this mechanism.
- Link to v5: https://patch.msgid.link/[email protected]
Changes in v5:
- Rebase on net-next again to be sure we apply.
- Fix the codepath where DCB was set up per-port, damaging KS8995XA
port registers.
- Fix up the transitional symbol NET_DSA_KS8995 to depend on
SPI and select both NET_DSA_MICROCHIP_KSZ_COMMON and NET_DSA_MICROCHIP_KSZ_SPI.
- Link to v4: https://patch.msgid.link/[email protected]
Changes in v4:
- Create a stub symbol for NET_DSA_KS8995 to phase over users to
the new driver.
- Link to v3: https://patch.msgid.link/[email protected]
Changes in v3:
- Rebase on net-next again, moving target!
- Fix a netdev_info() print in the tagger to be netdev_debug()
- Add net/dsa/tag_ks8995.c to MAINTAINERS
- Link to v2: https://patch.msgid.link/[email protected]
Changes in v2:
- Avoid trying to configure TOS priority settings (DCB) on the KSZ8995XA.
It does have some support for this, but let's add that later.
- Pick up Krzysztof's ACK on the new DT bindings.
- Reset the KSZ8995XA by disabling and enabling the switch like the old driver does.
- Move mutually exclusive Kconfig over to the patch introducing the
old Micrel compatibles to the Microchip ksz_spi driver.
(this complaint from Sashiko.)
- Use __be16 instead of u16 when casting into the SKB in the tagger
(this complaint from Sashiko.)
- Do not modify the hdr->h_vlan_TCI if no hardware accelerated tag
is detected, it would get nullified. Use whatever the Linux network stack assigned to TCI there.
(this complaint from Sashiko.)
- Avoid dereference of NULL in debug prints in the tagger.
(this complaint from Sashiko.)
- Ignored comment: Sashiko complains about ilog2(0) being potentially undefined but that is clearly defined as 0 in the Linux kernel.
- Link to v1: https://patch.msgid.link/[email protected]
---
Linus Walleij (5):
net: dsa: microchip: Add fallback Micrel compatibles
dt-bindings: net: dsa: microchip: Add KSZ8995XA
net: dsa: tag_ks8995: Add the KS8995 tag handling
net: dsa: microchip: Support Microchip KSZ8995XA / KS8995XA
net: dsa: ks8995: Delete surplus driver
.../devicetree/bindings/net/dsa/microchip,ksz.yaml | 1 + MAINTAINERS | 1 + drivers/net/dsa/Kconfig | 9 +- drivers/net/dsa/Makefile | 1 - drivers/net/dsa/ks8995.c | 857 --------------------- drivers/net/dsa/microchip/Kconfig | 1 + drivers/net/dsa/microchip/ksz8.c | 177 ++++- drivers/net/dsa/microchip/ksz8.h | 2 + drivers/net/dsa/microchip/ksz8_reg.h | 7 + drivers/net/dsa/microchip/ksz_common.c | 58 +- drivers/net/dsa/microchip/ksz_common.h | 11 +- drivers/net/dsa/microchip/ksz_spi.c | 33 +- include/linux/platform_data/microchip-ksz.h | 1 + include/net/dsa.h | 2 + net/dsa/Kconfig | 6 + net/dsa/Makefile | 1 + net/dsa/tag_ks8995.c | 132 ++++ 17 files changed, 400 insertions(+), 900 deletions(-)
---
base-commit: c1c3d01e3a9038d3e8f497e773e1f7b5d6b8212a
change-id: 20260509-ks8995-to-ksz8-15f3f9c8271f
Best regards,
Signature · 1 line
Linus Walleij <[email protected]>
PATCH v6 1/5 net: dsa: microchip: Add fallback Micrel compatibles
Because of forking paths when Micrel was acquired by Microchip, two devices also exist with the micrel,* prefix bindings. Add these to the KSZ SPI driver so users can use the more capable driver.
Make the KS8995 driver mutually exclusive with this driver to avoid probe races.
--- drivers/net/dsa/Kconfig | 1 + drivers/net/dsa/microchip/ksz_spi.c | 15 +++++++++++++++ 2 files changed, 16 insertions(+)
drivers/net/dsa/Kconfig +1 -0
@@ -100,6 +100,7 @@ config NET_DSA_RZN1_A5PSW config NET_DSA_KS8995 tristate "Micrel KS8995 family 5-ports 10/100 Ethernet switches" depends on SPI + depends on !NET_DSA_MICROCHIP_KSZ_SPI select NET_DSA_TAG_NONE help This driver supports the Micrel KS8995 family of 10/100 Mbit ethernet
drivers/net/dsa/microchip/ksz_spi.c +15 -0
@@ -224,6 +224,21 @@ static void ksz_spi_shutdown(struct spi_device *spi) }static const struct of_device_id ksz_dt_ids[] = { +/* +* Legacy Micrel bindings. In 2015 Microchip acquired +* Micrel which is the originator of the KSZ series, and +* devices branded for Micrel already existed, as well as +* some device tree bindings. These two products are identical +* to the same Microchip products. +*/ + { + .compatible ="micrel,ksz8864" , + .data = &ksz_switch_chips[KSZ8864 ] + }, + { + .compatible ="micrel,ksz8795" , + .data = &ksz_switch_chips[KSZ8795 ] + }, { .compatible ="microchip,ksz8463" , .data = &ksz_switch_chips[KSZ8463 ]
Signature · 1 line
2.54.0
PATCH v6 2/5 dt-bindings: net: dsa: microchip: Add KSZ8995XA
In reply to Linus WalleijThe KSZ8995XA is just like the KSZ8795 and KSZ8864 a Micrel product. It was renamed from KS8995XA to KSZ8995XA at some point, but it has the same properties as the KS8995XA.
Be careful to use the full product name in this new compatible:
there is also KSZ8995MA and KSZ8995E which are not compatible with the KS8995XA.
--- Documentation/devicetree/bindings/net/dsa/microchip,ksz.yaml | 1 + 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/net/dsa/microchip,ksz.yaml +1 -0
@@ -23,6 +23,7 @@ properties: - microchip,ksz8864 # 4-port version of KSZ8895 family switch - microchip,ksz8873 - microchip,ksz8895 # 5-port version of KSZ8895 family switch + - microchip,ksz8995xa - microchip,ksz9477 - microchip,ksz9897 - microchip,ksz9896
Signature · 1 line
2.54.0
PATCH v6 3/5 net: dsa: tag_ks8995: Add the KS8995 tag handling
In reply to Linus WalleijThe KS8995 100Mbit switch can do proper DSA per-port tagging with the proper set-up. This adds the code to handle ingress and egress KS8995 tags.
The tag is a modified 0x8100 ethertype tag where a bit in the last nybble is set for each target port.
--- MAINTAINERS | 1 + include/net/dsa.h | 2 + net/dsa/Kconfig | 6 +++ net/dsa/Makefile | 1 + net/dsa/tag_ks8995.c | 132 +++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 142 insertions(+)
MAINTAINERS +1 -0
@@ -17409,6 +17409,7 @@ F: Documentation/devicetree/bindings/net/dsa/microchip,lan937x.yaml F: drivers/net/dsa/microchip/* F: include/linux/dsa/ksz_common.h F: include/linux/platform_data/microchip-ksz.h +F: net/dsa/tag_ks8995.c F: net/dsa/tag_ksz.c MICROCHIP LAN743X ETHERNET DRIVER
include/net/dsa.h +2 -0
@@ -59,6 +59,7 @@ struct tc_action;#define DSA_TAG_PROTO_MXL_GSW1XX_VALUE 31#define DSA_TAG_PROTO_MXL862_VALUE 32#define DSA_TAG_PROTO_NETC_VALUE 33 +#define DSA_TAG_PROTO_KS8995_VALUE 34enum dsa_tag_protocol {DSA_TAG_PROTO_NONE =DSA_TAG_PROTO_NONE_VALUE ,
@@ -95,6 +96,7 @@ enum dsa_tag_protocol {DSA_TAG_PROTO_MXL_GSW1XX =DSA_TAG_PROTO_MXL_GSW1XX_VALUE ,DSA_TAG_PROTO_MXL862 =DSA_TAG_PROTO_MXL862_VALUE ,DSA_TAG_PROTO_NETC =DSA_TAG_PROTO_NETC_VALUE , + DSA_TAG_PROTO_KS8995 = DSA_TAG_PROTO_KS8995_VALUE, };struct dsa_switch ;
net/dsa/Kconfig +6 -0
@@ -119,6 +119,12 @@ config NET_DSA_TAG_MXL_GSW1XX Say Y or M if you want to enable support for tagging frames for MaxLinear GSW1xx switches. +config NET_DSA_TAG_KS8995 + tristate "Tag driver for Micrel KS8995 switch" + help + Say Y if you want to enable support for tagging frames for the + Micrel KS8995 switch. + config NET_DSA_TAG_KSZ tristate "Tag driver for Microchip 8795/937x/9477/9893 families of switches" help
net/dsa/Makefile +1 -0
@@ -25,6 +25,7 @@ obj-$(CONFIG_NET_DSA_TAG_BRCM_COMMON) += tag_brcm.o obj-$(CONFIG_NET_DSA_TAG_DSA_COMMON) += tag_dsa.o obj-$(CONFIG_NET_DSA_TAG_GSWIP) += tag_gswip.o obj-$(CONFIG_NET_DSA_TAG_HELLCREEK) += tag_hellcreek.o +obj-$(CONFIG_NET_DSA_TAG_KS8995) += tag_ks8995.o obj-$(CONFIG_NET_DSA_TAG_KSZ) += tag_ksz.o obj-$(CONFIG_NET_DSA_TAG_LAN9303) += tag_lan9303.o obj-$(CONFIG_NET_DSA_TAG_MTK) += tag_mtk.o
net/dsa/tag_ks8995.c new file +132 -0
132 lines not on this page · raw message
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH net-next v6 3/5] net: dsa: tag_ks8995: Add the KS8995 tag handling
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Critical] Double free of the socket buffer on the error path in `ks8995_rcv()` when `skb_vlan_untag()`…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Critical] Double free of the socket buffer on the error path in ks8995_rcv() when skb_vlan_untag() fails.
- [High] Unhandled hardware-accelerated VLAN tags bypass clearing and break the required DSA tagging order on transmission. --
commit e089d604a4cbc6ed8eab92ba9931985670f7afbe
Author: Linus Walleij <[email protected]>
net: dsa: tag_ks8995: Add the KS8995 tag handling
The KS8995 100Mbit switch can do proper DSA per-port tagging with the proper set-up. This adds the code to handle ingress and egress KS8995 tags.
Quoted 6 lines
net/dsa/tag_ks8995.c new file +1
-0@@ -0,0 +1,132 @@ +// SPDX-License-Identifier: GPL-2.0
[ ... ]
Quoted 4 lines
net/dsa/tag_ks8995.c new file +4
-0+static struct sk_buff *ks8995_xmit (struct sk_buff *skb,struct net_device *dev) +{ +struct vlan_ethhdr *hdr =vlan_eth_hdr (skb); +bool have_hwaccel_tag = false;
net/dsa/tag_ks8995.c line 39
Quoted 10 lines
net/dsa/tag_ks8995.c new file +10
-0+u16 tci =0 , portmask; + +/* Prepare the special KS8995 tags */ + portmask =dsa_xmit_port_mask (skb, dev); + +if (skb_vlan_tag_present (skb) && skb->vlan_proto ==htons (ETH_P_8021Q )) { + tci =skb_vlan_tag_get (skb); +__vlan_hwaccel_clear_tag (skb); + have_hwaccel_tag = true; + }
[Severity: High]
If a packet has a different hardware-accelerated tag (e.g., 802.1ad Provider Bridge), does it bypass this clearing logic?
The KS8995 switch architecture requires the special DSA tag (STPID) to be the first tag in the Ethernet frame immediately following the MAC addresses.
If the non-802.1Q hwaccel tag is left intact, the conduit network driver will insert the pending hwaccel tag immediately after the MAC addresses, placing it before the KS8995 DSA tag.
Could this cause the switch to fail to parse the DSA tag, leading to misrouted or dropped packets?
[ ... ]
Quoted 19 lines
net/dsa/tag_ks8995.c new file +19
-0+static struct sk_buff *ks8995_rcv (struct sk_buff *skb,struct net_device *dev) +{ +int portmask; +u16 etype; + +/* We are expecting all received packets to have a mangled VLAN +* TPID, so drop anything else. Because of the non-standard TPID, +* don't even bother looking for a tag in the hwaccel area. +* +* We have to inspect the ethertype directly because skb->protocol +* will contain garbage. +*/ + etype =ntohs (*(__be16 *)dsa_etype_header_pos_rx (skb)); +if ((etype &KS8995M_STPID_STD ) !=ETH_P_8021Q ) { +netdev_dbg (dev,"%s: dropped ethertype 0x%04x\n" , + __func__, etype); +return NULL ; + } + netdev_dbg(dev, "%s: received ethertype %04x\n",
net/dsa/tag_ks8995.c line 87
Quoted 10 lines
net/dsa/tag_ks8995.c new file +10
-0+ __func__, etype); + +/* Move the custom DSA+VLAN tag into the hwaccel area and strip +* it from the skb head +*/ + skb =skb_vlan_untag (skb); +if (!skb) { +netdev_err (dev,"%s: unable to untag skb\n" , __func__); +return NULL ; + }
[Severity: Critical]
Does this result in a double-free?
If skb_vlan_untag() fails, it frees the skb internally and returns NULL. ks8995_rcv() then returns NULL to the DSA core function dsa_switch_rcv().
The API contract for the DSA .rcv callback dictates that it must not free the original skb if it returns an error (NULL), because dsa_switch_rcv() will call kfree_skb() on the original skb pointer when receiving a NULL return.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Re: [PATCH net-next v6 3/5] net: dsa: tag_ks8995: Add the KS8995 tag handling
Quoted 3 lines · On Tue, Jun 9, 2026 at 12:42 AM <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Critical] Double free of the socket buffer on the error path inks8995_rcv()whenskb_vlan_untag()fails.
- [High] Unhandled hardware-accelerated VLAN tags bypass clearing and break the required DSA tagging order on transmission.
No.
This is how other taggers do it.
If something is wrong it points to a bigger problem.
Yours,
Linus Walleij
Jakub Kicinski
maintainerRe: [PATCH net-next v6 3/5] net: dsa: tag_ks8995: Add the KS8995 tag handling
In reply to Linus WalleijThis is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
net: dsa: tag_ks8995: Add the KS8995 tag handling
Adds a new DSA tagger for the Micrel/Microchip KS8995XA switch using a modified 0x8100 ethertype where the lower nybble encodes a port bitmap. The patch wires the new tagger into the DSA core, Kconfig, Makefile and MAINTAINERS.
A few questions inline below.
Quoted 6 lines
net/dsa/tag_ks8995.c new file +0
-0@@ -0,0 +1,132 @@
[ ... ]
Quoted 4 lines
net/dsa/tag_ks8995.c new file +4
-0+static struct sk_buff *ks8995_xmit (struct sk_buff *skb,struct net_device *dev) +{ +struct vlan_ethhdr *hdr =vlan_eth_hdr (skb); +bool have_hwaccel_tag = false;
net/dsa/tag_ks8995.c line 39
Quoted 10 lines
net/dsa/tag_ks8995.c new file +10
-0+u16 tci =0 , portmask; + +/* Prepare the special KS8995 tags */ + portmask =dsa_xmit_port_mask (skb, dev); + +if (skb_vlan_tag_present (skb) && skb->vlan_proto ==htons (ETH_P_8021Q )) { + tci =skb_vlan_tag_get (skb); +__vlan_hwaccel_clear_tag (skb); + have_hwaccel_tag = true; + }
[Low]
What is intended to happen if the skb arrives with both a hwaccel VLAN tag and an in-head 0x8100 tag, or with a hwaccel tag whose vlan_proto is something other than 0x8100 (for example 0x88a8 service tag)?
In those cases this branch leaves the hwaccel tag alone or only consumes it conditionally, and the second branch below either inserts a fresh in-head tag while keeping a pre-existing in-head 0x8100, or modifies the in-head 0x8100 while a non-8021Q hwaccel tag is still attached. Should this path either reject such frames or normalise them first?
net/dsa/tag_ks8995.c line 44
Quoted 5 lines
net/dsa/tag_ks8995.c new file +5
-0+ +if (have_hwaccel_tag || hdr->h_vlan_proto !=htons (ETH_P_8021Q )) { + skb =vlan_insert_tag (skb,KS8995M_STPID (portmask), tci); +if (!skb) +return NULL ;
[High]
Is returning NULL here safe?
include/linux/if_vlan.h documents that vlan_insert_tag() calls dev_kfree_skb_any(skb) on failure (e.g. when skb_cow_head() fails under memory pressure) and returns NULL. The caller in net/dsa/user.c does:
nskb = p->xmit(skb, dev);
if (!nskb) {
kfree_skb(skb);
return NETDEV_TX_OK;
}so on the NULL return dsa_user_xmit() runs kfree_skb() on its local pointer that vlan_insert_tag() has already freed. Doesn't that produce a use-after-free on skb->users plus a double free?
Should this path swallow the free done by vlan_insert_tag() (e.g. by returning a sentinel handled by the caller) so dsa_user_xmit() does not re-free the skb?
Quoted 33 lines
net/dsa/tag_ks8995.c new file +33
-0+ hdr =vlan_eth_hdr (skb); +netdev_dbg (dev,"%s: inserted VLAN TAG %04x TCI %04x\n" , + __func__, hdr->h_vlan_proto, hdr->h_vlan_TCI); + }else { +/* VLAN tag already exists in skb head, modify it in place */ + hdr =vlan_eth_hdr (skb); + hdr->h_vlan_proto =KS8995M_STPID (portmask); +netdev_dbg (dev,"%s: modified VLAN TAG %04x\n" , + __func__, hdr->h_vlan_proto); + } + +return skb; +} + +static struct sk_buff *ks8995_rcv (struct sk_buff *skb,struct net_device *dev) +{ +int portmask; +u16 etype; + +/* We are expecting all received packets to have a mangled VLAN +* TPID, so drop anything else. Because of the non-standard TPID, +* don't even bother looking for a tag in the hwaccel area. +* +* We have to inspect the ethertype directly because skb->protocol +* will contain garbage. +*/ + etype =ntohs (*(__be16 *)dsa_etype_header_pos_rx (skb)); +if ((etype &KS8995M_STPID_STD ) !=ETH_P_8021Q ) { +netdev_dbg (dev,"%s: dropped ethertype 0x%04x\n" , + __func__, etype); +return NULL ; + } + netdev_dbg(dev, "%s: received ethertype %04x\n",
net/dsa/tag_ks8995.c line 87
Quoted 10 lines
net/dsa/tag_ks8995.c new file +10
-0+ __func__, etype); + +/* Move the custom DSA+VLAN tag into the hwaccel area and strip +* it from the skb head +*/ + skb =skb_vlan_untag (skb); +if (!skb) { +netdev_err (dev,"%s: unable to untag skb\n" , __func__); +return NULL ; + }
[High]
Is the NULL return here compatible with the cpu_dp->rcv contract?
skb_vlan_untag() can take its err_free path (e.g. when the pskb_may_pull(VLAN_HLEN + sizeof(unsigned short)) inside it fails, or skb_reorder_vlan_header() fails) which calls kfree_skb(skb) and returns NULL.
The caller in net/dsa/tag.c is:
skb = skb_unshare(skb, GFP_ATOMIC);
...
nskb = cpu_dp->rcv(skb, dev);
...
if (!nskb) {
kfree_skb(skb);
return 0;
}so when ks8995_rcv() returns NULL after skb_vlan_untag() has already freed its argument, dsa_switch_rcv() ends up calling kfree_skb() on a freed skb. Wouldn't that be a use-after-free on skb->users plus a double free?
Other cpu_dp->rcv handlers appear to assume that returning NULL means the skb was not freed. Should this handler do something equivalent so the contract still holds?
net/dsa/tag_ks8995.c line 94
Quoted 7 lines
net/dsa/tag_ks8995.c new file +7
-0+ + portmask =FIELD_GET (KS8995M_STPID_PORTMASK , etype); +netdev_dbg (dev,"%s: etype %04x portmask %04x (%d)\n" , + __func__, etype, portmask,ilog2 (portmask)); + skb->dev =dsa_conduit_find_user (dev,0 ,ilog2 (portmask)); +if (!skb->dev) +return NULL ;
[Low, Low]
A literal 0x8100 frame from the wire passes the
(etype & GENMASK(15,4)) != ETH_P_8021Q gate above, in which case FIELD_GET(GENMASK(3,0), 0x8100) is 0 and ilog2(0) is computed (and also passed as a netdev_dbg() argument). The frame is only dropped because dsa_conduit_find_user() happens not to match port -1.
Would an explicit check be clearer:
portmask = FIELD_GET(KS8995M_STPID_PORTMASK, etype);
if (!portmask)
return NULL;The commit message says "a bit in the last nybble is set for each target port", suggesting bitmap semantics, but ilog2(portmask) on ingress only handles a single bit and silently picks the highest set bit if more than one is set. Would an is_power_of_2(portmask) sanity check be appropriate here?
Quoted 9 lines
net/dsa/tag_ks8995.c new file +9
-0+ +/* Preserve the VLAN tag if it contains a non-zero VID which is not +* identical to 0x001, or PCP, and restore its TPID to the standard +* value. +* +* If this is just an ordinary inbound package the datasheet claims +* it will "replace null VID with ingress port VID", which means +* VID set to 1: 0x8101 0001 for port 0 or 0x8102 0001 for port 1. +* So in the DSA driver we will set the default port VID to 0 so
net/dsa/tag_ks8995.c line 113
Quoted 10 lines
net/dsa/tag_ks8995.c new file +10
-0+* we can properly detect non-VLAN frames. +*/ +if (!skb->vlan_tci) { +netdev_dbg (dev,"%s: clear VLAN tag from frame\n" , __func__); +__vlan_hwaccel_clear_tag (skb); + }else { + skb->vlan_proto =htons (ETH_P_8021Q ); +netdev_dbg (dev,"%s: vlan_tci = 0x%04x VLAN frame\n" , + __func__, skb->vlan_tci); + }
[Low]
The comment says
Preserve the VLAN tag if it contains a non-zero VID which is not identical to 0x001, or PCP
but the code only tests:
if (!skb->vlan_tci)
That matches VID == 0 and PCP == 0 and DEI == 0 only, so frames with VID == 1 (the chip's "replace null VID with ingress port VID" default) fall through into the "preserve as a VLAN frame" branch instead of being stripped. Should the comment and the code be reconciled, or should the test also strip VID == 1 frames so the behaviour does not depend on the switch driver also forcing the default port VID to 0?
Quoted 5 lines
net/dsa/tag_ks8995.c new file +5
-0+ +dsa_default_offload_fwd_mark (skb); + +return skb; +}
Signature · 1 line
pw-bot: cr
Re: [PATCH net-next v6 3/5] net: dsa: tag_ks8995: Add the KS8995 tag handling
DSA maintainers, look into this analysis a bit below, the conclusion is that taggers can't re-use vlan_* helpers because they free the SKB:s on error, so maybe I need to create new derivative functions to reuse these.
Quoted 2 lines · Jakub Kicinski
This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
Fair enough.
Quoted 20 lines
Quoted 4 lines
net/dsa/tag_ks8995.c new file +4
-0+static struct sk_buff *ks8995_xmit (struct sk_buff *skb,struct net_device *dev) +{ +struct vlan_ethhdr *hdr =vlan_eth_hdr (skb); +bool have_hwaccel_tag = false;net/dsa/tag_ks8995.c line 39
Quoted 10 lines
net/dsa/tag_ks8995.c new file +10
-0+u16 tci =0 , portmask; + +/* Prepare the special KS8995 tags */ + portmask =dsa_xmit_port_mask (skb, dev); + +if (skb_vlan_tag_present (skb) && skb->vlan_proto ==htons (ETH_P_8021Q )) { + tci =skb_vlan_tag_get (skb); +__vlan_hwaccel_clear_tag (skb); + have_hwaccel_tag = true; + }[Low]
What is intended to happen if the skb arrives with both a hwaccel VLAN tag and an in-head0x8100tag, or with a hwaccel tag whosevlan_protois something other than0x8100(for example0x88a8service tag)?
Quoted 5 lines
In those cases this branch leaves the hwaccel tag alone or only consumes it conditionally, and the second branch below either inserts a fresh in-head tag while keeping a pre-existing in-head
0x8100, or modifies the in-head0x8100while a non-8021Q hwaccel tag is still attached. Should this path either reject such frames or normalise them first?
I have no idea what "normalise" means in this context.
What happens to e.g. a 88a8 service tag is that it gets forwarded to the target port using the modified vlan tag added by vlan_insert_tag() below, I think part of the AI confusion here is coming from the fact that we are using modified "vlan tags" and the semantics does not fit the common pattern, and the statistics that are used in the training data become irrelevant.
The whole point of the code is to modify pre-existing ETH_P_8021Q tags in-place rather than adding a second one, which means that everything else will get a second tag, the sole function of which is to direct the packet to the right port, where it will be stripped by the hardware.
Quoted 12 lines
net/dsa/tag_ks8995.c line 44
Quoted 4 lines
net/dsa/tag_ks8995.c new file +4
-0+if (have_hwaccel_tag || hdr->h_vlan_proto !=htons (ETH_P_8021Q )) { + skb =vlan_insert_tag (skb,KS8995M_STPID (portmask), tci); +if (!skb) +return NULL ;[High]
Is returning NULL here safe?
include/linux/if_vlan.hdocuments thatvlan_insert_tag()callsdev_kfree_skb_any(skb)on failure (e.g. whenskb_cow_head()fails under memory pressure) and returns NULL. The caller innet/dsa/user.cdoes:
Quoted 8 lines
nskb = p->xmit(skb, dev); if (!nskb) { kfree_skb(skb); return NETDEV_TX_OK; }so on the NULL return
dsa_user_xmit()runskfree_skb()on its local pointer thatvlan_insert_tag()has already freed.
vlan_insert_tag()
vlan_insert_inner_tag() <- returns NULL on error
__vlan_insert_inner_tag()
Quoted 6 lines
Doesn't that produce a
use-after-free onskb->usersplus a double free?Should this path swallow the free done by
vlan_insert_tag()(e.g. by returning a sentinel handled by the caller) sodsa_user_xmit()does not re-free the skb?
I looked into this.
The fact that several taggers do this in ->xmit() such as here in tag_8021q.c:
struct sk_buff *dsa_8021q_xmit(struct sk_buff *skb, struct net_device *netdev,
u16 tpid, u16 tci)
{
/* skb->data points at the MAC header, which is fine
* for vlan_insert_tag().
*/
return vlan_insert_tag(skb, htons(tpid), tci);
}should be a sign that this is OK in xmit:
return vlan_insert_tag(skb,...);
which is equivalent to:
skb = vlan_insert_tag(skb,...);
if (!skb)
return skb;which is equivalent to:
skb = vlan_insert_tag(skb,...);
if (!skb)
return NULL;Which is what I do.
So yeah. skb_free() will be free:ed twice. The code in tag_8021q.c will also do that. But what do you expect ->xmit() to return on error if not NULL?
When user.c does this:
/* Transmit function may have to reallocate the original SKB,
* in which case it must have freed it. Only free it here on error.
*/
nskb = p->xmit(skb, dev);
if (!nskb) {
kfree_skb(skb);
return NETDEV_TX_OK;
}
return dsa_enqueue_skb(nskb, dev);The only way to get clean out of this branch if you run into an error in ->xmit() is to return NULL!
Now let's look at ->rcv():
Quoted 28 lines
net/dsa/tag_ks8995.c line 87
Quoted 8 lines
net/dsa/tag_ks8995.c new file +8
-0+/* Move the custom DSA+VLAN tag into the hwaccel area and strip +* it from the skb head +*/ + skb =skb_vlan_untag (skb); +if (!skb) { +netdev_err (dev,"%s: unable to untag skb\n" , __func__); +return NULL ; + }[High]
Is the NULL return here compatible with thecpu_dp->rcvcontract?
skb_vlan_untag()can take itserr_freepath (e.g. when thepskb_may_pull(VLAN_HLEN + sizeof(unsigned short))inside it fails, orskb_reorder_vlan_header()fails) which callskfree_skb(skb)and returns NULL.The caller in
net/dsa/tag.cis:skb = skb_unshare(skb, GFP_ATOMIC); ... nskb = cpu_dp->rcv(skb, dev); ... if (!nskb) { kfree_skb(skb); return 0; }
Quoted 8 lines
so when
ks8995_rcv()returns NULL afterskb_vlan_untag()has already freed its argument,dsa_switch_rcv()ends up callingkfree_skb()on a freed skb. Wouldn't that be a use-after-free onskb->usersplus a double free?Other
cpu_dp->rcvhandlers appear to assume that returning NULL means the skb was not freed. Should this handler do something equivalent so the contract still holds?
Yes skb_vlan_untag() will free the skb on error and then this will free the tag again.
But how do you signal to the caller in net/dsa/tag.c that "things went sidewise and the SKB is already free:ed"?
So these semantics around ->xmit() and ->rcv() free:in the skb on a NULL return basically challenges Vladimir's request that I reuse these functions in the first place. They are not made for this kind of reuse.
What I *CAN* do is go and create wrappers in skbuff.h/c that will not free the skb on error just return NULL anyway, intended for this one user (to begin with), such as
vlan_insert_tag_no_free_skb_on_error();skb_vlan_untag_no_free_skb_on_errror()
I honestly think these are good names because there is no risk to misunderstand them...
But then I want some buy-in from the maintainers that this is the way to go.
Yours,
Linus Walleij
Jakub Kicinski
maintainerRe: [PATCH net-next v6 3/5] net: dsa: tag_ks8995: Add the KS8995 tag handling
Quoted 19 lines · On Sat, 13 Jun 2026 18:56:03 +0200 Linus Walleij wrote:
Which is what I do.
So yeah.
skb_free()will be free:ed twice. The code intag_8021q.cwill also do that. But what do you expect ->xmit() to return on error if not NULL?When
user.cdoes this:/* Transmit function may have to reallocate the original SKB, * in which case it must have freed it. Only free it here on error. */ nskb = p->xmit(skb, dev); if (!nskb) { kfree_skb(skb); return NETDEV_TX_OK; } return dsa_enqueue_skb(nskb, dev);
Quoted 2 lines
The only way to get clean out of this branch if you run into an error in ->xmit() is to return NULL!
Yes, maybe DSA experts remember the background here, and can guide us But from a fresh look this and ->rcv have very odd semantics.
nskb = func(skb);
should assume skb is either freed or returned. Freeing the input param on failure of func() is a rather strange pattern.
I vote we drop these kfree_skb()s (both xmit and rcv) and fix up any driver that depended on them (if any)?
PATCH v6 4/5 net: dsa: microchip: Support Microchip KSZ8995XA / KS8995XA
In reply to Linus WalleijThis adds support for the Microchip KSZ8995XA also known as the Micrel KS8995XA switch to the KSZ driver.
Notice: there are also KSZ8995E and KSZ8995MA. These are BOTH different from the KSZ8995XA.
The helper macros are named ksz_is_ksz8995xa() to make it possible to add E and MA support in the future.
--- drivers/net/dsa/microchip/Kconfig | 1 + drivers/net/dsa/microchip/ksz8.c | 177 +++++++++++++++++++++++----- drivers/net/dsa/microchip/ksz8.h | 2 + drivers/net/dsa/microchip/ksz8_reg.h | 7 ++ drivers/net/dsa/microchip/ksz_common.c | 58 +++++++-- drivers/net/dsa/microchip/ksz_common.h | 11 +- drivers/net/dsa/microchip/ksz_spi.c | 18 ++- include/linux/platform_data/microchip-ksz.h | 1 + 8 files changed, 236 insertions(+), 39 deletions(-)
drivers/net/dsa/microchip/Kconfig +1 -0
@@ -2,6 +2,7 @@ menuconfig NET_DSA_MICROCHIP_KSZ_COMMON tristate "Microchip KSZ8XXX/KSZ9XXX/LAN937X series switch support" depends on NET_DSA + select NET_DSA_TAG_KS8995 select NET_DSA_TAG_KSZ select NET_DSA_TAG_NONE select NET_IEEE8021Q_HELPERS
drivers/net/dsa/microchip/ksz8.c +148 -29
319 lines not on this page · raw message
drivers/net/dsa/microchip/ksz8.h +2 -0
@@ -12,11 +12,13 @@#include <net/dsa.h> #include "ksz_common.h" +extern const struct ksz_dev_ops ksz8995xa_dev_ops;extern const struct ksz_dev_ops ksz8463_dev_ops;extern const struct ksz_dev_ops ksz87xx_dev_ops;extern const struct ksz_dev_ops ksz88xx_dev_ops;extern const struct phylink_mac_ops ksz88x3_phylink_mac_ops;extern const struct phylink_mac_ops ksz8_phylink_mac_ops; +extern const struct dsa_switch_ops ksz8995xa_switch_ops;extern const struct dsa_switch_ops ksz8463_switch_ops;extern const struct dsa_switch_ops ksz87xx_switch_ops;extern const struct dsa_switch_ops ksz88xx_switch_ops;
drivers/net/dsa/microchip/ksz8_reg.h +7 -0
@@ -30,6 +30,11 @@#define KSZ88X3_REG_FVID_AND_HOST_MODE 0xC6#define KSZ88X3_PORT3_RMII_CLK_INTERNAL BIT(3) +#define REG_SW_ID_0 0x00 +#define REG_SW_ID_1 0x01 + +#define SW_START_SWITCH BIT(0) +#define REG_SW_CTRL_0 0x02#define SW_NEW_BACKOFF BIT(7)
@@ -95,6 +100,8 @@#define SW_LED_LINK_ACT_DUPLEX 2#define SW_LED_LINK_DUPLEX 3 +#define SW_SPECIAL_TAG BIT(0)/* KSZ8995XA only */ +#define REG_SW_CTRL_10 0x0C#define SW_PASS_PAUSE BIT(0)
drivers/net/dsa/microchip/ksz_common.c +51 -7
103 lines not on this page · raw message
drivers/net/dsa/microchip/ksz_common.h +10 -1
@@ -235,6 +235,7 @@ enum ksz_model {KSZ88X3 ,KSZ8864 ,KSZ8895 , +KSZ8995XA ,KSZ9477 ,KSZ9896 , KSZ9897,
@@ -751,7 +752,13 @@ static inline bool ksz_is_ksz88x3(struct ksz_device *dev)static inline bool ksz_is_8895_family (struct ksz_device *dev) {return dev->chip_id ==KSZ8895_CHIP_ID || - dev->chip_id ==KSZ8864_CHIP_ID ; + dev->chip_id ==KSZ8864_CHIP_ID || + dev->chip_id ==KSZ8995XA_CHIP_ID ; +} + +static inline bool ksz_is_ksz8995xa (struct ksz_device *dev) +{ +return dev->chip_id ==KSZ8995XA_CHIP_ID ; }static inline bool is_ksz8 (struct ksz_device *dev)
@@ -822,6 +829,7 @@ static inline bool ksz_is_sgmii_port(struct ksz_device *dev, int port)#define KSZ87_CHIP_ID_94 0x6#define KSZ87_CHIP_ID_95 0x9#define KSZ88_CHIP_ID_63 0x3 +#define KSZ8895_CHIP_ID_95XA 0x0#define KSZ8895_CHIP_ID_95 0x4#define KSZ8895_CHIP_ID_95R 0x6
@@ -885,6 +893,7 @@ static inline bool ksz_is_sgmii_port(struct ksz_device *dev, int port)#define KSZ8863_HUGE_PACKET_SIZE 1916#define KSZ8863_NORMAL_PACKET_SIZE 1536#define KSZ8_LEGAL_PACKET_SIZE 1518 +#define KSZ8995XA_LEGAL_PACKET_SIZE 1522#define KSZ9477_MAX_FRAME_SIZE 9000#define KSZ8873_REG_GLOBAL_CTRL_12 0x0e
drivers/net/dsa/microchip/ksz_spi.c +16 -2
@@ -161,7 +161,8 @@ static int ksz_spi_probe(struct spi_device *spi) chip->chip_id == KSZ8794_CHIP_ID || chip->chip_id == KSZ8765_CHIP_ID) regmap_config = ksz8795_regmap_config; - else if (chip->chip_id == KSZ8895_CHIP_ID || + else if (chip->chip_id == KSZ8995XA_CHIP_ID || + chip->chip_id == KSZ8895_CHIP_ID || chip->chip_id == KSZ8864_CHIP_ID) regmap_config = ksz8863_regmap_config; else
@@ -185,7 +186,10 @@ static int ksz_spi_probe(struct spi_device *spi) dev->pdata = spi->dev.platform_data;/* setup spi */ - spi->mode =SPI_MODE_3 ; +if (chip->chip_id ==KSZ8995XA_CHIP_ID ) + spi->mode =SPI_MODE_0 ; +else + spi->mode =SPI_MODE_3 ; ret =spi_setup (spi);if (ret)return ret;
@@ -239,6 +243,10 @@ static const struct of_device_id ksz_dt_ids[] = { .compatible = "micrel,ksz8795", .data = &ksz_switch_chips[KSZ8795 ] }, + { + .compatible = "micrel,ks8995", + .data = &ksz_switch_chips[KSZ8995XA ] + }, { .compatible ="microchip,ksz8463" , .data = &ksz_switch_chips[KSZ8463]
@@ -271,6 +279,10 @@ static const struct of_device_id ksz_dt_ids[] = { .compatible = "microchip,ksz8895", .data = &ksz_switch_chips[KSZ8895 ] }, + { + .compatible = "microchip,ksz8995xa", + .data = &ksz_switch_chips[KSZ8995XA ] + }, { .compatible ="microchip,ksz9477" , .data = &ksz_switch_chips[KSZ9477]
@@ -332,6 +344,7 @@ static const struct of_device_id ksz_dt_ids[] = {MODULE_DEVICE_TABLE (of, ksz_dt_ids);static const struct spi_device_id ksz_spi_ids[] = { + {"ks8995" }, {"ksz8463" }, {"ksz8765" }, {"ksz8794" },
@@ -340,6 +353,7 @@ static const struct spi_device_id ksz_spi_ids[] = { { "ksz8864" }, { "ksz8873" }, { "ksz8895" }, + { "ksz8995" }, { "ksz9477" }, { "ksz9896" }, { "ksz9897" },
include/linux/platform_data/microchip-ksz.h +1 -0
@@ -31,6 +31,7 @@ enum ksz_chip_id {KSZ88X3_CHIP_ID =0x8830 ,KSZ8864_CHIP_ID =0x8864 ,KSZ8895_CHIP_ID =0x8895 , +KSZ8995XA_CHIP_ID =0x8995 ,KSZ9477_CHIP_ID =0x00947700 ,KSZ9896_CHIP_ID =0x00989600 , KSZ9897_CHIP_ID = 0x00989700,
Signature · 1 line
2.54.0
Jakub Kicinski
maintainerRe: [PATCH net-next v6 4/5] net: dsa: microchip: Support Microchip KSZ8995XA / KS8995XA
This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
net: dsa: microchip: Support Microchip KSZ8995XA / KS8995XA
This patch adds support for the Microchip KSZ8995XA (a.k.a. Micrel KS8995XA) switch to the KSZ DSA driver, introducing a new chip entry, a restricted dev_ops/switch_ops set, and a ksz_is_ksz8995xa() helper for future KSZ8995E/MA differentiation.
Quoted 6 lines
drivers/net/dsa/microchip/ksz8.c +0
-0@@ -137,7 +138,18 @@ static int ksz8_pme_pwrite8(struct ksz_device *dev, int port, int offset, u8 dat
drivers/net/dsa/microchip/ksz8.c static int ksz8_pme_pwrite8(struct ksz_device *dev, int port, int offset, u8 dat · line 147
Quoted 10 lines
drivers/net/dsa/microchip/ksz8.c +7
-1static int ksz8_reset_switch (struct ksz_device *dev) { -if (ksz_is_ksz88x3 (dev)) { +if (ksz_is_ksz8995xa (dev)) { +unsigned int port; + +/* KSZ8995XA is "reset" by stopping the switch and starting it */ +ksz_cfg (dev,REG_SW_ID_1 ,SW_START_SWITCH , false); +usleep_range (10 ,100 ); +ksz_cfg (dev,REG_SW_ID_1 ,SW_START_SWITCH , true);
[Medium]
For KSZ8995XA, ksz8_reset_switch() asserts SW_START_SWITCH before ksz8_setup() programs broadcast storm rate, REG_SW_CTRL_2, REG_SW_CTRL_9 SW_SPECIAL_TAG, port-membership and the PORT_INSERT_TAG/PORT_REMOVE_TAG bits. Other variants in this same file (for example ksz88x3) keep the forwarding engine quiescent during configuration and only assert SW_START at the end of ksz8_setup() via:
regmap_update_bits(ksz_regmap_8(dev), regs[S_START_CTRL],
SW_START, SW_START);For KSZ8995XA, ksz8995xa_regs has [S_START_CTRL] = 0x01, the same register written here, so by the time ksz8_setup() reaches its final "start switch" step the engine has been forwarding throughout the reconfiguration window. Is that intentional? Could the switch be left stopped here and only started at the end of ksz8_setup() like the other variants?
drivers/net/dsa/microchip/ksz8.c static int ksz8_pme_pwrite8(struct ksz_device *dev, int port, int offset, u8 dat · line 151
Quoted 4 lines
drivers/net/dsa/microchip/ksz8.c +4
-0+ +/* Often boot loaders have fun with ports, so reset them */ +for (port =0 ; port < dev->info->port_cnt; port++) +ksz_port_cfg (dev, port,0x0f ,BIT (4 ), true);
[Medium]
This writes BIT(4) at port-relative offset 0x0F once per port and never clears it, with no readback or settling delay before the rest of the setup proceeds to read/write port registers. If that bit is a level-triggered reset, every port is left held in reset; if it is self-clearing or a feature bit, the code happens to work.
The KSZ8863 path in this same function explicitly clears its reset bit:
ksz_cfg(dev, KSZ8863_REG_SW_RESET,
KSZ8863_GLOBAL_SOFTWARE_RESET | KSZ8863_PCS_RESET, true);
ksz_cfg(dev, KSZ8863_REG_SW_RESET,
KSZ8863_GLOBAL_SOFTWARE_RESET | KSZ8863_PCS_RESET, false);and the KSZ87xx path uses an explicit power-down/power-up pair. Could this code use named macros in ksz8_reg.h (matching the other named constants added in this patch like SW_SPECIAL_TAG, SW_START_SWITCH, PORT_INSERT_TAG, PORT_REMOVE_TAG) and document whether the bit is self-clearing or whether a paired clear is needed?
Quoted 4 lines
drivers/net/dsa/microchip/ksz8.c +1
-0+ }else if (ksz_is_ksz88x3 (dev)) {/* reset switch */ ksz_cfg (dev,KSZ8863_REG_SW_RESET ,KSZ8863_GLOBAL_SOFTWARE_RESET |KSZ8863_PCS_RESET , true);
[ ... ]
drivers/net/dsa/microchip/ksz8.c static void ksz8_port_setup(struct ksz_device *dev, int port, bool cpu_port) · line 1733
Quoted 7 lines
drivers/net/dsa/microchip/ksz8.c +2
-1@@ -1693,14 +1729,16 @@ static void ksz8_port_setup(struct ksz_device *dev, int port, bool cpu_port) offset =P1CR1 ;ksz_port_cfg (dev, port, offset,PORT_BROADCAST_STORM , true); -ksz8_port_queue_split (dev, port, dev->info->num_tx_queues); +if (!ksz_is_ksz8995xa (dev)) { +ksz8_port_queue_split (dev, port, dev->info->num_tx_queues);
[Medium]ksz_chip_data for KSZ8995XA sets .num_tx_queues = 4, and ksz8_setup() unconditionally does:
ds->num_tx_queues = dev->info->num_tx_queues;
But ksz8_port_setup() now skips ksz8_port_queue_split() for KSZ8995XA, so the chip's queue-split hardware registers are left at their power-on default while DSA is told there are 4 TX queues. If the default is not a 4-queue split, classification decisions made by the stack (priority/PCP/DSCP-to-queue mapping) will not correspond to the queues the hardware actually uses.
Should .num_tx_queues reflect the actual default for this chip, or should the queue-split registers be programmed?
[ ... ]
Quoted 12 lines
drivers/net/dsa/microchip/ksz_common.c +4
-0@@ -1485,6 +1499,21 @@ const struct ksz_chip_data ksz_switch_chips[] = { .internal_phy = {true, true, true, true, false}, }, + [KSZ8995XA] = { + .chip_id =KSZ8995XA_CHIP_ID ,/* Also known as KS8995XA */ + .dev_name = "KSZ8995XA", + .cpu_ports = 0x10, /* can be configured as cpu port */
drivers/net/dsa/microchip/ksz_common.c const struct ksz_chip_data ksz_switch_chips[] = { · line 1515
Quoted 10 lines
drivers/net/dsa/microchip/ksz_common.c +10
-0+ .port_cnt = 5, /* total cpu and user ports */ + .num_tx_queues = 4, + .num_ipms = 4, + .ops = &ksz8995xa_dev_ops, + .switch_ops = &ksz8995xa_switch_ops, + .phylink_mac_ops = &ksz88x3_phylink_mac_ops, + .regs = ksz8995xa_regs, + .supports_mii = {true, true, true, true, true}, + .internal_phy = {true, true, true, true, false}, + },
[Low]
The KSZ8995XA chip data omits .num_vlans, .num_alus, and .num_statics, so they default to 0. ksz8_setup() then unconditionally calls:
dev->vlan_cache = devm_kcalloc(dev->dev, sizeof(struct vlan_table),
dev->info->num_vlans, GFP_KERNEL);
if (!dev->vlan_cache)
return -ENOMEM;devm_kcalloc with n = 0 returns ZERO_SIZE_PTR, which is non-NULL and therefore not caught by the !dev->vlan_cache check. Today every dereference of vlan_cache is gated by !ksz_is_ksz8995xa(dev) or by the absence of VLAN ops in ksz8995xa_switch_ops, so there is no crash, but any future shared helper that touches vlan_cache without a chip-id gate would dereference ZERO_SIZE_PTR.
Could the allocation be skipped for KSZ8995XA, or could .num_vlans be set to a value that makes the !NULL check meaningful?
[ ... ]
drivers/net/dsa/microchip/ksz_common.c void ksz_init_mib_timer(struct ksz_device *dev) · line 2862
Quoted 9 lines
drivers/net/dsa/microchip/ksz_common.c +4
-0@@ -2826,6 +2855,10 @@ void ksz_init_mib_timer(struct ksz_device *dev) {int i; +/* KSZ8995XA lacks MiB features */ +if (ksz_is_ksz8995xa (dev)) +return ; +INIT_DELAYED_WORK (&dev->mib_read, ksz_mib_read_work);
[Low]
This early return skips INIT_DELAYED_WORK(&dev->mib_read, ...). The patch then relies on the undocumented invariant that mib_read_interval == 0 means dev->mib_read must not be touched.
ksz_suspend()/ksz_resume() in ksz_common.c call cancel_delayed_work_sync(&dev->mib_read) and schedule_delayed_work(&dev->mib_read, ...) without any chip-id gate. ksz8995xa_switch_ops happens to omit .suspend/.resume today, so there is no current crash, but any future addition of those ops or any other unguarded user of dev->mib_read on this chip will operate on uninitialised work_struct memory.
Would it be safer to call INIT_DELAYED_WORK unconditionally and only skip the schedule for KSZ8995XA?
[ ... ]
drivers/net/dsa/microchip/ksz_common.c int ksz_switch_register(struct ksz_device *dev) · line 4706
Quoted 8 lines
drivers/net/dsa/microchip/ksz_common.c +4
-0@@ -4662,6 +4700,10 @@ int ksz_switch_register(struct ksz_device *dev)if (ret)return ret; +/* Override ops with something simpler for this legacy chip */ +if (ksz_is_ksz8995xa (dev)) + dev->ds->ops = &ksz8995xa_switch_ops; +
[Low]
Is this assignment a no-op in the supported flow? ksz_switch_alloc() has already set ds->ops = chip->switch_ops, and ksz_switch_chips[KSZ8995XA].switch_ops is &ksz8995xa_switch_ops, so the same pointer is being written back.
The comment "Override ops with something simpler for this legacy chip" implies a transformation that does not actually occur, and no other chip in the family does this. Could this hunk be dropped, or the comment reworded to match what the code does?
drivers/net/dsa/microchip/ksz_common.h static inline bool ksz_is_ksz88x3(struct ksz_device *dev) · line 757
Quoted 12 lines
drivers/net/dsa/microchip/ksz_common.h +2
-1@@ -751,7 +752,13 @@ static inline bool ksz_is_ksz88x3(struct ksz_device *dev)static inline bool ksz_is_8895_family (struct ksz_device *dev) {return dev->chip_id ==KSZ8895_CHIP_ID || - dev->chip_id ==KSZ8864_CHIP_ID ; + dev->chip_id ==KSZ8864_CHIP_ID || + dev->chip_id ==KSZ8995XA_CHIP_ID ; }
[Low]
This silently expands ksz_is_8895_family() to include KSZ8995XA, which through is_ksz8()/is_ksz88xx() classifies the new chip as an 8895 family member across ksz_dcb.c, ksz8.c and ksz_common.c.
Today every potentially-divergent path is explicitly gated by ksz_is_ksz8995xa() opt-outs or by the dev->ds->ops override, but this "opt in via family helper, then opt out via per-chip checks" pattern is brittle: future helper-driven logic touching the 8895 family will silently include KSZ8995XA, and comments such as "/* KSZ8864, KSZ8895 */" in ksz88xx_get_tag_protocol/ksz88xx_connect_tag_protocol become inaccurate.
The commit message also does not acknowledge this expansion or explain why a feature-bit approach in ksz_chip_data was not used, especially given that the KSZ8995E/MA variants are mentioned as future work. Could the commit message cover this design choice, or could the family classification be reconsidered?
PATCH v6 5/5 net: dsa: ks8995: Delete surplus driver
In reply to Linus WalleijThe Microchip ksz driver now handles all switches that the old driver was handling, but better.
Delete the old driver, but leave a stub behind in Kconfig so new users will be automatically phased over to the new symbol when migrating their configs.
The old driver supports platform data (board file) instantiation, but nothing in the kernel tree makes use of this legacy mechanism so it is fine to delete.
--- drivers/net/dsa/Kconfig | 10 +- drivers/net/dsa/Makefile | 1 - drivers/net/dsa/ks8995.c | 857 ----------------------------------------------- 3 files changed, 6 insertions(+), 862 deletions(-)
drivers/net/dsa/Kconfig +6 -4
@@ -100,11 +100,13 @@ config NET_DSA_RZN1_A5PSW config NET_DSA_KS8995 tristate "Micrel KS8995 family 5-ports 10/100 Ethernet switches" depends on SPI - depends on !NET_DSA_MICROCHIP_KSZ_SPI - select NET_DSA_TAG_NONE + select NET_DSA_MICROCHIP_KSZ_COMMON + select NET_DSA_MICROCHIP_KSZ_SPI help - This driver supports the Micrel KS8995 family of 10/100 Mbit ethernet - switches, managed over SPI. + This is a transitional option for users who had NET_DSA_KS8995 + enabled. It automatically enables the new NET_DSA_MICROCHIP_KSZ_SPI + driver which supersedes it. This option will be removed in a future + kernel release. config NET_DSA_SMSC_LAN9303 tristate
drivers/net/dsa/Makefile +0 -1
@@ -2,7 +2,6 @@ obj-$(CONFIG_NET_DSA_BCM_SF2) += bcm-sf2.o bcm-sf2-objs := bcm_sf2.o bcm_sf2_cfp.o obj-$(CONFIG_NET_DSA_LOOP) += dsa_loop.o -obj-$(CONFIG_NET_DSA_KS8995) += ks8995.o obj-$(CONFIG_NET_DSA_MT7530) += mt7530.o obj-$(CONFIG_NET_DSA_MT7530_MDIO) += mt7530-mdio.o obj-$(CONFIG_NET_DSA_MT7530_MMIO) += mt7530-mmio.o
drivers/net/dsa/ks8995.c deleted +0 -857
857 lines not on this page · raw message
Signature · 1 line
2.54.0