From patchwork Mon Feb 26 13:39:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?K=C3=B6ry_Maincent?= X-Patchwork-Id: 206631 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp2082356dyb; Mon, 26 Feb 2024 05:42:56 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU//77GMXx7OlO66nadulhJFpwNO0xk7rOVVS3N3u6VPXYCRkuGQGFRjNH8r9woAEOZfeI0kguz8n/k83OZaSD5PhASBw== X-Google-Smtp-Source: AGHT+IGq2kMyiyh3iwza92r/HlLIiNrcxNEPC/YWTDOr2abeC/lrojLUYYMqJl2KeQ9DHZ+16yec X-Received: by 2002:a05:6a20:f389:b0:1a0:e1b6:4306 with SMTP id qr9-20020a056a20f38900b001a0e1b64306mr7451677pzb.57.1708954976377; Mon, 26 Feb 2024 05:42:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708954976; cv=pass; d=google.com; s=arc-20160816; b=dyFSnAtelvG5i4nYh8GvyGBtJEfqcqx+YYjtSFpnLYFMZep6vqSgbfSUDbsN1m+iMV 7oCOqUOiN8p5POB51qaV5n7daRFo7ueuPnNGi+wm8R1w1eGBqGP2VZZbRt6RYxOw9OTW B9ZRH+RT1UNGs/g4gZztwlVkQgoebCmTpKU9/AnX3irMdxVC6Q5mLO9ePk5vj+fjbpCn aEV4fVTSQmFpaLhxVGiA4wYUiTwW+nGe2e4V7LqbD98PnVDFhHZdu++7gK3nyheOYZyW o6pQYlOayCglxJZYYFfWjMQuAFKwObT3oHgeXs9OpuW84zTPtJfvy4ibHtjNRFXcEKYk 1tCg== 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-81509-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id go11-20020a17090b03cb00b00299ecd1e886si5490200pjb.69.2024.02.26.05.42.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 05:42:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-81509-ouuuleilei=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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-81509-ouuuleilei=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 1F4DA2898BF for ; Mon, 26 Feb 2024 13:42:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6E7C012C812; Mon, 26 Feb 2024 13:40:29 +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 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791969173620727564 X-GMAIL-MSGID: 1791969173620727564 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; }