From patchwork Mon Aug 19 17:28:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hubert Feurstein X-Patchwork-Id: 1149447 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="DTTOm8ZD"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 46C1B22wfvz9sNp for ; Tue, 20 Aug 2019 03:28:58 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728105AbfHSR2o (ORCPT ); Mon, 19 Aug 2019 13:28:44 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:43179 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727819AbfHSR2m (ORCPT ); Mon, 19 Aug 2019 13:28:42 -0400 Received: by mail-wr1-f68.google.com with SMTP id y8so9544427wrn.10; Mon, 19 Aug 2019 10:28:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Aqe8ssO7vbcAbN8euP3FTsvyBcUk74KyUbdkeYdhPr8=; b=DTTOm8ZDNwuED6B/oQ05QNZWibeJ8s5kZMTNjf+jZm2+NKbZjjL7L0rANqI/Ylp26T Gi3QLyH3vuRlgpgJmpI0We7HphuMrIelqmGHBc22svtKLoUX3hgdXEMlHIjH7va1cefi 5vp6YM7Fjlvcg14SV4jpX1u/sQy4yDJlLcR+2Y49SIlZ7CkzDzZahHycjHatW+g4JDbY Cv6z5L0d4ES5oMelM/Cb1C+h5Jp1zz/uEOFSJ8XC7RriaIVixU0LsmAZShaoQQoyhrHs N65IuCllObV8f2mNpiTZihW0oHoFMmvQsc7eXNgimInccu2WXSPJgfy6a+zwFv5HWlc2 3fnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Aqe8ssO7vbcAbN8euP3FTsvyBcUk74KyUbdkeYdhPr8=; b=OSr+7/2uA61lkQht4/66mOo72crCmLX8A74aZu7CgOpSUmA0mUxr9dXlgVAlvCpiMr uHCkHhuTYbyGSIWAccL1mvmpmMLBFf5SOOXDOIhkmMwEYOiyZ7eu8qj12Z4Pt/fYIp8K 4hg3BVo8zokKpYjicE2OdWqBYW2AXA2TmfZtwKJUfExc6KLh9zo5vKutC5BzWFvteTQD RzmHJadzAmlA+HGQyRIXctcovBtFZMV21+iP/TzBE05gNoIccmhHhSHy01CaKlWRReRL DbKRAtED2z20+wXwwnsNSiO1tW8g99mRGGp2pbgwe94iAkXZ/IoPezrPfPgsOJzciatJ xMEA== X-Gm-Message-State: APjAAAXpeApv2YRo+5h9XGnYn59liPvFAB0P4Nm7LBj/0vJtxs5LIp24 ECpxziQZ7v4x9p3aYOgphamQQU/1DYQ= X-Google-Smtp-Source: APXvYqzHxSGNq9aOHNj7xQJvStXQinB6s6d5+l0bsK7KbJvqQrc7e6fFkWTzUHp1B8FjTqI5kyUwoQ== X-Received: by 2002:adf:f286:: with SMTP id k6mr15314522wro.320.1566235719544; Mon, 19 Aug 2019 10:28:39 -0700 (PDT) Received: from vd-lxpc-hfe.ad.vahle.at ([80.110.31.209]) by smtp.gmail.com with ESMTPSA id c15sm41983879wrb.80.2019.08.19.10.28.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Aug 2019 10:28:39 -0700 (PDT) From: Hubert Feurstein X-Google-Original-From: Hubert Feurstein To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Hubert Feurstein , Andrew Lunn , Richard Cochran , Florian Fainelli , Heiner Kallweit , Vladimir Oltean , "David S. Miller" Subject: [PATCH net-next v2 1/4] net: mdio: add support for passing a PTP system timestamp to the mii_bus driver Date: Mon, 19 Aug 2019 19:28:24 +0200 Message-Id: <20190819172827.9550-2-hubert.feurstein@vahle.at> X-Mailer: git-send-email 2.22.1 In-Reply-To: <20190819172827.9550-1-hubert.feurstein@vahle.at> References: <20190819172827.9550-1-hubert.feurstein@vahle.at> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Hubert Feurstein In order to improve the synchronisation precision of phc2sys (from the linuxptp project) for devices like switches which are attached to the MDIO bus, it is necessary the get the system timestamps as close as possible to the access which causes the PTP timestamp register to be snapshotted in the switch hardware. Usually this is triggered by an MDIO write access, the snapshotted timestamp is then transferred by several MDIO reads. This patch adds the required infrastructure to solve the problem described above. Signed-off-by: Hubert Feurstein --- Changes in v2: - Removed mdiobus_write_sts as there was no user - Removed ptp_sts_supported-boolean and introduced flags instead drivers/net/phy/mdio_bus.c | 76 ++++++++++++++++++++++++++++++++++++++ include/linux/mdio.h | 5 +++ include/linux/phy.h | 34 +++++++++++++++++ 3 files changed, 115 insertions(+) diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c index bd04fe762056..4dba2714495e 100644 --- a/drivers/net/phy/mdio_bus.c +++ b/drivers/net/phy/mdio_bus.c @@ -34,6 +34,7 @@ #include #include #include +#include #define CREATE_TRACE_POINTS #include @@ -697,6 +698,81 @@ int mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val) } EXPORT_SYMBOL(mdiobus_write); +/** + * __mdiobus_write_sts - Unlocked version of the mdiobus_write_sts function + * @bus: the mii_bus struct + * @addr: the phy address + * @regnum: register number to write + * @val: value to write to @regnum + * @sts: the ptp system timestamp + * + * Write a MDIO bus register and request the MDIO bus driver to take the + * system timestamps when sts-pointer is valid. When the bus driver doesn't + * support this, the timestamps are taken in this function instead. + * + * In order to improve the synchronisation precision of phc2sys (from + * the linuxptp project) for devices like switches which are attached + * to the MDIO bus, it is necessary the get the system timestamps as + * close as possible to the access which causes the PTP timestamp + * register to be snapshotted in the switch hardware. Usually this is + * triggered by an MDIO write access, the snapshotted timestamp is then + * transferred by several MDIO reads. + * + * Caller must hold the mdio bus lock. + * + * NOTE: MUST NOT be called from interrupt context. + */ +int __mdiobus_write_sts(struct mii_bus *bus, int addr, u32 regnum, u16 val, + struct ptp_system_timestamp *sts) +{ + int retval; + + WARN_ON_ONCE(!mutex_is_locked(&bus->mdio_lock)); + + if (!(bus->flags & MII_BUS_F_PTP_STS_SUPPORTED)) + ptp_read_system_prets(sts); + + bus->ptp_sts = sts; + retval = __mdiobus_write(bus, addr, regnum, val); + bus->ptp_sts = NULL; + + if (!(bus->flags & MII_BUS_F_PTP_STS_SUPPORTED)) + ptp_read_system_postts(sts); + + return retval; +} +EXPORT_SYMBOL(__mdiobus_write_sts); + +/** + * mdiobus_write_sts_nested - Nested version of the mdiobus_write_sts function + * @bus: the mii_bus struct + * @addr: the phy address + * @regnum: register number to write + * @val: value to write to @regnum + * @sts: the ptp system timestamp + * + * In case of nested MDIO bus access avoid lockdep false positives by + * using mutex_lock_nested(). + * + * NOTE: MUST NOT be called from interrupt context, + * because the bus read/write functions may wait for an interrupt + * to conclude the operation. + */ +int mdiobus_write_sts_nested(struct mii_bus *bus, int addr, u32 regnum, u16 val, + struct ptp_system_timestamp *sts) +{ + int retval; + + BUG_ON(in_interrupt()); + + mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED); + retval = __mdiobus_write_sts(bus, addr, regnum, val, sts); + mutex_unlock(&bus->mdio_lock); + + return retval; +} +EXPORT_SYMBOL(mdiobus_write_sts_nested); + /** * mdio_bus_match - determine if given MDIO driver supports the given * MDIO device diff --git a/include/linux/mdio.h b/include/linux/mdio.h index e8242ad88c81..482388341c7b 100644 --- a/include/linux/mdio.h +++ b/include/linux/mdio.h @@ -9,6 +9,7 @@ #include #include +struct ptp_system_timestamp; struct gpio_desc; struct mii_bus; @@ -305,11 +306,15 @@ static inline void mii_10gbt_stat_mod_linkmode_lpa_t(unsigned long *advertising, int __mdiobus_read(struct mii_bus *bus, int addr, u32 regnum); int __mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val); +int __mdiobus_write_sts(struct mii_bus *bus, int addr, u32 regnum, u16 val, + struct ptp_system_timestamp *sts); int mdiobus_read(struct mii_bus *bus, int addr, u32 regnum); int mdiobus_read_nested(struct mii_bus *bus, int addr, u32 regnum); int mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val); int mdiobus_write_nested(struct mii_bus *bus, int addr, u32 regnum, u16 val); +int mdiobus_write_sts_nested(struct mii_bus *bus, int addr, u32 regnum, u16 val, + struct ptp_system_timestamp *sts); int mdiobus_register_device(struct mdio_device *mdiodev); int mdiobus_unregister_device(struct mdio_device *mdiodev); diff --git a/include/linux/phy.h b/include/linux/phy.h index d26779f1fb6b..0b33662e0320 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -205,6 +205,13 @@ struct device; struct phylink; struct sk_buff; +/* MII-bus flags: + * @MII_BUS_F_PTP_STS_SUPPORTED: The driver supports PTP system timestamping + */ +enum mii_bus_flags { + MII_BUS_F_PTP_STS_SUPPORTED = BIT(0) +}; + /* * The Bus class for PHYs. Devices which provide access to * PHYs should register using this structure @@ -252,7 +259,34 @@ struct mii_bus { int reset_delay_us; /* RESET GPIO descriptor pointer */ struct gpio_desc *reset_gpiod; + + /* Feature flags */ + u32 flags; + + /* PTP system timestamping support + * + * In order to improve the synchronisation precision of phc2sys (from + * the linuxptp project) for devices like switches which are attached + * to the MDIO bus, it is necessary the get the system timestamps as + * close as possible to the access which causes the PTP timestamp + * register to be snapshotted in the switch hardware. Usually this is + * triggered by an MDIO write access, the snapshotted timestamp is then + * transferred by several MDIO reads. + * + * The switch driver can use mdio_write_sts*() to pass through the + * system timestamp pointer @ptp_sts to the MDIO bus driver. The bus + * driver simply has to do the following calls in its write handler: + * ptp_read_system_prets(bus->ptp_sts); + * writel(value, mdio-register) + * ptp_read_system_postts(bus->ptp_sts); + * + * The ptp_read_system_*ts functions already check the ptp_sts pointer. + * The MII_BUS_F_PTP_STS_SUPPORTED-bit must be set in flags, when the + * MDIO bus driver takes the timestamps as described above. + */ + struct ptp_system_timestamp *ptp_sts; }; + #define to_mii_bus(d) container_of(d, struct mii_bus, dev) struct mii_bus *mdiobus_alloc_size(size_t); From patchwork Mon Aug 19 17:28:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hubert Feurstein X-Patchwork-Id: 1149445 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="QbDyngL9"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 46C19p1Ggdz9sMr for ; Tue, 20 Aug 2019 03:28:46 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728160AbfHSR2o (ORCPT ); Mon, 19 Aug 2019 13:28:44 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:33836 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727094AbfHSR2m (ORCPT ); Mon, 19 Aug 2019 13:28:42 -0400 Received: by mail-wr1-f67.google.com with SMTP id s18so9574160wrn.1; Mon, 19 Aug 2019 10:28:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fJRlmlBru4RfFVqA4+d8k80FcuTjsj2jSzcYsHbb4+E=; b=QbDyngL9zFtAGjC3x/6yoI+ngXX8zIZ3g6f5LhhPKjeQdbJC75iUjIdPIUAbvw0mBv HL+0wx345agETAqUx2DeDyaquj38vWycdhR6saGG+aSa3BhSmtFrJRUj8wr2++u3V6Tk WRkF6pXeL8/lH71s42tKpCJmlaHaxmPankWNN6rtt/OsOpVmRlO/VjHWsCRVlP8ZPquS 4BROHWZXLCgwCefYfVvPLjNM9/G+T7AFnyUIqfjEqL+HWCnSw2MGIVurgYLxSlNpy/R1 Qulv+PE2MZgkkPexJdJ7fM1TRlvNGjVLhC1KggfQ+e+7iYsxG/YM7bzElSD7dDgEuR7g fPRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fJRlmlBru4RfFVqA4+d8k80FcuTjsj2jSzcYsHbb4+E=; b=qzdGQpVMJXkio0c4+yABEnmerIkTIK1qHNVs+tVWOezIaWlLuGqElKPhRVYygy4WSj Bv15NeqENpjM60FSNpxXd81AfT8OBGsMOcmhW4NBf6aVBWhknl8wU9c+wamSYWUNeEBg 2R2gqUxKMTCZGNHLyA5bmKxmgc2pO2oYqaW3HFzHtinb+x3CWv+I7loJn+3mLd+evPBm 8/4EQAGw1k82c7ZE2qRTu82CkR2JGQ9rLYukM2ft7sG1NwjiZTp5yCugrOWYrJC32JmK adrlG0pFrplUE7mH+5CGXoxDM1hf1lULE43uFfUSVMCXOlBHKzpzQ/2vN7WuQfveX19T k3gA== X-Gm-Message-State: APjAAAVTnso4F8BnMnaF2yJamq+IbwcFnYQAUa+ImXcQBRGSnx8uTnRs GIj8ooDnGn3oy17Ewq+wlrLWZK9VYTw= X-Google-Smtp-Source: APXvYqyGcAbp2p9pu3cM4D4KXc1lUmVtuwAh5z92aZ4jI0xDyQT9LJUXyKjjhR+D+jEDg5+H1OExhQ== X-Received: by 2002:adf:ea08:: with SMTP id q8mr5731752wrm.188.1566235720807; Mon, 19 Aug 2019 10:28:40 -0700 (PDT) Received: from vd-lxpc-hfe.ad.vahle.at ([80.110.31.209]) by smtp.gmail.com with ESMTPSA id c15sm41983879wrb.80.2019.08.19.10.28.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Aug 2019 10:28:40 -0700 (PDT) From: Hubert Feurstein X-Google-Original-From: Hubert Feurstein To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Hubert Feurstein , Andrew Lunn , Richard Cochran , Florian Fainelli , Heiner Kallweit , Vladimir Oltean , "David S. Miller" Subject: [PATCH net-next v2 2/4] net: mdio: add PTP offset compensation to mdiobus_write_sts Date: Mon, 19 Aug 2019 19:28:25 +0200 Message-Id: <20190819172827.9550-3-hubert.feurstein@vahle.at> X-Mailer: git-send-email 2.22.1 In-Reply-To: <20190819172827.9550-1-hubert.feurstein@vahle.at> References: <20190819172827.9550-1-hubert.feurstein@vahle.at> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Hubert Feurstein The slow MDIO access introduces quite a big offset (~13us) to the PTP system time synchronisation. With this patch the driver has the possibility to set the correct offset which can then be compensated. Signed-off-by: Hubert Feurstein --- drivers/net/phy/mdio_bus.c | 12 ++++++++++++ include/linux/phy.h | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c index 4dba2714495e..50a37cf46f96 100644 --- a/drivers/net/phy/mdio_bus.c +++ b/drivers/net/phy/mdio_bus.c @@ -739,6 +739,18 @@ int __mdiobus_write_sts(struct mii_bus *bus, int addr, u32 regnum, u16 val, if (!(bus->flags & MII_BUS_F_PTP_STS_SUPPORTED)) ptp_read_system_postts(sts); + /* PTP offset compensation: + * After the MDIO access is completed (from the chip perspective), the + * switch chip will snapshot the PHC timestamp. To make sure our system + * timestamp corresponds to the PHC timestamp, we have to add the + * duration of this MDIO access to sts->post_ts. Linuxptp's phc2sys + * takes the average of pre_ts and post_ts to calculate the final + * system timestamp. With this in mind, we have to add ptp_sts_offset + * twice to post_ts, in order to not introduce an constant time offset. + */ + if (sts) + timespec64_add_ns(&sts->post_ts, 2 * bus->ptp_sts_offset); + return retval; } EXPORT_SYMBOL(__mdiobus_write_sts); diff --git a/include/linux/phy.h b/include/linux/phy.h index 0b33662e0320..615df9c7f2c3 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -283,8 +283,16 @@ struct mii_bus { * The ptp_read_system_*ts functions already check the ptp_sts pointer. * The MII_BUS_F_PTP_STS_SUPPORTED-bit must be set in flags, when the * MDIO bus driver takes the timestamps as described above. + * + * @ptp_sts_offset: This is the compensation offset for the system + * timestamp which is introduced by the slow MDIO access duration. An + * MDIO access consists of 32 clock cycles. Usually the MDIO bus runs + * at ~2.5MHz, so we have to compensate ~12800ns offset. + * Set the ptp_sts_offset to the exact duration of one MDIO frame + * (= 32 * clock-period) in nano-seconds. */ struct ptp_system_timestamp *ptp_sts; + u32 ptp_sts_offset; }; #define to_mii_bus(d) container_of(d, struct mii_bus, dev) From patchwork Mon Aug 19 17:28:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hubert Feurstein X-Patchwork-Id: 1149448 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="rB+i0qyl"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 46C1B66n2qz9sNf for ; Tue, 20 Aug 2019 03:29:02 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728209AbfHSR26 (ORCPT ); Mon, 19 Aug 2019 13:28:58 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:34042 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727801AbfHSR2o (ORCPT ); Mon, 19 Aug 2019 13:28:44 -0400 Received: by mail-wm1-f66.google.com with SMTP id e8so511712wme.1; Mon, 19 Aug 2019 10:28:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=N4+pf5d7pVmnBlivGuHqKTTW2Rfxav1QD4GVn+SGku8=; b=rB+i0qylgMJQS7W6tIapfGXnwknLUgZSuLbNMFUO5e0mY9mi6LehXLYeQ7C3mPriH4 whXcuu7eAGt49zKShHlAgvFJ1XRBIiVz0kt46A8CXx2vZGTvbHHlfBIqPaPL65RQIyVR oSQhSq1QYb+sCIQht0/6YvF8jFqusSUf9CqGKcmpJkxzuznHJXTz8vKfK93dXq9wtSFa Tla2r5lNdRX9kqJRK8yFbc5WuRQws497J6xZM5QSCo0x61ZY93qkbiUhDOT6IEyeTweh iqFU76VYUaFuhL0tvdGfV6qUh4yuMGiYUcYlgCLseza4NiVq/5mIVi/b15a8oqx/CQiG 5ygw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=N4+pf5d7pVmnBlivGuHqKTTW2Rfxav1QD4GVn+SGku8=; b=WmSc7QzqcD9mFCqcmUmhXLYA9ZY9jFrMq+55iRUUGM4Jj6NJHtXaHLYFL2qSvnVz26 ElhXa99gEBVGQDc6xD/j5ZKTsHybNQZpwojyyMbXT8xG7Wtrnr30oR78UWDYVuQnYhoL ILvFiz73gE9DmBlfhPxzD75ZI2K5GY/0d12Nf5j15pkI6oITTDYQpt9NgXaOKsB9NAPL o6wIkTbSlqLO5ZcN4w6oKYrFjiqIp9vkaVaz5/VexIHZF8xmSKPPH4UPDsQTPg4lxUga 1i+kvh7D4jR7+rziuwmU3hIOsgwW2PF9tkgeJ0ScIQXviVPe6s8ROAxNjIDpEoCTDUa7 IkCw== X-Gm-Message-State: APjAAAWP6SH6GmTp27k9I0Zafz1aJlHO5d/26lcjTqAOJSaneFp3Qv/n glYTy65kl+mmgJqd3vVk67kgurMqhzs= X-Google-Smtp-Source: APXvYqy73eiSXTGbmsnpMG7uHCQEtftllyD/DExkUuGM5RhQ4eFmkuRfv24N/mORrnN11uzM7J/z+A== X-Received: by 2002:a1c:9ec5:: with SMTP id h188mr21805675wme.176.1566235722008; Mon, 19 Aug 2019 10:28:42 -0700 (PDT) Received: from vd-lxpc-hfe.ad.vahle.at ([80.110.31.209]) by smtp.gmail.com with ESMTPSA id c15sm41983879wrb.80.2019.08.19.10.28.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Aug 2019 10:28:41 -0700 (PDT) From: Hubert Feurstein X-Google-Original-From: Hubert Feurstein To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Hubert Feurstein , Andrew Lunn , Richard Cochran , Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S. Miller" Subject: [PATCH net-next v2 3/4] net: dsa: mv88e6xxx: extend PTP gettime function to read system clock Date: Mon, 19 Aug 2019 19:28:26 +0200 Message-Id: <20190819172827.9550-4-hubert.feurstein@vahle.at> X-Mailer: git-send-email 2.22.1 In-Reply-To: <20190819172827.9550-1-hubert.feurstein@vahle.at> References: <20190819172827.9550-1-hubert.feurstein@vahle.at> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Hubert Feurstein This adds support for the PTP_SYS_OFFSET_EXTENDED ioctl. Signed-off-by: Hubert Feurstein --- drivers/net/dsa/mv88e6xxx/chip.h | 2 ++ drivers/net/dsa/mv88e6xxx/ptp.c | 11 +++++++---- drivers/net/dsa/mv88e6xxx/smi.c | 3 ++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/net/dsa/mv88e6xxx/chip.h b/drivers/net/dsa/mv88e6xxx/chip.h index a406be2f5652..1bfde0d8a5a3 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.h +++ b/drivers/net/dsa/mv88e6xxx/chip.h @@ -275,6 +275,8 @@ struct mv88e6xxx_chip { struct ptp_clock_info ptp_clock_info; struct delayed_work tai_event_work; struct ptp_pin_desc pin_config[MV88E6XXX_MAX_GPIO]; + struct ptp_system_timestamp *ptp_sts; + u16 trig_config; u16 evcap_config; u16 enable_count; diff --git a/drivers/net/dsa/mv88e6xxx/ptp.c b/drivers/net/dsa/mv88e6xxx/ptp.c index 073cbd0bb91b..cf6e52ee9e0a 100644 --- a/drivers/net/dsa/mv88e6xxx/ptp.c +++ b/drivers/net/dsa/mv88e6xxx/ptp.c @@ -235,14 +235,17 @@ static int mv88e6xxx_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta) return 0; } -static int mv88e6xxx_ptp_gettime(struct ptp_clock_info *ptp, - struct timespec64 *ts) +static int mv88e6xxx_ptp_gettimex(struct ptp_clock_info *ptp, + struct timespec64 *ts, + struct ptp_system_timestamp *sts) { struct mv88e6xxx_chip *chip = ptp_to_chip(ptp); u64 ns; mv88e6xxx_reg_lock(chip); + chip->ptp_sts = sts; ns = timecounter_read(&chip->tstamp_tc); + chip->ptp_sts = NULL; mv88e6xxx_reg_unlock(chip); *ts = ns_to_timespec64(ns); @@ -426,7 +429,7 @@ static void mv88e6xxx_ptp_overflow_check(struct work_struct *work) struct mv88e6xxx_chip *chip = dw_overflow_to_chip(dw); struct timespec64 ts; - mv88e6xxx_ptp_gettime(&chip->ptp_clock_info, &ts); + mv88e6xxx_ptp_gettimex(&chip->ptp_clock_info, &ts, NULL); schedule_delayed_work(&chip->overflow_work, MV88E6XXX_TAI_OVERFLOW_PERIOD); @@ -472,7 +475,7 @@ int mv88e6xxx_ptp_setup(struct mv88e6xxx_chip *chip) chip->ptp_clock_info.max_adj = MV88E6XXX_MAX_ADJ_PPB; chip->ptp_clock_info.adjfine = mv88e6xxx_ptp_adjfine; chip->ptp_clock_info.adjtime = mv88e6xxx_ptp_adjtime; - chip->ptp_clock_info.gettime64 = mv88e6xxx_ptp_gettime; + chip->ptp_clock_info.gettimex64 = mv88e6xxx_ptp_gettimex; chip->ptp_clock_info.settime64 = mv88e6xxx_ptp_settime; chip->ptp_clock_info.enable = ptp_ops->ptp_enable; chip->ptp_clock_info.verify = ptp_ops->ptp_verify; diff --git a/drivers/net/dsa/mv88e6xxx/smi.c b/drivers/net/dsa/mv88e6xxx/smi.c index 282fe08db050..abedd04ff2ae 100644 --- a/drivers/net/dsa/mv88e6xxx/smi.c +++ b/drivers/net/dsa/mv88e6xxx/smi.c @@ -45,7 +45,8 @@ static int mv88e6xxx_smi_direct_write(struct mv88e6xxx_chip *chip, { int ret; - ret = mdiobus_write_nested(chip->bus, dev, reg, data); + ret = mdiobus_write_sts_nested(chip->bus, dev, reg, data, + chip->ptp_sts); if (ret < 0) return ret; From patchwork Mon Aug 19 17:28:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hubert Feurstein X-Patchwork-Id: 1149446 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Z60DL/+1"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 46C19w6YYCz9sNF for ; Tue, 20 Aug 2019 03:28:52 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728187AbfHSR2s (ORCPT ); Mon, 19 Aug 2019 13:28:48 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:36456 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728101AbfHSR2p (ORCPT ); Mon, 19 Aug 2019 13:28:45 -0400 Received: by mail-wr1-f65.google.com with SMTP id r3so9571460wrt.3; Mon, 19 Aug 2019 10:28:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LDL1hIKadz1gfObFDnKi45zKhu1D1Ko8kUYujKrQlXI=; b=Z60DL/+1uGqB6RAG9SY6mTUSrszUibmymMj+BCjmF8VzVv0OfxV6lTLlkqtJLYliZN ogn5iXTtb00TNB/5OSLI6xhz3CxHE7pJmcd7f5Axr/2IVT0/ELrp6GAZ+SbFNRhKKwWq hNMLwkTLlNmGgFiHX56LYQk1nL0vI0aCe6S6Q+UjxTMaX8kNewewdopAU+P/fix/I2lw tvJ4+WM2gEi00fnFGVzGXiQV+ClNzw3ztJci7nmC8Uo2JKobJVLBjzP5ATDeWHpRcZKd 6BKmclfp3iq2648uxgx6aWa/it/S41T/MVEDXzgdHCdRQGr7Vdgz5/RtRBTcRmmsB30z eP6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LDL1hIKadz1gfObFDnKi45zKhu1D1Ko8kUYujKrQlXI=; b=bPRgO3CRzkKDrNeVXjOX/CRb4jaQQVjGO62EA9J4Mil1fmoAQgdkf6oxsFeLzaWZiZ Wu9lcbS0rcVT4qYh2yX8/M+4kxyDSv093T/+C7GS7fVhvbyoVhQI8kwS6T0oBDOklKzL 4LxASy4MWOE0c3BNxOCUo0njJqOLQQoN+peUB4k7kbFuBGX3lvfPIAvmmLTLGoydLa0z b3FmW1YTjfLwcSBnaHx38sRDCvb2Jb+g5z4Gr65AlKK5Or/xt4Vxl2zc1NbUAbbh1A5D 8qyD5Guc603IeY6vJrpWBq8IvYqHFt9ExKlS9bczWh9m/DQDUROxD6TFp2Dm7ulOvOV/ aM4g== X-Gm-Message-State: APjAAAULgjud2ij0PiJumC+QbAMFl5RBMtP8WodjwmPjb+VsxatwCFcQ /0j5laO3CL2xD7mhkTCHh4coCQjENVA= X-Google-Smtp-Source: APXvYqx5uU5Wkhv60Ep5MQhWUVfVnCLRfGCdZTr4zXY0b1zOPWbc8aC4hUxy7JD5FDmQPjf/M14kSg== X-Received: by 2002:adf:e3ce:: with SMTP id k14mr27044218wrm.303.1566235723149; Mon, 19 Aug 2019 10:28:43 -0700 (PDT) Received: from vd-lxpc-hfe.ad.vahle.at ([80.110.31.209]) by smtp.gmail.com with ESMTPSA id c15sm41983879wrb.80.2019.08.19.10.28.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Aug 2019 10:28:42 -0700 (PDT) From: Hubert Feurstein X-Google-Original-From: Hubert Feurstein To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Hubert Feurstein , Andrew Lunn , Richard Cochran , Fugang Duan , Vladimir Oltean , "David S. Miller" Subject: [PATCH net-next v2 4/4] net: fec: add support for PTP system timestamping for MDIO devices Date: Mon, 19 Aug 2019 19:28:27 +0200 Message-Id: <20190819172827.9550-5-hubert.feurstein@vahle.at> X-Mailer: git-send-email 2.22.1 In-Reply-To: <20190819172827.9550-1-hubert.feurstein@vahle.at> References: <20190819172827.9550-1-hubert.feurstein@vahle.at> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Hubert Feurstein In order to improve the synchronisation precision of phc2sys (from the linuxptp project) for devices like switches which are attached to the MDIO bus, it is necessary the get the system timestamps as close as possible to the access which causes the PTP timestamp register to be snapshotted in the switch hardware. Usually this is triggered by an MDIO write access, the snapshotted timestamp is then transferred by several MDIO reads. The ptp_read_system_*ts functions already check the ptp_sts pointer. Signed-off-by: Hubert Feurstein --- drivers/net/ethernet/freescale/fec_main.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c index c01d3ec3e9af..dd1253683ac0 100644 --- a/drivers/net/ethernet/freescale/fec_main.c +++ b/drivers/net/ethernet/freescale/fec_main.c @@ -1815,10 +1815,12 @@ static int fec_enet_mdio_write(struct mii_bus *bus, int mii_id, int regnum, reinit_completion(&fep->mdio_done); /* start a write op */ + ptp_read_system_prets(bus->ptp_sts); writel(FEC_MMFR_ST | FEC_MMFR_OP_WRITE | FEC_MMFR_PA(mii_id) | FEC_MMFR_RA(regnum) | FEC_MMFR_TA | FEC_MMFR_DATA(value), fep->hwp + FEC_MII_DATA); + ptp_read_system_postts(bus->ptp_sts); /* wait for end of transfer */ time_left = wait_for_completion_timeout(&fep->mdio_done, @@ -1956,7 +1958,7 @@ static int fec_enet_mii_init(struct platform_device *pdev) struct fec_enet_private *fep = netdev_priv(ndev); struct device_node *node; int err = -ENXIO; - u32 mii_speed, holdtime; + u32 mii_speed, mii_period, holdtime; /* * The i.MX28 dual fec interfaces are not equal. @@ -1993,6 +1995,7 @@ static int fec_enet_mii_init(struct platform_device *pdev) * document. */ mii_speed = DIV_ROUND_UP(clk_get_rate(fep->clk_ipg), 5000000); + mii_period = div_u64((u64)mii_speed * 2 * NSEC_PER_SEC, clk_get_rate(fep->clk_ipg)); if (fep->quirks & FEC_QUIRK_ENET_MAC) mii_speed--; if (mii_speed > 63) { @@ -2034,6 +2037,8 @@ static int fec_enet_mii_init(struct platform_device *pdev) pdev->name, fep->dev_id + 1); fep->mii_bus->priv = fep; fep->mii_bus->parent = &pdev->dev; + fep->mii_bus->flags = MII_BUS_F_PTP_STS_SUPPORTED; + fep->mii_bus->ptp_sts_offset = 32 * mii_period; node = of_get_child_by_name(pdev->dev.of_node, "mdio"); err = of_mdiobus_register(fep->mii_bus, node);