From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-co1nam03on0049.outbound.protection.outlook.com [104.47.40.49]) by dpdk.org (Postfix) with ESMTP id 546EA3237 for ; Sun, 18 Dec 2016 15:22:37 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-cavium-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=H6ZY6zCc29GtoggtUsop0+NdQqbggqAchs2Y49k1hq0=; b=hmx6uFBs9Vv6eBKEKCZU+Tj+TkeKTLxOEHPCDOfu+GYQd5P4kb4gWTS3xw3wEPJwUJSnzp+b0Ml2gdJYDmC9luaEfm1U1Vcuw7GpzhiRNEQd766nGc7ZK7pGro98JoY1KKv0F2ITY5T2kFCWIhy+5H22iWliT+yU6OEqaYdlchs= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Jerin.Jacob@cavium.com; Received: from localhost.localdomain.localdomain (14.140.2.178) by CY1PR0701MB1725.namprd07.prod.outlook.com (10.163.21.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.789.14; Sun, 18 Dec 2016 14:22:32 +0000 From: Jerin Jacob To: CC: , , , , , Jerin Jacob Date: Sun, 18 Dec 2016 19:51:33 +0530 Message-ID: <1482070895-32491-5-git-send-email-jerin.jacob@caviumnetworks.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1482070895-32491-1-git-send-email-jerin.jacob@caviumnetworks.com> References: <1480798539-13360-1-git-send-email-jerin.jacob@caviumnetworks.com> <1482070895-32491-1-git-send-email-jerin.jacob@caviumnetworks.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [14.140.2.178] X-ClientProxiedBy: MAXPR01CA0003.INDPRD01.PROD.OUTLOOK.COM (10.164.147.10) To CY1PR0701MB1725.namprd07.prod.outlook.com (10.163.21.14) X-MS-Office365-Filtering-Correlation-Id: 65b0ffb6-a130-4f15-94fa-08d427514fc0 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:CY1PR0701MB1725; X-Microsoft-Exchange-Diagnostics: 1; CY1PR0701MB1725; 3:PclHsuNouVcxsry0jUb8hw8FomwPV5D3jTfQs4lr93xrA+UQXL8zt2YJybEPha1Mf3WkYhqLbLb3n1JzBPeWivKg+0LFb7/N7h0ltVM/tGXijPvmYo/BEeU++uokegpmUXbudu/qairTCOGlrw39pxKl9dELUp4Qp5QvsY3BX8Xu0H1nWn9yj5X/siUn9O/B/naOSWduSDqP1s45KIaFq05bRyCSkAVSDUw8C2N1ePshrvq0+Y9/zzbmFLyL/2/pixecG2ge3mMPmZiKv7/52A== X-Microsoft-Exchange-Diagnostics: 1; CY1PR0701MB1725; 25:SvOPaBM4iQx0jNqc8kTk/kQXwZIexS0CG20Mi0bSiKbppVK+LC2pAaNjFMUB0uR0xgGoJ0iTCEJSx8HemVO6wU8m0jgtnCVJmeoeylds+0Is4rE1hv+f538Wp/+ohZ7Ku3wm/JqwdnsIIqsvh2bT46OEMv+vVFKoTY4qfRNj7/y1saeDWLL7XBCip5ZTvq+mJJqPoOYhqeX1gOLWARuaQg44TS+M/JEDzlFoahysOqmqQT7DnBRr9r1su1YB0kOmHXmZzVkwsluVdkXjXW871xStWtdP/Di05IxNaTM1j8/LMXWGmNyrqv/fbtaZU6XykhEZ9KAV2zXU894/VMs3QZ3F1HGgmfjdrng6Dg3YPRcmRHIiVEG8cktAeo9dmxKFj+zJmXdCM7zVWscXhbNObrsUcb8M2PA14n7FfE+HGYrvabGaaaQQ8czCs6GSFBMjCRfELVFtCve6Zfs9bTbmK3eKwcGGpJGKS0TvY+Tm6cvYf7TsYl+OQFdwSNFEWCA/x91o1LN/enlr3LEnoYQdF71b7qAF7ZESdraTTds2sgeZtd75JyvqXfIw+8IXnb6LfDj1+AS72eJgvYUbYnEpYaq2hYoeznXD43ZLNYXVtV1Xqn57cEJnXnWsDh7NSdNyJd1aLZJTlwHrTnit0eLj1efqzGqGwc5fZRR5t9OPtEiNs27BTW5u8SNk1PsBy1T1VN/Tzj3I8VrfkLtLormOPuxGSbD/Ud2su1lrDg3JtSBTO2XQkI7viOZROaj/Y8is9LF6gOAc+inBnnsgv55mRlkA1x7/7ZN4/l7FWcw94mpQf7OCgBWA9b1jao0ic7o+aFOG5K+aRYTpbuy6QU71Sg== X-Microsoft-Exchange-Diagnostics: 1; CY1PR0701MB1725; 31:QFHDAou3v4/omXKZnDvEf5zubTzG/hr6hXevuO9kfdDoAxXwdHRhwQAOJuPJXf6kgJ5Dc1S/ltcTB8ZyzFM762kB53jS+ErLG8XFS0iFkN27NqaON7Il4fVaoTA4RjomdJlMAcM9T63wli6b/pvOPDZ10Rfqnxg4AI5+zblF1OiV4Kx855VQ03tHiv8AJiltSlk2B5GpJYczLtBIp5pW/NOqDYus7xBzyJAcqI0p/0s5rwSqwlhJ1oDags+lzJEINpIx2eyca3M7OnF3R53d5X7FTpF6NhUEgqR4SJYWLA4=; 20:WWPcEsST9iEXcbX/nFQjo1piQqaZg/0if+ONEB5vvbGw/zgX8jEttiX9ZvaS6/nADqsRPRlAINnvUGUCwCe/9zyuWcg2UZ8NU7YtsrguUb8YcxU6TN75dMm2eSb9YVzQ63Xc4qFgenXkCM+38/IkaJQ3a5wAeCU6SBNs0sCLY0I4jBmzvmNOX5uNmkdrZzbWYESHIpZpFkJ8Wy84rlpxxYafm58/fQgwoRCoPFpAHEnnee2NZZSIyvIX0e4DJy0R4aT19pCXkarlfZfs/OVewQ2l6NtjriymontUDsTA2M/FIQMHycDVmZanXSdwvv6WKkp/vkQHG87DDDnTo4JBCmm9PCBoeAhuo3LxeBFVHEVf9oED/Oli4jyK+hD9rM8iXR41gEVyfzOzBwJyJhSMIZAsRkMklOc4PlCt/YIz/CC4eER3/rMO2V8ZDdJy+Sh/xIMfBU2ISbPFTbYL9EN6uSa0LGYjfbh6SyEsr0TslQP5b+tVE8JDV0EC7KlFu2Y0f6MWG2FSQ51kUq/qTPk0JLVyEA6jFNH8IBJdr/a0FPVmKQNidmZA3h6fdqC4hy8lL1tCVqemYH3+YTbWtza05as7tRgvADhUgix8TRmXlik= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6041248)(20161123555025)(20161123560025)(20161123558021)(20161123564025)(20161123562025)(6072148); SRVR:CY1PR0701MB1725; BCL:0; PCL:0; RULEID:; SRVR:CY1PR0701MB1725; X-Microsoft-Exchange-Diagnostics: 1; CY1PR0701MB1725; 4:rLAqpMxnBhgugyV8EYYDeZptQdnWYatuGzqeDpqIpFZYiF7N6rNfQm+TUhD5K+y4CNL5l+a5jhmn9c1H4hi25b/m5nqfAoYRMJ2M2c11f9R7soneH76099le1MwQMd5wNXpJ9uzsK52CU6v3Po9YvxAEcQYMu8tBMUAk/Hk/p96ek4euNGImXMOkVTgq4U2ULtSiBSYIoZfwT9EZ5bSQ2gd9LO3Adw8TbSQd5+jYNLNjkRbT2cnxWEnLfBGMTFJdDX5O6LSFjzSyNzRUcZTpTW16pthdZEcvKHJG73hVNYs2k1eNzf5DxhwLX1XNQaI8LfH8ze7fHIabpdU3bB5wnsdgY2YSNl9uwqV7vg0gEJChnIjWxZQ+FWlwkt1JLYdZMqLFCKpKP4VDJ3mGFnGhmWGUNRw1KgPzG6imNdTzjAhnEIQnv/Bp0+r8W9KrmK6JhEVo8pjSVhAPTcJnao1ak3YWkGw/jVUxPvi3c2gIckdyYAYKt6NfL/U2xhInF9WfhUTgePPXzKRFICjqArZxm2V874uftno+ij/0jptyQzFcn3/J3/P+XUb+z5ecjdROBmAdrHNwurYMWhBmvCPG2SRLNCa3WayhaP835UmsiA8= X-Forefront-PRVS: 01604FB62B X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(6069001)(7916002)(39450400003)(189002)(199003)(6512006)(6506006)(106356001)(6486002)(5003940100001)(48376002)(68736007)(25786008)(101416001)(42186005)(5009440100003)(4001430100002)(81166006)(4326007)(105586002)(50226002)(92566002)(81156014)(50986999)(76176999)(107886002)(8676002)(2906002)(42882006)(6916009)(2950100002)(36756003)(110136003)(2351001)(47776003)(38730400001)(305945005)(3846002)(97736004)(66066001)(8666005)(50466002)(5890100001)(6116002)(189998001)(5660300001)(33646002)(7736002)(7099028)(110426004)(7059030); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR0701MB1725; H:localhost.localdomain.localdomain; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY1PR0701MB1725; 23:2eZIgbD2E0vwxO3j1RHOqOAtRIxTVjnvycVjrzo?= =?us-ascii?Q?hzkBhZiJwEWaVDoiqEUhXid2+Sz347VxQN4MevpUDO/670BUFuRxNRkyX6vp?= =?us-ascii?Q?cq9qgIbU/yxUlhTqg9oJ+z5AgzeG2C7TVlQCdZMyGsSaAqxG8Za20Gaf1r+/?= =?us-ascii?Q?QNXfIGmQoShVQTTyHRvBX0swJUrdggGaoDSub7DzVDunFhdujzo+CbY9MOVo?= =?us-ascii?Q?HWaOeITif+RWGFdkWKsokigFnWPqRAqgv+OhF5BxPbWmaEEJRGkoTpsqgKX9?= =?us-ascii?Q?C33YGrgLFz6aFWsTX9AA9xEyQuFhWHlSLlh/jW0vwbcRGfnF68Mjh2mQQrYb?= =?us-ascii?Q?qP18BxKxhpG46JIFS2Q8teEyoczGNI1weLm0pxMtBXT4onsed1XqrbX4IwW6?= =?us-ascii?Q?sUY9btTCys8jJi/a3lsnF7Qn1Rg4sDnttKtDRjvF5Qzy1VXmiYGl0fNIZYE/?= =?us-ascii?Q?opOS75EuQM8+GfevlCQusE2pQmB1jLeIpPRozuErHtdg7FuBWsBphIzPmhtz?= =?us-ascii?Q?mgk+PTYmREmW32gvZXNPDe5kCT6pgAMhw/cFZYbCBg0qv/n60hwfOYtIQjwk?= =?us-ascii?Q?gcCMEfw8gs6LRkk65ZvJ6VyLuTGi5YbA/0APRnSQrMSDKd2vAZum5aHswXSr?= =?us-ascii?Q?BWDcnI1AdVwFfkt5sMauvWAa/fUp5qPxrSBekV/3pRCvyUwh9MlnE2YoyxfR?= =?us-ascii?Q?+fq7fYjXUF09WmGiNGuGw6iunGfx4+/VDm2z/5MBS3i6IoABpE9dghCKdwEo?= =?us-ascii?Q?sefsmtRpSZABVOfjhbkOAGhgeoYMng/4kVyvlqR4zO2IWyshZ/QjFJbpBIYQ?= =?us-ascii?Q?2VUrkz6Lz7XtRvsPzNf36rTv1zHozJHzgODIEaicUEOjCPOk4ycl8zquW9lM?= =?us-ascii?Q?af3xdEmWk/Aucj4e/JB/ZekS6mGChYtNJ/oR1uffTyBy5NyJZm0RlcYCT39J?= =?us-ascii?Q?cwv74QjZrC8Kz8AQW//XhSPqIhzRiRzXBKNW7xJs9xbK5yn9uTvoE98rdIuE?= =?us-ascii?Q?Bg/+LJFZ24Ro4KMWYLlV+VA66a1S+EuvMJApPtK6mGrHSzHDaAY8SGIqZydR?= =?us-ascii?Q?0P/2KHt0J22f1yv8XWXiFA1RqLFb11hmklJK9JfAfg4ep0JzU40cykK7XGHg?= =?us-ascii?Q?GQtusdSSDcpZcNVa/e9PWrgGHznjjgTI5fmvR+nTpYB1HUUzWYbFzMzewezj?= =?us-ascii?Q?kYSLAaTM4aNBJvyLvjtow2aS1rCuRw8tGIH6nztcnJBrkP0fJNwZ1ra7r/4r?= =?us-ascii?Q?m9GED/G2/BAMV14PfbGK5MSWysILPqHw0Cw0eByFyJnRkCyleppdJNUjL770?= =?us-ascii?Q?umg=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; CY1PR0701MB1725; 6:9Gs2cQxF1xNthPQxx7TsT2TXrRhpXxFTgIfrj2m3SwXoImQT1HfHFYEZjeFn5c5JH27oe9G/vSOuZLWPORhrP+rt0zwpDysL6DevnKs4LGJ02KeCJ+Uyepk4f2yMIKbdcNj47iO+svFikk5L2E6wLC+iR2s5tO7PinJGYz7b3oYDnrTnNevQfBX0BGumSnpFctfIP8+ODrvzDYusSE92SXSrer6lkdlOWhJ1isDG03SDE7UJW1UNEnNKbcSqFJcyZFQfpmIGvw9RsET9PVwPnep4IjCUDwjDpx6gpu68fCgagOD+n4KGbDDXglvkL4SO7qgfFy3ur6gk3enqx75snXJIvn4ocNQME1477oeoXgePh+1ubltsOxS0aPFzCPObYbt9VEG26Kpc1ioMPeCZohhLsyVljDf85dsPeDpSDSQ=; 5:IzKDF7Xkl2GmzSWly5VtOj/BXgPW5069Q6kEgBy3LqZcTmdEGiYYWAksbcyqCH06N1KKagM9bV/Hup14EbcXp3fBZdIdXOg/pH+tuls2skzwX9M3Rl30sVoqlOiK+CpQY4+uC4NoFK+jbq+WHiancA==; 24:yVhGpzuNk8trmG+wmtV2UHIG5AyjjL0/BGRco64Zs8DBhP6AaL8PxvdZHwWvdQHQtkHlc+i2sCXif3o+LGlrK17cmJWgovV7tqOo56hPjBs= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CY1PR0701MB1725; 7:WTldabZBru6IfUjWScsGMdVgZ+IAMRj9u88YZoHftxk/gErtxKBEwcwUkEG733TzChWngXQdru/ByH67curJpk/nkSUPk++E75cvB1zXEdzGoTUq9CR0Nc5Z2Emo8FChazH/GFXXRFLSEZM0oYTWjYYjBn1DZEssFZrqhN6k2ObEWk1fE5Hu/9izM+8xQwjGU7JqMQ05JHYB1A/iQbLsVAaYA49je7Xc1cQLJqk3dpn68duoVVFrk1aTW4aXcCALgjKBLxc3AJdA/VQRvxZ0fpis+YOG6rwqdGnEirex1IFDpAkawVpayRG9qX5pEOqwVQ4co+ESSIOSz1gHWubGpXp4VqT70VOjLmBZTuOt/s6gcvasqr4lFNQ7F4UMIOXUHWYtdtcgqrS/EHgFSakAvbQlDQLRo2Deh22qbXdIjxxcDMXXtVqTqz1BvYD8bl6fTxj2V27u+CTnxEsRGk55fQ== X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Dec 2016 14:22:32.1154 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR0701MB1725 Subject: [dpdk-dev] [PATCH v3 4/6] eventdev: implement PMD registration 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: Sun, 18 Dec 2016 14:22:38 -0000 This patch adds infrastructure for registering the vdev or the PCI based event device. Signed-off-by: Jerin Jacob --- lib/librte_eventdev/rte_eventdev.c | 236 +++++++++++++++++++++++++++ lib/librte_eventdev/rte_eventdev_pmd.h | 111 +++++++++++++ lib/librte_eventdev/rte_eventdev_version.map | 6 + 3 files changed, 353 insertions(+) diff --git a/lib/librte_eventdev/rte_eventdev.c b/lib/librte_eventdev/rte_eventdev.c index 92424dc..582de96 100644 --- a/lib/librte_eventdev/rte_eventdev.c +++ b/lib/librte_eventdev/rte_eventdev.c @@ -124,6 +124,8 @@ rte_event_dev_info_get(uint8_t dev_id, struct rte_event_dev_info *dev_info) (*dev->dev_ops->dev_infos_get)(dev, dev_info); dev_info->pci_dev = dev->pci_dev; + if (dev->driver) + dev_info->driver_name = dev->driver->pci_drv.driver.name; return 0; } @@ -982,3 +984,237 @@ rte_event_dev_close(uint8_t dev_id) return (*dev->dev_ops->dev_close)(dev); } + +static inline int +rte_eventdev_data_alloc(uint8_t dev_id, struct rte_eventdev_data **data, + int socket_id) +{ + char mz_name[RTE_EVENTDEV_NAME_MAX_LEN]; + const struct rte_memzone *mz; + int n; + + /* Generate memzone name */ + n = snprintf(mz_name, sizeof(mz_name), "rte_eventdev_data_%u", dev_id); + if (n >= (int)sizeof(mz_name)) + return -EINVAL; + + if (rte_eal_process_type() == RTE_PROC_PRIMARY) { + mz = rte_memzone_reserve(mz_name, + sizeof(struct rte_eventdev_data), + socket_id, 0); + } else + mz = rte_memzone_lookup(mz_name); + + if (mz == NULL) + return -ENOMEM; + + *data = mz->addr; + if (rte_eal_process_type() == RTE_PROC_PRIMARY) + memset(*data, 0, sizeof(struct rte_eventdev_data)); + + return 0; +} + +static inline uint8_t +rte_eventdev_find_free_device_index(void) +{ + uint8_t dev_id; + + for (dev_id = 0; dev_id < RTE_EVENT_MAX_DEVS; dev_id++) { + if (rte_eventdevs[dev_id].attached == + RTE_EVENTDEV_DETACHED) + return dev_id; + } + return RTE_EVENT_MAX_DEVS; +} + +struct rte_eventdev * +rte_event_pmd_allocate(const char *name, int socket_id) +{ + struct rte_eventdev *eventdev; + uint8_t dev_id; + + if (rte_event_pmd_get_named_dev(name) != NULL) { + RTE_EDEV_LOG_ERR("Event device with name %s already " + "allocated!", name); + return NULL; + } + + dev_id = rte_eventdev_find_free_device_index(); + if (dev_id == RTE_EVENT_MAX_DEVS) { + RTE_EDEV_LOG_ERR("Reached maximum number of event devices"); + return NULL; + } + + eventdev = &rte_eventdevs[dev_id]; + + if (eventdev->data == NULL) { + struct rte_eventdev_data *eventdev_data = NULL; + + int retval = rte_eventdev_data_alloc(dev_id, &eventdev_data, + socket_id); + + if (retval < 0 || eventdev_data == NULL) + return NULL; + + eventdev->data = eventdev_data; + + snprintf(eventdev->data->name, RTE_EVENTDEV_NAME_MAX_LEN, + "%s", name); + + eventdev->data->dev_id = dev_id; + eventdev->data->socket_id = socket_id; + eventdev->data->dev_started = 0; + + eventdev->attached = RTE_EVENTDEV_ATTACHED; + + eventdev_globals.nb_devs++; + } + + return eventdev; +} + +int +rte_event_pmd_release(struct rte_eventdev *eventdev) +{ + int ret; + + if (eventdev == NULL) + return -EINVAL; + + ret = rte_event_dev_close(eventdev->data->dev_id); + if (ret < 0) + return ret; + + eventdev->attached = RTE_EVENTDEV_DETACHED; + eventdev_globals.nb_devs--; + eventdev->data = NULL; + + return 0; +} + +struct rte_eventdev * +rte_event_pmd_vdev_init(const char *name, size_t dev_private_size, + int socket_id) +{ + struct rte_eventdev *eventdev; + + /* Allocate device structure */ + eventdev = rte_event_pmd_allocate(name, socket_id); + if (eventdev == NULL) + return NULL; + + /* Allocate private device structure */ + if (rte_eal_process_type() == RTE_PROC_PRIMARY) { + eventdev->data->dev_private = + rte_zmalloc_socket("eventdev device private", + dev_private_size, + RTE_CACHE_LINE_SIZE, + socket_id); + + if (eventdev->data->dev_private == NULL) + rte_panic("Cannot allocate memzone for private device" + " data"); + } + + return eventdev; +} + +int +rte_event_pmd_pci_probe(struct rte_pci_driver *pci_drv, + struct rte_pci_device *pci_dev) +{ + struct rte_eventdev_driver *eventdrv; + struct rte_eventdev *eventdev; + + char eventdev_name[RTE_EVENTDEV_NAME_MAX_LEN]; + + int retval; + + eventdrv = (struct rte_eventdev_driver *)pci_drv; + if (eventdrv == NULL) + return -ENODEV; + + rte_eal_pci_device_name(&pci_dev->addr, eventdev_name, + sizeof(eventdev_name)); + + eventdev = rte_event_pmd_allocate(eventdev_name, + pci_dev->device.numa_node); + if (eventdev == NULL) + return -ENOMEM; + + if (rte_eal_process_type() == RTE_PROC_PRIMARY) { + eventdev->data->dev_private = + rte_zmalloc_socket( + "eventdev private structure", + eventdrv->dev_private_size, + RTE_CACHE_LINE_SIZE, + rte_socket_id()); + + if (eventdev->data->dev_private == NULL) + rte_panic("Cannot allocate memzone for private " + "device data"); + } + + eventdev->pci_dev = pci_dev; + eventdev->driver = eventdrv; + + /* Invoke PMD device initialization function */ + retval = (*eventdrv->eventdev_init)(eventdev); + if (retval == 0) + return 0; + + RTE_EDEV_LOG_ERR("driver %s: (vendor_id=0x%x device_id=0x%x)" + " failed", pci_drv->driver.name, + (unsigned int) pci_dev->id.vendor_id, + (unsigned int) pci_dev->id.device_id); + + if (rte_eal_process_type() == RTE_PROC_PRIMARY) + rte_free(eventdev->data->dev_private); + + eventdev->attached = RTE_EVENTDEV_DETACHED; + eventdev_globals.nb_devs--; + + return -ENXIO; +} + +int +rte_event_pmd_pci_remove(struct rte_pci_device *pci_dev) +{ + const struct rte_eventdev_driver *eventdrv; + struct rte_eventdev *eventdev; + char eventdev_name[RTE_EVENTDEV_NAME_MAX_LEN]; + int ret; + + if (pci_dev == NULL) + return -EINVAL; + + rte_eal_pci_device_name(&pci_dev->addr, eventdev_name, + sizeof(eventdev_name)); + + eventdev = rte_event_pmd_get_named_dev(eventdev_name); + if (eventdev == NULL) + return -ENODEV; + + eventdrv = (const struct rte_eventdev_driver *)pci_dev->driver; + if (eventdrv == NULL) + return -ENODEV; + + /* Invoke PMD device un-init function */ + if (*eventdrv->eventdev_uninit) { + ret = (*eventdrv->eventdev_uninit)(eventdev); + if (ret) + return ret; + } + + /* Free event device */ + rte_event_pmd_release(eventdev); + + if (rte_eal_process_type() == RTE_PROC_PRIMARY) + rte_free(eventdev->data->dev_private); + + eventdev->pci_dev = NULL; + eventdev->driver = NULL; + + return 0; +} diff --git a/lib/librte_eventdev/rte_eventdev_pmd.h b/lib/librte_eventdev/rte_eventdev_pmd.h index b146c5d..385272c 100644 --- a/lib/librte_eventdev/rte_eventdev_pmd.h +++ b/lib/librte_eventdev/rte_eventdev_pmd.h @@ -92,6 +92,60 @@ extern "C" { #define RTE_EVENTDEV_DETACHED (0) #define RTE_EVENTDEV_ATTACHED (1) +/** + * Initialisation function of a event driver invoked for each matching + * event PCI device detected during the PCI probing phase. + * + * @param dev + * The dev pointer is the address of the *rte_eventdev* structure associated + * with the matching device and which has been [automatically] allocated in + * the *rte_event_devices* array. + * + * @return + * - 0: Success, the device is properly initialised by the driver. + * In particular, the driver MUST have set up the *dev_ops* pointer + * of the *dev* structure. + * - <0: Error code of the device initialisation failure. + */ +typedef int (*eventdev_init_t)(struct rte_eventdev *dev); + +/** + * Finalisation function of a driver invoked for each matching + * PCI device detected during the PCI closing phase. + * + * @param dev + * The dev pointer is the address of the *rte_eventdev* structure associated + * with the matching device and which has been [automatically] allocated in + * the *rte_event_devices* array. + * + * @return + * - 0: Success, the device is properly finalised by the driver. + * In particular, the driver MUST free the *dev_ops* pointer + * of the *dev* structure. + * - <0: Error code of the device initialisation failure. + */ +typedef int (*eventdev_uninit_t)(struct rte_eventdev *dev); + +/** + * The structure associated with a PMD driver. + * + * Each driver acts as a PCI driver and is represented by a generic + * *event_driver* structure that holds: + * + * - An *rte_pci_driver* structure (which must be the first field). + * + * - The *eventdev_init* function invoked for each matching PCI device. + * + * - The size of the private data to allocate for each matching device. + */ +struct rte_eventdev_driver { + struct rte_pci_driver pci_drv; /**< The PMD is also a PCI driver. */ + unsigned int dev_private_size; /**< Size of device private data. */ + + eventdev_init_t eventdev_init; /**< Device init function. */ + eventdev_uninit_t eventdev_uninit; /**< Device uninit function. */ +}; + /** Global structure used for maintaining state of allocated event devices */ struct rte_eventdev_global { uint8_t nb_devs; /**< Number of devices found */ @@ -393,6 +447,63 @@ struct rte_eventdev_ops { /* Dump internal information */ }; +/** + * Allocates a new eventdev slot for an event device and returns the pointer + * to that slot for the driver to use. + * + * @param name + * Unique identifier name for each device + * @param socket_id + * Socket to allocate resources on. + * @return + * - Slot in the rte_dev_devices array for a new device; + */ +struct rte_eventdev * +rte_event_pmd_allocate(const char *name, int socket_id); + +/** + * Release the specified eventdev device. + * + * @param eventdev + * The *eventdev* pointer is the address of the *rte_eventdev* structure. + * @return + * - 0 on success, negative on error + */ +int +rte_event_pmd_release(struct rte_eventdev *eventdev); + +/** + * Creates a new virtual event device and returns the pointer to that device. + * + * @param name + * PMD type name + * @param dev_private_size + * Size of event PMDs private data + * @param socket_id + * Socket to allocate resources on. + * + * @return + * - Eventdev pointer if device is successfully created. + * - NULL if device cannot be created. + */ +struct rte_eventdev * +rte_event_pmd_vdev_init(const char *name, size_t dev_private_size, + int socket_id); + + +/** + * Wrapper for use by pci drivers as a .probe function to attach to a event + * interface. + */ +int rte_event_pmd_pci_probe(struct rte_pci_driver *pci_drv, + struct rte_pci_device *pci_dev); + +/** + * Wrapper for use by pci drivers as a .remove function to detach a event + * interface. + */ +int rte_event_pmd_pci_remove(struct rte_pci_device *pci_dev); + #ifdef __cplusplus } #endif diff --git a/lib/librte_eventdev/rte_eventdev_version.map b/lib/librte_eventdev/rte_eventdev_version.map index 3cae03d..68b8c81 100644 --- a/lib/librte_eventdev/rte_eventdev_version.map +++ b/lib/librte_eventdev/rte_eventdev_version.map @@ -29,5 +29,11 @@ DPDK_17.02 { rte_event_dequeue_timeout_ticks; + rte_event_pmd_allocate; + rte_event_pmd_release; + rte_event_pmd_vdev_init; + rte_event_pmd_pci_probe; + rte_event_pmd_pci_remove; + local: *; }; -- 2.5.5