Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp14583266rwb; Mon, 28 Nov 2022 02:51:05 -0800 (PST) X-Google-Smtp-Source: AA0mqf4MGDMET4DefKli3kdvCzE5YbhDOVSBfihICIdH2EF94D3rvpy1ajYTPdz/k4aAHe7P2GFr X-Received: by 2002:a17:902:8601:b0:189:7372:144c with SMTP id f1-20020a170902860100b001897372144cmr11686027plo.106.1669632665565; Mon, 28 Nov 2022 02:51:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669632665; cv=none; d=google.com; s=arc-20160816; b=0eKdXRVZ0f65wG8uKBHUQYbnMEVXJAYq4v34aD5qmbaUL3YQJPHXm+/tQui9ZHT5/C HfK7Gze78nwVItnQ+IjKne2QO2syS95iN6g/Kwg6g8pQqfEi3IpiwU5rHl3qPQ4/qEPY xlCBKkzASvg/zkxl2oc/2gwnz5seN5DbDCAo1jbTDb7Cj8AAJ1MShKAzQE9I5YSYeQYi xsVbR/KhS923RpZQFCge5uqVKQ9/TS/9wQdNT6W4e8BbUtKaygLPbggWczwRCq08BnIl OYxxuiulEhuF+I2KZ+guVBoirDxHtyd8HX7pvxEsivDg7WaEHd6gs4rB0fPQtz7XIidB gn7g== 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:cc:to:from :dkim-signature; bh=tkhgsKquTio/7FNNoIdwTp6LvO9zbuRzMBuEpebhqlU=; b=kllqzz6LNBUzFka1wv+ZbOwsP552KqhpbIrkA44alaw5hjnw/SpY2TBd9JCPP/pdhi f2egfn/apj0r1u23zSbwXkCjF8JEVXHGixCJPKX95XjMNb1+Ns79vHnXQX96cxSEb0gP Pd49gDnN+fthJZrL8raUlIyvaJflAIMklixU4vA4kBYxfB7Q1O6+r7PWJxeytZxFWgKd 6seaEwq0dRttno5EW6sT+7vS7H/Kae1i0lTW7joHOsGVLkcEWDtM/eqA1aFaQRdiluud WrQ2lez7edg5D/pIIpMnUPpvyS7k/KmU0/WvgblB5nfFAts9V7bBkTxJZC4y7coXOmZF nMoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=g4rI7Gse; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l131-20020a633e89000000b00477cc8b7275si12099556pga.444.2022.11.28.02.50.55; Mon, 28 Nov 2022 02:51:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=g4rI7Gse; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230325AbiK1Kdj (ORCPT + 85 others); Mon, 28 Nov 2022 05:33:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230314AbiK1KdT (ORCPT ); Mon, 28 Nov 2022 05:33:19 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6AE99165BF; Mon, 28 Nov 2022 02:33:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1669631595; x=1701167595; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0jWyCeJ8WBlrBWXB2TOdnjMx3E3TGNkmMzFIqVKoNmA=; b=g4rI7Gsedncb9kPuFjYwTPcYFzBntTZTOy4jvUdxT3FcoiyEkyMyfIHv z6mk6ofMpU9jw+EqelQKkfx63c/xepaGCO208LvDqaAHxRi28zU45jceX pwPamR8a5Eu1n638tRnCzx338OannrKUv6PR5c9Ncb9x73j833GGNX9wb NrvN4oIw2zNH2r+r4jK3+HUE6TGwwdASA/KCfi1+7YkGrC7IbxGuMzDAu dvp90FeoWia7UOhhPJzhEXS1qb6/Y10wHXCgF54Bymm2gma29J2NCmr0w uKYi8SgV7539Jio3Hju4+ufBuOVf/eX7uo9MWpNibQ+YNJBXEEFLVlP8P g==; X-IronPort-AV: E=Sophos;i="5.96,200,1665471600"; d="scan'208";a="125375559" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa6.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 28 Nov 2022 03:33:14 -0700 Received: from chn-vm-ex03.mchp-main.com (10.10.85.151) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.12; Mon, 28 Nov 2022 03:33:13 -0700 Received: from CHE-LT-I17769U.microchip.com (10.10.115.15) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server id 15.1.2507.12 via Frontend Transport; Mon, 28 Nov 2022 03:33:07 -0700 From: Arun Ramadoss To: , CC: , , , , , , , , , , , , , Subject: [Patch net-next v1 02/12] net: dsa: microchip: ptp: Initial hardware time stamping support Date: Mon, 28 Nov 2022 16:02:17 +0530 Message-ID: <20221128103227.23171-3-arun.ramadoss@microchip.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221128103227.23171-1-arun.ramadoss@microchip.com> References: <20221128103227.23171-1-arun.ramadoss@microchip.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS 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 From: Christian Eggers This patch adds the routine for get_ts_info, hwstamp_get, set. This enables the PTP support towards userspace applications such as linuxptp. Tx timestamping can be enabled per port and Rx timestamping enabled globally. Signed-off-by: Christian Eggers Co-developed-by: Arun Ramadoss Signed-off-by: Arun Ramadoss --- RFC v2 -> Patch v1 - moved tagger set and get function to separate patch - Removed unnecessary comments --- drivers/net/dsa/microchip/ksz_common.c | 2 + drivers/net/dsa/microchip/ksz_common.h | 4 ++ drivers/net/dsa/microchip/ksz_ptp.c | 77 +++++++++++++++++++++++++- drivers/net/dsa/microchip/ksz_ptp.h | 14 +++++ 4 files changed, 95 insertions(+), 2 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index 2d09cd141db6..7b85b258270c 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -2873,6 +2873,8 @@ static const struct dsa_switch_ops ksz_switch_ops = { .port_change_mtu = ksz_change_mtu, .port_max_mtu = ksz_max_mtu, .get_ts_info = ksz_get_ts_info, + .port_hwtstamp_get = ksz_hwtstamp_get, + .port_hwtstamp_set = ksz_hwtstamp_set, }; struct ksz_device *ksz_switch_alloc(struct device *base, void *priv) diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h index 5a6bfd42c6f9..cd20f39a565f 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h @@ -103,6 +103,10 @@ struct ksz_port { struct ksz_device *ksz_dev; struct ksz_irq pirq; u8 num; +#if IS_ENABLED(CONFIG_NET_DSA_MICROCHIP_KSZ_PTP) + u8 hwts_tx_en; + bool hwts_rx_en; +#endif }; struct ksz_device { diff --git a/drivers/net/dsa/microchip/ksz_ptp.c b/drivers/net/dsa/microchip/ksz_ptp.c index c737635ca266..a41418c6adf6 100644 --- a/drivers/net/dsa/microchip/ksz_ptp.c +++ b/drivers/net/dsa/microchip/ksz_ptp.c @@ -36,15 +36,88 @@ int ksz_get_ts_info(struct dsa_switch *ds, int port, struct ethtool_ts_info *ts) SOF_TIMESTAMPING_RX_HARDWARE | SOF_TIMESTAMPING_RAW_HARDWARE; - ts->tx_types = BIT(HWTSTAMP_TX_OFF); + ts->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ONESTEP_P2P); - ts->rx_filters = BIT(HWTSTAMP_FILTER_NONE); + ts->rx_filters = BIT(HWTSTAMP_FILTER_NONE) | BIT(HWTSTAMP_FILTER_ALL); ts->phc_index = ptp_clock_index(ptp_data->clock); return 0; } +int ksz_hwtstamp_get(struct dsa_switch *ds, int port, struct ifreq *ifr) +{ + struct ksz_device *dev = ds->priv; + struct hwtstamp_config config; + + config.flags = 0; + + config.tx_type = dev->ports[port].hwts_tx_en; + + if (dev->ports[port].hwts_rx_en) + config.rx_filter = HWTSTAMP_FILTER_ALL; + else + config.rx_filter = HWTSTAMP_FILTER_NONE; + + return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ? + -EFAULT : 0; +} + +static int ksz_set_hwtstamp_config(struct ksz_device *dev, int port, + struct hwtstamp_config *config) +{ + struct ksz_port *prt = &dev->ports[port]; + + if (config->flags) + return -EINVAL; + + switch (config->tx_type) { + case HWTSTAMP_TX_OFF: + case HWTSTAMP_TX_ONESTEP_P2P: + prt->hwts_tx_en = config->tx_type; + break; + default: + return -ERANGE; + } + + switch (config->rx_filter) { + case HWTSTAMP_FILTER_NONE: + prt->hwts_rx_en = false; + break; + default: + prt->hwts_rx_en = true; + break; + } + + return 0; +} + +int ksz_hwtstamp_set(struct dsa_switch *ds, int port, struct ifreq *ifr) +{ + struct ksz_device *dev = ds->priv; + struct ksz_ptp_data *ptp_data; + struct hwtstamp_config config; + int ret; + + ptp_data = &dev->ptp_data; + + mutex_lock(&ptp_data->lock); + + ret = copy_from_user(&config, ifr->ifr_data, sizeof(config)); + if (ret) + goto error_return; + + ret = ksz_set_hwtstamp_config(dev, port, &config); + if (ret) + goto error_return; + + ret = copy_to_user(ifr->ifr_data, &config, sizeof(config)); + +error_return: + mutex_unlock(&ptp_data->lock); + return ret; +} + static int _ksz_ptp_gettime(struct ksz_device *dev, struct timespec64 *ts) { u32 nanoseconds; diff --git a/drivers/net/dsa/microchip/ksz_ptp.h b/drivers/net/dsa/microchip/ksz_ptp.h index ea9fa46caa01..17f455c3b2c5 100644 --- a/drivers/net/dsa/microchip/ksz_ptp.h +++ b/drivers/net/dsa/microchip/ksz_ptp.h @@ -23,6 +23,8 @@ void ksz_ptp_clock_unregister(struct dsa_switch *ds); int ksz_get_ts_info(struct dsa_switch *ds, int port, struct ethtool_ts_info *ts); +int ksz_hwtstamp_get(struct dsa_switch *ds, int port, struct ifreq *ifr); +int ksz_hwtstamp_set(struct dsa_switch *ds, int port, struct ifreq *ifr); #else @@ -40,6 +42,18 @@ static inline void ksz_ptp_clock_unregister(struct dsa_switch *ds) { } #define ksz_get_ts_info NULL +static inline int ksz_hwtstamp_get(struct dsa_switch *ds, int port, + struct ifreq *ifr) +{ + return -EOPNOTSUPP; +} + +static inline int ksz_hwtstamp_set(struct dsa_switch *ds, int port, + struct ifreq *ifr) +{ + return -EOPNOTSUPP; +} + #endif /* End of CONFIG_NET_DSA_MICROCHIP_KSZ_PTP */ #endif -- 2.36.1