From patchwork Thu Oct 7 18:43:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srikanth Kaka X-Patchwork-Id: 100786 X-Patchwork-Delegate: rasland@nvidia.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id BB97BA034F; Fri, 8 Oct 2021 12:57:39 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7C95441197; Fri, 8 Oct 2021 12:56:18 +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 AD1DE411E0 for ; Thu, 7 Oct 2021 20:45:02 +0200 (CEST) Received: by mail-pj1-f51.google.com with SMTP id ls14-20020a17090b350e00b001a00e2251c8so5832857pjb.4 for ; Thu, 07 Oct 2021 11:45:02 -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=bjX+hK2/Uqg3HTwK9iNhMFfP0OY7+YjPmyNUGO1kAxc=; b=cr4sTgsygbeULuWgEfKhWLOfdwrSooJbjvqxvhmKG74F2SsINwNFyvxLSq/6l1Bq7V WK8UZCmXyTgHhS3gaLdiMSt2sbEG/J9rzR/CUh7yzfyqK/mXFQqOyvC9Up+jSesr7NAO D6gMR6NazNUBaZQS2/XgGirv2E0Hy0VAJm9Vc= 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=bjX+hK2/Uqg3HTwK9iNhMFfP0OY7+YjPmyNUGO1kAxc=; b=58pyb8Y31amC+YVYYPTOFLziN/q2mKFurN9PiGL4GwHGTHsx/7mqAl3gwjjE2X87xn VbsV9iS9gG3YlBBJjGiRHrywKePh/cug6cfglyg4Pvr2qRbxuVczzrUgAYij2DpmZlEF kt/AFNKuU5L5vQivw2Jd+0sM3OzV9IahmKv/rUk97VM2QhqvPy8145bfpWLfNCpdIoAw zm422vRUkLSll+AedGtHFZLmlJdpCR3J7n1SevmvPohBr+ZnLxxBUkIQIXe9IRHw7kni PST5iejhUmfNir/3L84jvedg+yH743ZN3v9SEvj2n68t+nQUqfz0fxUCvuKMlN87YiGI HWsA== X-Gm-Message-State: AOAM530OGrl5nLM3zilMXS5MRamNczF4RMzuy58wXYT3gF9TaeCk2Mtr QuOnto3T44xQCrnx70/bSRkgRdHHn0bbeQ== X-Google-Smtp-Source: ABdhPJwRWNKT8sgQ8eOniSHWf7CR4vPwmaTSDEy6uVjMTGLzcdayXiXgqOmaWNu0kWuxLJjq6wmfng== X-Received: by 2002:a17:90b:1d8e:: with SMTP id pf14mr6548935pjb.125.1633632301950; Thu, 07 Oct 2021 11:45:01 -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.44.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 11:45:01 -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:27 +0530 Message-Id: <20211007184350.73858-19-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 X-Mailman-Approved-At: Fri, 08 Oct 2021 12:55:54 +0200 Subject: [dpdk-dev] [PATCH v2 18/41] net/mlx5: add get MAC 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" MAC address is retrieved by making an IOCTL call Signed-off-by: Srikanth Kaka Signed-off-by: Vag Singh Signed-off-by: Anand Thulasiram --- drivers/net/mlx5/freebsd/mlx5_ethdev_os.c | 88 +++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/drivers/net/mlx5/freebsd/mlx5_ethdev_os.c b/drivers/net/mlx5/freebsd/mlx5_ethdev_os.c index ad53ec5968..9aa38de649 100644 --- a/drivers/net/mlx5/freebsd/mlx5_ethdev_os.c +++ b/drivers/net/mlx5/freebsd/mlx5_ethdev_os.c @@ -4,6 +4,9 @@ */ #include +#include +#include +#include #include @@ -31,3 +34,88 @@ mlx5_get_ifname(const struct rte_eth_dev *dev, char (*ifname)[MLX5_NAMESIZE]) MLX5_ASSERT(priv->sh); return mlx5_get_ifname_sysfs(priv->sh->ibdev_path, *ifname); } + +/** + * Perform ifreq ioctl() on associated netdev ifname. + * + * @param[in] ifname + * Pointer to netdev name. + * @param req + * Request number to pass to ioctl(). + * @param[out] ifr + * Interface request structure output buffer. + * + * @return + * 0 on success, a negative errno value otherwise and rte_errno is set. + */ +static int +mlx5_ifreq_by_ifname(const char *ifname, int req, struct ifreq *ifr) +{ + int sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); + int ret = 0; + + if (sock == -1) { + rte_errno = errno; + return -rte_errno; + } + rte_strscpy(ifr->ifr_name, ifname, sizeof(ifr->ifr_name)); + ret = ioctl(sock, req, ifr); + if (ret == -1) { + rte_errno = errno; + goto error; + } + close(sock); + return 0; +error: + close(sock); + return -rte_errno; +} + +/** + * Perform ifreq ioctl() on associated Ethernet device. + * + * @param[in] dev + * Pointer to Ethernet device. + * @param req + * Request number to pass to ioctl(). + * @param[out] ifr + * Interface request structure output buffer. + * + * @return + * 0 on success, a negative errno value otherwise and rte_errno is set. + */ +static int +mlx5_ifreq(const struct rte_eth_dev *dev, int req, struct ifreq *ifr) +{ + char ifname[sizeof(ifr->ifr_name)]; + int ret; + + ret = mlx5_get_ifname(dev, &ifname); + if (ret) + return -rte_errno; + return mlx5_ifreq_by_ifname(ifname, req, ifr); +} + +/** + * Get MAC address by querying netdevice. + * + * @param[in] dev + * Pointer to Ethernet device. + * @param[out] mac + * MAC address output buffer. + * + * @return + * 0 on success, a negative errno value otherwise and rte_errno is set. + */ +int +mlx5_get_mac(struct rte_eth_dev *dev, uint8_t (*mac)[RTE_ETHER_ADDR_LEN]) +{ + struct ifreq request; + int ret; + + ret = mlx5_ifreq(dev, SIOCGHWADDR, &request); + if (ret) + return ret; + memcpy(mac, request.ifr_addr.sa_data, RTE_ETHER_ADDR_LEN); + return 0; +}