net: dsa: mxl862xx: MDIO bus integrity and optimization
Daniel Golle
maintainerv2 cover net: dsa: mxl862xx: MDIO bus integrity and optimization
The MxL862xx firmware offers opt-in CRC validation on the MDIO/MMD command interface to guard against bit errors on the bus. The driver has not used this until now.
This series enables CRC protection on both the command registers (CRC-6) and data payloads (CRC-16), and reduces MDIO bus traffic by bulk-zeroing registers instead of writing zero-valued words individually.
Changes since initial submittions:
* trigger worker which takes down all ports in case of a CRC error
Daniel Golle (2):
net: dsa: mxl862xx: add CRC for MDIO communication
net: dsa: mxl862xx: use RST_DATA to skip writing zero words
drivers/net/dsa/mxl862xx/Kconfig | 1 + drivers/net/dsa/mxl862xx/mxl862xx-host.c | 377 +++++++++++++++++++---- drivers/net/dsa/mxl862xx/mxl862xx-host.h | 2 + drivers/net/dsa/mxl862xx/mxl862xx.c | 11 + drivers/net/dsa/mxl862xx/mxl862xx.h | 2 + 5 files changed, 331 insertions(+), 62 deletions(-)
Signature · 1 line
2.53.0
Daniel Golle
maintainerPATCH v2 1/2 net: dsa: mxl862xx: add CRC for MDIO communication
Enable the firmware's opt-in CRC validation on the MDIO/MMD command interface to detect bit errors on the bus. The firmware bundles CRC-6 and CRC-16 under a single enable flag, so both are implemented together.
CRC-6 protects the ctrl and len_ret command registers using a table- driven 3GPP algorithm. It is applied to every command exchange including SET_DATA/GET_DATA batch transfers. With CRC enabled, the firmware encodes its return value as a signed 11-bit integer within the CRC- protected register fields, replacing the previous 16-bit interpretation.
CRC-16 protects the data payload using the kernel's crc16() library. The driver appends a CRC-16 checksum to outgoing data and verifies the firmware-appended checksum on responses. The checksum is placed at the exact byte offset where the struct data ends, correctly handling packed structs with odd sizes by splitting the checksum across word boundaries. SET_DATA/GET_DATA sub-commands carry only CRC-6.
Upon detection of a CRC error on either side all conduit interfaces are taken down, triggering all user ports to go down as well. This is the most feasible option: CRC errors are likely caused either by broken hardware, or are symptom of overheating. In either case, trying to resume normal operation isn't reasonable.
---
v2: trigger worker which takes down all ports in case of a CRC error
drivers/net/dsa/mxl862xx/Kconfig | 1 + drivers/net/dsa/mxl862xx/mxl862xx-host.c | 345 ++++++++++++++++++----- drivers/net/dsa/mxl862xx/mxl862xx-host.h | 2 + drivers/net/dsa/mxl862xx/mxl862xx.c | 11 + drivers/net/dsa/mxl862xx/mxl862xx.h | 2 + 5 files changed, 296 insertions(+), 65 deletions(-)
drivers/net/dsa/mxl862xx/Kconfig +1 -0
@@ -2,6 +2,7 @@ config NET_DSA_MXL862 tristate "MaxLinear MxL862xx" depends on NET_DSA + select CRC16 select NET_DSA_TAG_MXL_862XX help This enables support for the MaxLinear MxL862xx switch family.
drivers/net/dsa/mxl862xx/mxl862xx-host.c +280 -65
456 lines not on this page · raw message
drivers/net/dsa/mxl862xx/mxl862xx-host.h +2 -0
@@ -5,6 +5,8 @@#include "mxl862xx.h" +void mxl862xx_host_init (struct mxl862xx_priv *priv); +void mxl862xx_host_shutdown (struct mxl862xx_priv *priv);int mxl862xx_api_wrap (struct mxl862xx_priv *priv,u16 cmd,void *data,u16 size,bool read,bool quiet);int mxl862xx_reset (struct mxl862xx_priv *priv);
drivers/net/dsa/mxl862xx/mxl862xx.c +11 -0
@@ -424,6 +424,7 @@ static int mxl862xx_probe(struct mdio_device *mdiodev) ds->ops = &mxl862xx_switch_ops; ds->phylink_mac_ops = &mxl862xx_phylink_mac_ops; ds->num_ports =MXL862XX_MAX_PORTS ; +mxl862xx_host_init (priv);dev_set_drvdata (dev, ds);
@@ -433,22 +434,32 @@ static int mxl862xx_probe(struct mdio_device *mdiodev)static void mxl862xx_remove (struct mdio_device *mdiodev) {struct dsa_switch *ds =dev_get_drvdata (&mdiodev->dev); +struct mxl862xx_priv *priv;if (!ds)return ; + priv = ds->priv; +dsa_unregister_switch (ds); + +mxl862xx_host_shutdown (priv); }static void mxl862xx_shutdown (struct mdio_device *mdiodev) {struct dsa_switch *ds =dev_get_drvdata (&mdiodev->dev); +struct mxl862xx_priv *priv;if (!ds)return ; + priv = ds->priv; +dsa_switch_shutdown (ds); +mxl862xx_host_shutdown (priv); +dev_set_drvdata (&mdiodev->dev,NULL ); }
drivers/net/dsa/mxl862xx/mxl862xx.h +2 -0
@@ -11,6 +11,8 @@struct mxl862xx_priv {struct dsa_switch *ds;struct mdio_device *mdiodev; +struct work_struct crc_err_work; +unsigned long crc_err; };#endif /* __MXL862XX_H */
Signature · 1 line
2.53.0
Re: [PATCH net-next v2 1/2] net: dsa: mxl862xx: add CRC for MDIO communication
Quoted 19 lines · Daniel Golle
Enable the firmware's opt-in CRC validation on the MDIO/MMD command interface to detect bit errors on the bus. The firmware bundles CRC-6 and CRC-16 under a single enable flag, so both are implemented together.
CRC-6 protects the ctrl and
len_retcommand registers using a table- driven 3GPP algorithm. It is applied to every command exchange including SET_DATA/GET_DATA batch transfers. With CRC enabled, the firmware encodes its return value as a signed 11-bit integer within the CRC- protected register fields, replacing the previous 16-bit interpretation.CRC-16 protects the data payload using the kernel's
crc16()library. The driver appends a CRC-16 checksum to outgoing data and verifies the firmware-appended checksum on responses. The checksum is placed at the exact byte offset where the struct data ends, correctly handling packed structs with odd sizes by splitting the checksum across word boundaries. SET_DATA/GET_DATA sub-commands carry only CRC-6.
Quoted 7 lines
Upon detection of a CRC error on either side all conduit interfaces are taken down, triggering all user ports to go down as well. This is the most feasible option: CRC errors are likely caused either by broken hardware, or are symptom of overheating. In either case, trying to resume normal operation isn't reasonable.
Signed-off-by Daniel Golle <[email protected]>
Andrew
Daniel Golle
maintainerPATCH v2 2/2 net: dsa: mxl862xx: use RST_DATA to skip writing zero words
In reply to Daniel GolleIssue the firmware's RST_DATA command before writing data payloads that contain many zero words. RST_DATA zeroes both the firmware's internal buffer and the MMD data registers in a single command, allowing the driver to skip individual MDIO writes for zero-valued words. This reduces bus traffic for the common case where API structs have many unused or default-zero fields.
The optimization is applied when at least 5 zero words are found in the payload, roughly the break-even point against the cost of the extra RST_DATA command round-trip.
---
v2: no changes
drivers/net/dsa/mxl862xx/mxl862xx-host.c | 38 ++++++++++++++++++++++++ 1 file changed, 38 insertions(+)
drivers/net/dsa/mxl862xx/mxl862xx-host.c +38 -0
@@ -283,6 +283,17 @@ static int mxl862xx_get_data(struct mxl862xx_priv *priv, u16 words) MXL862XX_MMD_REG_DATA_MAX_SIZE * sizeof(u16)); } +static int mxl862xx_rst_data (struct mxl862xx_priv *priv) +{ +return mxl862xx_issue_cmd (priv,MMD_API_RST_DATA ,0 ); +} + +/* Minimum number of zero words in the data payload before issuing a +* RST_DATA command is worthwhile. RST_DATA costs one full command +* round-trip (~5 MDIO transactions), so the threshold must offset that. +*/ +#define RST_DATA_THRESHOLD 5 +static int mxl862xx_send_cmd (struct mxl862xx_priv *priv,u16 cmd,u16 size,bool quiet) {
@@ -318,6 +329,8 @@ int mxl862xx_api_wrap(struct mxl862xx_priv *priv, u16 cmd, void *_data, u16 size, bool read, bool quiet) { __le16 *data = _data; +bool use_rst = false; +unsigned int zeros;int ret, cmd_ret;u16 max, crc, i;
@@ -331,6 +344,24 @@ int mxl862xx_api_wrap(struct mxl862xx_priv *priv, u16 cmd, void *_data,if (ret <0 ) goto out; +/* If the data contains enough zero words, issue RST_DATA to zero +* both the firmware buffer and MMD registers, then skip writing +* zero words individually. +*/ +for (i =0 , zeros =0 ; i < size /2 && zeros <RST_DATA_THRESHOLD ; i++) +if (!data[i]) + zeros++; + +if (zeros <RST_DATA_THRESHOLD && (size &1 ) && !*(u8 *)&data[i]) + zeros++; + +if (zeros >=RST_DATA_THRESHOLD ) { + ret =mxl862xx_rst_data (priv); +if (ret <0 ) + goto out; + use_rst = true; + } +/* Compute CRC-16 over the data payload; written as an extra word * after the data so the firmware can verify the transfer. */
@@ -367,6 +398,13 @@ int mxl862xx_api_wrap(struct mxl862xx_priv *priv, u16 cmd, void *_data, val =le16_to_cpu (data[i]); } +/* After RST_DATA, skip zero data words as the registers +* already contain zeros, but never skip the CRC word at the +* final word. +*/ +if (use_rst && i < max && val ==0 ) +continue ; + ret =mxl862xx_reg_write (priv,MXL862XX_MMD_REG_DATA_FIRST + off, val);
Signature · 1 line
2.53.0
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Sun, 22 Mar 2026 13:27:12 +0000 you wrote:
The MxL862xx firmware offers opt-in CRC validation on the MDIO/MMD command interface to guard against bit errors on the bus. The driver has not used this until now.
This series enables CRC protection on both the command registers (CRC-6) and data payloads (CRC-16), and reduces MDIO bus traffic by bulk-zeroing registers instead of writing zero-valued words individually.
[...]
Here is the summary with links:
- [net-next,v2,1/2] net: dsa: mxl862xx: add CRC for MDIO communication
https://git.kernel.org/netdev/net-next/c/a319d0c8c8ce - [net-next,v2,2/2] net: dsa: mxl862xx: use RST_DATA to skip writing zero words https://git.kernel.org/netdev/net-next/c/7c20f6c1cfb1
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html