From patchwork Thu Oct 7 18:43:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srikanth Kaka X-Patchwork-Id: 100776 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 BDDB7A034F; Fri, 8 Oct 2021 12:56:42 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 27BB141157; Fri, 8 Oct 2021 12:56:06 +0200 (CEST) Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by mails.dpdk.org (Postfix) with ESMTP id 86CE8411E0 for ; Thu, 7 Oct 2021 20:44:35 +0200 (CEST) Received: by mail-pf1-f176.google.com with SMTP id g2so6084126pfc.6 for ; Thu, 07 Oct 2021 11:44:35 -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=O1HAl/0obPYLy5OuIz4vR/jgvJYBAkOOVjqjEksmG9o=; b=it2GUB2Fyb00BLP6znGCAGLj/ESlVa51jOXIOHummHPmFbejeWm/KRCFm89aHvxRwS cADO2RZmXnDsQRItCl8vMMoe52Lu2qOkD9kXGZu/ieVZXQLFEXQMuWx6CRLgGTBB7fUn KTA85v78nMS2ad0EMGvtSm0lNHlUJX9JLZ3gA= 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=O1HAl/0obPYLy5OuIz4vR/jgvJYBAkOOVjqjEksmG9o=; b=CGuNTDVQjCp5FAz7SosYbe4JF/jHleC2+LNPqT1J8VIE6GVi32nIz9RLMh++n3i4Kq /WJq8obrXWVeKttD1vUcp3rZT+daverpy+c1oxZUPWxKVLxwwMmfed0wQUOFXQbWX37/ iRUb5wjOxlduwqYZ2+3a92fJME+uxuX1z75sBoQXNWifVmWWwZlywAgbV/LVNdEiMIkf vz0Al05c96oZhzHuz5MKNKElpgonUQmMrbmpgva2tGNeArL6QHfDTmy34YVcBafZiFVi 3Pn4lhKGTkQctafTSOA2YCpgWPjFHOhfyeyRMXp1rFyGdfn4nAcRWfte+O2LuSq+DXPX UCDQ== X-Gm-Message-State: AOAM531gzDsMWRXxO2SbIM+wTCKngET0kunK08FFMbQaHZtq+TMQTHS0 trOTwJq6dIoZC/CFtUPVoXPUSA== X-Google-Smtp-Source: ABdhPJwUafqOApWYIfBdyv0IsN3RGH9zPUjP+ObJj12bQtfU2kq+lQPU0fja70l6mPew3nckZYtsbw== X-Received: by 2002:a63:131c:: with SMTP id i28mr971243pgl.396.1633632274826; Thu, 07 Oct 2021 11:44:34 -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.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 11:44:34 -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:17 +0530 Message-Id: <20211007184350.73858-9-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 08/41] common/mlx5: derive PCI addr from device path 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" Using syctl call the PCI addr is derived dev.mlx5_core.0.%location: slot=8 function=0 dbsf=pci0:0:8:0 Signed-off-by: Srikanth Kaka Signed-off-by: Vag Singh Signed-off-by: Anand Thulasiram --- drivers/common/mlx5/freebsd/mlx5_common_os.c | 48 ++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/drivers/common/mlx5/freebsd/mlx5_common_os.c b/drivers/common/mlx5/freebsd/mlx5_common_os.c index 23370857eb..aa3b73f8a8 100644 --- a/drivers/common/mlx5/freebsd/mlx5_common_os.c +++ b/drivers/common/mlx5/freebsd/mlx5_common_os.c @@ -14,6 +14,54 @@ #include "mlx5_common_os.h" #include "mlx5_glue.h" +/** + * Derive PCI address from devpath + */ +int +mlx5_get_pci_addr(const char *dev_path, struct rte_pci_addr *pci_addr) +{ + char id[10]; + char searchstr[MLX5_SYSCTL_BY_NAME_SIZE]; + size_t length = MLX5_SYSCTL_BY_NAME_SIZE; + char name[MLX5_SYSCTL_BY_NAME_SIZE]; + int traverse = 0; + + strncpy(id, &dev_path[strlen("/sys/class/infiniband/mlx5_")], + strlen(dev_path) - strlen("/sys/class/infiniband/mlx5_")); + sprintf(searchstr, "dev.mlx5_core.%s.%slocation", id, "%"); + sysctlbyname(searchstr, &name, &length, NULL, 0); + + while (name[traverse]) { + if (name[traverse] == 'p' && name[traverse + 1] == 'c' && + name[traverse + 2] == 'i') + break; + ++traverse; + } + traverse += 3; + + int end = traverse; + + while (name[end] != ' ') + ++end; + + char address[end - traverse + 1]; + + memcpy(address, &name[traverse], end - traverse); + address[end - traverse] = '\0'; + + char *ptr = strtok(address, " :"); + + pci_addr->domain = (uint32_t)atoi(ptr); + ptr = strtok(NULL, " :"); + pci_addr->bus = (uint8_t)atoi(ptr); + ptr = strtok(NULL, " :"); + pci_addr->devid = (uint8_t)atoi(ptr); + ptr = strtok(NULL, " :"); + pci_addr->function = (uint8_t)atoi(ptr); + + return 0; +} + /** * Derive IB dev index from devpath */