From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR03-AM5-obe.outbound.protection.outlook.com (mail-eopbgr30078.outbound.protection.outlook.com [40.107.3.78]) by dpdk.org (Postfix) with ESMTP id C8FC2324A for ; Tue, 28 Nov 2017 12:58:28 +0100 (CET) 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=5ZopAfI83rBIC8TSg8k8V19hI44hvUyslkDYIrIgM3Q=; b=dciHTj4GplaEpVT7zUVO/ptnkpwCppPp3HFwhhaYXYqgoeLE39VV4I5tu97bR6vUaovrRRIermPMK1fFkaoYiiNWsRiwxCNu8NIyYuLWfVVUHS/tyrtWiIgQvWzcaGjmbN9b4b/0Bqo+a9kL33NxLrcoHIH8cN0G06jj5qoPI4Y= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=matan@mellanox.com; Received: from mellanox.com (37.142.13.130) by VI1PR0502MB3663.eurprd05.prod.outlook.com (2603:10a6:803:f::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.260.4; Tue, 28 Nov 2017 11:58:26 +0000 From: Matan Azrad To: Thomas Monjalon , Gaetan Rivet , Jingjing Wu Cc: dev@dpdk.org Date: Tue, 28 Nov 2017 11:57:58 +0000 Message-Id: <1511870281-15282-3-git-send-email-matan@mellanox.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1511870281-15282-1-git-send-email-matan@mellanox.com> References: <1511870281-15282-1-git-send-email-matan@mellanox.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [37.142.13.130] X-ClientProxiedBy: VI1PR0801CA0078.eurprd08.prod.outlook.com (2603:10a6:800:7d::22) To VI1PR0502MB3663.eurprd05.prod.outlook.com (2603:10a6:803:f::21) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 24d44c03-2c7e-4bdb-9fa8-08d5365755e6 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(5600026)(4604075)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(48565401081)(2017052603258); SRVR:VI1PR0502MB3663; X-Microsoft-Exchange-Diagnostics: 1; VI1PR0502MB3663; 3:4dWCBulniybPMjAgEBCRxVFRbtkcOY5oGzOOXEQdpWBSssrspKlOMAvFh0KgeMkzNqWk5P1r9ghg9eY2PxIgkxqVJw1pF8irULRjQgaAa3RXV5ShbnGh+u41YXeAuHFEQlv6JsurYBVayK+h5YYaURGu8cibA7bEVlO4tsl7Tc4OStij8IL734Dq+QS6nU+6Ictphqd1nwxTsgNXKWW5scKwPrwTLhxjkZcEjlqkgtb86p2algS1IcVVNhsuJPs8; 25:SdtRHFdygVSh0ibXt1isPqJW76OFswcPN1E0Umsi6telaMSQu6IwAoO5kYLEs06awckgYZ8qc2vfOP6ggYHVnzsZqAld1cQOPrnMKSLGGzprdZE8IbkVQk+Lxs+Hk1wk/q2H+s7XPeeQMtDoj+OSHG56nJ8IfXZ0hPUi3Ja3UYM+rXoLi2eKetXPWdZYwJ5RwmZkzUP7Buc7Eh6Sv6x6zeyX8cHe6UsJC7fpeSgowMUa2ULilBbZlVW1Z407OClCfFHmiPQwP5Bl1fhmgfGM17KPiAxgJD6c1gsojPb6V5GEvckheAysjQ5FxjCDHVeVMuymXPZ4wIlEwDZN4MuZoQ==; 31:MaGoSWeM98FFgsDcxfXOZ0kvjP5YX/a6IwE/s/JPbQ+Xpc5XhgiMvDfqLLl9zdg+ixHgl/fHIew9IvmaUrO9mdyaA2ilXPEGx9CD8PA9gmRt+bXcFppD2pAiriYJ+UMzfAty8A50AYO1LZYvsmBqMkxpcOAPo6faNmby37+HWj91h0keaD74EjzHXJP0p1d/NPf0rdAHtJzJ1AYOvHuBBxEKPKiirr0ZFKnK3AOERsA= X-MS-TrafficTypeDiagnostic: VI1PR0502MB3663: X-LD-Processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr X-Microsoft-Exchange-Diagnostics: 1; VI1PR0502MB3663; 20:mlfw6+QEPAzoDx60krEelweZqF+Kqw/s5TbBv98IeSig3etBz7w/SYQuAP1shzBy/ziZ/mw6nTv5xQBZN78mkw5Mbpr5Ic+xp+/9eZRR3xdNWDrNhcIVyS7CfvrIuX3bPGvWH/N7yBA0/O2ReAEHX2S0NpS7ZsydzA/kD/sD4TLqvBjEIQ7ZzkUtFdm/7VTbO+aZ+UgcveewS9dZ/BfeM54YQI21OEGQ6AOhmeYGGsmnXl4uSUUIxZF16PtKqFIW96sMz/XAagsIDA+AqbHhJ9DtFBolgLZEcmeDHP/+ibxN7sTb6okV7aTxrz/5FEXoG1rGzKjyjM+hnvIISZEMgvcX9LM87OhSU0imgbWemMsdtmQLE1k2SnvAmB4kBGq4GWsNSAprfX4lHz49rMTKbc64qB3tZ7MRpb6tnjy3+K+f/1fQx0RHqQ/qityFnoDktXAYCgQiA8z6s05AShmcRKmqtn2hYrUDtI17rCqtx6tXlbi7hr/Rl+7tNbxZsnlD; 4:pxrvgAe/ictuJ/nWZ5WPDhi2bTXEMqvq+kAaMcj+A0plqSbn86hhYp2L38fOwK694ShmCJ9lvazcBPs26pNYqpm71AUVfr6hcOzryFHiFJvbmZR6+vBaBidmSb8rZx1hp0KhJUpae3pZpnMqoaD/YSog8R/kMDbU18P/CLf9QQ86TrZZnEC+UhfQyzpeLnUKzwondY9uy5FhVTxVoGlW4adhAp0T3+ujyoDw8tv1iF2GPGq3Gi7Qiv56tPLTw8o1QcAdbm4OKhYaCQ84B9EsyvFCCrm0ULfhmTEUbpsh1cFwZSAT8L4J0KmhogwzSruL2cOXIPq0r6MCGSl1c8o5XhKvKdaD4+EfkTxWOfxPDI8= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(60795455431006)(278428928389397); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(2401047)(5005006)(8121501046)(3002001)(10201501046)(93006095)(93001095)(3231022)(6055026)(6041248)(20161123564025)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(20161123562025)(20161123560025)(6072148)(201708071742011); SRVR:VI1PR0502MB3663; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:VI1PR0502MB3663; X-Forefront-PRVS: 0505147DDB X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(376002)(39860400002)(346002)(366004)(199003)(189002)(4720700003)(50226002)(189998001)(8936002)(3846002)(97736004)(110136005)(5890100001)(2950100002)(6666003)(54075001)(6116002)(47776003)(316002)(5660300001)(16586007)(50986999)(105586002)(305945005)(76176999)(16526018)(106356001)(66066001)(21086003)(81156014)(69596002)(48376002)(50466002)(101416001)(4326008)(52116002)(55016002)(7696005)(25786009)(2906002)(51416003)(8676002)(33646002)(53936002)(68736007)(36756003)(86362001)(478600001)(33026002)(575784001)(7736002)(81166006); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR0502MB3663; H:mellanox.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX: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; VI1PR0502MB3663; 23:LIkefPnQwt9vO6eu+9rgNTw+ostPlq0Uhb+7pDB?= =?us-ascii?Q?QTQtmqiw2ukVcCxafLG5pJy/5e2MSfH16/8GLy6GrXKyVHx/Iz3ifef8jyna?= =?us-ascii?Q?mexiv4TCQNaey47/W7iV3egoXTsG+ulQb9ys8tUd51w7ImgRTmUZmM+gatJh?= =?us-ascii?Q?lVTpzWMJsjBnsD7r8lYNPHv+ly9UKD7Kc3r4/YeZpQ/a3DS+i1RsV5eCSvzk?= =?us-ascii?Q?YQz9na7QTA6nFDsbkKHXKBp0QT7a5Syr4mYK8ih8SCRMNs5+7J5Dk1Tm+jpm?= =?us-ascii?Q?q7nv8UZjAEv+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agnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Nov 2017 11:58:26.7306 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 24d44c03-2c7e-4bdb-9fa8-08d5365755e6 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0502MB3663 Subject: [dpdk-dev] [PATCH 2/5] ethdev: add port ownership 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, 28 Nov 2017 11:58:29 -0000 The ownership of a port is implicit in DPDK. Making it explicit is better from the next reasons: 1. It may be convenient for multi-process applications to know which process is in charge of a port. 2. A library could work on top of a port. 3. A port can work on top of another port. Also in the fail-safe case, an issue has been met in testpmd. We need to check that the user is not trying to use a port which is already managed by fail-safe. Add ownership mechanism to DPDK Ethernet devices to avoid multiple management of a device by different DPDK entities. A port owner is built from owner id(number) and owner name(string) while the owner id must be unique to distinguish between two identical entity instances and the owner name can be any name. The name helps to logically recognize the owner by different DPDK entities and allows easy debug. Each DPDK entity can allocate an owner unique identifier and can use it and its preferred name to owns valid ethdev ports. Each DPDK entity can get any port owner status to decide if it can manage the port or not. The current ethdev internal port management is not affected by this feature. Signed-off-by: Matan Azrad --- doc/guides/prog_guide/poll_mode_drv.rst | 12 +++- lib/librte_ether/rte_ethdev.c | 121 ++++++++++++++++++++++++++++++++ lib/librte_ether/rte_ethdev.h | 86 +++++++++++++++++++++++ lib/librte_ether/rte_ethdev_version.map | 12 ++++ 4 files changed, 230 insertions(+), 1 deletion(-) diff --git a/doc/guides/prog_guide/poll_mode_drv.rst b/doc/guides/prog_guide/poll_mode_drv.rst index 6a0c9f9..af639a1 100644 --- a/doc/guides/prog_guide/poll_mode_drv.rst +++ b/doc/guides/prog_guide/poll_mode_drv.rst @@ -156,7 +156,7 @@ concurrently on the same tx queue without SW lock. This PMD feature found in som See `Hardware Offload`_ for ``DEV_TX_OFFLOAD_MT_LOCKFREE`` capability probing details. -Device Identification and Configuration +Device Identification, Ownership and Configuration --------------------------------------- Device Identification @@ -171,6 +171,16 @@ Based on their PCI identifier, NIC ports are assigned two other identifiers: * A port name used to designate the port in console messages, for administration or debugging purposes. For ease of use, the port name includes the port index. +Port Ownership +~~~~~~~~~~~~~ +The Ethernet devices ports can be owned by a single DPDK entity (application, library, PMD, process, etc). +The ownership mechanism is controlled by ethdev APIs and allows to set/remove/get a port owner by DPDK entities. +Allowing this should prevent any multiple management of Ethernet port by different entities. + +.. note:: + + It is the DPDK entity responsibility either to check the port owner before using it or to set the port owner to prevent others from using it. + Device Configuration ~~~~~~~~~~~~~~~~~~~~ diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index 2d754d9..836991e 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -71,6 +71,7 @@ static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data"; struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS]; static struct rte_eth_dev_data *rte_eth_dev_data; +static uint16_t rte_eth_next_owner_id = RTE_ETH_DEV_NO_OWNER + 1; static uint8_t eth_dev_last_created_port; /* spinlock for eth device callbacks */ @@ -278,6 +279,7 @@ struct rte_eth_dev * if (eth_dev == NULL) return -EINVAL; + memset(ð_dev->data->owner, 0, sizeof(struct rte_eth_dev_owner)); eth_dev->state = RTE_ETH_DEV_UNUSED; return 0; } @@ -293,6 +295,125 @@ struct rte_eth_dev * return 1; } +static int +rte_eth_is_valid_owner_id(uint16_t owner_id) +{ + if (owner_id == RTE_ETH_DEV_NO_OWNER || + (rte_eth_next_owner_id != RTE_ETH_DEV_NO_OWNER && + rte_eth_next_owner_id <= owner_id)) { + RTE_LOG(ERR, EAL, "Invalid owner_id=%d.\n", owner_id); + return 0; + } + return 1; +} + +uint16_t +rte_eth_find_next_owned_by(uint16_t port_id, const uint16_t owner_id) +{ + while (port_id < RTE_MAX_ETHPORTS && + (rte_eth_devices[port_id].state != RTE_ETH_DEV_ATTACHED || + rte_eth_devices[port_id].data->owner.id != owner_id)) + port_id++; + + if (port_id >= RTE_MAX_ETHPORTS) + return RTE_MAX_ETHPORTS; + + return port_id; +} + +int +rte_eth_dev_owner_new(uint16_t *owner_id) +{ + if (rte_eal_process_type() != RTE_PROC_PRIMARY) { + RTE_PMD_DEBUG_TRACE("Not primary process cannot own ports.\n"); + return -EPERM; + } + if (rte_eth_next_owner_id == RTE_ETH_DEV_NO_OWNER) { + RTE_PMD_DEBUG_TRACE("Reached maximum number of Ethernet port owners.\n"); + return -EUSERS; + } + *owner_id = rte_eth_next_owner_id++; + return 0; +} + +int +rte_eth_dev_owner_set(const uint16_t port_id, + const struct rte_eth_dev_owner *owner) +{ + struct rte_eth_dev_owner *port_owner; + int ret; + + RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); + if (rte_eal_process_type() != RTE_PROC_PRIMARY) { + RTE_PMD_DEBUG_TRACE("Not primary process cannot own ports.\n"); + return -EPERM; + } + if (!rte_eth_is_valid_owner_id(owner->id)) + return -EINVAL; + port_owner = &rte_eth_devices[port_id].data->owner; + if (port_owner->id != RTE_ETH_DEV_NO_OWNER && + port_owner->id != owner->id) { + RTE_LOG(ERR, EAL, + "Cannot set owner to port %d already owned by %s_%05d.\n", + port_id, port_owner->name, port_owner->id); + return -EPERM; + } + ret = snprintf(port_owner->name, RTE_ETH_MAX_OWNER_NAME_LEN, "%s", + owner->name); + if (ret < 0 || ret >= RTE_ETH_MAX_OWNER_NAME_LEN) { + memset(port_owner->name, 0, RTE_ETH_MAX_OWNER_NAME_LEN); + RTE_LOG(ERR, EAL, "Invalid owner name.\n"); + return -EINVAL; + } + port_owner->id = owner->id; + RTE_PMD_DEBUG_TRACE("Port %d owner is %s_%05d.\n", port_id, + owner->name, owner->id); + return 0; +} + +int +rte_eth_dev_owner_remove(const uint16_t port_id, const uint16_t owner_id) +{ + struct rte_eth_dev_owner *port_owner; + RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); + if (!rte_eth_is_valid_owner_id(owner_id)) + return -EINVAL; + port_owner = &rte_eth_devices[port_id].data->owner; + if (port_owner->id != owner_id) { + RTE_LOG(ERR, EAL, + "Cannot remove port %d owner %s_%05d by different owner id %5d.\n", + port_id, port_owner->name, port_owner->id, owner_id); + return -EPERM; + } + RTE_PMD_DEBUG_TRACE("Port %d owner %s_%05d has removed.\n", port_id, + port_owner->name, port_owner->id); + memset(port_owner, 0, sizeof(struct rte_eth_dev_owner)); + return 0; +} + +void +rte_eth_dev_owner_delete(const uint16_t owner_id) +{ + uint16_t p; + + if (!rte_eth_is_valid_owner_id(owner_id)) + return; + RTE_ETH_FOREACH_DEV_OWNED_BY(p, owner_id) + memset(&rte_eth_devices[p].data->owner, 0, + sizeof(struct rte_eth_dev_owner)); + RTE_PMD_DEBUG_TRACE("All port owners owned by " + "%05d identifier has removed.\n", owner_id); +} + +const struct rte_eth_dev_owner * +rte_eth_dev_owner_get(const uint16_t port_id) +{ + RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, NULL); + if (rte_eth_devices[port_id].data->owner.id == RTE_ETH_DEV_NO_OWNER) + return NULL; + return &rte_eth_devices[port_id].data->owner; +} + int rte_eth_dev_socket_id(uint16_t port_id) { diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h index 341c2d6..f54c26d 100644 --- a/lib/librte_ether/rte_ethdev.h +++ b/lib/librte_ether/rte_ethdev.h @@ -1760,6 +1760,15 @@ struct rte_eth_dev_sriov { #define RTE_ETH_NAME_MAX_LEN RTE_DEV_NAME_MAX_LEN +#define RTE_ETH_DEV_NO_OWNER 0 + +#define RTE_ETH_MAX_OWNER_NAME_LEN 64 + +struct rte_eth_dev_owner { + uint16_t id; /**< The owner unique identifier. */ + char name[RTE_ETH_MAX_OWNER_NAME_LEN]; /**< The owner name. */ +}; + /** * @internal * The data part, with no function pointers, associated with each ethernet device. @@ -1810,6 +1819,7 @@ struct rte_eth_dev_data { int numa_node; /**< NUMA node connection */ struct rte_vlan_filter_conf vlan_filter_conf; /**< VLAN filter configuration. */ + struct rte_eth_dev_owner owner; /**< The port owner. */ }; /** Device supports link state interrupt */ @@ -1846,6 +1856,82 @@ struct rte_eth_dev_data { /** + * Iterates over valid ethdev ports owned by a specific owner. + * + * @param port_id + * The id of the next possible valid owned port. + * @param owner_id + * The owner identifier. + * RTE_ETH_DEV_NO_OWNER means iterate over all valid ownerless ports. + * @return + * Next valid port id owned by owner_id, RTE_MAX_ETHPORTS if there is none. + */ +uint16_t rte_eth_find_next_owned_by(uint16_t port_id, const uint16_t owner_id); + +/** + * Macro to iterate over all enabled ethdev ports owned by a specific owner. + */ +#define RTE_ETH_FOREACH_DEV_OWNED_BY(p, o) \ + for (p = rte_eth_find_next_owned_by(0, o); \ + (unsigned int)p < (unsigned int)RTE_MAX_ETHPORTS; \ + p = rte_eth_find_next_owned_by(p + 1, o)) + +/** + * Get a new unique owner identifier. + * An owner identifier is used to owns Ethernet devices by only one DPDK entity + * to avoid multiple management of device by different entities. + * + * @param owner_id + * Owner identifier pointer. + * @return + * Negative errno value on error, 0 on success. + */ +int rte_eth_dev_owner_new(uint16_t *owner_id); + +/** + * Set an Ethernet device owner. + * + * @param port_id + * The identifier of the port to own. + * @param owner + * The owner pointer. + * @return + * Negative errno value on error, 0 on success. + */ +int rte_eth_dev_owner_set(const uint16_t port_id, + const struct rte_eth_dev_owner *owner); + +/** + * Remove Ethernet device owner to make the device ownerless. + * + * @param port_id + * The identifier of port to make ownerless. + * @param owner + * The owner identifier. + * @return + * 0 on success, negative errno value on error. + */ +int rte_eth_dev_owner_remove(const uint16_t port_id, const uint16_t owner_id); + +/** + * Remove owner from all Ethernet devices owned by a specific owner. + * + * @param owner + * The owner identifier. + */ +void rte_eth_dev_owner_delete(const uint16_t owner_id); + +/** + * Get the owner of an Ethernet device. + * + * @param port_id + * The port identifier. + * @return + * NULL when the device is ownerless, else the device owner pointer. + */ +const struct rte_eth_dev_owner *rte_eth_dev_owner_get(const uint16_t port_id); + +/** * Get the total number of Ethernet devices that have been successfully * initialized by the matching Ethernet driver during the PCI probing phase * and that are available for applications to use. These devices must be diff --git a/lib/librte_ether/rte_ethdev_version.map b/lib/librte_ether/rte_ethdev_version.map index e9681ac..7d07edb 100644 --- a/lib/librte_ether/rte_ethdev_version.map +++ b/lib/librte_ether/rte_ethdev_version.map @@ -198,6 +198,18 @@ DPDK_17.11 { } DPDK_17.08; +DPDK_18.02 { + global: + + rte_eth_find_next_owned_by; + rte_eth_dev_owner_new; + rte_eth_dev_owner_set; + rte_eth_dev_owner_remove; + rte_eth_dev_owner_delete; + rte_eth_dev_owner_get; + +} DPDK_17.11; + EXPERIMENTAL { global: -- 1.8.3.1