From nobody Sat Feb 7 17:20:43 2026 Received: from mail-ej1-f49.google.com (mail-ej1-f49.google.com [209.85.218.49]) (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 6117A33C538 for ; Mon, 5 Jan 2026 15:47:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767628036; cv=none; b=t157WmO+22tkwh8fuR7YHBZU07pr98PEX3gnrzOccLlffBOizVG+wUf8DHNzTCrcoyLdMQDavPHuU3wHlPwAmCDZZDjRtY0r7X6WTkYRYH6oYAb0tqAUfXS11ae/5i6LhxGSD7fM4W3WVTVClypd2vondtul3VAoSPgRmKIdCo0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767628036; c=relaxed/simple; bh=QYEuEY61wG8oUvuzapP8GVYDVxXmSdsiwBHw/T5y+A4=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=HHwuWF5nNxjGwk7Xipvk1dIu/26Y77Zwr/n0ZU8ATb9ZV3i2IGVJIqyHUsFwf3yIQ9wtc+1r8MIygV3K44QuR6b3qK8JHO4YiyfeY/ICOjH2TVMtyGiuf6UvjymIuffzdbIxqmcnH/CfdQBgiE7h6F9o/mugT1iwoeqxm7FiMc4= 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=RQM40Uti; arc=none smtp.client-ip=209.85.218.49 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="RQM40Uti" Received: by mail-ej1-f49.google.com with SMTP id a640c23a62f3a-b832c65124cso15304266b.0 for ; Mon, 05 Jan 2026 07:47:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767628033; x=1768232833; 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=ma+GEuhKvq1iucMrcGxna3GqAPQ3VBX1HpzGhekETBM=; b=RQM40UtiY5lxvSSPjr3Y7DBzWVrUjl703d7JPmFrL5hUN7AiffT1RNc3ktIKABDnAB 484DKFA2v+zhn9DOJevM4fiHM68VwQt82DrZPkolwHZ7y9qLdky4nbGfkDw+TzlL39wc mlkH/Zb9xToM15IeHPCeLtokJCufNiSFfB/7D0jysZuFo+F1g0+HK+z7e35SCrEG47z4 UitAH278KfVgi8L24F40iIojGft7p9AlB822tGU4NHXy/0KXyE/v1uIdNMeE3EA4QvAj GysG0GAVZBMN3N+sTFgXxhpm4ucqbWuCZdRr3k7CDXHwCkMmqE+J62vbjocomkojbRhT Tj6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767628033; x=1768232833; 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=ma+GEuhKvq1iucMrcGxna3GqAPQ3VBX1HpzGhekETBM=; b=caEFZpgAVvNokDHZyvb28VBf1FO2bdnsu0mzY+drXSCymeIWAYdqKVsMR+D6bYC8lP q9dWvLtY8W15E0nqUBlEwqYSK2QhIccBYa/vmfUHuaph/hG/vOuSNOju67m9/vUfmRK+ NKSq/QVa6w3PaI6j7dWAq/P2/niomEe6UYBjxebL8zlgMvpZlnZU8Z9Svye22iY4sMaS gghoyCUPEmQJLmMUkQrvTXoc7IXIjCIRABB/qlB8JO4q2EmAqPNArES+ZXNsJfen4Qn/ enyBjfh34IvkATQcHlnItkF7cNLzyb+5rNWCogauDHsnoCpBFtqnWiDOuZPc/Lg1TgP4 arAw== X-Forwarded-Encrypted: i=1; AJvYcCWdKQ4mRcc++A2pvw/BndPUa37S8uGKSuAlb5AwstEL1tUXWEUjP9vT0On76wDa8X8yedgmEXeJrM4kleI=@vger.kernel.org X-Gm-Message-State: AOJu0YxKLbPtNM1UQwGg4aEpGDWSXCGcEM7XZmoSTyPDgljlmO55O0Um BmpQUtKGBHwfwogh4pmiS1vXiz07KRxLdP8mNEc89ScQ61WA9m/l+Kuq X-Gm-Gg: AY/fxX7PqBzj40aB8OgYvhYyR7xHXst53KrpXAljba4Aw1RZQ/IIbcDcNR41SF2vDPT QGngXnLZjf4ao9mSr4X0cbGGrTb6eTAo5nl9VbZpojuduvW5e7maE9PfQsqC+q6GnQjxm3WtaHC QiTIMlIHLtflyT+5Z4aNIEL2OEOyH8Jjws08KP8XzbJLZLzes4PS6Ob3tWoGqEq3/w53bl2ldN0 1HM+sysDAUM2RzoWvd/bGy80a8MaA6pN75/+tfeBtk3lQu7irtmb6nHRD4Jt2vptjDua7kjx0oQ 91YAc2LrwAE3FQI6YRPav89x45ENPhDG8T7kIaGZa5k8pNYifZvjugFmeJ3d8WhdcBSz4M0w5iD Q1wRGwl8PwUO0YJ6tUIhFvwMf7RH04aQ27t5+dpTIjbWFJWCB8DG8oe+Z0RjeZOTUS4nGWoiLcz aOt9tZ2j4/SnC7f3/CB/Vrx8OuUw== X-Google-Smtp-Source: AGHT+IFu4fkD1Setd5lZUTe5/J+3L/4MXVljFxVKe0P+9I4fnxbNSOkjXQLnIsMCeE/m70suRLe4ig== X-Received: by 2002:a17:907:a4b:b0:b6d:9576:3890 with SMTP id a640c23a62f3a-b8426bf130bmr18681866b.45.1767628032332; Mon, 05 Jan 2026 07:47:12 -0800 (PST) Received: from builder.. ([2001:9e8:f13d:d916:be24:11ff:fe30:5d85]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b8426612903sm27217466b.30.2026.01.05.07.47.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Jan 2026 07:47:11 -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 v2] net: sfp: add SMBus I2C block support Date: Mon, 5 Jan 2026 15:46:53 +0000 Message-ID: <20260105154653.575397-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 --- v2: return number of written bytes in sfp_smbus_block_write 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 6166e9196364..4f2175397534 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) { @@ -765,26 +794,70 @@ static int sfp_smbus_byte_write(struct sfp *sfp, bool= a2, u8 dev_addr, dev_addr++; } =20 + return data - (u8 *)buf; +} + +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 0; } =20 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 --=20 2.48.1