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 6C001A034F; Fri, 8 Oct 2021 12:58:06 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2EBD4411BA; Fri, 8 Oct 2021 12:56:24 +0200 (CEST) Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) by mails.dpdk.org (Postfix) with ESMTP id CC9DF411E0 for ; Thu, 7 Oct 2021 20:45:16 +0200 (CEST) Received: by mail-pj1-f51.google.com with SMTP id oa4so4874715pjb.2 for ; Thu, 07 Oct 2021 11:45:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oneconvergence.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DoysULAK+dKrjpiOk2yon28mzbgl6kIlwmgPfsgJlCw=; b=SmA0/PFCPsS5T1OJDtkxs6q/BvlziPiAtBPcKQIyC3fHgI6lIOYiJoHWW98HwzSZjb mw59rP1B0uJDOfARfdw+zxDiaadqG2GYJyMiQ1gdoO2isde0tKRNQ/DmAgQy6KYyL4Jm p91lmZ6VnTRoKSUkt1I9kbuSmU4LKDyFxzHDg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DoysULAK+dKrjpiOk2yon28mzbgl6kIlwmgPfsgJlCw=; b=l2nDpLBnkhMckf7/BZjnVd/amQfwDJLozo29puf+dmYzEgLj4pUJ8hKstv9lUw0p0N Wv11Cg88z6wHUlm0TGEexz2qUbp/HrXfFJBtLkrBhDzGfbF8xerpw8hCAgUBCRoF5JD5 3G8y8GS3Jk6yN+LwrCT3zaWAnbfS7QEPzqWOASXyPryqcoZpVgiz1Zt/H3I59D/cVgD9 3r+PlyKu2aLE8t7mW8mhsly+jveRD5/Vy0vvFLg5KZmXjPWa0g/NDzY7jtEAuHfMrlxR OZxsh3SzkhNEynaYSHzsT6Kwt3Sz6wIfXeWWz5MiIChGutAidPOfGWE7eLU71aQ47CKP ElfA== X-Gm-Message-State: AOAM532VtGh/5zYL9jNWAKVOynre/REEoMgxHCF3PiE1TPEq+61S4QXp IAhYpdnlBYTd2NaUPu8OrEXdbg== X-Google-Smtp-Source: ABdhPJzf8ns6/8XB/unAdqyKxnTqqbg5CPNjoD2QrY8HqtPARWK0JWvC3ETGtLo42T6Gfza2Dl3IBA== X-Received: by 2002:a17:90b:3901:: with SMTP id ob1mr7334329pjb.12.1633632316068; Thu, 07 Oct 2021 11:45:16 -0700 (PDT) Received: from srikanth-ThinkPad-T450.domain.name ([136.185.113.102]) by smtp.gmail.com with ESMTPSA id c11sm3311586pji.38.2021.10.07.11.45.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 11:45:15 -0700 (PDT) From: Srikanth Kaka To: Matan Azrad , Viacheslav Ovsiienko Cc: dev@dpdk.org, Vag Singh , Anand Thulasiram , Srikanth Kaka Date: Fri, 8 Oct 2021 00:13:32 +0530 Message-Id: <20211007184350.73858-24-srikanth.k@oneconvergence.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211007184350.73858-1-srikanth.k@oneconvergence.com> References: <20211007184350.73858-1-srikanth.k@oneconvergence.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Fri, 08 Oct 2021 12:55:54 +0200 Subject: [dpdk-dev] [PATCH v2 23/41] net/mlx5: add link update callback 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" callback to retrieve physical link information Signed-off-by: Srikanth Kaka Signed-off-by: Vag Singh Signed-off-by: Anand Thulasiram --- drivers/net/mlx5/freebsd/mlx5_ethdev_os.c | 175 ++++++++++++++++++++++ 1 file changed, 175 insertions(+) diff --git a/drivers/net/mlx5/freebsd/mlx5_ethdev_os.c b/drivers/net/mlx5/freebsd/mlx5_ethdev_os.c index 8b2ea1c594..d100addd51 100644 --- a/drivers/net/mlx5/freebsd/mlx5_ethdev_os.c +++ b/drivers/net/mlx5/freebsd/mlx5_ethdev_os.c @@ -7,6 +7,7 @@ #include #include #include +#include #include @@ -164,6 +165,180 @@ mlx5_set_flags(struct rte_eth_dev *dev, unsigned int keep, unsigned int flags) return mlx5_ifreq(dev, SIOCSIFFLAGS, &request); } +static const struct ifmedia_baudrate ifmedia_baudrate_desc[] = + IFM_BAUDRATE_DESCRIPTIONS; + +static uint64_t +mlx5_ifmedia_baudrate(int mword) +{ + int i; + + for (i = 0; ifmedia_baudrate_desc[i].ifmb_word != 0; i++) { + if (IFM_TYPE_MATCH(mword, ifmedia_baudrate_desc[i].ifmb_word)) + return (ifmedia_baudrate_desc[i].ifmb_baudrate); + } + + return (0); +} + +static int +mlx5_link_update_bsd(struct rte_eth_dev *dev, + struct rte_eth_link *link) +{ + struct mlx5_priv *priv = dev->data->dev_private; + struct rte_eth_link dev_link; + int link_speed = 0, sock; + struct ifmediareq ifmr; + char ifname[IF_NAMESIZE]; + int *media_list; + + sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); + if (sock == -1) { + DRV_LOG(ERR, + "port %u failed to open socket for link update: %s", + dev->data->port_id, strerror(rte_errno)); + return sock; + } + + mlx5_get_ifname(dev, &ifname); + memset(&ifmr, 0, sizeof(struct ifmediareq)); + strlcpy(ifmr.ifm_name, ifname, sizeof(ifmr.ifm_name)); + + if (ioctl(sock, SIOCGIFXMEDIA, (caddr_t)&ifmr) < 0) { + DRV_LOG(ERR, + "ioctl(SIOCGIFMEDIA) on %s: %s", + ifname, strerror(errno)); + close(sock); + return errno; + } + + media_list = (int *)malloc(ifmr.ifm_count * sizeof(int)); + ifmr.ifm_ulist = media_list; + + if (ioctl(sock, SIOCGIFXMEDIA, (caddr_t)&ifmr) < 0) { + DRV_LOG(ERR, + "ioctl(SIOCGIFMEDIA) on %s: %s", + ifname, strerror(errno)); + close(sock); + return errno; + } + + if (ifmr.ifm_status == (IFM_AVALID | IFM_ACTIVE)) + dev_link.link_status = ETH_LINK_UP; + else + dev_link.link_status = ETH_LINK_DOWN; + + link_speed = ifmr.ifm_status & IFM_AVALID ? + mlx5_ifmedia_baudrate(ifmr.ifm_active)/(1000*1000) : 0; + + if (link_speed == 0) + dev_link.link_speed = ETH_SPEED_NUM_NONE; + else + dev_link.link_speed = link_speed; + + priv->link_speed_capa = 0; + /* Add support for duplex types */ + dev_link.link_duplex = ETH_LINK_FULL_DUPLEX; + /* FreeBSD automatically negotiates speed, + * so it is displayed in its capabilities. + */ + priv->link_speed_capa |= ETH_LINK_SPEED_AUTONEG; + + for (int i = 1; i < ifmr.ifm_count; i += 2) { + switch (mlx5_ifmedia_baudrate(media_list[i]) / (1000 * 1000)) { + case 100000: + priv->link_speed_capa |= ETH_LINK_SPEED_100G; + break; + case 56000: + priv->link_speed_capa |= ETH_LINK_SPEED_56G; + break; + case 50000: + priv->link_speed_capa |= ETH_LINK_SPEED_50G; + break; + case 40000: + priv->link_speed_capa |= ETH_LINK_SPEED_40G; + break; + case 25000: + priv->link_speed_capa |= ETH_LINK_SPEED_25G; + break; + case 10000: + priv->link_speed_capa |= ETH_LINK_SPEED_10G; + break; + case 2500: + priv->link_speed_capa |= ETH_LINK_SPEED_2_5G; + break; + case 1000: + priv->link_speed_capa |= ETH_LINK_SPEED_1G; + break; + case 100: + priv->link_speed_capa |= (dev_link.link_duplex == + ETH_LINK_FULL_DUPLEX) ? + ETH_LINK_SPEED_100M : + ETH_LINK_SPEED_100M_HD; + break; + case 10: + priv->link_speed_capa |= (dev_link.link_duplex == + ETH_LINK_FULL_DUPLEX) ? + ETH_LINK_SPEED_10M : + ETH_LINK_SPEED_10M_HD; + break; + case 0: + default: + break; + } + } + dev_link.link_autoneg = !(dev->data->dev_conf.link_speeds & + ETH_LINK_SPEED_FIXED); + free(media_list); + *link = dev_link; + close(sock); + return 0; +} + +/** + * DPDK callback to retrieve physical link information. + * + * @param dev + * Pointer to Ethernet device structure. + * @param wait_to_complete + * Wait for request completion. + * + * @return + * 0 if link status was not updated, positive if it was, a negative errno + * value otherwise and rte_errno is set. + */ +int +mlx5_link_update(struct rte_eth_dev *dev, int wait_to_complete) +{ + int ret; + struct rte_eth_link dev_link; + time_t start_time = time(NULL); + int retry = MLX5_GET_LINK_STATUS_RETRY_COUNT; + + do { + ret = mlx5_link_update_bsd(dev, &dev_link); + if (ret == 0) + break; + /* Handle wait to complete situation. */ + if ((wait_to_complete || retry) && ret == -EAGAIN) { + if (abs((int)difftime(time(NULL), start_time)) < + MLX5_LINK_STATUS_TIMEOUT) { + usleep(0); + continue; + } else { + rte_errno = EBUSY; + return -rte_errno; + } + } else if (ret < 0) { + return ret; + } + } while (wait_to_complete || retry-- > 0); + ret = !!memcmp(&dev->data->dev_link, &dev_link, + sizeof(struct rte_eth_link)); + dev->data->dev_link = dev_link; + return ret; +} + /** * DPDK callback to bring the link DOWN. * -- 2.30.2