From nobody Sat Feb 7 07:24:57 2026 Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0FDA9329C5F for ; Mon, 5 Jan 2026 16:12:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767629579; cv=none; b=Khxq9q88tJUOEcYUa3L6E9zXD19nnY8WuKP7r0q1gZ1stuDUjQhV5tXGjXxSWg0tljvqWc/OG9jONfE2j9u0o4j39ZZfLtTk4LVzL2ddlxlWAMJHoMm7wENZNJQyynB1e0OdXpBB9JMBfE0vffgLttnr8sKpWZZzDuQdPRWb9tA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767629579; c=relaxed/simple; bh=+5jhfypVPPIYb0+sRwbUK3QmAT6+nuI7bYH6l4HoWgM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=YtsGlT3Gj1JDV/IZ9xu5MqSLakV/p6oY6IVn9X+hwFg1/UEwIo/kXzoN1c7U2IJKgrVR5/vrU0z9YiAhkAddEgsZkKJ+zIqzLN21yW9KmSUPKbFl8RNLDd6YqFycK6tNsm7iBwxqUmnAF0hBqHAeAesSYm1Vz9oyyzU9isYARmM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=OZoNDfGj; arc=none smtp.client-ip=209.85.208.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OZoNDfGj" Received: by mail-ed1-f50.google.com with SMTP id 4fb4d7f45d1cf-64b791b5584so99653a12.0 for ; Mon, 05 Jan 2026 08:12:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767629573; x=1768234373; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=6JyO/4GLHb5fMiTunzQRnSORs3Y8GgfKp+eWwFQOVdM=; b=OZoNDfGjYpdBxijD1H7c70TckZ1VT+D1C8FDMXvWhQVU4K/LmoH0pWpcY9cyxbdkX/ LTWsoE5ua4E5ktM3mZF+Uf3WNTSIbkjmu4dxlzze73Adq0v+6S4atZQd+LQjWhts92PV a8UuLqVTLwwREerata26q7EDovFPcjdQ/qdtSnw3BGLDb8p/n4jtLz/LczcVy3JVvsmb CtBbvs5BR/hMQEuxgi/Kxp4c6y4xdlkLBaqX/dWFGu52vr7xzIT/539OCBuXhYQpXVrd B/42PrgwKAnPP22SsajsWevCiLdtDIz97KxflBg97EgNrxg34yFIGALT5pMhCy0YwI9G WPpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767629573; x=1768234373; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=6JyO/4GLHb5fMiTunzQRnSORs3Y8GgfKp+eWwFQOVdM=; b=HE7u7XVf3aqQLbtmiZVDktf/TpsSypxgMn5PVufQIe5PpvLawWIfXHC5Eq03fqj0DX doBpSIPF3Brh/GvAvO+DeKk51S8gZpwWeIWCWix5LiElWfo3P4o2VSGBb4DZ/CPxWMFt H1GTrCnGOBSty/U354LUqiO3eNSQsNXIG2rTVwK10mFkmN0YYXKLKp7joVI2SsT1f5N7 ldfDoqbMwkiI+Vm0HILEOPVk60CuGa4Esmjj66cYjNle0+95DgcGUm7ThrHkMdjEeIzG hTldcuTJS+P+eFVH7PdpVAwRFnOUzf0cOj0TX4WZcAmi0jL+Mjn+OBNOsAx3J5154D92 fzSg== X-Forwarded-Encrypted: i=1; AJvYcCWk3OI7f8We3IiUWWRBlVfinnTKPKJyX3iaQdOgri7nD54HLZ1cLfS+iFeZmJrHZbbD7qhjbXwLRiLH3v0=@vger.kernel.org X-Gm-Message-State: AOJu0Yy+Dryvix97CEoOZyp6mYbB+TAlvoMam/AgJTVC2XHZ9EJMrfea 0H2Ux2xx3KKysU7fUzPXfaxHl7l+NPfogbKaESRMjSXTlH46Qm2N7Ecz X-Gm-Gg: AY/fxX65tyMjYRayBXm3LVaRb25PvWsF/1YcwQ6keZqKDArpXalQVARUTbD3bKebRMi MHDRNEmooDLcoR23iIDAuAlM1ZR3yk2qwmB+Lig5sO5dxrE6voBPHEbQy2VsXVsasE9r17UrFFj RGn6JUa58L4ZEj3Z9A8yq7VvKltoLAf8X42nfT2NhvZuHIxJWWzZgwxrjaLUV8uVwzOPAbGELit NoiunEj+3i7dKMvbPgsh2G02MbtBXZhjR8QQUIDe8qHElIF+juxzbugM7E+tcm3wZrbrJlldcQU nr5MN79rBdvKuwJ3Q5gcE0oY/UjPGXn5pw8W+5CxDW1LXzHYm/PUyrflJQ7Zuk2k2l0m5pXSWYe sNWdNha+3xm7pMasDh+w20Lfjg8FhGbcGLUF3OZleVZRzdEAlhMMl+IBIh4LqUf+EFHKap8z+fr +qNbO2jsU9PgEQ0iA= X-Google-Smtp-Source: AGHT+IENmT/MU8iQb9/3/4a9APHsSe4lNd++/lbyAnV3R6n9vio3JwjLfVyuMDllZ9wMr6RrbeBpkA== X-Received: by 2002:a17:907:6d21:b0:b7d:1cbb:5deb with SMTP id a640c23a62f3a-b8426a9f126mr33838266b.27.1767629572962; Mon, 05 Jan 2026 08:12:52 -0800 (PST) Received: from builder.. ([2001:9e8:f13d:d916:be24:11ff:fe30:5d85]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b84265ec75fsm29908566b.20.2026.01.05.08.12.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Jan 2026 08:12:52 -0800 (PST) From: Jonas Jelonek To: Russell King , Andrew Lunn , Heiner Kallweit , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Bj=C3=B8rn=20Mork?= , Maxime Chevallier , Jonas Jelonek Subject: [PATCH v3] net: sfp: add SMBus I2C block support Date: Mon, 5 Jan 2026 16:12:42 +0000 Message-ID: <20260105161242.578487-1-jelonek.jonas@gmail.com> X-Mailer: git-send-email 2.48.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Commit 7662abf4db94 ("net: phy: sfp: Add support for SMBus module access") added support for SMBus-only controllers for module access. However, this is restricted to single-byte accesses and has the implication that hwmon is disabled (due to missing atomicity of 16-bit accesses) and warnings are printed. There are probably a lot of SMBus-only I2C controllers out in the wild which support block reads. Right now, they don't work with SFP modules. This applies - amongst others - to I2C/SMBus-only controllers in Realtek longan and mango SoCs. Downstream in OpenWrt, a patch similar to the abovementioned patch is used for current LTS kernel 6.12. However, this uses byte-access for all kinds of access and thus disregards the atomicity for wider access. Introduce read/write SMBus I2C block operations to support SMBus-only controllers with appropriate support for block read/write. Those operations are used for all accesses if supported, otherwise the single-byte operations will be used. With block reads, atomicity for 16-bit reads as required by hwmon is preserved and thus, hwmon can be used. The implementation requires the I2C_FUNC_SMBUS_I2C_BLOCK to be supported as it relies on reading a pre-defined amount of bytes. This isn't intended by the official SMBus Block Read but supported by several I2C controllers/drivers. Support for word access is not implemented due to issues regarding endianness. Signed-off-by: Jonas Jelonek --- v3: fix previous attempt of v2 to fix return value v2: return number of written bytes in sfp_smbus_block_write v2: https://lore.kernel.org/netdev/20260105154653.575397-1-jelonek.jonas@gm= ail.com/ v1: https://lore.kernel.org/netdev/20251228213331.472887-1-jelonek.jonas@gm= ail.com/ --- drivers/net/phy/sfp.c | 77 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 75 insertions(+), 2 deletions(-) diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c index 84bef5099dda..a1deb80f630a 100644 --- a/drivers/net/phy/sfp.c +++ b/drivers/net/phy/sfp.c @@ -744,6 +744,35 @@ static int sfp_smbus_byte_read(struct sfp *sfp, bool a= 2, u8 dev_addr, return data - (u8 *)buf; } =20 +static int sfp_smbus_block_read(struct sfp *sfp, bool a2, u8 dev_addr, + void *buf, size_t len) +{ + size_t block_size =3D sfp->i2c_block_size; + union i2c_smbus_data smbus_data; + u8 bus_addr =3D a2 ? 0x51 : 0x50; + u8 *data =3D buf; + u8 this_len; + int ret; + + while (len) { + this_len =3D min(len, block_size); + + smbus_data.block[0] =3D this_len; + ret =3D i2c_smbus_xfer(sfp->i2c, bus_addr, 0, + I2C_SMBUS_READ, dev_addr, + I2C_SMBUS_I2C_BLOCK_DATA, &smbus_data); + if (ret < 0) + return ret; + + memcpy(data, &smbus_data.block[1], this_len); + len -=3D this_len; + data +=3D this_len; + dev_addr +=3D this_len; + } + + return data - (u8 *)buf; +} + static int sfp_smbus_byte_write(struct sfp *sfp, bool a2, u8 dev_addr, void *buf, size_t len) { @@ -768,23 +797,67 @@ static int sfp_smbus_byte_write(struct sfp *sfp, bool= a2, u8 dev_addr, return data - (u8 *)buf; } =20 +static int sfp_smbus_block_write(struct sfp *sfp, bool a2, u8 dev_addr, + void *buf, size_t len) +{ + size_t block_size =3D sfp->i2c_block_size; + union i2c_smbus_data smbus_data; + u8 bus_addr =3D a2 ? 0x51 : 0x50; + u8 *data =3D buf; + u8 this_len; + int ret; + + while (len) { + this_len =3D min(len, block_size); + + smbus_data.block[0] =3D this_len; + memcpy(&smbus_data.block[1], data, this_len); + ret =3D i2c_smbus_xfer(sfp->i2c, bus_addr, 0, + I2C_SMBUS_WRITE, dev_addr, + I2C_SMBUS_I2C_BLOCK_DATA, &smbus_data); + if (ret) + return ret; + + len -=3D this_len; + data +=3D this_len; + dev_addr +=3D this_len; + } + + return data - (u8 *)buf; +} + static int sfp_i2c_configure(struct sfp *sfp, struct i2c_adapter *i2c) { + size_t max_block_size; + sfp->i2c =3D i2c; =20 if (i2c_check_functionality(i2c, I2C_FUNC_I2C)) { sfp->read =3D sfp_i2c_read; sfp->write =3D sfp_i2c_write; - sfp->i2c_max_block_size =3D SFP_EEPROM_BLOCK_SIZE; + max_block_size =3D SFP_EEPROM_BLOCK_SIZE; + } else if (i2c_check_functionality(i2c, I2C_FUNC_SMBUS_I2C_BLOCK)) { + sfp->read =3D sfp_smbus_block_read; + sfp->write =3D sfp_smbus_block_write; + + max_block_size =3D SFP_EEPROM_BLOCK_SIZE; + if (i2c->quirks && i2c->quirks->max_read_len) + max_block_size =3D min(max_block_size, + i2c->quirks->max_read_len); + if (i2c->quirks && i2c->quirks->max_write_len) + max_block_size =3D min(max_block_size, + i2c->quirks->max_write_len); + } else if (i2c_check_functionality(i2c, I2C_FUNC_SMBUS_BYTE_DATA)) { sfp->read =3D sfp_smbus_byte_read; sfp->write =3D sfp_smbus_byte_write; - sfp->i2c_max_block_size =3D 1; + max_block_size =3D 1; } else { sfp->i2c =3D NULL; return -EINVAL; } =20 + sfp->i2c_max_block_size =3D max_block_size; return 0; } =20 base-commit: c303e8b86d9dbd6868f5216272973292f7f3b7f1 prerequisite-patch-id: ae039dad1e17867fce9182b6b36ac3b1926b254a --=20 2.48.1