Changing MT7530 registers

What is the easiest way to change the MT7530 runtime registers ?
Is there any module that allows this?
I would not like to compile code.

I am using MT7621 which has the MT7530 gigalan switch inside Some units fail to connect to gigalan and after three unsuccessful attempts connect at 100M I would like to try changing some analogue parameters to see if I can solve this.

Furthermore, I cannot find the datasheet with the registers online.
I only found this table in a linux driver.

/* String, offset, and register size in bytes if different from 4 bytes */
static const struct mt7530_mib_desc mt7530_mib[] = {
	MIB_DESC(1, 0x00, "TxDrop"),
	MIB_DESC(1, 0x04, "TxCrcErr"),
	MIB_DESC(1, 0x08, "TxUnicast"),
	MIB_DESC(1, 0x0c, "TxMulticast"),
	MIB_DESC(1, 0x10, "TxBroadcast"),
	MIB_DESC(1, 0x14, "TxCollision"),
	MIB_DESC(1, 0x18, "TxSingleCollision"),
	MIB_DESC(1, 0x1c, "TxMultipleCollision"),
	MIB_DESC(1, 0x20, "TxDeferred"),
	MIB_DESC(1, 0x24, "TxLateCollision"),
	MIB_DESC(1, 0x28, "TxExcessiveCollistion"),
	MIB_DESC(1, 0x2c, "TxPause"),
	MIB_DESC(1, 0x30, "TxPktSz64"),
	MIB_DESC(1, 0x34, "TxPktSz65To127"),
	MIB_DESC(1, 0x38, "TxPktSz128To255"),
	MIB_DESC(1, 0x3c, "TxPktSz256To511"),
	MIB_DESC(1, 0x40, "TxPktSz512To1023"),
	MIB_DESC(1, 0x44, "Tx1024ToMax"),
	MIB_DESC(2, 0x48, "TxBytes"),
	MIB_DESC(1, 0x60, "RxDrop"),
	MIB_DESC(1, 0x64, "RxFiltering"),
	MIB_DESC(1, 0x68, "RxUnicast"),
	MIB_DESC(1, 0x6c, "RxMulticast"),
	MIB_DESC(1, 0x70, "RxBroadcast"),
	MIB_DESC(1, 0x74, "RxAlignErr"),
	MIB_DESC(1, 0x78, "RxCrcErr"),
	MIB_DESC(1, 0x7c, "RxUnderSizeErr"),
	MIB_DESC(1, 0x80, "RxFragErr"),
	MIB_DESC(1, 0x84, "RxOverSzErr"),
	MIB_DESC(1, 0x88, "RxJabberErr"),
	MIB_DESC(1, 0x8c, "RxPause"),
	MIB_DESC(1, 0x90, "RxPktSz64"),
	MIB_DESC(1, 0x94, "RxPktSz65To127"),
	MIB_DESC(1, 0x98, "RxPktSz128To255"),
	MIB_DESC(1, 0x9c, "RxPktSz256To511"),
	MIB_DESC(1, 0xa0, "RxPktSz512To1023"),
	MIB_DESC(1, 0xa4, "RxPktSz1024ToMax"),
	MIB_DESC(2, 0xa8, "RxBytes"),
	MIB_DESC(1, 0xb0, "RxCtrlDrop"),
	MIB_DESC(1, 0xb4, "RxIngressDrop"),
	MIB_DESC(1, 0xb8, "RxArlDrop"),
};

probably this patch https://github.com/cmonroe/target-mediatek/blob/smartrg-master/mediatek/patches-6.6/990-41-smartrg-net-dsa-mt7530-add-sysfs-register-access.patch

In a programmatic way? Probably ioctl SIOCGMIIREG for reading and ioctl SIOCSMIIREG for writing. Ive used them to change LED parameters in the past, but it was recently broken for some drivers until recently, with 23.05.5.

You say you don't want to compile code. It's really trivial to just install the gcc package locally and then uninstall it after you're done, but you can install the mdio-tools package, which comes pre-compiled.
I've an example of its usage here: Ethernet LEDs control for TP-Link TL-WR1043ND v2/v3 - #4 by Cthulhu88

You still will have to go through the driver code to figure out where and what to change though.

Why did monrore publish a patch?
It seems to have added debugging options.
But I wouldn't know how to apply that patch and what debugging tools are used to get to the logs.

@Cthulhu88
I have cross compiler, maybe twice, on uboot and openwrt folder.
What I want to avoid is compiling 100 times for each test.
I could make a little programme that only changes the register I pass to it as parameters at runtime.
So no existing tool can do that ?

To control the LEDs I simply used "echo 1 > led"

Can you help me find the part of the driver that configures the switch?
I can't find any info on the leds, maybe there is some description in the driver.
I also didn't understand whether it is managed as MT7530 or MT7621

This is a not a problem with the local gcc package and a single line such as gcc -o test test.c
Should take less than 10s for compiling code with just MII ioctl calls.

I've mentioned a package that includes such a tool in the post above and linked my post with a practical usage of it.

Sure, if the LED is linked to a GPIO pin and is defined in a DTS. The linked thread has my description of why I needed to modify MII registers through ioctl in order to control the ethernet LEDs.

You didn't mention anywhere which parameters you were interested in modifying.

but do you mean compiling on the PC or inside the router?

I have problems connecting to gigalan.
I don't know if the cause is the transformer, the layout or something else.
I would like to try changing the analogue parameters.
Gain, signal amplitude, frequency, equalisation.

For found eth driver i have filtered .config, but i have not found:

CONFIG_TARGET_ramips_mt7621=y
CONFIG_DEFAULT_kmod-mt7615-firmware=y
CONFIG_DEFAULT_kmod-mt7615e=y
CONFIG_DEFAULT_kmod-nft-offload=y
CONFIG_DEFAULT_swconfig=y
CONFIG_KERNEL_DEBUG_FS=y
CONFIG_KERNEL_DEBUG_KERNEL=y
CONFIG_KERNEL_DEBUG_INFO=y
CONFIG_KERNEL_DEBUG_INFO_REDUCED=y
CONFIG_KERNEL_CPUSETS=y
CONFIG_EXTRA_OPTIMIZATION="-fno-caller-saves -fno-plt"
CONFIG_TARGET_OPTIMIZATION="-Os -pipe -mno-branch-likely -mips32r2 -mtune=24kc"
CONFIG_PACKAGE_swconfig=y
CONFIG_PACKAGE_kmod-mii=y
CONFIG_PACKAGE_kmod-mt76-connac=y
CONFIG_PACKAGE_kmod-mt76-core=y
CONFIG_PACKAGE_kmod-mt7615-common=y
CONFIG_PACKAGE_kmod-mt7615-firmware=y
CONFIG_PACKAGE_kmod-mt7615e=y

CONFIG_PACKAGE_ethtool=y

Take a moment and re-read both of my posts, including linked content.
I've provided you with two options for interacting with the driver via MDIO.

Yes, ok for write register, but which register ?
I found the linux driver of the mt7530 in which many registers are defined, but not the analogue ones.
In OpenWrt there is no trace of the mt7530, perhaps it is handled as mt7621
Where is the driver that configures the ETH?

mdio command is not present, which module should I install ?

cc @arinc9 for guidance ^

Quoting my response from a GitHub issue report:

I had a similar issue with the Killer E2500 Gigabit Ethernet Controller; the down-up issue appears on a 1Gbps negotiated link. After about 10 down-ups, the link speed becomes negotiated to 100Mbps, with which the down-up issue does not appear.

I don't have this behaviour with the Intel Corporation Ethernet Connection (2) I219-V ethernet controller.

With that said, you can apply this patch to read and write values to the switch registers.

The driver i have is completely different from yours.

My own problem. Mine only makes a few attempts, 2/4 How did you solve it? What was the cause?

Does nobody have the datasheet with the explanation of the registers?

I put an error in the mt7530.c file and recompiled OpenWRT
It seems that that file does not compile.
The error was not reported.

mt7621 uses the in-kernel dsa driver. The one you point to is for the other ralink subtargets

I did not solve it.

What was the cause?

I can only speculate. Having the behaviour experienced with only certain ethernet controllers as link partners tells me that it's not an MT7530 DSA driver bug that is causing bogus reads from the switch registers, as otherwise, we would have seen this happen with all ethernet controllers. It may be more complicated than that, so I can't say for certain. If I were to know this for certain, I'd suspect that it's the variation in the implementation of IEEE Std 802.3 on the MT7530 switch and/or the aforementioned ethernet controllers that causes this issue.

There is no open documentation for MT7530. You'll have to find leaked programming guide documents.

But I have to search MT7530 software datasheet?
Or MT7621?

"mt7621 uses the in-kernel dsa driver."
Can you give me link, where is switch register write on the driver?