From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qt0-f193.google.com (mail-qt0-f193.google.com [209.85.216.193]) by dpdk.org (Postfix) with ESMTP id 6F0D11B126 for ; Wed, 19 Sep 2018 21:56:20 +0200 (CEST) Received: by mail-qt0-f193.google.com with SMTP id l42-v6so6285954qtf.13 for ; Wed, 19 Sep 2018 12:56:20 -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=Nz/UmoQLVRgRqvHKfUeCvxAYUgThgWKOV7tL6gEQha0=; b=XzskoyeigMPc/wghr+5Eh2eAbW4mvc3tJHl3lyrnh9iuhEwcsC6BLQjDahTydLf+7g pmwVywxlInZ4TE7Lrl/uP0tCrnSwZ3BrNkHJhMKXsE8PXxYioYcZzs0VdX4q3F3YVWSX xpbWsV2T85J1JsJb/rPiSH/kdyRg5YOcATP2Uevq0lA7UqOx8ebw06yFb/kf1yYeChfm 7IXSjVNtuNTLCVfRh9xwr5AmUwY7vcwDR3ow3c6WGPhMx8l3OOgAq9mFhiSauAu3mse1 c+cphdNdsPM8kPB7eEqPlP8WHY9zj3pfyqzwHWtX4CcvrXpKirMKkrWZdHIU8X1QqOcE Zwsg== 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=Nz/UmoQLVRgRqvHKfUeCvxAYUgThgWKOV7tL6gEQha0=; b=AVvdM6hQJTLtX2LNoJG8kty6GCWBauyLUlH0CGF/FexjBuIjTCc4x3GpqLjywZ+Qna yZqEKyQr3st/SGZ4IcPyiQ8tbDebS9Xz5vo19c263mbf7sB1F2xnDvh4Zgfs6te7NBaX osq3UsvBH1YHDH/09wd18xwQe55a0Pa7TR5qCFrNo9SnfeojZbpsnOiusA+x/i1Hoe8G jlpRbpsEgeUuRSXP4f+M3M/prHkVr64thF2sGHoYp2ENQmMSh9Uv9xYEa4gWrKAB/7UV 13oPYS2VLFsH5ZyOQYo5tLTOkAd4pmCVi/Loi4cRxMz+cW6I8rhbexQGXfK2bEiaEiMo ri6A== X-Gm-Message-State: APzg51Dp9jxMSMfn1f1ixE36ZyIzxYm1NPQjVnMg5K2fNZ2+EKWa7/Sr muYRbzNmFs7pw1YPSlGQchmBUanl X-Google-Smtp-Source: ANB0VdbWlgCbCh+jJZ6jl8Qs3bk594hIM42/tn5gp3In7a00t7hKccSyq3ROFIpAbxxny/giXnP8fQ== X-Received: by 2002:a0c:80a8:: with SMTP id 37-v6mr25651473qvb.13.1537386979348; Wed, 19 Sep 2018 12:56:19 -0700 (PDT) Received: from snappy.local.lan ([187.10.145.241]) by smtp.gmail.com with ESMTPSA id g184-v6sm12431369qkb.15.2018.09.19.12.56.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 19 Sep 2018 12:56:18 -0700 (PDT) Sender: Dan Gora From: Dan Gora To: dev@dpdk.org Cc: Igor Ryzhov , Stephen Hemminger , Dan Gora , Ferruh Yigit Date: Wed, 19 Sep 2018 16:55:45 -0300 Message-Id: <20180919195549.5585-2-dg@adax.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180919195549.5585-1-dg@adax.com> References: <20180911232906.18352-1-dg@adax.com> <20180919195549.5585-1-dg@adax.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v2 1/5] 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: Wed, 19 Sep 2018 19:56:20 -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 ++ test/test/test_kni.c | 100 ++++++++++++++++++++++++++++- 4 files changed, 180 insertions(+), 1 deletion(-) 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; +}; diff --git a/test/test/test_kni.c b/test/test/test_kni.c index 3dcadcebd..d450cc342 100644 --- a/test/test/test_kni.c +++ b/test/test/test_kni.c @@ -118,6 +118,97 @@ kni_change_mtu(uint16_t port_id, unsigned int new_mtu) port_id, kni_pkt_mtu); return 0; } + +static int +kni_change_link(void) +{ + struct rte_eth_link link; + int ret; + + link.link_speed = 10; + link.link_status = ETH_LINK_UP; + link.link_autoneg = ETH_LINK_AUTONEG; + link.link_duplex = ETH_LINK_FULL_DUPLEX; + ret = rte_kni_update_link(test_kni_ctx, &link); + if (ret != 0) { + printf("Failed to change link state to " + "Up/10Mbps/AutoNeg/Full ret=%d.\n", ret); + return -1; + } + rte_delay_ms(1000); + + link.link_speed = 0; + link.link_status = ETH_LINK_DOWN; + link.link_autoneg = ETH_LINK_FIXED; + link.link_duplex = ETH_LINK_FULL_DUPLEX; + ret = rte_kni_update_link(test_kni_ctx, &link); + if (ret != 0) { + printf("Failed to change link state to Down ret=%d.\n", ret); + return -1; + } + rte_delay_ms(1000); + + link.link_speed = 1000; + link.link_status = ETH_LINK_UP; + link.link_autoneg = ETH_LINK_AUTONEG; + link.link_duplex = ETH_LINK_HALF_DUPLEX; + ret = rte_kni_update_link(test_kni_ctx, &link); + if (ret != 0) { + printf("Failed to change link state to " + "Up/1Gbps/AutoNeg/Half ret=%d.\n", ret); + return -1; + } + rte_delay_ms(1000); + + link.link_speed = 0; + link.link_status = ETH_LINK_DOWN; + link.link_autoneg = ETH_LINK_FIXED; + link.link_duplex = ETH_LINK_FULL_DUPLEX; + ret = rte_kni_update_link(test_kni_ctx, &link); + if (ret != 0) { + printf("Failed to change link state to Down ret=%d.\n", ret); + return -1; + } + rte_delay_ms(1000); + + link.link_speed = 40000; + link.link_status = ETH_LINK_UP; + link.link_autoneg = ETH_LINK_FIXED; + link.link_duplex = ETH_LINK_FULL_DUPLEX; + ret = rte_kni_update_link(test_kni_ctx, &link); + if (ret != 0) { + printf("Failed to change link state to " + "Up/40Gbps/Fixed/Full ret=%d.\n", ret); + return -1; + } + rte_delay_ms(1000); + + link.link_speed = 0; + link.link_status = ETH_LINK_DOWN; + link.link_autoneg = ETH_LINK_FIXED; + link.link_duplex = ETH_LINK_FULL_DUPLEX; + ret = rte_kni_update_link(test_kni_ctx, &link); + if (ret != 0) { + printf("Failed to change link state to Down ret=%d.\n", ret); + return -1; + } + rte_delay_ms(1000); + + link.link_speed = 100000; + link.link_status = ETH_LINK_UP; + link.link_autoneg = ETH_LINK_FIXED; + link.link_duplex = ETH_LINK_FULL_DUPLEX; + ret = rte_kni_update_link(test_kni_ctx, &link); + if (ret != 0) { + printf("Failed to change link state to " + "Up/100Gbps/Fixed/Full ret=%d.\n", ret); + return -1; + } + rte_delay_ms(1000); + + return 0; +} + /** * This loop fully tests the basic functions of KNI. e.g. transmitting, * receiving to, from kernel space, and kernel requests. @@ -148,9 +239,16 @@ test_kni_loop(__rte_unused void *arg) ret = -1; if (system(IFCONFIG TEST_KNI_PORT" mtu 1400") == -1) ret = -1; + + ret = kni_change_link(); + if (ret != 0) { + test_kni_processing_flag = 1; + return ret; + } + rte_delay_ms(KNI_TIMEOUT_MS); if (system(IFCONFIG TEST_KNI_PORT" down") == -1) ret = -1; - rte_delay_ms(KNI_TIMEOUT_MS); + rte_delay_ms(1000); test_kni_processing_flag = 1; } else if (lcore_id == lcore_ingress) { struct rte_mempool *mp = test_kni_lookup_mempool(); -- 2.19.0