Many drivers copy/paste same code to atomicly access link information.
Add functions to do this instead.

Signed-off-by: Stephen Hemminger <shemming at brocade.com>

--- a/lib/librte_ether/rte_ethdev.h     2014-05-14 11:27:07.409461720 -0700
+++ b/lib/librte_ether/rte_ethdev.h     2014-05-14 11:27:07.409461720 -0700
@@ -1704,6 +1704,45 @@ extern void rte_eth_link_get_nowait(uint
                                struct rte_eth_link *link);

 /**
+ * @internal
+ * Retrieve the link status from device in atomic fashion.
+ */
+static inline void rte_eth_dev_get_link(struct rte_eth_dev *dev,
+                                       struct rte_eth_link *link)
+{
+       int64_t val;
+
+       val = rte_atomic64_read((rte_atomic64_t *)&dev->data->dev_link);
+
+       memcpy(link, &val, sizeof(struct rte_eth_link));
+}
+
+/**
+ * @internal
+ * Set the link status from device in atomic fashion.
+ * Returns non-zero on success; 0 on failure
+ * Callers should retry on failure
+ */
+static inline void rte_eth_dev_set_link(struct rte_eth_dev *dev,
+                                       struct rte_eth_link *link)
+{
+       rte_atomic64_t *dst = (rte_atomic64_t *)&dev->data->dev_link;
+
+       rte_atomic64_set(dst, *(int64_t *)link);
+}
+
+/**
+ * @internal
+ * Clear link status.
+ */
+static inline void rte_eth_dev_clear_link(struct rte_eth_dev *dev)
+{
+       rte_atomic64_t *dst = (rte_atomic64_t *)&dev->data->dev_link;
+
+       rte_atomic64_set(dst, 0);
+}
+
+/**
  * Retrieve the general I/O statistics of an Ethernet device.
  *
  * @param port_id

Reply via email to