From patchwork Tue Jun 4 13:13: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: 13685320 X-Patchwork-Delegate: kuba@kernel.org Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.15]) (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 EFC0314831D for ; Tue, 4 Jun 2024 13:25:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.15 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717507505; cv=none; b=H9wIyk+9lqVNK59DwAxfg2BdDk7N2SHTqxr/N9HQMCDVlEYHdaUO3GV4iJRNF9zZZUP8YD5ospJeb4inv2+rdlIHBXxY26qEHackowHW4rcvqVXi78ovqt+s3SmgFOC0TdPUz4Xd+AU0bxZc8JMspSWXf+tA6eeN/nU6p9wtz6Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717507505; c=relaxed/simple; bh=tgUTGVWWHNQVwkRmoiAZcV5wbjVpI9a/ZCJnx8CzHX8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Y6cmu8Pu18l/NKm3gnq2Nw1nyQuWI8UzPYvo8Q7ofcJYsrOtFaPfRScyAlEP1DsHvTCqyGjkHrZ2ABFL1fteRRSq8Nx3JZ5+1n7EWW9zbzSmKS2AgCMltPRwtrHPj1qxbPLy3NIYWvxIzkF8irXU7j299hwmPGvsdpbizYIgk4U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=AeZ8VPGi; arc=none smtp.client-ip=192.198.163.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="AeZ8VPGi" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1717507504; x=1749043504; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tgUTGVWWHNQVwkRmoiAZcV5wbjVpI9a/ZCJnx8CzHX8=; b=AeZ8VPGiY65+NrgH9qIeKnkPHisBB2HBXU3vqt/71lYbuFaolEyGrSRJ 3Dklw9tH7jNqcoDFWiTOnqUxFPO/BP1oKqnxGYmSl6cu8jE/3SfBaU0ld l/IrYeTexRPTM/sgCAb968rF0xeviwtiuZyAZk6e1CDIAdpp1X9VFzvcx 4duOO74PZa/lr0j65eN/Fe+vsPafxoX7EH0IBWkKo6V5iwG38Uw4Fq7eS 7l5VumBVeTaoLkHFqAgCLlzj9RgB4vrU1I4K+6Ye+4VAMn0m1xUYpulUi exTvw1WQ2gkGpkOSx+I8v3Ru3vrOLw88DoHCvx1vt1Pf7pwbxaaiPh5bv A==; X-CSE-ConnectionGUID: ECM6cEUhSmW8NJBbzpc0tA== X-CSE-MsgGUID: mGzASYniTeGnO93f7d3qig== X-IronPort-AV: E=McAfee;i="6600,9927,11093"; a="14245403" X-IronPort-AV: E=Sophos;i="6.08,213,1712646000"; d="scan'208";a="14245403" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa109.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Jun 2024 06:25:03 -0700 X-CSE-ConnectionGUID: 2ReG5/7RSxSZbgkfv4tIbg== X-CSE-MsgGUID: CXD495YOT++vtat7BUQCQQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,213,1712646000"; d="scan'208";a="37109795" Received: from irvmail002.ir.intel.com ([10.43.11.120]) by fmviesa007.fm.intel.com with ESMTP; 04 Jun 2024 06:25:01 -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 A21B712425; Tue, 4 Jun 2024 14:24:54 +0100 (IST) From: Mateusz Polchlopek To: intel-wired-lan@lists.osuosl.org Cc: netdev@vger.kernel.org, Jacob Keller , Wojciech Drewek , Rahul Rameshbabu , Mateusz Polchlopek Subject: [Intel-wired-lan] [PATCH iwl-next v7 11/12] iavf: handle set and get timestamps ops Date: Tue, 4 Jun 2024 09:13:59 -0400 Message-Id: <20240604131400.13655-12-mateusz.polchlopek@intel.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20240604131400.13655-1-mateusz.polchlopek@intel.com> References: <20240604131400.13655-1-mateusz.polchlopek@intel.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jacob Keller Add handlers for the .ndo_hwtstamp_get and .ndo_hwtstamp_set ops 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 calling .ndo_hwtstamp_get The Tx timestamps are not implemented yet so calling set ops for Tx path will end with EOPNOTSUPP error code. Signed-off-by: Jacob Keller Reviewed-by: Wojciech Drewek Reviewed-by: Rahul Rameshbabu Co-developed-by: Mateusz Polchlopek Signed-off-by: Mateusz Polchlopek Reviewed-by: Simon Horman --- drivers/net/ethernet/intel/iavf/iavf_main.c | 19 +++ drivers/net/ethernet/intel/iavf/iavf_ptp.c | 136 ++++++++++++++++++++ drivers/net/ethernet/intel/iavf/iavf_ptp.h | 6 + drivers/net/ethernet/intel/iavf/iavf_txrx.h | 1 + 4 files changed, 162 insertions(+) diff --git a/drivers/net/ethernet/intel/iavf/iavf_main.c b/drivers/net/ethernet/intel/iavf/iavf_main.c index f613bffabf85..5c4c3032c30a 100644 --- a/drivers/net/ethernet/intel/iavf/iavf_main.c +++ b/drivers/net/ethernet/intel/iavf/iavf_main.c @@ -5068,6 +5068,23 @@ static netdev_features_t iavf_fix_features(struct net_device *netdev, return iavf_fix_strip_features(adapter, features); } +static int iavf_hwstamp_get(struct net_device *netdev, + struct kernel_hwtstamp_config *config) +{ + struct iavf_adapter *adapter = netdev_priv(netdev); + + return iavf_ptp_get_ts_config(adapter, config); +} + +static int iavf_hwstamp_set(struct net_device *netdev, + struct kernel_hwtstamp_config *config, + struct netlink_ext_ack *extack) +{ + struct iavf_adapter *adapter = netdev_priv(netdev); + + return iavf_ptp_set_ts_config(adapter, config, extack); +} + static const struct net_device_ops iavf_netdev_ops = { .ndo_open = iavf_open, .ndo_stop = iavf_close, @@ -5083,6 +5100,8 @@ 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_hwtstamp_get = iavf_hwstamp_get, + .ndo_hwtstamp_set = iavf_hwstamp_set }; /** diff --git a/drivers/net/ethernet/intel/iavf/iavf_ptp.c b/drivers/net/ethernet/intel/iavf/iavf_ptp.c index 69e4948a9057..1a0a7a038ae1 100644 --- a/drivers/net/ethernet/intel/iavf/iavf_ptp.c +++ b/drivers/net/ethernet/intel/iavf/iavf_ptp.c @@ -3,6 +3,136 @@ #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: pointer to kernel_hwtstamp_config + * + * Set the timestamping mode requested from the userspace. + * + * Note: this function always translates Rx timestamp requests for any packet + * category into HWTSTAMP_FILTER_ALL. + * + * Return: zero. + */ +static int iavf_ptp_set_timestamp_mode(struct iavf_adapter *adapter, + struct kernel_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 + * @adapter: private adapter structure + * @config: pointer to kernel_hwtstamp_config + * + * Return the current hardware timestamping configuration back to userspace. + * + * Return: zero. + */ +int iavf_ptp_get_ts_config(struct iavf_adapter *adapter, + struct kernel_hwtstamp_config *config) +{ + *config = adapter->ptp.hwtstamp_config; + + return 0; +} + +/** + * iavf_ptp_set_ts_config - Set timestamping configuration + * @adapter: private adapter structure + * @config: pointer to kernel_hwtstamp_config structure + * @extack: pointer to netlink_ext_ack structure + * + * Program the requested timestamping configuration to the device. + * + * Return: zero. + */ +int iavf_ptp_set_ts_config(struct iavf_adapter *adapter, + struct kernel_hwtstamp_config *config, + struct netlink_ext_ack *extack) +{ + int err; + + err = iavf_ptp_set_timestamp_mode(adapter, config); + if (err) + return err; + + /* Save successful settings for future reference */ + adapter->ptp.hwtstamp_config = *config; + + return 0; +} + /** * clock_to_adapter - Convert clock info pointer to adapter pointer * @ptp_info: PTP info structure @@ -335,4 +465,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..fd211b1c4025 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 kernel_hwtstamp_config hwtstamp_config; u64 cached_phc_time; unsigned long cached_phc_updated; bool initialized; @@ -35,5 +36,10 @@ 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 kernel_hwtstamp_config *config); +int iavf_ptp_set_ts_config(struct iavf_adapter *adapter, + struct kernel_hwtstamp_config *config, + struct netlink_ext_ack *extack); #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 3add31924d75..0379f94acb56 100644 --- a/drivers/net/ethernet/intel/iavf/iavf_txrx.h +++ b/drivers/net/ethernet/intel/iavf/iavf_txrx.h @@ -262,6 +262,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;