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 6F8C6A0C52; Wed, 24 Nov 2021 11:23:58 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5A47441177; Wed, 24 Nov 2021 11:23:58 +0100 (CET) Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2088.outbound.protection.outlook.com [40.107.243.88]) by mails.dpdk.org (Postfix) with ESMTP id 5CCF041165 for ; Wed, 24 Nov 2021 11:23:57 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HX7/7LekkEnFPljRZtXpcdYLwOu3eqK/WReA67+uI8s5KvxJwE2triyd1rzeqD2IBaRRLeTmLaWaitP39+oF0YPXOcEmJT5T57vORGDZLuEg8NxfgC2Y9NBI+p2Ox3lvilrgz0E9yTq67H+PF64osJidd13KClWu9wIE4V39tLHOaaTUUmlChzKywdr7or9Xqlx840rlMKVwduBSE6y10F8KKJ3bNSd5x9i+i4K7v11vxarNj2tHSMcv2ftCpnRWrfLIoJj+HKr9jejvoYQB/P57CqLBSAMz620SeLqYV04ssZ8LAanz77imUxNAiLDTjvomVX9/hw3XQXervtsRaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=eL4MFaF3lVSUJGASO0KO1OzIO18+4dM7jqBn3jmbM2w=; b=kRP3BGV3tj3Xk0oyQvRfi9qrkSOuRpnt7dkrLaQKqGPuacG3cthDdrgjMd3ulWbHt9waf+usvCbJrlrC4f4AxYJTVxcebXLwmkZm6hZn3THHiTKnAWtZ7IygeXXVHIxhLw7d7kspZZa1SeZ00RGi1GrIcfnScD6yvJ9whgeU8nwgPavfkSOJQMnAE0964Pj91/sdPHTDv97nM/8UwGhZn9ufqdsiPYChPDe3emaCXCuzZao/YSqjjva3JqpVf1d2jj9zcXDDrplpZf25vIChlPqjFABAXErhZGFBYlFWnZR/WCbvBxrP9awQ659P3gk8z7r0+2Xw4x52oTeliNysrQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=dpdk.org smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=eL4MFaF3lVSUJGASO0KO1OzIO18+4dM7jqBn3jmbM2w=; b=mqRZmC7p/HHnTXIyV151XKndnJc1BowLga/Sd1Q+yTqCkHMUA2Z110qdCNizKdtTSrTQINlUGDhtKpkt2cLz46IHNcHDg0ktXciViHaysGtL2auPEZBt8lneKoXH7z8w9A0QP4PVoq1kf9Q27y2DEElrcU7hX9NxkcuOm98mYSbCzPNdDjNxMH7MqwFUeXoGisqytBHEYhCyl568wZc0G658PvWv1gDO3W54qiGC1d+lJF5T9/podetW+9zDjkMrQg5MNTXHXZk9t0WjWheWtIGfmnzOwRsYF3hRhbZQbvVg4azRcHeo1RVCKlwLSpSuor0/gvFUE2mzBneQVNoZwQ== Received: from BN6PR11CA0020.namprd11.prod.outlook.com (2603:10b6:405:2::30) by MN2PR12MB3632.namprd12.prod.outlook.com (2603:10b6:208:c1::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.22; Wed, 24 Nov 2021 10:23:55 +0000 Received: from BN8NAM11FT003.eop-nam11.prod.protection.outlook.com (2603:10b6:405:2:cafe::99) by BN6PR11CA0020.outlook.office365.com (2603:10b6:405:2::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.21 via Frontend Transport; Wed, 24 Nov 2021 10:23:55 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by BN8NAM11FT003.mail.protection.outlook.com (10.13.177.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4713.20 via Frontend Transport; Wed, 24 Nov 2021 10:23:54 +0000 Received: from nvidia.com (172.20.187.5) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Wed, 24 Nov 2021 10:23:44 +0000 From: To: CC: Elena Agostini Subject: [PATCH v2] gpu/cuda: set rte_errno Date: Wed, 24 Nov 2021 18:34:09 +0000 Message-ID: <20211124183409.11181-1-eagostini@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211118204527.26524-1-eagostini@nvidia.com> References: <20211118204527.26524-1-eagostini@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [172.20.187.5] X-ClientProxiedBy: HQMAIL105.nvidia.com (172.20.187.12) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c710fedf-84cc-44d0-6948-08d9af3484d7 X-MS-TrafficTypeDiagnostic: MN2PR12MB3632: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:561; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SbC4HIzjAFs5kJoH+ZMJacvX+CrigL1OU+ZGWBZJ7BgOEh5g8QA8AyHNkBw4GDeVw9qlB7bqk8Te4H0IgwcGTkG8fnHk0BsPkLcrFu2KhVJ7BYz0tXEY4SFMj/J/ERbdU7pdIknG/YcqSKRDknLwZ4Qr+WfYgyJS9UDpksFZvbo1VTDTbUQL4opYdAOALqMLkNW4kOl9eRs/8o9A2TVzC+0IEoYAAkWHa8a968upjXf7d4rZaNI8GszhXq6enRwmyGen94xO0lTMAW/FzKO+vpmz4uilIn7vCeRw4kvDZ+5t14CEGACklVw0la8+fCoLvp4kmcHUiY41iG/CjWH6W1e8QNTKB9m6PtaOXClUQ1n+nwlengq9lKeXrLzwlXukNN+mlJJ3zCKZ7XETjmkvXAlRpyo+1BTyorn6456DkTxnAZTa7SdsbN0QH9psb5rWZpuB1/RWrQXvZfr6CThNNMas7FRVBKXY9YG0gJUTrLJFg2ZJ59oRz2NGqhTj5ZhTKCO6Z8uQx4H+t/MzV8jWC2nhrgIMDxjWWZ8FSFrL0gkmu4SrOz+5tdJliBB4K+Bde95rOR6cwtswALytCZ8golb/ZK9S55Wj7jAnvKSQbFTWNRaTyajSDq0uUgA683rVLcOxd1DKiJ16RlUVjAtO8fqcK7nmbsFTH4N4tQKaJb6WFJD0Ao6zYksRg3zZ4I8h8NUvHPYuHtqFeQ6HOLj5xw== X-Forefront-Antispam-Report: CIP:216.228.112.34; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid03.nvidia.com; CAT:NONE; SFS:(4636009)(36840700001)(46966006)(7696005)(426003)(5660300002)(70206006)(508600001)(83380400001)(6916009)(336012)(82310400004)(55016003)(70586007)(6666004)(36860700001)(1076003)(186003)(47076005)(2876002)(36756003)(16526019)(4326008)(7636003)(107886003)(86362001)(2616005)(8676002)(8936002)(2906002)(6286002)(30864003)(356005)(316002)(26005); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Nov 2021 10:23:54.2001 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c710fedf-84cc-44d0-6948-08d9af3484d7 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.34]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT003.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3632 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 From: Elena Agostini Set correct rte_errno variable in gpu/cuda and return -rte_errno in case of error. rte_errno values are compliant with the gpudev library documentation. Fixes: 1306a73b1958 ("gpu/cuda: introduce CUDA driver") Signed-off-by: Elena Agostini --- drivers/gpu/cuda/cuda.c | 184 +++++++++++++++++++++++++++------------- 1 file changed, 123 insertions(+), 61 deletions(-) diff --git a/drivers/gpu/cuda/cuda.c b/drivers/gpu/cuda/cuda.c index a4869da186..882df08e56 100644 --- a/drivers/gpu/cuda/cuda.c +++ b/drivers/gpu/cuda/cuda.c @@ -464,8 +464,10 @@ cuda_dev_info_get(struct rte_gpu *dev, struct rte_gpu_info *info) CUcontext current_ctx; CUcontext input_ctx; - if (dev == NULL) - return -ENODEV; + if (dev == NULL) { + rte_errno = ENODEV; + return -rte_errno; + } /* Child initialization time probably called by rte_gpu_add_child() */ if (dev->mpshared->info.parent != RTE_GPU_ID_NONE && @@ -476,7 +478,8 @@ cuda_dev_info_get(struct rte_gpu *dev, struct rte_gpu_info *info) pfn_cuGetErrorString(res, &(err_string)); rte_cuda_log(ERR, "cuCtxGetCurrent failed with %s", err_string); - return -EPERM; + rte_errno = EPERM; + return -rte_errno; } /* Set child ctx as current ctx */ @@ -486,7 +489,8 @@ cuda_dev_info_get(struct rte_gpu *dev, struct rte_gpu_info *info) pfn_cuGetErrorString(res, &(err_string)); rte_cuda_log(ERR, "cuCtxSetCurrent input failed with %s", err_string); - return -EPERM; + rte_errno = EPERM; + return -rte_errno; } /* @@ -505,8 +509,10 @@ cuda_dev_info_get(struct rte_gpu *dev, struct rte_gpu_info *info) (uint32_t)affinityPrm.param.smCount.val; ret = rte_gpu_info_get(dev->mpshared->info.parent, &parent_info); - if (ret) - return -ENODEV; + if (ret) { + rte_errno = ENODEV; + return -rte_errno; + } dev->mpshared->info.total_memory = parent_info.total_memory; /* @@ -517,7 +523,8 @@ cuda_dev_info_get(struct rte_gpu *dev, struct rte_gpu_info *info) RTE_CACHE_LINE_SIZE); if (dev->mpshared->dev_private == NULL) { rte_cuda_log(ERR, "Failed to allocate memory for GPU process private"); - return -EPERM; + rte_errno = EPERM; + return -rte_errno; } private = (struct cuda_info *)dev->mpshared->dev_private; @@ -527,7 +534,8 @@ cuda_dev_info_get(struct rte_gpu *dev, struct rte_gpu_info *info) pfn_cuGetErrorString(res, &(err_string)); rte_cuda_log(ERR, "cuCtxGetDevice failed with %s", err_string); - return -EPERM; + rte_errno = EPERM; + return -rte_errno; } res = pfn_cuDeviceGetName(private->gpu_name, @@ -536,7 +544,8 @@ cuda_dev_info_get(struct rte_gpu *dev, struct rte_gpu_info *info) pfn_cuGetErrorString(res, &(err_string)); rte_cuda_log(ERR, "cuDeviceGetName failed with %s", err_string); - return -EPERM; + rte_errno = EPERM; + return -rte_errno; } /* Restore original ctx as current ctx */ @@ -545,7 +554,8 @@ cuda_dev_info_get(struct rte_gpu *dev, struct rte_gpu_info *info) pfn_cuGetErrorString(res, &(err_string)); rte_cuda_log(ERR, "cuCtxSetCurrent current failed with %s", err_string); - return -EPERM; + rte_errno = EPERM; + return -rte_errno; } } @@ -576,7 +586,8 @@ cuda_mem_alloc(struct rte_gpu *dev, size_t size, void **ptr) pfn_cuGetErrorString(res, &(err_string)); rte_cuda_log(ERR, "cuCtxGetCurrent failed with %s", err_string); - return -EPERM; + rte_errno = EPERM; + return -rte_errno; } /* Set child ctx as current ctx */ @@ -586,13 +597,16 @@ cuda_mem_alloc(struct rte_gpu *dev, size_t size, void **ptr) pfn_cuGetErrorString(res, &(err_string)); rte_cuda_log(ERR, "cuCtxSetCurrent input failed with %s", err_string); - return -EPERM; + rte_errno = EPERM; + return -rte_errno; } /* Get next memory list item */ mem_alloc_list_tail = mem_list_add_item(); - if (mem_alloc_list_tail == NULL) - return -ENOMEM; + if (mem_alloc_list_tail == NULL) { + rte_errno = EPERM; + return -rte_errno; + } /* Allocate memory */ mem_alloc_list_tail->size = size; @@ -602,7 +616,8 @@ cuda_mem_alloc(struct rte_gpu *dev, size_t size, void **ptr) pfn_cuGetErrorString(res, &(err_string)); rte_cuda_log(ERR, "cuCtxSetCurrent current failed with %s", err_string); - return -EPERM; + rte_errno = EPERM; + return -rte_errno; } /* GPUDirect RDMA attribute required */ @@ -613,7 +628,8 @@ cuda_mem_alloc(struct rte_gpu *dev, size_t size, void **ptr) rte_cuda_log(ERR, "Could not set SYNC MEMOP attribute for " "GPU memory at %"PRIu32", err %d", (uint32_t)mem_alloc_list_tail->ptr_d, res); - return -EPERM; + rte_errno = EPERM; + return -rte_errno; } mem_alloc_list_tail->pkey = get_hash_from_ptr((void *)mem_alloc_list_tail->ptr_d); @@ -629,7 +645,8 @@ cuda_mem_alloc(struct rte_gpu *dev, size_t size, void **ptr) pfn_cuGetErrorString(res, &(err_string)); rte_cuda_log(ERR, "cuCtxSetCurrent current failed with %s", err_string); - return -EPERM; + rte_errno = EPERM; + return -rte_errno; } *ptr = (void *)mem_alloc_list_tail->ptr_d; @@ -656,7 +673,8 @@ cuda_mem_register(struct rte_gpu *dev, size_t size, void *ptr) pfn_cuGetErrorString(res, &(err_string)); rte_cuda_log(ERR, "cuCtxGetCurrent failed with %s", err_string); - return -EPERM; + rte_errno = EPERM; + return -rte_errno; } /* Set child ctx as current ctx */ @@ -666,13 +684,16 @@ cuda_mem_register(struct rte_gpu *dev, size_t size, void *ptr) pfn_cuGetErrorString(res, &(err_string)); rte_cuda_log(ERR, "cuCtxSetCurrent input failed with %s", err_string); - return -EPERM; + rte_errno = EPERM; + return -rte_errno; } /* Get next memory list item */ mem_alloc_list_tail = mem_list_add_item(); - if (mem_alloc_list_tail == NULL) - return -ENOMEM; + if (mem_alloc_list_tail == NULL) { + rte_errno = EPERM; + return -rte_errno; + } /* Allocate memory */ mem_alloc_list_tail->size = size; @@ -688,7 +709,8 @@ cuda_mem_register(struct rte_gpu *dev, size_t size, void *ptr) err_string, mem_alloc_list_tail->ptr_h, mem_alloc_list_tail->size); - return -EPERM; + rte_errno = EPERM; + return -rte_errno; } res = pfn_cuDeviceGetAttribute(&(use_ptr_h), @@ -698,7 +720,8 @@ cuda_mem_register(struct rte_gpu *dev, size_t size, void *ptr) pfn_cuGetErrorString(res, &(err_string)); rte_cuda_log(ERR, "cuDeviceGetAttribute failed with %s", err_string); - return -EPERM; + rte_errno = EPERM; + return -rte_errno; } if (use_ptr_h == 0) { @@ -708,13 +731,15 @@ cuda_mem_register(struct rte_gpu *dev, size_t size, void *ptr) pfn_cuGetErrorString(res, &(err_string)); rte_cuda_log(ERR, "cuMemHostGetDevicePointer failed with %s", err_string); - return -EPERM; + rte_errno = EPERM; + return -rte_errno; } if ((uintptr_t)mem_alloc_list_tail->ptr_d != (uintptr_t)mem_alloc_list_tail->ptr_h) { rte_cuda_log(ERR, "Host input pointer is different wrt GPU registered pointer"); - return -ENOTSUP; + rte_errno = ENOTSUP; + return -rte_errno; } } else { mem_alloc_list_tail->ptr_d = (CUdeviceptr)mem_alloc_list_tail->ptr_h; @@ -727,7 +752,8 @@ cuda_mem_register(struct rte_gpu *dev, size_t size, void *ptr) if (res != 0) { rte_cuda_log(ERR, "Could not set SYNC MEMOP attribute for GPU memory at %"PRIu32 ", err %d", (uint32_t)mem_alloc_list_tail->ptr_d, res); - return -EPERM; + rte_errno = EPERM; + return -rte_errno; } mem_alloc_list_tail->pkey = get_hash_from_ptr((void *)mem_alloc_list_tail->ptr_h); @@ -742,7 +768,8 @@ cuda_mem_register(struct rte_gpu *dev, size_t size, void *ptr) pfn_cuGetErrorString(res, &(err_string)); rte_cuda_log(ERR, "cuCtxSetCurrent current failed with %s", err_string); - return -EPERM; + rte_errno = EPERM; + return -rte_errno; } return 0; @@ -764,7 +791,8 @@ cuda_mem_free(struct rte_gpu *dev, void *ptr) mem_item = mem_list_find_item(hk); if (mem_item == NULL) { rte_cuda_log(ERR, "Memory address 0x%p not found in driver memory", ptr); - return -EPERM; + rte_errno = EPERM; + return -rte_errno; } if (mem_item->mtype == GPU_MEM) { @@ -773,7 +801,8 @@ cuda_mem_free(struct rte_gpu *dev, void *ptr) pfn_cuGetErrorString(res, &(err_string)); rte_cuda_log(ERR, "cuMemFree current failed with %s", err_string); - return -EPERM; + rte_errno = EPERM; + return -rte_errno; } return mem_list_del_item(hk); @@ -800,7 +829,8 @@ cuda_mem_unregister(struct rte_gpu *dev, void *ptr) mem_item = mem_list_find_item(hk); if (mem_item == NULL) { rte_cuda_log(ERR, "Memory address 0x%p not found in driver memory", ptr); - return -EPERM; + rte_errno = EPERM; + return -rte_errno; } if (mem_item->mtype == CPU_REGISTERED) { @@ -809,7 +839,8 @@ cuda_mem_unregister(struct rte_gpu *dev, void *ptr) pfn_cuGetErrorString(res, &(err_string)); rte_cuda_log(ERR, "cuMemHostUnregister current failed with %s", err_string); - return -EPERM; + rte_errno = EPERM; + return -rte_errno; } return mem_list_del_item(hk); @@ -817,7 +848,8 @@ cuda_mem_unregister(struct rte_gpu *dev, void *ptr) rte_cuda_log(ERR, "Memory type %d not supported", mem_item->mtype); - return -EPERM; + rte_errno = EPERM; + return -rte_errno; } static int @@ -840,8 +872,10 @@ cuda_wmb(struct rte_gpu *dev) CUcontext input_ctx; struct cuda_info *private; - if (dev == NULL) - return -ENODEV; + if (dev == NULL) { + rte_errno = ENODEV; + return -rte_errno; + } private = (struct cuda_info *)dev->mpshared->dev_private; @@ -860,7 +894,9 @@ cuda_wmb(struct rte_gpu *dev) */ rte_cuda_log(WARNING, "Can't flush GDR writes with cuFlushGPUDirectRDMAWrites CUDA function." "Application needs to use alternative methods."); - return -ENOTSUP; + + rte_errno = ENOTSUP; + return -rte_errno; } /* Store current ctx */ @@ -869,7 +905,8 @@ cuda_wmb(struct rte_gpu *dev) pfn_cuGetErrorString(res, &(err_string)); rte_cuda_log(ERR, "cuCtxGetCurrent failed with %s", err_string); - return -EPERM; + rte_errno = EPERM; + return -rte_errno; } /* Set child ctx as current ctx */ @@ -879,7 +916,8 @@ cuda_wmb(struct rte_gpu *dev) pfn_cuGetErrorString(res, &(err_string)); rte_cuda_log(ERR, "cuCtxSetCurrent input failed with %s", err_string); - return -EPERM; + rte_errno = EPERM; + return -rte_errno; } res = pfn_cuFlushGPUDirectRDMAWrites(CU_FLUSH_GPU_DIRECT_RDMA_WRITES_TARGET_CURRENT_CTX, @@ -888,7 +926,8 @@ cuda_wmb(struct rte_gpu *dev) pfn_cuGetErrorString(res, &(err_string)); rte_cuda_log(ERR, "cuFlushGPUDirectRDMAWrites current failed with %s", err_string); - return -EPERM; + rte_errno = EPERM; + return -rte_errno; } /* Restore original ctx as current ctx */ @@ -897,7 +936,8 @@ cuda_wmb(struct rte_gpu *dev) pfn_cuGetErrorString(res, &(err_string)); rte_cuda_log(ERR, "cuCtxSetCurrent current failed with %s", err_string); - return -EPERM; + rte_errno = EPERM; + return -rte_errno; } return 0; @@ -917,15 +957,18 @@ cuda_gpu_probe(__rte_unused struct rte_pci_driver *pci_drv, struct rte_pci_devic if (pci_dev == NULL) { rte_cuda_log(ERR, "NULL PCI device"); - return -EINVAL; + rte_errno = ENODEV; + return -rte_errno; } rte_pci_device_name(&pci_dev->addr, dev_name, sizeof(dev_name)); /* Allocate memory to be used privately by drivers */ dev = rte_gpu_allocate(pci_dev->device.name); - if (dev == NULL) - return -ENODEV; + if (dev == NULL) { + rte_errno = ENODEV; + return -rte_errno; + } /* Initialize values only for the first CUDA driver call */ if (dev->mpshared->info.dev_id == 0) { @@ -936,13 +979,15 @@ cuda_gpu_probe(__rte_unused struct rte_pci_driver *pci_drv, struct rte_pci_devic /* Load libcuda.so library */ if (cuda_loader()) { rte_cuda_log(ERR, "CUDA Driver library not found"); - return -ENOTSUP; + rte_errno = ENOTSUP; + return -rte_errno; } /* Load initial CUDA functions */ if (cuda_sym_func_loader()) { rte_cuda_log(ERR, "CUDA functions not found in library"); - return -ENOTSUP; + rte_errno = ENOTSUP; + return -rte_errno; } /* @@ -955,7 +1000,8 @@ cuda_gpu_probe(__rte_unused struct rte_pci_driver *pci_drv, struct rte_pci_devic res = sym_cuDriverGetVersion(&cuda_driver_version); if (res != 0) { rte_cuda_log(ERR, "cuDriverGetVersion failed with %d", res); - return -ENOTSUP; + rte_errno = ENOTSUP; + return -rte_errno; } if (cuda_driver_version < CUDA_DRIVER_MIN_VERSION) { @@ -963,12 +1009,14 @@ cuda_gpu_probe(__rte_unused struct rte_pci_driver *pci_drv, struct rte_pci_devic "Minimum requirement is %d", cuda_driver_version, CUDA_DRIVER_MIN_VERSION); - return -ENOTSUP; + rte_errno = ENOTSUP; + return -rte_errno; } if (cuda_pfn_func_loader()) { rte_cuda_log(ERR, "CUDA PFN functions not found in library"); - return -ENOTSUP; + rte_errno = ENOTSUP; + return -rte_errno; } } @@ -982,7 +1030,8 @@ cuda_gpu_probe(__rte_unused struct rte_pci_driver *pci_drv, struct rte_pci_devic pfn_cuGetErrorString(res, &(err_string)); rte_cuda_log(ERR, "cuDeviceGetByPCIBusId name %s failed with %d: %s", dev->device->name, res, err_string); - return -EPERM; + rte_errno = EPERM; + return -rte_errno; } res = pfn_cuDevicePrimaryCtxRetain(&pctx, cu_dev_id); @@ -990,19 +1039,22 @@ cuda_gpu_probe(__rte_unused struct rte_pci_driver *pci_drv, struct rte_pci_devic pfn_cuGetErrorString(res, &(err_string)); rte_cuda_log(ERR, "cuDevicePrimaryCtxRetain name %s failed with %d: %s", dev->device->name, res, err_string); - return -EPERM; + rte_errno = EPERM; + return -rte_errno; } res = pfn_cuCtxGetApiVersion(pctx, &cuda_api_version); if (res != 0) { rte_cuda_log(ERR, "cuCtxGetApiVersion failed with %d", res); - return -ENOTSUP; + rte_errno = ENOTSUP; + return -rte_errno; } if (cuda_api_version < CUDA_API_MIN_VERSION) { rte_cuda_log(ERR, "CUDA API version found is %d Minimum requirement is %d", cuda_api_version, CUDA_API_MIN_VERSION); - return -ENOTSUP; + rte_errno = ENOTSUP; + return -rte_errno; } dev->mpshared->info.context = (uint64_t)pctx; @@ -1019,7 +1071,8 @@ cuda_gpu_probe(__rte_unused struct rte_pci_driver *pci_drv, struct rte_pci_devic pfn_cuGetErrorString(res, &(err_string)); rte_cuda_log(ERR, "cuDeviceGetAttribute failed with %s", err_string); - return -EPERM; + rte_errno = EPERM; + return -rte_errno; } dev->mpshared->info.processor_count = (uint32_t)processor_count; @@ -1029,7 +1082,8 @@ cuda_gpu_probe(__rte_unused struct rte_pci_driver *pci_drv, struct rte_pci_devic pfn_cuGetErrorString(res, &(err_string)); rte_cuda_log(ERR, "cuDeviceTotalMem failed with %s", err_string); - return -EPERM; + rte_errno = EPERM; + return -rte_errno; } /* @@ -1040,7 +1094,8 @@ cuda_gpu_probe(__rte_unused struct rte_pci_driver *pci_drv, struct rte_pci_devic RTE_CACHE_LINE_SIZE); if (dev->mpshared->dev_private == NULL) { rte_cuda_log(ERR, "Failed to allocate memory for GPU process private"); - return -ENOMEM; + rte_errno = EPERM; + return -rte_errno; } private = (struct cuda_info *)dev->mpshared->dev_private; @@ -1052,7 +1107,8 @@ cuda_gpu_probe(__rte_unused struct rte_pci_driver *pci_drv, struct rte_pci_devic pfn_cuGetErrorString(res, &(err_string)); rte_cuda_log(ERR, "cuDeviceGetName failed with %s", err_string); - return -EPERM; + rte_errno = EPERM; + return -rte_errno; } res = pfn_cuDeviceGetAttribute(&(private->gdr_supported), @@ -1062,7 +1118,8 @@ cuda_gpu_probe(__rte_unused struct rte_pci_driver *pci_drv, struct rte_pci_devic pfn_cuGetErrorString(res, &(err_string)); rte_cuda_log(ERR, "cuDeviceGetAttribute failed with %s", err_string); - return -EPERM; + rte_errno = EPERM; + return -rte_errno; } if (private->gdr_supported == 0) @@ -1077,7 +1134,8 @@ cuda_gpu_probe(__rte_unused struct rte_pci_driver *pci_drv, struct rte_pci_devic rte_cuda_log(ERR, "cuDeviceGetAttribute failed with %s", err_string); - return -EPERM; + rte_errno = EPERM; + return -rte_errno; } if (private->gdr_write_ordering == CU_GPU_DIRECT_RDMA_WRITES_ORDERING_NONE) { @@ -1088,7 +1146,8 @@ cuda_gpu_probe(__rte_unused struct rte_pci_driver *pci_drv, struct rte_pci_devic pfn_cuGetErrorString(res, &(err_string)); rte_cuda_log(ERR, "cuDeviceGetAttribute failed with %s", err_string); - return -EPERM; + rte_errno = EPERM; + return -rte_errno; } if (private->gdr_flush_type != CU_FLUSH_GPU_DIRECT_RDMA_WRITES_OPTION_HOST) @@ -1118,14 +1177,17 @@ cuda_gpu_remove(struct rte_pci_device *pci_dev) int ret; uint8_t gpu_id; - if (pci_dev == NULL) - return -EINVAL; + if (pci_dev == NULL) { + rte_errno = ENODEV; + return -rte_errno; + } dev = rte_gpu_get_by_name(pci_dev->device.name); if (dev == NULL) { rte_cuda_log(ERR, "Couldn't find HW dev \"%s\" to uninitialise it", pci_dev->device.name); - return -ENODEV; + rte_errno = ENODEV; + return -rte_errno; } gpu_id = dev->mpshared->info.dev_id; -- 2.17.1