Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'net-sfp-add-support-for-gpon-rtl8672-rtl9601c-and-ubiquiti-u-fiber'

Pali Rohár says:

====================
net: sfp: add support for GPON RTL8672/RTL9601C and Ubiquiti U-Fiber

This is fourth version of patches which add workarounds for
RTL8672/RTL9601C EEPROMs and Ubiquiti U-Fiber Instant SFP.
====================

Link: https://lore.kernel.org/r/20210125150228.8523-1-pali@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+97 -35
+15
drivers/net/phy/sfp-bus.c
··· 44 44 phylink_set(modes, 2500baseX_Full); 45 45 } 46 46 47 + static void sfp_quirk_ubnt_uf_instant(const struct sfp_eeprom_id *id, 48 + unsigned long *modes) 49 + { 50 + /* Ubiquiti U-Fiber Instant module claims that support all transceiver 51 + * types including 10G Ethernet which is not truth. So clear all claimed 52 + * modes and set only one mode which module supports: 1000baseX_Full. 53 + */ 54 + phylink_zero(modes); 55 + phylink_set(modes, 1000baseX_Full); 56 + } 57 + 47 58 static const struct sfp_quirk sfp_quirks[] = { 48 59 { 49 60 // Alcatel Lucent G-010S-P can operate at 2500base-X, but ··· 74 63 .vendor = "HUAWEI", 75 64 .part = "MA5671A", 76 65 .modes = sfp_quirk_2500basex, 66 + }, { 67 + .vendor = "UBNT", 68 + .part = "UF-INSTANT", 69 + .modes = sfp_quirk_ubnt_uf_instant, 77 70 }, 78 71 }; 79 72
+82 -35
drivers/net/phy/sfp.c
··· 277 277 278 278 static bool sfp_module_supported(const struct sfp_eeprom_id *id) 279 279 { 280 - return id->base.phys_id == SFF8024_ID_SFP && 281 - id->base.phys_ext_id == SFP_PHYS_EXT_ID_SFP; 280 + if (id->base.phys_id == SFF8024_ID_SFP && 281 + id->base.phys_ext_id == SFP_PHYS_EXT_ID_SFP) 282 + return true; 283 + 284 + /* SFP GPON module Ubiquiti U-Fiber Instant has in its EEPROM stored 285 + * phys id SFF instead of SFP. Therefore mark this module explicitly 286 + * as supported based on vendor name and pn match. 287 + */ 288 + if (id->base.phys_id == SFF8024_ID_SFF_8472 && 289 + id->base.phys_ext_id == SFP_PHYS_EXT_ID_SFP && 290 + !memcmp(id->base.vendor_name, "UBNT ", 16) && 291 + !memcmp(id->base.vendor_pn, "UF-INSTANT ", 16)) 292 + return true; 293 + 294 + return false; 282 295 } 283 296 284 297 static const struct sff_data sfp_data = { ··· 353 340 size_t len) 354 341 { 355 342 struct i2c_msg msgs[2]; 356 - size_t block_size; 343 + u8 bus_addr = a2 ? 0x51 : 0x50; 344 + size_t block_size = sfp->i2c_block_size; 357 345 size_t this_len; 358 - u8 bus_addr; 359 346 int ret; 360 - 361 - if (a2) { 362 - block_size = 16; 363 - bus_addr = 0x51; 364 - } else { 365 - block_size = sfp->i2c_block_size; 366 - bus_addr = 0x50; 367 - } 368 347 369 348 msgs[0].addr = bus_addr; 370 349 msgs[0].flags = 0; ··· 1291 1286 struct sfp *sfp = container_of(work, struct sfp, hwmon_probe.work); 1292 1287 int err, i; 1293 1288 1289 + /* hwmon interface needs to access 16bit registers in atomic way to 1290 + * guarantee coherency of the diagnostic monitoring data. If it is not 1291 + * possible to guarantee coherency because EEPROM is broken in such way 1292 + * that does not support atomic 16bit read operation then we have to 1293 + * skip registration of hwmon device. 1294 + */ 1295 + if (sfp->i2c_block_size < 2) { 1296 + dev_info(sfp->dev, 1297 + "skipping hwmon device registration due to broken EEPROM\n"); 1298 + dev_info(sfp->dev, 1299 + "diagnostic EEPROM area cannot be read atomically to guarantee data coherency\n"); 1300 + return; 1301 + } 1302 + 1294 1303 err = sfp_read(sfp, true, 0, &sfp->diag, sizeof(sfp->diag)); 1295 1304 if (err < 0) { 1296 1305 if (sfp->hwmon_tries--) { ··· 1721 1702 return 0; 1722 1703 } 1723 1704 1724 - /* Some modules (Nokia 3FE46541AA) lock up if byte 0x51 is read as a 1725 - * single read. Switch back to reading 16 byte blocks unless we have 1726 - * a CarlitoxxPro module (rebranded VSOL V2801F). Even more annoyingly, 1727 - * some VSOL V2801F have the vendor name changed to OEM. 1705 + /* GPON modules based on Realtek RTL8672 and RTL9601C chips (e.g. V-SOL 1706 + * V2801F, CarlitoxxPro CPGOS03-0490, Ubiquiti U-Fiber Instant, ...) do 1707 + * not support multibyte reads from the EEPROM. Each multi-byte read 1708 + * operation returns just one byte of EEPROM followed by zeros. There is 1709 + * no way to identify which modules are using Realtek RTL8672 and RTL9601C 1710 + * chips. Moreover every OEM of V-SOL V2801F module puts its own vendor 1711 + * name and vendor id into EEPROM, so there is even no way to detect if 1712 + * module is V-SOL V2801F. Therefore check for those zeros in the read 1713 + * data and then based on check switch to reading EEPROM to one byte 1714 + * at a time. 1728 1715 */ 1729 - static int sfp_quirk_i2c_block_size(const struct sfp_eeprom_base *base) 1716 + static bool sfp_id_needs_byte_io(struct sfp *sfp, void *buf, size_t len) 1730 1717 { 1731 - if (!memcmp(base->vendor_name, "VSOL ", 16)) 1732 - return 1; 1733 - if (!memcmp(base->vendor_name, "OEM ", 16) && 1734 - !memcmp(base->vendor_pn, "V2801F ", 16)) 1735 - return 1; 1718 + size_t i, block_size = sfp->i2c_block_size; 1736 1719 1737 - /* Some modules can't cope with long reads */ 1738 - return 16; 1739 - } 1720 + /* Already using byte IO */ 1721 + if (block_size == 1) 1722 + return false; 1740 1723 1741 - static void sfp_quirks_base(struct sfp *sfp, const struct sfp_eeprom_base *base) 1742 - { 1743 - sfp->i2c_block_size = sfp_quirk_i2c_block_size(base); 1724 + for (i = 1; i < len; i += block_size) { 1725 + if (memchr_inv(buf + i, '\0', min(block_size - 1, len - i))) 1726 + return false; 1727 + } 1728 + return true; 1744 1729 } 1745 1730 1746 1731 static int sfp_cotsworks_fixup_check(struct sfp *sfp, struct sfp_eeprom_id *id) ··· 1788 1765 u8 check; 1789 1766 int ret; 1790 1767 1791 - /* Some modules (CarlitoxxPro CPGOS03-0490) do not support multibyte 1792 - * reads from the EEPROM, so start by reading the base identifying 1793 - * information one byte at a time. 1768 + /* Some SFP modules and also some Linux I2C drivers do not like reads 1769 + * longer than 16 bytes, so read the EEPROM in chunks of 16 bytes at 1770 + * a time. 1794 1771 */ 1795 - sfp->i2c_block_size = 1; 1772 + sfp->i2c_block_size = 16; 1796 1773 1797 1774 ret = sfp_read(sfp, false, 0, &id.base, sizeof(id.base)); 1798 1775 if (ret < 0) { ··· 1804 1781 if (ret != sizeof(id.base)) { 1805 1782 dev_err(sfp->dev, "EEPROM short read: %d\n", ret); 1806 1783 return -EAGAIN; 1784 + } 1785 + 1786 + /* Some SFP modules (e.g. Nokia 3FE46541AA) lock up if read from 1787 + * address 0x51 is just one byte at a time. Also SFF-8472 requires 1788 + * that EEPROM supports atomic 16bit read operation for diagnostic 1789 + * fields, so do not switch to one byte reading at a time unless it 1790 + * is really required and we have no other option. 1791 + */ 1792 + if (sfp_id_needs_byte_io(sfp, &id.base, sizeof(id.base))) { 1793 + dev_info(sfp->dev, 1794 + "Detected broken RTL8672/RTL9601C emulated EEPROM\n"); 1795 + dev_info(sfp->dev, 1796 + "Switching to reading EEPROM to one byte at a time\n"); 1797 + sfp->i2c_block_size = 1; 1798 + 1799 + ret = sfp_read(sfp, false, 0, &id.base, sizeof(id.base)); 1800 + if (ret < 0) { 1801 + if (report) 1802 + dev_err(sfp->dev, "failed to read EEPROM: %d\n", 1803 + ret); 1804 + return -EAGAIN; 1805 + } 1806 + 1807 + if (ret != sizeof(id.base)) { 1808 + dev_err(sfp->dev, "EEPROM short read: %d\n", ret); 1809 + return -EAGAIN; 1810 + } 1807 1811 } 1808 1812 1809 1813 /* Cotsworks do not seem to update the checksums when they ··· 1866 1816 return -EINVAL; 1867 1817 } 1868 1818 } 1869 - 1870 - /* Apply any early module-specific quirks */ 1871 - sfp_quirks_base(sfp, &id.base); 1872 1819 1873 1820 ret = sfp_read(sfp, false, SFP_CC_BASE + 1, &id.ext, sizeof(id.ext)); 1874 1821 if (ret < 0) {