forked from Minki/linux
f8c8c7d5f1
This patch adds support for doing various on-the-fly reset of Goya. The driver supports two types of resets: 1. soft-reset 2. hard-reset Soft-reset is done when the device detects a timeout of a command submission that was given to the device. The soft-reset process only resets the engines that are relevant for the submission of compute jobs, i.e. the DMA channels, the TPCs and the MME. The purpose is to bring the device as fast as possible to a working state. Hard-reset is done in several cases: 1. After soft-reset is done but the device is not responding 2. When fatal errors occur inside the device, e.g. ECC error 3. When the driver is removed Hard-reset performs a reset of the entire chip except for the PCI controller and the PLLs. It is a much longer process then soft-reset but it helps to recover the device without the need to reboot the Host. After hard-reset, the driver will restore the max power attribute and in case of manual power management, the frequencies that were set. This patch also adds two entries to the sysfs, which allows the root user to initiate a soft or hard reset. Reviewed-by: Mike Rapoport <rppt@linux.ibm.com> Signed-off-by: Oded Gabbay <oded.gabbay@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
255 lines
5.1 KiB
C
255 lines
5.1 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
/*
|
|
* Copyright 2016-2019 HabanaLabs, Ltd.
|
|
* All Rights Reserved.
|
|
*/
|
|
|
|
#include "goyaP.h"
|
|
|
|
void goya_set_pll_profile(struct hl_device *hdev, enum hl_pll_frequency freq)
|
|
{
|
|
struct goya_device *goya = hdev->asic_specific;
|
|
|
|
switch (freq) {
|
|
case PLL_HIGH:
|
|
hl_set_frequency(hdev, MME_PLL, hdev->high_pll);
|
|
hl_set_frequency(hdev, TPC_PLL, hdev->high_pll);
|
|
hl_set_frequency(hdev, IC_PLL, hdev->high_pll);
|
|
break;
|
|
case PLL_LOW:
|
|
hl_set_frequency(hdev, MME_PLL, GOYA_PLL_FREQ_LOW);
|
|
hl_set_frequency(hdev, TPC_PLL, GOYA_PLL_FREQ_LOW);
|
|
hl_set_frequency(hdev, IC_PLL, GOYA_PLL_FREQ_LOW);
|
|
break;
|
|
case PLL_LAST:
|
|
hl_set_frequency(hdev, MME_PLL, goya->mme_clk);
|
|
hl_set_frequency(hdev, TPC_PLL, goya->tpc_clk);
|
|
hl_set_frequency(hdev, IC_PLL, goya->ic_clk);
|
|
break;
|
|
default:
|
|
dev_err(hdev->dev, "unknown frequency setting\n");
|
|
}
|
|
}
|
|
|
|
static ssize_t mme_clk_show(struct device *dev, struct device_attribute *attr,
|
|
char *buf)
|
|
{
|
|
struct hl_device *hdev = dev_get_drvdata(dev);
|
|
long value;
|
|
|
|
if (hl_device_disabled_or_in_reset(hdev))
|
|
return -ENODEV;
|
|
|
|
value = hl_get_frequency(hdev, MME_PLL, false);
|
|
|
|
if (value < 0)
|
|
return value;
|
|
|
|
return sprintf(buf, "%lu\n", value);
|
|
}
|
|
|
|
static ssize_t mme_clk_store(struct device *dev, struct device_attribute *attr,
|
|
const char *buf, size_t count)
|
|
{
|
|
struct hl_device *hdev = dev_get_drvdata(dev);
|
|
struct goya_device *goya = hdev->asic_specific;
|
|
int rc;
|
|
long value;
|
|
|
|
if (hl_device_disabled_or_in_reset(hdev)) {
|
|
count = -ENODEV;
|
|
goto fail;
|
|
}
|
|
|
|
if (hdev->pm_mng_profile == PM_AUTO) {
|
|
count = -EPERM;
|
|
goto fail;
|
|
}
|
|
|
|
rc = kstrtoul(buf, 0, &value);
|
|
|
|
if (rc) {
|
|
count = -EINVAL;
|
|
goto fail;
|
|
}
|
|
|
|
hl_set_frequency(hdev, MME_PLL, value);
|
|
goya->mme_clk = value;
|
|
|
|
fail:
|
|
return count;
|
|
}
|
|
|
|
static ssize_t tpc_clk_show(struct device *dev, struct device_attribute *attr,
|
|
char *buf)
|
|
{
|
|
struct hl_device *hdev = dev_get_drvdata(dev);
|
|
long value;
|
|
|
|
if (hl_device_disabled_or_in_reset(hdev))
|
|
return -ENODEV;
|
|
|
|
value = hl_get_frequency(hdev, TPC_PLL, false);
|
|
|
|
if (value < 0)
|
|
return value;
|
|
|
|
return sprintf(buf, "%lu\n", value);
|
|
}
|
|
|
|
static ssize_t tpc_clk_store(struct device *dev, struct device_attribute *attr,
|
|
const char *buf, size_t count)
|
|
{
|
|
struct hl_device *hdev = dev_get_drvdata(dev);
|
|
struct goya_device *goya = hdev->asic_specific;
|
|
int rc;
|
|
long value;
|
|
|
|
if (hl_device_disabled_or_in_reset(hdev)) {
|
|
count = -ENODEV;
|
|
goto fail;
|
|
}
|
|
|
|
if (hdev->pm_mng_profile == PM_AUTO) {
|
|
count = -EPERM;
|
|
goto fail;
|
|
}
|
|
|
|
rc = kstrtoul(buf, 0, &value);
|
|
|
|
if (rc) {
|
|
count = -EINVAL;
|
|
goto fail;
|
|
}
|
|
|
|
hl_set_frequency(hdev, TPC_PLL, value);
|
|
goya->tpc_clk = value;
|
|
|
|
fail:
|
|
return count;
|
|
}
|
|
|
|
static ssize_t ic_clk_show(struct device *dev, struct device_attribute *attr,
|
|
char *buf)
|
|
{
|
|
struct hl_device *hdev = dev_get_drvdata(dev);
|
|
long value;
|
|
|
|
if (hl_device_disabled_or_in_reset(hdev))
|
|
return -ENODEV;
|
|
|
|
value = hl_get_frequency(hdev, IC_PLL, false);
|
|
|
|
if (value < 0)
|
|
return value;
|
|
|
|
return sprintf(buf, "%lu\n", value);
|
|
}
|
|
|
|
static ssize_t ic_clk_store(struct device *dev, struct device_attribute *attr,
|
|
const char *buf, size_t count)
|
|
{
|
|
struct hl_device *hdev = dev_get_drvdata(dev);
|
|
struct goya_device *goya = hdev->asic_specific;
|
|
int rc;
|
|
long value;
|
|
|
|
if (hl_device_disabled_or_in_reset(hdev)) {
|
|
count = -ENODEV;
|
|
goto fail;
|
|
}
|
|
|
|
if (hdev->pm_mng_profile == PM_AUTO) {
|
|
count = -EPERM;
|
|
goto fail;
|
|
}
|
|
|
|
rc = kstrtoul(buf, 0, &value);
|
|
|
|
if (rc) {
|
|
count = -EINVAL;
|
|
goto fail;
|
|
}
|
|
|
|
hl_set_frequency(hdev, IC_PLL, value);
|
|
goya->ic_clk = value;
|
|
|
|
fail:
|
|
return count;
|
|
}
|
|
|
|
static ssize_t mme_clk_curr_show(struct device *dev,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
struct hl_device *hdev = dev_get_drvdata(dev);
|
|
long value;
|
|
|
|
if (hl_device_disabled_or_in_reset(hdev))
|
|
return -ENODEV;
|
|
|
|
value = hl_get_frequency(hdev, MME_PLL, true);
|
|
|
|
if (value < 0)
|
|
return value;
|
|
|
|
return sprintf(buf, "%lu\n", value);
|
|
}
|
|
|
|
static ssize_t tpc_clk_curr_show(struct device *dev,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
struct hl_device *hdev = dev_get_drvdata(dev);
|
|
long value;
|
|
|
|
if (hl_device_disabled_or_in_reset(hdev))
|
|
return -ENODEV;
|
|
|
|
value = hl_get_frequency(hdev, TPC_PLL, true);
|
|
|
|
if (value < 0)
|
|
return value;
|
|
|
|
return sprintf(buf, "%lu\n", value);
|
|
}
|
|
|
|
static ssize_t ic_clk_curr_show(struct device *dev,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
struct hl_device *hdev = dev_get_drvdata(dev);
|
|
long value;
|
|
|
|
if (hl_device_disabled_or_in_reset(hdev))
|
|
return -ENODEV;
|
|
|
|
value = hl_get_frequency(hdev, IC_PLL, true);
|
|
|
|
if (value < 0)
|
|
return value;
|
|
|
|
return sprintf(buf, "%lu\n", value);
|
|
}
|
|
|
|
static DEVICE_ATTR_RW(ic_clk);
|
|
static DEVICE_ATTR_RO(ic_clk_curr);
|
|
static DEVICE_ATTR_RW(mme_clk);
|
|
static DEVICE_ATTR_RO(mme_clk_curr);
|
|
static DEVICE_ATTR_RW(tpc_clk);
|
|
static DEVICE_ATTR_RO(tpc_clk_curr);
|
|
|
|
static struct attribute *goya_dev_attrs[] = {
|
|
&dev_attr_ic_clk.attr,
|
|
&dev_attr_ic_clk_curr.attr,
|
|
&dev_attr_mme_clk.attr,
|
|
&dev_attr_mme_clk_curr.attr,
|
|
&dev_attr_tpc_clk.attr,
|
|
&dev_attr_tpc_clk_curr.attr,
|
|
NULL,
|
|
};
|
|
|
|
void goya_add_device_attr(struct hl_device *hdev,
|
|
struct attribute_group *dev_attr_grp)
|
|
{
|
|
dev_attr_grp->attrs = goya_dev_attrs;
|
|
}
|