From patchwork Wed Mar 28 11:16:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matan Azrad X-Patchwork-Id: 36611 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6F31B2BB8; Wed, 28 Mar 2018 13:16:26 +0200 (CEST) Received: from EUR02-AM5-obe.outbound.protection.outlook.com (mail-eopbgr00057.outbound.protection.outlook.com [40.107.0.57]) by dpdk.org (Postfix) with ESMTP id A3A692B9C for ; Wed, 28 Mar 2018 13:16:25 +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; bh=4hM0l/vCzYPMJwTFK2xieKnFKPwLi6h2ET4PuLsA0sA=; b=OfGEsBy59mwrqD+JdEDT675W3Jm5n1A0iWO9bYVx3tIlu5KCnJ5BX4KTpAAl5xAY+P/Ef86AztlhaWhXWbaeSJmDitX9i5jeKIgWVaDNF9DnQ4Gnl23DzD1bb81YvnPunmvJ1QG6lMJdnK3yImTM6e4TVOgXVUl9UHwRiP1skqk= Received: from mellanox.com (37.142.13.130) by VI1PR0501MB2669.eurprd05.prod.outlook.com (2603:10a6:800:9d::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.609.10; Wed, 28 Mar 2018 11:16:22 +0000 From: Matan Azrad To: Declan Doherty Cc: dev@dpdk.org Date: Wed, 28 Mar 2018 11:16:01 +0000 Message-Id: <1522235761-21928-1-git-send-email-matan@mellanox.com> X-Mailer: git-send-email 1.9.5 MIME-Version: 1.0 X-Originating-IP: [37.142.13.130] X-ClientProxiedBy: AM3PR04CA0142.eurprd04.prod.outlook.com (2603:10a6:207::26) To VI1PR0501MB2669.eurprd05.prod.outlook.com (2603:10a6:800:9d::19) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 7f7efe8a-9272-41dd-83c4-08d5949d5711 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:VI1PR0501MB2669; X-Microsoft-Exchange-Diagnostics: 1; VI1PR0501MB2669; 3:ndW7BjRZJrW66ixX/44H9//mY/BNTmGNMW6x0aEV58U0m1HyHx5NIwYfeecC+sJq1ULrIWagdV3oFSzHbRBVFgjTnTDD5CTcsASA4eO8gjEL3sdRtji5YorowNGk7y9StXuE9NMc+7gyjjVxKnL3vFWLgPDFOjSDq7A8fmJ5I86dFFpmQGxwdODcV090MKwpIpv+ebPVdrzaoVJt5ZWsp1IobWQf1hd6cW7Ix613KEgSIlSp8SijvyS5lO64PSib; 25:Uxe98B2A4/5AJ50/w32NZ8A3dd3rXEc8E0eGjpdXeinmVngm2GbXDZOL7mNk396oqelQKgsUIrHTcBsP8dqPKpaxMioMoyKKPDZxy1/2h6FCpU+vhe4RAGgCelcMebRbMb5LD5VFgKwR/aeX2HF8siVM4tRdZkUV/hViKQcjp+t3XRkbUF9AxzKuDr5gjw0LsphJbPfkp8SPBwsP99eC3pKR99O9zush0yTp8VfGXpma9iNU6qWNUJb1snUe/qqEVLvnQ96bFxaH16F9cqa9RLiE1Cex3a5Qw5OrLYy3/rUaOWayfGiTFTFP/u8s3OQ0yDDX3WaaPIPnK5NHSzxsow==; 31:GcRUlqkKC97Gra2++IhEJqbbhZ31NGwLF0KXLGpJ/8oisPx2xHt+JU9pDWlzWptdE4g7qDjV7p2TdygIqsTOh3w6dVJ4C0SQ3TSJk/9Sa8YGld/xdfwXwtXvT24X68gu+t4XSnFR0/IMgL9GgSYzAQApjkTTE0SnAlwRYFGs34lBLrsoq6RUQ3xZtqQQmDSeV4X7ghG/2GLsZihrooaKayLJN3Fo/WO0EP7E1+JzaNs= X-MS-TrafficTypeDiagnostic: VI1PR0501MB2669: Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=matan@mellanox.com; X-Microsoft-Exchange-Diagnostics: 1; VI1PR0501MB2669; 20:g59hJky4OWK/s+zgXnzt6tZzniThy6U2eaOkFbntLzpK1ATTEVnvKPP60YbetwhvyNoFK5YQ5oAk/8AL+C8cbtWdcKEBPefsR39CkBJLu5zNOEknEwchoqxhaFek38VBjgar+31qDedtK0XFsYjKxf7iiOtlsBRqLNFe27ga9qeQL7CVS6SIAfvfZUZFrMgqR9+gYGuJjucA4q9OvHKF4W+vxrrVDDbC0MlRPPHxiIvU4sfiISTkNvbnXxjJHVcPmZORxlaD3y6e/ltpcDtLeg3rnXDHi6VM069l4LNOhgDeLJLt5VF+oI4EzF2igNZa6pxpdve9wYsBXpSq6ppTag70xNpaQZO5PapxHLrSWUCz/LLMEtvBIaLvr1OvhGRhJC4Y0wgY0/V2RCnvQvBVr9Gj/kc+CHGKfmnho5dw1PKFgtJyeFavmGTGS31AGvlo0qpFZTC4Fe1uIw5kbe/by5v6HwpoKKbnfI0bs8LYObi6q4ClgF8oZaepGwzwtrbz; 4:4yMlkCAQTq6rofD52WLf277kSzTr8eo3cp32l1P5IapXr6LuxbOC+TIIvISmYsJd0PyJN1JcA6iigbZ+UTRPW5DzCfZRoUTDvfiS1VNuLkz4I+BT4Mkl3sgW74ZHgCHnoJomT75fN0MyKo1XqATXgQDfdo6wEgV5jbEG3fZoWcVurLWsecYpeiKN7yIa2lZZkHIz+m965NMg96PvzHaJDj2OjLl4gV7/kJtOM9MAvrlPNHjQvkar1W4x+bWQCev7NTXptrvVZJUz3l50Vfwl1Q== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3231221)(944501327)(52105095)(10201501046)(3002001)(93006095)(93001095)(6055026)(6041310)(20161123562045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123558120)(6072148)(201708071742011); SRVR:VI1PR0501MB2669; BCL:0; PCL:0; RULEID:; SRVR:VI1PR0501MB2669; X-Forefront-PRVS: 06259BA5A2 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(979002)(366004)(346002)(376002)(39380400002)(396003)(39860400002)(189003)(199004)(53936002)(48376002)(8936002)(50466002)(476003)(486005)(105586002)(69596002)(50226002)(486005)(55016002)(86362001)(6666003)(33026002)(956004)(2616005)(7696005)(386003)(68736007)(59450400001)(51416003)(52116002)(6916009)(16586007)(7736002)(26005)(25786009)(36756003)(305945005)(478600001)(1857600001)(6116002)(5660300001)(21086003)(3846002)(106356001)(66066001)(97736004)(81156014)(81166006)(8676002)(316002)(16526019)(4326008)(47776003)(186003)(2906002)(969003)(989001)(999001)(1009001)(1019001); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR0501MB2669; H:mellanox.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR0501MB2669; 23:RQ6MFGShrSghlJkbgJ3AlgUiTM8AeT1Ew6zcD7/?= la3eH2Hnyz/OwJKDc/xG3coWlGr9iYyJuw3IQrfxTE+Cq3upGBUITr3Z/9uqgv9qOLdMyIJWC/8QfFj+saq7QUwiGUPqW7aBiUlpWsoQg4atalPN0hkWHLsOvuBai+HGg4T484RaQGXoSmc47UaZAixJRwPIs7Lhjis51Cz1gdU6htcdcA2rvfAswtmzwtZZPbebLDWmxb51h0eaMu+rIpGdguHTIm49YWwbayKnnn/QWic8IDPHNMRX9BtpztNdXACC7nT/Gnsai+kf9p91463ZZSMhstUK1+HHnh+eR6KiTFXBXUDn5VTnx3CVLLq+D72tQ+Jo0X+4cuWEyliEbWBCRU9eNjXpniJ9/uCBDwUiZAMb8Vsm4fR9cWaOXkQJbzgJTeQY9hVsIbgqh/pT9oetMQtkYgI2OU0KzobaWFY0U5YfWpXwNsO5IOdtvSQltSQsyCSROGwLhRlBEMDrLcP9Mj0YiTzOWKrRwMe1bhWUwCYDLY4WqlurIlPVX7GJTiUymMOh3Kl4St4ypnXtEQW8N7XfRnmjDGYtKyY2J+/foEtjkhY1Tq57W4ycI6dFWPOQhHXvn1WXrqp8qmuBzky3K72Eb++WB5mHu06xvi+kAfo6cXNgN3alHBoAIlzpinhYw+gq5tikt77OB2Amu2Sn+jOvg0axFLY4ySmq4BRv/pBXvBNwiJDbh20uv+miKX2cuJwW/xY4eFLfY1pisZv6cgkxjk9XjDgKKfHpxqS6rkQFUwrU8UQI48fhicUbjy9SG/2Nn5I26t2XcI3c33IwkC8i+o36RZj54WEzz/YtJ2SNKWd9GfDUtp0wS9jQjt9VQpQ87R3VGX3tMXJyDbVOAjUhwFn6V8zGQboFf6iC+Hek8vAicxaVMUCKbdDJzZzGYbtt7JXMBubvH+5+kNAGqg1xbfosJNxhDXhqJWsd4Q14+yB+BsBKWu3Z0flYJmQqJvTdGFExQFs56iL0ZO+ACE/VXuHGhFloXlv3DhHUU/HgsMFVr9VFxoLvdccP6Zo7p4v6VQTWHZkvELFKSFU1Xe6RLk/Jtx3IWXFjqg1bEOlkIGNdHw2QR/GGcpWtJqIWjps2BeOpkGJIYW/3zQS17pNnPqJCI8+qjN0J4XaKcuamr8MaUJ169st8EkGO6hn9c6P/g67udGaCcYZB+bvy+aTDxpGDRU3jJczyPZIAU0odBil82NwSbb1CI3u9MsCoxOIarwNLDtEjy14Qk/NiRs1C7bzn27WLkf137QT22ajY7fVbsiBC2YlVxpAwQLdqIXEyeJJPQXITE+SKT6hbs X-Microsoft-Antispam-Message-Info: yUF8H0r+O1kJlod1Yg1h1TI+Vk/3MLptXtAWp4Rn+U8layHNi/XppjVtoWkEaSqmctHVT43G+e6rh1i+QrrW/tB09EOq0mTzgfaFj0jXUz/aqzjriEBfoxGglO1yqpVDVj9zhFf6eZfKjI8dMMbQV7ootfjVxgr7Ssay6dI7LG4UpfRAN0tmM1NS8nW/h7bp X-Microsoft-Exchange-Diagnostics: 1; VI1PR0501MB2669; 6:3iXKdqTSyLQV8AccS2sMDrXYYtJ7kdeAAS2ElRWG3ZCPaDT75RWKPiPDvLCTTAshQiRYjpUkNLGEl7Fj61iLbZMDEj/MQDwPV8gCjjHdvKhF8R0nBKqYIn1PPyeywCjR/2a68RHtfKfolkWMqlJcIDfgi/+iA6TOVpBlQV1Y5JAypxaYrR2BCzvFLODBzEXVeIYWvea4z2tw6Wzb0iGR695X5S5iClBz/xeWKxbR2/jpE9Aw0s4RUlK+gi94Ffmba8pKdCrN2cM6ZefEgQnTu5n7pGMV/viRl2Mxl3s4ZIzT2zxd3RUqUVLseePia5RrC503fuaHNl357frysnyRp/dOJMPedqrxvgv9qZEz8GH3SsqBlHsaN6I1iPEMB0lJp4IZ7lhWCZjNgC9KaO/O5pejSUv+FkLZOzsbYNSCi/VxkFOFyvZoKaRUZMoAagYCP6Jx87doL836fmOglsjfvw==; 5:ykOaswWBSk+7t73ODjFh8MnubFqUkzUejHvJtzY0tnoJyEzd8gci9/0wnqU2hls88e8T93ik2x3K940rM/3DBIlIE42paMD30bG5z1f0p9X5i7ktTdCZXXJ3PiiClbdE4VTl/3/I7IoTkH0crjdfVKl4pelXHfPMFL0zyr2/5Rs=; 24:XUflS2g3YBJxBfpg6RXdcnYOk0FIiDTJIdU8uG8Tr2Nqe1cZURo2IvKQu8WXsNmIEBlryZ4WYKtcynZtlGBFukad37klX5YjqCv+cmIAgDM= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; VI1PR0501MB2669; 7:fyc+z/sdErSstXg1PuviWGpjPCbKmT2H65LpcIfYwUEpRzvA6uMsqHTyBzoZNyd2xUId94YmSJJ/gkSyEmIGLSFLZ6sHP+3W4M8pw78qTkrCggG2bo4/gInj9DoMJ6Sj+TWP3/XbboB4dhPmP0xcQM7xkbK06dGPlXWN8APxi1utv3k4I/zvAmUMfuznu+4rsIy3qrDQgEm2nVYXMwXQs8ihpsynNKOa9XpLytxz2yy/SSrNHwl/kKOnepZd2+bY X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Mar 2018 11:16:22.7616 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7f7efe8a-9272-41dd-83c4-08d5949d5711 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0501MB2669 Subject: [dpdk-dev] [PATCH] net/bonding: add rte flow support 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Ethernet devices which are grouped by bonding PMD, aka slaves, are sharing the same queues and RSS configurations and their Rx burst functions must be managed by the bonding PMD according to the bonding architectuer. So, it makes sense to configure the same flow rules for all the bond slaves to allow consistency in packet flow management. Add rte flow support to the bonding PMD to manage all flow configuration to the bonded slaves. Signed-off-by: Matan Azrad Acked-by: Declan Doherty --- .../prog_guide/link_bonding_poll_mode_drv_lib.rst | 43 +++- drivers/net/bonding/Makefile | 1 + drivers/net/bonding/meson.build | 2 +- drivers/net/bonding/rte_eth_bond_api.c | 63 ++++++ drivers/net/bonding/rte_eth_bond_flow.c | 227 +++++++++++++++++++++ drivers/net/bonding/rte_eth_bond_pmd.c | 30 ++- drivers/net/bonding/rte_eth_bond_private.h | 20 ++ 7 files changed, 381 insertions(+), 5 deletions(-) create mode 100644 drivers/net/bonding/rte_eth_bond_flow.c diff --git a/doc/guides/prog_guide/link_bonding_poll_mode_drv_lib.rst b/doc/guides/prog_guide/link_bonding_poll_mode_drv_lib.rst index 0da1e63..56abee5 100644 --- a/doc/guides/prog_guide/link_bonding_poll_mode_drv_lib.rst +++ b/doc/guides/prog_guide/link_bonding_poll_mode_drv_lib.rst @@ -148,6 +148,8 @@ the RX and TX queues are also reconfigured using ``rte_eth_tx_queue_setup`` / ``rte_eth_rx_queue_setup`` with the parameters use to configure the bonding device. If RSS is enabled for bonding device, this mode is also enabled on new slave and configured as well. +Any flow which was configured to the bond device also is configured to the added +slave. Setting up multi-queue mode for bonding device to RSS, makes it fully RSS-capable, so all slaves are synchronized with its configuration. This mode is @@ -166,6 +168,43 @@ it can be easily used as a pattern providing expected behavior, even if slave RETAs' sizes are different. If RSS Key is not set for bonded device, it's not changed on the slaves and default key for device is used. +As RSS configurations, there is flow consistency in the bonded slaves for the +next rte flow operations: + +Validate: + - Validate flow for each slave, failure at least for one slave causes to + bond validation failure. + +Create: + - Create the flow in all slaves. + - Save all the slaves created flows objects in bonding internal flow + structure. + - Failure in flow creation for existed slave rejects the flow. + - Failure in flow creation for new slaves in slave adding time rejects + the slave. + +Destroy: + - Destroy the flow in all slaves and release the bond internal flow + memory. + +Flush: + - Destroy all the bonding PMD flows in all the slaves. + +.. note:: + + Don't call slaves flush directly, It destroys all the slave flows which + may include external flows or the bond internal LACP flow. + +Query: + - Summarize flow counters from all the slaves, relevant only for + ``RTE_FLOW_ACTION_TYPE_COUNT``. + +Isolate: + - Call to flow isolate for all slaves. + - Failure in flow isolation for existed slave rejects the isolate mode. + - Failure in flow isolation for new slaves in slave adding time rejects + the slave. + All settings are managed through the bonding port API and always are propagated in one direction (from bonding to slaves). @@ -207,8 +246,8 @@ common hash function available for each of them. Changing RSS key is only possible, when all slave devices support the same key size. To prevent inconsistency on how slaves process packets, once a device is added -to a bonding device, RSS configuration should be managed through the bonding -device API, and not directly on the slave. +to a bonding device, RSS and rte flow configurations should be managed through +the bonding device API, and not directly on the slave. Like all other PMD, all functions exported by a PMD are lock-free functions that are assumed not to be invoked in parallel on different logical cores to diff --git a/drivers/net/bonding/Makefile b/drivers/net/bonding/Makefile index 4a6633e..acad16a 100644 --- a/drivers/net/bonding/Makefile +++ b/drivers/net/bonding/Makefile @@ -27,6 +27,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_PMD_BOND) += rte_eth_bond_pmd.c SRCS-$(CONFIG_RTE_LIBRTE_PMD_BOND) += rte_eth_bond_args.c SRCS-$(CONFIG_RTE_LIBRTE_PMD_BOND) += rte_eth_bond_8023ad.c SRCS-$(CONFIG_RTE_LIBRTE_PMD_BOND) += rte_eth_bond_alb.c +SRCS-$(CONFIG_RTE_LIBRTE_PMD_BOND) += rte_eth_bond_flow.c # # Export include files diff --git a/drivers/net/bonding/meson.build b/drivers/net/bonding/meson.build index b90abc6..ba8480e 100644 --- a/drivers/net/bonding/meson.build +++ b/drivers/net/bonding/meson.build @@ -2,7 +2,7 @@ # Copyright(c) 2017 Intel Corporation name = 'bond' #, james bond :-) -sources = files('rte_eth_bond_api.c', 'rte_eth_bond_pmd.c', +sources = files('rte_eth_bond_api.c', 'rte_eth_bond_pmd.c','rte_eth_bond_flow.c', 'rte_eth_bond_args.c', 'rte_eth_bond_8023ad.c', 'rte_eth_bond_alb.c') deps += 'sched' # needed for rte_bitmap.h diff --git a/drivers/net/bonding/rte_eth_bond_api.c b/drivers/net/bonding/rte_eth_bond_api.c index f854b73..8464523 100644 --- a/drivers/net/bonding/rte_eth_bond_api.c +++ b/drivers/net/bonding/rte_eth_bond_api.c @@ -223,6 +223,49 @@ } static int +slave_rte_flow_prepare(uint16_t slave_id, struct bond_dev_private *internals) +{ + struct rte_flow *flow; + struct rte_flow_error ferror; + uint16_t slave_port_id = internals->slaves[slave_id].port_id; + + if (internals->flow_isolated_valid != 0) { + rte_eth_dev_stop(slave_port_id); + if (rte_flow_isolate(slave_port_id, internals->flow_isolated, + &ferror)) { + RTE_BOND_LOG(ERR, "rte_flow_isolate failed for slave" + " %d: %s", slave_id, ferror.message ? + ferror.message : "(no stated reason)"); + return -1; + } + } + TAILQ_FOREACH(flow, &internals->flow_list, next) { + flow->flows[slave_id] = rte_flow_create(slave_port_id, + &flow->fd->attr, + flow->fd->items, + flow->fd->actions, + &ferror); + if (flow->flows[slave_id] == NULL) { + RTE_BOND_LOG(ERR, "Cannot create flow for slave" + " %d: %s", slave_id, + ferror.message ? ferror.message : + "(no stated reason)"); + /* Destroy successful bond flows from the slave */ + TAILQ_FOREACH(flow, &internals->flow_list, next) { + if (flow->flows[slave_id] != NULL) { + rte_flow_destroy(slave_port_id, + flow->flows[slave_id], + &ferror); + flow->flows[slave_id] = NULL; + } + } + return -1; + } + } + return 0; +} + +static int __eth_bond_slave_add_lock_free(uint16_t bonded_port_id, uint16_t slave_port_id) { struct rte_eth_dev *bonded_eth_dev, *slave_eth_dev; @@ -316,6 +359,12 @@ bonded_eth_dev->data->dev_conf.rx_adv_conf.rss_conf.rss_hf &= internals->flow_type_rss_offloads; + if (slave_rte_flow_prepare(internals->slave_count, internals) != 0) { + RTE_BOND_LOG(ERR, "Failed to prepare new slave flows: port=%d", + slave_port_id); + return -1; + } + internals->slave_count++; if (bonded_eth_dev->data->dev_started) { @@ -393,6 +442,8 @@ struct rte_eth_dev *bonded_eth_dev; struct bond_dev_private *internals; struct rte_eth_dev *slave_eth_dev; + struct rte_flow_error flow_error; + struct rte_flow *flow; int i, slave_idx; bonded_eth_dev = &rte_eth_devices[bonded_port_id]; @@ -432,6 +483,18 @@ rte_eth_dev_default_mac_addr_set(slave_port_id, &(internals->slaves[slave_idx].persisted_mac_addr)); + /* + * Remove bond device flows from slave device. + * Note: don't restore flow isolate mode. + */ + TAILQ_FOREACH(flow, &internals->flow_list, next) { + if (flow->flows[slave_idx] != NULL) { + rte_flow_destroy(slave_port_id, flow->flows[slave_idx], + &flow_error); + flow->flows[slave_idx] = NULL; + } + } + slave_eth_dev = &rte_eth_devices[slave_port_id]; slave_remove(internals, slave_eth_dev); slave_eth_dev->data->dev_flags &= (~RTE_ETH_DEV_BONDED_SLAVE); diff --git a/drivers/net/bonding/rte_eth_bond_flow.c b/drivers/net/bonding/rte_eth_bond_flow.c new file mode 100644 index 0000000..8093c04 --- /dev/null +++ b/drivers/net/bonding/rte_eth_bond_flow.c @@ -0,0 +1,227 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright 2018 Mellanox Technologies, Ltd + */ + +#include + +#include +#include +#include + +#include "rte_eth_bond_private.h" + +static struct rte_flow * +bond_flow_alloc(int numa_node, const struct rte_flow_attr *attr, + const struct rte_flow_item *items, + const struct rte_flow_action *actions) +{ + struct rte_flow *flow; + size_t fdsz; + + fdsz = rte_flow_copy(NULL, 0, attr, items, actions); + flow = rte_zmalloc_socket(NULL, sizeof(struct rte_flow) + fdsz, + RTE_CACHE_LINE_SIZE, numa_node); + if (unlikely(flow == NULL)) { + RTE_BOND_LOG(ERR, "Could not allocate new flow"); + return NULL; + } + flow->fd = (void *)((uintptr_t)flow + sizeof(*flow)); + if (unlikely(rte_flow_copy(flow->fd, fdsz, attr, items, actions) != + fdsz)) { + RTE_BOND_LOG(ERR, "Failed to copy flow description"); + rte_free(flow); + return NULL; + } + return flow; +} + +static void +bond_flow_release(struct rte_flow **flow) +{ + rte_free(*flow); + *flow = NULL; +} + +static int +bond_flow_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr, + const struct rte_flow_item patterns[], + const struct rte_flow_action actions[], + struct rte_flow_error *err) +{ + struct bond_dev_private *internals = dev->data->dev_private; + int i; + int ret; + + for (i = 0; i < internals->slave_count; i++) { + ret = rte_flow_validate(internals->slaves[i].port_id, attr, + patterns, actions, err); + if (ret) { + RTE_BOND_LOG(ERR, "Operation rte_flow_validate failed" + " for slave %d with error %d", i, ret); + return ret; + } + } + return 0; +} + +static struct rte_flow * +bond_flow_create(struct rte_eth_dev *dev, const struct rte_flow_attr *attr, + const struct rte_flow_item patterns[], + const struct rte_flow_action actions[], + struct rte_flow_error *err) +{ + struct bond_dev_private *internals = dev->data->dev_private; + struct rte_flow *flow; + int i; + + flow = bond_flow_alloc(dev->data->numa_node, attr, patterns, actions); + if (unlikely(flow == NULL)) { + rte_flow_error_set(err, ENOMEM, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, rte_strerror(ENOMEM)); + return NULL; + } + for (i = 0; i < internals->slave_count; i++) { + flow->flows[i] = rte_flow_create(internals->slaves[i].port_id, + attr, patterns, actions, err); + if (unlikely(flow->flows[i] == NULL)) { + RTE_BOND_LOG(ERR, "Failed to create flow on slave %d", + i); + goto err; + } + } + TAILQ_INSERT_TAIL(&internals->flow_list, flow, next); + return flow; +err: + /* Destroy all slaves flows. */ + for (i = 0; i < internals->slave_count; i++) { + if (flow->flows[i] != NULL) + rte_flow_destroy(internals->slaves[i].port_id, + flow->flows[i], err); + } + bond_flow_release(&flow); + return NULL; +} + +static int +bond_flow_destroy(struct rte_eth_dev *dev, struct rte_flow *flow, + struct rte_flow_error *err) +{ + struct bond_dev_private *internals = dev->data->dev_private; + int i; + int ret = 0; + + for (i = 0; i < internals->slave_count; i++) { + int lret; + + if (unlikely(flow->flows[i] == NULL)) + continue; + lret = rte_flow_destroy(internals->slaves[i].port_id, + flow->flows[i], err); + if (unlikely(lret != 0)) { + RTE_BOND_LOG(ERR, "Failed to destroy flow on slave %d:" + " %d", i, lret); + ret = lret; + } + } + TAILQ_REMOVE(&internals->flow_list, flow, next); + bond_flow_release(&flow); + return ret; +} + +static int +bond_flow_flush(struct rte_eth_dev *dev, struct rte_flow_error *err) +{ + struct bond_dev_private *internals = dev->data->dev_private; + struct rte_flow *flow; + void *tmp; + int ret = 0; + int lret; + + /* Destroy all bond flows from its slaves instead of flushing them to + * keep the LACP flow or any other external flows. + */ + TAILQ_FOREACH_SAFE(flow, &internals->flow_list, next, tmp) { + lret = bond_flow_destroy(dev, flow, err); + if (unlikely(lret != 0)) + ret = lret; + } + if (unlikely(ret != 0)) + RTE_BOND_LOG(ERR, "Failed to flush flow in all slaves"); + return ret; +} + +static int +bond_flow_query_count(struct rte_eth_dev *dev, struct rte_flow *flow, + struct rte_flow_query_count *count, + struct rte_flow_error *err) +{ + struct bond_dev_private *internals = dev->data->dev_private; + struct rte_flow_query_count slave_count; + int i; + int ret; + + count->bytes = 0; + count->hits = 0; + rte_memcpy(&slave_count, count, sizeof(slave_count)); + for (i = 0; i < internals->slave_count; i++) { + ret = rte_flow_query(internals->slaves[i].port_id, + flow->flows[i], RTE_FLOW_ACTION_TYPE_COUNT, + &slave_count, err); + if (unlikely(ret != 0)) { + RTE_BOND_LOG(ERR, "Failed to query flow on" + " slave %d: %d", i, ret); + return ret; + } + count->bytes += slave_count.bytes; + count->hits += slave_count.hits; + slave_count.bytes = 0; + slave_count.hits = 0; + } + return 0; +} + +static int +bond_flow_query(struct rte_eth_dev *dev, struct rte_flow *flow, + enum rte_flow_action_type type, void *arg, + struct rte_flow_error *err) +{ + switch (type) { + case RTE_FLOW_ACTION_TYPE_COUNT: + return bond_flow_query_count(dev, flow, arg, err); + default: + return rte_flow_error_set(err, ENOTSUP, + RTE_FLOW_ERROR_TYPE_ACTION, arg, + rte_strerror(ENOTSUP)); + } +} + +static int +bond_flow_isolate(struct rte_eth_dev *dev, int set, + struct rte_flow_error *err) +{ + struct bond_dev_private *internals = dev->data->dev_private; + int i; + int ret; + + for (i = 0; i < internals->slave_count; i++) { + ret = rte_flow_isolate(internals->slaves[i].port_id, set, err); + if (unlikely(ret != 0)) { + RTE_BOND_LOG(ERR, "Operation rte_flow_isolate failed" + " for slave %d with error %d", i, ret); + internals->flow_isolated_valid = 0; + return ret; + } + } + internals->flow_isolated = set; + internals->flow_isolated_valid = 1; + return 0; +} + +const struct rte_flow_ops bond_flow_ops = { + .validate = bond_flow_validate, + .create = bond_flow_create, + .destroy = bond_flow_destroy, + .flush = bond_flow_flush, + .query = bond_flow_query, + .isolate = bond_flow_isolate, +}; diff --git a/drivers/net/bonding/rte_eth_bond_pmd.c b/drivers/net/bonding/rte_eth_bond_pmd.c index b59ba9f..3ced9dc 100644 --- a/drivers/net/bonding/rte_eth_bond_pmd.c +++ b/drivers/net/bonding/rte_eth_bond_pmd.c @@ -1958,10 +1958,19 @@ struct bwg_slave { slave_eth_dev->data->port_id) break; - if (i < (internals->slave_count - 1)) + if (i < (internals->slave_count - 1)) { + struct rte_flow *flow; + memmove(&internals->slaves[i], &internals->slaves[i + 1], sizeof(internals->slaves[0]) * (internals->slave_count - i - 1)); + TAILQ_FOREACH(flow, &internals->flow_list, next) { + memmove(&flow->flows[i], &flow->flows[i + 1], + sizeof(flow->flows[0]) * + (internals->slave_count - i - 1)); + flow->flows[internals->slave_count - 1] = NULL; + } + } internals->slave_count--; @@ -2180,6 +2189,7 @@ struct bwg_slave { struct bond_dev_private *internals = dev->data->dev_private; uint8_t bond_port_id = internals->port_id; int skipped = 0; + struct rte_flow_error ferror; RTE_LOG(INFO, EAL, "Closing bonded device %s\n", dev->device->name); while (internals->slave_count != skipped) { @@ -2194,6 +2204,7 @@ struct bwg_slave { skipped++; } } + bond_flow_ops.flush(dev, &ferror); bond_ethdev_free_queues(dev); rte_bitmap_reset(internals->vlan_filter_bmp); } @@ -2866,6 +2877,17 @@ struct bwg_slave { RTE_BOND_LOG(ERR, "Failed to update MAC address"); } +static int +bond_filter_ctrl(struct rte_eth_dev *dev __rte_unused, + enum rte_filter_type type, enum rte_filter_op op, void *arg) +{ + if (type == RTE_ETH_FILTER_GENERIC && op == RTE_ETH_FILTER_GET) { + *(const void **)arg = &bond_flow_ops; + return 0; + } + return -ENOTSUP; +} + const struct eth_dev_ops default_dev_ops = { .dev_start = bond_ethdev_start, .dev_stop = bond_ethdev_stop, @@ -2887,7 +2909,8 @@ struct bwg_slave { .rss_hash_update = bond_ethdev_rss_hash_update, .rss_hash_conf_get = bond_ethdev_rss_hash_conf_get, .mtu_set = bond_ethdev_mtu_set, - .mac_addr_set = bond_ethdev_mac_address_set + .mac_addr_set = bond_ethdev_mac_address_set, + .filter_ctrl = bond_filter_ctrl }; static int @@ -2953,6 +2976,9 @@ struct bwg_slave { memset(internals->active_slaves, 0, sizeof(internals->active_slaves)); memset(internals->slaves, 0, sizeof(internals->slaves)); + TAILQ_INIT(&internals->flow_list); + internals->flow_isolated_valid = 0; + /* Set mode 4 default configuration */ bond_mode_8023ad_setup(eth_dev, NULL); if (bond_ethdev_mode_set(eth_dev, mode)) { diff --git a/drivers/net/bonding/rte_eth_bond_private.h b/drivers/net/bonding/rte_eth_bond_private.h index 92e15f8..981c797 100644 --- a/drivers/net/bonding/rte_eth_bond_private.h +++ b/drivers/net/bonding/rte_eth_bond_private.h @@ -5,9 +5,12 @@ #ifndef _RTE_ETH_BOND_PRIVATE_H_ #define _RTE_ETH_BOND_PRIVATE_H_ +#include + #include #include #include +#include #include "rte_eth_bond.h" #include "rte_eth_bond_8023ad_private.h" @@ -37,6 +40,8 @@ extern struct rte_vdev_driver pmd_bond_drv; +extern const struct rte_flow_ops bond_flow_ops; + /** Port Queue Mapping Structure */ struct bond_rx_queue { uint16_t queue_id; @@ -80,6 +85,14 @@ struct bond_slave_details { uint16_t reta_size; }; +struct rte_flow { + TAILQ_ENTRY(rte_flow) next; + /* Slaves flows */ + struct rte_flow *flows[RTE_MAX_ETHPORTS]; + /* Flow description for synchronization */ + struct rte_flow_desc *fd; +}; + typedef void (*burst_xmit_hash_t)(struct rte_mbuf **buf, uint16_t nb_pkts, uint8_t slave_count, uint16_t *slaves); @@ -131,6 +144,13 @@ struct bond_dev_private { uint32_t rx_offload_capa; /** Rx offload capability */ uint32_t tx_offload_capa; /** Tx offload capability */ + /**< List of the configured flows */ + TAILQ_HEAD(sub_flows, rte_flow) flow_list; + + /**< Flow isolation state */ + int flow_isolated; + int flow_isolated_valid; + /** Bit mask of RSS offloads, the bit offset also means flow type */ uint64_t flow_type_rss_offloads;