From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qt0-f194.google.com (mail-qt0-f194.google.com [209.85.216.194]) by dpdk.org (Postfix) with ESMTP id 90A9E4C95 for ; Wed, 12 Sep 2018 01:14:33 +0200 (CEST) Received: by mail-qt0-f194.google.com with SMTP id g44-v6so30115062qtb.12 for ; Tue, 11 Sep 2018 16:14:33 -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=QbVzj3tE2DwRLfrpgVw7cgM0BzKD2Sqto3np8ee1VMPrryMjTgdvtTdpsmueRjqopn 5kwLKZD8FSBYkZ9Vl2U9D4v7vYZt3stdoK6UzdJwORv4RfCpSt9l3TWRd+pHhucu3TwF 2MFsHMS623uf4P5BWmmamDXS82eKD4w2iXIGBB73xkSGdcpu1v0egzIH4TtGXfZ7JAhn 0ICDPHErfoImjkkDneiqef3holDDlNJZgU/UKLQE0fqul6Cc4XW7uM7HnN+uj2MEWiKd uW8nqTQ3TX7iEF+kD5ql7yeBFoQJTBwu6k+cJC4JWXyTTnjxGeZBHoVkNxFEm4ym7kp7 FNvA== 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=fCNpFZs8g0+ZeHvHkOdp8uK74QDoBIIj24n5OWa5VvkPsO0TfPIl9yL3gtNdBFcYXP kAM7NV7hMSklkcXpnGrndxUu8siRNSP6QBm6YNf4YC59TcXJSyEm0W2dZrO+Jjk/zAJz QEMFG9VWpNQZuq/AG6ObF3DatF/qzhMSOlXIxI4WSsu/lYqdD1hwJS7/0hSYjA6xh6Wi Swy0YN5b2a0ZIMlbFXtNOn4beI2bjisQIieP7QrrWxMVuO+AZFlSu7jMP9XN9Gri4CAv 9TC/+0zd/kDMri2ePbIdaeV9Ap1gs3Fo8jz4VVg4idUsZvCC5LJPsn5/u50aLghWzGr7 rKJg== X-Gm-Message-State: APzg51AJzzcOD0gPAr7Hm9+YSMerzoY4tf9Bvpo+DDJgxy70TxBCrwz7 l42z8VfBsHRY41xmIFoLKhwMQjRN X-Google-Smtp-Source: ANB0VdZ3sHTqQZvLM088tCK2rxBjOaD4EnGGehNcLOdDDOYGmgHUm64FCIG4vcw4UHGIot2Sfp2dHA== X-Received: by 2002:ac8:2fa4:: with SMTP id l33-v6mr21567216qta.83.1536707672646; Tue, 11 Sep 2018 16:14:32 -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 l87-v6sm12999066qki.82.2018.09.11.16.14.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 11 Sep 2018 16:14:31 -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:14:17 -0300 Message-Id: <20180911231417.17222-1-dg@adax.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180629015508.26599-11-dg@adax.com> References: <20180629015508.26599-11-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:14:33 -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