Skip to contentSkip to conversation

Re-organize MediaTek ethernet phy drivers and propose mtk-phy-lib

PATCH Applied Sky Huang 4 participants 14 messages Nov 8, 2024 – Nov 19, 2024

Subsystems (6)
lore
Share & tools
lore

Sky Huang

author maintainer
#0 lore raw

v3 cover Re-organize MediaTek ethernet phy drivers and propose mtk-phy-lib

From: Sky Huang <[email protected]>

This patchset comes from patch 1/9, 3/9, 4/9, 5/9 and 7/9 of:
https://lore.kernel.org/netdev/[email protected]/

This patchset changes MediaTek's ethernet phy's folder structure and integrates helper functions, including LED & token ring manipulation, into mtk-phy-lib.

---
Change in v2:
- Add correct Reviewed-by tag in each patch.

Change in v3:
[patch 4/5]
- Fix kernel test robot error by adding missing MTK_NET_PHYLIB.
---

SkyLake.Huang (5):
net: phy: mediatek: Re-organize MediaTek ethernet phy drivers
net: phy: mediatek: Move LED helper functions into mtk phy lib
net: phy: mediatek: Improve readability of mtk-phy-lib.c's

    mtk_phy_led_hw_ctrl_set()

net: phy: mediatek: Integrate read/write page helper functions
net: phy: mediatek: add MT7530 & MT7531's PHY ID macros

 MAINTAINERS                                   |   6 +-
 drivers/net/phy/Kconfig                       |  17 +-
 drivers/net/phy/Makefile                      |   3 +-
 drivers/net/phy/mediatek/Kconfig              |  27 ++
 drivers/net/phy/mediatek/Makefile             |   4 +
 .../mtk-ge-soc.c}                             | 298 ++----------------
 .../phy/{mediatek-ge.c => mediatek/mtk-ge.c}  |  31 +-
 drivers/net/phy/mediatek/mtk-phy-lib.c        | 270 ++++++++++++++++
 drivers/net/phy/mediatek/mtk.h                |  89 ++++++
 9 files changed, 438 insertions(+), 307 deletions(-)
 create mode 100644 drivers/net/phy/mediatek/Kconfig
 create mode 100644 drivers/net/phy/mediatek/Makefile
 rename drivers/net/phy/{mediatek-ge-soc.c => mediatek/mtk-ge-soc.c} (83%)
 rename drivers/net/phy/{mediatek-ge.c => mediatek/mtk-ge.c} (82%)
 create mode 100644 drivers/net/phy/mediatek/mtk-phy-lib.c
 create mode 100644 drivers/net/phy/mediatek/mtk.h
Signature · 1 line
2.45.2
author maintainer
#1 lore raw

PATCH v3 1/5 net: phy: mediatek: Re-organize MediaTek ethernet phy drivers

From: "SkyLake.Huang" <[email protected]>

Re-organize MediaTek ethernet phy driver files and get ready to integrate some common functions and add new 2.5G phy driver.
mtk-ge.c: MT7530 Gphy on MT7621 & MT7531 Gphy
mtk-ge-soc.c: Built-in Gphy on MT7981 & Built-in switch Gphy on MT7988 mtk-2p5ge.c: Planned for built-in 2.5G phy on MT7988

---
 MAINTAINERS                                   |  4 ++--
 drivers/net/phy/Kconfig                       | 17 +-------------
 drivers/net/phy/Makefile                      |  3 +--
 drivers/net/phy/mediatek/Kconfig              | 22 +++++++++++++++++++
 drivers/net/phy/mediatek/Makefile             |  3 +++
 .../mtk-ge-soc.c}                             |  0
 .../phy/{mediatek-ge.c => mediatek/mtk-ge.c}  |  0
 7 files changed, 29 insertions(+), 20 deletions(-)
 create mode 100644 drivers/net/phy/mediatek/Kconfig
 create mode 100644 drivers/net/phy/mediatek/Makefile
 rename drivers/net/phy/{mediatek-ge-soc.c => mediatek/mtk-ge-soc.c} (100%)
 rename drivers/net/phy/{mediatek-ge.c => mediatek/mtk-ge.c} (100%)
MAINTAINERS +2 -2
index e291445..6deaf94 100644
@@ -13793,8 +13793,8 @@ M:	Qingfang Deng <[email protected]>
 M:	SkyLake Huang <[email protected]>
 L:	[email protected]
 S:	Maintained
-F:	drivers/net/phy/mediatek-ge-soc.c
-F:	drivers/net/phy/mediatek-ge.c
+F:	drivers/net/phy/mediatek/mtk-ge-soc.c
+F:	drivers/net/phy/mediatek/mtk-ge.c
 F:	drivers/phy/mediatek/phy-mtk-xfi-tphy.c
 
 MEDIATEK I2C CONTROLLER DRIVER
drivers/net/phy/Kconfig +1 -16
index 1df0595..e0e4b5e 100644
@@ -251,22 +251,7 @@ config MAXLINEAR_GPHY
 	  Support for the Maxlinear GPY115, GPY211, GPY212, GPY215,
 	  GPY241, GPY245 PHYs.
 
-config MEDIATEK_GE_PHY
-	tristate "MediaTek Gigabit Ethernet PHYs"
-	help
-	  Supports the MediaTek Gigabit Ethernet PHYs.
-
-config MEDIATEK_GE_SOC_PHY
-	tristate "MediaTek SoC Ethernet PHYs"
-	depends on (ARM64 && ARCH_MEDIATEK) || COMPILE_TEST
-	depends on NVMEM_MTK_EFUSE
-	help
-	  Supports MediaTek SoC built-in Gigabit Ethernet PHYs.
-
-	  Include support for built-in Ethernet PHYs which are present in
-	  the MT7981 and MT7988 SoCs. These PHYs need calibration data
-	  present in the SoCs efuse and will dynamically calibrate VCM
-	  (common-mode voltage) during startup.
+source "drivers/net/phy/mediatek/Kconfig"
 
 config MICREL_PHY
 	tristate "Micrel PHYs"
drivers/net/phy/Makefile +1 -2
index 197acfa..de38cbf 100644
@@ -71,8 +71,7 @@ obj-$(CONFIG_MARVELL_PHY)	+= marvell.o
 obj-$(CONFIG_MARVELL_88Q2XXX_PHY)	+= marvell-88q2xxx.o
 obj-$(CONFIG_MARVELL_88X2222_PHY)	+= marvell-88x2222.o
 obj-$(CONFIG_MAXLINEAR_GPHY)	+= mxl-gpy.o
-obj-$(CONFIG_MEDIATEK_GE_PHY)	+= mediatek-ge.o
-obj-$(CONFIG_MEDIATEK_GE_SOC_PHY)	+= mediatek-ge-soc.o
+obj-y				+= mediatek/
 obj-$(CONFIG_MESON_GXL_PHY)	+= meson-gxl.o
 obj-$(CONFIG_MICREL_KS8995MA)	+= spi_ks8995.o
 obj-$(CONFIG_MICREL_PHY)	+= micrel.o
drivers/net/phy/mediatek/Kconfig new file +22 -0
new file mode 100644
index 0000000..112d9c0
@@ -0,0 +1,22 @@
+# SPDX-License-Identifier: GPL-2.0-only
+config MEDIATEK_GE_PHY
+	tristate "MediaTek Gigabit Ethernet PHYs"
+	help
+	  Supports the MediaTek non-built-in Gigabit Ethernet PHYs.
+
+	  Non-built-in Gigabit Ethernet PHYs include mt7530/mt7531.
+	  You may find mt7530 inside mt7621. This driver shares some
+	  common operations with MediaTek SoC built-in Gigabit
+	  Ethernet PHYs.
+
+config MEDIATEK_GE_SOC_PHY
+	tristate "MediaTek SoC Ethernet PHYs"
+	depends on (ARM64 && ARCH_MEDIATEK) || COMPILE_TEST
+	depends on NVMEM_MTK_EFUSE
+	help
+	  Supports MediaTek SoC built-in Gigabit Ethernet PHYs.
+
+	  Include support for built-in Ethernet PHYs which are present in
+	  the MT7981 and MT7988 SoCs. These PHYs need calibration data
+	  present in the SoCs efuse and will dynamically calibrate VCM
+	  (common-mode voltage) during startup.
drivers/net/phy/mediatek/Makefile new file +3 -0
new file mode 100644
index 0000000..005bde2
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_MEDIATEK_GE_PHY)		+= mtk-ge.o
+obj-$(CONFIG_MEDIATEK_GE_SOC_PHY)	+= mtk-ge-soc.o
drivers/net/phy/mediatek/mtk-ge-soc.c renamed from drivers/net/phy/mediatek-ge-soc.c +0 -0
similarity index 100%
rename from drivers/net/phy/mediatek-ge-soc.c
rename to drivers/net/phy/mediatek/mtk-ge-soc.c
drivers/net/phy/mediatek/mtk-ge.c renamed from drivers/net/phy/mediatek-ge.c +0 -0
similarity index 100%
rename from drivers/net/phy/mediatek-ge.c
rename to drivers/net/phy/mediatek/mtk-ge.c
Signature · 1 line
2.45.2
author maintainer
#2 lore raw

PATCH v3 2/5 net: phy: mediatek: Move LED helper functions into mtk phy lib

In reply to Sky Huang

From: "SkyLake.Huang" <[email protected]>

This patch creates mtk-phy-lib.c & mtk-phy.h and integrates mtk-ge-soc.c's LED helper functions so that we can use those helper functions in other MTK's ethernet phy driver.

---
 MAINTAINERS                            |   2 +
 drivers/net/phy/mediatek/Kconfig       |   4 +
 drivers/net/phy/mediatek/Makefile      |   1 +
 drivers/net/phy/mediatek/mtk-ge-soc.c  | 280 +++----------------------
 drivers/net/phy/mediatek/mtk-phy-lib.c | 254 ++++++++++++++++++++++
 drivers/net/phy/mediatek/mtk.h         |  86 ++++++++
 6 files changed, 372 insertions(+), 255 deletions(-)
 create mode 100644 drivers/net/phy/mediatek/mtk-phy-lib.c
 create mode 100644 drivers/net/phy/mediatek/mtk.h
MAINTAINERS +2 -0
index 6deaf94..e58e05c 100644
@@ -13794,7 +13794,9 @@ M:	SkyLake Huang <[email protected]>
 L:	[email protected]
 S:	Maintained
 F:	drivers/net/phy/mediatek/mtk-ge-soc.c
+F:	drivers/net/phy/mediatek/mtk-phy-lib.c
 F:	drivers/net/phy/mediatek/mtk-ge.c
+F:	drivers/net/phy/mediatek/mtk.h
 F:	drivers/phy/mediatek/phy-mtk-xfi-tphy.c
 
 MEDIATEK I2C CONTROLLER DRIVER
drivers/net/phy/mediatek/Kconfig +4 -0
index 112d9c0..19b5d23 100644
@@ -1,4 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0-only
+config MTK_NET_PHYLIB
+	tristate
+
 config MEDIATEK_GE_PHY
 	tristate "MediaTek Gigabit Ethernet PHYs"
 	help
@@ -13,6 +16,7 @@ config MEDIATEK_GE_SOC_PHY
 	tristate "MediaTek SoC Ethernet PHYs"
 	depends on (ARM64 && ARCH_MEDIATEK) || COMPILE_TEST
 	depends on NVMEM_MTK_EFUSE
+	select MTK_NET_PHYLIB
 	help
 	  Supports MediaTek SoC built-in Gigabit Ethernet PHYs.
 
drivers/net/phy/mediatek/Makefile +1 -0
index 005bde2..814879d 100644
@@ -1,3 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_MTK_NET_PHYLIB)		+= mtk-phy-lib.o
 obj-$(CONFIG_MEDIATEK_GE_PHY)		+= mtk-ge.o
 obj-$(CONFIG_MEDIATEK_GE_SOC_PHY)	+= mtk-ge-soc.o
drivers/net/phy/mediatek/mtk-ge-soc.c +25 -255

356 lines not on this page · raw message

drivers/net/phy/mediatek/mtk-phy-lib.c new file +254 -0

254 lines not on this page · raw message

drivers/net/phy/mediatek/mtk.h new file +86 -0

86 lines not on this page · raw message

Signature · 1 line
2.45.2
author maintainer
#3 lore raw

PATCH v3 3/5 net: phy: mediatek: Improve readability of mtk-phy-lib.c's mtk_phy_led_hw_ctrl_set()

In reply to Sky Huang

From: "SkyLake.Huang" <[email protected]>

This patch removes parens around TRIGGER_NETDEV_RX/TRIGGER_NETDEV_TX in mtk_phy_led_hw_ctrl_set(), which improves readability.

---
 drivers/net/phy/mediatek/mtk-phy-lib.c | 44 ++++++++++++++------------
 1 file changed, 24 insertions(+), 20 deletions(-)
drivers/net/phy/mediatek/mtk-phy-lib.c +24 -20
index 34b0957..8d795bc 100644
@@ -129,29 +129,33 @@ int mtk_phy_led_hw_ctrl_set(struct phy_device *phydev, u8 index,
 		on |= MTK_PHY_LED_ON_LINK2500;
 
 	if (rules & BIT(TRIGGER_NETDEV_RX)) {
-		blink |= (on & on_set) ?
-			  (((on & MTK_PHY_LED_ON_LINK10) ?
-			    MTK_PHY_LED_BLINK_10RX : 0) |
-			   ((on & MTK_PHY_LED_ON_LINK100) ?
-			    MTK_PHY_LED_BLINK_100RX : 0) |
-			   ((on & MTK_PHY_LED_ON_LINK1000) ?
-			    MTK_PHY_LED_BLINK_1000RX : 0) |
-			   ((on & MTK_PHY_LED_ON_LINK2500) ?
-			    MTK_PHY_LED_BLINK_2500RX : 0)) :
-			  rx_blink_set;
+		if (on & on_set) {
+			if (on & MTK_PHY_LED_ON_LINK10)
+				blink |= MTK_PHY_LED_BLINK_10RX;
+			if (on & MTK_PHY_LED_ON_LINK100)
+				blink |= MTK_PHY_LED_BLINK_100RX;
+			if (on & MTK_PHY_LED_ON_LINK1000)
+				blink |= MTK_PHY_LED_BLINK_1000RX;
+			if (on & MTK_PHY_LED_ON_LINK2500)
+				blink |= MTK_PHY_LED_BLINK_2500RX;
+		} else {
+			blink |= rx_blink_set;
+		}
 	}
 
 	if (rules & BIT(TRIGGER_NETDEV_TX)) {
-		blink |= (on & on_set) ?
-			  (((on & MTK_PHY_LED_ON_LINK10) ?
-			    MTK_PHY_LED_BLINK_10TX : 0) |
-			   ((on & MTK_PHY_LED_ON_LINK100) ?
-			    MTK_PHY_LED_BLINK_100TX : 0) |
-			   ((on & MTK_PHY_LED_ON_LINK1000) ?
-			    MTK_PHY_LED_BLINK_1000TX : 0) |
-			   ((on & MTK_PHY_LED_ON_LINK2500) ?
-			    MTK_PHY_LED_BLINK_2500TX : 0)) :
-			  tx_blink_set;
+		if (on & on_set) {
+			if (on & MTK_PHY_LED_ON_LINK10)
+				blink |= MTK_PHY_LED_BLINK_10TX;
+			if (on & MTK_PHY_LED_ON_LINK100)
+				blink |= MTK_PHY_LED_BLINK_100TX;
+			if (on & MTK_PHY_LED_ON_LINK1000)
+				blink |= MTK_PHY_LED_BLINK_1000TX;
+			if (on & MTK_PHY_LED_ON_LINK2500)
+				blink |= MTK_PHY_LED_BLINK_2500TX;
+		} else {
+			blink |= tx_blink_set;
+		}
 	}
 
 	if (blink || on)
Signature · 1 line
2.45.2
author maintainer
#4 lore raw

Re: [PATCH v2] mtd: spinand: add support for FORESEE F35SQA002G

Hi Miquel/Martin,
About this driver, including F35SQA001G/F35SQA002G parts, I'm concerned that the driver will always use 32H for update_cache operations, which means it's not compitable with those SPI controller who can't transmit 2048 bytes (most small-density SPI-NAND's page size nowadays) at one time.

The following controller's driver seems that they can't transmit 2048 bytes in one transmission:
- spi-amd.c: 64 bytes (AMD_SPI_MAX_DATA)
- spi-amlogic-spifc-a1.c: 512 bytes (SPIFC_A1_BUFFER_SIZE)
- spi-fsl-qspi.c: 1KB
- spi-hisi-sfc-v3xx.c: 64*6 bytes
- spi-intel.c: 64 bytes (INTEL_SPI_FIFO_SZ)
- spi-microchip-core-qspi.c: 256 bytesc (MAX_DATA_CMD_LEN)
- spi-nxp-fspi.c: TX:1KB, RX: 512B in FIFO mode
- spi-wpcm-fiu.c: 4B

I guess we need to add some check to make sure that F35SQA series work only with those SPI controllers who can transmit more than 2048 bytes(NAND page size) at one time?

BRs,
Sky

maintainer
#5 lore raw

Re: [PATCH v2] mtd: spinand: add support for FORESEE F35SQA002G

Hi Sky,

Quoted 7 lines · SkyLake Huang (黃啟澤)

Hi Miquel/Martin,
About this driver, including F35SQA001G/F35SQA002G parts, I'm concerned that the driver will always use 32H for update_cache operations, which means it's not compitable with those SPI controller who can't transmit 2048 bytes (most small-density SPI-NAND's page size nowadays) at one time.

Quoted 10 lines

The following controller's driver seems that they can't transmit 2048 bytes in one transmission:
- spi-amd.c: 64 bytes (AMD_SPI_MAX_DATA)
- spi-amlogic-spifc-a1.c: 512 bytes (SPIFC_A1_BUFFER_SIZE)
- spi-fsl-qspi.c: 1KB
- spi-hisi-sfc-v3xx.c: 64*6 bytes
- spi-intel.c: 64 bytes (INTEL_SPI_FIFO_SZ)
- spi-microchip-core-qspi.c: 256 bytesc (MAX_DATA_CMD_LEN)
- spi-nxp-fspi.c: TX:1KB, RX: 512B in FIFO mode
- spi-wpcm-fiu.c: 4B

I believe most of these drivers are still able to send one page of data without toggling the CS (which is what actually matters, I believe). If they were broken, they would be broken with all spi memory devices, not only Foresee's.

Quoted 3 lines

I guess we need to add some check to make sure that F35SQA series work only with those SPI controllers who can transmit more than 2048 bytes(NAND page size) at one time?

There is already a supports_op() hook for that, I believe we are fine. If however you experience errors, please report them and we'll look for a solution.

Thanks,
Miquèl

author maintainer
#6 lore raw

Re: [PATCH v2] mtd: spinand: add support for FORESEE F35SQA002G

Quoted 32 lines · Miquel Raynal

External email : Please do not click links or open attachments until you have verified the sender or the content.

Hi Sky,

Quoted 11 lines · SkyLake Huang (黃啟澤)

Hi Miquel/Martin,
About this driver, including F35SQA001G/F35SQA002G parts, I'm concerned
that the driver will always use 32H for update_cache operations, which
means it's not compitable with those SPI controller who can't transmit
2048 bytes (most small-density SPI-NAND's page size nowadays) at one
time.

Quoted 11 lines

The following controller's driver seems that they can't transmit 2048
bytes in one transmission:
- spi-amd.c: 64 bytes (AMD_SPI_MAX_DATA)
- spi-amlogic-spifc-a1.c: 512 bytes (SPIFC_A1_BUFFER_SIZE)
- spi-fsl-qspi.c: 1KB
- spi-hisi-sfc-v3xx.c: 64*6 bytes
- spi-intel.c: 64 bytes (INTEL_SPI_FIFO_SZ)
- spi-microchip-core-qspi.c: 256 bytesc (MAX_DATA_CMD_LEN)
- spi-nxp-fspi.c: TX:1KB, RX: 512B in FIFO mode
- spi-wpcm-fiu.c: 4B

Quoted 8 lines

I believe most of these drivers are still able to send one page of data
without toggling the CS (which is what actually matters, I believe). If
they were broken, they would be broken with all spi memory devices, not
only Foresee's.

Hi Miquel,
I think it's not about toggling the CS?

If a SPI controller tries to execute write page and it's capable to send only 1KB in one transmission, it should transmit data in two
steps: 1st 34H (random program load x4) and 2nd 34H. However, when F35SQA002G executes 2nd 34H command, it needs to execute 32H first, and it will clear data transmitted by 1st 34H in NAND flash's cache. This will cause data corruption. Other SPI-NANDs doesn't need to execute 32H before 34H.

Quoted 11 lines
Quoted 4 lines

I guess we need to add some check to make sure that F35SQA series work
only with those SPI controllers who can transmit more than 2048 bytes(NAND page size) at one time?

There is already a supports_op() hook for that, I believe we are fine. If however you experience errors, please report them and we'll look for a solution.

Thanks,
Miquèl

We can block 32H update_cache opcode in supports_op() hook for those light SPI controllers(transmittion cap. < 2048 Bytes)? Not sure if there's a better solution.

Indeed, most SPI controllers support DMA transmission(>2048 Bytes) now, including our MTK filogic platform. If this doesn't bother other FIFO- only SPI controllers, I'll take it.

BRs,
Sky

maintainer
#7 lore raw

Re: [PATCH v2] mtd: spinand: add support for FORESEE F35SQA002G

Quoted 44 lines · SkyLake Huang (黃啟澤)
Quoted 32 lines · Miquel Raynal

External email : Please do not click links or open attachments until you have verified the sender or the content.

Hi Sky,

Quoted 11 lines · SkyLake Huang (黃啟澤)

Hi Miquel/Martin,
About this driver, including F35SQA001G/F35SQA002G parts, I'm concerned
that the driver will always use 32H for update_cache operations, which
means it's not compitable with those SPI controller who can't transmit
2048 bytes (most small-density SPI-NAND's page size nowadays) at one
time.

Quoted 11 lines

The following controller's driver seems that they can't transmit 2048
bytes in one transmission:
- spi-amd.c: 64 bytes (AMD_SPI_MAX_DATA)
- spi-amlogic-spifc-a1.c: 512 bytes (SPIFC_A1_BUFFER_SIZE)
- spi-fsl-qspi.c: 1KB
- spi-hisi-sfc-v3xx.c: 64*6 bytes
- spi-intel.c: 64 bytes (INTEL_SPI_FIFO_SZ)
- spi-microchip-core-qspi.c: 256 bytesc (MAX_DATA_CMD_LEN)
- spi-nxp-fspi.c: TX:1KB, RX: 512B in FIFO mode
- spi-wpcm-fiu.c: 4B

Quoted 8 lines

I believe most of these drivers are still able to send one page of data
without toggling the CS (which is what actually matters, I believe). If
they were broken, they would be broken with all spi memory devices, not
only Foresee's.

Hi Miquel,
I think it's not about toggling the CS?

Quoted 7 lines

If a SPI controller tries to execute write page and it's capable to send only 1KB in one transmission, it should transmit data in two
steps: 1st 34H (random program load x4) and 2nd 34H. However, when F35SQA002G executes 2nd 34H command, it needs to execute 32H first, and it will clear data transmitted by 1st 34H in NAND flash's cache. This will cause data corruption. Other SPI-NANDs doesn't need to execute 32H before 34H.

Is it really what happens? I'd instead expect the spi controller to send:
- 34h
- 1k data
- 1k data
...

Why should we repeat the command while we are in the I/O phase?

Thanks,
Miquèl

#8 lore raw

Re: [PATCH v2] mtd: spinand: add support for FORESEE F35SQA002G

Hello all!

Quoted 44 lines · Miquel Raynal
Quoted 41 lines · SkyLake Huang (黃啟澤)
Quoted 40 lines · Miquel Raynal

External email : Please do not click links or open attachments until you have verified the sender or the content.

Hi Sky,

Quoted 11 lines · SkyLake Huang (黃啟澤)

Hi Miquel/Martin,
About this driver, including F35SQA001G/F35SQA002G parts, I'm concerned
that the driver will always use 32H for update_cache operations, which
means it's not compitable with those SPI controller who can't transmit
2048 bytes (most small-density SPI-NAND's page size nowadays) at one
time.

Quoted 11 lines

The following controller's driver seems that they can't transmit 2048
bytes in one transmission:
- spi-amd.c: 64 bytes (AMD_SPI_MAX_DATA)
- spi-amlogic-spifc-a1.c: 512 bytes (SPIFC_A1_BUFFER_SIZE)
- spi-fsl-qspi.c: 1KB
- spi-hisi-sfc-v3xx.c: 64*6 bytes
- spi-intel.c: 64 bytes (INTEL_SPI_FIFO_SZ)
- spi-microchip-core-qspi.c: 256 bytesc (MAX_DATA_CMD_LEN)
- spi-nxp-fspi.c: TX:1KB, RX: 512B in FIFO mode
- spi-wpcm-fiu.c: 4B

I believe most of these drivers are still able to send one page of data
without toggling the CS (which is what actually matters, I believe). If
they were broken, they would be broken with all spi memory devices, not
only Foresee's.

Quoted 7 lines
Quoted 7 lines

Hi Miquel,
I think it's not about toggling the CS?

If a SPI controller tries to execute write page and it's capable to send only 1KB in one transmission, it should transmit data in two
steps: 1st 34H (random program load x4) and 2nd 34H. However, when F35SQA002G executes 2nd 34H command, it needs to execute 32H first, and

I don't think that's what the datasheet means. I think it needs 02h/32h as the first
command to write page cache, and the subsequent page cache writing can be done using 84h/34h before the final page program happens. Otherwise the 84h/34h command is just completely broken and useless.
If it actually is broken, we do need additional guards in spinand_write_cache_op to abort when spi_mem_dirmap_write doesn't return exactly nbytes as requested.

Quoted 4 lines
Quoted 3 lines

it will clear data transmitted by 1st 34H in NAND flash's cache. This will cause data corruption. Other SPI-NANDs doesn't need to execute 32H before 34H.

Quoted 8 lines

Is it really what happens? I'd instead expect the spi controller to send:
- 34h
- 1k data
- 1k data
...

Why should we repeat the command while we are in the I/O phase?

Several SPI-MEM controller don't allow software controlled CS, or for some other reasons are unable to execute a longer spi-mem op. spi_mem_dirmap_write returns the actual request size it's able to make, and spinand_write_to_cache_op use a while loop to split one update_cache request into multiple ones.

This only works using the Random Program Load instruction (84h/34h) which preserves the previous written data in the flash data cache. All current supported flashes are exclusively using 84h/34h as the command to write the page cache.

Load Program Data(02h/32h) will clear the entire page cache. As a result, when a request is split as described above, the previous written data will be cleared, breaking the page cache writing procedure.

We can change write_to_cache_op to use Load Program Data on the first request. If that doesn't finish writing, use Random Program Load on subsequent data loading.

Signature · 2 lines
Regards,
Chuanhong Guo
maintainer
#9 lore raw

Re: [PATCH v2] mtd: spinand: add support for FORESEE F35SQA002G

Hello,

Quoted 11 lines

Several SPI-MEM controller don't allow software controlled CS, or for some other reasons are unable to execute a longer spi-mem op. spi_mem_dirmap_write returns the actual request size it's able to make, and spinand_write_to_cache_op use a while loop to split one update_cache request into multiple ones.

This only works using the Random Program Load instruction (84h/34h) which preserves the previous written data in the flash data cache. All current supported flashes are exclusively using 84h/34h as the command to write the page cache.

Quoted 7 lines

Load Program Data(02h/32h) will clear the entire page cache. As a result, when a request is split as described above, the previous written data will be cleared, breaking the page cache writing procedure.

We can change write_to_cache_op to use Load Program Data on the first request. If that doesn't finish writing, use Random Program Load on subsequent data loading.

Sounds reasonable indeed, feel free to send a patch.

Thanks,
Miquèl

author maintainer
#10 lore raw

Re: [PATCH v2] mtd: spinand: add support for FORESEE F35SQA002G

In reply to Chuanhong Guo
Quoted 72 lines · Chuanhong Guo

External email : Please do not click links or open attachments until you have verified the sender or the content.

Hello all!

Quoted 56 lines · Miquel Raynal
Quoted 52 lines · SkyLake Huang (黃啟澤)
Quoted 36 lines · Miquel Raynal

External email : Please do not click links or open attachments until
you have verified the sender or the content.

Hi Sky,

Quoted 13 lines · SkyLake Huang (黃啟澤)

Hi Miquel/Martin,
About this driver, including F35SQA001G/F35SQA002G parts, I'm concerned
that the driver will always use 32H for update_cache operations,
which
means it's not compitable with those SPI controller who can't transmit
2048 bytes (most small-density SPI-NAND's page size nowadays) at
one
time.

Quoted 12 lines

The following controller's driver seems that they can't transmit
2048
bytes in one transmission:
- spi-amd.c: 64 bytes (AMD_SPI_MAX_DATA)
- spi-amlogic-spifc-a1.c: 512 bytes (SPIFC_A1_BUFFER_SIZE)
- spi-fsl-qspi.c: 1KB
- spi-hisi-sfc-v3xx.c: 64*6 bytes
- spi-intel.c: 64 bytes (INTEL_SPI_FIFO_SZ)
- spi-microchip-core-qspi.c: 256 bytesc (MAX_DATA_CMD_LEN)
- spi-nxp-fspi.c: TX:1KB, RX: 512B in FIFO mode
- spi-wpcm-fiu.c: 4B

Quoted 11 lines

I believe most of these drivers are still able to send one page of
data
without toggling the CS (which is what actually matters, I believe).
If
they were broken, they would be broken with all spi memory devices,
not
only Foresee's.

Hi Miquel,
I think it's not about toggling the CS?

Quoted 7 lines
Quoted 7 lines

If a SPI controller tries to execute write page and it's capable to
send only 1KB in one transmission, it should transmit data in two
steps: 1st 34H (random program load x4) and 2nd 34H. However, when
F35SQA002G executes 2nd 34H command, it needs to execute 32H first, and

Quoted 12 lines

I don't think that's what the datasheet means. I think it needs 02h/32h as the first
command to write page cache, and the subsequent page cache writing can
be done using 84h/34h before the final page program happens. Otherwise the
84h/34h command is just completely broken and useless. If it actually is broken, we do need additional guards in spinand_write_cache_op
to abort when spi_mem_dirmap_write doesn't return exactly nbytes as requested.

Confirm with Foresee and yes you're right XD

Quoted 35 lines
Quoted 6 lines
Quoted 5 lines

it will clear data transmitted by 1st 34H in NAND flash's cache. This
will cause data corruption. Other SPI-NANDs doesn't need to execute 32H
before 34H.

Quoted 8 lines

Is it really what happens? I'd instead expect the spi controller to send:
- 34h
- 1k data
- 1k data
...

Why should we repeat the command while we are in the I/O phase?

Several SPI-MEM controller don't allow software controlled CS, or for some
other reasons are unable to execute a longer spi-mem op. spi_mem_dirmap_write returns the actual request size it's able to make,
and spinand_write_to_cache_op use a while loop to split one update_cache
request into multiple ones.

This only works using the Random Program Load instruction (84h/34h) which preserves the previous written data in the flash data cache. All current supported flashes are exclusively using 84h/34h as the command
to write the page cache.

Load Program Data(02h/32h) will clear the entire page cache. As a result, when a request is split as described above, the previous written
data will be cleared, breaking the page cache writing procedure.

Quoted 7 lines

We can change write_to_cache_op to use Load Program Data on the first request. If that doesn't finish writing, use Random Program Load
on subsequent data loading.
--
Regards,
Chuanhong Guo

I observe that exec_op() in drivers/spi/spi-mt65xx.c on our platform will issue the following commands once I limit its capability in 1024Bytes: (try to write 1 page)
- 34H
- addr
- 1020KB (1024KB - 1 byte opcode - 3 bytes addr)
- 34H
- addr
- 1020KB (1024KB - 1 byte opcode - 3 bytes addr)
- 34H
- addr
- 72KB

Is it possible to send 34H, 1K, 1K with current nbytes loop in spinand_write_to_cache_op()? With which SPI controller?

I submit a patch according to this discussion, anyway.

https://lore.kernel.org/linux-mtd/[email protected]/

BRs,
Sky

author maintainer
#11 lore raw

PATCH v3 4/5 net: phy: mediatek: Integrate read/write page helper functions

In reply to Sky Huang

From: "SkyLake.Huang" <[email protected]>

This patch integrates read/write page helper functions as MTK phy lib. They are basically the same in mtk-ge.c & mtk-ge-soc.c.

---
Change in v3:
- Fix kernel test robot error by adding missing MTK_NET_PHYLIB.

---
 drivers/net/phy/mediatek/Kconfig       |  1 +
 drivers/net/phy/mediatek/mtk-ge-soc.c  | 18 ++++--------------
 drivers/net/phy/mediatek/mtk-ge.c      | 20 ++++++--------------
 drivers/net/phy/mediatek/mtk-phy-lib.c | 12 ++++++++++++
 drivers/net/phy/mediatek/mtk.h         |  3 +++
 5 files changed, 26 insertions(+), 28 deletions(-)
drivers/net/phy/mediatek/Kconfig +1 -0
index 19b5d23..2a8ac5a 100644
@@ -4,6 +4,7 @@ config MTK_NET_PHYLIB
 
 config MEDIATEK_GE_PHY
 	tristate "MediaTek Gigabit Ethernet PHYs"
+	select MTK_NET_PHYLIB
 	help
 	  Supports the MediaTek non-built-in Gigabit Ethernet PHYs.
 
drivers/net/phy/mediatek/mtk-ge-soc.c +4 -14
index d3a8b39..38dc898 100644
@@ -271,16 +271,6 @@ struct mtk_socphy_shared {
 	struct mtk_socphy_priv	priv[4];
 };
 
-static int mtk_socphy_read_page(struct phy_device *phydev)
-{
-	return __phy_read(phydev, MTK_EXT_PAGE_ACCESS);
-}
-
-static int mtk_socphy_write_page(struct phy_device *phydev, int page)
-{
-	return __phy_write(phydev, MTK_EXT_PAGE_ACCESS, page);
-}
-
 /* One calibration cycle consists of:
  * 1.Set DA_CALIN_FLAG high to start calibration. Keep it high
  *   until AD_CAL_COMP is ready to output calibration result.
@@ -1337,8 +1327,8 @@ static struct phy_driver mtk_socphy_driver[] = {
 		.probe		= mt7981_phy_probe,
 		.suspend	= genphy_suspend,
 		.resume		= genphy_resume,
-		.read_page	= mtk_socphy_read_page,
-		.write_page	= mtk_socphy_write_page,
+		.read_page	= mtk_phy_read_page,
+		.write_page	= mtk_phy_write_page,
 		.led_blink_set	= mt798x_phy_led_blink_set,
 		.led_brightness_set = mt798x_phy_led_brightness_set,
 		.led_hw_is_supported = mt798x_phy_led_hw_is_supported,
@@ -1354,8 +1344,8 @@ static struct phy_driver mtk_socphy_driver[] = {
 		.probe		= mt7988_phy_probe,
 		.suspend	= genphy_suspend,
 		.resume		= genphy_resume,
-		.read_page	= mtk_socphy_read_page,
-		.write_page	= mtk_socphy_write_page,
+		.read_page	= mtk_phy_read_page,
+		.write_page	= mtk_phy_write_page,
 		.led_blink_set	= mt798x_phy_led_blink_set,
 		.led_brightness_set = mt798x_phy_led_brightness_set,
 		.led_hw_is_supported = mt798x_phy_led_hw_is_supported,
drivers/net/phy/mediatek/mtk-ge.c +6 -14
index 54ea64a..9122899 100644
@@ -3,6 +3,8 @@
 #include <linux/module.h>
 #include <linux/phy.h>
 
+#include "mtk.h"
+
 #define MTK_EXT_PAGE_ACCESS		0x1f
 #define MTK_PHY_PAGE_STANDARD		0x0000
 #define MTK_PHY_PAGE_EXTENDED		0x0001
@@ -11,16 +13,6 @@
 #define MTK_PHY_PAGE_EXTENDED_2A30	0x2a30
 #define MTK_PHY_PAGE_EXTENDED_52B5	0x52b5
 
-static int mtk_gephy_read_page(struct phy_device *phydev)
-{
-	return __phy_read(phydev, MTK_EXT_PAGE_ACCESS);
-}
-
-static int mtk_gephy_write_page(struct phy_device *phydev, int page)
-{
-	return __phy_write(phydev, MTK_EXT_PAGE_ACCESS, page);
-}
-
 static void mtk_gephy_config_init(struct phy_device *phydev)
 {
 	/* Enable HW auto downshift */
@@ -77,8 +69,8 @@ static struct phy_driver mtk_gephy_driver[] = {
 		.handle_interrupt = genphy_handle_interrupt_no_ack,
 		.suspend	= genphy_suspend,
 		.resume		= genphy_resume,
-		.read_page	= mtk_gephy_read_page,
-		.write_page	= mtk_gephy_write_page,
+		.read_page	= mtk_phy_read_page,
+		.write_page	= mtk_phy_write_page,
 	},
 	{
 		PHY_ID_MATCH_EXACT(0x03a29441),
@@ -91,8 +83,8 @@ static struct phy_driver mtk_gephy_driver[] = {
 		.handle_interrupt = genphy_handle_interrupt_no_ack,
 		.suspend	= genphy_suspend,
 		.resume		= genphy_resume,
-		.read_page	= mtk_gephy_read_page,
-		.write_page	= mtk_gephy_write_page,
+		.read_page	= mtk_phy_read_page,
+		.write_page	= mtk_phy_write_page,
 	},
 };
 
drivers/net/phy/mediatek/mtk-phy-lib.c +12 -0
index 8d795bc..98a09d6 100644
@@ -6,6 +6,18 @@
 
 #include "mtk.h"
 
+int mtk_phy_read_page(struct phy_device *phydev)
+{
+	return __phy_read(phydev, MTK_EXT_PAGE_ACCESS);
+}
+EXPORT_SYMBOL_GPL(mtk_phy_read_page);
+
+int mtk_phy_write_page(struct phy_device *phydev, int page)
+{
+	return __phy_write(phydev, MTK_EXT_PAGE_ACCESS, page);
+}
+EXPORT_SYMBOL_GPL(mtk_phy_write_page);
+
 int mtk_phy_led_hw_is_supported(struct phy_device *phydev, u8 index,
 				unsigned long rules,
 				unsigned long supported_triggers)
drivers/net/phy/mediatek/mtk.h +3 -0
index 9aaff2c..63d9fe1 100644
@@ -66,6 +66,9 @@ struct mtk_socphy_priv {
 	unsigned long		led_state;
 };
 
+int mtk_phy_read_page(struct phy_device *phydev);
+int mtk_phy_write_page(struct phy_device *phydev, int page);
+
 int mtk_phy_led_hw_is_supported(struct phy_device *phydev, u8 index,
 				unsigned long rules,
 				unsigned long supported_triggers);
Signature · 1 line
2.45.2
author maintainer
#12 lore raw

PATCH v3 5/5 net: phy: mediatek: add MT7530 & MT7531's PHY ID macros

In reply to Sky Huang

From: "SkyLake.Huang" <[email protected]>

This patch adds MT7530 & MT7531's PHY ID macros in mtk-ge.c so that it follows the same rule of mtk-ge-soc.c.

---
 drivers/net/phy/mediatek/mtk-ge.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/net/phy/mediatek/mtk-ge.c +7 -4
index 9122899..ed2617b 100644
@@ -5,6 +5,9 @@
 
 #include "mtk.h"
 
+#define MTK_GPHY_ID_MT7530		0x03a29412
+#define MTK_GPHY_ID_MT7531		0x03a29441
+
 #define MTK_EXT_PAGE_ACCESS		0x1f
 #define MTK_PHY_PAGE_STANDARD		0x0000
 #define MTK_PHY_PAGE_EXTENDED		0x0001
@@ -59,7 +62,7 @@ static int mt7531_phy_config_init(struct phy_device *phydev)
 
 static struct phy_driver mtk_gephy_driver[] = {
 	{
-		PHY_ID_MATCH_EXACT(0x03a29412),
+		PHY_ID_MATCH_EXACT(MTK_GPHY_ID_MT7530),
 		.name		= "MediaTek MT7530 PHY",
 		.config_init	= mt7530_phy_config_init,
 		/* Interrupts are handled by the switch, not the PHY
@@ -73,7 +76,7 @@ static struct phy_driver mtk_gephy_driver[] = {
 		.write_page	= mtk_phy_write_page,
 	},
 	{
-		PHY_ID_MATCH_EXACT(0x03a29441),
+		PHY_ID_MATCH_EXACT(MTK_GPHY_ID_MT7531),
 		.name		= "MediaTek MT7531 PHY",
 		.config_init	= mt7531_phy_config_init,
 		/* Interrupts are handled by the switch, not the PHY
@@ -91,8 +94,8 @@ static struct phy_driver mtk_gephy_driver[] = {
 module_phy_driver(mtk_gephy_driver);
 
 static struct mdio_device_id __maybe_unused mtk_gephy_tbl[] = {
-	{ PHY_ID_MATCH_EXACT(0x03a29441) },
-	{ PHY_ID_MATCH_EXACT(0x03a29412) },
+	{ PHY_ID_MATCH_EXACT(MTK_GPHY_ID_MT7530) },
+	{ PHY_ID_MATCH_EXACT(MTK_GPHY_ID_MT7531) },
 	{ }
 };
 
Signature · 1 line
2.45.2
#13 lore raw
In reply to Sky Huang
This series was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:

Quoted 10 lines · On Sat, 9 Nov 2024 00:34:50 +0800 you wrote:

From: Sky Huang <[email protected]>

This patchset comes from patch 1/9, 3/9, 4/9, 5/9 and 7/9 of:
https://lore.kernel.org/netdev/[email protected]/

This patchset changes MediaTek's ethernet phy's folder structure and integrates helper functions, including LED & token ring manipulation, into mtk-phy-lib.

[...]

Here is the summary with links:
- [net-next,v3,1/5] net: phy: mediatek: Re-organize MediaTek ethernet phy drivers

    https://git.kernel.org/netdev/net-next/c/4c452f7ea862
  - [net-next,v3,2/5] net: phy: mediatek: Move LED helper functions into mtk phy lib
    https://git.kernel.org/netdev/net-next/c/7f9c320c98db
  - [net-next,v3,3/5] net: phy: mediatek: Improve readability of mtk-phy-lib.c's mtk_phy_led_hw_ctrl_set()
    https://git.kernel.org/netdev/net-next/c/477c200aa7d2
  - [net-next,v3,4/5] net: phy: mediatek: Integrate read/write page helper functions
    https://git.kernel.org/netdev/net-next/c/3cb1a3c9cbaa
  - [net-next,v3,5/5] net: phy: mediatek: add MT7530 & MT7531's PHY ID macros
    https://git.kernel.org/netdev/net-next/c/219cecbb3e86

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html