From patchwork Thu Dec 14 12:10:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 178741 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp8551065dys; Thu, 14 Dec 2023 05:41:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IESSJhK8cnBU5Ml3vRiHA/MDth2+vIYsmUjGXH+s41kVcZ4HhJk4S6k/WH2IRj50NnOe7cF X-Received: by 2002:a05:6e02:1b06:b0:35d:6798:1734 with SMTP id i6-20020a056e021b0600b0035d67981734mr15012139ilv.27.1702561273684; Thu, 14 Dec 2023 05:41:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702561273; cv=none; d=google.com; s=arc-20160816; b=uLHaG0dsVgSXdILQlh9njusxRQB83joLzmzhDr7GDxZzUM/v+gbvihIIDgo9wVdd3H ZPV/BE5Dd2EKS9kzb2FuL2/jqxI0c4uuEpg8efO2vYDYqVCEBeQ25jhnxuHKbpjpILe0 WvdKVpz+paOfV+r+Y+G3K51nrniy21CSjaY7RTccSX9L8mkE4u45C7Q1iZQpIt9ZEeD6 CZGKW9WkgLs0VDAjyR4qPORsK+68/frU1TjZofOHVQ/Xx0lfWyCom1loH0mk2BSOctCO WYWnicdZ9hpapyzIL+ZvG0GOyZqAIX9siQQZxaUjXP99YaM8lK5D22cA3gdP+pGHR9Pp HBYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=sXxUg8r4wEYQBuQ5G/+HpnGYG3sKQPUKb6HI5iMSDJc=; fh=wWo03r2JjWghae2V0hr6u9jTJqCCGGThYJ7k0BaFlTY=; b=V7v7fk+L/46OTxZVjx1w6vwyFTBNNppfxjrxAhpO8SRG7+06p50JRwMZpvCE7MR/Z2 XLRHbBaB4hWEpY/mma95CzztbektOYX4mC7n4upcAH/pK5WbehYF9tTrPRbF9hREoH0h BUiWIJLz6yZtlaJtRbz9kNC+GzRfBIb996E1VFuQ5WNdAoXTLHKRJ3WzVWsFMM8yDTSA 1AM0OSt/irWqoeAo9G3rwDTCjFjtqPVTErmjeDjfkAjdyJ8NQx0DucF8sZtasmeXy7C9 EzRfYHZUGxFzjszUYvpLjdhBAONV2eFyzNSXl702FkIukLuYZnB33GiG1GAtyfvX3RNW UPlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Jo07xeup; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id v33-20020a631521000000b005c5e214d722si11392360pgl.80.2023.12.14.05.41.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 05:41:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Jo07xeup; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id D53B184E98A7; Thu, 14 Dec 2023 05:41:08 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1444228AbjLNNk4 (ORCPT + 99 others); Thu, 14 Dec 2023 08:40:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1572944AbjLNMKr (ORCPT ); Thu, 14 Dec 2023 07:10:47 -0500 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68E0610A; Thu, 14 Dec 2023 04:10:53 -0800 (PST) Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-33642ab735dso1080596f8f.0; Thu, 14 Dec 2023 04:10:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702555852; x=1703160652; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=sXxUg8r4wEYQBuQ5G/+HpnGYG3sKQPUKb6HI5iMSDJc=; b=Jo07xeupV5d4bzAdJChklfSQbDIwg87WdGLEOJbEmXZkDHLvbM+pGn/yh5SUItN8FB uAuhPkhBZamjvHhZTiDfd0aou/bOIWC61QHQna+NKz9cpYpXRi3eKwZLtD7ZO2DE7bp5 PPrANUi+wDmUXS9BMsmBq4q+alvbsdvwbpr73ptrRhwqZ9Ej3OPtjcr+nNT9nXCtMyv9 1LHQunIdAxasQ2FfYhaRhZXKLqdH3QwTA0YCumEhhY7IZDqes6Zt38xu29wk1WrcHqsh iJq6DTw3OI+0O5Tyjw6igoFCE8QrG+dZFAM//R0hdBak2zL5qjtHPJtfNmHXB+V5Ufcw XoCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702555852; x=1703160652; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sXxUg8r4wEYQBuQ5G/+HpnGYG3sKQPUKb6HI5iMSDJc=; b=qu5+v6djOGn1v0qLr5FFdgg7a2pJnEftAefA/PUGY/0bz2qrUpaGREP16XXEbY7V4a pJNY1SCEahFJRAVlFh89k+RtT+9EFvO3SgeTlstmAF8s8129wZMMJa1695lB5XnviWiB ZDTZKzKsy3RPm6obAA/5pOmh7wqhIajo7b5YcfJsdqG223tVpXBuU9RJBZHUNzyARPij vBmIBxxsrEum51BUA1oYbyNxNCnu+CJ32yh1fKLMNRvYejU0r40+KOD0jA300dKQT+KO 81cis0ZqoBo8nTrXZVFuwCMe/J+3TfIu8UXpDTl/ucsWsDjFyeh6k2+/0qcoxIglD5oM W/cg== X-Gm-Message-State: AOJu0YxSHeNl4WRvDTSmqGzCLkZaPx3GF4s/idohq7+E34E5b/sYhRii 5K9p9YkOm0sjJL0q7+b21j0= X-Received: by 2002:adf:f60f:0:b0:332:dfeb:76ab with SMTP id t15-20020adff60f000000b00332dfeb76abmr2449946wrp.60.1702555851704; Thu, 14 Dec 2023 04:10:51 -0800 (PST) Received: from localhost.localdomain (93-34-89-13.ip49.fastwebnet.it. [93.34.89.13]) by smtp.googlemail.com with ESMTPSA id d12-20020adfa40c000000b003333fa3d043sm16026765wra.12.2023.12.14.04.10.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 04:10:51 -0800 (PST) From: Christian Marangi To: Florian Fainelli , Broadcom internal kernel review list , Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Vladimir Oltean , David Epping , "Russell King (Oracle)" , Christian Marangi , Harini Katakam , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [net-next PATCH v7 4/4] net: phy: add support for PHY package MMD read/write Date: Thu, 14 Dec 2023 13:10:26 +0100 Message-Id: <20231214121026.4340-5-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231214121026.4340-1-ansuelsmth@gmail.com> References: <20231214121026.4340-1-ansuelsmth@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 14 Dec 2023 05:41:09 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785264890038799156 X-GMAIL-MSGID: 1785264890038799156 Some PHY in PHY package may require to read/write MMD regs to correctly configure the PHY package. Add support for these additional required function in both lock and no lock variant. It's assumed that the entire PHY package is either C22 or C45. We use C22 or C45 way of writing/reading to mmd regs based on the passed phydev whether it's C22 or C45. Signed-off-by: Christian Marangi --- Changes v7: - Change addr to u8 Changes v6: - Fix copy paste error for kdoc Changes v5: - Improve function description Changes v4: - Drop function comments in header file Changes v3: - Move in phy-core.c from phy.h - Base c45 from phydev Changes v2: - Rework to use newly introduced helper - Add common check for regnum and devad drivers/net/phy/phy-core.c | 144 +++++++++++++++++++++++++++++++++++++ include/linux/phy.h | 16 +++++ 2 files changed, 160 insertions(+) diff --git a/drivers/net/phy/phy-core.c b/drivers/net/phy/phy-core.c index b729ac8b2640..7af935c6abe5 100644 --- a/drivers/net/phy/phy-core.c +++ b/drivers/net/phy/phy-core.c @@ -650,6 +650,150 @@ int phy_write_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val) } EXPORT_SYMBOL(phy_write_mmd); +/** + * __phy_package_read_mmd - read MMD reg relative to PHY package base addr + * @phydev: The phy_device struct + * @addr_offset: The offset to be added to PHY package base_addr + * @devad: The MMD to read from + * @regnum: The register on the MMD to read + * + * Convenience helper for reading a register of an MMD on a given PHY + * using the PHY package base address. The base address is added to + * the addr_offset value. + * + * Same calling rules as for __phy_read(); + * + * NOTE: It's assumed that the entire PHY package is either C22 or C45. + */ +int __phy_package_read_mmd(struct phy_device *phydev, + unsigned int addr_offset, int devad, + u32 regnum) +{ + struct phy_package_shared *shared = phydev->shared; + u8 addr = shared->base_addr + addr_offset; + + if (addr >= PHY_MAX_ADDR) + return -EIO; + + if (regnum > (u16)~0 || devad > 32) + return -EINVAL; + + return mmd_phy_read(phydev->mdio.bus, addr, phydev->is_c45, devad, + regnum); +} +EXPORT_SYMBOL(__phy_package_read_mmd); + +/** + * phy_package_read_mmd - read MMD reg relative to PHY package base addr + * @phydev: The phy_device struct + * @addr_offset: The offset to be added to PHY package base_addr + * @devad: The MMD to read from + * @regnum: The register on the MMD to read + * + * Convenience helper for reading a register of an MMD on a given PHY + * using the PHY package base address. The base address is added to + * the addr_offset value. + * + * Same calling rules as for phy_read(); + * + * NOTE: It's assumed that the entire PHY package is either C22 or C45. + */ +int phy_package_read_mmd(struct phy_device *phydev, + unsigned int addr_offset, int devad, + u32 regnum) +{ + struct phy_package_shared *shared = phydev->shared; + u8 addr = shared->base_addr + addr_offset; + int val; + + if (addr >= PHY_MAX_ADDR) + return -EIO; + + if (regnum > (u16)~0 || devad > 32) + return -EINVAL; + + phy_lock_mdio_bus(phydev); + val = mmd_phy_read(phydev->mdio.bus, addr, phydev->is_c45, devad, + regnum); + phy_unlock_mdio_bus(phydev); + + return val; +} +EXPORT_SYMBOL(phy_package_read_mmd); + +/** + * __phy_package_write_mmd - write MMD reg relative to PHY package base addr + * @phydev: The phy_device struct + * @addr_offset: The offset to be added to PHY package base_addr + * @devad: The MMD to write to + * @regnum: The register on the MMD to write + * @val: value to write to @regnum + * + * Convenience helper for writing a register of an MMD on a given PHY + * using the PHY package base address. The base address is added to + * the addr_offset value. + * + * Same calling rules as for __phy_write(); + * + * NOTE: It's assumed that the entire PHY package is either C22 or C45. + */ +int __phy_package_write_mmd(struct phy_device *phydev, + unsigned int addr_offset, int devad, + u32 regnum, u16 val) +{ + struct phy_package_shared *shared = phydev->shared; + u8 addr = shared->base_addr + addr_offset; + + if (addr >= PHY_MAX_ADDR) + return -EIO; + + if (regnum > (u16)~0 || devad > 32) + return -EINVAL; + + return mmd_phy_write(phydev->mdio.bus, addr, phydev->is_c45, devad, + regnum, val); +} +EXPORT_SYMBOL(__phy_package_write_mmd); + +/** + * phy_package_write_mmd - write MMD reg relative to PHY package base addr + * @phydev: The phy_device struct + * @addr_offset: The offset to be added to PHY package base_addr + * @devad: The MMD to write to + * @regnum: The register on the MMD to write + * @val: value to write to @regnum + * + * Convenience helper for writing a register of an MMD on a given PHY + * using the PHY package base address. The base address is added to + * the addr_offset value. + * + * Same calling rules as for phy_write(); + * + * NOTE: It's assumed that the entire PHY package is either C22 or C45. + */ +int phy_package_write_mmd(struct phy_device *phydev, + unsigned int addr_offset, int devad, + u32 regnum, u16 val) +{ + struct phy_package_shared *shared = phydev->shared; + u8 addr = shared->base_addr + addr_offset; + int ret; + + if (addr >= PHY_MAX_ADDR) + return -EIO; + + if (regnum > (u16)~0 || devad > 32) + return -EINVAL; + + phy_lock_mdio_bus(phydev); + ret = mmd_phy_write(phydev->mdio.bus, addr, phydev->is_c45, devad, + regnum, val); + phy_unlock_mdio_bus(phydev); + + return ret; +} +EXPORT_SYMBOL(phy_package_write_mmd); + /** * phy_modify_changed - Function for modifying a PHY register * @phydev: the phy_device struct diff --git a/include/linux/phy.h b/include/linux/phy.h index aaec34389f48..78daac729385 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -2049,6 +2049,22 @@ static inline int __phy_package_write(struct phy_device *phydev, return __mdiobus_write(phydev->mdio.bus, addr, regnum, val); } +int __phy_package_read_mmd(struct phy_device *phydev, + unsigned int addr_offset, int devad, + u32 regnum); + +int phy_package_read_mmd(struct phy_device *phydev, + unsigned int addr_offset, int devad, + u32 regnum); + +int __phy_package_write_mmd(struct phy_device *phydev, + unsigned int addr_offset, int devad, + u32 regnum, u16 val); + +int phy_package_write_mmd(struct phy_device *phydev, + unsigned int addr_offset, int devad, + u32 regnum, u16 val); + static inline bool __phy_package_set_once(struct phy_device *phydev, unsigned int b) {