From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01on0044.outbound.protection.outlook.com [104.47.1.44]) by dpdk.org (Postfix) with ESMTP id 059B32C17 for ; Tue, 19 Jun 2018 11:00:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yb1RXD2wWHZ0Q3+fVLFyAMPNjaZLsvTjsatMzTzWBs8=; b=Mu+nOH5DnuQzbv2VJhPpWjpoZdEJSqtga1WZgQ3a3iM5n2Nc7IW/1BC0bG8HBMiv4z5QIXvg8mzZ7w66NgdVLRvSEn9jnnZ8Jm8OpnR8OOUisrTQ7EEzJlrP0uqUsz62JcarFvWeFc2WtajuQpm3d4hVj43E3G1SWTlBB32IdFc= Received: from VI1PR0501MB2608.eurprd05.prod.outlook.com (10.168.137.20) by VI1PR0501MB2848.eurprd05.prod.outlook.com (10.172.11.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.863.19; Tue, 19 Jun 2018 09:00:37 +0000 Received: from VI1PR0501MB2608.eurprd05.prod.outlook.com ([fe80::4548:a183:6278:6d9f]) by VI1PR0501MB2608.eurprd05.prod.outlook.com ([fe80::4548:a183:6278:6d9f%2]) with mapi id 15.20.0863.016; Tue, 19 Jun 2018 09:00:37 +0000 From: Matan Azrad To: Alex Kiselev , "dev@dpdk.org" , Chas Williams <3chas3@gmail.com>, Stephen Hemminger Thread-Topic: [PATCH v3] net/bonding: add add/remove mac addrs Thread-Index: AQHUB6gE1ABdmYF0+ki0J7ZTCtW20qRnRWog Date: Tue, 19 Jun 2018 09:00:37 +0000 Message-ID: References: <0d1c4f28-e08b-40e7-9b9e-0d4bdd15279a@VE1EUR03FT041.eop-EUR03.prod.protection.outlook.com> In-Reply-To: <0d1c4f28-e08b-40e7-9b9e-0d4bdd15279a@VE1EUR03FT041.eop-EUR03.prod.protection.outlook.com> Accept-Language: en-US, he-IL Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=matan@mellanox.com; x-originating-ip: [193.47.165.251] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; VI1PR0501MB2848; 7:oUJ6yn4YN2A29AHvmt18l+Udz+tmc2e5PYNN6RTvdAXDHymdkzBbgiK5CE5Nc5qd38vfHnUxEgalBgq5+Gn1o3Y9FaAupmFoFGWuPPVL1P4eQGP87Q2gFXwf1szatXewY8qrwuUdxYR2pfXyP/hptqavE6AghDZ0oVYQwXH/Ed8+vW/KR4YlzKEIfFIQRmdyNCP+KAycqesJV8b4er7lW1IoJTLAvAauu0Hg9xpzQUwj4j489+NOFoB/AJs1rjAb x-ms-exchange-antispam-srfa-diagnostics: SOS; x-ms-office365-filtering-correlation-id: 16060e55-5564-430f-01d7-08d5d5c32003 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(711020)(48565401081)(2017052603328)(7153060)(7193020); SRVR:VI1PR0501MB2848; x-ms-traffictypediagnostic: VI1PR0501MB2848: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(10201501046)(3231254)(944501410)(52105095)(93006095)(93001095)(3002001)(6055026)(149027)(150027)(6041310)(20161123564045)(20161123558120)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(6072148)(201708071742011)(7699016); SRVR:VI1PR0501MB2848; BCL:0; PCL:0; RULEID:; SRVR:VI1PR0501MB2848; x-forefront-prvs: 07083FF734 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(376002)(366004)(346002)(39860400002)(39380400002)(396003)(199004)(189003)(229853002)(316002)(68736007)(26005)(14454004)(55016002)(2906002)(110136005)(97736004)(105586002)(59450400001)(102836004)(66066001)(478600001)(6436002)(2900100001)(3846002)(6116002)(6506007)(25786009)(106356001)(7696005)(33656002)(76176011)(2501003)(575784001)(86362001)(6246003)(486006)(186003)(446003)(11346002)(81166006)(99286004)(81156014)(8936002)(8676002)(476003)(53936002)(3660700001)(5250100002)(305945005)(9686003)(3280700002)(74316002)(39060400002)(7736002)(5660300001); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR0501MB2848; H:VI1PR0501MB2608.eurprd05.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: pTfl6xluQ6WeZc2bBVQckC+YpR95nYLkzJySA2zEL1UGGhAzchECRrxdEsRWJ+ZxufmIA+UfOriiMxr0IC+5VfSunFdBVQgOBBZCUmciUFjusIDL9YfWvvxCE1Cyt1XDIt7gdQ7sXRFDfJxRsIC2yG6taEN5FeUXyGZbbfwdG7yGNcfGVt6ktvl1KSE6/DKR+lszKy4SwFXE8wc4m+TL26cZC2XtFI1HMZyf769/RJ8N1TCsaBIkMpvBCYEyBmSKQTZOTU5OEkfelg67rt1cpywcqQVFT9UGP/p5yzaZNKKgYn+cvVC+haKYn+v6XFnV76StBXRcEDbxE4mXZX/khA== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: 16060e55-5564-430f-01d7-08d5d5c32003 X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Jun 2018 09:00:37.3368 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0501MB2848 Subject: Re: [dpdk-dev] [PATCH v3] net/bonding: add add/remove mac addrs 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: Tue, 19 Jun 2018 09:00:39 -0000 Hi Alex Please see comments below. From: Alex Kiselev > add functions to add/remove MAC addresses > Signed-off-by: Alex Kiselev > --- > drivers/net/bonding/rte_eth_bond_api.c | 12 ++- > drivers/net/bonding/rte_eth_bond_pmd.c | 127 > ++++++++++++++++++++++++++++- > drivers/net/bonding/rte_eth_bond_private.h | 8 ++ > 3 files changed, 142 insertions(+), 5 deletions(-) >=20 > diff --git a/drivers/net/bonding/rte_eth_bond_api.c > b/drivers/net/bonding/rte_eth_bond_api.c > index d558df8b9..9123f4614 100644 > --- a/drivers/net/bonding/rte_eth_bond_api.c > +++ b/drivers/net/bonding/rte_eth_bond_api.c > @@ -373,6 +373,13 @@ __eth_bond_slave_add_lock_free(uint16_t > bonded_port_id, uint16_t slave_port_id) > return -1; > } >=20 > + /* Add additional MAC addresses to the slave */ > + if (slave_add_mac_addresses(bonded_eth_dev, slave_port_id) !=3D 0) { > + RTE_BOND_LOG(ERR, "Failed to add mac address(es) to slave > %hu", > + slave_port_id); > + return -1; > + } > + > internals->slave_count++; >=20 > if (bonded_eth_dev->data->dev_started) { @@ -387,7 +394,7 @@ > __eth_bond_slave_add_lock_free(uint16_t bonded_port_id, uint16_t > slave_port_id) > /* Add slave details to bonded device */ > slave_eth_dev->data->dev_flags |=3D RTE_ETH_DEV_BONDED_SLAVE; >=20 > - /* Update all slave devices MACs*/ > + /* Update all slave devices MACs */ > mac_address_slaves_update(bonded_eth_dev); >=20 > /* Register link status change callback with bonded device pointer as > @@ -491,6 +498,9 @@ __eth_bond_slave_remove_lock_free(uint16_t > bonded_port_id, > rte_eth_dev_default_mac_addr_set(slave_port_id, > &(internals->slaves[slave_idx].persisted_mac_addr)); >=20 > + /* remove additional MAC addresses from the slave */ > + slave_remove_mac_addresses(bonded_eth_dev, slave_port_id); > + > /* > * Remove bond device flows from slave device. > * Note: don't restore flow isolate mode. > diff --git a/drivers/net/bonding/rte_eth_bond_pmd.c > b/drivers/net/bonding/rte_eth_bond_pmd.c > index 02d94b1b1..97d689261 100644 > --- a/drivers/net/bonding/rte_eth_bond_pmd.c > +++ b/drivers/net/bonding/rte_eth_bond_pmd.c > @@ -25,6 +25,7 @@ >=20 > #define REORDER_PERIOD_MS 10 > #define DEFAULT_POLLING_INTERVAL_10_MS (10) > +#define BOND_MAX_MAC_ADDRS 16 >=20 > #define HASH_L4_PORTS(h) ((h)->src_port ^ (h)->dst_port) >=20 > @@ -1588,6 +1589,57 @@ mac_address_set(struct rte_eth_dev *eth_dev, > struct ether_addr *new_mac_addr) > return 0; > } >=20 > +static const struct ether_addr null_mac_addr; > + > +/* > + * Add additional MAC addresses to the slave */ int > +slave_add_mac_addresses(struct rte_eth_dev *bonded_eth_dev, > + uint16_t slave_port_id) > +{ > + int i, ret; > + struct ether_addr *mac_addr; > + > + for (i =3D 1; i < BOND_MAX_MAC_ADDRS; i++) { > + mac_addr =3D &bonded_eth_dev->data->mac_addrs[i]; > + if (is_same_ether_addr(mac_addr, &null_mac_addr)) > + break; > + > + ret =3D rte_eth_dev_mac_addr_add(slave_port_id, mac_addr, 0); > + if (ret < 0) { > + /* rollback */ > + for (i--; i > 0; i--) > + In case of failure in the first mac address(i=3D1) you are going to remove = the default mac address(i=3D0) from the slave. > rte_eth_dev_mac_addr_remove(slave_port_id, > + &bonded_eth_dev->data- > >mac_addrs[i]); > + return ret; > + } > + } > + > + return 0; > +} > + > +/* > + * Remove additional MAC addresses from the slave */ int > +slave_remove_mac_addresses(struct rte_eth_dev *bonded_eth_dev, > + uint16_t slave_port_id) > +{ > + int i, ret =3D 0; > + struct ether_addr *mac_addr; > + > + for (i =3D 1; i < BOND_MAX_MAC_ADDRS; i++) { > + mac_addr =3D &bonded_eth_dev->data->mac_addrs[i]; > + if (is_same_ether_addr(mac_addr, &null_mac_addr)) > + break; > + > + ret =3D rte_eth_dev_mac_addr_remove(slave_port_id, > mac_addr); > + } I suggest to return the first error, also in case of all success with last = failure, the code here wrongly returns success.=20 > + > + return ret; > +} > + > int > mac_address_slaves_update(struct rte_eth_dev *bonded_eth_dev) { @@ - > 2219,7 +2271,7 @@ bond_ethdev_info(struct rte_eth_dev *dev, struct > rte_eth_dev_info *dev_info) > uint16_t max_nb_rx_queues =3D UINT16_MAX; > uint16_t max_nb_tx_queues =3D UINT16_MAX; >=20 > - dev_info->max_mac_addrs =3D 1; > + dev_info->max_mac_addrs =3D BOND_MAX_MAC_ADDRS; >=20 > dev_info->max_rx_pktlen =3D internals->candidate_max_rx_pktlen ? > internals->candidate_max_rx_pktlen : > @@ -2905,6 +2957,68 @@ bond_filter_ctrl(struct rte_eth_dev *dev > __rte_unused, > return -ENOTSUP; > } >=20 > +static int > +bond_ethdev_mac_addr_add(struct rte_eth_dev *dev, struct ether_addr > *mac_addr, > + __rte_unused uint32_t index, uint32_t vmdq) { > + struct rte_eth_dev *slave_eth_dev; > + struct bond_dev_private *internals =3D dev->data->dev_private; > + int ret, i; > + > + rte_spinlock_lock(&internals->lock); > + > + for (i =3D 0; i < internals->slave_count; i++) { > + slave_eth_dev =3D &rte_eth_devices[internals->slaves[i].port_id]; > + if (*slave_eth_dev->dev_ops->mac_addr_add =3D=3D NULL || > + *slave_eth_dev->dev_ops->mac_addr_remove =3D=3D > NULL) { > + ret =3D -ENOTSUP; > + goto end; > + } > + } > + > + for (i =3D 0; i < internals->slave_count; i++) { > + ret =3D rte_eth_dev_mac_addr_add(internals->slaves[i].port_id, > + mac_addr, vmdq); > + if (ret < 0) { > + /* rollback */ > + for (i--; i >=3D 0; i--) In case of failure in the first slave(i=3D0) you are going probably to get = memory error (i=3D-1). > + rte_eth_dev_mac_addr_remove( > + internals->slaves[i].port_id, > mac_addr); > + goto end; > + } > + } > + > + ret =3D 0; > +end: > + rte_spinlock_unlock(&internals->lock); > + return ret; > +} > + > +static void > +bond_ethdev_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index) { > + struct rte_eth_dev *slave_eth_dev; > + struct bond_dev_private *internals =3D dev->data->dev_private; > + int i; > + > + rte_spinlock_lock(&internals->lock); > + > + for (i =3D 0; i < internals->slave_count; i++) { > + slave_eth_dev =3D &rte_eth_devices[internals->slaves[i].port_id]; > + if (*slave_eth_dev->dev_ops->mac_addr_remove =3D=3D NULL) > + goto end; > + } > + > + struct ether_addr *mac_addr =3D &dev->data->mac_addrs[index]; > + > + for (i =3D 0; i < internals->slave_count; i++) > + rte_eth_dev_mac_addr_remove(internals->slaves[i].port_id, > + mac_addr); > + > +end: > + rte_spinlock_unlock(&internals->lock); > +} > + > const struct eth_dev_ops default_dev_ops =3D { > .dev_start =3D bond_ethdev_start, > .dev_stop =3D bond_ethdev_stop, > @@ -2927,6 +3041,8 @@ const struct eth_dev_ops default_dev_ops =3D { > .rss_hash_conf_get =3D bond_ethdev_rss_hash_conf_get, > .mtu_set =3D bond_ethdev_mtu_set, > .mac_addr_set =3D bond_ethdev_mac_address_set, > + .mac_addr_add =3D bond_ethdev_mac_addr_add, > + .mac_addr_remove =3D bond_ethdev_mac_addr_remove, > .filter_ctrl =3D bond_filter_ctrl > }; >=20 > @@ -2954,10 +3070,13 @@ bond_alloc(struct rte_vdev_device *dev, uint8_t > mode) > eth_dev->data->nb_rx_queues =3D (uint16_t)1; > eth_dev->data->nb_tx_queues =3D (uint16_t)1; >=20 > - eth_dev->data->mac_addrs =3D rte_zmalloc_socket(name, > ETHER_ADDR_LEN, 0, > - socket_id); > + /* Allocate memory for storing MAC addresses */ > + eth_dev->data->mac_addrs =3D rte_zmalloc_socket(name, > ETHER_ADDR_LEN * > + BOND_MAX_MAC_ADDRS, 0, socket_id); > if (eth_dev->data->mac_addrs =3D=3D NULL) { > - RTE_BOND_LOG(ERR, "Unable to malloc mac_addrs"); > + RTE_BOND_LOG(ERR, > + "Failed to allocate %u bytes needed to store MAC > addresses", > + ETHER_ADDR_LEN * BOND_MAX_MAC_ADDRS); > goto err; > } >=20 > diff --git a/drivers/net/bonding/rte_eth_bond_private.h > b/drivers/net/bonding/rte_eth_bond_private.h > index 65445b863..43e0e448d 100644 > --- a/drivers/net/bonding/rte_eth_bond_private.h > +++ b/drivers/net/bonding/rte_eth_bond_private.h > @@ -230,6 +230,14 @@ mac_address_get(struct rte_eth_dev *eth_dev, struct > ether_addr *dst_mac_addr); int mac_address_slaves_update(struct > rte_eth_dev *bonded_eth_dev); >=20 > +int > +slave_add_mac_addresses(struct rte_eth_dev *bonded_eth_dev, > + uint16_t slave_port_id); > + > +int > +slave_remove_mac_addresses(struct rte_eth_dev *bonded_eth_dev, > + uint16_t slave_port_id); > + > int > bond_ethdev_mode_set(struct rte_eth_dev *eth_dev, int mode); >=20 > -- > 2.16.1.windows.1