From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-f176.google.com (mail-qk1-f176.google.com [209.85.222.176]) by dpdk.org (Postfix) with ESMTP id 5D1FE1B213 for ; Thu, 27 Sep 2018 02:34:04 +0200 (CEST) Received: by mail-qk1-f176.google.com with SMTP id q12-v6so522666qkl.13 for ; Wed, 26 Sep 2018 17:34:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PlH/VAfIrUGq17Kvr2neDS51vqfEwcHSM70/Jy2B3NE=; b=jH4xuT7IpWHZwgFkuw8NrXmt35YOBwN+qeJQRmr33xHlEXsGXdzxC5ngywB9DOHlB/ uib0BCQCamSlXWMroSjdpRWillX6P40LtFL2lcth8s/SB4bukAtgZH6+rmJStOOTIWnI axB6ZVDbDS3iprkOalQTbW/Pk8s9cMgaIuB0znlAsB6a3gdMhQMerOprsMkpolryWLOB 4gFDoZ+FP4aMIf+eMk+vUB/ocQZkjbaFe/xDujmXOYHBinBIo3xmVjKgTMUNeFJIAZzT bUlQJCMAmpxE5+NiK4TCncEGPq2NRwSotb133aTd9bHL4bkhcT1vsaGaRVWMNlI/ol20 RTFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=PlH/VAfIrUGq17Kvr2neDS51vqfEwcHSM70/Jy2B3NE=; b=m8RyVtNY8lJGaWngsM98WyT1JZKuCHzrCJTfQWhhYK9dccYJJktkfGx1nX3Ygsw+WK zY3avaFOAngn9bOCpPu6NMPjFYz5Ul82HyVpplpuXcT1G8nfd2w77oeW/6liCBq0C6St i427BKU72exWHcSGrlL0pyCpwDtrpp5YRInwExdZZuLhvYjXPk9/Ttd8V1yrziopzkw7 r+eTjGKM2Ks17LaKfpZKfJn2mz47iW4724TiybpbdF7FxoKBE7fRoIWoAoTfWhrQtiF5 YaHzkWGCL+aV5+OpPP82kaHBLkwSNJjfo+50CdpXyuWmj8s5Dmu8ETzajFh32O+AWCwT h4GQ== X-Gm-Message-State: ABuFfoiZZg46FJDtpvkbcwPi6ytFnAYy9GHjauGupGKzNE9y2h7w2bv0 wC8HZDXTFKKmIaKxFS0AuU+H2AsA X-Google-Smtp-Source: ACcGV60F5ANhfU20GVWeRpk05nnP23KTpJ2P8dr1eHYjdMod+oGkM3f4IfRqW0/yuzOJqb7oVZb9FA== X-Received: by 2002:a37:30d4:: with SMTP id w203-v6mr2829130qkw.106.1538008443306; Wed, 26 Sep 2018 17:34:03 -0700 (PDT) Received: from snappy.local.lan (189-46-124-178.dsl.telesp.net.br. [189.46.124.178]) by smtp.gmail.com with ESMTPSA id x26-v6sm463053qth.15.2018.09.26.17.34.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 26 Sep 2018 17:34:02 -0700 (PDT) Sender: Dan Gora From: Dan Gora To: dev@dpdk.org Cc: Igor Ryzhov , Stephen Hemminger , Ferruh Yigit , Dan Gora Date: Wed, 26 Sep 2018 21:32:51 -0300 Message-Id: <20180927003256.6901-2-dg@adax.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180927003256.6901-1-dg@adax.com> References: <20180911232906.18352-1-dg@adax.com> <20180927003256.6901-1-dg@adax.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v3 1/6] kni: add API to set link status on kernel interface 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: Thu, 27 Sep 2018 00:34:04 -0000 Add a new API function to KNI, rte_kni_update_link() to allow DPDK applications to update the link status for KNI network interfaces in the linux kernel. Signed-off-by: Dan Gora --- lib/librte_kni/rte_kni.c | 57 ++++++++++++++++++++++++++++++ lib/librte_kni/rte_kni.h | 18 ++++++++++ lib/librte_kni/rte_kni_version.map | 6 ++++ 3 files changed, 81 insertions(+) diff --git a/lib/librte_kni/rte_kni.c b/lib/librte_kni/rte_kni.c index 65f6a2b03..0c3e17dbb 100644 --- a/lib/librte_kni/rte_kni.c +++ b/lib/librte_kni/rte_kni.c @@ -790,6 +790,63 @@ rte_kni_unregister_handlers(struct rte_kni *kni) return 0; } + +int __rte_experimental +rte_kni_update_link(struct rte_kni *kni, struct rte_eth_link *link) +{ + char path[64]; + char carrier[2]; + const char *new_carrier; + int fd, ret; + + if (kni == NULL || link == NULL) + return -1; + + snprintf(path, sizeof(path), "/sys/devices/virtual/net/%s/carrier", + kni->name); + + fd = open(path, O_RDWR); + if (fd == -1) { + RTE_LOG(ERR, KNI, "Failed to open file: %s.\n", path); + return -1; + } + + ret = read(fd, carrier, 2); + if (ret < 1) { + /* Cannot read carrier until interface is marked + * 'up', so don't log an error. + */ + close(fd); + return -1; + } + + new_carrier = (link->link_status == ETH_LINK_UP) ? "1" : "0"; + ret = write(fd, new_carrier, 1); + if (ret < 1) { + RTE_LOG(ERR, KNI, "Failed to write file: %s.\n", path); + close(fd); + return -1; + } + + if (strncmp(carrier, new_carrier, 1)) { + if (link->link_status == ETH_LINK_UP) { + RTE_LOG(INFO, KNI, "%s NIC Link is Up %d Mbps %s %s.\n", + kni->name, + link->link_speed, + link->link_autoneg ? "(AutoNeg)" : "(Fixed)", + link->link_duplex ? + "Full Duplex" : "Half Duplex"); + } else { + RTE_LOG(INFO, KNI, "%s NIC Link is Down.\n", + kni->name); + } + } + + close(fd); + + return 0; +} + void rte_kni_close(void) { diff --git a/lib/librte_kni/rte_kni.h b/lib/librte_kni/rte_kni.h index 99055e2c2..4118ae97a 100644 --- a/lib/librte_kni/rte_kni.h +++ b/lib/librte_kni/rte_kni.h @@ -21,6 +21,7 @@ #include #include #include +#include #include @@ -228,6 +229,23 @@ int rte_kni_register_handlers(struct rte_kni *kni, struct rte_kni_ops *ops); */ int rte_kni_unregister_handlers(struct rte_kni *kni); +/** + * Update link status info for KNI port. + * + * Update the linkup/linkdown status of a KNI interface in the kernel. + * + * @param kni + * pointer to struct rte_kni. + * @param link + * pointer to struct rte_eth_link containing new interface status. + * + * @return + * On success: 0 + * On failure: -1 + */ +int __rte_experimental +rte_kni_update_link(struct rte_kni *kni, struct rte_eth_link *link); + /** * Close KNI device. */ diff --git a/lib/librte_kni/rte_kni_version.map b/lib/librte_kni/rte_kni_version.map index acd515eb0..c877dc6aa 100644 --- a/lib/librte_kni/rte_kni_version.map +++ b/lib/librte_kni/rte_kni_version.map @@ -15,3 +15,9 @@ DPDK_2.0 { local: *; }; + +EXPERIMENTAL { + global: + + rte_kni_update_link; +}; -- 2.19.0