From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3859843DEE; Wed, 3 Apr 2024 18:09:38 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0B2374025C; Wed, 3 Apr 2024 18:09:38 +0200 (CEST) Received: from mail-pl1-f228.google.com (mail-pl1-f228.google.com [209.85.214.228]) by mails.dpdk.org (Postfix) with ESMTP id 283394025C for ; Wed, 3 Apr 2024 15:40:31 +0200 (CEST) Received: by mail-pl1-f228.google.com with SMTP id d9443c01a7336-1e252f2bf23so27179465ad.2 for ; Wed, 03 Apr 2024 06:40:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712151630; x=1712756430; h=content-transfer-encoding:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7ZBh5weVpChsH75Wef9UINqrt1A9b85T/5MeNtS11UA=; b=JW8RZz4Ih1peYAw3nXUnqw/RMrWT3pHHmGNAYsrZhykFvOkg0ixElCbzkZT9uN3Pet wBQ7rAT9AnYrNJhPTmL7MP18EgsCQwYb0spDQpHsyCe9pV+3Utf12dgbn0mw0WncOudJ nsrH13xGHLBtu1qDRJ6WmoNhd+/670L8+1gnDRHfnZCxdLuX3U43XC1WYaq50gga2U8H OkKE/iL4pmg/5cL+aPema0wKwj6e8CTwtQgShndKUQYYYm50lLTP6HV9FvEbuwmtY00e dZdnv0VCot2azO4smuJKXjZlRADXjFVXud3JrrAXILKCYi2Gj5alBr53PLVUDjHIMDcW +J3w== X-Gm-Message-State: AOJu0Yxzh6c8NaDCeEyjj6tgpiULecItjzkhZF0IIhlatB8NJujSxNhO g4IZH9OzHBmr0U+QoU290eJBeXUm/EYJ97JmCXDIuJkO4B4em5N7Kv07P/+nd4HiO8VM4isHg8/ SueC31heTprbvT5+NW52I966h34FCzw== X-Google-Smtp-Source: AGHT+IFiN7I6CVzIA5Qqg6FUQZNVy0imYyF6zjA6Wga6hf3Qg1s+BykmKH53kiXSqy6J7HEmw8ld/HKPsb5p X-Received: by 2002:a17:902:ecc8:b0:1e0:342b:af6f with SMTP id a8-20020a170902ecc800b001e0342baf6fmr2539666plh.16.1712151630283; Wed, 03 Apr 2024 06:40:30 -0700 (PDT) Received: from smtp.aristanetworks.com ([74.123.28.25]) by smtp-relay.gmail.com with ESMTPS id w6-20020a170902904600b001d987771274sm310524plz.81.2024.04.03.06.40.29 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Apr 2024 06:40:30 -0700 (PDT) X-Relaying-Domain: arista.com Received: from mpazdan-autoneg-dpdk-0.sjc.aristanetworks.com (mpazdan-autoneg-dpdk-0-us184.sjc.aristanetworks.com [10.243.132.215]) by smtp.aristanetworks.com (Postfix) with ESMTP id 25197402016; Wed, 3 Apr 2024 06:40:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=Arista-A; t=1712151629; bh=7ZBh5weVpChsH75Wef9UINqrt1A9b85T/5MeNtS11UA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZvH25/fRtZ5ATRPgPjjfjv1+DsABZ6VPTzpD0pjsJYpiVvM2twLt/aVcf0emw/sQF BNuOZMLhGkV3KFE7G3hvrIH/3xNGaYy626ZgUflWALCeeo0P1YgtMY5b0P7bJG2e+z OImgI4MIt4t9I27Hx/1g270gmSEOEnrZEOxJOhX22uXJUsu+8v0yai8Zs1BW3slSc8 7pHR26SshyGhHepw1nokrvypYIpNpNzZRqLnQ5xbr3xomtbV3O3Ogk4tMrTUQ+9cNB ixhsPTlC1P6gC/mMpawPuKhVnE0uQk+An7FhM11NV0nOJZeIgF8jgeDFyeScCAa+Cy Utf87io4V/IwQ== X-SMTP-Authentication: Allow-List-permitted X-SMTP-Authentication: Allow-List-permitted From: Marek Pazdan To: Thomas Monjalon , Ferruh Yigit , Andrew Rybchenko Cc: dev@dpdk.org, Marek Pazdan Subject: [PATCH] lib: add get/set link settings interface Date: Wed, 3 Apr 2024 06:40:24 -0700 Message-ID: <20240403134026.7037-1-mpazdan@arista.com> In-Reply-To: <20240326235909.25276-1-mpazdan@arista.com> References: <20240326235909.25276-1-mpazdan@arista.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Wed, 03 Apr 2024 18:09:36 +0200 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org There are link settings parameters available from PMD drivers level which are currently not exposed to the user via consistent interface. When interface is available for system level those information can be acquired with 'ethtool DEVNAME' (ioctl: ETHTOOL_SLINKSETTINGS/ ETHTOOL_GLINKSETTINGS). There are use cases where physical interface is passthrough to dpdk driver and is not available from system level. Information provided by ioctl carries information useful for link auto negotiation settings among others. Signed-off-by: Marek Pazdan --- .mailmap | 1 + lib/ethdev/ethdev_driver.h | 33 ++++++ lib/ethdev/rte_ethdev.c | 26 +++++ lib/ethdev/rte_ethdev.h | 215 +++++++++++++++++++++++++++++++++++-- lib/ethdev/version.map | 3 + 5 files changed, 270 insertions(+), 8 deletions(-) diff --git a/.mailmap b/.mailmap index 3843868716..145ce726ba 100644 --- a/.mailmap +++ b/.mailmap @@ -885,6 +885,7 @@ Marcin Wojtas Marcin Zapolski Marco Varlese Marc Sune +Marek Pazdan Maria Lingemark Mario Carrillo Mário Kuka diff --git a/lib/ethdev/ethdev_driver.h b/lib/ethdev/ethdev_driver.h index 0dbf2dd6a2..ee8f786b99 100644 --- a/lib/ethdev/ethdev_driver.h +++ b/lib/ethdev/ethdev_driver.h @@ -1119,6 +1119,34 @@ typedef const uint32_t *(*eth_buffer_split_supported_hdr_ptypes_get_t)(struct rt */ typedef int (*eth_dev_priv_dump_t)(struct rte_eth_dev *dev, FILE *file); +/** @internal Retrieve physical link settings of a port. + * + * @param dev + * Port (ethdev) handle + * + * @param[out] settings + * Physical port link settings. + * + * @return + * Negative errno value on error, zero otherwise + */ +typedef int (*eth_get_link_settings_t)(struct rte_eth_dev *dev, + struct rte_link_settings *settings); + +/** @internal Configure physical link settings of a port. + * + * @param dev + * Port (ethdev) handle + * + * @param settings + * Physical port link settings. + * + * @return + * Negative errno value on error, zero otherwise + */ +typedef int (*eth_set_link_settings_t)(struct rte_eth_dev *dev, + const struct rte_link_settings *settings); + /** * @internal Set Rx queue available descriptors threshold. * @see rte_eth_rx_avail_thresh_set() @@ -1474,6 +1502,11 @@ struct eth_dev_ops { eth_count_aggr_ports_t count_aggr_ports; /** Map a Tx queue with an aggregated port of the DPDK port */ eth_map_aggr_tx_affinity_t map_aggr_tx_affinity; + + /** Retrieve physical link settings */ + eth_get_link_settings_t get_link_settings; + /** Configure physical link settings */ + eth_set_link_settings_t set_link_settings; }; /** diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c index f1c658f49e..d2c52921ef 100644 --- a/lib/ethdev/rte_ethdev.c +++ b/lib/ethdev/rte_ethdev.c @@ -6844,6 +6844,32 @@ rte_eth_dev_priv_dump(uint16_t port_id, FILE *file) return eth_err(port_id, (*dev->dev_ops->eth_dev_priv_dump)(dev, file)); } +int rte_eth_dev_get_link_settings(uint16_t port_id, + struct rte_link_settings *settings) +{ + struct rte_eth_dev *dev; + + RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); + dev = &rte_eth_devices[port_id]; + + if (*dev->dev_ops->get_link_settings == NULL) + return -ENOTSUP; + return eth_err(port_id, (*dev->dev_ops->get_link_settings)(dev, settings)); +} + +int rte_eth_dev_set_link_settings(uint16_t port_id, + const struct rte_link_settings *settings) +{ + struct rte_eth_dev *dev; + + RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); + dev = &rte_eth_devices[port_id]; + + if (*dev->dev_ops->set_link_settings == NULL) + return -ENOTSUP; + return eth_err(port_id, (*dev->dev_ops->set_link_settings)(dev, settings)); +} + int rte_eth_rx_descriptor_dump(uint16_t port_id, uint16_t queue_id, uint16_t offset, uint16_t num, FILE *file) diff --git a/lib/ethdev/rte_ethdev.h b/lib/ethdev/rte_ethdev.h index 147257d6a2..66aad925d0 100644 --- a/lib/ethdev/rte_ethdev.h +++ b/lib/ethdev/rte_ethdev.h @@ -335,7 +335,7 @@ struct rte_eth_stats { __extension__ struct __rte_aligned(8) rte_eth_link { /**< aligned for atomic64 read/write */ uint32_t link_speed; /**< RTE_ETH_SPEED_NUM_ */ - uint16_t link_duplex : 1; /**< RTE_ETH_LINK_[HALF/FULL]_DUPLEX */ + uint16_t link_duplex : 2; /**< RTE_ETH_LINK_[HALF/FULL/UNKNOWN]_DUPLEX */ uint16_t link_autoneg : 1; /**< RTE_ETH_LINK_[AUTONEG/FIXED] */ uint16_t link_status : 1; /**< RTE_ETH_LINK_[DOWN/UP] */ }; @@ -343,13 +343,27 @@ struct __rte_aligned(8) rte_eth_link { /**< aligned for atomic64 read/write */ /**@{@name Link negotiation * Constants used in link management. */ -#define RTE_ETH_LINK_HALF_DUPLEX 0 /**< Half-duplex connection (see link_duplex). */ -#define RTE_ETH_LINK_FULL_DUPLEX 1 /**< Full-duplex connection (see link_duplex). */ -#define RTE_ETH_LINK_DOWN 0 /**< Link is down (see link_status). */ -#define RTE_ETH_LINK_UP 1 /**< Link is up (see link_status). */ -#define RTE_ETH_LINK_FIXED 0 /**< No autonegotiation (see link_autoneg). */ -#define RTE_ETH_LINK_AUTONEG 1 /**< Autonegotiated (see link_autoneg). */ -#define RTE_ETH_LINK_MAX_STR_LEN 40 /**< Max length of default link string. */ +#define RTE_ETH_LINK_HALF_DUPLEX 0 /**< Half-duplex connection (see link_duplex). */ +#define RTE_ETH_LINK_FULL_DUPLEX 1 /**< Full-duplex connection (see link_duplex). */ +#define RTE_ETH_LINK_UNKNOWN_DUPLEX 2 /**