From patchwork Thu Apr 18 05:24:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mateusz Polchlopek X-Patchwork-Id: 1924821 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=osuosl.org header.i=@osuosl.org header.a=rsa-sha256 header.s=default header.b=Ae3iug8w; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=osuosl.org (client-ip=2605:bc80:3010::138; helo=smtp1.osuosl.org; envelope-from=intel-wired-lan-bounces@osuosl.org; receiver=patchwork.ozlabs.org) Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VKmgy48ghz1yZ2 for ; Thu, 18 Apr 2024 15:35:10 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 36E9281F40; Thu, 18 Apr 2024 05:35:08 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id ul1LiC0Js_6L; Thu, 18 Apr 2024 05:35:05 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=140.211.166.34; helo=ash.osuosl.org; envelope-from=intel-wired-lan-bounces@osuosl.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org EA81A81F34 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osuosl.org; s=default; t=1713418505; bh=mUV3aIVf3RfXcPswKJAzsi3ulxjFngcIV4CbcyhFEhM=; h=From:To:Date:In-Reply-To:References:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: Cc:From; b=Ae3iug8wVhedYvEJU1tqP598W94p80A3TIPSU3X2193Vk8dz3pyMZHhLRYnCg561T xIIb7XFW23QMEu0W+fM85047qgvFPXR1Dia9HEO5HJlMndifXxNmcFjz5yF9dJWbR7 3/Irf5kaTyEnXwiCK4Gf/PZX1jvmAY0pM8cwek5jsVu8c4L2XmzhbbTz01o8jcFtUT dT9TU04mtG7VHGMHygsyHQzpAnTVfubsA/S1cdHXZLQ7MfXkszOs1hsZt9Vqxf2bK8 SQM4y+39oVcnCTRZnfGjZH6v9XP2FXmjtA+ofZXhXxhoIFdhxbL/30dNtKuJw/506X GavZhTpe4IORg== Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by smtp1.osuosl.org (Postfix) with ESMTP id EA81A81F34; Thu, 18 Apr 2024 05:35:04 +0000 (UTC) X-Original-To: intel-wired-lan@lists.osuosl.org Delivered-To: intel-wired-lan@lists.osuosl.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by ash.osuosl.org (Postfix) with ESMTP id 8E0531BF3A7 for ; Thu, 18 Apr 2024 05:34:55 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 78B7B40153 for ; Thu, 18 Apr 2024 05:34:54 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id cMqRX5d_nq1P for ; Thu, 18 Apr 2024 05:34:53 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=198.175.65.19; helo=mgamail.intel.com; envelope-from=mateusz.polchlopek@intel.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp2.osuosl.org 5E1F84043A DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 5E1F84043A Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) by smtp2.osuosl.org (Postfix) with ESMTPS id 5E1F84043A for ; Thu, 18 Apr 2024 05:34:53 +0000 (UTC) X-CSE-ConnectionGUID: h5HDtNQUSPS5TvuqndHTNA== X-CSE-MsgGUID: JX70uiLxRtizro2bC18wlQ== X-IronPort-AV: E=McAfee;i="6600,9927,11047"; a="8814688" X-IronPort-AV: E=Sophos;i="6.07,211,1708416000"; d="scan'208";a="8814688" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Apr 2024 22:34:52 -0700 X-CSE-ConnectionGUID: +83zJgwqSeaVJtdanHQHrQ== X-CSE-MsgGUID: Wo+x6Hi4RRmz9SQvJz8BnA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,211,1708416000"; d="scan'208";a="22947408" Received: from irvmail002.ir.intel.com ([10.43.11.120]) by fmviesa009.fm.intel.com with ESMTP; 17 Apr 2024 22:34:51 -0700 Received: from fedora.igk.intel.com (Metan_eth.igk.intel.com [10.123.220.124]) by irvmail002.ir.intel.com (Postfix) with ESMTP id D0B7D28763; Thu, 18 Apr 2024 06:34:49 +0100 (IST) From: Mateusz Polchlopek To: intel-wired-lan@lists.osuosl.org Date: Thu, 18 Apr 2024 01:24:59 -0400 Message-Id: <20240418052500.50678-12-mateusz.polchlopek@intel.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20240418052500.50678-1-mateusz.polchlopek@intel.com> References: <20240418052500.50678-1-mateusz.polchlopek@intel.com> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1713418493; x=1744954493; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=A2Qp+nWJp1beCDvx9sjfK6YfY3+PtCLzZg0f/06B7TM=; b=ESQtLfGyCZAjCEHoklcuXGDtlraxi6rkqkxlaRypcKkMdo/LTEW94f0y rIV9RIp+18umKz/xAXT+2m9xX1Ek9yULnU+jgWJ1TmbCDqXgFgQbwnUw6 E8HwsqDe9yHFPIUCSEHZ3uuQDI44O6SVPr0bCxb6xRB2gphLUWQ343jcp WQmo3Umiql1gCagA7WmMfln717Jr6nQL5ZtbTAn6cvps0o2aBP1qNDIJB bXSP5RPgt6jhpzUrBwiCkN7uyQAr5cZLu53mNsLsJWiyv+ci9gnmYIuL+ LEJxjTZQ4PZxSGgqJvN+S0cC0+PSXN1ht29F/u7IZ3vMDPcXfw1Lq8bpe A==; X-Mailman-Original-Authentication-Results: smtp2.osuosl.org; dmarc=pass (p=none dis=none) header.from=intel.com X-Mailman-Original-Authentication-Results: smtp2.osuosl.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=ESQtLfGy Subject: [Intel-wired-lan] [PATCH iwl-next v5 11/12] iavf: handle SIOCSHWTSTAMP and SIOCGHWTSTAMP X-BeenThere: intel-wired-lan@osuosl.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Wired Ethernet Linux Kernel Driver Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Wojciech Drewek , netdev@vger.kernel.org, anthony.l.nguyen@intel.com, horms@kernel.org, Mateusz Polchlopek , Jacob Keller Errors-To: intel-wired-lan-bounces@osuosl.org Sender: "Intel-wired-lan" From: Jacob Keller Add handlers for the SIOCSHWTSTAMP and SIOCGHWTSTAMP ioctls which allow userspace to request timestamp enablement for the device. This support allows standard Linux applications to request the timestamping desired. As with other devices that support timestamping all packets, the driver will upgrade any request for timestamping of a specific type of packet to HWTSTAMP_FILTER_ALL. The current configuration is stored, so that it can be retrieved by SIOCGHWTSTAMP. The Tx timestamps are not implemented yet so calling SIOCSHWTSTAMP for Tx path will end with EOPNOTSUPP error code. Reviewed-by: Wojciech Drewek Signed-off-by: Jacob Keller Co-developed-by: Mateusz Polchlopek Signed-off-by: Mateusz Polchlopek Reviewed-by: Rahul Rameshbabu --- drivers/net/ethernet/intel/iavf/iavf_main.c | 28 ++++ drivers/net/ethernet/intel/iavf/iavf_ptp.c | 141 ++++++++++++++++++++ drivers/net/ethernet/intel/iavf/iavf_ptp.h | 3 + drivers/net/ethernet/intel/iavf/iavf_txrx.h | 1 + 4 files changed, 173 insertions(+) diff --git a/drivers/net/ethernet/intel/iavf/iavf_main.c b/drivers/net/ethernet/intel/iavf/iavf_main.c index b5152ad870a4..a75c5fbad13c 100644 --- a/drivers/net/ethernet/intel/iavf/iavf_main.c +++ b/drivers/net/ethernet/intel/iavf/iavf_main.c @@ -4925,6 +4925,33 @@ static netdev_features_t iavf_fix_features(struct net_device *netdev, return iavf_fix_strip_features(adapter, features); } +/** + * iavf_do_ioctl - Handle network device specific ioctls + * @netdev: network interface device structure + * @ifr: interface request data + * @cmd: ioctl command + * + * Callback to handle the networking device specific ioctls. Used to handle + * the SIOCGHWTSTAMP and SIOCSHWTSTAMP ioctl requests that configure Tx and Rx + * timstamping support. + * + * Return: call to functions iavf_ptp_get_ts_config/iavf_ptp_set_ts_config or + * -EOPNOTSUPP if wrong ioctl command passed + */ +static int iavf_do_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) +{ + struct iavf_adapter *adapter = netdev_priv(netdev); + + switch (cmd) { + case SIOCGHWTSTAMP: + return iavf_ptp_get_ts_config(adapter, ifr); + case SIOCSHWTSTAMP: + return iavf_ptp_set_ts_config(adapter, ifr); + default: + return -EOPNOTSUPP; + } +} + static const struct net_device_ops iavf_netdev_ops = { .ndo_open = iavf_open, .ndo_stop = iavf_close, @@ -4940,6 +4967,7 @@ static const struct net_device_ops iavf_netdev_ops = { .ndo_fix_features = iavf_fix_features, .ndo_set_features = iavf_set_features, .ndo_setup_tc = iavf_setup_tc, + .ndo_eth_ioctl = iavf_do_ioctl, }; /** diff --git a/drivers/net/ethernet/intel/iavf/iavf_ptp.c b/drivers/net/ethernet/intel/iavf/iavf_ptp.c index 8f6b1a8df5df..4ae80eac8236 100644 --- a/drivers/net/ethernet/intel/iavf/iavf_ptp.c +++ b/drivers/net/ethernet/intel/iavf/iavf_ptp.c @@ -3,6 +3,141 @@ #include "iavf.h" +/** + * iavf_ptp_disable_rx_tstamp - Disable timestamping in Rx rings + * @adapter: private adapter structure + * + * Disable timestamp reporting for all Rx rings. + */ +static void iavf_ptp_disable_rx_tstamp(struct iavf_adapter *adapter) +{ + unsigned int i; + + for (i = 0; i < adapter->num_active_queues; i++) + adapter->rx_rings[i].flags &= ~IAVF_TXRX_FLAGS_HW_TSTAMP; +} + +/** + * iavf_ptp_enable_rx_tstamp - Enable timestamping in Rx rings + * @adapter: private adapter structure + * + * Enable timestamp reporting for all Rx rings. + */ +static void iavf_ptp_enable_rx_tstamp(struct iavf_adapter *adapter) +{ + unsigned int i; + + for (i = 0; i < adapter->num_active_queues; i++) + adapter->rx_rings[i].flags |= IAVF_TXRX_FLAGS_HW_TSTAMP; +} + +/** + * iavf_ptp_set_timestamp_mode - Set device timestamping mode + * @adapter: private adapter structure + * @config: timestamping configuration request + * + * Set the timestamping mode requested from the SIOCSHWTSTAMP ioctl. + * + * Note: this function always translates Rx timestamp requests for any packet + * category into HWTSTAMP_FILTER_ALL. + * + * Return: 0 if success, error code otherwise + */ +static int iavf_ptp_set_timestamp_mode(struct iavf_adapter *adapter, + struct hwtstamp_config *config) +{ + /* Reserved for future extensions. */ + if (config->flags) + return -EINVAL; + + switch (config->tx_type) { + case HWTSTAMP_TX_OFF: + break; + case HWTSTAMP_TX_ON: + return -EOPNOTSUPP; + default: + return -ERANGE; + } + + switch (config->rx_filter) { + case HWTSTAMP_FILTER_NONE: + iavf_ptp_disable_rx_tstamp(adapter); + break; + case HWTSTAMP_FILTER_PTP_V1_L4_EVENT: + case HWTSTAMP_FILTER_PTP_V1_L4_SYNC: + case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ: + case HWTSTAMP_FILTER_PTP_V2_EVENT: + case HWTSTAMP_FILTER_PTP_V2_L2_EVENT: + case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: + case HWTSTAMP_FILTER_PTP_V2_SYNC: + case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: + case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: + case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: + case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: + case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: + case HWTSTAMP_FILTER_NTP_ALL: + case HWTSTAMP_FILTER_ALL: + if (!(iavf_ptp_cap_supported(adapter, + VIRTCHNL_1588_PTP_CAP_RX_TSTAMP))) + return -EOPNOTSUPP; + config->rx_filter = HWTSTAMP_FILTER_ALL; + iavf_ptp_enable_rx_tstamp(adapter); + break; + default: + return -ERANGE; + } + + return 0; +} + +/** + * iavf_ptp_get_ts_config - Get timestamping configuration for SIOCGHWTSTAMP + * @adapter: private adapter structure + * @ifr: the ioctl request structure + * + * Copy the current hardware timestamping configuration back to userspace. + * Called in response to the SIOCGHWTSTAMP ioctl that queries a device's + * current timestamp settings. + * + * Return: 0 if success, -EFAULT otherwise + */ +int iavf_ptp_get_ts_config(struct iavf_adapter *adapter, struct ifreq *ifr) +{ + struct hwtstamp_config *config = &adapter->ptp.hwtstamp_config; + + return copy_to_user(ifr->ifr_data, config, + sizeof(*config)) ? -EFAULT : 0; +} + +/** + * iavf_ptp_set_ts_config - Set timestamping configuration from SIOCSHWTSTAMP + * @adapter: private adapter structure + * @ifr: the ioctl request structure + * + * Program the requested timestamping configuration from SIOCSHWTSTAMP ioctl + * to the device. + * + * Return: 0 if success, -EFAULT otherwise + */ +int iavf_ptp_set_ts_config(struct iavf_adapter *adapter, struct ifreq *ifr) +{ + struct hwtstamp_config config; + int err; + + if (copy_from_user(&config, ifr->ifr_data, sizeof(config))) + return -EFAULT; + + err = iavf_ptp_set_timestamp_mode(adapter, &config); + if (err) + return err; + + /* Save successful settings for future reference */ + adapter->ptp.hwtstamp_config = config; + + return copy_to_user(ifr->ifr_data, &config, + sizeof(config)) ? -EFAULT : 0; +} + /** * clock_to_adapter - Convert clock info pointer to adapter pointer * @ptp_info: PTP info structure @@ -335,4 +470,10 @@ void iavf_ptp_process_caps(struct iavf_adapter *adapter) else if (!adapter->ptp.initialized && iavf_ptp_cap_supported(adapter, VIRTCHNL_1588_PTP_CAP_READ_PHC)) iavf_ptp_init(adapter); + + /* Check if the device lost access to Rx timestamp incoming packets */ + if (!iavf_ptp_cap_supported(adapter, VIRTCHNL_1588_PTP_CAP_RX_TSTAMP)) { + adapter->ptp.hwtstamp_config.rx_filter = HWTSTAMP_FILTER_NONE; + iavf_ptp_disable_rx_tstamp(adapter); + } } diff --git a/drivers/net/ethernet/intel/iavf/iavf_ptp.h b/drivers/net/ethernet/intel/iavf/iavf_ptp.h index 7a25647980f3..337bf184a7ea 100644 --- a/drivers/net/ethernet/intel/iavf/iavf_ptp.h +++ b/drivers/net/ethernet/intel/iavf/iavf_ptp.h @@ -21,6 +21,7 @@ struct iavf_ptp { struct list_head aq_cmds; /* Lock protecting access to the AQ command list */ spinlock_t aq_cmd_lock; + struct hwtstamp_config hwtstamp_config; u64 cached_phc_time; unsigned long cached_phc_updated; bool initialized; @@ -35,5 +36,7 @@ void iavf_ptp_process_caps(struct iavf_adapter *adapter); bool iavf_ptp_cap_supported(struct iavf_adapter *adapter, u32 cap); void iavf_virtchnl_send_ptp_cmd(struct iavf_adapter *adapter); long iavf_ptp_do_aux_work(struct ptp_clock_info *ptp); +int iavf_ptp_get_ts_config(struct iavf_adapter *adapter, struct ifreq *ifr); +int iavf_ptp_set_ts_config(struct iavf_adapter *adapter, struct ifreq *ifr); #endif /* _IAVF_PTP_H_ */ diff --git a/drivers/net/ethernet/intel/iavf/iavf_txrx.h b/drivers/net/ethernet/intel/iavf/iavf_txrx.h index 54d858303839..f77407030566 100644 --- a/drivers/net/ethernet/intel/iavf/iavf_txrx.h +++ b/drivers/net/ethernet/intel/iavf/iavf_txrx.h @@ -358,6 +358,7 @@ struct iavf_ring { #define IAVF_TXRX_FLAGS_VLAN_TAG_LOC_L2TAG1 BIT(3) #define IAVF_TXR_FLAGS_VLAN_TAG_LOC_L2TAG2 BIT(4) #define IAVF_RXR_FLAGS_VLAN_TAG_LOC_L2TAG2_2 BIT(5) +#define IAVF_TXRX_FLAGS_HW_TSTAMP BIT(6) /* stats structs */ struct iavf_queue_stats stats;