From patchwork Fri Oct 2 09:08:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Iremonger, Bernard" X-Patchwork-Id: 7358 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 5FC818D93; Fri, 2 Oct 2015 11:08:10 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 0E695E72 for ; Fri, 2 Oct 2015 11:08:07 +0200 (CEST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga103.fm.intel.com with ESMTP; 02 Oct 2015 02:08:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,622,1437462000"; d="scan'208";a="782610630" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga001.jf.intel.com with ESMTP; 02 Oct 2015 02:08:05 -0700 Received: from sivswdev01.ir.intel.com (sivswdev01.ir.intel.com [10.237.217.45]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id t92985x8007631; Fri, 2 Oct 2015 10:08:05 +0100 Received: from sivswdev01.ir.intel.com (localhost [127.0.0.1]) by sivswdev01.ir.intel.com with ESMTP id t92985Bi006693; Fri, 2 Oct 2015 10:08:05 +0100 Received: (from bairemon@localhost) by sivswdev01.ir.intel.com with id t92985Jo006689; Fri, 2 Oct 2015 10:08:05 +0100 From: Bernard Iremonger To: dev@dpdk.org Date: Fri, 2 Oct 2015 10:08:02 +0100 Message-Id: <1443776883-6654-1-git-send-email-bernard.iremonger@intel.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: References: Subject: [dpdk-dev] [PATCH 1/2] xenvirt: add support for PCI Port Hotplug X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Signed-off-by: Bernard Iremonger --- drivers/net/xenvirt/rte_eth_xenvirt.c | 63 +++++++++++++++++++++++++++++++---- drivers/net/xenvirt/rte_xen_lib.c | 26 ++++++++++++--- drivers/net/xenvirt/rte_xen_lib.h | 5 ++- 3 files changed, 83 insertions(+), 11 deletions(-) diff --git a/drivers/net/xenvirt/rte_eth_xenvirt.c b/drivers/net/xenvirt/rte_eth_xenvirt.c index b3383af..8923826 100644 --- a/drivers/net/xenvirt/rte_eth_xenvirt.c +++ b/drivers/net/xenvirt/rte_eth_xenvirt.c @@ -1,7 +1,7 @@ /*- * BSD LICENSE * - * Copyright(c) 2010-2014 Intel Corporation. All rights reserved. + * Copyright(c) 2010-2015 Intel Corporation. All rights reserved. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -642,10 +642,14 @@ eth_dev_xenvirt_create(const char *name, const char *params, if (internals == NULL) goto err; - /* reserve an ethdev entry */ - eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_VIRTUAL); - if (eth_dev == NULL) - goto err; + /* find an ethdev entry */ + eth_dev = rte_eth_dev_allocated(name); + if (eth_dev == NULL) { + /* reserve an ethdev entry */ + eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_VIRTUAL); + if (eth_dev == NULL) + goto err; + } data->dev_private = internals; data->port_id = eth_dev->data->port_id; @@ -661,7 +665,7 @@ eth_dev_xenvirt_create(const char *name, const char *params, eth_dev->data = data; eth_dev->dev_ops = &ops; - eth_dev->data->dev_flags = 0; + eth_dev->data->dev_flags = RTE_PCI_DRV_DETACHABLE; eth_dev->data->kdrv = RTE_KDRV_NONE; eth_dev->data->drv_name = NULL; eth_dev->driver = NULL; @@ -683,6 +687,38 @@ err: } +static int +eth_dev_xenvirt_free(const char *name, const unsigned numa_node) +{ + struct rte_eth_dev *eth_dev = NULL; + + RTE_LOG(DEBUG, PMD, + "Free virtio rings backed ethdev on numa socket %u\n", + numa_node); + + /* find an ethdev entry */ + eth_dev = rte_eth_dev_allocated(name); + if (eth_dev == NULL) + return -1; + + if (eth_dev->data->dev_started == 1) { + eth_dev_stop(eth_dev); + eth_dev_close(eth_dev); + } + + eth_dev->rx_pkt_burst = NULL; + eth_dev->tx_pkt_burst = NULL; + eth_dev->dev_ops = NULL; + + rte_free(eth_dev->data); + rte_free(eth_dev->data->dev_private); + rte_free(eth_dev->data->mac_addrs); + + virtio_idx--; + + return 0; +} + /*TODO: Support multiple process model */ static int rte_pmd_xenvirt_devinit(const char *name, const char *params) @@ -701,10 +737,25 @@ rte_pmd_xenvirt_devinit(const char *name, const char *params) return 0; } +static int +rte_pmd_xenvirt_devuninit(const char *name) +{ + eth_dev_xenvirt_free(name, rte_socket_id()); + + if (virtio_idx == 0) { + if (xenstore_uninit() != 0) + RTE_LOG(ERR, PMD, "%s: xenstore uninit failed\n", __func__); + + gntalloc_close(); + } + return 0; +} + static struct rte_driver pmd_xenvirt_drv = { .name = "eth_xenvirt", .type = PMD_VDEV, .init = rte_pmd_xenvirt_devinit, + .uninit = rte_pmd_xenvirt_devuninit, }; PMD_REGISTER_DRIVER(pmd_xenvirt_drv); diff --git a/drivers/net/xenvirt/rte_xen_lib.c b/drivers/net/xenvirt/rte_xen_lib.c index b3932f0..5900b53 100644 --- a/drivers/net/xenvirt/rte_xen_lib.c +++ b/drivers/net/xenvirt/rte_xen_lib.c @@ -1,7 +1,7 @@ /*- * BSD LICENSE * - * Copyright(c) 2010-2014 Intel Corporation. All rights reserved. + * Copyright(c) 2010-2015 Intel Corporation. All rights reserved. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -50,6 +50,7 @@ #include #include +#include #include "rte_xen_lib.h" @@ -72,6 +73,8 @@ int gntalloc_fd = -1; static char *dompath = NULL; /* handle to xenstore read/write operations */ static struct xs_handle *xs = NULL; +/* flag to indicate if xenstore cleanup is required */ +static bool is_xenstore_cleaned_up; /* * Reserve a virtual address space. @@ -275,7 +278,6 @@ xenstore_init(void) { unsigned int len, domid; char *buf; - static int cleanup = 0; char *end; xs = xs_domain_open(); @@ -301,16 +303,32 @@ xenstore_init(void) xs_transaction_start(xs); /* When to stop transaction */ - if (cleanup == 0) { + if (is_xenstore_cleaned_up == 0) { if (xenstore_cleanup()) return -1; - cleanup = 1; + is_xenstore_cleaned_up = 1; } return 0; } int +xenstore_uninit(void) +{ + xs_close(xs); + + if (is_xenstore_cleaned_up == 0) { + if (xenstore_cleanup()) + return -1; + is_xenstore_cleaned_up = 1; + } + free(dompath); + dompath = NULL; + + return 0; +} + +int xenstore_write(const char *key_str, const char *val_str) { char grant_path[PATH_MAX]; diff --git a/drivers/net/xenvirt/rte_xen_lib.h b/drivers/net/xenvirt/rte_xen_lib.h index 0ba7148..d973eac 100644 --- a/drivers/net/xenvirt/rte_xen_lib.h +++ b/drivers/net/xenvirt/rte_xen_lib.h @@ -1,7 +1,7 @@ /*- * BSD LICENSE * - * Copyright(c) 2010-2014 Intel Corporation. All rights reserved. + * Copyright(c) 2010-2015 Intel Corporation. All rights reserved. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -93,6 +93,9 @@ int xenstore_init(void); int +xenstore_uninit(void); + +int xenstore_write(const char *key_str, const char *val_str); int