Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp2229832rdb; Mon, 20 Nov 2023 05:53:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IFQA21B7GoKQn9pSCKd96dNrlgsKOBA3AQTLbyim+cRelXbYDCmgMHdr7vkELXuIUSAR5dw X-Received: by 2002:a05:6808:23ce:b0:3b2:e3b5:b88 with SMTP id bq14-20020a05680823ce00b003b2e3b50b88mr9358735oib.26.1700488410873; Mon, 20 Nov 2023 05:53:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700488410; cv=none; d=google.com; s=arc-20160816; b=QjMyGGMZstSHp7v2W1ljg2ZiV3PRNnfrNc9TjFsBLfdCdGC6ODm/cW5wxkuLkgYXuj aP4tl3Uk0HX2w0FAPGDBPNrfLjdCafRk01nD4T2u7vqve8lKGvBKoYw1LbQN0IV+JwHe 9ITPuRv+fJqTEyjdIb/nDL1senKma1uS2kAk6WFUvyoVmWfvj4dsOrDZSSF18vDfTVvP kIuc7iuy7f/114dTXDoiwsEowAgBVzjPuqr9XDdtnovAiIH6J1uGezrnD9xRjCHhyHSV am0IWC2/0gKuC+av3+9eWueOFwYXyJmAlOAZomDvEdupYILsjH0POUenxBwh8wM2pdRQ 18ZQ== 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=RJJcNZQjoxDpL64YJUPbX5zAdxkULtiEGewpt5HLNRQ=; fh=zPyAtQBIWE/l9hby8g4KTASOZz1Q4ly6b7sYfyUlIrs=; b=K0fSM3jE35m8Txo0TyH2yf8Zf8ljO2PRirclcyQkM30Xd+1aZDrN4VRpz7RtZMnMq2 ROJGjI0QYgTGK0/a+JaAmR5xY1M4iyt3cd4rwsaL6CudXKQlN+OQwy81ZnqFVvWzedDU nW3X+kOw40Soz6fj5TRWV20qlmBKvDflLUhaCuZNUZpCdKtpyOVGI8CAeDebqCGfQUdI mgAJ+6ayb/4B+LHoPk7ieEb9U+1p4wYyTu6vxXnKzX1P1QwDKlwJOQjGCcG5waSv3J75 0K6pg8CgC8zVjhXjoc6AZHfmxWvxbgAGHsqgvaqFVQwcoQxmMpNJsUsr8uNFVfCtIMx2 7S/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=lNI38QJY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id c20-20020a63d514000000b005b9053cf6f2si8265066pgg.163.2023.11.20.05.53.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 05:53:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=lNI38QJY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id C3347804E2FB; Mon, 20 Nov 2023 05:52:15 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231961AbjKTNv5 (ORCPT + 99 others); Mon, 20 Nov 2023 08:51:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233468AbjKTNvi (ORCPT ); Mon, 20 Nov 2023 08:51:38 -0500 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFC00D78; Mon, 20 Nov 2023 05:51:26 -0800 (PST) Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-50aab0ca90aso1754615e87.0; Mon, 20 Nov 2023 05:51:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700488285; x=1701093085; 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=RJJcNZQjoxDpL64YJUPbX5zAdxkULtiEGewpt5HLNRQ=; b=lNI38QJY+hLhb05yxNU8aMXdbP1ccm/A0KKezhus2NmfKLnTP4uHCMNTI6LLwd7DSp nn5rlkvXOjpv/CXXgEb66R0q2leOEKyYbOa46FQUPzt3PCgPy9hdQf9RqPlrl+NEKATz o6N9Vetc2vlV3NLSNZv8nTdQAZKRo40kKIcHjuTjU2WOG3mBFf171uDNFSppiSilg7Uw 62c/gg+Qje3XFS5+euq2MScISJff7hfxVum1pVEcQ7dgH6ix+LekQ085hs6KiOmEZxmN nMtjN2dcVNekncsvx69VxkfEjz+LE+3l0ci67Wn+AbcUZbinAhBXSqmG0+dWqMU9vzS9 pQww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700488285; x=1701093085; 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=RJJcNZQjoxDpL64YJUPbX5zAdxkULtiEGewpt5HLNRQ=; b=lEf3HYlrB5hMDVRormqdUBwGzfCuAbV8zOwui9bPvUyuJpRuczIW9dhgQjtJo4m7Ca L8HE6rc5K6wa/BXF1DEMo4nGtqlY+ppez1GQO1vJkuFrtCP/OifWMIIVCiqzxNM0VK3e zo1Pkmj0AjLe1DcagFzGf0X2rcnHb4rw9JWAzYNZGMB9WqEiXhRf1Y0OPjJrwa1RNGNf u9AZ4ltiOygEb+EWooBDH7MkaaugkV1N/BHCSGH3y0oXOWplJfC+iWW/2IP/6UNetqr0 kfk978w+4ujgPHo7Xj5n37D9TjwtpZvwgvOMl+P4dJRzCIdr5dgAx3EiWgzN8M2F5EGD VhmA== X-Gm-Message-State: AOJu0Yw8zyQpUBc/5bg1DpHUFE8JYLn47eZ5qvLQKy7Gp/JaiorfiNz+ AiLeCqHpO9FQOJaD33+N/Zo= X-Received: by 2002:a2e:7302:0:b0:2c5:ee7:b322 with SMTP id o2-20020a2e7302000000b002c50ee7b322mr6395660ljc.18.1700488284849; Mon, 20 Nov 2023 05:51:24 -0800 (PST) Received: from localhost.localdomain (93-34-89-13.ip49.fastwebnet.it. [93.34.89.13]) by smtp.googlemail.com with ESMTPSA id j33-20020a05600c1c2100b0040772934b12sm18205846wms.7.2023.11.20.05.51.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 05:51:24 -0800 (PST) From: Christian Marangi To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Andy Gross , Bjorn Andersson , Konrad Dybcio , Andrew Lunn , Heiner Kallweit , Russell King , Florian Fainelli , Broadcom internal kernel review list , Daniel Golle , Qingfang Deng , SkyLake Huang , Matthias Brugger , AngeloGioacchino Del Regno , David Epping , Vladimir Oltean , Christian Marangi , "Russell King (Oracle)" , Harini Katakam , Simon Horman , Robert Marko , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Subject: [net-next RFC PATCH 08/14] net: phy: add support for PHY package interface mode Date: Mon, 20 Nov 2023 14:50:35 +0100 Message-Id: <20231120135041.15259-9-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231120135041.15259-1-ansuelsmth@gmail.com> References: <20231120135041.15259-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Mon, 20 Nov 2023 05:52:16 -0800 (PST) Some PHY in PHY package supports running only at a specific mode for each PHY in the package. Add support for enforcing this special thing a verify consistency with the requested mode to prevent misconfiguration. To set the PHY package mode, simply set "phy-mode" in the phy-package node. Each PHY on init will verify if the requested mode match the one set for the PHY package and will return -EINVAL if this is not true. If PHY package doesn't specify any mode, it's assumed that PHY in the package doesn't have such limitation. Signed-off-by: Christian Marangi --- drivers/net/phy/phy_device.c | 37 ++++++++++++++++++++++++++++++++++++ include/linux/phy.h | 6 ++++++ 2 files changed, 43 insertions(+) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 0b7ba6995929..73af4197a7af 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -1225,8 +1226,17 @@ static int phy_poll_reset(struct phy_device *phydev) int phy_init_hw(struct phy_device *phydev) { + phy_interface_t package_interface; int ret = 0; + /* Validate we are requesting consistent mode if we + * are in a PHY package and the PHY package requires a + * specific mode. + */ + ret = phy_package_get_mode(phydev, &package_interface); + if (!ret && phydev->interface != package_interface) + return -EINVAL; + /* Deassert the reset signal */ phy_device_reset(phydev, 0); @@ -1776,6 +1786,32 @@ void phy_package_leave(struct phy_device *phydev) } EXPORT_SYMBOL_GPL(phy_package_leave); +/** + * phy_package_get_mode - get PHY interface mode for PHY package + * @phydev: target phy_device struct + * @interface: phy_interface_t pointer where to save the PHY package mode + * + * Gets PHY interface mode for the shared data of the PHY package. + * Returns 0 and updates @interface with the PHY package value, or -ENODEV + * if PHY is not in PHY package or -EINVAL if a PHY package interface mode + * is not set. + */ +int phy_package_get_mode(struct phy_device *phydev, phy_interface_t *interface) +{ + struct phy_package_shared *shared = phydev->shared; + + if (!shared) + return -ENODEV; + + if (shared->package_interface == PHY_INTERFACE_MODE_NA) + return -EINVAL; + + *interface = shared->package_interface; + + return 0; +} +EXPORT_SYMBOL_GPL(phy_package_get_mode); + static void devm_phy_package_leave(struct device *dev, void *res) { phy_package_leave(*(struct phy_device **)res); @@ -3270,6 +3306,7 @@ static int of_phy_package(struct phy_device *phydev) goto exit; phydev->shared->np = package_node; + of_get_phy_mode(package_node, &phydev->shared->package_interface); exit: kfree(global_phy_addrs); diff --git a/include/linux/phy.h b/include/linux/phy.h index 1849fc637196..8af0a8a72b88 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -341,6 +341,11 @@ struct mdio_bus_stats { struct phy_package_shared { /* With PHY package defined in DT this points to the PHY package node */ struct device_node *np; + /* PHY package interface + * If defined, each PHY of the package MUST have the interface + * set to the PHY package. + */ + phy_interface_t package_interface; /* addrs list pointer */ /* note that this pointer is shared between different phydevs. * It is allocated and freed automatically by phy_package_join() and @@ -2014,6 +2019,7 @@ int phy_ethtool_nway_reset(struct net_device *ndev); int phy_package_join(struct phy_device *phydev, int *addrs, size_t addrs_num, size_t priv_size); void phy_package_leave(struct phy_device *phydev); +int phy_package_get_mode(struct phy_device *phydev, phy_interface_t *interface); int devm_phy_package_join(struct device *dev, struct phy_device *phydev, int *addrs, size_t addrs_num, size_t priv_size); -- 2.40.1