r8169: add ethtool eeprom change/dump feature
PATCH 1/1 r8169: add ethtool eeprom change/dump feature
This adds the ability to read and change EEPROM for 93C46/93C56 serial EEPROM. Two-Wire serial interface and SPI are not supported. (Do not even try this for SPI or other chips, it may break your hardware.)
Works with RTL8169SCL (driver detects RTL8169sb), with some quirks. Not sure if it is a hardware bug, but to be able to read EEPROM, one has to write something, e.g.:
printf '\0\0' | ethtool -E eth0 magic 0x8169 offset 0x40 length 2
Otherwise, only zeroes are read. Another note for this NIC, one has to "enable" the eeprom by writing to it (as shown above) and then make the NIC to reload the contents from firmware such that the PCI ID gets detected correctly (10ec:8169 instead of 10ec:8129). Reload by writing 0x40 (Auto-load) to register 0x50 (9346CR):
printf '\x40' | dd seek=80 bs=1 \
of=/sys/bus/pci/devices/0000:03:00.0/resource0Then detach and rescan the PCI device (use lspci -tv to find parent):
echo 1 > /sys/bus/pci/devices/0000\:03\:00.0/remove
echo 1 > /sys/bus/pci/devices/0000\:02\:00.0/rescanAfter this, this RTL8169sb PCI GbE NIC appears to work.
On a second RTL8188E onboard GbE chip, EEPROM cannot be dumped, writing also does nothing. Here, reads all return FFs.
---
Hi,
An RFC of this patch was created a month ago[1]. Ben Hutchings suggested to drop the CONFIG knob and always include the ethtool operations for getting and setting the EEPROM, so I did that for later versions. This new patch also checks the EEPROM size (depends on whether 93C46 or 93C56 is used) and has a minor style fix (brace on new line).
I do not know why exactly I have to do funky things with the EEPROM to fix the PCI IDs. Hayes, perhaps you have an idea?
[ lspci of broken device ]
03:00.0 Ethernet controller [0200]: Realtek Semiconductor Co., Ltd. RTL-8129 [10ec:8129] (rev 10)
Subsystem: Coreco Inc RT8129 Fast Ethernet Adapter [11ec:8129]
Control: I/O+ Mem+ BusMaster- SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx-
Status: Cap+ 66MHz+ UDF- FastB2B+ ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
Interrupt: pin A routed to IRQ 19
Region 0: I/O ports at e000 [size=256]
Region 1: Memory at f7b41000 (32-bit, non-prefetchable) [size=256]
Expansion ROM at f7b00000 [disabled] [size=256K]
Capabilities: [dc] Power Management version 1
Flags: PMEClk- DSI- D1- D2- AuxCurrent=55mA PME(D0-,D1-,D2-,D3hot-,D3cold+)
Status: D0 NoSoftRst- PME-Enable- DSel=0 DScale=0 PME-
Kernel driver in use: pci-stub
Kernel modules: r8169, 8139too
[ lspci after EEPROM activation, working device ]
03:00.0 Ethernet controller [0200]: Realtek Semiconductor Co., Ltd. RTL-8129 [10ec:8129] (rev 10)
Subsystem: Realtek Semiconductor Co., Ltd. Device [10ec:8169]
Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV+ VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx-
Status: Cap+ 66MHz+ UDF- FastB2B+ ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
Latency: 32 (8000ns min, 16000ns max), Cache Line Size: 64 bytes
Interrupt: pin A routed to IRQ 19
Region 0: I/O ports at e000 [size=256]
Region 1: [virtual] Memory at f7b41000 (32-bit, non-prefetchable) [size=256] Expansion ROM at f7b00000 [disabled] [size=256K]
Capabilities: [dc] Power Management version 2
Flags: PMEClk- DSI- D1+ D2+ AuxCurrent=375mA PME(D0-,D1+,D2+,D3hot+,D3cold+)
Status: D0 NoSoftRst- PME-Enable- DSel=0 DScale=0 PME-
Kernel driver in use: r8169
Kernel modules: r8169, 8139too
Note: while writing the EEPROM while the card is "broken", I see the following in my dmesg:
eeprom_93cx6_write: timeout
FWIW, two photos of this card can be found on
https://lekensteyn.nl/files/realtek/ (this Lefen BL-L8169-2 card was bought via eBay).
Regards,
Peter
[1]: http://lkml.kernel.org/r/1906856.2MoFjQXLhS@al
--- drivers/net/ethernet/realtek/Kconfig | 1 + drivers/net/ethernet/realtek/r8169.c | 158 ++++++++++++++++++++++++++++++++++- 2 files changed, 156 insertions(+), 3 deletions(-)
drivers/net/ethernet/realtek/Kconfig +1 -0
@@ -106,6 +106,7 @@ config R8169 select FW_LOADER select CRC32 select MII + select EEPROM_93CX6 ---help--- Say Y here if you have a Realtek 8169 PCI Gigabit Ethernet adapter.
drivers/net/ethernet/realtek/r8169.c +155 -3
194 lines not on this page · raw message
Signature · 1 line
1.8.4
David Miller
maintainerFrom: Peter Wu <[email protected]>
Date: Thu, 29 Aug 2013 16:44:51 +0200
Quoted 3 lines
This adds the ability to read and change EEPROM for 93C46/93C56 serial EEPROM. Two-Wire serial interface and SPI are not supported. (Do not even try this for SPI or other chips, it may break your hardware.)
Please block the operation on configurations, such as the aforementioned SPI, where it won't work.
Quoted 9 lines · On Tuesday 03 September 2013 21:59:35 David Miller wrote:
From: Peter Wu <[email protected]>
Date: Thu, 29 Aug 2013 16:44:51 +0200Quoted 3 lines
This adds the ability to read and change EEPROM for 93C46/93C56 serial EEPROM. Two-Wire serial interface and SPI are not supported. (Do not even try this for SPI or other chips, it may break your hardware.)
Please block the operation on configurations, such as the aforementioned SPI, where it won't work.
I do not know how to detect those, as far as I know it's harmless, the r8168 vendor driver does not perform other checks either. If I look at "Realtek RTL8411 EEPROM/eFUSE Datasheet 1.1", then SPI access is done via CONFIG0 which is then at offset 51h and not 50h (which is used for 9346CR).
This SPI seems to be used for the Boot ROM, not EEPROM. Even the "RTL8111E-VL- CG" (May 2012) mentions the 9346CR register, so I think it is safe to assume that nothing breaks. At worst you read invalid values (ff) and writes are no- op.
I can remove this scary warning from the commit message, but it would really be nice if a Realtek engineer could give more information on this.
Regards,
Peter