lib: add get/set link settings interface

Message ID 20240403134026.7037-1-mpazdan@arista.com (mailing list archive)
State Superseded
Delegated to: Ferruh Yigit
Headers
Series lib: add get/set link settings interface |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation fail Compilation issues
ci/intel-Testing success Testing PASS
ci/github-robot: build fail github build: failed
ci/intel-Functional success Functional PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-abi-testing warning Testing issues
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Functional success Functional Testing PASS

Commit Message

Marek Pazdan April 3, 2024, 1:40 p.m. UTC
  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 <mpazdan@arista.com>
---
 .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(-)
  

Comments

Tyler Retzlaff April 3, 2024, 4:49 p.m. UTC | #1
On Wed, Apr 03, 2024 at 06:40:24AM -0700, Marek Pazdan wrote:
>  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 <mpazdan@arista.com>
> ---
> 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] */
>  };

this breaks the abi. David does libabigail pick this up i wonder?
  
David Marchand April 4, 2024, 7:09 a.m. UTC | #2
Hello Tyler, Marek,

On Wed, Apr 3, 2024 at 6:49 PM Tyler Retzlaff
<roretzla@linux.microsoft.com> wrote:
>
> On Wed, Apr 03, 2024 at 06:40:24AM -0700, Marek Pazdan wrote:
> >  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 <mpazdan@arista.com>
> > ---
> > 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] */
> >  };
>
> this breaks the abi. David does libabigail pick this up i wonder?
>

Yes, the CI flagged it.

Looking at the UNH report (in patchwork):
http://mails.dpdk.org/archives/test-report/2024-April/631222.html

1 function with some indirect sub-type change:

[C] 'function int rte_eth_link_get(uint16_t, rte_eth_link*)' at
rte_ethdev.c:2972:1 has some indirect sub-type changes:
parameter 2 of type 'rte_eth_link*' has sub-type changes:
in pointed to type 'struct rte_eth_link' at rte_ethdev.h:336:1:
type size hasn't changed
2 data member changes:
'uint16_t link_autoneg' offset changed from 33 to 34 (in bits) (by +1 bits)
'uint16_t link_status' offset changed from 34 to 35 (in bits) (by +1 bits)

Error: ABI issue reported for abidiff --suppr
/home-local/jenkins-local/jenkins-agent/workspace/Generic-DPDK-Compile-ABI
at 3/dpdk/devtools/libabigail.abignore --no-added-syms --headers-dir1
reference/usr/local/include --headers-dir2
build_install/usr/local/include
reference/usr/local/lib/x86_64-linux-gnu/librte_ethdev.so.24.0
build_install/usr/local/lib/x86_64-linux-gnu/librte_ethdev.so.24.2
ABIDIFF_ABI_CHANGE, this change requires a review (abidiff flagged
this as a potential issue).


GHA would have caught it too, but the documentation generation failed
before reaching the ABI check.
http://mails.dpdk.org/archives/test-report/2024-April/631086.html
  
Tyler Retzlaff April 5, 2024, 12:55 a.m. UTC | #3
On Thu, Apr 04, 2024 at 09:09:40AM +0200, David Marchand wrote:
> Hello Tyler, Marek,
> 
> On Wed, Apr 3, 2024 at 6:49 PM Tyler Retzlaff
> <roretzla@linux.microsoft.com> wrote:
> >
> > On Wed, Apr 03, 2024 at 06:40:24AM -0700, Marek Pazdan wrote:
> > >  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 <mpazdan@arista.com>
> > > ---
> > > 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] */
> > >  };
> >
> > this breaks the abi. David does libabigail pick this up i wonder?
> >
> 
> Yes, the CI flagged it.
> 
> Looking at the UNH report (in patchwork):
> http://mails.dpdk.org/archives/test-report/2024-April/631222.html

i'm jealous we don't have libabigail on windows, so helpfull.

> 
> 1 function with some indirect sub-type change:
> 
> [C] 'function int rte_eth_link_get(uint16_t, rte_eth_link*)' at
> rte_ethdev.c:2972:1 has some indirect sub-type changes:
> parameter 2 of type 'rte_eth_link*' has sub-type changes:
> in pointed to type 'struct rte_eth_link' at rte_ethdev.h:336:1:
> type size hasn't changed
> 2 data member changes:
> 'uint16_t link_autoneg' offset changed from 33 to 34 (in bits) (by +1 bits)
> 'uint16_t link_status' offset changed from 34 to 35 (in bits) (by +1 bits)
> 
> Error: ABI issue reported for abidiff --suppr
> /home-local/jenkins-local/jenkins-agent/workspace/Generic-DPDK-Compile-ABI
> at 3/dpdk/devtools/libabigail.abignore --no-added-syms --headers-dir1
> reference/usr/local/include --headers-dir2
> build_install/usr/local/include
> reference/usr/local/lib/x86_64-linux-gnu/librte_ethdev.so.24.0
> build_install/usr/local/lib/x86_64-linux-gnu/librte_ethdev.so.24.2
> ABIDIFF_ABI_CHANGE, this change requires a review (abidiff flagged
> this as a potential issue).
> 
> 
> GHA would have caught it too, but the documentation generation failed
> before reaching the ABI check.
> http://mails.dpdk.org/archives/test-report/2024-April/631086.html
> 
> 
> -- 
> David Marchand
  
Tyler Retzlaff April 5, 2024, 12:56 a.m. UTC | #4
On Thu, Apr 04, 2024 at 05:55:18PM -0700, Tyler Retzlaff wrote:
> On Thu, Apr 04, 2024 at 09:09:40AM +0200, David Marchand wrote:
> > Hello Tyler, Marek,
> > 
> > On Wed, Apr 3, 2024 at 6:49 PM Tyler Retzlaff
> > <roretzla@linux.microsoft.com> wrote:
> > >
> > > On Wed, Apr 03, 2024 at 06:40:24AM -0700, Marek Pazdan wrote:
> > > >  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 <mpazdan@arista.com>
> > > > ---
> > > > 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] */
> > > >  };
> > >
> > > this breaks the abi. David does libabigail pick this up i wonder?
> > >
> > 
> > Yes, the CI flagged it.
> > 
> > Looking at the UNH report (in patchwork):
> > http://mails.dpdk.org/archives/test-report/2024-April/631222.html
> 
> i'm jealous we don't have libabigail on windows, so helpfull.

s/ll/l/ end of day bah.

> 
> > 
> > 1 function with some indirect sub-type change:
> > 
> > [C] 'function int rte_eth_link_get(uint16_t, rte_eth_link*)' at
> > rte_ethdev.c:2972:1 has some indirect sub-type changes:
> > parameter 2 of type 'rte_eth_link*' has sub-type changes:
> > in pointed to type 'struct rte_eth_link' at rte_ethdev.h:336:1:
> > type size hasn't changed
> > 2 data member changes:
> > 'uint16_t link_autoneg' offset changed from 33 to 34 (in bits) (by +1 bits)
> > 'uint16_t link_status' offset changed from 34 to 35 (in bits) (by +1 bits)
> > 
> > Error: ABI issue reported for abidiff --suppr
> > /home-local/jenkins-local/jenkins-agent/workspace/Generic-DPDK-Compile-ABI
> > at 3/dpdk/devtools/libabigail.abignore --no-added-syms --headers-dir1
> > reference/usr/local/include --headers-dir2
> > build_install/usr/local/include
> > reference/usr/local/lib/x86_64-linux-gnu/librte_ethdev.so.24.0
> > build_install/usr/local/lib/x86_64-linux-gnu/librte_ethdev.so.24.2
> > ABIDIFF_ABI_CHANGE, this change requires a review (abidiff flagged
> > this as a potential issue).
> > 
> > 
> > GHA would have caught it too, but the documentation generation failed
> > before reaching the ABI check.
> > http://mails.dpdk.org/archives/test-report/2024-April/631086.html
> > 
> > 
> > -- 
> > David Marchand
  
David Marchand April 5, 2024, 8:58 a.m. UTC | #5
On Fri, Apr 5, 2024 at 2:55 AM Tyler Retzlaff
<roretzla@linux.microsoft.com> wrote:
> On Thu, Apr 04, 2024 at 09:09:40AM +0200, David Marchand wrote:
> > On Wed, Apr 3, 2024 at 6:49 PM Tyler Retzlaff
> > > this breaks the abi. David does libabigail pick this up i wonder?
> >
> > Yes, the CI flagged it.
> >
> > Looking at the UNH report (in patchwork):
> > http://mails.dpdk.org/archives/test-report/2024-April/631222.html
>
> i'm jealous we don't have libabigail on windows, so helpful.

libabigail is written in C++ and relies on the elfutils and libxml2 libraries.
I am unclear about what binary format is used in Windows... so I am
not sure how much work would be required to have it on Windows.

That's more something to discuss with Dodji :-).
  
Dodji Seketeli April 5, 2024, 1:05 p.m. UTC | #6
Hello,

> On Fri, Apr 5, 2024 at 2:55 AM Tyler Retzlaff

[...]

>> i'm jealous we don't have libabigail on windows, so helpful.

Heh, thank you for the kind words.

David Marchand <david.marchand@redhat.com> writes:

[...]

> libabigail is written in C++ and relies on the elfutils and libxml2
> libraries.

That is correct.  Thank you for chiming in, David.

> I am unclear about what binary format is used in Windows... so I am
> not sure how much work would be required to have it on Windows.

So for a little bit of context, libabigail constructs its own internal
representation (IR) of the artifacts relevant to perform the analysis.
The middle-end of the system then performs the needed analysis on that
IR.

The binary format itself it handled by a front-end.  Today, we have
front-ends that reads the ELF format and constructs the IR and hands it
over to the middle end.

One could very well imagine a new front-end that knows how to read the
Portable Executable (PE) format that is used on Windows, along with its
accompanying debug information.

Luckily, I've written articles[1][2] that explains how libabigail
recently switched to having a multi-front-end architecture that we have
used to support alternative debug information formats like CTF[3] and
BTF.

In light of that, adding a new PE front-end would be "just work to do",
I would think.  And I would obviously not be opposed to helping such a
project and merging the result in the end.

As for any feature request, I would encourage potentially interested
parties to file an "enhancement request" on the bug tracker of the
project[4].

> That's more something to discuss with Dodji :-).

Thanks for the plug ;-)

I hope this helps.

[1]: https://developers.redhat.com/articles/2023/01/05/libabigail-multiple-debugging-formats#the_resulting_multi_front_end_architecture
[2]: https://www.redhat.com/en/blog/bpf-type-format-support-libabigail-23
[3]: https://lwn.net/Articles/795384/
[4]: https://sourceware.org/bugzilla/enter_bug.cgi?product=libabigail

Cheers,
  

Patch

diff --git a/.mailmap b/.mailmap
index 3843868716..145ce726ba 100644
--- a/.mailmap
+++ b/.mailmap
@@ -885,6 +885,7 @@  Marcin Wojtas <mw@semihalf.com>
 Marcin Zapolski <marcinx.a.zapolski@intel.com>
 Marco Varlese <mvarlese@suse.de>
 Marc Sune <marcdevel@gmail.com> <marc.sune@bisdn.de>
+Marek Pazdan <mpazdan@arista.com>
 Maria Lingemark <maria.lingemark@ericsson.com>
 Mario Carrillo <mario.alfredo.c.arevalo@intel.com>
 Mário Kuka <kuka@cesnet.cz>
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 /**</ Unknown-duplex (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. */
+/**@}*/
+
+/**@{@name Link negotiation
+ * Constants used in link management to specify connector port.
+ */
+#define RTE_PORT_TP             0x00
+#define RTE_PORT_AUI            0x01
+#define RTE_PORT_MII            0x02
+#define RTE_PORT_FIBRE          0x03
+#define RTE_PORT_BNC            0x04
+#define RTE_PORT_DA             0x05
+#define RTE_PORT_NONE           0xef
+#define RTE_PORT_OTHER          0xff
 /**@}*/
 
 /**
@@ -1433,6 +1447,147 @@  struct rte_eth_pfc_queue_conf {
 	} tx_pause; /* Valid when (mode == FC_TX_PAUSE || mode == FC_FULL) */
 };
 
+/* Enable or disable autonegotiation. */
+#define RTE_AUTONEG_DISABLE         0x00
+#define RTE_AUTONEG_ENABLE          0x01
+
+/* MDI or MDI-X status/control - if MDI/MDI_X/AUTO is set then
+ * the driver is required to renegotiate link
+ */
+#define RTE_TP_MDI_INVALID      0x00 /* status: unknown; control: unsupported */
+#define RTE_TP_MDI              0x01 /* status: MDI;     control: force MDI */
+#define RTE_TP_MDI_X            0x02 /* status: MDI-X;   control: force MDI-X */
+#define RTE_TP_MDI_AUTO         0x03 /*                  control: auto-select */
+
+/* Link mode bit indices */
+enum rte_link_mode_bit_indices {
+	RTE_LINK_MODE_10baseT_Half_BIT	= 0,
+	RTE_LINK_MODE_10baseT_Full_BIT	= 1,
+	RTE_LINK_MODE_100baseT_Half_BIT	= 2,
+	RTE_LINK_MODE_100baseT_Full_BIT	= 3,
+	RTE_LINK_MODE_1000baseT_Half_BIT	= 4,
+	RTE_LINK_MODE_1000baseT_Full_BIT	= 5,
+	RTE_LINK_MODE_Autoneg_BIT		= 6,
+	RTE_LINK_MODE_TP_BIT		= 7,
+	RTE_LINK_MODE_AUI_BIT		= 8,
+	RTE_LINK_MODE_MII_BIT		= 9,
+	RTE_LINK_MODE_FIBRE_BIT		= 10,
+	RTE_LINK_MODE_BNC_BIT		= 11,
+	RTE_LINK_MODE_10000baseT_Full_BIT	= 12,
+	RTE_LINK_MODE_Pause_BIT		= 13,
+	RTE_LINK_MODE_Asym_Pause_BIT	= 14,
+	RTE_LINK_MODE_2500baseX_Full_BIT	= 15,
+	RTE_LINK_MODE_Backplane_BIT		= 16,
+	RTE_LINK_MODE_1000baseKX_Full_BIT	= 17,
+	RTE_LINK_MODE_10000baseKX4_Full_BIT	= 18,
+	RTE_LINK_MODE_10000baseKR_Full_BIT	= 19,
+	RTE_LINK_MODE_10000baseR_FEC_BIT	= 20,
+	RTE_LINK_MODE_20000baseMLD2_Full_BIT = 21,
+	RTE_LINK_MODE_20000baseKR2_Full_BIT	= 22,
+	RTE_LINK_MODE_40000baseKR4_Full_BIT	= 23,
+	RTE_LINK_MODE_40000baseCR4_Full_BIT	= 24,
+	RTE_LINK_MODE_40000baseSR4_Full_BIT	= 25,
+	RTE_LINK_MODE_40000baseLR4_Full_BIT	= 26,
+	RTE_LINK_MODE_56000baseKR4_Full_BIT	= 27,
+	RTE_LINK_MODE_56000baseCR4_Full_BIT	= 28,
+	RTE_LINK_MODE_56000baseSR4_Full_BIT	= 29,
+	RTE_LINK_MODE_56000baseLR4_Full_BIT	= 30,
+	RTE_LINK_MODE_25000baseCR_Full_BIT	= 31,
+	RTE_LINK_MODE_25000baseKR_Full_BIT	= 32,
+	RTE_LINK_MODE_25000baseSR_Full_BIT	= 33,
+	RTE_LINK_MODE_50000baseCR2_Full_BIT	= 34,
+	RTE_LINK_MODE_50000baseKR2_Full_BIT	= 35,
+	RTE_LINK_MODE_100000baseKR4_Full_BIT	= 36,
+	RTE_LINK_MODE_100000baseSR4_Full_BIT	= 37,
+	RTE_LINK_MODE_100000baseCR4_Full_BIT	= 38,
+	RTE_LINK_MODE_100000baseLR4_ER4_Full_BIT	= 39,
+	RTE_LINK_MODE_50000baseSR2_Full_BIT		= 40,
+	RTE_LINK_MODE_1000baseX_Full_BIT	= 41,
+	RTE_LINK_MODE_10000baseCR_Full_BIT	= 42,
+	RTE_LINK_MODE_10000baseSR_Full_BIT	= 43,
+	RTE_LINK_MODE_10000baseLR_Full_BIT	= 44,
+	RTE_LINK_MODE_10000baseLRM_Full_BIT	= 45,
+	RTE_LINK_MODE_10000baseER_Full_BIT	= 46,
+	RTE_LINK_MODE_2500baseT_Full_BIT	= 47,
+	RTE_LINK_MODE_5000baseT_Full_BIT	= 48,
+
+	RTE_LINK_MODE_FEC_NONE_BIT	= 49,
+	RTE_LINK_MODE_FEC_RS_BIT	= 50,
+	RTE_LINK_MODE_FEC_BASER_BIT	= 51,
+	RTE_LINK_MODE_50000baseKR_Full_BIT		 = 52,
+	RTE_LINK_MODE_50000baseSR_Full_BIT		 = 53,
+	RTE_LINK_MODE_50000baseCR_Full_BIT		 = 54,
+	RTE_LINK_MODE_50000baseLR_ER_FR_Full_BIT	 = 55,
+	RTE_LINK_MODE_50000baseDR_Full_BIT		 = 56,
+	RTE_LINK_MODE_100000baseKR2_Full_BIT	 = 57,
+	RTE_LINK_MODE_100000baseSR2_Full_BIT	 = 58,
+	RTE_LINK_MODE_100000baseCR2_Full_BIT	 = 59,
+	RTE_LINK_MODE_100000baseLR2_ER2_FR2_Full_BIT = 60,
+	RTE_LINK_MODE_100000baseDR2_Full_BIT	 = 61,
+	RTE_LINK_MODE_200000baseKR4_Full_BIT	 = 62,
+	RTE_LINK_MODE_200000baseSR4_Full_BIT	 = 63,
+	RTE_LINK_MODE_200000baseLR4_ER4_FR4_Full_BIT = 64,
+	RTE_LINK_MODE_200000baseDR4_Full_BIT	 = 65,
+	RTE_LINK_MODE_200000baseCR4_Full_BIT	 = 66,
+	RTE_LINK_MODE_100baseT1_Full_BIT		 = 67,
+	RTE_LINK_MODE_1000baseT1_Full_BIT		 = 68,
+	RTE_LINK_MODE_400000baseKR8_Full_BIT	 = 69,
+	RTE_LINK_MODE_400000baseSR8_Full_BIT	 = 70,
+	RTE_LINK_MODE_400000baseLR8_ER8_FR8_Full_BIT = 71,
+	RTE_LINK_MODE_400000baseDR8_Full_BIT	 = 72,
+	RTE_LINK_MODE_400000baseCR8_Full_BIT	 = 73,
+	RTE_LINK_MODE_FEC_LLRS_BIT			 = 74,
+	RTE_LINK_MODE_100000baseKR_Full_BIT		 = 75,
+	RTE_LINK_MODE_100000baseSR_Full_BIT		 = 76,
+	RTE_LINK_MODE_100000baseLR_ER_FR_Full_BIT	 = 77,
+	RTE_LINK_MODE_100000baseCR_Full_BIT		 = 78,
+	RTE_LINK_MODE_100000baseDR_Full_BIT		 = 79,
+	RTE_LINK_MODE_200000baseKR2_Full_BIT	 = 80,
+	RTE_LINK_MODE_200000baseSR2_Full_BIT	 = 81,
+	RTE_LINK_MODE_200000baseLR2_ER2_FR2_Full_BIT = 82,
+	RTE_LINK_MODE_200000baseDR2_Full_BIT	 = 83,
+	RTE_LINK_MODE_200000baseCR2_Full_BIT	 = 84,
+	RTE_LINK_MODE_400000baseKR4_Full_BIT	 = 85,
+	RTE_LINK_MODE_400000baseSR4_Full_BIT	 = 86,
+	RTE_LINK_MODE_400000baseLR4_ER4_FR4_Full_BIT = 87,
+	RTE_LINK_MODE_400000baseDR4_Full_BIT	 = 88,
+	RTE_LINK_MODE_400000baseCR4_Full_BIT	 = 89,
+	RTE_LINK_MODE_100baseFX_Half_BIT		 = 90,
+	RTE_LINK_MODE_100baseFX_Full_BIT		 = 91,
+	/* must be last entry */
+	__RTE_LINK_MODE_MASK_NBITS
+};
+
+/* number of 32-bit words to store the user's link mode bitmaps */
+#define RTE_DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
+#define __RTE_LINK_MODE_MASK_NU32                   \
+	RTE_DIV_ROUND_UP(__RTE_LINK_MODE_MASK_NBITS, 32)
+
+/**
+ * Link control and status
+ * @speed: Link speed (Mbps)
+ * @duplex: Duplex mode; one of %DUPLEX_*
+ * @port: Physical connector type; one of %PORT_*
+ * @autoneg: Enable/disable autonegotiation and auto-detection;
+ *	either %AUTONEG_DISABLE or %AUTONEG_ENABLE
+ */
+struct rte_link_base_settings {
+	struct rte_eth_link link;
+	uint8_t port;
+	uint8_t phy_address;
+	uint8_t eth_tp_mdix;
+	uint8_t eth_tp_mdix_ctrl;
+};
+
+struct rte_link_settings {
+	struct rte_link_base_settings base;
+	struct {
+		uint32_t supported[__RTE_LINK_MODE_MASK_NU32];
+		uint32_t advertising[__RTE_LINK_MODE_MASK_NU32];
+		uint32_t lp_advertising[__RTE_LINK_MODE_MASK_NU32];
+	} link_modes;
+};
+
 /**
  * Tunnel type for device-specific classifier configuration.
  * @see rte_eth_udp_tunnel
@@ -5936,6 +6091,50 @@  int rte_eth_cman_config_init(uint16_t port_id, struct rte_eth_cman_config *confi
 __rte_experimental
 int rte_eth_cman_config_set(uint16_t port_id, const struct rte_eth_cman_config *config);
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change, or be removed, without prior notice
+ *
+ * Retrieve link settings
+ *
+ * @param port_id
+ *   The port identifier of the Ethernet device.
+ * @param settings
+ *   A pointer to a structure of type *rte_link_settings* to retrieve
+ *   link settings parameters for the given port.
+ *
+ * @return
+ *   - (0) if successful.
+ *   - (-ENOTSUP) if support for cman_config_get does not exist.
+ *   - (-ENODEV) if *port_id* invalid.
+ *   - (-EINVAL) if bad parameter.
+ */
+__rte_experimental
+int rte_eth_dev_get_link_settings(uint16_t port_id,
+				  struct rte_link_settings *settings);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change, or be removed, without prior notice
+ *
+ * Configure link settings
+ *
+ * @param port_id
+ *   The port identifier of the Ethernet device.
+ * @param settings
+ *   A pointer to a structure of type *rte_link_settings* to configure
+ *   link settings parameters for the given port.
+ *
+ * @return
+ *   - (0) if successful.
+ *   - (-ENOTSUP) if support for cman_config_get does not exist.
+ *   - (-ENODEV) if *port_id* invalid.
+ *   - (-EINVAL) if bad parameter.
+ */
+__rte_experimental
+int rte_eth_dev_set_link_settings(uint16_t port_id,
+				  const struct rte_link_settings *settings);
+
 /**
  * @warning
  * @b EXPERIMENTAL: this API may change, or be removed, without prior notice
diff --git a/lib/ethdev/version.map b/lib/ethdev/version.map
index 79f6f5293b..5e138a3d10 100644
--- a/lib/ethdev/version.map
+++ b/lib/ethdev/version.map
@@ -325,6 +325,9 @@  EXPERIMENTAL {
 	rte_flow_template_table_resizable;
 	rte_flow_template_table_resize;
 	rte_flow_template_table_resize_complete;
+	rte_eth_dev_get_link_settings;
+	rte_eth_dev_set_link_settings;
+
 };
 
 INTERNAL {