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 178B9A0C46; Mon, 27 Sep 2021 16:59:06 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7C6F74113A; Mon, 27 Sep 2021 16:58:17 +0200 (CEST) Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) by mails.dpdk.org (Postfix) with ESMTP id 7419C410DD for ; Mon, 27 Sep 2021 15:36:25 +0200 (CEST) Received: by mail-pj1-f54.google.com with SMTP id nn5-20020a17090b38c500b0019af1c4b31fso13720170pjb.3 for ; Mon, 27 Sep 2021 06:36:25 -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=nfwyr54uQ/aTRN+CCX/AIpcZWFvZzvzWpu82MeTdmX4=; b=b4iU6CMEhYZkZDP3iL8TTQPA20K0jbEOa0Vz1pvDTZrdHG6SPfQlTtGUZ10lL04Ew8 MXBzOEbc9G2IV1kUMxqFf7xSAty9cn4h3R3s9m80tBNfNj4zT14vX5g5FPURfF/LnWUY RfScQf5oc3lXq5hIN5CTSZNX8vp7nrr1LEXTE= 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=nfwyr54uQ/aTRN+CCX/AIpcZWFvZzvzWpu82MeTdmX4=; b=gtBjefWK/htjBShQhTQGkfhB4mzgfbNT4ye6WwYQiCmxA2ZzzYFDVxV8UQTETNHE6i tifyPhBvIj+KycGF89Jr75ZCKTFHbvL0ntce1TYfWPV6C/2q8Iv7cD+VNPX2LFkNyxcc +3xZyqR8nJ5OABmm+wkCNTSyZt7o3n2HKd+YdZC2/6UIC0XBSiaIvTt0Ab6HdahPxAfj zLHANgDaUxqE23k42sOOfv0iA15IdzeP3bzprOE5iA8PpIK9ivvL+zpP6UAxd581wc9e rRqypmxs+eCUJ7UopR6TtUiQ82jcypPqdmwPFuNS6LX9lynDGqTCmFphnbej9krrBPXU TnIA== X-Gm-Message-State: AOAM531Bb/RVhKcfa0eJotOpElqGXl17DgWr80vMCG3WStwd7QgDzEVv n8UhHsP0MvMBrC8qIBrlQFnnj6m0IXGXQQ== X-Google-Smtp-Source: ABdhPJxpnzUc+z0dzYeOqb3S79mehsykRRiL3NW67vNdtOTud6rUlA2u/Tu+Edo1ubeG5wLBdx/JWg== X-Received: by 2002:a17:902:708b:b0:13e:1a20:f1b0 with SMTP id z11-20020a170902708b00b0013e1a20f1b0mr7889662plk.51.1632749784683; Mon, 27 Sep 2021 06:36:24 -0700 (PDT) Received: from srikanth-ThinkPad-T450.domain.name ([223.178.22.200]) by smtp.gmail.com with ESMTPSA id t6sm17342274pfh.63.2021.09.27.06.36.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Sep 2021 06:36:24 -0700 (PDT) From: Srikanth Kaka To: Matan Azrad , Viacheslav Ovsiienko Cc: dev@dpdk.org, Vag Singh , Anand Thulasiram , Srikanth Kaka Date: Mon, 27 Sep 2021 19:04:39 +0530 Message-Id: <20210927133450.10653-9-srikanth.k@oneconvergence.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210927133450.10653-1-srikanth.k@oneconvergence.com> References: <20210927133450.10653-1-srikanth.k@oneconvergence.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Mon, 27 Sep 2021 16:58:07 +0200 Subject: [dpdk-dev] [PATCH 08/19] common/mlx5: derive PCI addr in FreeBSD 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" The FreeBSD OFED gives the Linux path as the IBV device path. The PCI addr is derived by getting the IBV dev interface index and finding the corresponding sysctl variable pertaining to it. Signed-off-by: Srikanth Kaka Signed-off-by: Vag Singh Signed-off-by: Anand Thulasiram --- drivers/common/mlx5/freebsd/mlx5_common_os.c | 79 ++++++++++---------- drivers/common/mlx5/freebsd/mlx5_common_os.h | 2 + 2 files changed, 41 insertions(+), 40 deletions(-) diff --git a/drivers/common/mlx5/freebsd/mlx5_common_os.c b/drivers/common/mlx5/freebsd/mlx5_common_os.c index 9e0c823c97..af28ff756d 100644 --- a/drivers/common/mlx5/freebsd/mlx5_common_os.c +++ b/drivers/common/mlx5/freebsd/mlx5_common_os.c @@ -10,6 +10,7 @@ #endif #include #include +#include #include #include @@ -26,48 +27,46 @@ const struct mlx5_glue *mlx5_glue; int mlx5_get_pci_addr(const char *dev_path, struct rte_pci_addr *pci_addr) { - FILE *file; - char line[32]; - int rc = -ENOENT; - MKSTR(path, "%s/device/uevent", dev_path); - - file = fopen(path, "rb"); - if (file == NULL) { - rte_errno = errno; - return -rte_errno; - } - while (fgets(line, sizeof(line), file) == line) { - size_t len = strlen(line); - - /* Truncate long lines. */ - if (len == (sizeof(line) - 1)) { - while (line[(len - 1)] != '\n') { - int ret = fgetc(file); - - if (ret == EOF) - goto exit; - line[(len - 1)] = ret; - } - /* No match for long lines. */ - continue; - } - /* Extract information. */ - if (sscanf(line, - "PCI_SLOT_NAME=" - "%" SCNx32 ":%" SCNx8 ":%" SCNx8 ".%" SCNx8 "\n", - &pci_addr->domain, - &pci_addr->bus, - &pci_addr->devid, - &pci_addr->function) == 4) { - rc = 0; + 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; } -exit: - fclose(file); - if (rc) - rte_errno = -rc; - return rc; + 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; } /** diff --git a/drivers/common/mlx5/freebsd/mlx5_common_os.h b/drivers/common/mlx5/freebsd/mlx5_common_os.h index c3202b6786..8fb681444f 100644 --- a/drivers/common/mlx5/freebsd/mlx5_common_os.h +++ b/drivers/common/mlx5/freebsd/mlx5_common_os.h @@ -19,6 +19,8 @@ #include "mlx5_glue.h" #include "mlx5_malloc.h" +#define MLX5_SYSCTL_BY_NAME_SIZE 100 + /** * Get device name. Given an ibv_device pointer - return a * pointer to the corresponding device name. -- 2.30.2