Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1310413rbb; Mon, 26 Feb 2024 05:42:33 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXiTpUT0yVnu+2A7xE/8iOtDHuvpFLL4E7qC4OcVYvqod/hV5h+aEwEMLs+98nk4KN3rCbXttB8P82IBqJ6R2AxF7TBgR8DqBj7bOfzaQ== X-Google-Smtp-Source: AGHT+IGybBCUBQcG3K31dTEuG5WyMwUS10wRDeLSw6t1hIoL42W2dRVO/LSy1TbhWfTSb8jaeGYI X-Received: by 2002:a05:6870:d202:b0:21f:ccef:a731 with SMTP id g2-20020a056870d20200b0021fccefa731mr6537339oac.43.1708954953514; Mon, 26 Feb 2024 05:42:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708954953; cv=pass; d=google.com; s=arc-20160816; b=vcDTHlo3VqOkVblIFyX2zHS3/pF5AUPrbAJ8mRDwe0eAeuzIiYZaneptsC81iz9ZaI 0gnYr9Bi873GfFZhGlPBHy19RIWyg7X2VFTgmtrJJKHGRo9iAFLkG7GdT43gCz52H5tX wkzc+9JtsRT9uPaSBW28DviGjHRPa6WVHwjNi9AsggTFS7K0MK4zZdEH4i2JznR+RVuX LNc96f7EQVrylhvig8PfK9hmoz6Sz3BjwleUoo3ADd+rTKBmEf1l9/9q2gadhB69H/MU w35rT53WB1fpTxAjsBuV0Nrp67cyIinDulh9Cy/4GQivuAUKebhNVQhQZ1T3SeXbDhNI uxOQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=Uet75mnIaE3JwyHsIIMQq6iy2iUMj02Z/O8LfzL/MwQ=; fh=vtlcgQ30nO0QjQR7y1Wfn7g9c11A+T6SWcSZ6WixcJI=; b=ESMJPsfwtt2aNTHYukSP6iv0ja29iF54QQP69JawMw8v42zzo3KH0GZNCWD5WjzeUJ 7WJvypmqK/4vCHeemMz+aKLfE2uZX3J1JOqparI/UTSLvcL/LpeoJM0lsMFxpt/l2phu Q1hHnfzIE1z+BEhhtowDZcc/aYQJ7JS9ZrMmFJ7yEk/mNXrtQsZz7ehhN7PcmlLfqSqb XE8KeMoNJWcMN/NTewNeIy0DcDgkgy94OEFQmulIg9rPGQDU7DgDg6w+NpqgTbngjViK yv5PW36F3N2aKd/5MtzpDZsFHklubH+0rCImZaqH+QyFxlHpTx+vG4p1pr6VgVT3Esix YSkQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=f5GzajkF; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-81509-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-81509-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id c11-20020a63d50b000000b005dc42a836a3si3744234pgg.625.2024.02.26.05.42.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 05:42:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-81509-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=f5GzajkF; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-81509-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-81509-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id E5A3F28369C for ; Mon, 26 Feb 2024 13:42:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A3CBD12C545; Mon, 26 Feb 2024 13:40:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="f5GzajkF" Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3B4C412882C; Mon, 26 Feb 2024 13:40:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708954825; cv=none; b=Q0Ua/YbLiJP4/MeKzGMuleErwx1e2YqlWwLwlIUd5/RoW4iTCXaJGvkZxueAqVCzYRq2XgvU9zkcLJLi2VRkIpwQs6sxiutlwQPVzNIV1Xh/U1rVy/WdzffbN+ph4rt49oqjwCovXgZ96O0YjYfOwSTA0hAmCLrpXTPtWohU+e8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708954825; c=relaxed/simple; bh=zLUUTvjdltLauytWMLXk0P21dQJFhX21nlwthpGvqBs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bM3QR9bcZtICSyukHx54rV8wmO9XyPWVswiMByHNKAmDfh4nq6zd889tTPuTM0+vQF6CJD2mOhBD5ha+ptFkW1hPnnmh3oJ8w+vGZkU4SR/PakabFrx/dbdZ26C13JT5U1P/E80Ew1QmHxSRiSohcyPgyhyKF/eX36x88MDdTdE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=f5GzajkF; arc=none smtp.client-ip=217.70.183.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id 9A9014000D; Mon, 26 Feb 2024 13:40:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1708954821; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Uet75mnIaE3JwyHsIIMQq6iy2iUMj02Z/O8LfzL/MwQ=; b=f5GzajkF32vfkm5PyVLBuYCycbD3E1GF5EYcOaDrJfJfR3HaHbQ0bZK8aVAPYkbgbZ327/ TqlaYXrunpcHlC/Kgff7SZr0AWyyy5KmT9bceSunDaxbQw5MGtf3le/UEiwo9bMzdxeJxi 7Z4iKrNyzewdZ3J3YBqeh4rmieQOSmpr64xgCw3LX8GIKjAmhFH5ZzX0NppKvdIIkGnoCi ULRZUVl8dtWJMnLTKuaOUoC5qgX8CBsx4HthzmHndnaFFuNa+Io9EsKN76xfLLmYBwRE5C rjwaJ8Y+3a/6onG/lKppRn3nvKaOIVcqbJwdLaXQDCknWNmKy59MCtTJPgr5RQ== From: Kory Maincent Date: Mon, 26 Feb 2024 14:39:59 +0100 Subject: [PATCH net-next v9 08/13] ptp: Add phc source and helpers to register specific PTP clock or get information Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240226-feature_ptp_netnext-v9-8-455611549f21@bootlin.com> References: <20240226-feature_ptp_netnext-v9-0-455611549f21@bootlin.com> In-Reply-To: <20240226-feature_ptp_netnext-v9-0-455611549f21@bootlin.com> To: Florian Fainelli , Broadcom internal kernel review list , Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Richard Cochran , Radu Pirea , Jay Vosburgh , Andy Gospodarek , Nicolas Ferre , Claudiu Beznea , Willem de Bruijn , Jonathan Corbet , Horatiu Vultur , UNGLinuxDriver@microchip.com, Simon Horman , Vladimir Oltean Cc: Thomas Petazzoni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Maxime Chevallier , Rahul Rameshbabu , Kory Maincent X-Mailer: b4 0.12.4 X-GND-Sasl: kory.maincent@bootlin.com Prepare for future hardware timestamp selection by adding source and corresponding pointers to ptp_clock structure. Additionally, introduce helpers for registering specific phydev or netdev PTP clocks, retrieving PTP clock information such as hwtstamp source or phydev/netdev pointers, and obtaining the ptp_clock structure from the phc index. Signed-off-by: Kory Maincent --- Change in v8: - New patch. --- drivers/ptp/ptp_clock.c | 71 +++++++++++++++++++++++++++++++++ drivers/ptp/ptp_private.h | 5 +++ include/linux/ptp_clock_kernel.h | 84 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 160 insertions(+) diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c index f374b1e89780..d7cd7e01990e 100644 --- a/drivers/ptp/ptp_clock.c +++ b/drivers/ptp/ptp_clock.c @@ -504,6 +504,77 @@ void ptp_cancel_worker_sync(struct ptp_clock *ptp) } EXPORT_SYMBOL(ptp_cancel_worker_sync); +struct ptp_clock *netdev_ptp_clock_register(struct ptp_clock_info *info, + struct net_device *dev) +{ + struct ptp_clock *ptp; + + ptp = ptp_clock_register(info, &dev->dev); + if (IS_ERR(ptp)) + return ptp; + + ptp->phc_source = HWTSTAMP_SOURCE_NETDEV; + ptp->netdev = dev; + + return ptp; +} +EXPORT_SYMBOL(netdev_ptp_clock_register); + +struct ptp_clock *phydev_ptp_clock_register(struct ptp_clock_info *info, + struct phy_device *phydev) +{ + struct ptp_clock *ptp; + + ptp = ptp_clock_register(info, &phydev->mdio.dev); + if (IS_ERR(ptp)) + return ptp; + + ptp->phc_source = HWTSTAMP_SOURCE_PHYLIB; + ptp->phydev = phydev; + + return ptp; +} +EXPORT_SYMBOL(phydev_ptp_clock_register); + +bool ptp_clock_from_phylib(struct ptp_clock *ptp) +{ + return ptp->phc_source == HWTSTAMP_SOURCE_PHYLIB; +} +EXPORT_SYMBOL(ptp_clock_from_phylib); + +bool ptp_clock_from_netdev(struct ptp_clock *ptp) +{ + return ptp->phc_source == HWTSTAMP_SOURCE_NETDEV; +} +EXPORT_SYMBOL(ptp_clock_from_netdev); + +struct net_device *ptp_clock_netdev(struct ptp_clock *ptp) +{ + if (ptp->phc_source != HWTSTAMP_SOURCE_NETDEV) + return NULL; + + return ptp->netdev; +} +EXPORT_SYMBOL(ptp_clock_netdev); + +struct phy_device *ptp_clock_phydev(struct ptp_clock *ptp) +{ + if (ptp->phc_source != HWTSTAMP_SOURCE_PHYLIB) + return NULL; + + return ptp->phydev; +} +EXPORT_SYMBOL(ptp_clock_phydev); + +struct ptp_clock *ptp_clock_get_by_index(int index) +{ + if (index < 0) + return NULL; + + return xa_load(&ptp_clocks_map, (unsigned long)index); +} +EXPORT_SYMBOL(ptp_clock_get_by_index); + /* module operations */ static void __exit ptp_exit(void) diff --git a/drivers/ptp/ptp_private.h b/drivers/ptp/ptp_private.h index 45f9002a5dca..3faecc5b9136 100644 --- a/drivers/ptp/ptp_private.h +++ b/drivers/ptp/ptp_private.h @@ -41,6 +41,11 @@ struct ptp_clock { struct ptp_clock_info *info; dev_t devid; int index; /* index into clocks.map */ + enum hwtstamp_source phc_source; + union { /* Pointer of the phc_source device */ + struct net_device *netdev; + struct phy_device *phydev; + }; struct pps_device *pps_source; long dialed_frequency; /* remembers the frequency adjustment */ struct list_head tsevqs; /* timestamp fifo list */ diff --git a/include/linux/ptp_clock_kernel.h b/include/linux/ptp_clock_kernel.h index 6e4b8206c7d0..174a0b98632b 100644 --- a/include/linux/ptp_clock_kernel.h +++ b/include/linux/ptp_clock_kernel.h @@ -9,7 +9,9 @@ #define _PTP_CLOCK_KERNEL_H_ #include +#include #include +#include #include #include #include @@ -340,6 +342,70 @@ extern void ptp_clock_event(struct ptp_clock *ptp, extern int ptp_clock_index(struct ptp_clock *ptp); +/** + * netdev_ptp_clock_register() - register a PTP hardware clock driver for + * a net device + * + * @info: Structure describing the new clock. + * @dev: Pointer of the net device + */ + +extern struct ptp_clock * +netdev_ptp_clock_register(struct ptp_clock_info *info, + struct net_device *dev); + +/** + * phydev_ptp_clock_register() - register a PTP hardware clock driver for + * a phy device + * + * @info: Structure describing the new clock. + * @phydev: Pointer of the phy device + */ + +extern struct ptp_clock * +phydev_ptp_clock_register(struct ptp_clock_info *info, + struct phy_device *phydev); + +/** + * ptp_clock_from_phylib() - return true if the PTP clock comes from phylib + * + * @ptp: The clock obtained from net/phy_ptp_clock_register(). + */ + +bool ptp_clock_from_phylib(struct ptp_clock *ptp); + +/** + * ptp_clock_from_netdev() - return true if the PTP clock comes from netdev + * + * @ptp: The clock obtained from net/phy_ptp_clock_register(). + */ + +bool ptp_clock_from_netdev(struct ptp_clock *ptp); + +/** + * ptp_clock_netdev() - obtain the net_device of PTP clock + * + * @ptp: The clock obtained from netdev_ptp_clock_register(). + */ + +struct net_device *ptp_clock_netdev(struct ptp_clock *ptp); + +/** + * ptp_clock_phydev() - obtain the phy_device of a PTP clock + * + * @ptp: The clock obtained from phydev_ptp_clock_register(). + */ + +struct phy_device *ptp_clock_phydev(struct ptp_clock *ptp); + +/** + * ptp_clock_get_by_index() - obtain the PTP clock from a given PHC index + * + * @index: The device index of a PTP clock. + */ + +struct ptp_clock *ptp_clock_get_by_index(int index); + /** * ptp_find_pin() - obtain the pin index of a given auxiliary function * @@ -405,6 +471,24 @@ static inline void ptp_clock_event(struct ptp_clock *ptp, { } static inline int ptp_clock_index(struct ptp_clock *ptp) { return -1; } +static inline struct ptp_clock * +netdev_ptp_clock_register(struct ptp_clock_info *info, + struct net_device *dev) +{ return NULL; } +static inline struct ptp_clock * +phydev_ptp_clock_register(struct ptp_clock_info *info, + struct phy_device *phydev) +{ return NULL; } +static inline bool ptp_clock_from_phylib(struct ptp_clock *ptp) +{ return false; } +static inline bool ptp_clock_from_netdev(struct ptp_clock *ptp) +{ return false; } +static inline struct net_device *ptp_clock_netdev(struct ptp_clock *ptp) +{ return NULL; } +static inline struct phy_device *ptp_clock_phydev(struct ptp_clock *ptp); +{ return NULL; } +static inline struct ptp_clock *ptp_clock_get_by_index(int index); +{ return NULL; } static inline int ptp_find_pin(struct ptp_clock *ptp, enum ptp_pin_function func, unsigned int chan) { return -1; } -- 2.25.1