From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pa0-f44.google.com (mail-pa0-f44.google.com [209.85.220.44]) by dpdk.org (Postfix) with ESMTP id 9DFA6B0BE for ; Wed, 14 May 2014 20:57:37 +0200 (CEST) Received: by mail-pa0-f44.google.com with SMTP id ld10so2030447pab.3 for ; Wed, 14 May 2014 11:57:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:user-agent:date:from:to:cc:subject :references:mime-version:content-type:content-disposition; bh=6aIwRoFBdZgiqG7y+i2U1PeZ7BRojvEyJ6ecI4eUdx0=; b=Au8/gfJIdPRvq6LL/aznO+rxiFUvFAZkZYA58Ep7XXzZdyhJgyS2m7CfttkWOrGn0R 8/w0JXdj0yMidGNdWOk3rmvnZgC2HPYal2NV65ldftvEQnm+pLKGKDMZgMevQpMcpQeJ E45WZXOe/cgCfo2I0ROWokcc/g6mCjzyqOuCG2y2NPGFXgJQbmFtEC+S4jh55dTga16A DLcIvshEj9TMUpOzSS3vu3bUTs5mRuNuGjHFKO31Cww1ADoTRcag2aOvWRqmbR3OBs2K cS5JAMnRDJ1uJKBRM6sr3eH1D7GLMTJS1189fzyTfA+MxuhUZUHeOuLy7bm5uDaXjOCj T2+A== X-Gm-Message-State: ALoCoQlDfx+vqQvckok8ENosyZh2WQCCVgxSuIwc+EdOYrXEKBFH7GkrwY7E3YIUFRTDBTQe54vt X-Received: by 10.68.254.5 with SMTP id ae5mr6412825pbd.83.1400093865116; Wed, 14 May 2014 11:57:45 -0700 (PDT) Received: from localhost (static-50-53-83-51.bvtn.or.frontiernet.net. [50.53.83.51]) by mx.google.com with ESMTPSA id vf9sm4811495pbc.94.2014.05.14.11.57.43 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 May 2014 11:57:44 -0700 (PDT) Message-Id: <20140514185743.414400480@networkplumber.org> User-Agent: quilt/0.61-1 Date: Wed, 14 May 2014 11:55:29 -0700 From: Stephen Hemminger To: dev@dpdk.org References: <20140514185527.771828962@networkplumber.org> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Disposition: inline; filename=eth-dev-link.patch Cc: Stephen Hemminger Subject: [dpdk-dev] [PATCH 2/6] Subjet: ethdev: add common code to atomicly access link X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 May 2014 18:57:38 -0000 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