Re: [PATCH] Documentation/networking/af_xdp: Inhibit reference to struct socket

2019-08-11 Thread Jonathan Neuschäfer
On Sat, Aug 10, 2019 at 08:58:21AM -0600, Jonathan Corbet wrote:
> On Sat, 10 Aug 2019 14:17:37 +0200
> Jonathan Neuschäfer  wrote:
> 
> > With the recent change to auto-detect function names, Sphinx parses
> > socket() as a reference to the in-kernel definition of socket. It then
> > decides that struct socket is a good match, which was obviously not
> > intended in this case, because the text speaks about the syscall with
> > the same name.
> > 
> > Prevent socket() from being misinterpreted by wrapping it in ``inline
> > literal`` quotes.
> > 
> > Signed-off-by: Jonathan Neuschäfer 
> 
> Thanks for looking at that.  The better fix, though, would be to add
> socket() to the Skipfuncs array in Documentation/sphinx/automarkup.py.
> Then it will do the right thing everywhere without the need to add markup
> to the RST files.

Alright, I'll do that for v2.


Thanks,
Jonathan Neuschäfer


signature.asc
Description: PGP signature


[PATCH 1/3] workqueue: Convert for_each_wq to use built-in list check (v2)

2019-08-11 Thread Joel Fernandes (Google)
list_for_each_entry_rcu now has support to check for RCU reader sections
as well as lock. Just use the support in it, instead of explicitly
checking in the caller.

Signed-off-by: Joel Fernandes (Google) 
---
 kernel/workqueue.c | 10 ++
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 601d61150b65..e882477ebf6e 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -364,11 +364,6 @@ static void workqueue_sysfs_unregister(struct 
workqueue_struct *wq);
 !lockdep_is_held(&wq_pool_mutex),  \
 "RCU or wq_pool_mutex should be held")
 
-#define assert_rcu_or_wq_mutex(wq) \
-   RCU_LOCKDEP_WARN(!rcu_read_lock_held() &&   \
-!lockdep_is_held(&wq->mutex),  \
-"RCU or wq->mutex should be held")
-
 #define assert_rcu_or_wq_mutex_or_pool_mutex(wq)   \
RCU_LOCKDEP_WARN(!rcu_read_lock_held() &&   \
 !lockdep_is_held(&wq->mutex) &&\
@@ -425,9 +420,8 @@ static void workqueue_sysfs_unregister(struct 
workqueue_struct *wq);
  * ignored.
  */
 #define for_each_pwq(pwq, wq)  \
-   list_for_each_entry_rcu((pwq), &(wq)->pwqs, pwqs_node)  \
-   if (({ assert_rcu_or_wq_mutex(wq); false; })) { }   \
-   else
+   list_for_each_entry_rcu((pwq), &(wq)->pwqs, pwqs_node,  \
+lock_is_held(&(wq->mutex).dep_map))
 
 #ifdef CONFIG_DEBUG_OBJECTS_WORK
 
-- 
2.23.0.rc1.153.gdeed80330f-goog



[PATCH 3/3] driver/core: Fix build error when SRCU and lockdep disabled

2019-08-11 Thread Joel Fernandes (Google)
Properly check if lockdep lock checking is disabled at config time. If
so, then lock_is_held() is undefined so don't do any checking.

This fix is similar to the pattern used in srcu_read_lock_held().

Link: https://lore.kernel.org/lkml/201908080026.wsafx14k%25...@intel.com/
Fixes: c9e4d3a2fee8 ("acpi: Use built-in RCU list checking for acpi_ioremaps 
list")
Reported-by: kbuild test robot 
Signed-off-by: Joel Fernandes (Google) 
---
This patch is based on the -rcu dev branch.

 drivers/base/core.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index 32cf83d1c744..fe25cf690562 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -99,7 +99,11 @@ void device_links_read_unlock(int not_used)
 
 int device_links_read_lock_held(void)
 {
-   return lock_is_held(&device_links_lock);
+#ifdef CONFIG_DEBUG_LOCK_ALLOC
+   return lock_is_held(&(device_links_lock.dep_map));
+#else
+   return 1;
+#endif
 }
 #endif /* !CONFIG_SRCU */
 
-- 
2.23.0.rc1.153.gdeed80330f-goog


[PATCH 2/3] doc: Update documentation about list_for_each_entry_rcu (v1)

2019-08-11 Thread Joel Fernandes (Google)
This patch updates the documentation with information about
usage of lockdep with list_for_each_entry_rcu().

Signed-off-by: Joel Fernandes (Google) 
---
 Documentation/RCU/lockdep.txt   | 15 +++
 Documentation/RCU/whatisRCU.txt |  9 -
 2 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/Documentation/RCU/lockdep.txt b/Documentation/RCU/lockdep.txt
index da51d3068850..3d967df3a801 100644
--- a/Documentation/RCU/lockdep.txt
+++ b/Documentation/RCU/lockdep.txt
@@ -96,7 +96,14 @@ other flavors of rcu_dereference().  On the other hand, it 
is illegal
 to use rcu_dereference_protected() if either the RCU-protected pointer
 or the RCU-protected data that it points to can change concurrently.
 
-There are currently only "universal" versions of the rcu_assign_pointer()
-and RCU list-/tree-traversal primitives, which do not (yet) check for
-being in an RCU read-side critical section.  In the future, separate
-versions of these primitives might be created.
+Similar to rcu_dereference_protected, The RCU list and hlist traversal
+primitives also check for whether there are called from within a reader
+section. However, an optional lockdep expression can be passed to them as
+the last argument in case they are called under other non-RCU protection.
+
+For example, the workqueue for_each_pwq() macro is implemented as follows.
+It is safe to call for_each_pwq() outside a reader section but under protection
+of wq->mutex:
+#define for_each_pwq(pwq, wq)
+   list_for_each_entry_rcu((pwq), &(wq)->pwqs, pwqs_node,
+   lock_is_held(&(wq->mutex).dep_map))
diff --git a/Documentation/RCU/whatisRCU.txt b/Documentation/RCU/whatisRCU.txt
index 17f48319ee16..cdd2a3e10e40 100644
--- a/Documentation/RCU/whatisRCU.txt
+++ b/Documentation/RCU/whatisRCU.txt
@@ -290,7 +290,7 @@ rcu_dereference()
at any time, including immediately after the rcu_dereference().
And, again like rcu_assign_pointer(), rcu_dereference() is
typically used indirectly, via the _rcu list-manipulation
-   primitives, such as list_for_each_entry_rcu().
+   primitives, such as list_for_each_entry_rcu() [2].
 
[1] The variant rcu_dereference_protected() can be used outside
of an RCU read-side critical section as long as the usage is
@@ -305,6 +305,13 @@ rcu_dereference()
a lockdep splat is emitted.  See 
Documentation/RCU/Design/Requirements/Requirements.rst
and the API's code comments for more details and example usage.
 
+   [2] In case the list_for_each_entry_rcu() primitive is intended
+   to be used outside of an RCU reader section such as when
+   protected by a lock, then an additional lockdep expression can be
+   passed as the last argument to it so that RCU lockdep checking code
+   knows that the dereference of the list pointers are safe. If the
+   indicated protection is not provided, a lockdep splat is emitted.
+
 The following diagram shows how each API communicates among the
 reader, updater, and reclaimer.
 
-- 
2.23.0.rc1.153.gdeed80330f-goog



Re: [PATCH 1/3] workqueue: Convert for_each_wq to use built-in list check (v2)

2019-08-11 Thread Joel Fernandes
On Sun, Aug 11, 2019 at 6:11 PM Joel Fernandes (Google)
 wrote:
>
> list_for_each_entry_rcu now has support to check for RCU reader sections
> as well as lock. Just use the support in it, instead of explicitly
> checking in the caller.
>
> Signed-off-by: Joel Fernandes (Google) 

Tejun,
Could you please Ack this patch? I have resent it here.

Thank you,
- Joel


> ---
>  kernel/workqueue.c | 10 ++
>  1 file changed, 2 insertions(+), 8 deletions(-)
>
> diff --git a/kernel/workqueue.c b/kernel/workqueue.c
> index 601d61150b65..e882477ebf6e 100644
> --- a/kernel/workqueue.c
> +++ b/kernel/workqueue.c
> @@ -364,11 +364,6 @@ static void workqueue_sysfs_unregister(struct 
> workqueue_struct *wq);
>  !lockdep_is_held(&wq_pool_mutex),  \
>  "RCU or wq_pool_mutex should be held")
>
> -#define assert_rcu_or_wq_mutex(wq) \
> -   RCU_LOCKDEP_WARN(!rcu_read_lock_held() &&   \
> -!lockdep_is_held(&wq->mutex),  \
> -"RCU or wq->mutex should be held")
> -
>  #define assert_rcu_or_wq_mutex_or_pool_mutex(wq)   \
> RCU_LOCKDEP_WARN(!rcu_read_lock_held() &&   \
>  !lockdep_is_held(&wq->mutex) &&\
> @@ -425,9 +420,8 @@ static void workqueue_sysfs_unregister(struct 
> workqueue_struct *wq);
>   * ignored.
>   */
>  #define for_each_pwq(pwq, wq)  \
> -   list_for_each_entry_rcu((pwq), &(wq)->pwqs, pwqs_node)  \
> -   if (({ assert_rcu_or_wq_mutex(wq); false; })) { }   \
> -   else
> +   list_for_each_entry_rcu((pwq), &(wq)->pwqs, pwqs_node,  \
> +lock_is_held(&(wq->mutex).dep_map))
>
>  #ifdef CONFIG_DEBUG_OBJECTS_WORK
>
> --
> 2.23.0.rc1.153.gdeed80330f-goog
>


Re: [PATCH v2 2/2] hwmon: pmbus: Add Inspur Power System power supply driver

2019-08-11 Thread Milton Miller II
Around 08/10/2019 04:55AM in some time zone, John Wang wrote:
>
>Add the driver to monitor Inspur Power System power supplies
>with hwmon over pmbus.
>
>This driver adds sysfs attributes for additional power supply data,
>including vendor, model, part_number, serial number,
>firmware revision, hardware revision, and psu mode(active/standby).
>
>Signed-off-by: John Wang 
>---
>v2:
>- Fix typos in commit message
>- Invert Christmas tree
>- Configure device with sysfs attrs, not debugfs entries
>- Fix errno in fw_version_read, ENODATA to EPROTO
>- Change the print format of fw-version
>- Use sysfs_streq instead of strcmp("xxx" "\n", "xxx")
>- Document sysfs attributes
>---
> Documentation/hwmon/inspur-ipsps1.rst |  79 +
> drivers/hwmon/pmbus/Kconfig   |   9 +
> drivers/hwmon/pmbus/Makefile  |   1 +
> drivers/hwmon/pmbus/inspur-ipsps.c| 236
>++
> 4 files changed, 325 insertions(+)
> create mode 100644 Documentation/hwmon/inspur-ipsps1.rst
> create mode 100644 drivers/hwmon/pmbus/inspur-ipsps.c
>
>diff --git a/Documentation/hwmon/inspur-ipsps1.rst
>b/Documentation/hwmon/inspur-ipsps1.rst

>diff --git a/drivers/hwmon/pmbus/Kconfig>b/drivers/hwmon/pmbus/Kconfig
>index 30751eb9550a..c09357c26b10 100644
>--- a/drivers/hwmon/pmbus/Kconfig
>+++ b/drivers/hwmon/pmbus/Kconfig
>@@ -203,4 +203,13 @@ config SENSORS_ZL6100
> This driver can also be built as a module. If so, the module will
> be called zl6100.
> 
>+config SENSORS_INSPUR_IPSPS
>+  tristate "INSPUR Power System Power Supply"

The entries in this file are sorted alphabetically.

>diff --git a/drivers/hwmon/pmbus/Makefile>b/drivers/hwmon/pmbus/Makefile
>index 2219b9300316..fde2d10cd05c 100644
>--- a/drivers/hwmon/pmbus/Makefile
>+++ b/drivers/hwmon/pmbus/Makefile
>@@ -23,3 +23,4 @@ obj-$(CONFIG_SENSORS_TPS53679)   += tps53679.o
> obj-$(CONFIG_SENSORS_UCD9000) += ucd9000.o
> obj-$(CONFIG_SENSORS_UCD9200) += ucd9200.o
> obj-$(CONFIG_SENSORS_ZL6100)  += zl6100.o
>+obj-$(CONFIG_SENSORS_INSPUR_IPSPS)+= inspur-ipsps.o
>diff --git a/drivers/hwmon/pmbus/inspur-ipsps.c
>b/drivers/hwmon/pmbus/inspur-ipsps.c
>new file mode 100644
>index ..f6dd10a62aef
>--- /dev/null
>+++ b/drivers/hwmon/pmbus/inspur-ipsps.c
>@@ -0,0 +1,236 @@
>+// SPDX-License-Identifier: GPL-2.0-or-later
>+/*
>+ * Copyright 2019 Inspur Corp.
>+ */
>+
>+#include 
>+#include 
>+#include 
>+#include 
>+#include 
>+#include 
>+#include 
>+
>+#include "pmbus.h"
>+
>+#define IPSPS_REG_VENDOR_ID   0x99
>+#define IPSPS_REG_MODEL   0x9A
>+#define IPSPS_REG_FW_VERSION  0x9B
>+#define IPSPS_REG_PN  0x9C
>+#define IPSPS_REG_SN  0x9E
>+#define IPSPS_REG_HW_VERSION  0xB0
>+#define IPSPS_REG_MODE0xFC
>+
>+#define MODE_ACTIVE   0x55
>+#define MODE_STANDBY  0x0E
>+#define MODE_REDUNDANCY   0x00
>+
>+#define MODE_ACTIVE_STRING"active"
>+#define MODE_STANDBY_STRING   "standby"
>+#define MODE_REDUNDANCY_STRING"redundancy"
>+
>+enum ipsps_index {
>+  vendor,
>+  model,
>+  fw_version,
>+  part_number,
>+  serial_number,
>+  hw_version,
>+  mode,
>+  num_regs,
>+};
>+
>+static const u8 ipsps_regs[num_regs] = {
>+  [vendor] = IPSPS_REG_VENDOR_ID,
>+  [model] = IPSPS_REG_MODEL,
>+  [fw_version] = IPSPS_REG_FW_VERSION,
>+  [part_number] = IPSPS_REG_PN,
>+  [serial_number] = IPSPS_REG_SN,
>+  [hw_version] = IPSPS_REG_HW_VERSION,
>+  [mode] = IPSPS_REG_MODE,
>+};
>+
>+static ssize_t ipsps_string_show(struct device *dev,
>+   struct device_attribute *devattr,
>+   char *buf)
>+{
>+  u8 reg;
>+  int rc, i;
>+  char data[I2C_SMBUS_BLOCK_MAX + 1] = { 0 };

Shouldn't need to initialize this.

>+  struct i2c_client *client = to_i2c_client(dev->parent);>+   struct 
>sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
>+
>+  reg = ipsps_regs[attr->index];
>+  rc = i2c_smbus_read_block_data(client, reg, data);
>+  if (rc < 0)
>+  return rc;
>+
>+  for (i = 0; i < rc; i++) {
>+  /* filled with printable characters, ending with # */
>+  if (data[i] == '#')
>+  break;
>+  }

This seems to be p = memscan(data, '#', rc);

>+>+data[i] = '\0';
>+
>+  return snprintf(buf, PAGE_SIZE, "%s\n", data);
>+}
>+
>+static ssize_t ipsps_fw_version_show(struct device *dev,
>+   struct device_attribute *devattr,
>+   char *buf)
>+{
>+  u8 reg;
>+  int rc;
>+  u8 data[I2C_SMBUS_BLOCK_MAX] = { 0 };
>+  struct i2c_client *client = to_i2c_client(dev->parent);
>+  struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
>+
>+  reg = ipsps_regs[attr->index];
>+  rc = i2c_smbus_read_block_data(client, reg, data);

Re: [PATCH] mailmap: add entry for Jaegeuk Kim

2019-08-11 Thread Chao Yu
On 2019/8/10 0:28, Jonathan Corbet wrote:
> On Thu, 8 Aug 2019 22:37:41 +0800
> Chao Yu  wrote:
> 
>>> IMO, when we use git-blame to find out who is response for specified code, 
>>> w/o
>>> mailmap we may just found old obsolete email address in the related commit; 
>>> even
>>> we can search full name for his/her new email address, how can we make sure 
>>> they
>>> are the same person... so anyway, it can help to find last valid/canonical 
>>> email
>>> address of someone.  
>>
>> Any thoughts?
> 
> I'm not fully convinced that we want to maintain a database of every
> developer's email history.  But I did merge this patch a few days ago.

Thanks for the merging anyway. :)

> 
> Thanks,
> 
> jon
> .
> 


[PATCH v3 2/2] hwmon: pmbus: Add Inspur Power System power supply driver

2019-08-11 Thread John Wang
Add the driver to monitor Inspur Power System power supplies
with hwmon over pmbus.

This driver adds sysfs attributes for additional power supply data,
including vendor, model, part_number, serial number,
firmware revision, hardware revision, and psu mode(active/standby).

Signed-off-by: John Wang 
---
v3:
- Sort kconfig/makefile entries alphabetically
- Remove unnecessary initialization
- Use ATTRIBUTE_GROUPS instead of expanding directly
- Use memscan to avoid reimplementation
v2:
- Fix typos in commit message
- Invert Christmas tree
- Configure device with sysfs attrs, not debugfs entries
- Fix errno in fw_version_read, ENODATA to EPROTO
- Change the print format of fw-version
- Use sysfs_streq instead of strcmp("xxx" "\n", "xxx")
- Document sysfs attributes
---
 Documentation/hwmon/inspur-ipsps1.rst |  79 +
 drivers/hwmon/pmbus/Kconfig   |   9 +
 drivers/hwmon/pmbus/Makefile  |  41 ++---
 drivers/hwmon/pmbus/inspur-ipsps.c| 226 ++
 4 files changed, 335 insertions(+), 20 deletions(-)
 create mode 100644 Documentation/hwmon/inspur-ipsps1.rst
 create mode 100644 drivers/hwmon/pmbus/inspur-ipsps.c

diff --git a/Documentation/hwmon/inspur-ipsps1.rst 
b/Documentation/hwmon/inspur-ipsps1.rst
new file mode 100644
index ..aa19f0ccc8b0
--- /dev/null
+++ b/Documentation/hwmon/inspur-ipsps1.rst
@@ -0,0 +1,79 @@
+Kernel driver inspur-ipsps1
+===
+
+Supported chips:
+
+  * Inspur Power System power supply unit
+
+Author: John Wang 
+
+Description
+---
+
+This driver supports Inspur Power System power supplies. This driver
+is a client to the core PMBus driver.
+
+Usage Notes
+---
+
+This driver does not auto-detect devices. You will have to instantiate the
+devices explicitly. Please see Documentation/i2c/instantiating-devices for
+details.
+
+Sysfs entries
+-
+
+The following attributes are supported:
+
+=== ==
+curr1_input Measured input current
+curr1_label "iin"
+curr1_max   Maximum current
+curr1_max_alarm Current high alarm
+curr2_inputMeasured output current in mA.
+curr2_label"iout1"
+curr2_crit  Critical maximum current
+curr2_crit_alarmCurrent critical high alarm
+curr2_max   Maximum current
+curr2_max_alarm Current high alarm
+
+fan1_alarm Fan 1 warning.
+fan1_fault Fan 1 fault.
+fan1_input Fan 1 speed in RPM.
+
+in1_alarm  Input voltage under-voltage alarm.
+in1_input  Measured input voltage in mV.
+in1_label  "vin"
+in2_input  Measured output voltage in mV.
+in2_label  "vout1"
+in2_lcrit   Critical minimum output voltage
+in2_lcrit_alarm Output voltage critical low alarm
+in2_max Maximum output voltage
+in2_max_alarm   Output voltage high alarm
+in2_min Minimum output voltage
+in2_min_alarm   Output voltage low alarm
+
+power1_alarm   Input fault or alarm.
+power1_input   Measured input power in uW.
+power1_label   "pin"
+power1_max  Input power limit
+power2_max_alarm   Output power high alarm
+power2_max  Output power limit
+power2_input   Measured output power in uW.
+power2_label   "pout"
+
+temp[1-3]_inputMeasured temperature
+temp[1-2]_max  Maximum temperature
+temp[1-3]_max_alarmTemperature high alarm
+
+vendor  Manufacturer name
+model   Product model
+part_number Product part number
+serial_number   Product serial number
+fw_version  Firmware version
+hw_version  Hardware version
+modeWork mode. Can be set to active or
+standby, when set to standby, PSU will
+automatically switch between standby
+and redundancy mode.
+=== ==
diff --git a/drivers/hwmon/pmbus/Kconfig b/drivers/hwmon/pmbus/Kconfig
index 30751eb9550a..2370fce6e816 100644
--- a/drivers/hwmon/pmbus/Kconfig
+++ b/drivers/hwmon/pmbus/Kconfig
@@ -46,6 +46,15 @@ config SENSORS_IBM_CFFPS
  This driver can also be built as a module. If so, the module will
  be called ibm-cffps.
 
+config SENSORS_INSPUR_IPSPS
+   tristate "INSPUR Power System Power Supply"
+   help
+ If you say yes here you get hardware monitoring support for the INSPUR
+ Power System power supply.
+
+ This driver can also be built as a module. If so, the module will
+ be called inspur-ipsps.
+
 config SENSORS_IR35221
tristate "Infineon IR35221"
help
diff --git a/drivers/hwmon/pmbus

[PATCH v5 2/9] fpga: dfl: fme: convert platform_driver to use dev_groups

2019-08-11 Thread Wu Hao
This patch takes advantage of driver core which helps to create
and remove sysfs attribute files, so there is no need to register
sysfs entries manually in dfl-fme platform river code.

Signed-off-by: Wu Hao 
---
 drivers/fpga/dfl-fme-main.c | 29 ++---
 1 file changed, 2 insertions(+), 27 deletions(-)

diff --git a/drivers/fpga/dfl-fme-main.c b/drivers/fpga/dfl-fme-main.c
index f033f1c..bf8114d 100644
--- a/drivers/fpga/dfl-fme-main.c
+++ b/drivers/fpga/dfl-fme-main.c
@@ -129,30 +129,6 @@ static ssize_t socket_id_show(struct device *dev,
 };
 ATTRIBUTE_GROUPS(fme_hdr);
 
-static int fme_hdr_init(struct platform_device *pdev,
-   struct dfl_feature *feature)
-{
-   void __iomem *base = feature->ioaddr;
-   int ret;
-
-   dev_dbg(&pdev->dev, "FME HDR Init.\n");
-   dev_dbg(&pdev->dev, "FME cap %llx.\n",
-   (unsigned long long)readq(base + FME_HDR_CAP));
-
-   ret = device_add_groups(&pdev->dev, fme_hdr_groups);
-   if (ret)
-   return ret;
-
-   return 0;
-}
-
-static void fme_hdr_uinit(struct platform_device *pdev,
- struct dfl_feature *feature)
-{
-   dev_dbg(&pdev->dev, "FME HDR UInit.\n");
-   device_remove_groups(&pdev->dev, fme_hdr_groups);
-}
-
 static long fme_hdr_ioctl_release_port(struct dfl_feature_platform_data *pdata,
   unsigned long arg)
 {
@@ -199,8 +175,6 @@ static long fme_hdr_ioctl(struct platform_device *pdev,
 };
 
 static const struct dfl_feature_ops fme_hdr_ops = {
-   .init = fme_hdr_init,
-   .uinit = fme_hdr_uinit,
.ioctl = fme_hdr_ioctl,
 };
 
@@ -361,7 +335,8 @@ static int fme_remove(struct platform_device *pdev)
 
 static struct platform_driver fme_driver = {
.driver = {
-   .name= DFL_FPGA_FEATURE_DEV_FME,
+   .name   = DFL_FPGA_FEATURE_DEV_FME,
+   .dev_groups = fme_hdr_groups,
},
.probe   = fme_probe,
.remove  = fme_remove,
-- 
1.8.3.1



[PATCH v5 6/9] fpga: dfl: afu: add error reporting support.

2019-08-11 Thread Wu Hao
Error reporting is one important private feature, it reports error
detected on port and accelerated function unit (AFU). It introduces
several sysfs interfaces to allow userspace to check and clear
errors detected by hardware.

Signed-off-by: Xu Yilun 
Signed-off-by: Wu Hao 
Acked-by: Alan Tull 
Signed-off-by: Moritz Fischer 
---
v2: switch to device_add/remove_group for sysfs.
v3: update kernel version and date in sysfs doc
v4: remove dev_dbg in init/uinit callback function.
v5: rework init/uinit function and improve naming.
update sysfs entries:
  remove revision sysfs entry.
  merge WO "clear" sysfs to RO "errors" to keep alignment with
  latest changes in fme error reporting support.
expose error related sysfs entries via dev_groups.
---
 Documentation/ABI/testing/sysfs-platform-dfl-port |  25 +++
 drivers/fpga/Makefile |   1 +
 drivers/fpga/dfl-afu-error.c  | 230 ++
 drivers/fpga/dfl-afu-main.c   |   5 +
 drivers/fpga/dfl-afu.h|   5 +
 5 files changed, 266 insertions(+)
 create mode 100644 drivers/fpga/dfl-afu-error.c

diff --git a/Documentation/ABI/testing/sysfs-platform-dfl-port 
b/Documentation/ABI/testing/sysfs-platform-dfl-port
index c2660e4..6565826 100644
--- a/Documentation/ABI/testing/sysfs-platform-dfl-port
+++ b/Documentation/ABI/testing/sysfs-platform-dfl-port
@@ -74,3 +74,28 @@ KernelVersion:   5.4
 Contact:   Wu Hao 
 Description:   Read-only. Read this file to get the status of issued command
to userclck_freqcntrcmd.
+
+What:  /sys/bus/platform/devices/dfl-port.0/errors/errors
+Date:  August 2019
+KernelVersion: 5.4
+Contact:   Wu Hao 
+Description:   Read-Write. Read this file to get errors detected on port and
+   Accelerated Function Unit (AFU). Write error code to this file
+   to clear errors. Write fails with -EINVAL if input parsing
+   fails or input error code doesn't match. Write fails with
+   -EBUSY or -ETIMEDOUT if error can't be cleared as hardware
+   in low power state (-EBUSY) or not respoding (-ETIMEDOUT).
+
+What:  /sys/bus/platform/devices/dfl-port.0/errors/first_error
+Date:  August 2019
+KernelVersion: 5.4
+Contact:   Wu Hao 
+Description:   Read-only. Read this file to get the first error detected by
+   hardware.
+
+What:  /sys/bus/platform/devices/dfl-port.0/errors/first_malformed_req
+Date:  August 2019
+KernelVersion: 5.4
+Contact:   Wu Hao 
+Description:   Read-only. Read this file to get the first malformed request
+   captured by hardware.
diff --git a/drivers/fpga/Makefile b/drivers/fpga/Makefile
index 312b937..7255891 100644
--- a/drivers/fpga/Makefile
+++ b/drivers/fpga/Makefile
@@ -41,6 +41,7 @@ obj-$(CONFIG_FPGA_DFL_AFU)+= dfl-afu.o
 
 dfl-fme-objs := dfl-fme-main.o dfl-fme-pr.o
 dfl-afu-objs := dfl-afu-main.o dfl-afu-region.o dfl-afu-dma-region.o
+dfl-afu-objs += dfl-afu-error.o
 
 # Drivers for FPGAs which implement DFL
 obj-$(CONFIG_FPGA_DFL_PCI) += dfl-pci.o
diff --git a/drivers/fpga/dfl-afu-error.c b/drivers/fpga/dfl-afu-error.c
new file mode 100644
index 000..c1467ae
--- /dev/null
+++ b/drivers/fpga/dfl-afu-error.c
@@ -0,0 +1,230 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Driver for FPGA Accelerated Function Unit (AFU) Error Reporting
+ *
+ * Copyright 2019 Intel Corporation, Inc.
+ *
+ * Authors:
+ *   Wu Hao 
+ *   Xiao Guangrong 
+ *   Joseph Grecco 
+ *   Enno Luebbers 
+ *   Tim Whisonant 
+ *   Ananda Ravuri 
+ *   Mitchel Henry 
+ */
+
+#include 
+
+#include "dfl-afu.h"
+
+#define PORT_ERROR_MASK0x8
+#define PORT_ERROR 0x10
+#define PORT_FIRST_ERROR   0x18
+#define PORT_MALFORMED_REQ00x20
+#define PORT_MALFORMED_REQ10x28
+
+#define ERROR_MASK GENMASK_ULL(63, 0)
+
+/* mask or unmask port errors by the error mask register. */
+static void __afu_port_err_mask(struct device *dev, bool mask)
+{
+   void __iomem *base;
+
+   base = dfl_get_feature_ioaddr_by_id(dev, PORT_FEATURE_ID_ERROR);
+
+   writeq(mask ? ERROR_MASK : 0, base + PORT_ERROR_MASK);
+}
+
+static void afu_port_err_mask(struct device *dev, bool mask)
+{
+   struct dfl_feature_platform_data *pdata = dev_get_platdata(dev);
+
+   mutex_lock(&pdata->lock);
+   __afu_port_err_mask(dev, mask);
+   mutex_unlock(&pdata->lock);
+}
+
+/* clear port errors. */
+static int afu_port_err_clear(struct device *dev, u64 err)
+{
+   struct dfl_feature_platform_data *pdata = dev_get_platdata(dev);
+   struct platform_device *pdev = to_platform_device(dev);
+   void __iomem *base_err, *base_hdr;
+   int ret = -EBUSY;
+   u64 v;
+
+   base_err = dfl_get_feature_ioaddr_by_id(dev, PORT_FEATURE_ID_ERROR);
+   base_hdr = dfl_get_feature_ioaddr_by_id(dev, PORT_FEATURE_ID

[PATCH v5 9/9] Documentation: fpga: dfl: add descriptions for virtualization and new interfaces.

2019-08-11 Thread Wu Hao
This patch adds virtualization support description for DFL based
FPGA devices (based on PCIe SRIOV), and introductions to new
interfaces added by new dfl private feature drivers.

[m...@kernel.org: Fixed up to make it work with new reStructuredText docs]
Signed-off-by: Xu Yilun 
Signed-off-by: Wu Hao 
Acked-by: Alan Tull 
Signed-off-by: Moritz Fischer 
---
 Documentation/fpga/dfl.rst | 105 +
 1 file changed, 105 insertions(+)

diff --git a/Documentation/fpga/dfl.rst b/Documentation/fpga/dfl.rst
index 2f125ab..6fa483f 100644
--- a/Documentation/fpga/dfl.rst
+++ b/Documentation/fpga/dfl.rst
@@ -87,6 +87,8 @@ The following functions are exposed through ioctls:
 - Get driver API version (DFL_FPGA_GET_API_VERSION)
 - Check for extensions (DFL_FPGA_CHECK_EXTENSION)
 - Program bitstream (DFL_FPGA_FME_PORT_PR)
+- Assign port to PF (DFL_FPGA_FME_PORT_ASSIGN)
+- Release port from PF (DFL_FPGA_FME_PORT_RELEASE)
 
 More functions are exposed through sysfs
 (/sys/class/fpga_region/regionX/dfl-fme.n/):
@@ -102,6 +104,10 @@ More functions are exposed through sysfs
  one FPGA device may have more than one port, this sysfs interface 
indicates
  how many ports the FPGA device has.
 
+ Global error reporting management (errors/)
+ error reporting sysfs interfaces allow user to read errors detected by the
+ hardware, and clear the logged errors.
+
 
 FIU - PORT
 ==
@@ -143,6 +149,10 @@ More functions are exposed through sysfs:
  Read Accelerator GUID (afu_id)
  afu_id indicates which PR bitstream is programmed to this AFU.
 
+ Error reporting (errors/)
+ error reporting sysfs interfaces allow user to read port/afu errors
+ detected by the hardware, and clear the logged errors.
+
 
 DFL Framework Overview
 ==
@@ -218,6 +228,101 @@ the compat_id exposed by the target FPGA region. This 
check is usually done by
 userspace before calling the reconfiguration IOCTL.
 
 
+FPGA virtualization - PCIe SRIOV
+
+This section describes the virtualization support on DFL based FPGA device to
+enable accessing an accelerator from applications running in a virtual machine
+(VM). This section only describes the PCIe based FPGA device with SRIOV 
support.
+
+Features supported by the particular FPGA device are exposed through Device
+Feature Lists, as illustrated below:
+
+::
+
++---+  +-+
+|  PF   |  | VF  |
++---+  +-+
+^^ ^  ^
+|| |  |
+  +-||-|--|---+
+  | || |  |   |
+  |  +-+ +---+ +---+  +---+   |
+  |  | FME | | Port0 | | Port1 |  | Port2 |   |
+  |  +-+ +---+ +---+  +---+   |
+  |  ^ ^  ^   |
+  |  | |  |   |
+  |  +---+ +--+   +---+   |
+  |  |  AFU  | |  AFU |   |  AFU  |   |
+  |  +---+ +--+   +---+   |
+  |   |
+  |DFL based FPGA PCIe Device |
+  +---+
+
+FME is always accessed through the physical function (PF).
+
+Ports (and related AFUs) are accessed via PF by default, but could be exposed
+through virtual function (VF) devices via PCIe SRIOV. Each VF only contains
+1 Port and 1 AFU for isolation. Users could assign individual VFs 
(accelerators)
+created via PCIe SRIOV interface, to virtual machines.
+
+The driver organization in virtualization case is illustrated below:
+::
+
++---++--++--+ |
+| FME   || FME  || FME  | |
+| FPGA  || FPGA || FPGA | |
+|Manager||Bridge||Region| |
++---++--++--+ |
++---+  ++ | ++
+|  FME  |  |  AFU   | | |  AFU   |
+| Module|  | Module | | | Module |
++---+  ++ | ++
+  +---+   |   +---+
+  | FPGA Container Device |   |   | FPGA Container Device |
+  |  (FPGA Base Region)   |   |   |  (FPGA Base Region)   |
+  +---+   |   +---+
++--+  | +--+
+| FPGA PCIE Module |  | Virtual | FPGA PCIE Module |
++--+   Host   | Machine +--+
+   -- | --
+ +---+

[PATCH v5 1/9] fpga: dfl: make init callback optional

2019-08-11 Thread Wu Hao
This patch makes init callback of sub features optional. With
this change, people don't need to prepare any empty init callback.

Signed-off-by: Wu Hao 
---
 drivers/fpga/dfl.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c
index c0512af..96a2b82 100644
--- a/drivers/fpga/dfl.c
+++ b/drivers/fpga/dfl.c
@@ -271,11 +271,13 @@ static int dfl_feature_instance_init(struct 
platform_device *pdev,
 struct dfl_feature *feature,
 struct dfl_feature_driver *drv)
 {
-   int ret;
+   int ret = 0;
 
-   ret = drv->ops->init(pdev, feature);
-   if (ret)
-   return ret;
+   if (drv->ops->init) {
+   ret = drv->ops->init(pdev, feature);
+   if (ret)
+   return ret;
+   }
 
feature->ops = drv->ops;
 
-- 
1.8.3.1



[PATCH v5 7/9] fpga: dfl: afu: add STP (SignalTap) support

2019-08-11 Thread Wu Hao
STP (SignalTap) is one of the private features under the port for
debugging. This patch adds private feature driver support for it
to allow userspace applications to mmap related mmio region and
provide STP service.

Signed-off-by: Xu Yilun 
Signed-off-by: Wu Hao 
Acked-by: Moritz Fischer 
Acked-by: Alan Tull 
Signed-off-by: Moritz Fischer 
---
v4: remove uinit callback which does nothing.
remove dev_dbg in init callback function.
---
 drivers/fpga/dfl-afu-main.c | 25 +
 1 file changed, 25 insertions(+)

diff --git a/drivers/fpga/dfl-afu-main.c b/drivers/fpga/dfl-afu-main.c
index e11352a..e4a34dc 100644
--- a/drivers/fpga/dfl-afu-main.c
+++ b/drivers/fpga/dfl-afu-main.c
@@ -508,6 +508,27 @@ static int port_afu_init(struct platform_device *pdev,
.init = port_afu_init,
 };
 
+static int port_stp_init(struct platform_device *pdev,
+struct dfl_feature *feature)
+{
+   struct resource *res = &pdev->resource[feature->resource_index];
+
+   return afu_mmio_region_add(dev_get_platdata(&pdev->dev),
+  DFL_PORT_REGION_INDEX_STP,
+  resource_size(res), res->start,
+  DFL_PORT_REGION_MMAP | DFL_PORT_REGION_READ |
+  DFL_PORT_REGION_WRITE);
+}
+
+static const struct dfl_feature_id port_stp_id_table[] = {
+   {.id = PORT_FEATURE_ID_STP,},
+   {0,}
+};
+
+static const struct dfl_feature_ops port_stp_ops = {
+   .init = port_stp_init,
+};
+
 static struct dfl_feature_driver port_feature_drvs[] = {
{
.id_table = port_hdr_id_table,
@@ -522,6 +543,10 @@ static int port_afu_init(struct platform_device *pdev,
.ops = &port_err_ops,
},
{
+   .id_table = port_stp_id_table,
+   .ops = &port_stp_ops,
+   },
+   {
.ops = NULL,
}
 };
-- 
1.8.3.1



[PATCH v5 3/9] fpga: dfl: afu: convert platform_driver to use dev_groups

2019-08-11 Thread Wu Hao
This patch takes advantage of driver core which helps to create
and remove sysfs attribute files, so there is no need to register
sysfs entries manually in dfl-afu platform river code.

Signed-off-by: Wu Hao 
---
 drivers/fpga/dfl-afu-main.c | 69 +++--
 1 file changed, 36 insertions(+), 33 deletions(-)

diff --git a/drivers/fpga/dfl-afu-main.c b/drivers/fpga/dfl-afu-main.c
index e50c45e..e955149 100644
--- a/drivers/fpga/dfl-afu-main.c
+++ b/drivers/fpga/dfl-afu-main.c
@@ -282,24 +282,17 @@ static int port_get_id(struct platform_device *pdev)
&dev_attr_power_state.attr,
NULL,
 };
-ATTRIBUTE_GROUPS(port_hdr);
+
+static const struct attribute_group port_hdr_group = {
+   .attrs = port_hdr_attrs,
+};
 
 static int port_hdr_init(struct platform_device *pdev,
 struct dfl_feature *feature)
 {
-   dev_dbg(&pdev->dev, "PORT HDR Init.\n");
-
port_reset(pdev);
 
-   return device_add_groups(&pdev->dev, port_hdr_groups);
-}
-
-static void port_hdr_uinit(struct platform_device *pdev,
-  struct dfl_feature *feature)
-{
-   dev_dbg(&pdev->dev, "PORT HDR UInit.\n");
-
-   device_remove_groups(&pdev->dev, port_hdr_groups);
+   return 0;
 }
 
 static long
@@ -330,7 +323,6 @@ static void port_hdr_uinit(struct platform_device *pdev,
 
 static const struct dfl_feature_ops port_hdr_ops = {
.init = port_hdr_init,
-   .uinit = port_hdr_uinit,
.ioctl = port_hdr_ioctl,
 };
 
@@ -361,32 +353,37 @@ static void port_hdr_uinit(struct platform_device *pdev,
&dev_attr_afu_id.attr,
NULL
 };
-ATTRIBUTE_GROUPS(port_afu);
 
-static int port_afu_init(struct platform_device *pdev,
-struct dfl_feature *feature)
+static umode_t port_afu_attrs_visible(struct kobject *kobj,
+ struct attribute *attr, int n)
 {
-   struct resource *res = &pdev->resource[feature->resource_index];
-   int ret;
-
-   dev_dbg(&pdev->dev, "PORT AFU Init.\n");
+   struct device *dev = kobj_to_dev(kobj);
 
-   ret = afu_mmio_region_add(dev_get_platdata(&pdev->dev),
- DFL_PORT_REGION_INDEX_AFU, resource_size(res),
- res->start, DFL_PORT_REGION_READ |
- DFL_PORT_REGION_WRITE | DFL_PORT_REGION_MMAP);
-   if (ret)
-   return ret;
+   /*
+* sysfs entries are visible only if related private feature is
+* enumerated.
+*/
+   if (!dfl_get_feature_by_id(dev, PORT_FEATURE_ID_AFU))
+   return 0;
 
-   return device_add_groups(&pdev->dev, port_afu_groups);
+   return attr->mode;
 }
 
-static void port_afu_uinit(struct platform_device *pdev,
-  struct dfl_feature *feature)
+static const struct attribute_group port_afu_group = {
+   .attrs  = port_afu_attrs,
+   .is_visible = port_afu_attrs_visible,
+};
+
+static int port_afu_init(struct platform_device *pdev,
+struct dfl_feature *feature)
 {
-   dev_dbg(&pdev->dev, "PORT AFU UInit.\n");
+   struct resource *res = &pdev->resource[feature->resource_index];
 
-   device_remove_groups(&pdev->dev, port_afu_groups);
+   return afu_mmio_region_add(dev_get_platdata(&pdev->dev),
+  DFL_PORT_REGION_INDEX_AFU,
+  resource_size(res), res->start,
+  DFL_PORT_REGION_MMAP | DFL_PORT_REGION_READ |
+  DFL_PORT_REGION_WRITE);
 }
 
 static const struct dfl_feature_id port_afu_id_table[] = {
@@ -396,7 +393,6 @@ static void port_afu_uinit(struct platform_device *pdev,
 
 static const struct dfl_feature_ops port_afu_ops = {
.init = port_afu_init,
-   .uinit = port_afu_uinit,
 };
 
 static struct dfl_feature_driver port_feature_drvs[] = {
@@ -748,9 +744,16 @@ static int afu_remove(struct platform_device *pdev)
return 0;
 }
 
+static const struct attribute_group *afu_dev_groups[] = {
+   &port_hdr_group,
+   &port_afu_group,
+   NULL
+};
+
 static struct platform_driver afu_driver = {
.driver = {
-   .name= DFL_FPGA_FEATURE_DEV_PORT,
+   .name   = DFL_FPGA_FEATURE_DEV_PORT,
+   .dev_groups = afu_dev_groups,
},
.probe   = afu_probe,
.remove  = afu_remove,
-- 
1.8.3.1



[PATCH v5 8/9] fpga: dfl: fme: add global error reporting support

2019-08-11 Thread Wu Hao
This patch adds support for global error reporting for FPGA
Management Engine (FME), it introduces sysfs interfaces to
report different error detected by the hardware, and allow
user to clear errors or inject error for testing purpose.

Signed-off-by: Luwei Kang 
Signed-off-by: Ananda Ravuri 
Signed-off-by: Xu Yilun 
Signed-off-by: Wu Hao 
Acked-by: Alan Tull 
Signed-off-by: Moritz Fischer 
---
v2: switch to device_add/remove_groups for sysfs.
v3: update kernel version and date in sysfs doc
v4: rebase, remove dev_dbg in init/uinit callback.
v5: reorganize sysfs entries:
  remove "fme-errors" sub folder and related sysfs entries to
  upper level folder.
  merge WO "clear" to RO "errors" to keep alignment with error
  sysfs entries in upper level folder.
  remove revision sysfs entry.
add missed locking in sysfs entries.
expose sysfs group with is_visible via dev_groups.
---
 Documentation/ABI/testing/sysfs-platform-dfl-fme |  62 
 drivers/fpga/Makefile|   2 +-
 drivers/fpga/dfl-fme-error.c | 359 +++
 drivers/fpga/dfl-fme-main.c  |  17 +-
 drivers/fpga/dfl-fme.h   |   3 +
 5 files changed, 440 insertions(+), 3 deletions(-)
 create mode 100644 drivers/fpga/dfl-fme-error.c

diff --git a/Documentation/ABI/testing/sysfs-platform-dfl-fme 
b/Documentation/ABI/testing/sysfs-platform-dfl-fme
index 65372aa..72634d3 100644
--- a/Documentation/ABI/testing/sysfs-platform-dfl-fme
+++ b/Documentation/ABI/testing/sysfs-platform-dfl-fme
@@ -44,3 +44,65 @@ Description: Read-only. It returns socket_id to indicate 
which socket
this FPGA belongs to, only valid for integrated solution.
User only needs this information, in case standard numa node
can't provide correct information.
+
+What:  /sys/bus/platform/devices/dfl-fme.0/errors/pcie0_errors
+Date:  August 2019
+KernelVersion:  5.4
+Contact:   Wu Hao 
+Description:   Read-Write. Read this file for errors detected on pcie0 link.
+   Write this file to clear errors logged in pcie0_errors. Write
+   fails with -EINVAL if input parsing fails or input error code
+   doesn't match.
+
+What:  /sys/bus/platform/devices/dfl-fme.0/errors/pcie1_errors
+Date:  August 2019
+KernelVersion:  5.4
+Contact:   Wu Hao 
+Description:   Read-Write. Read this file for errors detected on pcie1 link.
+   Write this file to clear errors logged in pcie1_errors. Write
+   fails with -EINVAL if input parsing fails or input error code
+   doesn't match.
+
+What:  /sys/bus/platform/devices/dfl-fme.0/errors/nonfatal_errors
+Date:  August 2019
+KernelVersion:  5.4
+Contact:   Wu Hao 
+Description:   Read-only. It returns non-fatal errors detected.
+
+What:  /sys/bus/platform/devices/dfl-fme.0/errors/catfatal_errors
+Date:  August 2019
+KernelVersion:  5.4
+Contact:   Wu Hao 
+Description:   Read-only. It returns catastrophic and fatal errors detected.
+
+What:  /sys/bus/platform/devices/dfl-fme.0/errors/inject_errors
+Date:  August 2019
+KernelVersion:  5.4
+Contact:   Wu Hao 
+Description:   Read-Write. Read this file to check errors injected. Write this
+   file to inject errors for testing purpose. Write fails with
+   -EINVAL if input parsing fails or input inject error code isn't
+   supported.
+
+What:  /sys/bus/platform/devices/dfl-fme.0/errors/fme_errors
+Date:  August 2019
+KernelVersion:  5.4
+Contact:   Wu Hao 
+Description:   Read-Write. Read this file to get errors detected on FME.
+   Write this file to clear errors logged in fme_errors. Write
+   fials with -EINVAL if input parsing fails or input error code
+   doesn't match.
+
+What:  /sys/bus/platform/devices/dfl-fme.0/errors/first_error
+Date:  August 2019
+KernelVersion:  5.4
+Contact:   Wu Hao 
+Description:   Read-only. Read this file to get the first error detected by
+   hardware.
+
+What:  /sys/bus/platform/devices/dfl-fme.0/errors/next_error
+Date:  August 2019
+KernelVersion:  5.4
+Contact:   Wu Hao 
+Description:   Read-only. Read this file to get the second error detected by
+   hardware.
diff --git a/drivers/fpga/Makefile b/drivers/fpga/Makefile
index 7255891..4865b74 100644
--- a/drivers/fpga/Makefile
+++ b/drivers/fpga/Makefile
@@ -39,7 +39,7 @@ obj-$(CONFIG_FPGA_DFL_FME_BRIDGE) += dfl-fme-br.o
 obj-$(CONFIG_FPGA_DFL_FME_REGION)  += dfl-fme-region.o
 obj-$(CONFIG_FPGA_DFL_AFU) += dfl-afu.o
 
-dfl-fme-objs := dfl-fme-main.o dfl-fme-pr.o
+dfl-fme-objs := dfl-fme-main.o dfl-fme-pr.o dfl-fme-error.o
 dfl-afu-objs := dfl-afu-main.o dfl-afu-region.o dfl-afu-dma-region.o
 dfl-afu-objs += dfl-afu-error.o

[PATCH v5 5/9] fpga: dfl: afu: expose __afu_port_enable/disable function.

2019-08-11 Thread Wu Hao
As these two functions are used by other private features within the
same driver module but different driver files. e.g. in error reporting
private feature, it requires to clear errors when port is in reset.

Signed-off-by: Xu Yilun 
Signed-off-by: Wu Hao 
Acked-by: Moritz Fischer 
Acked-by: Alan Tull 
Signed-off-by: Moritz Fischer 
---
v2: rebased
v5: add afu prefix to __port_enable/disable function to keep
alignment with other func exposed across different afu files.
---
 drivers/fpga/dfl-afu-main.c | 26 +++---
 drivers/fpga/dfl-afu.h  |  4 
 2 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/drivers/fpga/dfl-afu-main.c b/drivers/fpga/dfl-afu-main.c
index f0b45f2..449185c 100644
--- a/drivers/fpga/dfl-afu-main.c
+++ b/drivers/fpga/dfl-afu-main.c
@@ -22,14 +22,17 @@
 #include "dfl-afu.h"
 
 /**
- * port_enable - enable a port
+ * __afu_port_enable - enable a port by clear reset
  * @pdev: port platform device.
  *
  * Enable Port by clear the port soft reset bit, which is set by default.
  * The AFU is unable to respond to any MMIO access while in reset.
- * port_enable function should only be used after port_disable function.
+ * __afu_port_enable function should only be used after __afu_port_disable
+ * function.
+ *
+ * The caller needs to hold lock for protection.
  */
-static void port_enable(struct platform_device *pdev)
+void __afu_port_enable(struct platform_device *pdev)
 {
struct dfl_feature_platform_data *pdata = dev_get_platdata(&pdev->dev);
void __iomem *base;
@@ -52,13 +55,14 @@ static void port_enable(struct platform_device *pdev)
 #define RST_POLL_TIMEOUT 1000 /* us */
 
 /**
- * port_disable - disable a port
+ * __afu_port_disable - disable a port by hold reset
  * @pdev: port platform device.
  *
- * Disable Port by setting the port soft reset bit, it puts the port into
- * reset.
+ * Disable Port by setting the port soft reset bit, it puts the port into 
reset.
+ *
+ * The caller needs to hold lock for protection.
  */
-static int port_disable(struct platform_device *pdev)
+int __afu_port_disable(struct platform_device *pdev)
 {
struct dfl_feature_platform_data *pdata = dev_get_platdata(&pdev->dev);
void __iomem *base;
@@ -104,9 +108,9 @@ static int __port_reset(struct platform_device *pdev)
 {
int ret;
 
-   ret = port_disable(pdev);
+   ret = __afu_port_disable(pdev);
if (!ret)
-   port_enable(pdev);
+   __afu_port_enable(pdev);
 
return ret;
 }
@@ -799,9 +803,9 @@ static int port_enable_set(struct platform_device *pdev, 
bool enable)
 
mutex_lock(&pdata->lock);
if (enable)
-   port_enable(pdev);
+   __afu_port_enable(pdev);
else
-   ret = port_disable(pdev);
+   ret = __afu_port_disable(pdev);
mutex_unlock(&pdata->lock);
 
return ret;
diff --git a/drivers/fpga/dfl-afu.h b/drivers/fpga/dfl-afu.h
index 0c7630a..83683f2 100644
--- a/drivers/fpga/dfl-afu.h
+++ b/drivers/fpga/dfl-afu.h
@@ -79,6 +79,10 @@ struct dfl_afu {
struct dfl_feature_platform_data *pdata;
 };
 
+/* hold pdata->lock when call __afu_port_enable/disable */
+void __afu_port_enable(struct platform_device *pdev);
+int __afu_port_disable(struct platform_device *pdev);
+
 void afu_mmio_region_init(struct dfl_feature_platform_data *pdata);
 int afu_mmio_region_add(struct dfl_feature_platform_data *pdata,
u32 region_index, u64 region_size, u64 phys, u32 flags);
-- 
1.8.3.1



[PATCH v5 0/9] FPGA DFL updates

2019-08-11 Thread Wu Hao
Hi Greg,

This is v5 patchset which adds more features to FPGA DFL. Marjor changes
against v4 are sysfs related code rework to address comments on v4.

Please help to take a look. Thanks!

Main changes from v4:
  - convert code to use dev_groups for sysfs entries (#2, #3, #4, #6, #8).
  - clean up for empty init function after remove sysfs add/remove (#1).
  - introduce is_visible for sysfs groups (#3, #4, #6, #8).
  - remove revision sysfs entries (#4, #6, #8).
  - improve naming on shared functions (#5).
  - reorganize sysfs entries for port and fme error reporting (#6, #8).

Main changes from v3:
  - drop avx512 partail reconfiguration patch for now.
  - split dfl_fpga_cdev_config_port to 2 functions *_release/assign_port
(#1).
  - split __dfl_fpga_cdev_config_port_vf into 2 functions with locking
added (#2).
  - improve description in sysfs doc to avoid misunderstanding (#3).
  - switch to boolean in sysfs entry store function (#3).
  - remove dev_dbg in init/uinit callback function (#7, #9, #11).
  - remove uinit callback which does does nothing (#8, #9)

Main changes from v2:
  - update kernel version/date in sysfs doc (patch #4, #5, #8, #10, #11).
  - add back Documentation patch (patch #12).

Main changes from v1:
  - remove DRV/MODULE_VERSION modifications. (patch #1, #3, #4, #6)
  - remove argsz from new ioctls. (patch #2)
  - replace sysfs_create/remove_* with device_add/remove_* for sysfs entries.
(patch #5, #8, #11)

Wu Hao (9):
  fpga: dfl: make init callback optional
  fpga: dfl: fme: convert platform_driver to use dev_groups
  fpga: dfl: afu: convert platform_driver to use dev_groups
  fpga: dfl: afu: add userclock sysfs interfaces.
  fpga: dfl: afu: expose __afu_port_enable/disable function.
  fpga: dfl: afu: add error reporting support.
  fpga: dfl: afu: add STP (SignalTap) support
  fpga: dfl: fme: add global error reporting support
  Documentation: fpga: dfl: add descriptions for virtualization and new
interfaces.

 Documentation/ABI/testing/sysfs-platform-dfl-fme  |  62 
 Documentation/ABI/testing/sysfs-platform-dfl-port |  53 
 Documentation/fpga/dfl.rst| 105 +++
 drivers/fpga/Makefile |   3 +-
 drivers/fpga/dfl-afu-error.c  | 230 ++
 drivers/fpga/dfl-afu-main.c   | 230 +++---
 drivers/fpga/dfl-afu.h|   9 +
 drivers/fpga/dfl-fme-error.c  | 359 ++
 drivers/fpga/dfl-fme-main.c   |  42 +--
 drivers/fpga/dfl-fme.h|   3 +
 drivers/fpga/dfl.c|  10 +-
 drivers/fpga/dfl.h|   9 +
 12 files changed, 1041 insertions(+), 74 deletions(-)
 create mode 100644 drivers/fpga/dfl-afu-error.c
 create mode 100644 drivers/fpga/dfl-fme-error.c

-- 
1.8.3.1



[PATCH v5 4/9] fpga: dfl: afu: add userclock sysfs interfaces.

2019-08-11 Thread Wu Hao
This patch introduces userclock sysfs interfaces for AFU, user
could use these interfaces for clock setting to AFU.

Please note that, this is only working for port header feature
with revision 0, for later revisions, userclock setting is moved
to a separated private feature, so one revision sysfs interface
is exposed to userspace application for this purpose too.

Signed-off-by: Ananda Ravuri 
Signed-off-by: Russ Weight 
Signed-off-by: Xu Yilun 
Signed-off-by: Wu Hao 
Acked-by: Alan Tull 
Signed-off-by: Moritz Fischer 
---
v2: rebased, and switched to use device_add/remove_groups for sysfs
v3: update kernel version and date in sysfs doc
v4: rebased.
v5: drop sysfs add/remove in init/uinit callback.
add missed locking for sysfs.
use is_visible to decide if hardware supports userclk or not.
remove revision sysfs entry.
---
 Documentation/ABI/testing/sysfs-platform-dfl-port |  28 ++
 drivers/fpga/dfl-afu-main.c   | 111 +-
 drivers/fpga/dfl.h|   9 ++
 3 files changed, 147 insertions(+), 1 deletion(-)

diff --git a/Documentation/ABI/testing/sysfs-platform-dfl-port 
b/Documentation/ABI/testing/sysfs-platform-dfl-port
index 1ab3e6f..c2660e4 100644
--- a/Documentation/ABI/testing/sysfs-platform-dfl-port
+++ b/Documentation/ABI/testing/sysfs-platform-dfl-port
@@ -46,3 +46,31 @@ Contact: Wu Hao 
 Description:   Read-write. Read or set AFU latency tolerance reporting value.
Set ltr to 1 if the AFU can tolerate latency >= 40us or set it
to 0 if it is latency sensitive.
+
+What:  /sys/bus/platform/devices/dfl-port.0/userclk_freqcmd
+Date:  August 2019
+KernelVersion: 5.4
+Contact:   Wu Hao 
+Description:   Write-only. User writes command to this interface to set
+   userclock to AFU.
+
+What:  /sys/bus/platform/devices/dfl-port.0/userclk_freqsts
+Date:  August 2019
+KernelVersion: 5.4
+Contact:   Wu Hao 
+Description:   Read-only. Read this file to get the status of issued command
+   to userclck_freqcmd.
+
+What:  /sys/bus/platform/devices/dfl-port.0/userclk_freqcntrcmd
+Date:  August 2019
+KernelVersion: 5.4
+Contact:   Wu Hao 
+Description:   Write-only. User writes command to this interface to set
+   userclock counter.
+
+What:  /sys/bus/platform/devices/dfl-port.0/userclk_freqcntrsts
+Date:  August 2019
+KernelVersion: 5.4
+Contact:   Wu Hao 
+Description:   Read-only. Read this file to get the status of issued command
+   to userclck_freqcntrcmd.
diff --git a/drivers/fpga/dfl-afu-main.c b/drivers/fpga/dfl-afu-main.c
index e955149..f0b45f2 100644
--- a/drivers/fpga/dfl-afu-main.c
+++ b/drivers/fpga/dfl-afu-main.c
@@ -274,17 +274,126 @@ static int port_get_id(struct platform_device *pdev)
 }
 static DEVICE_ATTR_RO(power_state);
 
+static ssize_t
+userclk_freqcmd_store(struct device *dev, struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+   struct dfl_feature_platform_data *pdata = dev_get_platdata(dev);
+   u64 userclk_freq_cmd;
+   void __iomem *base;
+
+   if (kstrtou64(buf, 0, &userclk_freq_cmd))
+   return -EINVAL;
+
+   base = dfl_get_feature_ioaddr_by_id(dev, PORT_FEATURE_ID_HEADER);
+
+   mutex_lock(&pdata->lock);
+   writeq(userclk_freq_cmd, base + PORT_HDR_USRCLK_CMD0);
+   mutex_unlock(&pdata->lock);
+
+   return count;
+}
+static DEVICE_ATTR_WO(userclk_freqcmd);
+
+static ssize_t
+userclk_freqcntrcmd_store(struct device *dev, struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+   struct dfl_feature_platform_data *pdata = dev_get_platdata(dev);
+   u64 userclk_freqcntr_cmd;
+   void __iomem *base;
+
+   if (kstrtou64(buf, 0, &userclk_freqcntr_cmd))
+   return -EINVAL;
+
+   base = dfl_get_feature_ioaddr_by_id(dev, PORT_FEATURE_ID_HEADER);
+
+   mutex_lock(&pdata->lock);
+   writeq(userclk_freqcntr_cmd, base + PORT_HDR_USRCLK_CMD1);
+   mutex_unlock(&pdata->lock);
+
+   return count;
+}
+static DEVICE_ATTR_WO(userclk_freqcntrcmd);
+
+static ssize_t
+userclk_freqsts_show(struct device *dev, struct device_attribute *attr,
+char *buf)
+{
+   struct dfl_feature_platform_data *pdata = dev_get_platdata(dev);
+   u64 userclk_freqsts;
+   void __iomem *base;
+
+   base = dfl_get_feature_ioaddr_by_id(dev, PORT_FEATURE_ID_HEADER);
+
+   mutex_lock(&pdata->lock);
+   userclk_freqsts = readq(base + PORT_HDR_USRCLK_STS0);
+   mutex_unlock(&pdata->lock);
+
+   return sprintf(buf, "0x%llx\n", (unsigned long long)userclk_freqsts);
+}
+static DEVICE_ATTR_RO(userclk_freqsts);
+
+static ssize_t
+userclk_freqcntrsts_show(struct device *dev, struct device_attribute *attr,
+char *buf)
+{
+   struct dfl_feature_platform_data *pdat

Re: [PATCH v3 2/2] hwmon: pmbus: Add Inspur Power System power supply driver

2019-08-11 Thread Guenter Roeck

On 8/11/19 7:53 PM, John Wang wrote:

Add the driver to monitor Inspur Power System power supplies
with hwmon over pmbus.

This driver adds sysfs attributes for additional power supply data,
including vendor, model, part_number, serial number,
firmware revision, hardware revision, and psu mode(active/standby).

Signed-off-by: John Wang 
---
v3:
 - Sort kconfig/makefile entries alphabetically
 - Remove unnecessary initialization
 - Use ATTRIBUTE_GROUPS instead of expanding directly
 - Use memscan to avoid reimplementation
v2:
 - Fix typos in commit message
 - Invert Christmas tree
 - Configure device with sysfs attrs, not debugfs entries
 - Fix errno in fw_version_read, ENODATA to EPROTO
 - Change the print format of fw-version
 - Use sysfs_streq instead of strcmp("xxx" "\n", "xxx")
 - Document sysfs attributes
---
  Documentation/hwmon/inspur-ipsps1.rst |  79 +
  drivers/hwmon/pmbus/Kconfig   |   9 +
  drivers/hwmon/pmbus/Makefile  |  41 ++---
  drivers/hwmon/pmbus/inspur-ipsps.c| 226 ++
  4 files changed, 335 insertions(+), 20 deletions(-)
  create mode 100644 Documentation/hwmon/inspur-ipsps1.rst
  create mode 100644 drivers/hwmon/pmbus/inspur-ipsps.c

diff --git a/Documentation/hwmon/inspur-ipsps1.rst 
b/Documentation/hwmon/inspur-ipsps1.rst
new file mode 100644
index ..aa19f0ccc8b0
--- /dev/null
+++ b/Documentation/hwmon/inspur-ipsps1.rst
@@ -0,0 +1,79 @@
+Kernel driver inspur-ipsps1
+===
+
+Supported chips:
+
+  * Inspur Power System power supply unit
+
+Author: John Wang 
+
+Description
+---
+
+This driver supports Inspur Power System power supplies. This driver
+is a client to the core PMBus driver.
+
+Usage Notes
+---
+
+This driver does not auto-detect devices. You will have to instantiate the
+devices explicitly. Please see Documentation/i2c/instantiating-devices for
+details.
+
+Sysfs entries
+-
+
+The following attributes are supported:
+
+=== ==
+curr1_input Measured input current
+curr1_label "iin"
+curr1_max   Maximum current
+curr1_max_alarm Current high alarm
+curr2_inputMeasured output current in mA.
+curr2_label"iout1"
+curr2_crit  Critical maximum current
+curr2_crit_alarmCurrent critical high alarm
+curr2_max   Maximum current
+curr2_max_alarm Current high alarm
+
+fan1_alarm Fan 1 warning.
+fan1_fault Fan 1 fault.
+fan1_input Fan 1 speed in RPM.
+
+in1_alarm  Input voltage under-voltage alarm.
+in1_input  Measured input voltage in mV.
+in1_label  "vin"
+in2_input  Measured output voltage in mV.
+in2_label  "vout1"
+in2_lcrit   Critical minimum output voltage
+in2_lcrit_alarm Output voltage critical low alarm
+in2_max Maximum output voltage
+in2_max_alarm   Output voltage high alarm
+in2_min Minimum output voltage
+in2_min_alarm   Output voltage low alarm
+
+power1_alarm   Input fault or alarm.
+power1_input   Measured input power in uW.
+power1_label   "pin"
+power1_max  Input power limit
+power2_max_alarm   Output power high alarm
+power2_max  Output power limit
+power2_input   Measured output power in uW.
+power2_label   "pout"
+
+temp[1-3]_inputMeasured temperature
+temp[1-2]_max  Maximum temperature
+temp[1-3]_max_alarmTemperature high alarm
+
+vendor  Manufacturer name
+model   Product model
+part_number Product part number
+serial_number   Product serial number
+fw_version  Firmware version
+hw_version  Hardware version
+modeWork mode. Can be set to active or
+standby, when set to standby, PSU will
+automatically switch between standby
+and redundancy mode.
+=== ==
diff --git a/drivers/hwmon/pmbus/Kconfig b/drivers/hwmon/pmbus/Kconfig
index 30751eb9550a..2370fce6e816 100644
--- a/drivers/hwmon/pmbus/Kconfig
+++ b/drivers/hwmon/pmbus/Kconfig
@@ -46,6 +46,15 @@ config SENSORS_IBM_CFFPS
  This driver can also be built as a module. If so, the module will
  be called ibm-cffps.
  
+config SENSORS_INSPUR_IPSPS

+   tristate "INSPUR Power System Power Supply"
+   help
+ If you say yes here you get hardware monitoring support for the INSPUR
+ Power System power supply.
+
+ This driver can also be built as a module. If so, the module will
+ be called inspur-ipsps.
+
  config SENSORS_IR35221
tristate "Inf

Re: [PATCH v3 2/2] hwmon: pmbus: Add Inspur Power System power supply driver

2019-08-11 Thread John Wang
On Mon, Aug 12, 2019 at 12:21 PM Guenter Roeck  wrote:
>
> On 8/11/19 7:53 PM, John Wang wrote:
> > Add the driver to monitor Inspur Power System power supplies
> > with hwmon over pmbus.
> >
> > This driver adds sysfs attributes for additional power supply data,
> > including vendor, model, part_number, serial number,
> > firmware revision, hardware revision, and psu mode(active/standby).
> >
> > Signed-off-by: John Wang 
> > ---
> > v3:
> >  - Sort kconfig/makefile entries alphabetically
> >  - Remove unnecessary initialization
> >  - Use ATTRIBUTE_GROUPS instead of expanding directly
> >  - Use memscan to avoid reimplementation
> > v2:
> >  - Fix typos in commit message
> >  - Invert Christmas tree
> >  - Configure device with sysfs attrs, not debugfs entries
> >  - Fix errno in fw_version_read, ENODATA to EPROTO
> >  - Change the print format of fw-version
> >  - Use sysfs_streq instead of strcmp("xxx" "\n", "xxx")
> >  - Document sysfs attributes
> > ---
> >   Documentation/hwmon/inspur-ipsps1.rst |  79 +
> >   drivers/hwmon/pmbus/Kconfig   |   9 +
> >   drivers/hwmon/pmbus/Makefile  |  41 ++---
> >   drivers/hwmon/pmbus/inspur-ipsps.c| 226 ++
> >   4 files changed, 335 insertions(+), 20 deletions(-)
> >   create mode 100644 Documentation/hwmon/inspur-ipsps1.rst
> >   create mode 100644 drivers/hwmon/pmbus/inspur-ipsps.c
> >
> > diff --git a/Documentation/hwmon/inspur-ipsps1.rst 
> > b/Documentation/hwmon/inspur-ipsps1.rst
> > new file mode 100644
> > index ..aa19f0ccc8b0
> > --- /dev/null
> > +++ b/Documentation/hwmon/inspur-ipsps1.rst
> > @@ -0,0 +1,79 @@
> > +Kernel driver inspur-ipsps1
> > +===
> > +
> > +Supported chips:
> > +
> > +  * Inspur Power System power supply unit
> > +
> > +Author: John Wang 
> > +
> > +Description
> > +---
> > +
> > +This driver supports Inspur Power System power supplies. This driver
> > +is a client to the core PMBus driver.
> > +
> > +Usage Notes
> > +---
> > +
> > +This driver does not auto-detect devices. You will have to instantiate the
> > +devices explicitly. Please see Documentation/i2c/instantiating-devices for
> > +details.
> > +
> > +Sysfs entries
> > +-
> > +
> > +The following attributes are supported:
> > +
> > +=== 
> > ==
> > +curr1_input Measured input current
> > +curr1_label "iin"
> > +curr1_max   Maximum current
> > +curr1_max_alarm Current high alarm
> > +curr2_input  Measured output current in mA.
> > +curr2_label  "iout1"
> > +curr2_crit  Critical maximum current
> > +curr2_crit_alarmCurrent critical high alarm
> > +curr2_max   Maximum current
> > +curr2_max_alarm Current high alarm
> > +
> > +fan1_alarm   Fan 1 warning.
> > +fan1_fault   Fan 1 fault.
> > +fan1_input   Fan 1 speed in RPM.
> > +
> > +in1_alarmInput voltage under-voltage alarm.
> > +in1_inputMeasured input voltage in mV.
> > +in1_label"vin"
> > +in2_inputMeasured output voltage in mV.
> > +in2_label"vout1"
> > +in2_lcrit   Critical minimum output voltage
> > +in2_lcrit_alarm Output voltage critical low alarm
> > +in2_max Maximum output voltage
> > +in2_max_alarm   Output voltage high alarm
> > +in2_min Minimum output voltage
> > +in2_min_alarm   Output voltage low alarm
> > +
> > +power1_alarm Input fault or alarm.
> > +power1_input Measured input power in uW.
> > +power1_label "pin"
> > +power1_max  Input power limit
> > +power2_max_alarm Output power high alarm
> > +power2_max  Output power limit
> > +power2_input Measured output power in uW.
> > +power2_label "pout"
> > +
> > +temp[1-3]_input  Measured temperature
> > +temp[1-2]_maxMaximum temperature
> > +temp[1-3]_max_alarm  Temperature high alarm
> > +
> > +vendor  Manufacturer name
> > +model   Product model
> > +part_number Product part number
> > +serial_number   Product serial number
> > +fw_version  Firmware version
> > +hw_version  Hardware version
> > +modeWork mode. Can be set to active or
> > +standby, when set to standby, PSU will
> > +automatically switch between standby
> > +and redundancy mode.
> > +=== 
> > ==
> > diff --git a/drivers/hwmon/pmbus/Kconfig b/drivers/hwmon/pmbus/Kconfig
> > index 30751eb9550a..2370fce6e816 100644
> > --- a/drivers/hwmon/pmbus/Kconfig
> > +++ b/drivers/hwmon/pmbus/Kconfig
> > @@ -4

Re: [PATCH 3/3] driver/core: Fix build error when SRCU and lockdep disabled

2019-08-11 Thread Greg Kroah-Hartman
On Sun, Aug 11, 2019 at 06:11:11PM -0400, Joel Fernandes (Google) wrote:
> Properly check if lockdep lock checking is disabled at config time. If
> so, then lock_is_held() is undefined so don't do any checking.
> 
> This fix is similar to the pattern used in srcu_read_lock_held().
> 
> Link: https://lore.kernel.org/lkml/201908080026.wsafx14k%25...@intel.com/
> Fixes: c9e4d3a2fee8 ("acpi: Use built-in RCU list checking for acpi_ioremaps 
> list")

What tree is this commit in?

> Reported-by: kbuild test robot 
> Signed-off-by: Joel Fernandes (Google) 
> ---
> This patch is based on the -rcu dev branch.

Ah...

>  drivers/base/core.c | 6 +-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index 32cf83d1c744..fe25cf690562 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -99,7 +99,11 @@ void device_links_read_unlock(int not_used)
>  
>  int device_links_read_lock_held(void)
>  {
> - return lock_is_held(&device_links_lock);
> +#ifdef CONFIG_DEBUG_LOCK_ALLOC
> + return lock_is_held(&(device_links_lock.dep_map));
> +#else
> + return 1;
> +#endif

return 1?  So the lock is always held?

confused,

greg k-h