From nobody Sat Feb 7 09:59:31 2026 Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.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 388D0336EF1 for ; Fri, 9 Jan 2026 10:13:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767953610; cv=none; b=ICjoHvz2fQkd2ykFZ+6psI+Za2/ac7a9lsW5P2YBu6Ya3E9+i4ZG5FNzqpf1sKUXG113XYHTLZ+IfZAxazf8tBDiXnRrJ65AR8x/8acwwedOgJTr53eIpfml4UZqdWjAdVkg06TxVPtoSzXTRlnk4j9eGFtQMT2QX7q1iuNHTEk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767953610; c=relaxed/simple; bh=LZv7VbJVZNPCl/GQ3+7aKwn27qsXY6G1rJO/vD5EKeI=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=hM44rBDL+MpNQ15x//e4f3UxhqgQE4/Xt2RW8uQq2MNvpWusL/gfL9nNtGYfAmqDkpYTItLx9qBcjXI3wKPM2RH+f2r1wojqgQz3q90WMcRNT/X/c61n7qklwY0Vp1sgXkqK3saUTA0IhebNk8rDy+3squ6WAcOfAkiFCsluVxI= 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=NBjU0aNp; arc=none smtp.client-ip=209.85.208.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="NBjU0aNp" Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-65089cebdb4so4723317a12.0 for ; Fri, 09 Jan 2026 02:13:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767953605; x=1768558405; 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=T0HVCB8h37LjRdbYf+NBimR89qCOjk6XADJ4vCRu8yk=; b=NBjU0aNpmbNHIQOm7TpGa+/AM3fOQs1WOoVaQVyTILoCzyWsmZcZfygTkCNfrrIkG5 2QFy0D31yIKIeTg5cLLWXGaPiPmpfRXT1no0xtO0906kh6bUuFe8g2woH8BOYeTLRh5w k3mWSpJla5007ZYNH2v98MfDJ18iGyQvD+ypAVSYuXaoixuEuLgtXPZnFsT/HMVejuOn X+eWZI4tNW+wtw8rQlOladLjZUD8kumNdFnqGQio6rOAw2cad5ZWYXJU9oyFnzrhsLAM FsEiI9AaXvr8BTOcqrGNbufH2Q9na8nen3zVMep6Cz0srQm522Fulj2RMmaCBUlZNekM q72g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767953605; x=1768558405; 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=T0HVCB8h37LjRdbYf+NBimR89qCOjk6XADJ4vCRu8yk=; b=FgFQo+IRSfsbFCE9P0IQitAlGDA6dfNJE033PQ5QxMkG4g8umkgCn2bzJRaGCV5rZI TTHwn8UnkLZQFebC+D2rd3BSBEfUmcYLkjvFwic2d3qnc6N+p75ecQCCqh/7WHY0osl1 vpSv/akRqTqF3BHJEf87Ec4AVzWKRU30crrTfGdYfoYjMYrHKiwy5OYyCD2z+IJBldQ9 IHf/xzusnY6K9q4U1bQwfYoMOWRxQAK90shSJN/asY3NT44ZXnLqe24KxpfMXMJ1pfsu EOg+nx7mtoOyMhY+JqJy2B48H8+GbbJhC25JZ7gXwH4fyMxIVbwj1h4buekaH4jbJqRz 3KNg== X-Forwarded-Encrypted: i=1; AJvYcCUe8ckfqo9YWKL0V6lhmHMcQCXrEAmuY+VoyTe5SUts+/gRJVQI4fJll0yuuvZvxT1ALhzTVIqgcj4HDfM=@vger.kernel.org X-Gm-Message-State: AOJu0Yzp690vybFBnCL/tEhPKc6qFnAo9Drfh2l0Ew2IFWAV1qf4DdI/ g5nU3DD+F7mmGQFNszuaDcQJGkA5z7VagExGt4SSC0rbgGqqPCy26NGY85NT1tlZ X-Gm-Gg: AY/fxX4C/1eMusiVO6a341sIgn36/eHA6o4tTW/bO+xvXobPGYPxIqD/GlpKj+NBRmi vbd53t/Ad5jQg7b2s5jnUcVXeKIy1QE3bL3aUV4/JJcDZeD/Fp/CLmSZGZgp/XGQ+HhIAZSvNQ2 BYZ/E0RH6xhgvMqA1XD7sP8D2V1hemspawdN+1I5hLxlBqzCqjm9eAMYLBm+y5fL4EKnwpL/ckT M7qGYG8/ha4Boy3WEokdlcc3AOmq0YmMd2rlbpZ2dXcEvdWgS0Z1KmCCB6JmXNVV05SwRuOQ2ZY H0AB/4NH+8bs+saYti5dqyzsC/OwZ+AkA0Zr0phRYOaQnK42xu5UCuG0h5J6yRPt+LE17tT/HZ5 53XqCRNmHc3BxUMep6iuLGDf8dbzHdQ6601lYv/Vh6pZ/QVp5mTA+2KtE89uVPdXq8wxNBbZSQV KGtdcLnezfnc4sWPU= X-Google-Smtp-Source: AGHT+IHAs6M6/6d6TDseCaw58asjnE8jcwm8lPKvdScGi5kyj3ItTa1ERPN4RKKTaHnv8Pk62CNf+Q== X-Received: by 2002:aa7:cf97:0:b0:64d:17af:81d4 with SMTP id 4fb4d7f45d1cf-65097e494a5mr6938930a12.20.1767953605213; Fri, 09 Jan 2026 02:13:25 -0800 (PST) Received: from builder.. ([2001:9e8:f116:2816:be24:11ff:fe30:5d85]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6507bf661fesm10688575a12.25.2026.01.09.02.13.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Jan 2026 02:13:24 -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 net-next v4] net: sfp: add SMBus I2C block support Date: Fri, 9 Jan 2026 10:13:21 +0000 Message-ID: <20260109101321.2804-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 --- changes since v4: - fix formal issues v3: https://lore.kernel.org/netdev/20260105161242.578487-1-jelonek.jonas@gm= ail.com/ changes since v2: - fix previous attempt of v2 to fix return value v2: https://lore.kernel.org/netdev/20260105154653.575397-1-jelonek.jonas@gm= ail.com/ changes since v1: - return number of written bytes instead of zero 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: fc65403d55c3be44d19e6290e641433201345a5e --=20 2.48.1