From b4b1fb97bd095fa0de72550b04dc414b0194903e Mon Sep 17 00:00:00 2001 From: Nitin Kumbhar Date: Mon, 11 Jun 2018 15:31:33 +0530 Subject: gpu: nvgpu: shutdown nvlink in driver remove During driver remove, if nvlink is set up, gracefully shut it down so that it can be enumerated again. Bug 1987855 Change-Id: Ibd83a5e29364b22264e689aa879569a9cccf0f79 Signed-off-by: Nitin Kumbhar Reviewed-on: https://git-master.nvidia.com/r/1746073 Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/os/linux/nvlink.c | 26 ++++++++++++++++++++++++++ drivers/gpu/nvgpu/os/linux/nvlink.h | 22 ++++++++++++++++++++++ drivers/gpu/nvgpu/os/linux/pci.c | 8 +++++--- 3 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 drivers/gpu/nvgpu/os/linux/nvlink.h (limited to 'drivers/gpu/nvgpu/os') diff --git a/drivers/gpu/nvgpu/os/linux/nvlink.c b/drivers/gpu/nvgpu/os/linux/nvlink.c index c93514c0..0db483d6 100644 --- a/drivers/gpu/nvgpu/os/linux/nvlink.c +++ b/drivers/gpu/nvgpu/os/linux/nvlink.c @@ -14,6 +14,10 @@ * along with this program. If not, see . */ +#ifdef CONFIG_TEGRA_NVLINK +#include +#endif + #include #include #include @@ -104,3 +108,25 @@ void nvgpu_mss_nvlink_init_credits(struct gk20a *g) val = readl_relaxed(soc4 + 4); writel_relaxed(val, soc4 + 4); } + +int nvgpu_nvlink_deinit(struct gk20a *g) +{ +#ifdef CONFIG_TEGRA_NVLINK + struct nvlink_device *ndev = g->nvlink.priv; + int err; + + if (!nvgpu_is_enabled(g, NVGPU_SUPPORT_NVLINK)) + return -ENODEV; + + err = nvlink_shutdown(ndev); + if (err) { + nvgpu_err(g, "failed to shut down nvlink"); + return err; + } + + nvgpu_nvlink_remove(g); + + return 0; +#endif + return -ENODEV; +} diff --git a/drivers/gpu/nvgpu/os/linux/nvlink.h b/drivers/gpu/nvgpu/os/linux/nvlink.h new file mode 100644 index 00000000..4dc54f6f --- /dev/null +++ b/drivers/gpu/nvgpu/os/linux/nvlink.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef NVGPU_OS_LINUX_NVLINK_H + +struct gk20a; +int nvgpu_nvlink_deinit(struct gk20a *g); + +#endif diff --git a/drivers/gpu/nvgpu/os/linux/pci.c b/drivers/gpu/nvgpu/os/linux/pci.c index 41fb69a0..ee4bcf8c 100644 --- a/drivers/gpu/nvgpu/os/linux/pci.c +++ b/drivers/gpu/nvgpu/os/linux/pci.c @@ -26,7 +26,9 @@ #include #include #include +#include +#include "nvlink.h" #include "gk20a/gk20a.h" #include "clk/clk.h" #include "clk/clk_mclk.h" @@ -35,12 +37,10 @@ #include "sysfs.h" #include "os_linux.h" #include "platform_gk20a.h" -#include #include "pci.h" #include "pci_usermode.h" -#include "os_linux.h" #include "driver_common.h" #define PCI_INTERFACE_NAME "card-%s%%s" @@ -828,9 +828,11 @@ static void nvgpu_pci_remove(struct pci_dev *pdev) if (gk20a_gpu_is_virtual(dev)) return; - nvgpu_nvlink_remove(g); + err = nvgpu_nvlink_deinit(g); + WARN(err, "gpu failed to remove nvlink"); gk20a_driver_start_unload(g); + err = nvgpu_quiesce(g); /* TODO: handle failure to idle */ WARN(err, "gpu failed to idle during driver removal"); -- cgit v1.2.2