/* * nvlink-core.c: * This driver manages the entire NVLINK system that the Tegra SOC is connected * to. The NVLINK core driver interfaces with the NVLINK endpoint drivers. Each * endpoint driver is responsible for the HW programming of 1 particular NVLINK * device. The core driver uses the endpoint drivers to manage the NVLINK * system. * * Copyright (c) 2017-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 <http://www.gnu.org/licenses/>. */#include <linux/debugfs.h>#include <linux/delay.h>#include <linux/module.h>#include <linux/platform/tegra/tegra-nvlink.h>#include <asm/cacheflush.h>#define NVLINK_MODULE_NAME"nvlink-core"#define NVLINK_DEBUGFS_ROOT"nvlink"#define NVLINK_DEBUGFS_TESTS"tests"#define DEFAULT_LOOP_SLEEP_US 100#define DEFAULT_LOOP_TIMEOUT_US 1000000#define NVLINK_TRANSITION_HS_TIMEOUT_MS 2000#define NVLINK_TRANSITION_SAFE_TIMEOUT_MS 5struct nvlink_intranode_conn {struct nvlink_device *ndev0;struct nvlink_device *ndev1;};struct topology {int slave_dev_id;int master_dev_id;int slave_link_id;int master_link_id;};struct nvlink_core {struct nvlink_device *ndevs[NVLINK_MAX_DEVICES];struct nvlink_link *nlinks[NVLINK_MAX_LINKS];struct topology topology;struct nvlink_intranode_conn intranode_conn;struct mutex mutex;};/* * We're exporting the NVLINK driver stack's logging APIs to the NVLINK kernel * test modules. The logging APIs use nvlink_log_mask. Therefore, we have to * export nvlink_log_mask along with the logging APIs. */
u32 nvlink_log_mask = NVLINK_DEFAULT_LOG_MASK;EXPORT_SYMBOL(nvlink_log_mask);#ifdef CONFIG_DEBUG_FS/* This is the root debugfs directory for the entire NVLINK driver stack */struct dentry *nvlink_debugfs_root;/* * This is the parent debugfs directory for NVLINK tests. We need to export this * symbol so that the NVLINK kernel test modules can create their debugfs nodes * under the correct path. */struct dentry *nvlink_debugfs_tests;EXPORT_SYMBOL(nvlink_debugfs_tests);#endif/* CONFIG_DEBUG_FS */static struct nvlink_core nvlink_core;static boolnvlink_is_single_lane_mode_supported(struct nvlink_intranode_conn *conn){/* * Single-lane mode is supported on the connection * only when both of the nvlink devices support this feature. */return(conn->ndev0->link.is_sl_supported &&
conn->ndev1->link.is_sl_supported);}intnvlink_get_init_state(struct nvlink_device *ndev,enum init_state *state){int ret =0;if(!ndev) {nvlink_err("Inva