From patchwork Wed Mar 16 14:40:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Mauricio_V=C3=A1squez?= X-Patchwork-Id: 598431 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (archives.nicira.com [96.126.127.54]) by ozlabs.org (Postfix) with ESMTP id 3qQDg85Q1yz9snk for ; Thu, 17 Mar 2016 01:40:36 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=studenti.polito.it header.i=@studenti.polito.it header.b=ixqH0bhC; dkim-atps=neutral Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id B116E10539; Wed, 16 Mar 2016 07:40:35 -0700 (PDT) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx1e4.cudamail.com (mx1.cudamail.com [69.90.118.67]) by archives.nicira.com (Postfix) with ESMTPS id 5677B10530 for ; Wed, 16 Mar 2016 07:40:34 -0700 (PDT) Received: from bar5.cudamail.com (unknown [192.168.21.12]) by mx1e4.cudamail.com (Postfix) with ESMTPS id D3FAC1E0C68 for ; Wed, 16 Mar 2016 08:40:33 -0600 (MDT) X-ASG-Debug-ID: 1458139231-09eadd30612b2050001-byXFYA Received: from mx1-pf2.cudamail.com ([192.168.24.2]) by bar5.cudamail.com with ESMTP id W2JYTvnJWk2gZ0HF (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 16 Mar 2016 08:40:31 -0600 (MDT) X-Barracuda-Envelope-From: mauricio.vasquezbernal@studenti.polito.it X-Barracuda-RBL-Trusted-Forwarder: 192.168.24.2 Received: from unknown (HELO compass.polito.it) (130.192.55.110) by mx1-pf2.cudamail.com with ESMTPS (DHE-RSA-AES256-SHA encrypted); 16 Mar 2016 14:40:31 -0000 Received-SPF: pass (mx1-pf2.cudamail.com: SPF record at studenti.polito.it designates 130.192.55.110 as permitted sender) X-Barracuda-Apparent-Source-IP: 130.192.55.110 X-Barracuda-RBL-IP: 130.192.55.110 Received: from localhost (localhost [127.0.0.1]) by compass.polito.it (Postfix) with ESMTP id 4C09F1000E7 for ; Wed, 16 Mar 2016 15:40:29 +0100 (CET) Authentication-Results: compass.polito.it (amavisd-new); dkim=pass (1024-bit key) reason="pass (just generated, assumed good)" header.d=studenti.polito.it DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= studenti.polito.it; h=x-mailer:message-id:date:date:subject :subject:to:from:from:received:received; s=y2k10; t=1458139228; bh=PbgA+XQNTveTnz/ZokUUoiShxyGzziwz78iksgr9OU0=; b=ixqH0bhCOgHx gRK9OVXX1PQKL567+gFkhu4LbqO2a7r5rHwr8OBHYqbnvd9aVtcxlbb8jrSFnwFm P1kQVkguLzqA2yKJDSpaSUowdC+mCmFRBP/AsCkBL0Lpft4FKV3hyWNaa4GUmvZn XtNl7q5mvPLo+zo3Uo4plttESpHUbNY= X-Virus-Scanned: amavisd-new at studenti.polito.it X-Spam-Flag: NO X-Spam-Score: -6.5 X-Spam-Level: X-Spam-Status: No, score=-6.5 tagged_above=-100 required=3.5 tests=[ALL_TRUSTED=-5, BAYES_00=-1.5] autolearn=ham Received: from compass.polito.it ([127.0.0.1]) by localhost (compass.polito.it [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id mUqaa1kar9Mm for ; Wed, 16 Mar 2016 15:40:28 +0100 (CET) Received: from mvb-X455LJ.station (net-130-25-120-150.cust.vodafonedsl.it [130.25.120.150]) (using TLSv1.2 with cipher AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: s203403@studenti.polito.it) by compass.polito.it (Postfix) with ESMTPSA id 4775E1000DD for ; Wed, 16 Mar 2016 15:40:28 +0100 (CET) X-CudaMail-Envelope-Sender: mauricio.vasquezbernal@studenti.polito.it From: Mauricio Vasquez B To: dev@openvswitch.org X-CudaMail-MID: CM-E2-315032234 X-CudaMail-DTE: 031616 X-CudaMail-Originating-IP: 130.192.55.110 Date: Wed, 16 Mar 2016 15:40:22 +0100 X-ASG-Orig-Subj: [##CM-E2-315032234##][RFC] lib/netdev-dpdk: add hotplug support Message-Id: <1458139222-4863-1-git-send-email-mauricio.vasquezbernal@studenti.polito.it> X-Mailer: git-send-email 1.9.1 X-GBUdb-Analysis: 0, 130.192.55.110, Ugly c=0 p=0 Source New X-MessageSniffer-Rules: 0-0-0-7093-c X-Barracuda-Connect: UNKNOWN[192.168.24.2] X-Barracuda-Start-Time: 1458139231 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 1.85 X-Barracuda-Spam-Status: No, SCORE=1.85 using per-user scores of TAG_LEVEL=3.5 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=4.0 tests=BSF_RULE_7580B, BSF_RULE_7582B, BSF_SC5_MJ1963, DKIM_SIGNED, RDNS_NONE X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.27898 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.00 DKIM_SIGNED Domain Keys Identified Mail: message has a signature 0.50 BSF_RULE_7582B Custom Rule 7582B 0.10 RDNS_NONE Delivered to trusted network by a host with no rDNS 0.75 BSF_RULE_7580B Custom Rule 7580B 0.50 BSF_SC5_MJ1963 Custom Rule MJ1963 Subject: [ovs-dev] [RFC] lib/netdev-dpdk: add hotplug support X-BeenThere: dev@openvswitch.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dev-bounces@openvswitch.org Sender: "dev" In order to use dpdk ports in ovs they have to be bound to a DPDK compatible driver before ovs is started. This patch adds the possibility to hotplug (or hot-unplug) a device after ovs has been started. The implementation adds two appctl commands: netdev-dpdk/attach and netdev-dpdk/detach. After the user attaches a new device, it can use the add-port command to use it in a switch, similarly, before detaching a device, it has to be removed using the del-port command. Signed-off-by: Mauricio Vasquez B --- lib/netdev-dpdk.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c index f402354..c3a99e7 100644 --- a/lib/netdev-dpdk.c +++ b/lib/netdev-dpdk.c @@ -2253,12 +2253,91 @@ dpdk_vhost_user_class_init(void) } static void +netdev_dpdk_attach(struct unixctl_conn *conn, int argc, + const char *argv[], void *aux OVS_UNUSED) +{ + int ret; + uint8_t port_id; + char response[512]; + + ovs_mutex_lock(&dpdk_mutex); + + ret = rte_eth_dev_attach(argv[1], &port_id); + if(ret < 0) { + snprintf(response, sizeof(response), + "Error attaching device ''", argv[1]); + unixctl_command_reply_error(conn, response); + goto unlock; + } + + snprintf(response, sizeof(response), + "Device '%s' has been attached as 'dpdk%d'", argv[1], port_id); + unixctl_command_reply(conn, response); + +unlock: + ovs_mutex_unlock(&dpdk_mutex); +} + +static void +netdev_dpdk_detach(struct unixctl_conn *conn, int argc, + const char *argv[], void *aux OVS_UNUSED) +{ + int ret; + unsigned int port_id; + char name[RTE_ETH_NAME_MAX_LEN]; + char response[512]; + + ret = dpdk_dev_parse_name(argv[1], "dpdk", &port_id); + if(ret) { + snprintf(response, sizeof(response), + "'%s' is not a valid dpdk device", argv[1]); + unixctl_command_reply_error(conn, response); + return; + } + + ovs_mutex_lock(&dpdk_mutex); + + struct netdev * netdev = netdev_from_name(argv[1]); + if(netdev) { + netdev_close(netdev); + snprintf(response, sizeof(response), + "Port '%s' is being used. Remove it before detaching", argv[1]); + unixctl_command_reply_error(conn, response); + goto unlock; + } + + rte_eth_dev_close(port_id); + + ret = rte_eth_dev_detach(port_id, name); + if(ret < 0) { + snprintf(response, sizeof(response), + "Port '%s' can not be detached", argv[1]); + unixctl_command_reply_error(conn, response); + goto unlock; + } + + snprintf(response, sizeof(response), "Port '%s' has been detached", argv[1]); + unixctl_command_reply(conn, response); + +unlock: + ovs_mutex_unlock(&dpdk_mutex); +} + +static void dpdk_common_init(void) { unixctl_command_register("netdev-dpdk/set-admin-state", "[netdev] up|down", 1, 2, netdev_dpdk_set_admin_state, NULL); + unixctl_command_register("netdev-dpdk/attach", + "device", 1, 1, + netdev_dpdk_attach, NULL); + + unixctl_command_register("netdev-dpdk/detach", + "port", 1, 1, + netdev_dpdk_detach, NULL); + ovs_thread_create("dpdk_watchdog", dpdk_watchdog, NULL); }