From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 834C9A0A0C; Sun, 4 Jul 2021 18:06:15 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id ECBA240686; Sun, 4 Jul 2021 18:06:14 +0200 (CEST) Received: from mail-lj1-f180.google.com (mail-lj1-f180.google.com [209.85.208.180]) by mails.dpdk.org (Postfix) with ESMTP id 3C1E740040 for ; Sun, 4 Jul 2021 18:06:13 +0200 (CEST) Received: by mail-lj1-f180.google.com with SMTP id q4so21067943ljp.13 for ; Sun, 04 Jul 2021 09:06:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nfware.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=W2L7P6lGGUvQMAn/tYVQkFB2uVhra/rWhQ6XtvnD2/A=; b=aeXuVdvu99lcptPPwWx+NWJGfJTOt7aumaSrMRii6l1QHHJbGHFbAvNC8p0VnvNfRk 9/xPJsy5ssgLJBGYjcqKRfI0C2U/OSEGrgGA/c4DhbVbi/PKg3oJGvcZp6S29fSin256 fzSudXq4sUutEyhNfmhpESGABEevwMInJnxTdS+37Tmc/w7sNnJ6win8j45lMzOSvoqs zmPm67POLezNPtcnwbriToL6nqH1574m+0OcTafn/uFtEXQMGLAbBlouf9NkiPmxRBPM 4ZhG5j/HlMq9/k+jFTgJA0TrX9B26JC9s/+r0f9NemfyUQ+opvlY4VAuHI3NU/3U8avQ k4wA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=W2L7P6lGGUvQMAn/tYVQkFB2uVhra/rWhQ6XtvnD2/A=; b=To7aw5PaRkukUPqnMVcGohpeMP0nJid7IfpTFhqxC8SsVkQ08rTzYEhV5fGg5IT2ag vPsVziXOLA6S/7ZQIg+1Q/GCGgeLvikpNBlDlZzyheCo1+TI2mnGmNInJLmQ1Vwc58x9 aNorO+iL0my5VDVKmm+VurUJF315BvJUFgdP1Vqu99/5bAXZ9ukznbenWhGrNUme3Iab P1YtyGYWGGALep74KbHWlBK4LmhuNwebXhkt6ffAiw4GFWVG3EXF23wpgahTschZkyAe vurwvgxKG1qvBNSnAbu5DUVNsTLN6Rvw6F5i/VMjth/OA8SmWEozFZLlZ12tnpAdclTT sWgA== X-Gm-Message-State: AOAM53160JcB9DVYD+jyG92aMIqf4DrvBD7QiGov6k4Ncdkzd4olEcpf Tn9CR/PnTPJsb9GFsse9RwOhzQnF4J7sbw== X-Google-Smtp-Source: ABdhPJyXzK6jjNLCht6zL8645uEXyKKiXsO1b2Pt+9xu5hxnW4cxALvKxBipGhVhpdsUZdbbvpyL1A== X-Received: by 2002:a2e:9e41:: with SMTP id g1mr7776825ljk.471.1625414772218; Sun, 04 Jul 2021 09:06:12 -0700 (PDT) Received: from localhost.localdomain ([77.105.178.215]) by smtp.gmail.com with ESMTPSA id 125sm482056lfm.173.2021.07.04.09.06.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Jul 2021 09:06:11 -0700 (PDT) From: Igor Ryzhov To: dev@dpdk.org Cc: ferruh.yigit@intel.com, dg@adax.com Date: Sun, 4 Jul 2021 19:06:08 +0300 Message-Id: <20210704160610.62682-1-iryzhov@nfware.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20190924193312.17381-1-iryzhov@nfware.com> References: <20190924193312.17381-1-iryzhov@nfware.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v4 1/2] kni: rework rte_kni_update_link using ioctl X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Current implementation doesn't allow us to update KNI carrier if the interface is not yet UP in kernel. It means that we can't use it in the same thread which is processing rte_kni_ops.config_network_if, which is very convenient, because it allows us to have correct carrier status of the interface right after we enabled it and we don't have to use any additional thread to track link status. Propagating speed/duplex/autoneg to the kernel module also allows us to implement ethtool_ops.get_link_ksettings callback. Suggested-by: Dan Gora Signed-off-by: Igor Ryzhov --- app/test/test_kni.c | 32 ++++++++++--------------- examples/kni/main.c | 2 +- kernel/linux/kni/compat.h | 4 ---- kernel/linux/kni/kni_dev.h | 5 ++++ kernel/linux/kni/kni_misc.c | 47 +++++++++++++++++++++++++++++++++++++ kernel/linux/kni/kni_net.c | 15 ------------ lib/kni/rte_kni.c | 38 ++++++++---------------------- lib/kni/rte_kni.h | 10 ++++---- lib/kni/rte_kni_common.h | 9 +++++++ 9 files changed, 89 insertions(+), 73 deletions(-) diff --git a/app/test/test_kni.c b/app/test/test_kni.c index 96733554b6c4..f9300552b3f6 100644 --- a/app/test/test_kni.c +++ b/app/test/test_kni.c @@ -125,6 +125,7 @@ kni_change_mtu(uint16_t port_id, unsigned int new_mtu) static int test_kni_link_change(void) { + struct rte_eth_link link; int ret; int pid; @@ -135,42 +136,35 @@ test_kni_link_change(void) } if (pid == 0) { + link.link_speed = ETH_SPEED_NUM_10G; + link.link_duplex = ETH_LINK_FULL_DUPLEX; + link.link_autoneg = ETH_LINK_AUTONEG; + printf("Starting KNI Link status change tests.\n"); if (system(IFCONFIG TEST_KNI_PORT" up") == -1) { ret = -1; goto error; } - ret = rte_kni_update_link(test_kni_ctx, 1); + link.link_status = ETH_LINK_UP; + ret = rte_kni_update_link(test_kni_ctx, &link); if (ret < 0) { printf("Failed to change link state to Up ret=%d.\n", ret); goto error; } rte_delay_ms(1000); - printf("KNI: Set LINKUP, previous state=%d\n", ret); - - ret = rte_kni_update_link(test_kni_ctx, 0); - if (ret != 1) { - printf( - "Failed! Previous link state should be 1, returned %d.\n", - ret); - goto error; - } - rte_delay_ms(1000); - printf("KNI: Set LINKDOWN, previous state=%d\n", ret); + printf("KNI: Set LINKUP\n"); - ret = rte_kni_update_link(test_kni_ctx, 1); - if (ret != 0) { - printf( - "Failed! Previous link state should be 0, returned %d.\n", + link.link_status = ETH_LINK_DOWN; + ret = rte_kni_update_link(test_kni_ctx, &link); + if (ret < 0) { + printf("Failed to change link state to Down ret=%d.\n", ret); goto error; } - printf("KNI: Set LINKUP, previous state=%d\n", ret); - - ret = 0; rte_delay_ms(1000); + printf("KNI: Set LINKDOWN\n"); error: if (system(IFCONFIG TEST_KNI_PORT" down") == -1) diff --git a/examples/kni/main.c b/examples/kni/main.c index beabb3c848aa..5833037cf1c9 100644 --- a/examples/kni/main.c +++ b/examples/kni/main.c @@ -755,7 +755,7 @@ monitor_all_ports_link_status(void *arg) } for (i = 0; i < p[portid]->nb_kni; i++) { prev = rte_kni_update_link(p[portid]->kni[i], - link.link_status); + &link); log_link_state(p[portid]->kni[i], prev, &link); } } diff --git a/kernel/linux/kni/compat.h b/kernel/linux/kni/compat.h index 5f65640d5ed2..995d109c275a 100644 --- a/kernel/linux/kni/compat.h +++ b/kernel/linux/kni/compat.h @@ -61,10 +61,6 @@ #define kni_sock_map_fd(s) sock_map_fd(s, 0) #endif -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0) -#define HAVE_CHANGE_CARRIER_CB -#endif - #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0) #define ether_addr_copy(dst, src) memcpy(dst, src, ETH_ALEN) #endif diff --git a/kernel/linux/kni/kni_dev.h b/kernel/linux/kni/kni_dev.h index c15da311ba25..969108cc30f8 100644 --- a/kernel/linux/kni/kni_dev.h +++ b/kernel/linux/kni/kni_dev.h @@ -88,6 +88,11 @@ struct kni_dev { void *alloc_va[MBUF_BURST_SZ]; struct task_struct *usr_tsk; + + /* correct when netif_carrier_ok */ + uint32_t speed; + uint8_t duplex; + uint8_t autoneg; }; #ifdef HAVE_IOVA_TO_KVA_MAPPING_SUPPORT diff --git a/kernel/linux/kni/kni_misc.c b/kernel/linux/kni/kni_misc.c index 2b464c438113..30ee69661935 100644 --- a/kernel/linux/kni/kni_misc.c +++ b/kernel/linux/kni/kni_misc.c @@ -481,6 +481,50 @@ kni_ioctl_release(struct net *net, uint32_t ioctl_num, return ret; } +static int +kni_ioctl_link(struct net *net, uint32_t ioctl_num, + unsigned long ioctl_param) +{ + struct kni_net *knet = net_generic(net, kni_net_id); + int ret = -EINVAL; + struct kni_dev *dev, *n; + struct rte_kni_link_info link_info; + struct net_device *netdev; + + if (_IOC_SIZE(ioctl_num) > sizeof(link_info)) + return -EINVAL; + + if (copy_from_user(&link_info, (void *)ioctl_param, sizeof(link_info))) + return -EFAULT; + + if (strlen(link_info.name) == 0) + return -EINVAL; + + down_read(&knet->kni_list_lock); + list_for_each_entry_safe(dev, n, &knet->kni_list_head, list) { + if (strncmp(dev->name, link_info.name, RTE_KNI_NAMESIZE) != 0) + continue; + + netdev = dev->net_dev; + + if (link_info.status) { + netif_carrier_on(netdev); + + dev->speed = link_info.speed; + dev->duplex = link_info.duplex; + dev->autoneg = link_info.autoneg; + } else { + netif_carrier_off(netdev); + } + + ret = 0; + break; + } + up_read(&knet->kni_list_lock); + + return ret; +} + static int kni_ioctl(struct inode *inode, uint32_t ioctl_num, unsigned long ioctl_param) { @@ -502,6 +546,9 @@ kni_ioctl(struct inode *inode, uint32_t ioctl_num, unsigned long ioctl_param) case _IOC_NR(RTE_KNI_IOCTL_RELEASE): ret = kni_ioctl_release(net, ioctl_num, ioctl_param); break; + case _IOC_NR(RTE_KNI_IOCTL_LINK): + ret = kni_ioctl_link(net, ioctl_num, ioctl_param); + break; default: pr_debug("IOCTL default\n"); break; diff --git a/kernel/linux/kni/kni_net.c b/kernel/linux/kni/kni_net.c index 611719b5ee27..99da8d37dd6b 100644 --- a/kernel/linux/kni/kni_net.c +++ b/kernel/linux/kni/kni_net.c @@ -778,18 +778,6 @@ kni_net_set_mac(struct net_device *netdev, void *p) return (ret == 0 ? req.result : ret); } -#ifdef HAVE_CHANGE_CARRIER_CB -static int -kni_net_change_carrier(struct net_device *dev, bool new_carrier) -{ - if (new_carrier) - netif_carrier_on(dev); - else - netif_carrier_off(dev); - return 0; -} -#endif - static const struct header_ops kni_net_header_ops = { .create = kni_net_header, .parse = eth_header_parse, @@ -808,9 +796,6 @@ static const struct net_device_ops kni_net_netdev_ops = { .ndo_change_mtu = kni_net_change_mtu, .ndo_tx_timeout = kni_net_tx_timeout, .ndo_set_mac_address = kni_net_set_mac, -#ifdef HAVE_CHANGE_CARRIER_CB - .ndo_change_carrier = kni_net_change_carrier, -#endif }; static void kni_get_drvinfo(struct net_device *dev, diff --git a/lib/kni/rte_kni.c b/lib/kni/rte_kni.c index eb24b0d0ae4e..0a7b562abf11 100644 --- a/lib/kni/rte_kni.c +++ b/lib/kni/rte_kni.c @@ -784,43 +784,25 @@ rte_kni_unregister_handlers(struct rte_kni *kni) } int -rte_kni_update_link(struct rte_kni *kni, unsigned int linkup) +rte_kni_update_link(struct rte_kni *kni, struct rte_eth_link *link) { - char path[64]; - char old_carrier[2]; - const char *new_carrier; - int old_linkup; - int fd, ret; + struct rte_kni_link_info link_info; if (kni == NULL) return -1; - snprintf(path, sizeof(path), "/sys/devices/virtual/net/%s/carrier", - kni->name); + snprintf(link_info.name, RTE_KNI_NAMESIZE, "%s", kni->name); + link_info.speed = link->link_speed; + link_info.duplex = link->link_duplex; + link_info.autoneg = link->link_autoneg; + link_info.status = link->link_status; - fd = open(path, O_RDWR); - if (fd == -1) { - RTE_LOG(ERR, KNI, "Failed to open file: %s.\n", path); + if (ioctl(kni_fd, RTE_KNI_IOCTL_LINK, &link_info) < 0) { + RTE_LOG(ERR, KNI, "Fail to update KNI link\n"); return -1; } - ret = read(fd, old_carrier, 2); - if (ret < 1) { - close(fd); - return -1; - } - old_linkup = (old_carrier[0] == '1'); - - new_carrier = linkup ? "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; - } - - close(fd); - return old_linkup; + return 0; } void diff --git a/lib/kni/rte_kni.h b/lib/kni/rte_kni.h index b0eaf4610416..ab5990fd210d 100644 --- a/lib/kni/rte_kni.h +++ b/lib/kni/rte_kni.h @@ -21,6 +21,7 @@ #include #include #include +#include #include @@ -245,18 +246,15 @@ int rte_kni_unregister_handlers(struct rte_kni *kni); * @param kni * pointer to struct rte_kni. * @param linkup - * New link state: - * 0 for linkdown. - * > 0 for linkup. + * new link state, speed, duplex, autoneg. * * @return + * On success: 0 * On failure: -1 - * Previous link state == linkdown: 0 - * Previous link state == linkup: 1 */ __rte_experimental int -rte_kni_update_link(struct rte_kni *kni, unsigned int linkup); +rte_kni_update_link(struct rte_kni *kni, struct rte_eth_link *link); /** * Close KNI device. diff --git a/lib/kni/rte_kni_common.h b/lib/kni/rte_kni_common.h index b547ea550171..35a1620e0bd2 100644 --- a/lib/kni/rte_kni_common.h +++ b/lib/kni/rte_kni_common.h @@ -130,10 +130,19 @@ struct rte_kni_device_info { uint8_t iova_mode; }; +struct rte_kni_link_info { + char name[RTE_KNI_NAMESIZE]; + unsigned int speed; + unsigned char duplex; + unsigned char autoneg; + unsigned char status; +}; + #define KNI_DEVICE "kni" #define RTE_KNI_IOCTL_TEST _IOWR(0, 1, int) #define RTE_KNI_IOCTL_CREATE _IOWR(0, 2, struct rte_kni_device_info) #define RTE_KNI_IOCTL_RELEASE _IOWR(0, 3, struct rte_kni_device_info) +#define RTE_KNI_IOCTL_LINK _IOWR(0, 4, struct rte_kni_link_info) #endif /* _RTE_KNI_COMMON_H_ */ -- 2.32.0