From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id D65A4107A for ; Wed, 11 Oct 2017 10:32:33 +0200 (CEST) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Oct 2017 01:32:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.43,360,1503385200"; d="scan'208";a="1023979753" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by orsmga003.jf.intel.com with ESMTP; 11 Oct 2017 01:32:32 -0700 Received: from fmsmsx120.amr.corp.intel.com (10.18.124.208) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 11 Oct 2017 01:32:15 -0700 Received: from shsmsx152.ccr.corp.intel.com (10.239.6.52) by fmsmsx120.amr.corp.intel.com (10.18.124.208) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 11 Oct 2017 01:32:14 -0700 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.159]) by SHSMSX152.ccr.corp.intel.com ([169.254.6.93]) with mapi id 14.03.0319.002; Wed, 11 Oct 2017 16:32:12 +0800 From: "Yang, Qiming" To: Stephen Hemminger , "dev@dpdk.org" CC: Stephen Hemminger Thread-Topic: [dpdk-dev] [RFC 01/14] ethdev: add link status read/write functions Thread-Index: AQHS/M9mtp032pzloEeMUBxtm8mreaLe2m1Q Date: Wed, 11 Oct 2017 08:32:12 +0000 Message-ID: References: <20170714183027.16021-1-stephen@networkplumber.org> <20170714183027.16021-2-stephen@networkplumber.org> In-Reply-To: <20170714183027.16021-2-stephen@networkplumber.org> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiMzA4OGIxMmItMWE0OS00MGM1LWEyMWYtYjRhNTgwZjdmMGJkIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE2LjUuOS4zIiwiVHJ1c3RlZExhYmVsSGFzaCI6ImxGTDY1XC9mVm5kZDIwM01UYzd4a1VUa1hiT01vckR1bkkzZytndVZ6eE5NPSJ9 x-ctpclassification: CTP_IC dlp-product: dlpe-windows dlp-version: 11.0.0.116 dlp-reaction: no-action x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [RFC 01/14] ethdev: add link status read/write functions X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Oct 2017 08:32:34 -0000 > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Stephen Hemminger > Sent: Saturday, July 15, 2017 2:30 AM > To: dev@dpdk.org > Cc: Stephen Hemminger ; Stephen Hemminger > > Subject: [dpdk-dev] [RFC 01/14] ethdev: add link status read/write functi= ons >=20 > Many drivers are all doing copy/paste of the same code to atomicly update= the > link status. Reduce duplication, and allow for future changes by having c= ommon > function for this. >=20 > Signed-off-by: Stephen Hemminger > --- > lib/librte_ether/rte_ethdev.c | 36 ++++++++++++++++++++++++++++++++++++ > lib/librte_ether/rte_ethdev.h | 28 ++++++++++++++++++++++++++++ > 2 files changed, 64 insertions(+) >=20 > diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.= c index > a1b744704f3a..7532fc6b65f0 100644 > --- a/lib/librte_ether/rte_ethdev.c > +++ b/lib/librte_ether/rte_ethdev.c > @@ -1332,6 +1332,42 @@ rte_eth_link_get_nowait(uint8_t port_id, struct > rte_eth_link *eth_link) } >=20 > int > +_rte_eth_link_update(struct rte_eth_dev *dev, > + const struct rte_eth_link *link) > +{ > + volatile struct rte_eth_link *dev_link =3D &(dev->data->dev_link); > + struct rte_eth_link old; > + > + RTE_BUILD_BUG_ON(sizeof(*link) !=3D sizeof(uint64_t)); > + > + old =3D *dev_link; > + > + /* Only reason we use cmpset rather than set is > + * that on some architecture may use sign bit as a flag value. > + */ > + while (rte_atomic64_cmpset((volatile uint64_t *)dev_link, > + *(volatile uint64_t *)dev_link, > + *(const uint64_t *)link) =3D=3D 0) > + continue; > + > + return (old.link_status =3D=3D link->link_status) ? -1 : 0; } > + > +void _rte_eth_link_read(struct rte_eth_dev *dev, > + struct rte_eth_link *link) > +{ > + const uint64_t *src =3D (const uint64_t *)&(dev->data->dev_link); > + volatile uint64_t *dst =3D (uint64_t *)link; > + > + RTE_BUILD_BUG_ON(sizeof(*link) !=3D sizeof(uint64_t)); > + > + /* Note: this should never fail since both destination and expected > + * values are the same and are a pointer from caller. > + */ > + rte_atomic64_cmpset(dst, *dst, *src); > +} > + > +int > rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats) { > struct rte_eth_dev *dev; > diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.= h index > f6837278521c..974657933f23 100644 > --- a/lib/librte_ether/rte_ethdev.h > +++ b/lib/librte_ether/rte_ethdev.h > @@ -2219,6 +2219,34 @@ void rte_eth_link_get(uint8_t port_id, struct > rte_eth_link *link); > */ > void rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *link)= ; >=20 > + > +/** > + * @internal > + * Atomically write the link status for the specific device. > + * It is for use by DPDK device driver use only. > + * User applications should not call it > + * > + * @param dev > + * Pointer to struct rte_eth_dev. > + * @param link > + * New link status value. > + * @return > + * -1 if link state has changed, 0 if the same. > + */ > +int _rte_eth_link_update(struct rte_eth_dev *dev, > + const struct rte_eth_link *link); > + This function is only do the atomically write, what do you think to change = the function name to _rte_eth_atomic_write_link_status, Use name link_update makes me confused, and mix up it with dev_ops link_upd= ate. > +/** > + * @internal > + * Atomically read the link speed and status. > + * @param dev > + * Pointer to struct rte_eth_dev. > + * @param link > + * link status value. > + */ > +void _rte_eth_link_read(struct rte_eth_dev *dev, > + struct rte_eth_link *link); > + This name is also not very clear. I think change to _rte_eth_atomic_read_li= nk_status will better. > /** > * Retrieve the general I/O statistics of an Ethernet device. > * > -- > 2.11.0