From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stephen Hemminger Subject: [PATCH 2/6] Subjet: ethdev: add common code to atomicly access link Date: Wed, 14 May 2014 11:55:29 -0700 Message-ID: <20140514185743.414400480@networkplumber.org> References: <20140514185527.771828962@networkplumber.org> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15 Cc: Stephen Hemminger To: dev-VfR2kkLFssw@public.gmane.org Return-path: Content-Disposition: inline; filename=eth-dev-link.patch List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces-VfR2kkLFssw@public.gmane.org Sender: "dev" Many drivers copy/paste same code to atomicly access link information. Add functions to do this instead. Signed-off-by: Stephen Hemminger --- 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