From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-f195.google.com (mail-qk1-f195.google.com [209.85.222.195]) by dpdk.org (Postfix) with ESMTP id D69CB4C94 for ; Wed, 12 Sep 2018 01:29:25 +0200 (CEST) Received: by mail-qk1-f195.google.com with SMTP id f17-v6so32608qkh.4 for ; Tue, 11 Sep 2018 16:29:25 -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=brKgXRmAdYdNeL3uqBo0I3ImwvPWLgFWozo5r8fr8WE=; b=KJlNr9W+jF7TRpZem/EbIKwgveOlC4PL2Zd13KCpNi7odfYYHKpvtMjVYGm6Y/jfv8 KCbukPkFLJFYqx5kwE4FZRF2cr1/Y3E+lPLVE9mVYjObleJnkWjNADeUcwhJZXRQyfon IUWWsiogbcQTzSNnOBiQ/PIEP4Ec75OQu4qtW+6LEJ5Yc5nPsDkBR5V07wgt7hjRqG21 GIZC4BmYxvCSvxtCLIxsJYN79O97EEcDC33P7x0fKh1L+xnXmdFiLRF4DMYs3AuDQd3x ek4YfHxw4XdKZkA0m1Kn1B7LnH4zzHP2Ap+RRSjioAIqJE6fYOdXSYRHbjtaOfX/y/EM HXqA== 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=brKgXRmAdYdNeL3uqBo0I3ImwvPWLgFWozo5r8fr8WE=; b=LScDXJTP/jGo+IA+xonP8eGpsZPhLZ/beOEbeVH/jtQwGJX+mcEZXnQOErEfMwwJhK 5cKWOmEZOIO2lO7JAiO1Ww2Yjb8XhWHcR8oAp61pWoZutIvZ/A6eAeUlVC3p2z7CcZSL Ftf+QAaxKM4rKj5dMviVJ/YtOmLewbVhwxY9C6RoGOrdA3tmwXMFK88ZVlWRrMdAVq6o rmF19xfdLpjfi46zuV8UEKGF0ATW9DLzDcLtDJ7a+FRM15CyKMcW8xzETVJqRMDQH/XW JcVlH3s32Mrc6nt3WcmMJzEM6eWdEEBstvKK4aCn/my7r23v8CfExoH/Cam7blvet3az J7mw== X-Gm-Message-State: APzg51DTsCf3syC/4GrqZSav3svLhuE9nUMxe4IG1yuBTbj2Wcv+jsMf 88eCjMXNJDEBbnY05w/lJGjd22fz X-Google-Smtp-Source: ANB0VdZSMqU3g7agqrJwRA750traNHslUqwZJ0vL+3BISYnDbqaa82gN1kdCR9W19cjH0EWvK26qSQ== X-Received: by 2002:a37:cc9a:: with SMTP id n26-v6mr20947097qkl.112.1536708564872; Tue, 11 Sep 2018 16:29:24 -0700 (PDT) Received: from snappy.local.lan (189-46-164-241.dsl.telesp.net.br. [189.46.164.241]) by smtp.gmail.com with ESMTPSA id p30-v6sm12767814qta.4.2018.09.11.16.29.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 11 Sep 2018 16:29:24 -0700 (PDT) Sender: Dan Gora From: Dan Gora To: dev@dpdk.org Cc: Igor Ryzhov , Stephen Hemminger , Ferruh Yigit , Dan Gora Date: Tue, 11 Sep 2018 20:29:05 -0300 Message-Id: <20180911232906.18352-2-dg@adax.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180911232906.18352-1-dg@adax.com> References: <20180911232906.18352-1-dg@adax.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH 1/2] 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: Tue, 11 Sep 2018 23:29:26 -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 +++++++++++++ 2 files changed, 75 insertions(+) diff --git a/lib/librte_kni/rte_kni.c b/lib/librte_kni/rte_kni.c index 65f6a2b03..afe1d7410 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_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 ? "(Fixed)" : "(AutoNeg)", + 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. */ -- 2.19.0