From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) (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 51B12332EB7 for ; Mon, 5 Jan 2026 15:49:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767628198; cv=none; b=hFNpfsmYVtxbAmYygxV2zZiaAQCmvkkCH9UoPH9tCihIIJEtTmKJVW1albi+3eQJG5IOwATyahrw/PdWvH6WNCVQXhsDzk3cO4ErHvpWlzo1PNkyxJHxPAbOgcmBcXjMLAuWt3C/UwBmf4nhpi9mhcTqNm5KUAcpHtrVxBo6IhY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767628198; c=relaxed/simple; bh=olQyVYH0Ag2RJAuLBgwkYLxW77WAllEc9l+jkla2DQY=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=C9Y2RrTeNZufe1HaS0s0sjDOZEkL9hXIlGiOPZlu+VHFntNqA7+I+1ADm3jLd6Qx62OiK0oaF1u56q4i4zzGVFGOzZ4P0FK+2m0el4xnMDagxEzHZw6AM/2tpm2+LVVA/X9ih0xsvnNbt70uyTFsGfmSrQdDPsNfBR4j7tpJR14= 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=QurvtCqD; arc=none smtp.client-ip=209.85.218.44 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="QurvtCqD" Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-b83b72508f3so15268766b.2 for ; Mon, 05 Jan 2026 07:49:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767628193; x=1768232993; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=DuXlLK2RIL3I+JB1SrVBkkjGCSZRxW7su/cgJs2ojpw=; b=QurvtCqDL8vIrw9lAnOhKC7W5/cRjcyZJKktQ9+ujr4M5JZrZUng90vhIK8du39mSP Q/M3JmCNobe0XtodWoMlKlq/bCN44aXB3da3cqxYcga1eIBbm1iPzU5/il0esJXoeyqT mq0Q+y8ehEei2Q832jgSp7Zdt7qwv2Jj5zlX3KAtC3Oq3QFTbYBpAiLlYuvxaUdFOiAu MrRonFkqIJEUbW0EWI7znc7vWgtswvhH+eEWVApKhdsU/KWGK562QOGhaGqowWBHvcmI /Et8c4KXSzo7oBxc75poYENApj7dhj4zbF8ZrX/aOeH4qDiskT+aMOJzqhMCCTGfoh5Q GNaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767628193; x=1768232993; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=DuXlLK2RIL3I+JB1SrVBkkjGCSZRxW7su/cgJs2ojpw=; b=PZj7E+zAODG9co1kD0pL/qcWTcOS5uNuC1tlq/KPTAt7jyXOpNbI9vDLKV8oc87tyr 0Bu1VOtbGfRjF+m3DzyKVt4IQbwekLfI4rrPQ0cPb9ysVaI/Hps/xaaiFPZF50oB2aa1 i5SUJUpKd04WJVgPg8PjZfOVvULYI7CfKgWSLUzvJil2HeoLtVuqSvLnk27+kjo95lcY M3x/Kaq7lBfOGM9uijUE/pYSCAzq6puqXoTnR9ZrGDATKVutcQoUUFu8O18QVGKJ8psl ozuYsohrgeVnPtryrv+ocHZ+hDQ+KoQ2RZqJsTVV1omzsWZ8DoXzDo7ej0GYC3X2SJxb CGYg== X-Forwarded-Encrypted: i=1; AJvYcCUggfKcpddJWcq20mhwEufn4yhes17mLYn8/FujUk28yga9cBTaQDLSQ8QHiEYNx1z++RBQ75u1U306EJQ=@vger.kernel.org X-Gm-Message-State: AOJu0YyO1wrxMXCurntHsi6SKZ58kPhw69lJrrsTEopPXrAugc/0jjgR DFg0r0bDe2wdXX/MVMLfG30M8Aj6PuwtpwRw+Eorx2zTe0XznldCIzpl X-Gm-Gg: AY/fxX4n5I9vEQZlws/wUSauL0n45hNbphABGPDv3mWSSdYARgaYsLxDKf6RnN5rIHb rRdhSL2QGXYSETWOL6XIGxaT8G4tOGyYnc3he8U+MkZyMXzuIhQrx+H7kP0xMAM7QwEDtVDoZm/ BXHEouXy+wHYaOz9h8csszRdFzziumBkSb+OWfVYERLLO8a/y3gm3OIIGFAiyK1cWLrzPDZg0EW 9RrTzebqsrVQtH1h4nrPfZY0hk01Z8l/NcrZwqr3tnS5Fz+naegpbjBiLThjhCp3E5AL2DyipmX R1u9RG7/jDieThDXMmffc/7xS4nMB07Gn7UtjSI+sEBx9LfenjMZQldHaIpY3g2H/eyhoS8W4KX 523o7Pc1no55H5e2RuIKex0pYJEzbvKasdd+O4fXRYQDtMPfI+OrHENzG6c9LsPkh7ZpbEN+HV3 zNlBFKFhgZpPgTU9FTt0pAUZKz2oH9CJ8S8+7qX/iCNYuwEkVYju0urxCEbYWNCrJ5 X-Google-Smtp-Source: AGHT+IGTcaItzX7HWOz93kzAf22nt1bsFCnAPA784RIhU2WoxE4dAY76osHO6taYvvS2ivmDpGRAng== X-Received: by 2002:a17:906:f598:b0:b76:e6bd:7bcd with SMTP id a640c23a62f3a-b8426a864ffmr24637866b.20.1767628193235; Mon, 05 Jan 2026 07:49:53 -0800 (PST) Received: from [192.168.255.3] (217-8-142-46.pool.kielnet.net. [46.142.8.217]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6507618cc59sm111239a12.28.2026.01.05.07.49.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 05 Jan 2026 07:49:52 -0800 (PST) Message-ID: <4628df96-5ad7-411b-9b9d-4084cb5da87a@gmail.com> Date: Mon, 5 Jan 2026 16:49:51 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] net: sfp: add SMBus I2C block support Content-Language: en-US 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_Mork?= , Maxime Chevallier References: <20260105154653.575397-1-jelonek.jonas@gmail.com> From: Jonas Jelonek In-Reply-To: <20260105154653.575397-1-jelonek.jonas@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Sorry for the noise, messed that version up. Will send a v3 quickly. Best regards, Jonas Jelonek On 05.01.26 16:46, Jonas Jelonek wrote: > 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@gmail.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 a2, u8 dev_addr, > return data - (u8 *)buf; > } > > +static int sfp_smbus_block_read(struct sfp *sfp, bool a2, u8 dev_addr, > + void *buf, size_t len) > +{ > + size_t block_size = sfp->i2c_block_size; > + union i2c_smbus_data smbus_data; > + u8 bus_addr = a2 ? 0x51 : 0x50; > + u8 *data = buf; > + u8 this_len; > + int ret; > + > + while (len) { > + this_len = min(len, block_size); > + > + smbus_data.block[0] = this_len; > + ret = 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 -= this_len; > + data += this_len; > + dev_addr += 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++; > } > > + 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 = sfp->i2c_block_size; > + union i2c_smbus_data smbus_data; > + u8 bus_addr = a2 ? 0x51 : 0x50; > + u8 *data = buf; > + u8 this_len; > + int ret; > + > + while (len) { > + this_len = min(len, block_size); > + > + smbus_data.block[0] = this_len; > + memcpy(&smbus_data.block[1], data, this_len); > + ret = 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 -= this_len; > + data += this_len; > + dev_addr += this_len; > + } > + > return 0; > } > > static int sfp_i2c_configure(struct sfp *sfp, struct i2c_adapter *i2c) > { > + size_t max_block_size; > + > sfp->i2c = i2c; > > if (i2c_check_functionality(i2c, I2C_FUNC_I2C)) { > sfp->read = sfp_i2c_read; > sfp->write = sfp_i2c_write; > - sfp->i2c_max_block_size = SFP_EEPROM_BLOCK_SIZE; > + max_block_size = SFP_EEPROM_BLOCK_SIZE; > + } else if (i2c_check_functionality(i2c, I2C_FUNC_SMBUS_I2C_BLOCK)) { > + sfp->read = sfp_smbus_block_read; > + sfp->write = sfp_smbus_block_write; > + > + max_block_size = SFP_EEPROM_BLOCK_SIZE; > + if (i2c->quirks && i2c->quirks->max_read_len) > + max_block_size = min(max_block_size, > + i2c->quirks->max_read_len); > + if (i2c->quirks && i2c->quirks->max_write_len) > + max_block_size = min(max_block_size, > + i2c->quirks->max_write_len); > + > } else if (i2c_check_functionality(i2c, I2C_FUNC_SMBUS_BYTE_DATA)) { > sfp->read = sfp_smbus_byte_read; > sfp->write = sfp_smbus_byte_write; > - sfp->i2c_max_block_size = 1; > + max_block_size = 1; > } else { > sfp->i2c = NULL; > return -EINVAL; > } > > + sfp->i2c_max_block_size = max_block_size; > return 0; > } > > > base-commit: c303e8b86d9dbd6868f5216272973292f7f3b7f1