Commit 9a8d3cda authored by Russ Weight's avatar Russ Weight Committed by Moritz Fischer

fpga: dfl: afu: harden port enable logic

Port enable is not complete until ACK = 0. Change
__afu_port_enable() to guarantee that the enable process
is complete by polling for ACK == 0.
Signed-off-by: default avatarRuss Weight <russell.h.weight@intel.com>
Reviewed-by: default avatarTom Rix <trix@redhat.com>
Reviewed-by: default avatarMatthew Gerlach <matthew.gerlach@linux.intel.com>
Acked-by: default avatarWu Hao <hao.wu@intel.com>
Signed-off-by: default avatarMoritz Fischer <mdf@kernel.org>
parent 6f1e376c
...@@ -52,7 +52,7 @@ static int afu_port_err_clear(struct device *dev, u64 err) ...@@ -52,7 +52,7 @@ static int afu_port_err_clear(struct device *dev, u64 err)
struct dfl_feature_platform_data *pdata = dev_get_platdata(dev); struct dfl_feature_platform_data *pdata = dev_get_platdata(dev);
struct platform_device *pdev = to_platform_device(dev); struct platform_device *pdev = to_platform_device(dev);
void __iomem *base_err, *base_hdr; void __iomem *base_err, *base_hdr;
int ret = -EBUSY; int enable_ret = 0, ret = -EBUSY;
u64 v; u64 v;
base_err = dfl_get_feature_ioaddr_by_id(dev, PORT_FEATURE_ID_ERROR); base_err = dfl_get_feature_ioaddr_by_id(dev, PORT_FEATURE_ID_ERROR);
...@@ -96,18 +96,20 @@ static int afu_port_err_clear(struct device *dev, u64 err) ...@@ -96,18 +96,20 @@ static int afu_port_err_clear(struct device *dev, u64 err)
v = readq(base_err + PORT_FIRST_ERROR); v = readq(base_err + PORT_FIRST_ERROR);
writeq(v, base_err + PORT_FIRST_ERROR); writeq(v, base_err + PORT_FIRST_ERROR);
} else { } else {
dev_warn(dev, "%s: received 0x%llx, expected 0x%llx\n",
__func__, v, err);
ret = -EINVAL; ret = -EINVAL;
} }
/* Clear mask */ /* Clear mask */
__afu_port_err_mask(dev, false); __afu_port_err_mask(dev, false);
/* Enable the Port by clear the reset */ /* Enable the Port by clearing the reset */
__afu_port_enable(pdev); enable_ret = __afu_port_enable(pdev);
done: done:
mutex_unlock(&pdata->lock); mutex_unlock(&pdata->lock);
return ret; return enable_ret ? enable_ret : ret;
} }
static ssize_t errors_show(struct device *dev, struct device_attribute *attr, static ssize_t errors_show(struct device *dev, struct device_attribute *attr,
......
...@@ -21,6 +21,9 @@ ...@@ -21,6 +21,9 @@
#include "dfl-afu.h" #include "dfl-afu.h"
#define RST_POLL_INVL 10 /* us */
#define RST_POLL_TIMEOUT 1000 /* us */
/** /**
* __afu_port_enable - enable a port by clear reset * __afu_port_enable - enable a port by clear reset
* @pdev: port platform device. * @pdev: port platform device.
...@@ -32,7 +35,7 @@ ...@@ -32,7 +35,7 @@
* *
* The caller needs to hold lock for protection. * The caller needs to hold lock for protection.
*/ */
void __afu_port_enable(struct platform_device *pdev) int __afu_port_enable(struct platform_device *pdev)
{ {
struct dfl_feature_platform_data *pdata = dev_get_platdata(&pdev->dev); struct dfl_feature_platform_data *pdata = dev_get_platdata(&pdev->dev);
void __iomem *base; void __iomem *base;
...@@ -41,7 +44,7 @@ void __afu_port_enable(struct platform_device *pdev) ...@@ -41,7 +44,7 @@ void __afu_port_enable(struct platform_device *pdev)
WARN_ON(!pdata->disable_count); WARN_ON(!pdata->disable_count);
if (--pdata->disable_count != 0) if (--pdata->disable_count != 0)
return; return 0;
base = dfl_get_feature_ioaddr_by_id(&pdev->dev, PORT_FEATURE_ID_HEADER); base = dfl_get_feature_ioaddr_by_id(&pdev->dev, PORT_FEATURE_ID_HEADER);
...@@ -49,10 +52,20 @@ void __afu_port_enable(struct platform_device *pdev) ...@@ -49,10 +52,20 @@ void __afu_port_enable(struct platform_device *pdev)
v = readq(base + PORT_HDR_CTRL); v = readq(base + PORT_HDR_CTRL);
v &= ~PORT_CTRL_SFTRST; v &= ~PORT_CTRL_SFTRST;
writeq(v, base + PORT_HDR_CTRL); writeq(v, base + PORT_HDR_CTRL);
}
#define RST_POLL_INVL 10 /* us */ /*
#define RST_POLL_TIMEOUT 1000 /* us */ * HW clears the ack bit to indicate that the port is fully out
* of reset.
*/
if (readq_poll_timeout(base + PORT_HDR_CTRL, v,
!(v & PORT_CTRL_SFTRST_ACK),
RST_POLL_INVL, RST_POLL_TIMEOUT)) {
dev_err(&pdev->dev, "timeout, failure to enable device\n");
return -ETIMEDOUT;
}
return 0;
}
/** /**
* __afu_port_disable - disable a port by hold reset * __afu_port_disable - disable a port by hold reset
...@@ -86,7 +99,7 @@ int __afu_port_disable(struct platform_device *pdev) ...@@ -86,7 +99,7 @@ int __afu_port_disable(struct platform_device *pdev)
if (readq_poll_timeout(base + PORT_HDR_CTRL, v, if (readq_poll_timeout(base + PORT_HDR_CTRL, v,
v & PORT_CTRL_SFTRST_ACK, v & PORT_CTRL_SFTRST_ACK,
RST_POLL_INVL, RST_POLL_TIMEOUT)) { RST_POLL_INVL, RST_POLL_TIMEOUT)) {
dev_err(&pdev->dev, "timeout, fail to reset device\n"); dev_err(&pdev->dev, "timeout, failure to disable device\n");
return -ETIMEDOUT; return -ETIMEDOUT;
} }
...@@ -110,10 +123,10 @@ static int __port_reset(struct platform_device *pdev) ...@@ -110,10 +123,10 @@ static int __port_reset(struct platform_device *pdev)
int ret; int ret;
ret = __afu_port_disable(pdev); ret = __afu_port_disable(pdev);
if (!ret) if (ret)
__afu_port_enable(pdev); return ret;
return ret; return __afu_port_enable(pdev);
} }
static int port_reset(struct platform_device *pdev) static int port_reset(struct platform_device *pdev)
...@@ -872,11 +885,11 @@ static int afu_dev_destroy(struct platform_device *pdev) ...@@ -872,11 +885,11 @@ static int afu_dev_destroy(struct platform_device *pdev)
static int port_enable_set(struct platform_device *pdev, bool enable) static int port_enable_set(struct platform_device *pdev, bool enable)
{ {
struct dfl_feature_platform_data *pdata = dev_get_platdata(&pdev->dev); struct dfl_feature_platform_data *pdata = dev_get_platdata(&pdev->dev);
int ret = 0; int ret;
mutex_lock(&pdata->lock); mutex_lock(&pdata->lock);
if (enable) if (enable)
__afu_port_enable(pdev); ret = __afu_port_enable(pdev);
else else
ret = __afu_port_disable(pdev); ret = __afu_port_disable(pdev);
mutex_unlock(&pdata->lock); mutex_unlock(&pdata->lock);
......
...@@ -80,7 +80,7 @@ struct dfl_afu { ...@@ -80,7 +80,7 @@ struct dfl_afu {
}; };
/* hold pdata->lock when call __afu_port_enable/disable */ /* hold pdata->lock when call __afu_port_enable/disable */
void __afu_port_enable(struct platform_device *pdev); int __afu_port_enable(struct platform_device *pdev);
int __afu_port_disable(struct platform_device *pdev); int __afu_port_disable(struct platform_device *pdev);
void afu_mmio_region_init(struct dfl_feature_platform_data *pdata); void afu_mmio_region_init(struct dfl_feature_platform_data *pdata);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment