From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (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 823DA3644C0 for ; Fri, 9 Jan 2026 16:46:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767977186; cv=none; b=LYrzLhVe8dTtdezXVpiXInthTUzl29erKD+qEE8ZT6RMFY8BM69R66a1cAkkumhHf5w5SS5PCb7pB+JnPApyET6QOwGDa69oqEUSqwsBD6q1Jb+7rBob4WX/UNFKTj1rmZZW/UaIMoqdLLHprTwQNaOGQD+Oa4oQAcKauz3aXAY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767977186; c=relaxed/simple; bh=DwF3SqCOufYVEKJlQsLZXEKLkZR/ulbFkCnyykmzN0g=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=s/biJrXEu8NFxivcCpTUA2DdaruBOFXWRdb7PND0N7/qj+JtUZR1xH3z4LvnAVRznJKVDpvcLNTl5Iaq3ZvpWjCFClxsUtymqgL/1KARRWeCskVZKQiJD51ZM991fkyglgcu6dQvaUAW172q86gzN4lTFpC7wNFzoKEMDTY7RTU= 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=ePPlebfZ; arc=none smtp.client-ip=209.85.128.52 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="ePPlebfZ" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-47d3ffa6720so45511235e9.0 for ; Fri, 09 Jan 2026 08:46:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767977183; x=1768581983; 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=N2HTlKYpOW86DgnaF2KWZRrdaVbBQotXHitT2ePEDuU=; b=ePPlebfZyUe7PuIztjJ0NpEXeS285iX2hx3WxYZWBkrvdWiknsFPhYWAr8MQIUDAY+ cQjTOwFJrdI8rnVINTKCBzGz4LBQ55E8F8GaiqnZK36t5DxVNY7YgvxBbJqW6XLsEWCa DLp0Fsakb+Laa4qlXlC/zjkwFNbHwyGg/8i01TlLHZou3WyDlZJAY8+BzN8C4mHE3jxw ZimR9ksOa2MbGL+VJk5MiVTCqAZ4jZi86fkUZ8XY6u6PRWxsdRTi9NG72zVpwQhubm61 3PfZDcA7uZacxHWKMTOIrC0aohwhVaSlxzrgSE0ALpZZnioKhxdKs74UtkF2yvcaR66h bZtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767977183; x=1768581983; 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=N2HTlKYpOW86DgnaF2KWZRrdaVbBQotXHitT2ePEDuU=; b=HhSs0vUd9SDSLBCaTN2OrM+nCDk9SwQjFEN5qd4K6d3sED88ZWu3gXbfcaTfFE5ukk 686ilFHzkNfzzO2J2DDSUsWhjk4owL4E3g6ijEg3zYKbHgzzL/4RInDyZQ0vcIAZYg8u ZEtdQLoBR2IAO7MVa24FPSkwqDtU4WGohQtea+NEX2aUtKQCuvsc3+quHbyDY4A+ZQWt 8oQsS5c3guRnQoTgJR80c/bw/xTHzjlutzgdJk+FKw3YjT0IybWeiplLQpkL/ddmNpbt KpUjKZibUfJCjDrgbUtLVNg2uNewf2X88DfuNQx2gjC8Q4WwGfLSDx+mQfmi0/7R8J9X CCKQ== X-Forwarded-Encrypted: i=1; AJvYcCXw3wMXSgnWmJ5scuwuuyBCkMEGeoXentfhKzxUcWY7s2joDr/y7OgVQrvsOCuk2vgVdNGWq0efREL9BT4=@vger.kernel.org X-Gm-Message-State: AOJu0YxXNa5f45RWMPvhRNAVt9RbkBQlQh81BmxSbiDnyOFZSNENcgsA h0aS+owR2OwXnMun3LbTF7ki2lUWxFBv3oQ3ujNSstxqjF/hTxVpWXMO X-Gm-Gg: AY/fxX7tPnJ//2JqEONCmYgvfZClrh6QOSpPO+o1Tb01mqQddsS7hlGatAfMIgKOWGA 6B2Ndg72qTJurYxUyM4kxC4BwFDV0zfMP1OnvUZchIVymthTOKbzpGVDzRNhtb7WN2DscboZD50 wfmmF1wPmZG5LyZFBNE9HEDyzISXKsm5djwteby8k6A6bWf/SuX3Aa+rezihsTiPxNG8F+7yqfu BpgoYMNelHrx5/dB5yzu7ccRiXlI7luRmS0eX79CCF0ZTGejmtFWswfa2LNFUJq6OPpr35ai8hG DMhws9VuGVjdzhxAPdkbPcZx70AJ37e8JixPnPIC3dRz/G6RSnriT9vlD1MHpU8tivSuQSoKOml KfngL4Iq7SrNakuHF7QDHpxukl7bZRXv+Ju2VNSah9CBo6v5o7NWcf0ErO6nS82Q2V5b3zjDXSk ftjN7scEhZVch1xgVqcIuHhAZ7zGqC6VPCKCxK/gLfS9b6qTGtrbAawiXT3zmnUMfSSae0KyvW7 DdSFq8kw3BkTYsH X-Google-Smtp-Source: AGHT+IHnL0DXnjf5grmc8kFqboTCBQH7jNsckL4Ib5Ns6ZQkI8W4vFRRk1sMaI3PNYP25f/TkgV3kg== X-Received: by 2002:a05:600c:3152:b0:479:1a0a:ebbe with SMTP id 5b1f17b1804b1-47d84b18db4mr121604445e9.14.1767977182547; Fri, 09 Jan 2026 08:46:22 -0800 (PST) Received: from ?IPV6:2001:9e8:f116:2801:5cbd:7d69:3b4c:169? ([2001:9e8:f116:2801:5cbd:7d69:3b4c:169]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47d7f6953fasm210190305e9.5.2026.01.09.08.46.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 09 Jan 2026 08:46:22 -0800 (PST) Message-ID: Date: Fri, 9 Jan 2026 17:46:21 +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 net-next v4] net: sfp: add SMBus I2C block support Content-Language: en-US To: "Russell King (Oracle)" Cc: Andrew Lunn , Heiner Kallweit , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?Q?Bj=C3=B8rn_Mork?= , Maxime Chevallier References: <20260109101321.2804-1-jelonek.jonas@gmail.com> From: Jonas Jelonek In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Hi Russell, On 09.01.26 17:21, Russell King (Oracle) wrote: > On Fri, Jan 09, 2026 at 12:13:06PM +0000, Russell King (Oracle) wrote: >> On Fri, Jan 09, 2026 at 10:13:21AM +0000, 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. >> I'm wondering whether we should go further with this - we implement >> byte mode SMBus support, but there is also word mode, too, which >> would solve the HWMON issues. It looks like more SMBus devices support >> word mode than I2C block mode. >> >> So, if we're seeing more SMBus adapters being used with SFPs, maybe >> we should be thinking about a more adaptive approach to SMBus, where >> we try to do the best with the features that the SMBus adapter >> provides us. Makes totally sense, my initial version was just a pragmatic attempt to solve the issues downstream for a single target. But covering byte, word and I2C block is a better approach. >> Maybe something like: >> >> static int sfp_smbus_write(struct sfp *sfp, bool a2, u8 dev_addr, void *buf, >> size_t len) >> { >> size_t this_len, transferred, total; >> union i2c_smbus_data smbus_data; >> u8 bus_addr = a2 ? 0x51 : 0x50; >> u32 functionality; >> int ret; >> >> functioality = i2c_get_functionality(sfp->i2c); >> total = len; >> >> while (len) { >> if (len > sfp->i2c_max_block_size) >> this_len = sfp->i2c_max_block_size; >> else >> this_len = len; >> >> if (this_len > 2 && >> functionality & I2C_FUNC_SMBUS_READ_I2C_BLOCK) { >> .. use smbus i2c block mode .. >> transferred = this_len; >> } else if (this_len >= 2 && >> functionality & I2C_FUNC_SMBUS_READ_WORD_DATA) { >> .. use smbus word mode .. >> transferred = 2; >> } else { >> .. use smbus byte mode .. >> transferred = 1; >> } >> >> buf += transferred; >> len -= transferred; >> } >> >> return ret < 0 : ret : total - len; >> } >> >> sfp_hwmon_probe() will do the right thing based upon i2c_block_size, so >> where only byte mode is supported, we don't get hwmon support. Thanks for providing this. I'll take that as a starting point and come up with a better patch. > I should also note that, when checking for the appropriate > functionality in sfp_i2c_configure(), we need to be careful that > we can read single bytes. > > In other words, if an adapter reports that it supports smbus word data > access, we need it to also support smbus byte data access or smbus i2c > block access. > Good that you mention it, haven't considered this yet. Best, Jonas