Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Rustam Adilov" <adilov@disroot.org>, devicetree@vger.kernel.org
Cc: robh@kernel.org, conor+dt@kernel.org
Subject: Re: [RFC PATCH net-next 4/6] net: dsa: realtek: add support for RTL9607C switch
Date: Sat, 05 Dec 2026 18:29:43 +0000	[thread overview]
Message-ID: <sashiko-outbox-251795@kernel.org> (raw)
In-Reply-To: <20261204182553.33952-5-adilov@disroot.org>

Thank you for your contribution! Sashiko AI review found 14 potential
issues to consider:
- [High] net: dsa: realtek: Kconfig selects nonexistent
  NET_DSA_TAG_RTL8_4AP
- [High] net: dsa: realtek: ev_err() typo in rtl83xx_probe() breaks
  compilation
- [High] net: dsa: tag_rtl8_4: undefined protocol macro and rcv callback
  break build
- [Medium] net: dsa: realtek: rtl9607c_irq_setup() frees unrequested IRQ
  on error
- [Medium] net: dsa: realtek: rtl9607c duplicates standard stats in
  ethtool -S
- [Medium] net: dsa: realtek: wrong regmap_set_bits() for 4-bit
  CHIP_INFO_EN
- [Medium] net: dsa: realtek: missing Clause 22 regnum check in rtl9607c
  PHY ops
- [Medium] net: dsa: realtek: CPU port 7 lacks phylink caps in rtl9607c
  driver
- [Medium] net: dsa: realtek: unchecked regmap_read() leaks stack val in
  MIB reads
- [Medium] net: dsa: realtek: u64 underflow in rtl9607c_get_mac_stats()
  read order
- [Medium] net: dsa: realtek: non-forced regmap_set_bits() in
  rtl9607c_port_mib_reset()
- [Medium] net: dsa: realtek: unguarded 64-bit MIB reads in
  rtl9607c_mib_counter_read()
- [Low] net: dsa: realtek: rtl9607c_irq_teardown() leaves hardware IRQs
  enabled
- [Low] net: dsa: realtek: struct rtl9607c kernel-doc lists nonexistent
  page field
--

commit 331bdac5ba13a62d7d2a46f0ba6f31d9309cb63f
Author: Rustam Adilov <adilov@disroot.org>

net: dsa: realtek: add support for RTL9607C switch

This commit adds a Realtek MMIO DSA switch driver for the embedded
RTL9607C switch, supporting chip detection, internal PHY MDIO access,
cascaded link interrupts, STP state, port isolation, MTU configuration,
and port MIB statistics.

> diff --git a/drivers/net/dsa/realtek/Kconfig b/drivers/net/dsa/realtek/Kconfig
> index aa4955fef4aa9..d38a434ec834b 100644
> --- a/drivers/net/dsa/realtek/Kconfig
> +++ b/drivers/net/dsa/realtek/Kconfig
> @@ -57,4 +57,11 @@ config NET_DSA_REALTEK_RTL8366RB_LEDS
>  	depends on NET_DSA_REALTEK_RTL8366RB
>  	default NET_DSA_REALTEK_RTL8366RB
>  
> +config NET_DSA_REALTEK_RTL9607C
> +	tristate "Realtek RTL9607C embedded switch driver"
> +	depends on NET_DSA_REALTEK_MMIO
> +	select NET_DSA_TAG_RTL8_4AP
> +	help
> +	  Select to enable support for Realtek RTL9607C embedded switch.

[Severity: High]
Should this select NET_DSA_TAG_RTL8_4 instead of NET_DSA_TAG_RTL8_4AP?

NET_DSA_TAG_RTL8_4AP is not defined anywhere in the tree, while
net/dsa/Kconfig defines NET_DSA_TAG_RTL8_4 to build tag_rtl8_4.o
containing DSA_TAG_PROTO_RTL8_4AP.  Selecting the nonexistent symbol emits
a Kconfig warning and leaves the tagger unbuilt unless enabled separately,
causing dsa_register_switch() to fail at runtime.

> diff --git a/drivers/net/dsa/realtek/rtl9607c_main.c b/drivers/net/dsa/realtek/rtl9607c_main.c
> new file mode 100644
> index 0000000000000..5d5633c544bb4
> --- /dev/null
> +++ b/drivers/net/dsa/realtek/rtl9607c_main.c

[ ... ]

> +static const struct rtl9607c_mib_counter rtl9607c_mib_counters[] = {
> +	MIB_DESC(RTL9607C_ETHER_STATS_TX_MULTICAST_PKTS, 1, "etherStatsTxMulticastPkts"),
> +	MIB_DESC(RTL9607C_ETHER_STATS_TX_BROADCAST_PKTS, 1, "etherStatsTxBroadcastPkts"),
> +	MIB_DESC(RTL9607C_ETHER_STATS_TX_UNDERSIZE_PKTS, 1, "etherStatsTxUndersizePkts"),
> +	MIB_DESC(RTL9607C_ETHER_STATS_TX_OVERSIZE_PKTS, 1, "etherStatsTxOversizePkts"),
> +	MIB_DESC(RTL9607C_ETHER_STATS_COLLISIONS, 1, "etherStatsCollisions"),
> +	MIB_DESC(RTL9607C_IF_OUT_DISCARDS, 1, "ifOutDiscards"),
> +	MIB_DESC(RTL9607C_DOT1D_TP_PORT_IN_DISCARDS, 1, "dot1dTpPortInDiscards"),
> +	MIB_DESC(RTL9607C_ETHER_STATS_DROP_EVENTS, 1, "etherStatsDropEvents"),
> +	MIB_DESC(RTL9607C_ETHER_STATS_CRC_ALIGN_ERRORS, 1, "etherStatsCrcAlignErrors"),
> +};

[Severity: Medium]
Should these counters be removed from ethtool -S where standard uAPI
interfaces already exist?

etherStatsCollisions, ifOutDiscards, and etherStatsDropEvents are already
reported through rtnl_link_stats64 in rtl9607c_get_stats64(), and
etherStatsCrcAlignErrors, etherStatsTxMulticastPkts, and
etherStatsTxBroadcastPkts also map to standard rtnl_link_stats64 or
ethtool_eth_mac_stats counters.  Per Documentation/networking/statistics.rst,
ethtool -S is reserved for driver-private statistics without a standard
representation.

[ ... ]

> +/**
> + * struct rtl9607c - driver private data
> + * @priv: pointer to parent realtek_priv data
> + * @irq: registered IRQ or zero
> + * @chip_info: chip-specific info about the attached switch
> + * @page: phy page
> + *
> + * Private data for this driver.
> + */
> +struct rtl9607c {
> +	struct realtek_priv *priv;
> +	int irq;
> +	const struct rtl9607c_chip_info *chip_info;
> +};

[Severity: Low]
The kernel-doc comment documents a nonexistent @page member, which
triggers a W=1 scripts/kernel-doc warning.  The RTL9607C_PAGE_SELECT macro
at the top of the file is also unused.

[ ... ]

> +static int rtl9607c_phy_read(struct realtek_priv *priv, int phy, int regnum)
> +{
> +	u32 ocp_addr;
> +	u16 val;
> +	int ret;
> +
> +	if (phy > RTL9607C_PHYADDRMAX)
> +		return -EINVAL;
> +
> +	ocp_addr = RTL9607C_PHY_OCP_ADDR_PHYREG_BASE + regnum * 2;

[ ... ]

> +static int rtl9607c_phy_write(struct realtek_priv *priv, int phy, int regnum,
> +			      u16 val)
> +{
> +	u32 ocp_addr;
> +	int ret;
> +
> +	if (phy > RTL9607C_PHYADDRMAX)
> +		return -EINVAL;
> +
> +	ocp_addr = RTL9607C_PHY_OCP_ADDR_PHYREG_BASE + regnum * 2;

[Severity: Medium]
Should rtl9607c_phy_read() and rtl9607c_phy_write() reject Clause 22
regnum values greater than 31?

SIOCGMIIREG and SIOCSMIIREG forward an unmasked 16-bit reg_num through
phy_mii_ioctl() -> mdiobus_read()/mdiobus_write() without bounding regnum.
Values above 31 access internal GPHY OCP registers outside the Clause 22
bank, and values >= 0x2e00 overflow the 16-bit
RTL9607C_INDIRECT_COMMAND_OCP_ADDR_MASK field and wrap to arbitrary even
OCP addresses.

[ ... ]

> +static enum dsa_tag_protocol
> +rtl9607c_dsa_get_tag_protocol(struct dsa_switch *ds, int port,
> +			      enum dsa_tag_protocol mp)
> +{
> +	return DSA_TAG_PROTO_RTL8_4AP;
> +}

[Severity: High]
Does the RTL8_4AP tagger introduced earlier in this series compile?

In commit "net: dsa: tag_rtl8_4: add support for RTL9607C tag variant",
net/dsa/tag_rtl8_4.c uses undefined macro RTL8_4_PROTOCOL_RTL9607C in
rtl8_4ap_write_tag() and rtl8_4ap_read_tag(), and assigns
.rcv = rtl8_4ap_tag_rcv in rtl8_4ap_netdev_ops even though
rtl8_4ap_tag_rcv() is never defined.  This breaks the build whenever
CONFIG_NET_DSA_TAG_RTL8_4 is enabled.

> +
> +static void rtl9607c_dsa_phylink_get_caps(struct dsa_switch *ds, int port,
> +					  struct phylink_config *config)
> +{
> +	switch (port) {
> +	/* Ports connected to the integrated GPHYs */
> +	case 0 ... 3:
> +		__set_bit(PHY_INTERFACE_MODE_INTERNAL, config->supported_interfaces);
> +		/*
> +		 * GMII is the default interface mode for phylib, so we have
> +		 * to support it for ports with integrated PHY.
> +		 */
> +		__set_bit(PHY_INTERFACE_MODE_GMII, config->supported_interfaces);
> +
> +		config->mac_capabilities = MAC_SYM_PAUSE | MAC_ASYM_PAUSE |
> +					   MAC_10 | MAC_100 | MAC_1000FD;
> +		break;
> +	/* Main CPU NIC ports */
> +	case 9:
> +	case 10:
> +		__set_bit(PHY_INTERFACE_MODE_INTERNAL, config->supported_interfaces);
> +
> +		config->mac_capabilities = MAC_1000FD;
> +		break;
> +	/* PON and 2 HSGMII serdes are not supported yet */
> +	default:
> +		break;
> +	}
> +}

[Severity: Medium]
Does CPU port 7 fail to register because rtl9607c_dsa_phylink_get_caps()
leaves config->supported_interfaces empty for it?

rtl9607c_cpu_port_setup() explicitly handles port 7 as GMAC2 and
port_mask includes BIT(7), but port 7 falls into the default case here.
phylink_create() returns -EINVAL when supported_interfaces is empty, so
switch registration will fail on any board using port 7 as a CPU port.

[ ... ]

> +static int rtl9607c_port_mib_reset(struct realtek_priv *priv, u32 pmask)
> +{
> +	u32 val;
> +	int ret;
> +
> +	ret = regmap_set_bits(priv->map, RTL9607C_STAT_PORT_RESET_REG, pmask);
> +	if (ret)
> +		return ret;
> +
> +	ret = regmap_set_bits(priv->map, RTL9607C_STAT_RESET_CONFIG_REG,
> +			      RTL9607C_STAT_RESET_CMD_MASK);
> +	if (ret)
> +		return ret;
> +
> +	return regmap_read_poll_timeout(priv->map, RTL9607C_STAT_RESET_REG, val,
> +					!FIELD_GET(RTL9607C_STAT_RESET_STATUS_MASK, val),
> +					10, 1000);
> +}

[Severity: Medium]
Can regmap_set_bits() skip the MMIO trigger write for
RTL9607C_STAT_RESET_CMD_MASK?

priv->map comes from syscon_node_to_regmap(), which leaves
force_write_field false, and regmap_set_bits() passes force = false.  If
RTL9607C_STAT_RESET_CMD_MASK already reads back as 1, _regmap_update_bits()
elides the bus write and the function returns success without clearing the
MIB counters; regmap_write_bits() should be used to force the trigger
write.  Using regmap_set_bits() on RTL9607C_STAT_PORT_RESET_REG also
preserves any stale port bits instead of writing only pmask.

> +
> +static void rtl9607c_mib_counter_read(struct realtek_priv *priv, int port, u32 offset,
> +				      u32 length, u64 *mibvalue)
> +{
> +	u32 val, reg = RTL9607C_STAT_PORT_MIB_REG(port) + offset;
> +
> +	regmap_read(priv->map, reg, &val);
> +	*mibvalue = val;

[Severity: Medium]
Can rtl9607c_mib_counter_read() leak uninitialized stack bytes into
*mibvalue when regmap_read() fails?

val is uninitialized and both regmap_read() return values are ignored.  If
a read fails (for example due to a syscon clock enable error or register
bounds check in _regmap_read()), uninitialized stack data is stored in
*mibvalue and copied to userspace via ethtool or rtnetlink statistics.

> +
> +	if (length == 2) {
> +		regmap_read(priv->map, reg + 4, &val);
> +		*mibvalue |= (u64)val << 32;
> +	}
> +}

[Severity: Medium]
Can reading 64-bit octet counters as two separate 32-bit MMIO reads
produce torn values?

Without a hardware snapshot/latch or a hi-lo-hi rollover retry loop, if
the low 32-bit word wraps into the high word between the two regmap_read()
calls (about every 34 seconds at 1 Gbps), the combined counter will be off
by 4 GiB.

[ ... ]

> +	rtl9607c_mib_counter_read(priv, port, RTL9607C_IF_OUT_OCTETS, 2,
> +				  &mac_stats->OctetsTransmittedOK);

[ ... ]

> +	rtl9607c_mib_counter_read(priv, port, RTL9607C_IF_IN_OCTETS, 2,
> +				  &mac_stats->OctetsReceivedOK);
> +
> +	rtl9607c_mib_counter_read(priv, port, RTL9607C_IF_OUT_MULTICAST_PKTS, 1,
> +				  &mac_stats->MulticastFramesXmittedOK);
> +	mac_stats->FramesTransmittedOK += mac_stats->MulticastFramesXmittedOK;
> +
> +	rtl9607c_mib_counter_read(priv, port, RTL9607C_IF_OUT_BROADCAST_PKTS, 1,
> +				  &mac_stats->BroadcastFramesXmittedOK);
> +	mac_stats->FramesTransmittedOK += mac_stats->BroadcastFramesXmittedOK;
> +
> +	rtl9607c_mib_counter_read(priv, port, RTL9607C_DOT3_OUT_PAUSE_FRAMES, 1,
> +				  &data);
> +	mac_stats->FramesTransmittedOK += data;
> +
> +	rtl9607c_mib_counter_read(priv, port, RTL9607C_IF_OUT_DISCARDS, 1, &data);
> +	mac_stats->FramesTransmittedOK -= data;
> +
> +	mac_stats->OctetsTransmittedOK -= 18 * mac_stats->FramesTransmittedOK;
> +
> +	rtl9607c_mib_counter_read(priv, port, RTL9607C_IF_IN_MULTICAST_PKTS, 1,
> +				  &mac_stats->MulticastFramesReceivedOK);
> +	mac_stats->FramesReceivedOK += mac_stats->MulticastFramesReceivedOK;
> +
> +	rtl9607c_mib_counter_read(priv, port, RTL9607C_IF_IN_BROADCAST_PKTS, 1,
> +				  &mac_stats->BroadcastFramesReceivedOK);
> +	mac_stats->FramesReceivedOK += mac_stats->BroadcastFramesReceivedOK;
> +
> +	rtl9607c_mib_counter_read(priv, port, RTL9607C_DOT3_IN_PAUSE_FRAMES, 1,
> +				  &data);
> +	mac_stats->FramesReceivedOK += data;
> +
> +	mac_stats->OctetsReceivedOK -= 18 * mac_stats->FramesReceivedOK;

[Severity: Medium]
Can the unchecked u64 subtractions in rtl9607c_get_mac_stats() underflow
to near U64_MAX?

OctetsTransmittedOK and OctetsReceivedOK are sampled before the multicast,
broadcast, pause, and discard packet counters.  If a frame arrives or is
discarded between those live MMIO reads (especially shortly after a MIB
reset), subtracting 18 * Frames{Transmitted,Received}OK or
RTL9607C_IF_OUT_DISCARDS wraps around unsigned u64.  Reading packet
counters before octet counters (as in rtl9607c_get_stats64()) and clamping
against underflow would avoid this.

[ ... ]

> +static void rtl9607c_irq_teardown(struct realtek_priv *priv)
> +{
> +	struct rtl9607c *mb = priv->chip_data;
> +	struct dsa_switch *ds = &priv->ds;
> +	struct dsa_port *dp;
> +	int virq;
> +
> +	if (mb->irq) {
> +		free_irq(mb->irq, priv);
> +		mb->irq = 0;
> +	}

[Severity: Low]
Should rtl9607c_irq_teardown() call rtl9607c_irq_disable(priv) before
free_irq()?

Without masking RTL9607C_INTR_IMR_REG, switch hardware interrupt
generation remains armed across driver unbind or kexec.

[ ... ]

> +	/* Store the irq so that we know to map and free it during teardown */
> +	mb->irq = irq;

[ ... ]

> +	ret = request_threaded_irq(irq, NULL, rtl9607c_irq, IRQF_ONESHOT,
> +				   "rtl9607c-switch", priv);
> +	if (ret) {
> +		dev_err(priv->dev, "failed to request irq: %pe\n",
> +			ERR_PTR(ret));
> +		goto out_teardown_irq;
> +	}

[Severity: Medium]
Does rtl9607c_irq_setup() call free_irq() on an IRQ that was never
requested when an error occurs before or during request_threaded_irq()?

mb->irq is set before request_threaded_irq(), and every error path from
irq_create_mapping() through request_threaded_irq() jumps to
out_teardown_irq, where rtl9607c_irq_teardown() unconditionally calls
free_irq(mb->irq, priv) and triggers WARN in __free_irq().  Only calling
free_irq() after request_threaded_irq() succeeds (or using a separate
unwind label) avoids this.

[ ... ]

> +static int rtl9607c_get_chip_id_and_ver(struct regmap *map, u32 *id, u32 *ver)
> +{
> +	u32 chip_info;
> +	int ret;
> +
> +	/* The CHIP_INFO_EN must be set to 0xa to enable chip information */
> +	ret = regmap_set_bits(map, RTL9607C_CHIP_INFO_REG,
> +			      FIELD_PREP(RTL9607C_CHIP_INFO_EN_MASK,
> +					 RTL9607C_CHIP_INFO_EN_VALUE));
> +	if (ret)
> +		return ret;
> +
> +	ret = regmap_read(map, RTL9607C_CHIP_INFO_REG, &chip_info);
> +	if (ret)
> +		return ret;

[Severity: Medium]
Should this use regmap_update_bits() with RTL9607C_CHIP_INFO_EN_MASK
instead of regmap_set_bits()?

regmap_set_bits() passes 0xa0000000 as both mask and value, so bits 30 and
28 are never cleared.  If bootloader or prior state left either bit set,
CHIP_INFO_EN will not become 0xa and probe will fail with -ENODEV.  Also,
if regmap_read() fails, CHIP_INFO_EN is left enabled instead of being
cleared.

[ ... ]

> +static struct platform_driver rtl9607c_mmio_driver = {
> +	.driver = {
> +		.name = "rtl9607c-mmio",
> +		.of_match_table = rtl9607c_of_match,
> +	},
> +	.probe  = realtek_mmio_probe,
> +	.remove = realtek_mmio_remove,
> +	.shutdown = realtek_mmio_shutdown,
> +};

[Severity: High]
Does the shared realtek_dsa module compile with this series?

In commit "net: dsa: realtek: add new mmio interface for drivers",
rtl83xx_probe() in drivers/net/dsa/realtek/rtl83xx.c calls undeclared
ev_err() instead of dev_err(), breaking compilation of realtek_dsa.o
required by realtek_mmio_probe().

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204182553.33952-1-adilov@disroot.org?part=4

  reply	other threads:[~2026-12-05 18:29 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 18:25 [RFC PATCH net-next 0/6] net: dsa: realtek: add support for RTL9607C switch Rustam Adilov
2026-12-04 18:25 ` [RFC PATCH net-next 1/6] net: dsa: tag_rtl8_4: add support for RTL9607C tag variant Rustam Adilov
2026-12-05 18:29   ` sashiko-bot
2026-12-04 18:25 ` [RFC PATCH net-next 2/6] net: dsa: realtek: add new mmio interface for drivers Rustam Adilov
2026-12-05 18:29   ` sashiko-bot
2026-12-04 18:25 ` [RFC PATCH net-next 3/6] dt-bindings: net: dsa: realtek: add new rtl9607c switch compatible Rustam Adilov
2026-12-05 18:29   ` sashiko-bot
2026-12-04 18:25 ` [RFC PATCH net-next 4/6] net: dsa: realtek: add support for RTL9607C switch Rustam Adilov
2026-12-05 18:29   ` sashiko-bot [this message]
2026-12-04 18:25 ` [RFC PATCH net-next 5/6] net: phy: realtek: use mdio.addr instead of 0 in rtlgen_read/write_vend2 Rustam Adilov
2026-12-04 18:25 ` [RFC PATCH net-next 6/6] net: phy: realtek: add support for RTL9607C internal PHYs Rustam Adilov
2026-12-05 18:29   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-251795@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=adilov@disroot.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox