Re: [PATCH v3 9/9] dt-bindings: serial: stm32: add phandle 'bluetooth' to fix dtbs_check warrning

2021-03-18 Thread dillon min
No changes, Just loop lkp in.


Hi lkp,

Sorry for the late reply, thanks for your report.
This patch is to fix the build warning message.

Thanks.
Regards

On Mon, Mar 15, 2021 at 5:45 PM  wrote:
>
> From: dillon min 
>
> when run make dtbs_check with 'bluetoothi brcm,bcm43438-bt'
> dts enabled on stm32h7, there is a warrning popup:
>
> >> arch/arm/boot/dts/stm32h750i-art-pi.dt.yaml: serial@40004800: 'bluetooth'
>does not match any of the regexes: 'pinctrl-[0-9]+'
>
> to make dtbs_check happy, so add a phandle bluetooth
>
> Fixes: 500cdb23d608 ("ARM: dts: stm32: Add STM32H743 MCU and STM32H743i-EVAL 
> board")
> Signed-off-by: dillon min 
> Reported-by: kernel test robot 
> ---
>  Documentation/devicetree/bindings/serial/st,stm32-uart.yaml | 5 +
>  1 file changed, 5 insertions(+)
>
> diff --git a/Documentation/devicetree/bindings/serial/st,stm32-uart.yaml 
> b/Documentation/devicetree/bindings/serial/st,stm32-uart.yaml
> index 8631678283f9..5e674840e62d 100644
> --- a/Documentation/devicetree/bindings/serial/st,stm32-uart.yaml
> +++ b/Documentation/devicetree/bindings/serial/st,stm32-uart.yaml
> @@ -50,6 +50,11 @@ properties:
>  minItems: 1
>  maxItems: 2
>
> +  bluetooth:
> +type: object
> +description: |
> +  phandles to the usart controller and bluetooth
> +
>  # cts-gpios and rts-gpios properties can be used instead of 'uart-has-rtscts'
>  # or 'st,hw-flow-ctrl' (deprecated) for making use of any gpio pins for flow
>  # control instead of dedicated pins.
> --
> 1.9.1
>


[PATCH net-next 3/4] net: ipa: introduce ipa_assert()

2021-03-18 Thread Alex Elder
Create a new macro ipa_assert() to verify that a condition is true.
This produces a build-time error if the condition can be evaluated
at build time; otherwise __ipa_assert_runtime() is called (described
below).

Another macro, ipa_assert_always() verifies that an expression
yields true at runtime, and if it does not, reports an error
message.

When IPA validation is enabled, __ipa_assert_runtime() becomes a
call to ipa_assert_always(), resulting in runtime verification of
the asserted condition.  Otherwise __ipa_assert_runtime() has no
effect, so such ipa_assert() calls are effectively ignored.

IPA assertion errors will be reported using the IPA device if
possible.

Signed-off-by: Alex Elder 
---
 drivers/net/ipa/ipa_assert.h | 50 
 1 file changed, 50 insertions(+)
 create mode 100644 drivers/net/ipa/ipa_assert.h

diff --git a/drivers/net/ipa/ipa_assert.h b/drivers/net/ipa/ipa_assert.h
new file mode 100644
index 0..7e5b9d487f69d
--- /dev/null
+++ b/drivers/net/ipa/ipa_assert.h
@@ -0,0 +1,50 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2021 Linaro Ltd.
+ */
+#ifndef _IPA_ASSERT_H_
+#define _IPA_ASSERT_H_
+
+#include 
+#include 
+#include 
+
+/* Verify the expression yields true, and fail at build time if possible */
+#define ipa_assert(dev, expr) \
+   do { \
+   if (__builtin_constant_p(expr)) \
+   compiletime_assert(expr, __ipa_failure_msg(expr)); \
+   else \
+   __ipa_assert_runtime(dev, expr); \
+   } while (0)
+
+/* Report an error if the given expression evaluates to false at runtime */
+#define ipa_assert_always(dev, expr) \
+   do { \
+   if (unlikely(!(expr))) { \
+   struct device *__dev = (dev); \
+   \
+   if (__dev) \
+   dev_err(__dev, __ipa_failure_msg(expr)); \
+   else  \
+   pr_err(__ipa_failure_msg(expr)); \
+   } \
+   } while (0)
+
+/* Constant message used when an assertion fails */
+#define __ipa_failure_msg(expr)"IPA assertion failed: " #expr "\n"
+
+#ifdef IPA_VALIDATION
+
+/* Only do runtime checks for "normal" assertions if validating the code */
+#define __ipa_assert_runtime(dev, expr)ipa_assert_always(dev, expr)
+
+#else /* !IPA_VALIDATION */
+
+/* "Normal" assertions aren't checked when validation is disabled */
+#define __ipa_assert_runtime(dev, expr)\
+   do { (void)(dev); (void)(expr); } while (0)
+
+#endif /* !IPA_VALIDATION */
+
+#endif /* _IPA_ASSERT_H_ */
-- 
2.27.0



[PATCH net-next 1/4] net: ipa: fix init header command validation

2021-03-18 Thread Alex Elder
We use ipa_cmd_header_valid() to ensure certain values we will
program into hardware are within range, well in advance of when we
actually program them.  This way we avoid having to check for errors
when we actually program the hardware.

Unfortunately the dev_err() call for a bad offset value does not
supply the arguments to match the format specifiers properly.
Fix this.

There was also supposed to be a check to ensure the size to be
programmed fits in the field that holds it.  Add this missing check.

Rearrange the way we ensure the header table fits in overall IPA
memory range.

Signed-off-by: Alex Elder 
---
 drivers/net/ipa/ipa_cmd.c | 49 +--
 1 file changed, 32 insertions(+), 17 deletions(-)

diff --git a/drivers/net/ipa/ipa_cmd.c b/drivers/net/ipa/ipa_cmd.c
index 35e35852c25c5..b40f031a905a7 100644
--- a/drivers/net/ipa/ipa_cmd.c
+++ b/drivers/net/ipa/ipa_cmd.c
@@ -175,21 +175,23 @@ bool ipa_cmd_table_valid(struct ipa *ipa, const struct 
ipa_mem *mem,
: field_max(IP_FLTRT_FLAGS_NHASH_ADDR_FMASK);
if (mem->offset > offset_max ||
ipa->mem_offset > offset_max - mem->offset) {
-   dev_err(dev, "IPv%c %s%s table region offset too large "
- "(0x%04x + 0x%04x > 0x%04x)\n",
- ipv6 ? '6' : '4', hashed ? "hashed " : "",
- route ? "route" : "filter",
- ipa->mem_offset, mem->offset, offset_max);
+   dev_err(dev, "IPv%c %s%s table region offset too large\n",
+   ipv6 ? '6' : '4', hashed ? "hashed " : "",
+   route ? "route" : "filter");
+   dev_err(dev, "(0x%04x + 0x%04x > 0x%04x)\n",
+   ipa->mem_offset, mem->offset, offset_max);
+
return false;
}
 
if (mem->offset > ipa->mem_size ||
mem->size > ipa->mem_size - mem->offset) {
-   dev_err(dev, "IPv%c %s%s table region out of range "
- "(0x%04x + 0x%04x > 0x%04x)\n",
- ipv6 ? '6' : '4', hashed ? "hashed " : "",
- route ? "route" : "filter",
- mem->offset, mem->size, ipa->mem_size);
+   dev_err(dev, "IPv%c %s%s table region out of range\n",
+   ipv6 ? '6' : '4', hashed ? "hashed " : "",
+   route ? "route" : "filter");
+   dev_err(dev, "(0x%04x + 0x%04x > 0x%04x)\n",
+   mem->offset, mem->size, ipa->mem_size);
+
return false;
}
 
@@ -205,22 +207,35 @@ static bool ipa_cmd_header_valid(struct ipa *ipa)
u32 size_max;
u32 size;
 
+   /* In ipa_cmd_hdr_init_local_add() we record the offset and size
+* of the header table memory area.  Make sure the offset and size
+* fit in the fields that need to hold them, and that the entire
+* range is within the overall IPA memory range.
+*/
offset_max = field_max(HDR_INIT_LOCAL_FLAGS_HDR_ADDR_FMASK);
if (mem->offset > offset_max ||
ipa->mem_offset > offset_max - mem->offset) {
-   dev_err(dev, "header table region offset too large "
- "(0x%04x + 0x%04x > 0x%04x)\n",
- ipa->mem_offset + mem->offset, offset_max);
+   dev_err(dev, "header table region offset too large\n");
+   dev_err(dev, "(0x%04x + 0x%04x > 0x%04x)\n",
+   ipa->mem_offset, mem->offset, offset_max);
+
return false;
}
 
size_max = field_max(HDR_INIT_LOCAL_FLAGS_TABLE_SIZE_FMASK);
size = ipa->mem[IPA_MEM_MODEM_HEADER].size;
size += ipa->mem[IPA_MEM_AP_HEADER].size;
-   if (mem->offset > ipa->mem_size || size > ipa->mem_size - mem->offset) {
-   dev_err(dev, "header table region out of range "
- "(0x%04x + 0x%04x > 0x%04x)\n",
- mem->offset, size, ipa->mem_size);
+   if (size > size_max) {
+   dev_err(dev, "header table region too large\n");
+   dev_err(dev, "(0x%04x > 0x%04x)\n", size, size_max);
+
+   return false;
+   }
+   if (size > ipa->mem_size || mem->offset > ipa->mem_size - size) {
+   dev_err(dev, "header table region out of range\n");
+   dev_err(dev, "(0x%04x + 0x%04x > 0x%04x)\n",
+   mem->offset, size, ipa->mem_size);
+
return false;
}
 
-- 
2.27.0



[PATCH net-next 4/4] net: ipa: activate some commented assertions

2021-03-18 Thread Alex Elder
Convert some commented assertion statements into real calls to
ipa_assert().  If the IPA device pointer is available, provide it,
otherwise pass NULL for that.

There are lots more places to convert, but this serves as an initial
verification of the new mechanism.  The assertions here implement
both runtime and build-time assertions, both with and without the
device pointer.

Signed-off-by: Alex Elder 
---
 drivers/net/ipa/ipa_reg.h   | 7 ---
 drivers/net/ipa/ipa_table.c | 5 -
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ipa/ipa_reg.h b/drivers/net/ipa/ipa_reg.h
index 732e691e9aa62..d0de85de9f08d 100644
--- a/drivers/net/ipa/ipa_reg.h
+++ b/drivers/net/ipa/ipa_reg.h
@@ -9,6 +9,7 @@
 #include 
 
 #include "ipa_version.h"
+#include "ipa_assert.h"
 
 struct ipa;
 
@@ -212,7 +213,7 @@ static inline u32 ipa_reg_bcr_val(enum ipa_version version)
BCR_HOLB_DROP_L2_IRQ_FMASK |
BCR_DUAL_TX_FMASK;
 
-   /* assert(version != IPA_VERSION_4_5); */
+   ipa_assert(NULL, version != IPA_VERSION_4_5);
 
return 0x;
 }
@@ -413,7 +414,7 @@ static inline u32 ipa_header_size_encoded(enum ipa_version 
version,
 
val = u32_encode_bits(size, HDR_LEN_FMASK);
if (version < IPA_VERSION_4_5) {
-   /* ipa_assert(header_size == size); */
+   ipa_assert(NULL, header_size == size);
return val;
}
 
@@ -433,7 +434,7 @@ static inline u32 ipa_metadata_offset_encoded(enum 
ipa_version version,
 
val = u32_encode_bits(off, HDR_OFST_METADATA_FMASK);
if (version < IPA_VERSION_4_5) {
-   /* ipa_assert(offset == off); */
+   ipa_assert(NULL, offset == off);
return val;
}
 
diff --git a/drivers/net/ipa/ipa_table.c b/drivers/net/ipa/ipa_table.c
index aa8b3ce7e21d9..7784b42fbaccc 100644
--- a/drivers/net/ipa/ipa_table.c
+++ b/drivers/net/ipa/ipa_table.c
@@ -23,6 +23,7 @@
 #include "ipa_cmd.h"
 #include "gsi.h"
 #include "gsi_trans.h"
+#include "ipa_assert.h"
 
 /**
  * DOC: IPA Filter and Route Tables
@@ -237,11 +238,13 @@ static void ipa_table_validate_build(void)
 static dma_addr_t ipa_table_addr(struct ipa *ipa, bool filter_mask, u16 count)
 {
u32 skip;
+   u32 max;
 
if (!count)
return 0;
 
-/* assert(count <= max_t(u32, IPA_FILTER_COUNT_MAX, IPA_ROUTE_COUNT_MAX)); */
+   max = max_t(u32, IPA_FILTER_COUNT_MAX, IPA_ROUTE_COUNT_MAX);
+   ipa_assert(&ipa->pdev->dev, max);
 
/* Skip over the zero rule and possibly the filter mask */
skip = filter_mask ? 1 : 2;
-- 
2.27.0



[PATCH net-next 0/4] net: ipa: fix validation

2021-03-18 Thread Alex Elder
There is sanity checking code in the IPA driver that's meant to be
enabled only during development.  This allows the driver to make
certain assumptions, but not have to verify those assumptions are
true at (operational) runtime.  This code is built conditional on
IPA_VALIDATION, set (if desired) inside the IPA makefile.

Unfortunately, this validation code has some errors.  First, there
are some mismatched arguments supplied to some dev_err() calls in
ipa_cmd_table_valid() and ipa_cmd_header_valid(), and these are
exposed if validation is enabled.  Second, the tag that enables
this conditional code isn't used consistently (it's IPA_VALIDATE
in some spots and IPA_VALIDATION in others).

This series fixes those two problems with the conditional validation
code.

In addition, this series introduces some new assertion macros.  I
have been meaning to add this for a long time.  There are comments
indicating places where assertions could be checked throughout the
code.

The macros are designed so that any asserted condition will be
checked at compile time if possible.  Otherwise, the condition
will be checked at runtime *only* if IPA_VALIDATION is enabled,
and ignored otherwise.

NOTE:  The third patch produces two bogus (but understandable)
warnings from checkpatch.pl.  It does not recognize that the "expr"
argument passed to those macros aren't actually evaluated more than
once.  In both cases, all but one reference is consumed by the
preprocessor or compiler.

A final patch converts a handful of commented assertions into
"real" ones.  Some existing validation code can done more simply
with assertions, so over time such cases will be converted.  For
now though, this series adds this assertion capability.

-Alex

Alex Elder (4):
  net: ipa: fix init header command validation
  net: ipa: fix IPA validation
  net: ipa: introduce ipa_assert()
  net: ipa: activate some commented assertions

 drivers/net/ipa/Makefile   |  2 +-
 drivers/net/ipa/gsi_trans.c|  8 ++---
 drivers/net/ipa/ipa_assert.h   | 50 
 drivers/net/ipa/ipa_cmd.c  | 53 ++
 drivers/net/ipa/ipa_cmd.h  |  6 ++--
 drivers/net/ipa/ipa_endpoint.c |  6 ++--
 drivers/net/ipa/ipa_main.c |  6 ++--
 drivers/net/ipa/ipa_mem.c  |  6 ++--
 drivers/net/ipa/ipa_reg.h  |  7 +++--
 drivers/net/ipa/ipa_table.c| 11 ---
 drivers/net/ipa/ipa_table.h|  6 ++--
 11 files changed, 115 insertions(+), 46 deletions(-)
 create mode 100644 drivers/net/ipa/ipa_assert.h

-- 
2.27.0



[PATCH net-next 2/4] net: ipa: fix IPA validation

2021-03-18 Thread Alex Elder
There are blocks of IPA code that sanity-check various values, at
compile time where possible.  Most of these checks can be done once
during development but skipped for normal operation.  These checks
permit the driver to make certain assumptions, thereby avoiding the
need for runtime error checking.

The checks are defined conditionally, but not consistently.  In
some cases IPA_VALIDATION enables the optional checks, while in
others IPA_VALIDATE is used.

Fix this by using IPA_VALIDATION consistently.

Signed-off-by: Alex Elder 
---
 drivers/net/ipa/Makefile   | 2 +-
 drivers/net/ipa/gsi_trans.c| 8 
 drivers/net/ipa/ipa_cmd.c  | 4 ++--
 drivers/net/ipa/ipa_cmd.h  | 6 +++---
 drivers/net/ipa/ipa_endpoint.c | 6 +++---
 drivers/net/ipa/ipa_main.c | 6 +++---
 drivers/net/ipa/ipa_mem.c  | 6 +++---
 drivers/net/ipa/ipa_table.c| 6 +++---
 drivers/net/ipa/ipa_table.h| 6 +++---
 9 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/drivers/net/ipa/Makefile b/drivers/net/ipa/Makefile
index afe5df1e6..014ae36ac6004 100644
--- a/drivers/net/ipa/Makefile
+++ b/drivers/net/ipa/Makefile
@@ -1,5 +1,5 @@
 # Un-comment the next line if you want to validate configuration data
-#ccflags-y +=  -DIPA_VALIDATE
+# ccflags-y+=  -DIPA_VALIDATION
 
 obj-$(CONFIG_QCOM_IPA) +=  ipa.o
 
diff --git a/drivers/net/ipa/gsi_trans.c b/drivers/net/ipa/gsi_trans.c
index 6c3ed5b17b80c..284063b39b33c 100644
--- a/drivers/net/ipa/gsi_trans.c
+++ b/drivers/net/ipa/gsi_trans.c
@@ -90,14 +90,14 @@ int gsi_trans_pool_init(struct gsi_trans_pool *pool, size_t 
size, u32 count,
 {
void *virt;
 
-#ifdef IPA_VALIDATE
+#ifdef IPA_VALIDATION
if (!size || size % 8)
return -EINVAL;
if (count < max_alloc)
return -EINVAL;
if (!max_alloc)
return -EINVAL;
-#endif /* IPA_VALIDATE */
+#endif /* IPA_VALIDATION */
 
/* By allocating a few extra entries in our pool (one less
 * than the maximum number that will be requested in a
@@ -140,14 +140,14 @@ int gsi_trans_pool_init_dma(struct device *dev, struct 
gsi_trans_pool *pool,
dma_addr_t addr;
void *virt;
 
-#ifdef IPA_VALIDATE
+#ifdef IPA_VALIDATION
if (!size || size % 8)
return -EINVAL;
if (count < max_alloc)
return -EINVAL;
if (!max_alloc)
return -EINVAL;
-#endif /* IPA_VALIDATE */
+#endif /* IPA_VALIDATION */
 
/* Don't let allocations cross a power-of-two boundary */
size = __roundup_pow_of_two(size);
diff --git a/drivers/net/ipa/ipa_cmd.c b/drivers/net/ipa/ipa_cmd.c
index b40f031a905a7..87e1ca2e27106 100644
--- a/drivers/net/ipa/ipa_cmd.c
+++ b/drivers/net/ipa/ipa_cmd.c
@@ -162,7 +162,7 @@ static void ipa_cmd_validate_build(void)
 #undef TABLE_SIZE
 }
 
-#ifdef IPA_VALIDATE
+#ifdef IPA_VALIDATION
 
 /* Validate a memory region holding a table */
 bool ipa_cmd_table_valid(struct ipa *ipa, const struct ipa_mem *mem,
@@ -316,7 +316,7 @@ bool ipa_cmd_data_valid(struct ipa *ipa)
return true;
 }
 
-#endif /* IPA_VALIDATE */
+#endif /* IPA_VALIDATION */
 
 int ipa_cmd_pool_init(struct gsi_channel *channel, u32 tre_max)
 {
diff --git a/drivers/net/ipa/ipa_cmd.h b/drivers/net/ipa/ipa_cmd.h
index 6dd3d35cf315d..429245f075122 100644
--- a/drivers/net/ipa/ipa_cmd.h
+++ b/drivers/net/ipa/ipa_cmd.h
@@ -50,7 +50,7 @@ struct ipa_cmd_info {
enum dma_data_direction direction;
 };
 
-#ifdef IPA_VALIDATE
+#ifdef IPA_VALIDATION
 
 /**
  * ipa_cmd_table_valid() - Validate a memory region holding a table
@@ -73,7 +73,7 @@ bool ipa_cmd_table_valid(struct ipa *ipa, const struct 
ipa_mem *mem,
  */
 bool ipa_cmd_data_valid(struct ipa *ipa);
 
-#else /* !IPA_VALIDATE */
+#else /* !IPA_VALIDATION */
 
 static inline bool ipa_cmd_table_valid(struct ipa *ipa,
   const struct ipa_mem *mem, bool route,
@@ -87,7 +87,7 @@ static inline bool ipa_cmd_data_valid(struct ipa *ipa)
return true;
 }
 
-#endif /* !IPA_VALIDATE */
+#endif /* !IPA_VALIDATION */
 
 /**
  * ipa_cmd_pool_init() - initialize command channel pools
diff --git a/drivers/net/ipa/ipa_endpoint.c b/drivers/net/ipa/ipa_endpoint.c
index 7209ee3c31244..1a4de4e9eafcd 100644
--- a/drivers/net/ipa/ipa_endpoint.c
+++ b/drivers/net/ipa/ipa_endpoint.c
@@ -75,7 +75,7 @@ struct ipa_status {
 #define IPA_STATUS_FLAGS1_RT_RULE_ID_FMASK GENMASK(31, 22)
 #define IPA_STATUS_FLAGS2_TAG_FMASKGENMASK_ULL(63, 16)
 
-#ifdef IPA_VALIDATE
+#ifdef IPA_VALIDATION
 
 static bool ipa_endpoint_data_valid_one(struct ipa *ipa, u32 count,
const struct ipa_gsi_endpoint_data *all_data,
@@ -225,7 +225,7 @@ static bool ipa_endpoint_data_valid(struct ipa *ipa, u32 
count,
return true;
 }
 
-#else /* !IPA_VALIDATE */
+#else /* !IPA_VALIDATION */
 
 static bool ipa_endpoint_data_valid(struct ipa *ipa, u32 count,

Re: [PATCH v2 5/6] PCI: fu740: Add SiFive FU740 PCIe host controller driver

2021-03-18 Thread Krzysztof Wilczyński
Hi,

[...]
> +static void fu740_phyregwrite(const uint8_t phy, const uint16_t addr,
> +   const uint16_t wrdata, struct fu740_pcie *afp)
> +{
> + struct device *dev = afp->pci.dev;
> + void __iomem *phy_cr_para_addr;
> + void __iomem *phy_cr_para_wr_data;
> + void __iomem *phy_cr_para_wr_en;
> + void __iomem *phy_cr_para_ack;
> + int ret, val;
> +
> + /* Setup */
> + if (phy) {
> + phy_cr_para_addr = afp->mgmt_base + 
> PCIEX8MGMT_PHY1_CR_PARA_ADDR;
> + phy_cr_para_wr_data = afp->mgmt_base + 
> PCIEX8MGMT_PHY1_CR_PARA_WR_DATA;
> + phy_cr_para_wr_en = afp->mgmt_base + 
> PCIEX8MGMT_PHY1_CR_PARA_WR_EN;
> + phy_cr_para_ack = afp->mgmt_base + PCIEX8MGMT_PHY1_CR_PARA_ACK;
> + } else {
> + phy_cr_para_addr = afp->mgmt_base + 
> PCIEX8MGMT_PHY0_CR_PARA_ADDR;
> + phy_cr_para_wr_data = afp->mgmt_base + 
> PCIEX8MGMT_PHY0_CR_PARA_WR_DATA;
> + phy_cr_para_wr_en = afp->mgmt_base + 
> PCIEX8MGMT_PHY0_CR_PARA_WR_EN;
> + phy_cr_para_ack = afp->mgmt_base + PCIEX8MGMT_PHY0_CR_PARA_ACK;
> + }
> +
> + writel_relaxed(addr, phy_cr_para_addr);
> + writel_relaxed(wrdata, phy_cr_para_wr_data);
> + writel_relaxed(1, phy_cr_para_wr_en);
> +
> + /* Wait for wait_idle */
> + ret = readl_poll_timeout(phy_cr_para_ack, val, val, 10, 5000);
> + if (ret)
> + dev_err(dev, "Wait for wait_ilde state failed!\n");

It would be "wait_idle" rather than "wait_idle".

[...]
> + /* Wait for ~wait_idle */
> + ret = readl_poll_timeout(phy_cr_para_ack, val, !val, 10, 5000);
> + if (ret)
> + dev_err(dev, "Wait for !wait_ilde state failed!\n");
[...]

Same as above, it would be "wait_idle" in the above.

> +static void fu740_pcie_ltssm_enable(struct device *dev)
> +{
> + struct fu740_pcie *afp = dev_get_drvdata(dev);
> +
> + /* Enable LTSSM */
> + writel_relaxed(0x1, afp->mgmt_base + PCIEX8MGMT_APP_LTSSM_ENABLE);
> +}
> +
> +static int fu740_pcie_start_link(struct dw_pcie *pci)
> +{
> + struct device *dev = pci->dev;
> +
> + /* Start LTSSM. */

Nitpick.  No need for a dot in this comment to keep it consistent with
the comment in the function above this one.

> +static int fu740_pcie_host_init(struct pcie_port *pp)
> +{
> + struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
> + struct fu740_pcie *afp = to_fu740_pcie(pci);
> + struct device *dev = pci->dev;
> + int ret;
> +
> + /* Power on reset */
> + fu740_pcie_drive_perstn(afp);
> +
> + /* Enable pcieauxclk */
> + ret = clk_prepare_enable(afp->pcie_aux);
> + if (ret)
> + dev_err(dev, "unable to enable pcie_aux clock\n");
> +
> + /*
> +  * Assert hold_phy_rst (hold the controller LTSSM in reset after
> +  * power_up_rst_n for register programming with cr_para)
> +  */
> + writel_relaxed(0x1, afp->mgmt_base + PCIEX8MGMT_APP_HOLD_PHY_RST);
> +
> + /* Deassert power_up_rst_n */
> + ret = reset_control_deassert(afp->rst);
> + if (ret)
> + dev_err(dev, "unable to deassert pcie_power_up_rst_n\n");
> +
> + fu740_pcie_init_phy(afp);
> +
> + /* Disable pcieauxclk */
> + clk_disable_unprepare(afp->pcie_aux);
> + /* Clear hold_phy_rst */
> + writel_relaxed(0x0, afp->mgmt_base + PCIEX8MGMT_APP_HOLD_PHY_RST);
> + /* Enable pcieauxclk */
> + ret = clk_prepare_enable(afp->pcie_aux);
> + /* Set RC mode */
> + writel_relaxed(0x4, afp->mgmt_base + PCIEX8MGMT_DEVICE_TYPE);
> +
> + return 0;
> +}
[...]

It seems that the error handling is somewhat broken in the above
function, especially when you look at how the "ret" variables does not
seem to be used for anything once there was an error.

Krzysztof


[PATCH] drm: i915: Fix a typo

2021-03-18 Thread Bhaskar Chowdhury


s/nothign/nothing/

Signed-off-by: Bhaskar Chowdhury 
---
 drivers/gpu/drm/i915/display/intel_dpll_mgr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/display/intel_dpll_mgr.c 
b/drivers/gpu/drm/i915/display/intel_dpll_mgr.c
index f6ad257a260e..14d784a6fae5 100644
--- a/drivers/gpu/drm/i915/display/intel_dpll_mgr.c
+++ b/drivers/gpu/drm/i915/display/intel_dpll_mgr.c
@@ -4185,7 +4185,7 @@ static void icl_pll_disable(struct drm_i915_private 
*dev_priv,
/*
 * DVFS pre sequence would be here, but in our driver the cdclk code
 * paths should already be setting the appropriate voltage, hence we do
-* nothign here.
+* nothing here.
 */

val = intel_de_read(dev_priv, enable_reg);
--
2.26.2



RE: [PATCH 02/11] i2c: imx-lpi2c: add runtime pm support

2021-03-18 Thread Aisheng Dong
> From: Clark Wang 
> Sent: Wednesday, March 17, 2021 2:54 PM
> Subject: [PATCH 02/11] i2c: imx-lpi2c: add runtime pm support
> 
> - Add runtime pm support to dynamicly manage the clock.
> - Put the suspend to suspend_noirq.
> - Call .pm_runtime_force_suspend() to force runtime pm suspended
>   in .suspend_noirq().
> 

The patch title needs to be improved as the driver already supports rpm.
And do one thing in one patch.

> Signed-off-by: Fugang Duan 
> Signed-off-by: Gao Pan 
> Reviewed-by: Anson Huang 

Please add your sign-off.

> ---
>  drivers/i2c/busses/i2c-imx-lpi2c.c | 50 --
>  1 file changed, 33 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-imx-lpi2c.c
> b/drivers/i2c/busses/i2c-imx-lpi2c.c
> index bbf44ac95021..1e920e7ac7c1 100644
> --- a/drivers/i2c/busses/i2c-imx-lpi2c.c
> +++ b/drivers/i2c/busses/i2c-imx-lpi2c.c
> @@ -574,7 +574,8 @@ static int lpi2c_imx_probe(struct platform_device
> *pdev)
>   if (ret)
>   lpi2c_imx->bitrate = I2C_MAX_STANDARD_MODE_FREQ;
> 
> - ret = devm_request_irq(&pdev->dev, irq, lpi2c_imx_isr, 0,
> + ret = devm_request_irq(&pdev->dev, irq, lpi2c_imx_isr,
> +IRQF_NO_SUSPEND,

This belongs to a separate patch

>  pdev->name, lpi2c_imx);
>   if (ret) {
>   dev_err(&pdev->dev, "can't claim irq %d\n", irq); @@ -584,35
> +585,32 @@ static int lpi2c_imx_probe(struct platform_device *pdev)
>   i2c_set_adapdata(&lpi2c_imx->adapter, lpi2c_imx);
>   platform_set_drvdata(pdev, lpi2c_imx);
> 
> - ret = clk_prepare_enable(lpi2c_imx->clk);
> - if (ret) {
> - dev_err(&pdev->dev, "clk enable failed %d\n", ret);
> - return ret;
> - }
> -
>   pm_runtime_set_autosuspend_delay(&pdev->dev, I2C_PM_TIMEOUT);
>   pm_runtime_use_autosuspend(&pdev->dev);
> - pm_runtime_get_noresume(&pdev->dev);
> - pm_runtime_set_active(&pdev->dev);
>   pm_runtime_enable(&pdev->dev);
> 
> + ret = pm_runtime_get_sync(&pdev->dev);
> + if (ret < 0) {
> + pm_runtime_put_noidle(&pdev->dev);
> + dev_err(&pdev->dev, "failed to enable clock\n");
> + return ret;
> + }

Can't current clk control via rpm work well?
Please describe why need change.

> +
>   temp = readl(lpi2c_imx->base + LPI2C_PARAM);
>   lpi2c_imx->txfifosize = 1 << (temp & 0x0f);
>   lpi2c_imx->rxfifosize = 1 << ((temp >> 8) & 0x0f);
> 
> + pm_runtime_put(&pdev->dev);
> +
>   ret = i2c_add_adapter(&lpi2c_imx->adapter);
>   if (ret)
>   goto rpm_disable;
> 
> - pm_runtime_mark_last_busy(&pdev->dev);
> - pm_runtime_put_autosuspend(&pdev->dev);
> -
>   dev_info(&lpi2c_imx->adapter.dev, "LPI2C adapter registered\n");
> 
>   return 0;
> 
>  rpm_disable:
> - pm_runtime_put(&pdev->dev);
>   pm_runtime_disable(&pdev->dev);
>   pm_runtime_dont_use_autosuspend(&pdev->dev);
> 
> @@ -636,7 +634,7 @@ static int __maybe_unused
> lpi2c_runtime_suspend(struct device *dev)
>   struct lpi2c_imx_struct *lpi2c_imx = dev_get_drvdata(dev);
> 
>   clk_disable_unprepare(lpi2c_imx->clk);
> - pinctrl_pm_select_sleep_state(dev);
> + pinctrl_pm_select_idle_state(dev);

This belongs to a separate patch

> 
>   return 0;
>  }
> @@ -649,16 +647,34 @@ static int __maybe_unused
> lpi2c_runtime_resume(struct device *dev)
>   pinctrl_pm_select_default_state(dev);
>   ret = clk_prepare_enable(lpi2c_imx->clk);
>   if (ret) {
> - dev_err(dev, "failed to enable I2C clock, ret=%d\n", ret);
> + dev_err(dev, "can't enable I2C clock, ret=%d\n", ret);

Probably unnecessary change

>   return ret;
>   }
> 
> + return ret;
> +}
> +
> +static int lpi2c_suspend_noirq(struct device *dev) {
> + int ret;
> +
> + ret = pm_runtime_force_suspend(dev);
> + if (ret)
> + return ret;
> +
> + pinctrl_pm_select_sleep_state(dev);
> +
>   return 0;
>  }
> 
> +static int lpi2c_resume_noirq(struct device *dev) {
> + return pm_runtime_force_resume(dev);
> +}
> +
>  static const struct dev_pm_ops lpi2c_pm_ops = {
> - SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
> -   pm_runtime_force_resume)
> + SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(lpi2c_suspend_noirq,
> +  lpi2c_resume_noirq)

Belongs to separate change and explain why need do this

>   SET_RUNTIME_PM_OPS(lpi2c_runtime_suspend,
>  lpi2c_runtime_resume, NULL)
>  };
> --
> 2.25.1



Re: [PATCH v2 5/6] PCI: fu740: Add SiFive FU740 PCIe host controller driver

2021-03-18 Thread Krzysztof Wilczyński
Hi,

[...]
> > +   /* Wait for wait_idle */
> > +   ret = readl_poll_timeout(phy_cr_para_ack, val, val, 10, 5000);
> > +   if (ret)
> > +   dev_err(dev, "Wait for wait_ilde state failed!\n");
> 
> It would be "wait_idle" rather than "wait_idle".
[...]

Apologies, meant to say "wait_ilde" in the "rather than" part, but went
ahead and somehow used the correct spelling. :)

Krzysztof


Re: [PATCH] cifsd: Fix a use after free on error path

2021-03-18 Thread Sergey Senozhatsky
On (21/03/18 16:12), Dan Carpenter wrote:
> The ksmbd_free_work_struct() frees "work" so we need to swap the order
> of these two function calls to avoid a use after free.
> 
> Fixes: cabcebc31de4 ("cifsd: introduce SMB3 kernel server")
> Signed-off-by: Dan Carpenter 

Thanks.

Reviewed-by: Sergey Senozhatsky 

-ss


Re: [PATCH RESEND] cifsd: fix a IS_ERR() vs NULL bug

2021-03-18 Thread Sergey Senozhatsky
On (21/03/18 16:11), Dan Carpenter wrote:
> 
> The smb_direct_alloc_sendmsg() function never returns NULL, it only
> returns error pointers so the check needs to be updated.
> 
> Fixes: cabcebc31de4 ("cifsd: introduce SMB3 kernel server")
> Signed-off-by: Dan Carpenter 

Thanks.

Reviewed-by: Sergey Senozhatsky 

-ss


Re: [PATCH] cifsd: fix a precedence bug in parse_dacl()

2021-03-18 Thread Sergey Senozhatsky
On (21/03/18 16:10), Dan Carpenter wrote:
> 
> The shift has higher precedence than mask so this doesn't work as
> intended.
> 
> Fixes: ef24dca82789 ("cifsd: add support for ACLs")
> Signed-off-by: Dan Carpenter 

Thanks.

Reviewed-by: Sergey Senozhatsky 

-ss


Re: [PATCH] PCI: keystone: Let AM65 use the pci_ops defined in pcie-designware-host.c

2021-03-18 Thread Krzysztof Wilczyński
Hi Kishon,

Thank you for the fix!

[...]
> @@ -798,7 +798,8 @@ static int __init ks_pcie_host_init(struct pcie_port *pp)
>   int ret;
>  
>   pp->bridge->ops = &ks_pcie_ops;
> - pp->bridge->child_ops = &ks_child_pcie_ops;
> + if (!ks_pcie->is_am6)
> + pp->bridge->child_ops = &ks_child_pcie_ops;
>  
>   ret = ks_pcie_config_legacy_irq(ks_pcie);
>   if (ret)
[...]

Reviewed-by: Krzysztof Wilczyński 

Krzysztof


RE: [PATCH 03/11] i2c: imx-lpi2c: add ipg clk for lpi2c driver

2021-03-18 Thread Aisheng Dong
> From: Clark Wang 
> Sent: Wednesday, March 17, 2021 2:54 PM
> 
> The lpi2c IP needs two clks: ipg clk and per clk. The old lpi2c driver missed 
> ipg
> clk. This patch adds ipg clk for lpi2c driver.
> 

Pleas also update dt-binding and sent along with this patchset.(before this one)

> Signed-off-by: Gao Pan 
> Signed-off-by: Clark Wang 
> Acked-by: Fugang Duan 

You can drop the Ack tag if the patch was changed 

> ---
>  drivers/i2c/busses/i2c-imx-lpi2c.c | 28 +---
>  1 file changed, 21 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-imx-lpi2c.c
> b/drivers/i2c/busses/i2c-imx-lpi2c.c
> index 1e920e7ac7c1..664fcc0dba51 100644
> --- a/drivers/i2c/busses/i2c-imx-lpi2c.c
> +++ b/drivers/i2c/busses/i2c-imx-lpi2c.c
> @@ -94,7 +94,8 @@ enum lpi2c_imx_pincfg {
> 
>  struct lpi2c_imx_struct {
>   struct i2c_adapter  adapter;
> - struct clk  *clk;
> + struct clk  *clk_per;
> + struct clk  *clk_ipg;
>   void __iomem*base;
>   __u8*rx_buf;
>   __u8*tx_buf;
> @@ -563,10 +564,16 @@ static int lpi2c_imx_probe(struct platform_device
> *pdev)
>   strlcpy(lpi2c_imx->adapter.name, pdev->name,
>   sizeof(lpi2c_imx->adapter.name));
> 
> - lpi2c_imx->clk = devm_clk_get(&pdev->dev, NULL);
> - if (IS_ERR(lpi2c_imx->clk)) {
> + lpi2c_imx->clk_per = devm_clk_get(&pdev->dev, "per");
> + if (IS_ERR(lpi2c_imx->clk_per)) {
>   dev_err(&pdev->dev, "can't get I2C peripheral clock\n");
> - return PTR_ERR(lpi2c_imx->clk);
> + return PTR_ERR(lpi2c_imx->clk_per);
> + }
> +
> + lpi2c_imx->clk_ipg = devm_clk_get(&pdev->dev, "ipg");
> + if (IS_ERR(lpi2c_imx->clk_ipg)) {
> + dev_err(&pdev->dev, "can't get I2C ipg clock\n");
> + return PTR_ERR(lpi2c_imx->clk_ipg);
>   }

Will this break exist dts?

Regards
Aisheng

> 
>   ret = of_property_read_u32(pdev->dev.of_node,
> @@ -633,7 +640,8 @@ static int __maybe_unused
> lpi2c_runtime_suspend(struct device *dev)  {
>   struct lpi2c_imx_struct *lpi2c_imx = dev_get_drvdata(dev);
> 
> - clk_disable_unprepare(lpi2c_imx->clk);
> + clk_disable_unprepare(lpi2c_imx->clk_ipg);
> + clk_disable_unprepare(lpi2c_imx->clk_per);
>   pinctrl_pm_select_idle_state(dev);
> 
>   return 0;
> @@ -645,12 +653,18 @@ static int __maybe_unused
> lpi2c_runtime_resume(struct device *dev)
>   int ret;
> 
>   pinctrl_pm_select_default_state(dev);
> - ret = clk_prepare_enable(lpi2c_imx->clk);
> + ret = clk_prepare_enable(lpi2c_imx->clk_per);
>   if (ret) {
> - dev_err(dev, "can't enable I2C clock, ret=%d\n", ret);
> + dev_err(dev, "can't enable I2C per clock, ret=%d\n", ret);
>   return ret;
>   }
> 
> + ret = clk_prepare_enable(lpi2c_imx->clk_ipg);
> + if (ret) {
> + clk_disable_unprepare(lpi2c_imx->clk_per);
> + dev_err(dev, "can't enable I2C ipg clock, ret=%d\n", ret);
> + }
> +
>   return ret;
>  }
> 
> --
> 2.25.1



[PATCH] sch_red: Fix a typo

2021-03-18 Thread Bhaskar Chowdhury


s/recalcultion/recalculation/

Signed-off-by: Bhaskar Chowdhury 
---
 include/net/red.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/net/red.h b/include/net/red.h
index 932f0d79d60c..6b418b69dc48 100644
--- a/include/net/red.h
+++ b/include/net/red.h
@@ -287,7 +287,7 @@ static inline unsigned long 
red_calc_qavg_from_idle_time(const struct red_parms
int  shift;

/*
-* The problem: ideally, average length queue recalcultion should
+* The problem: ideally, average length queue recalculation should
 * be done over constant clock intervals. This is too expensive, so
 * that the calculation is driven by outgoing packets.
 * When the queue is idle we have to model this clock by hand.
--
2.26.2



RE: [PATCH 04/11] i2c: imx-lpi2c: manage irq resource request/release in runtime pm

2021-03-18 Thread Aisheng Dong
> From: Clark Wang 
> Sent: Wednesday, March 17, 2021 2:54 PM
> 
> Manage irq resource request/release in runtime pm to save irq domain's
> power.
> 
> Signed-off-by: Frank Li 
> Signed-off-by: Fugang Duan 
> Reviewed-by: Frank Li 
> ---
>  drivers/i2c/busses/i2c-imx-lpi2c.c | 26 ++
>  1 file changed, 14 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-imx-lpi2c.c
> b/drivers/i2c/busses/i2c-imx-lpi2c.c
> index 664fcc0dba51..e718bb6b2387 100644
> --- a/drivers/i2c/busses/i2c-imx-lpi2c.c
> +++ b/drivers/i2c/busses/i2c-imx-lpi2c.c
> @@ -94,6 +94,7 @@ enum lpi2c_imx_pincfg {
> 
>  struct lpi2c_imx_struct {
>   struct i2c_adapter  adapter;
> + int irq;
>   struct clk  *clk_per;
>   struct clk  *clk_ipg;
>   void __iomem*base;
> @@ -543,7 +544,7 @@ static int lpi2c_imx_probe(struct platform_device
> *pdev)  {
>   struct lpi2c_imx_struct *lpi2c_imx;
>   unsigned int temp;
> - int irq, ret;
> + int ret;
> 
>   lpi2c_imx = devm_kzalloc(&pdev->dev, sizeof(*lpi2c_imx), GFP_KERNEL);
>   if (!lpi2c_imx)
> @@ -553,9 +554,9 @@ static int lpi2c_imx_probe(struct platform_device
> *pdev)
>   if (IS_ERR(lpi2c_imx->base))
>   return PTR_ERR(lpi2c_imx->base);
> 
> - irq = platform_get_irq(pdev, 0);
> - if (irq < 0)
> - return irq;
> + lpi2c_imx->irq = platform_get_irq(pdev, 0);
> + if (lpi2c_imx->irq < 0)
> + return lpi2c_imx->irq;
> 
>   lpi2c_imx->adapter.owner= THIS_MODULE;
>   lpi2c_imx->adapter.algo = &lpi2c_imx_algo;
> @@ -581,14 +582,6 @@ static int lpi2c_imx_probe(struct platform_device
> *pdev)
>   if (ret)
>   lpi2c_imx->bitrate = I2C_MAX_STANDARD_MODE_FREQ;
> 
> - ret = devm_request_irq(&pdev->dev, irq, lpi2c_imx_isr,
> -IRQF_NO_SUSPEND,
> -pdev->name, lpi2c_imx);
> - if (ret) {
> - dev_err(&pdev->dev, "can't claim irq %d\n", irq);
> - return ret;
> - }
> -
>   i2c_set_adapdata(&lpi2c_imx->adapter, lpi2c_imx);
>   platform_set_drvdata(pdev, lpi2c_imx);
> 
> @@ -640,6 +633,7 @@ static int __maybe_unused
> lpi2c_runtime_suspend(struct device *dev)  {
>   struct lpi2c_imx_struct *lpi2c_imx = dev_get_drvdata(dev);
> 
> + devm_free_irq(dev, lpi2c_imx->irq, lpi2c_imx);
>   clk_disable_unprepare(lpi2c_imx->clk_ipg);
>   clk_disable_unprepare(lpi2c_imx->clk_per);
>   pinctrl_pm_select_idle_state(dev);
> @@ -665,6 +659,14 @@ static int __maybe_unused
> lpi2c_runtime_resume(struct device *dev)
>   dev_err(dev, "can't enable I2C ipg clock, ret=%d\n", ret);
>   }
> 
> + ret = devm_request_irq(dev, lpi2c_imx->irq, lpi2c_imx_isr,

I guess unnecessary to use devm in rpm

> +IRQF_NO_SUSPEND,
> +dev_name(dev), lpi2c_imx);
> + if (ret) {
> + dev_err(dev, "can't claim irq %d\n", lpi2c_imx->irq);
> + return ret;
> + }
> +
>   return ret;
>  }
> 
> --
> 2.25.1



Re: [PATCH net-next 3/4] net: ipa: introduce ipa_assert()

2021-03-18 Thread Leon Romanovsky
On Thu, Mar 18, 2021 at 11:29:22PM -0500, Alex Elder wrote:
> Create a new macro ipa_assert() to verify that a condition is true.
> This produces a build-time error if the condition can be evaluated
> at build time; otherwise __ipa_assert_runtime() is called (described
> below).
> 
> Another macro, ipa_assert_always() verifies that an expression
> yields true at runtime, and if it does not, reports an error
> message.
> 
> When IPA validation is enabled, __ipa_assert_runtime() becomes a
> call to ipa_assert_always(), resulting in runtime verification of
> the asserted condition.  Otherwise __ipa_assert_runtime() has no
> effect, so such ipa_assert() calls are effectively ignored.
> 
> IPA assertion errors will be reported using the IPA device if
> possible.
> 
> Signed-off-by: Alex Elder 
> ---
>  drivers/net/ipa/ipa_assert.h | 50 
>  1 file changed, 50 insertions(+)
>  create mode 100644 drivers/net/ipa/ipa_assert.h
> 
> diff --git a/drivers/net/ipa/ipa_assert.h b/drivers/net/ipa/ipa_assert.h
> new file mode 100644
> index 0..7e5b9d487f69d
> --- /dev/null
> +++ b/drivers/net/ipa/ipa_assert.h
> @@ -0,0 +1,50 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/*
> + * Copyright (C) 2021 Linaro Ltd.
> + */
> +#ifndef _IPA_ASSERT_H_
> +#define _IPA_ASSERT_H_
> +
> +#include 
> +#include 
> +#include 
> +
> +/* Verify the expression yields true, and fail at build time if possible */
> +#define ipa_assert(dev, expr) \
> + do { \
> + if (__builtin_constant_p(expr)) \
> + compiletime_assert(expr, __ipa_failure_msg(expr)); \
> + else \
> + __ipa_assert_runtime(dev, expr); \
> + } while (0)
> +
> +/* Report an error if the given expression evaluates to false at runtime */
> +#define ipa_assert_always(dev, expr) \
> + do { \
> + if (unlikely(!(expr))) { \
> + struct device *__dev = (dev); \
> + \
> + if (__dev) \
> + dev_err(__dev, __ipa_failure_msg(expr)); \
> + else  \
> + pr_err(__ipa_failure_msg(expr)); \
> + } \
> + } while (0)

It will be much better for everyone if you don't obfuscate existing
kernel primitives and don't hide constant vs. dynamic expressions.

So any random kernel developer will be able to change the code without
investing too much time to understand this custom logic.

And constant expressions are checked with BUILD_BUG_ON().

If you still feel need to provide assertion like this, it should be done
in general code.

Thanks

> +
> +/* Constant message used when an assertion fails */
> +#define __ipa_failure_msg(expr)  "IPA assertion failed: " #expr "\n"
> +
> +#ifdef IPA_VALIDATION
> +
> +/* Only do runtime checks for "normal" assertions if validating the code */
> +#define __ipa_assert_runtime(dev, expr)  ipa_assert_always(dev, expr)
> +
> +#else /* !IPA_VALIDATION */
> +
> +/* "Normal" assertions aren't checked when validation is disabled */
> +#define __ipa_assert_runtime(dev, expr)  \
> + do { (void)(dev); (void)(expr); } while (0)
> +
> +#endif /* !IPA_VALIDATION */
> +
> +#endif /* _IPA_ASSERT_H_ */
> -- 
> 2.27.0
> 


[PATCH] microblaze: Fix a typo

2021-03-18 Thread Bhaskar Chowdhury


s/storign/storing/

Signed-off-by: Bhaskar Chowdhury 
---
 arch/microblaze/lib/uaccess_old.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/microblaze/lib/uaccess_old.S 
b/arch/microblaze/lib/uaccess_old.S
index 0e8cc2710c27..eca290090038 100644
--- a/arch/microblaze/lib/uaccess_old.S
+++ b/arch/microblaze/lib/uaccess_old.S
@@ -188,7 +188,7 @@ w2: sw  r4, r5, r3
.text

 .align 4 /* Alignment is important to keep icache happy */
-page:  /* Create room on stack and save registers for storign values */
+page:  /* Create room on stack and save registers for storing values */
addik   r1, r1, -40
swi r5, r1, 0
swi r6, r1, 4
--
2.26.2



RE: [PATCH 05/11] i2c: imx-lpi2c: add debug message when i2c peripheral clk doesn't work

2021-03-18 Thread Aisheng Dong
> From: Clark Wang 
> Sent: Wednesday, March 17, 2021 2:54 PM
> 
> add debug message when i2c peripheral clk rate is 0, then directly return
> -EINVAL.
> 
> Signed-off-by: Gao Pan 
> Reviewed-by: Andy Duan 

Drop old review when patch is changed

> ---
>  drivers/i2c/busses/i2c-imx-lpi2c.c | 7 ++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/i2c/busses/i2c-imx-lpi2c.c
> b/drivers/i2c/busses/i2c-imx-lpi2c.c
> index e718bb6b2387..8f9dd3dd2951 100644
> --- a/drivers/i2c/busses/i2c-imx-lpi2c.c
> +++ b/drivers/i2c/busses/i2c-imx-lpi2c.c
> @@ -209,7 +209,12 @@ static int lpi2c_imx_config(struct lpi2c_imx_struct
> *lpi2c_imx)
> 
>   lpi2c_imx_set_mode(lpi2c_imx);
> 
> - clk_rate = clk_get_rate(lpi2c_imx->clk);

I guess the kernel can't compile right before this patch because lpi2c_imx->clk 
was
Removed In former patch
You need double check not break bisect

> + clk_rate = clk_get_rate(lpi2c_imx->clk_per);
> + if (!clk_rate) {
> + dev_dbg(&lpi2c_imx->adapter.dev, "clk_per rate is 0\n");

s/dev_dbg/dev_err

> + return -EINVAL;
> + }
> +
>   if (lpi2c_imx->mode == HS || lpi2c_imx->mode == ULTRA_FAST)
>   filt = 0;
>   else
> --
> 2.25.1



Re: [PATCH v2] perf stat: Align CSV output for summary mode

2021-03-18 Thread Jin, Yao

Hi Arnaldo,

On 3/18/2021 9:15 PM, Arnaldo Carvalho de Melo wrote:

Em Wed, Mar 17, 2021 at 02:51:42PM -0700, Andi Kleen escreveu:

If you care about not breaking existing scripts, then the output they
get with what they use as command line options must continue to produce
the same output.


It's not clear there are any useful ones (except for tools that handle
both). It's really hard to parse the previous mess. It's simply not
valid CSV.

That's why I'm arguing that keeping compatibility is not useful here.

We would be stuck with the broken mess as default forever.


Fair enough, lets fix the default then. Jin, can you please consider
adding a 'perf test' shell entry to parse the CSV mode with/without that
summary? This way we'll notice when the new normal gets broken.

- Arnaldo



Thanks Arnaldo! I will post v3 with the perf test script.

Thanks
Jin Yao



[PATCH v2] hwmon: add driver for NZXT Kraken X42/X52/X62/X72

2021-03-18 Thread Jonas Malaco
These are "all-in-one" CPU liquid coolers that can be monitored and
controlled through a proprietary USB HID protocol.

While the models have differently sized radiators and come with varying
numbers of fans, they are all indistinguishable at the software level.

The driver exposes fan/pump speeds and coolant temperature through the
standard hwmon sysfs interface.

Fan and pump control, while supported by the devices, are not currently
exposed.  The firmware accepts up to 61 trip points per channel
(fan/pump), but the same set of trip temperatures has to be maintained
for both; with pwmX_auto_point_Y_temp attributes, users would need to
maintain this invariant themselves.

Instead, fan and pump control, as well as LED control (which the device
also supports for 9 addressable RGB LEDs on the CPU water block) are
left for existing and already mature user-space tools, which can still
be used alongside the driver, thanks to hidraw.  A link to one, which I
also maintain, is provided in the documentation.

The implementation is based on USB traffic analysis.  It has been
runtime tested on x86_64, both as a built-in driver and as a module.

Signed-off-by: Jonas Malaco 
---
Changes in v2:
- remove unnecessary type, attr and channel checks from _is_visible
- remove unnecessary attr and channel checks from _read/_read_string
- remove the spinlock by computing values in the event handler
- add comment describing how the device reports data
- report missing or stale data to user-space
- adjust copyright notice

 Documentation/hwmon/index.rst|   1 +
 Documentation/hwmon/nzxt-kraken2.rst |  42 +
 MAINTAINERS  |   7 +
 drivers/hwmon/Kconfig|  10 ++
 drivers/hwmon/Makefile   |   1 +
 drivers/hwmon/nzxt-kraken2.c | 235 +++
 6 files changed, 296 insertions(+)
 create mode 100644 Documentation/hwmon/nzxt-kraken2.rst
 create mode 100644 drivers/hwmon/nzxt-kraken2.c

diff --git a/Documentation/hwmon/index.rst b/Documentation/hwmon/index.rst
index d4b422edbe3a..48bfa7887dd4 100644
--- a/Documentation/hwmon/index.rst
+++ b/Documentation/hwmon/index.rst
@@ -143,6 +143,7 @@ Hardware Monitoring Kernel Drivers
npcm750-pwm-fan
nsa320
ntc_thermistor
+   nzxt-kraken2
occ
pc87360
pc87427
diff --git a/Documentation/hwmon/nzxt-kraken2.rst 
b/Documentation/hwmon/nzxt-kraken2.rst
new file mode 100644
index ..94025de65a81
--- /dev/null
+++ b/Documentation/hwmon/nzxt-kraken2.rst
@@ -0,0 +1,42 @@
+.. SPDX-License-Identifier: GPL-2.0-or-later
+
+Kernel driver nzxt-kraken2
+==
+
+Supported devices:
+
+* NZXT Kraken X42
+* NZXT Kraken X52
+* NZXT Kraken X62
+* NZXT Kraken X72
+
+Author: Jonas Malaco
+
+Description
+---
+
+This driver enables hardware monitoring support for NZXT Kraken X42/X52/X62/X72
+all-in-one CPU liquid coolers.  Three sensors are available: fan speed, pump
+speed and coolant temperature.
+
+Fan and pump control, while supported by the firmware, are not currently
+exposed.  The addressable RGB LEDs, present in the integrated CPU water block
+and pump head, are not supported either.  But both features can be found in
+existing user-space tools (e.g. `liquidctl`_).
+
+.. _liquidctl: https://github.com/liquidctl/liquidctl
+
+Usage Notes
+---
+
+As these are USB HIDs, the driver can be loaded automatically by the kernel and
+supports hot swapping.
+
+Sysfs entries
+-
+
+===

+fan1_input Fan speed (in rpm)
+fan2_input Pump speed (in rpm)
+temp1_inputCoolant temperature (in millidegrees Celsius)
+===

diff --git a/MAINTAINERS b/MAINTAINERS
index 0635b30e467c..b8f9fc5eaf08 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -12911,6 +12911,13 @@ L: linux-...@lists.01.org (moderated for 
non-subscribers)
 S: Supported
 F: drivers/nfc/nxp-nci
 
+NZXT-KRAKEN2 HARDWARE MONITORING DRIVER
+M: Jonas Malaco 
+L: linux-hw...@vger.kernel.org
+S: Maintained
+F: Documentation/hwmon/nzxt-kraken2.rst
+F: drivers/hwmon/nzxt-kraken2.c
+
 OBJAGG
 M: Jiri Pirko 
 L: net...@vger.kernel.org
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 54f04e61fb83..0ddc974b102e 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -1492,6 +1492,16 @@ config SENSORS_NSA320
  This driver can also be built as a module. If so, the module
  will be called nsa320-hwmon.
 
+config SENSORS_NZXT_KRAKEN2
+   tristate "NZXT Kraken X42/X51/X62/X72 liquid coolers"
+   depends on USB_HID
+   help
+ If you say yes here you get support for hardware monitoring for the
+ NZXT Kraken X42/X52/X62/X72 all-in-one CPU liquid coolers.
+
+ This driver can also be built as a module. If so, the modul

Re: [PATCH net-next 4/4] net: ipa: activate some commented assertions

2021-03-18 Thread Leon Romanovsky
On Thu, Mar 18, 2021 at 11:29:23PM -0500, Alex Elder wrote:
> Convert some commented assertion statements into real calls to
> ipa_assert().  If the IPA device pointer is available, provide it,
> otherwise pass NULL for that.
> 
> There are lots more places to convert, but this serves as an initial
> verification of the new mechanism.  The assertions here implement
> both runtime and build-time assertions, both with and without the
> device pointer.
> 
> Signed-off-by: Alex Elder 
> ---
>  drivers/net/ipa/ipa_reg.h   | 7 ---
>  drivers/net/ipa/ipa_table.c | 5 -
>  2 files changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/net/ipa/ipa_reg.h b/drivers/net/ipa/ipa_reg.h
> index 732e691e9aa62..d0de85de9f08d 100644
> --- a/drivers/net/ipa/ipa_reg.h
> +++ b/drivers/net/ipa/ipa_reg.h
> @@ -9,6 +9,7 @@
>  #include 
>  
>  #include "ipa_version.h"
> +#include "ipa_assert.h"
>  
>  struct ipa;
>  
> @@ -212,7 +213,7 @@ static inline u32 ipa_reg_bcr_val(enum ipa_version 
> version)
>   BCR_HOLB_DROP_L2_IRQ_FMASK |
>   BCR_DUAL_TX_FMASK;
>  
> - /* assert(version != IPA_VERSION_4_5); */
> + ipa_assert(NULL, version != IPA_VERSION_4_5);

This assert will fire for IPA_VERSION_4_2, I doubt that this is
something you want.

Thanks


Re: [PATCH] swiotlb: Make SWIOTLB_NO_FORCE perform no allocation

2021-03-18 Thread Konrad Rzeszutek Wilk
On Thu, Mar 18, 2021 at 09:00:54PM -0700, Florian Fainelli wrote:
> When SWIOTLB_NO_FORCE is used, there should really be no allocations of
> io_tlb_nslabs to occur since we are not going to use those slabs. If a
> platform was somehow setting swiotlb_no_force and a later call to
> swiotlb_init() was to be made we would still be proceeding with
> allocating the default SWIOTLB size (64MB), whereas if swiotlb=noforce
> was set on the kernel command line we would have only allocated 2KB.
> 
> This would be inconsistent and the point of initializing io_tlb_nslabs
> to 1, was to avoid hitting the test for io_tlb_nslabs being 0/not
> initialized.

Could you rebase this on devel/for-linus-5.13 in

git://git.kernel.org/pub/scm/linux/kernel/git/konrad/swiotlb.git

please?
> 
> Signed-off-by: Florian Fainelli 
> ---
>  kernel/dma/swiotlb.c | 10 ++
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
> index c10e855a03bc..526c8321b76f 100644
> --- a/kernel/dma/swiotlb.c
> +++ b/kernel/dma/swiotlb.c
> @@ -121,12 +121,10 @@ setup_io_tlb_npages(char *str)
>   }
>   if (*str == ',')
>   ++str;
> - if (!strcmp(str, "force")) {
> + if (!strcmp(str, "force"))
>   swiotlb_force = SWIOTLB_FORCE;
> - } else if (!strcmp(str, "noforce")) {
> + else if (!strcmp(str, "noforce"))
>   swiotlb_force = SWIOTLB_NO_FORCE;
> - io_tlb_nslabs = 1;
> - }
>  
>   return 0;
>  }
> @@ -284,6 +282,9 @@ swiotlb_init(int verbose)
>   unsigned char *vstart;
>   unsigned long bytes;
>  
> + if (swiotlb_force == SWIOTLB_NO_FORCE)
> + goto out;
> +
>   if (!io_tlb_nslabs) {
>   io_tlb_nslabs = (default_size >> IO_TLB_SHIFT);
>   io_tlb_nslabs = ALIGN(io_tlb_nslabs, IO_TLB_SEGSIZE);
> @@ -302,6 +303,7 @@ swiotlb_init(int verbose)
>   io_tlb_start = 0;
>   }
>   pr_warn("Cannot allocate buffer");
> +out:
>   no_iotlb_memory = true;
>  }
>  
> -- 
> 2.25.1
> 


RE: [PATCH 06/11] i2c: imx-lpi2c: improve i2c driver probe priority

2021-03-18 Thread Aisheng Dong
> From: Clark Wang 
> Sent: Wednesday, March 17, 2021 2:54 PM
> 
> use subsys_initcall for i2c driver to improve i2c driver probe priority

Will this affect DMA support which will be probed much later compared with 
subsys_initcall?

> 
> Signed-off-by: Gao Pan 

Add your sign-off

> ---
>  drivers/i2c/busses/i2c-imx-lpi2c.c | 12 +++-
>  1 file changed, 11 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/i2c/busses/i2c-imx-lpi2c.c
> b/drivers/i2c/busses/i2c-imx-lpi2c.c
> index 8f9dd3dd2951..86b69852f7be 100644
> --- a/drivers/i2c/busses/i2c-imx-lpi2c.c
> +++ b/drivers/i2c/busses/i2c-imx-lpi2c.c
> @@ -710,7 +710,17 @@ static struct platform_driver lpi2c_imx_driver = {
>   },
>  };
> 
> -module_platform_driver(lpi2c_imx_driver);
> +static int __init lpi2c_imx_init(void)
> +{
> + return platform_driver_register(&lpi2c_imx_driver);
> +}
> +subsys_initcall(lpi2c_imx_init);
> +
> +static void __exit lpi2c_imx_exit(void) {
> + platform_driver_unregister(&lpi2c_imx_driver);
> +}
> +module_exit(lpi2c_imx_exit);
> 
>  MODULE_AUTHOR("Gao Pan ");
> MODULE_DESCRIPTION("I2C adapter driver for LPI2C bus");
> --
> 2.25.1



Re: [PATCH V3] exit: trigger panic when global init has exited

2021-03-18 Thread qianli zhao
Hi,Oleg

> But then I don't understand the SIGNAL_GROUP_EXIT check added by your
> patch. Do we really need it if we want to avoid zap_pid_ns_processes()
> when the global init exits?

I think check SIGNAL_GROUP_EXIT is necessary,or panic() will happen
after all init sub-threads do_exit(),so the following two situations
will happen:
1.According to the timing in the changelog,
zap_pid_ns_processes()->BUG() maybe happened.
2.The key variables of each init sub-threads will be in the exit
state(such task->mm=NULL,task->flags=PF_EXITING,task->nsproxy=NULL),resulting
in the failure to parse coredump from fulldump.

So i think check SIGNAL_GROUP_EXIT is a simple and effective way to
prevent these

> Does this connect to SIGNAL_GROUP_EXIT check? Do you mean that you want
> to panic earlier, before other init's sub-threads exit?

Yes, my patch just want panic earlier before other init's sub-threads exit

Oleg Nesterov  于2021年3月19日周五 上午2:05写道:
>
> On 03/18, qianli zhao wrote:
> >
> > Hi,Oleg
> >
> > Thank you for your reply.
> >
> > >> When init sub-threads running on different CPUs exit at the same time,
> > >> zap_pid_ns_processe()->BUG() may be happened.
> >
> > > and why do you think your patch can't prevent this?
> >
> > > Sorry, I must have missed something. But it seems to me that you are 
> > > trying
> > > to fix the wrong problem. Yes, zap_pid_ns_processes() must not be called 
> > > in
> > > the root namespace, and this has nothing to do with CONFIG_PID_NS.
> >
> > Yes, i try to fix this exception by test SIGNAL_GROUP_EXIT and call
> > panic before setting PF_EXITING to prevent zap_pid_ns_processes()
> > being called when init do_exit().
>
> Ah, I didn't notice your patch does atomic_dec_and_test(signal->live)
> before exit_signals() which sets PF_EXITING. Thanks for correcting me.
>
> So yes, I was wrong, your patch can prevent this. Although I'd like to
> recheck if every do-something-if-group-dead action is correct in the
> case we have a non-PF_EXITING thread...
>
> But then I don't understand the SIGNAL_GROUP_EXIT check added by your
> patch. Do we really need it if we want to avoid zap_pid_ns_processes()
> when the global init exits?
>
> > In addition, the patch also protects the init process state to
> > successfully get usable init coredump.
>
> Could you spell please?
>
> Does this connect to SIGNAL_GROUP_EXIT check? Do you mean that you want
> to panic earlier, before other init's sub-threads exit?
>
> Thanks,
>
> Oleg.
>


RE: [PATCH 07/11] i2c: imx-lpi2c: increase PM timeout to avoid operate clk frequently

2021-03-18 Thread Aisheng Dong
> From: Clark Wang 
> Sent: Wednesday, March 17, 2021 2:54 PM
> 
> Switching the clock frequently will affect the data transmission efficiency, 
> and
> prolong the timeout to reduce autosuspend times for lpi2c.
> 
> Acked-by: Fugang Duan 
> Signed-off-by: Clark Wang 

Reviewed-by: Dong Aisheng 

Regards
Aisheng

> ---
>  drivers/i2c/busses/i2c-imx-lpi2c.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/i2c/busses/i2c-imx-lpi2c.c
> b/drivers/i2c/busses/i2c-imx-lpi2c.c
> index 86b69852f7be..c0cb77c66090 100644
> --- a/drivers/i2c/busses/i2c-imx-lpi2c.c
> +++ b/drivers/i2c/busses/i2c-imx-lpi2c.c
> @@ -75,7 +75,7 @@
>  #define I2C_CLK_RATIO2
>  #define CHUNK_DATA   256
> 
> -#define I2C_PM_TIMEOUT   10 /* ms */
> +#define I2C_PM_TIMEOUT   1000 /* ms */
> 
>  enum lpi2c_imx_mode {
>   STANDARD,   /* 100+Kbps */
> --
> 2.25.1



[PATCH v5 1/2] dt-bindings: Add doc for FriendlyARM NanoPi R4S

2021-03-18 Thread Tianling Shen
Add devicetree binding documentation for the FriendlyARM NanoPi R4S.

Changes in v5:
- Dropped the empty PCIe node
- Dropped useless `/delete-property/`
- Renamed LED nodes

Changes in v4:
- Correctly dropped `display-subsystem` node
- Dropped meaningless `pwm-fan` node
- Dropped wrong `sdmmc` node
- Disabled `i2c4` and `uart0` as they don't exist in the design
- Format fixes

Changes in v3:
- Dropped non-existent node `display_subsystem`

Changes in v2:
- Disable display for NanoPi R4S (reference commit: 74532de460ec)
- Light "sys" LED on NanoPi R4S (reference commit: 833821eeab91)

Signed-off-by: Tianling Shen 
---
 Documentation/devicetree/bindings/arm/rockchip.yaml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/arm/rockchip.yaml 
b/Documentation/devicetree/bindings/arm/rockchip.yaml
index c3036f95c7bc..4a6f772c1043 100644
--- a/Documentation/devicetree/bindings/arm/rockchip.yaml
+++ b/Documentation/devicetree/bindings/arm/rockchip.yaml
@@ -134,6 +134,7 @@ properties:
   - friendlyarm,nanopi-m4
   - friendlyarm,nanopi-m4b
   - friendlyarm,nanopi-neo4
+  - friendlyarm,nanopi-r4s
   - const: rockchip,rk3399
 
   - description: GeekBuying GeekBox
-- 
2.17.1



[PATCH v5 2/2] rockchip: rk3399: Add support for FriendlyARM NanoPi R4S

2021-03-18 Thread Tianling Shen
This adds support for the NanoPi R4S from FriendlyArm.

Rockchip RK3399 SoC
1GB DDR3 or 4GB LPDDR4 RAM
Gigabit Ethernet (WAN)
Gigabit Ethernet (PCIe) (LAN)
USB 3.0 Port x 2
MicroSD slot
Reset button
WAN - LAN - SYS LED

[initial DTS file]
Co-developed-by: Jensen Huang 
Signed-off-by: Jensen Huang 
[minor adjustments]
Co-developed-by: Marty Jones 
Signed-off-by: Marty Jones 
[further adjustments, fixed format issues]
Signed-off-by: Tianling Shen 
---
 arch/arm64/boot/dts/rockchip/Makefile |   1 +
 .../boot/dts/rockchip/rk3399-nanopi-r4s.dts   | 133 ++
 2 files changed, 134 insertions(+)
 create mode 100644 arch/arm64/boot/dts/rockchip/rk3399-nanopi-r4s.dts

diff --git a/arch/arm64/boot/dts/rockchip/Makefile 
b/arch/arm64/boot/dts/rockchip/Makefile
index 62d3abc17a24..c3e00c0e2db7 100644
--- a/arch/arm64/boot/dts/rockchip/Makefile
+++ b/arch/arm64/boot/dts/rockchip/Makefile
@@ -36,6 +36,7 @@ dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3399-nanopc-t4.dtb
 dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3399-nanopi-m4.dtb
 dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3399-nanopi-m4b.dtb
 dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3399-nanopi-neo4.dtb
+dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3399-nanopi-r4s.dtb
 dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3399-orangepi.dtb
 dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3399-pinebook-pro.dtb
 dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3399-puma-haikou.dtb
diff --git a/arch/arm64/boot/dts/rockchip/rk3399-nanopi-r4s.dts 
b/arch/arm64/boot/dts/rockchip/rk3399-nanopi-r4s.dts
new file mode 100644
index ..0aa19c06908d
--- /dev/null
+++ b/arch/arm64/boot/dts/rockchip/rk3399-nanopi-r4s.dts
@@ -0,0 +1,133 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * FriendlyElec NanoPC-T4 board device tree source
+ *
+ * Copyright (c) 2020 FriendlyElec Computer Tech. Co., Ltd.
+ * (http://www.friendlyarm.com)
+ *
+ * Copyright (c) 2018 Collabora Ltd.
+ *
+ * Copyright (c) 2020 Jensen Huang 
+ * Copyright (c) 2020 Marty Jones 
+ * Copyright (c) 2021 Tianling Shen 
+ */
+
+/dts-v1/;
+#include "rk3399-nanopi4.dtsi"
+
+/ {
+   model = "FriendlyElec NanoPi R4S";
+   compatible = "friendlyarm,nanopi-r4s", "rockchip,rk3399";
+
+   /delete-node/ display-subsystem;
+
+   gpio-leds {
+   pinctrl-0 = <&lan_led_pin>, <&sys_led_pin>, <&wan_led_pin>;
+
+   /delete-node/ led-0;
+
+   lan_led: lan-led {
+   gpios = <&gpio1 RK_PA1 GPIO_ACTIVE_HIGH>;
+   label = "nanopi-r4s:green:lan";
+   };
+
+   sys_led: sys-led {
+   gpios = <&gpio0 RK_PB5 GPIO_ACTIVE_HIGH>;
+   label = "nanopi-r4s:red:sys";
+   default-state = "on";
+   };
+
+   wan_led: wan-led {
+   gpios = <&gpio1 RK_PA0 GPIO_ACTIVE_HIGH>;
+   label = "nanopi-r4s:green:wan";
+   };
+   };
+
+   gpio-keys {
+   pinctrl-0 = <&reset_button_pin>;
+
+   /delete-node/ power;
+
+   reset {
+   debounce-interval = <50>;
+   gpios = <&gpio1 RK_PC6 GPIO_ACTIVE_LOW>;
+   label = "reset";
+   linux,code = ;
+   };
+   };
+
+   vdd_5v: vdd-5v {
+   compatible = "regulator-fixed";
+   regulator-name = "vdd_5v";
+   regulator-always-on;
+   regulator-boot-on;
+   };
+};
+
+&emmc_phy {
+   status = "disabled";
+};
+
+&i2c4 {
+   status = "disabled";
+};
+
+&pcie0 {
+   max-link-speed = <1>;
+   num-lanes = <1>;
+   vpcie3v3-supply = <&vcc3v3_sys>;
+};
+
+&pinctrl {
+   gpio-leds {
+   /delete-node/ status-led-pin;
+
+   lan_led_pin: lan-led-pin {
+   rockchip,pins = <1 RK_PA1 RK_FUNC_GPIO &pcfg_pull_none>;
+   };
+
+   sys_led_pin: sys-led-pin {
+   rockchip,pins = <0 RK_PB5 RK_FUNC_GPIO &pcfg_pull_none>;
+   };
+
+   wan_led_pin: wan-led-pin {
+   rockchip,pins = <1 RK_PA0 RK_FUNC_GPIO &pcfg_pull_none>;
+   };
+   };
+
+   rockchip-key {
+   /delete-node/ power-key;
+
+   reset_button_pin: reset-button-pin {
+   rockchip,pins = <1 RK_PC6 RK_FUNC_GPIO &pcfg_pull_up>;
+   };
+   };
+};
+
+&sdhci {
+   status = "disabled";
+};
+
+&sdio0 {
+   status = "disabled";
+};
+
+&u2phy0_host {
+   phy-supply = <&vdd_5v>;
+};
+
+&u2phy1_host {
+   status = "disabled";
+};
+
+&uart0 {
+   status = "disabled";
+};
+
+&usbdrd_dwc3_0 {
+   dr_mode = "host";
+};
+
+&vcc3v3_sys {
+   vin-supply = <&vcc5v0_sys>;
+};
-- 
2.17.1



RE: [PATCH 08/11] i2c: imx-lpi2c: add bus recovery feature

2021-03-18 Thread Aisheng Dong
> From: Clark Wang 
> Sent: Wednesday, March 17, 2021 2:54 PM
> 
> Add bus recovery feature for LPI2C.
> Need add gpio pinctrl, scl-gpios and sda-gpios configuration in dts.
> 

Pls also update dt-binding first

> Signed-off-by: Clark Wang 
> ---
>  drivers/i2c/busses/i2c-imx-lpi2c.c | 83 ++
>  1 file changed, 83 insertions(+)
> 
> diff --git a/drivers/i2c/busses/i2c-imx-lpi2c.c
> b/drivers/i2c/busses/i2c-imx-lpi2c.c
> index c0cb77c66090..7216a393095d 100644
> --- a/drivers/i2c/busses/i2c-imx-lpi2c.c
> +++ b/drivers/i2c/busses/i2c-imx-lpi2c.c
> @@ -18,6 +18,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -108,6 +109,11 @@ struct lpi2c_imx_struct {
>   unsigned inttxfifosize;
>   unsigned intrxfifosize;
>   enum lpi2c_imx_mode mode;
> +
> + struct i2c_bus_recovery_info rinfo;
> + struct pinctrl *pinctrl;
> + struct pinctrl_state *pinctrl_pins_default;
> + struct pinctrl_state *pinctrl_pins_gpio;
>  };
> 
>  static void lpi2c_imx_intctrl(struct lpi2c_imx_struct *lpi2c_imx, @@ -135,6
> +141,8 @@ static int lpi2c_imx_bus_busy(struct lpi2c_imx_struct *lpi2c_imx)
> 
>   if (time_after(jiffies, orig_jiffies + msecs_to_jiffies(500))) {
>   dev_dbg(&lpi2c_imx->adapter.dev, "bus not work\n");
> + if (lpi2c_imx->adapter.bus_recovery_info)
> + i2c_recover_bus(&lpi2c_imx->adapter);
>   return -ETIMEDOUT;
>   }
>   schedule();
> @@ -192,6 +200,8 @@ static void lpi2c_imx_stop(struct lpi2c_imx_struct
> *lpi2c_imx)
> 
>   if (time_after(jiffies, orig_jiffies + msecs_to_jiffies(500))) {
>   dev_dbg(&lpi2c_imx->adapter.dev, "stop timeout\n");
> + if (lpi2c_imx->adapter.bus_recovery_info)
> + i2c_recover_bus(&lpi2c_imx->adapter);
>   break;
>   }
>   schedule();
> @@ -329,6 +339,8 @@ static int lpi2c_imx_txfifo_empty(struct
> lpi2c_imx_struct *lpi2c_imx)
> 
>   if (time_after(jiffies, orig_jiffies + msecs_to_jiffies(500))) {
>   dev_dbg(&lpi2c_imx->adapter.dev, "txfifo empty 
> timeout\n");
> + if (lpi2c_imx->adapter.bus_recovery_info)
> + i2c_recover_bus(&lpi2c_imx->adapter);
>   return -ETIMEDOUT;
>   }
>   schedule();
> @@ -528,6 +540,71 @@ static irqreturn_t lpi2c_imx_isr(int irq, void *dev_id)
>   return IRQ_HANDLED;
>  }
> 
> +static void lpi2c_imx_prepare_recovery(struct i2c_adapter *adap) {
> + struct lpi2c_imx_struct *lpi2c_imx;
> +
> + lpi2c_imx = container_of(adap, struct lpi2c_imx_struct, adapter);
> +
> + pinctrl_select_state(lpi2c_imx->pinctrl,
> +lpi2c_imx->pinctrl_pins_gpio); }
> +
> +static void lpi2c_imx_unprepare_recovery(struct i2c_adapter *adap) {
> + struct lpi2c_imx_struct *lpi2c_imx;
> +
> + lpi2c_imx = container_of(adap, struct lpi2c_imx_struct, adapter);
> +
> + pinctrl_select_state(lpi2c_imx->pinctrl,
> +lpi2c_imx->pinctrl_pins_default); }
> +
> +/*
> + * We switch SCL and SDA to their GPIO function and do some bitbanging
> + * for bus recovery. These alternative pinmux settings can be
> + * described in the device tree by a separate pinctrl state "gpio". If
> + * this is missing this is not a big problem, the only implication is
> + * that we can't do bus recovery.
> + */
> +static int lpi2c_imx_init_recovery_info(struct lpi2c_imx_struct *lpi2c_imx,
> + struct platform_device *pdev)
> +{
> + struct i2c_bus_recovery_info *rinfo = &lpi2c_imx->rinfo;
> +
> + lpi2c_imx->pinctrl = devm_pinctrl_get(&pdev->dev);
> + if (!lpi2c_imx->pinctrl || IS_ERR(lpi2c_imx->pinctrl)) {
> + dev_info(&pdev->dev, "can't get pinctrl, bus recovery not
> supported\n");
> + return PTR_ERR(lpi2c_imx->pinctrl);
> + }
> +
> + lpi2c_imx->pinctrl_pins_default = 
> pinctrl_lookup_state(lpi2c_imx->pinctrl,
> + PINCTRL_STATE_DEFAULT);
> + lpi2c_imx->pinctrl_pins_gpio = pinctrl_lookup_state(lpi2c_imx->pinctrl,
> + "gpio");
> + rinfo->sda_gpiod = devm_gpiod_get(&pdev->dev, "sda", GPIOD_IN);
> + rinfo->scl_gpiod = devm_gpiod_get(&pdev->dev, "scl",
> +GPIOD_OUT_HIGH_OPEN_DRAIN);
> +
> + if (PTR_ERR(rinfo->sda_gpiod) == -EPROBE_DEFER ||
> + PTR_ERR(rinfo->scl_gpiod) == -EPROBE_DEFER) {
> + return -EPROBE_DEFER;
> + } else if (IS_ERR(rinfo->sda_gpiod) ||
> +IS_ERR(rinfo->scl_gpiod) ||
> +IS_ERR(lpi2c_imx->pinctrl_pins_default) ||
> +IS_ERR(lpi2c_imx->pinctrl_pins_gpio)) {
> + dev_dbg(&pdev->dev, "recovery information incomplete\n");
> + return 0;
> + }
> +
> + dev_info(&pdev->dev, "using scl%s for rec

[PATCH] MAINTAINERS: Update MCAN MMIO device driver maintainer

2021-03-18 Thread Pankaj Sharma
Update Chandrasekar Ramakrishnan as maintainer for mcan mmio device driver as I
will be moving to a different role.

Signed-off-by: Pankaj Sharma 
---
 MAINTAINERS | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index a50a543e3c81..76db44337f6c 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -10820,7 +10820,7 @@ F:  drivers/media/radio/radio-maxiradio*
 
 MCAN MMIO DEVICE DRIVER
 M: Dan Murphy 
-M: Pankaj Sharma 
+M: Chandrasekar Ramakrishnan 
 L: linux-...@vger.kernel.org
 S: Maintained
 F: Documentation/devicetree/bindings/net/can/bosch,m_can.yaml
-- 
2.17.1



RE: [PATCH 09/11] i2c: imx-lpi2c: fix i2c timing issue

2021-03-18 Thread Aisheng Dong
> From: Clark Wang 
> Sent: Wednesday, March 17, 2021 2:54 PM
> 
> The clkhi and clklo ratio was not very precise before that can make the time 
> of
> START/STOP/HIGH LEVEL out of specification.
> 
> Therefore, the calculation of these times has been modified in this patch.
> At the same time, the mode rate definition of i2c is corrected.
> 
> Reviewed-by: Fugang Duan 
> Signed-off-by: Clark Wang 
> ---
>  drivers/i2c/busses/i2c-imx-lpi2c.c | 27 ++-
>  1 file changed, 14 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-imx-lpi2c.c
> b/drivers/i2c/busses/i2c-imx-lpi2c.c
> index 7216a393095d..5dbe85126f24 100644
> --- a/drivers/i2c/busses/i2c-imx-lpi2c.c
> +++ b/drivers/i2c/busses/i2c-imx-lpi2c.c
> @@ -73,17 +73,17 @@
>  #define MCFGR1_IGNACKBIT(9)
>  #define MRDR_RXEMPTY BIT(14)
> 
> -#define I2C_CLK_RATIO2
> +#define I2C_CLK_RATIO24 / 59

Where is this ratio coming from?
Can you describe why use it in commit message?

Regards
Aisheng

>  #define CHUNK_DATA   256
> 
>  #define I2C_PM_TIMEOUT   1000 /* ms */
> 
>  enum lpi2c_imx_mode {
> - STANDARD,   /* 100+Kbps */
> - FAST,   /* 400+Kbps */
> - FAST_PLUS,  /* 1.0+Mbps */
> - HS, /* 3.4+Mbps */
> - ULTRA_FAST, /* 5.0+Mbps */
> + STANDARD,   /* <=100Kbps */
> + FAST,   /* <=400Kbps */
> + FAST_PLUS,  /* <=1.0Mbps */
> + HS, /* <=3.4Mbps */
> + ULTRA_FAST, /* <=5.0Mbps */
>  };
> 
>  enum lpi2c_imx_pincfg {
> @@ -156,13 +156,13 @@ static void lpi2c_imx_set_mode(struct
> lpi2c_imx_struct *lpi2c_imx)
>   unsigned int bitrate = lpi2c_imx->bitrate;
>   enum lpi2c_imx_mode mode;
> 
> - if (bitrate < I2C_MAX_FAST_MODE_FREQ)
> + if (bitrate <= I2C_MAX_STANDARD_MODE_FREQ)
>   mode = STANDARD;
> - else if (bitrate < I2C_MAX_FAST_MODE_PLUS_FREQ)
> + else if (bitrate <= I2C_MAX_FAST_MODE_FREQ)
>   mode = FAST;
> - else if (bitrate < I2C_MAX_HIGH_SPEED_MODE_FREQ)
> + else if (bitrate <= I2C_MAX_FAST_MODE_PLUS_FREQ)
>   mode = FAST_PLUS;
> - else if (bitrate < I2C_MAX_ULTRA_FAST_MODE_FREQ)
> + else if (bitrate <= I2C_MAX_HIGH_SPEED_MODE_FREQ)
>   mode = HS;
>   else
>   mode = ULTRA_FAST;
> @@ -209,7 +209,8 @@ static void lpi2c_imx_stop(struct lpi2c_imx_struct
> *lpi2c_imx)
>   } while (1);
>  }
> 
> -/* CLKLO = I2C_CLK_RATIO * CLKHI, SETHOLD = CLKHI, DATAVD = CLKHI/2 */
> +/* CLKLO = (1 - I2C_CLK_RATIO) * clk_cycle, SETHOLD = CLKHI, DATAVD =
> CLKHI/2
> +   CLKHI = I2C_CLK_RATIO * clk_cycle */
>  static int lpi2c_imx_config(struct lpi2c_imx_struct *lpi2c_imx)  {
>   u8 prescale, filt, sethold, clkhi, clklo, datavd; @@ -232,8 +233,8 @@
> static int lpi2c_imx_config(struct lpi2c_imx_struct *lpi2c_imx)
> 
>   for (prescale = 0; prescale <= 7; prescale++) {
>   clk_cycle = clk_rate / ((1 << prescale) * lpi2c_imx->bitrate)
> - - 3 - (filt >> 1);
> - clkhi = (clk_cycle + I2C_CLK_RATIO) / (I2C_CLK_RATIO + 1);
> + - (2 + filt) / (1 << prescale);
> + clkhi = clk_cycle * I2C_CLK_RATIO;
>   clklo = clk_cycle - clkhi;
>   if (clklo < 64)
>   break;
> --
> 2.25.1



RE: [PATCH 10/11] i2c: imx-lpi2c: fix type char overflow issue when calculating the clock cycle

2021-03-18 Thread Aisheng Dong
> From: Clark Wang 
> Sent: Wednesday, March 17, 2021 2:54 PM
> 
> Claim clkhi and clklo as integer type to avoid possible calculation errors 
> caused
> by data overflow.
> 
> Reviewed-by: Fugang Duan 
> Signed-off-by: Clark Wang 

Reviewed-by: Dong Aisheng 

Regards
Aisheng

> ---
>  drivers/i2c/busses/i2c-imx-lpi2c.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-imx-lpi2c.c
> b/drivers/i2c/busses/i2c-imx-lpi2c.c
> index 5dbe85126f24..1e26672d47bf 100644
> --- a/drivers/i2c/busses/i2c-imx-lpi2c.c
> +++ b/drivers/i2c/busses/i2c-imx-lpi2c.c
> @@ -213,8 +213,8 @@ static void lpi2c_imx_stop(struct lpi2c_imx_struct
> *lpi2c_imx)
> CLKHI = I2C_CLK_RATIO * clk_cycle */  static int lpi2c_imx_config(struct
> lpi2c_imx_struct *lpi2c_imx)  {
> - u8 prescale, filt, sethold, clkhi, clklo, datavd;
> - unsigned int clk_rate, clk_cycle;
> + u8 prescale, filt, sethold, datavd;
> + unsigned int clk_rate, clk_cycle, clkhi, clklo;
>   enum lpi2c_imx_pincfg pincfg;
>   unsigned int temp;
> 
> --
> 2.25.1



[PATCH v6 1/2] dt-bindings: Add doc for FriendlyARM NanoPi R4S

2021-03-18 Thread Tianling Shen
Add devicetree binding documentation for the FriendlyARM NanoPi R4S.

Changes in v6:
- Fixed format of LED nodes

Changes in v5:
- Dropped the empty PCIe node
- Dropped useless `/delete-property/`
- Renamed LED nodes

Changes in v4:
- Correctly dropped `display-subsystem` node
- Dropped meaningless `pwm-fan` node
- Dropped wrong `sdmmc` node
- Disabled `i2c4` and `uart0` as they don't exist in the design
- Format fixes

Changes in v3:
- Dropped non-existent node `display_subsystem`

Changes in v2:
- Disable display for NanoPi R4S (reference commit: 74532de460ec)
- Light "sys" LED on NanoPi R4S (reference commit: 833821eeab91)

Signed-off-by: Tianling Shen 
---
 Documentation/devicetree/bindings/arm/rockchip.yaml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/arm/rockchip.yaml 
b/Documentation/devicetree/bindings/arm/rockchip.yaml
index c3036f95c7bc..4a6f772c1043 100644
--- a/Documentation/devicetree/bindings/arm/rockchip.yaml
+++ b/Documentation/devicetree/bindings/arm/rockchip.yaml
@@ -134,6 +134,7 @@ properties:
   - friendlyarm,nanopi-m4
   - friendlyarm,nanopi-m4b
   - friendlyarm,nanopi-neo4
+  - friendlyarm,nanopi-r4s
   - const: rockchip,rk3399
 
   - description: GeekBuying GeekBox
-- 
2.17.1



[PATCH v6 2/2] rockchip: rk3399: Add support for FriendlyARM NanoPi R4S

2021-03-18 Thread Tianling Shen
This adds support for the NanoPi R4S from FriendlyArm.

Rockchip RK3399 SoC
1GB DDR3 or 4GB LPDDR4 RAM
Gigabit Ethernet (WAN)
Gigabit Ethernet (PCIe) (LAN)
USB 3.0 Port x 2
MicroSD slot
Reset button
WAN - LAN - SYS LED

[initial DTS file]
Co-developed-by: Jensen Huang 
Signed-off-by: Jensen Huang 
[minor adjustments]
Co-developed-by: Marty Jones 
Signed-off-by: Marty Jones 
[further adjustments, fixed format issues]
Signed-off-by: Tianling Shen 
---
 arch/arm64/boot/dts/rockchip/Makefile |   1 +
 .../boot/dts/rockchip/rk3399-nanopi-r4s.dts   | 133 ++
 2 files changed, 134 insertions(+)
 create mode 100644 arch/arm64/boot/dts/rockchip/rk3399-nanopi-r4s.dts

diff --git a/arch/arm64/boot/dts/rockchip/Makefile 
b/arch/arm64/boot/dts/rockchip/Makefile
index 62d3abc17a24..c3e00c0e2db7 100644
--- a/arch/arm64/boot/dts/rockchip/Makefile
+++ b/arch/arm64/boot/dts/rockchip/Makefile
@@ -36,6 +36,7 @@ dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3399-nanopc-t4.dtb
 dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3399-nanopi-m4.dtb
 dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3399-nanopi-m4b.dtb
 dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3399-nanopi-neo4.dtb
+dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3399-nanopi-r4s.dtb
 dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3399-orangepi.dtb
 dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3399-pinebook-pro.dtb
 dtb-$(CONFIG_ARCH_ROCKCHIP) += rk3399-puma-haikou.dtb
diff --git a/arch/arm64/boot/dts/rockchip/rk3399-nanopi-r4s.dts 
b/arch/arm64/boot/dts/rockchip/rk3399-nanopi-r4s.dts
new file mode 100644
index ..fa5809887643
--- /dev/null
+++ b/arch/arm64/boot/dts/rockchip/rk3399-nanopi-r4s.dts
@@ -0,0 +1,133 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * FriendlyElec NanoPC-T4 board device tree source
+ *
+ * Copyright (c) 2020 FriendlyElec Computer Tech. Co., Ltd.
+ * (http://www.friendlyarm.com)
+ *
+ * Copyright (c) 2018 Collabora Ltd.
+ *
+ * Copyright (c) 2020 Jensen Huang 
+ * Copyright (c) 2020 Marty Jones 
+ * Copyright (c) 2021 Tianling Shen 
+ */
+
+/dts-v1/;
+#include "rk3399-nanopi4.dtsi"
+
+/ {
+   model = "FriendlyElec NanoPi R4S";
+   compatible = "friendlyarm,nanopi-r4s", "rockchip,rk3399";
+
+   /delete-node/ display-subsystem;
+
+   gpio-leds {
+   pinctrl-0 = <&lan_led_pin>, <&sys_led_pin>, <&wan_led_pin>;
+
+   /delete-node/ led-0;
+
+   lan_led: led-lan {
+   gpios = <&gpio1 RK_PA1 GPIO_ACTIVE_HIGH>;
+   label = "green:lan";
+   };
+
+   sys_led: led-sys {
+   gpios = <&gpio0 RK_PB5 GPIO_ACTIVE_HIGH>;
+   label = "red:sys";
+   default-state = "on";
+   };
+
+   wan_led: led-wan {
+   gpios = <&gpio1 RK_PA0 GPIO_ACTIVE_HIGH>;
+   label = "green:wan";
+   };
+   };
+
+   gpio-keys {
+   pinctrl-0 = <&reset_button_pin>;
+
+   /delete-node/ power;
+
+   reset {
+   debounce-interval = <50>;
+   gpios = <&gpio1 RK_PC6 GPIO_ACTIVE_LOW>;
+   label = "reset";
+   linux,code = ;
+   };
+   };
+
+   vdd_5v: vdd-5v {
+   compatible = "regulator-fixed";
+   regulator-name = "vdd_5v";
+   regulator-always-on;
+   regulator-boot-on;
+   };
+};
+
+&emmc_phy {
+   status = "disabled";
+};
+
+&i2c4 {
+   status = "disabled";
+};
+
+&pcie0 {
+   max-link-speed = <1>;
+   num-lanes = <1>;
+   vpcie3v3-supply = <&vcc3v3_sys>;
+};
+
+&pinctrl {
+   gpio-leds {
+   /delete-node/ status-led-pin;
+
+   lan_led_pin: lan-led-pin {
+   rockchip,pins = <1 RK_PA1 RK_FUNC_GPIO &pcfg_pull_none>;
+   };
+
+   sys_led_pin: sys-led-pin {
+   rockchip,pins = <0 RK_PB5 RK_FUNC_GPIO &pcfg_pull_none>;
+   };
+
+   wan_led_pin: wan-led-pin {
+   rockchip,pins = <1 RK_PA0 RK_FUNC_GPIO &pcfg_pull_none>;
+   };
+   };
+
+   rockchip-key {
+   /delete-node/ power-key;
+
+   reset_button_pin: reset-button-pin {
+   rockchip,pins = <1 RK_PC6 RK_FUNC_GPIO &pcfg_pull_up>;
+   };
+   };
+};
+
+&sdhci {
+   status = "disabled";
+};
+
+&sdio0 {
+   status = "disabled";
+};
+
+&u2phy0_host {
+   phy-supply = <&vdd_5v>;
+};
+
+&u2phy1_host {
+   status = "disabled";
+};
+
+&uart0 {
+   status = "disabled";
+};
+
+&usbdrd_dwc3_0 {
+   dr_mode = "host";
+};
+
+&vcc3v3_sys {
+   vin-supply = <&vcc5v0_sys>;
+};
-- 
2.17.1



[PATCH] MIPS: PCI: Fix a typo

2021-03-18 Thread Bhaskar Chowdhury


s/packt/packet/

Signed-off-by: Bhaskar Chowdhury 
---
 arch/mips/pci/pci-xtalk-bridge.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/mips/pci/pci-xtalk-bridge.c b/arch/mips/pci/pci-xtalk-bridge.c
index 50f7d42cca5a..d2216942af18 100644
--- a/arch/mips/pci/pci-xtalk-bridge.c
+++ b/arch/mips/pci/pci-xtalk-bridge.c
@@ -385,7 +385,7 @@ static int bridge_domain_activate(struct irq_domain *domain,
bridge_set(bc, b_int_enable, 0x7e00); /* more stuff in int_enable */

/*
-* Enable sending of an interrupt clear packt to the hub on a high to
+* Enable sending of an interrupt clear packet to the hub on a high to
 * low transition of the interrupt pin.
 *
 * IRIX sets additional bits in the address which are documented as
--
2.26.2



[PATCH v3 2/2] arm64: dts: ti: k3-am642: reserve gpio in mcu domain for firmware usage

2021-03-18 Thread Aswath Govindraju
The gpio0 subsystem present in MCU domain might be used by firmware and is
not pinned out in evm/sk. Therefore, reserve it for MCU firmware.

Signed-off-by: Aswath Govindraju 
---
 arch/arm64/boot/dts/ti/k3-am642-evm.dts | 5 +
 arch/arm64/boot/dts/ti/k3-am642-sk.dts  | 5 +
 2 files changed, 10 insertions(+)

diff --git a/arch/arm64/boot/dts/ti/k3-am642-evm.dts 
b/arch/arm64/boot/dts/ti/k3-am642-evm.dts
index 9522f104d979..385d99a3bc4f 100644
--- a/arch/arm64/boot/dts/ti/k3-am642-evm.dts
+++ b/arch/arm64/boot/dts/ti/k3-am642-evm.dts
@@ -310,6 +310,11 @@
};
 };
 
+/* mcu_gpio0 is reserved for mcu firmware usage */
+&mcu_gpio0 {
+   status = "reserved";
+};
+
 &mcu_i2c0 {
status = "disabled";
 };
diff --git a/arch/arm64/boot/dts/ti/k3-am642-sk.dts 
b/arch/arm64/boot/dts/ti/k3-am642-sk.dts
index 3a5bee4b0b0c..282fb4185db9 100644
--- a/arch/arm64/boot/dts/ti/k3-am642-sk.dts
+++ b/arch/arm64/boot/dts/ti/k3-am642-sk.dts
@@ -220,6 +220,11 @@
status = "disabled";
 };
 
+/* mcu_gpio0 is reserved for mcu firmware usage */
+&mcu_gpio0 {
+   status = "reserved";
+};
+
 &sdhci1 {
/* SD/MMC */
vmmc-supply = <&vdd_mmc1>;
-- 
2.17.1



[PATCH v3 0/2] AM64: Add support for GPIO

2021-03-18 Thread Aswath Govindraju
The following series of patches adds support for gpio on AM642 evm/sk.

GPIO test logs,
AM642-evm: https://pastebin.ubuntu.com/p/PCGmY34spb/
AM642-sk:  https://pastebin.ubuntu.com/p/nrxzyQTKkX/

Changes since v2:
- Rebased the series on top of ti-k3-dts-next branch
- Added gpio test logs.

Changes since v1:
- Added DT for gpio subsystem present in MCU domain
- reserved the mcu gpio for firmware usage

Aswath Govindraju (2):
  arm64: dts: ti: k3-am64: Add GPIO DT nodes
  arm64: dts: ti: k3-am642: reserve gpio in mcu domain for firmware
usage

 arch/arm64/boot/dts/ti/k3-am64-main.dtsi | 45 
 arch/arm64/boot/dts/ti/k3-am64-mcu.dtsi  | 27 ++
 arch/arm64/boot/dts/ti/k3-am642-evm.dts  |  5 +++
 arch/arm64/boot/dts/ti/k3-am642-sk.dts   |  5 +++
 4 files changed, 82 insertions(+)

-- 
2.17.1



[PATCH v3 1/2] arm64: dts: ti: k3-am64: Add GPIO DT nodes

2021-03-18 Thread Aswath Govindraju
Add device tree nodes for GPIO modules and interrupt controller in main
and mcu domains.

Signed-off-by: Aswath Govindraju 
---
 arch/arm64/boot/dts/ti/k3-am64-main.dtsi | 45 
 arch/arm64/boot/dts/ti/k3-am64-mcu.dtsi  | 27 ++
 2 files changed, 72 insertions(+)

diff --git a/arch/arm64/boot/dts/ti/k3-am64-main.dtsi 
b/arch/arm64/boot/dts/ti/k3-am64-main.dtsi
index a03b66456062..b997d13f9ec5 100644
--- a/arch/arm64/boot/dts/ti/k3-am64-main.dtsi
+++ b/arch/arm64/boot/dts/ti/k3-am64-main.dtsi
@@ -373,6 +373,51 @@
clocks = <&k3_clks 145 0>;
};
 
+   main_gpio_intr: interrupt-controller0 {
+   compatible = "ti,sci-intr";
+   ti,intr-trigger-type = <1>;
+   interrupt-controller;
+   interrupt-parent = <&gic500>;
+   #interrupt-cells = <1>;
+   ti,sci = <&dmsc>;
+   ti,sci-dev-id = <3>;
+   ti,interrupt-ranges = <0 32 16>;
+   };
+
+   main_gpio0: gpio@60 {
+   compatible = "ti,am64-gpio", "ti,keystone-gpio";
+   reg = <0x0 0x0060 0x0 0x100>;
+   gpio-controller;
+   #gpio-cells = <2>;
+   interrupt-parent = <&main_gpio_intr>;
+   interrupts = <190>, <191>, <192>,
+<193>, <194>, <195>;
+   interrupt-controller;
+   #interrupt-cells = <2>;
+   ti,ngpio = <87>;
+   ti,davinci-gpio-unbanked = <0>;
+   power-domains = <&k3_pds 77 TI_SCI_PD_EXCLUSIVE>;
+   clocks = <&k3_clks 77 0>;
+   clock-names = "gpio";
+   };
+
+   main_gpio1: gpio@601000 {
+   compatible = "ti,am64-gpio", "ti,keystone-gpio";
+   reg = <0x0 0x00601000 0x0 0x100>;
+   gpio-controller;
+   #gpio-cells = <2>;
+   interrupt-parent = <&main_gpio_intr>;
+   interrupts = <180>, <181>, <182>,
+<183>, <184>, <185>;
+   interrupt-controller;
+   #interrupt-cells = <2>;
+   ti,ngpio = <88>;
+   ti,davinci-gpio-unbanked = <0>;
+   power-domains = <&k3_pds 78 TI_SCI_PD_EXCLUSIVE>;
+   clocks = <&k3_clks 78 0>;
+   clock-names = "gpio";
+   };
+
sdhci0: mmc@fa1 {
compatible = "ti,am64-sdhci-8bit";
reg = <0x00 0xfa1 0x00 0x260>, <0x00 0xfa18000 0x00 0x134>;
diff --git a/arch/arm64/boot/dts/ti/k3-am64-mcu.dtsi 
b/arch/arm64/boot/dts/ti/k3-am64-mcu.dtsi
index 1d2be485a669..99e94dee1bd4 100644
--- a/arch/arm64/boot/dts/ti/k3-am64-mcu.dtsi
+++ b/arch/arm64/boot/dts/ti/k3-am64-mcu.dtsi
@@ -73,4 +73,31 @@
power-domains = <&k3_pds 148 TI_SCI_PD_EXCLUSIVE>;
clocks = <&k3_clks 148 0>;
};
+
+   mcu_gpio_intr: interrupt-controller1 {
+   compatible = "ti,sci-intr";
+   ti,intr-trigger-type = <1>;
+   interrupt-controller;
+   interrupt-parent = <&gic500>;
+   #interrupt-cells = <1>;
+   ti,sci = <&dmsc>;
+   ti,sci-dev-id = <5>;
+   ti,interrupt-ranges = <0 104 4>;
+   };
+
+   mcu_gpio0: gpio@4201000 {
+   compatible = "ti,am64-gpio", "keystone-gpio";
+   reg = <0x0 0x4201000 0x0 0x100>;
+   gpio-controller;
+   #gpio-cells = <2>;
+   interrupt-parent = <&mcu_gpio_intr>;
+   interrupts = <30>, <31>;
+   interrupt-controller;
+   #interrupt-cells = <2>;
+   ti,ngpio = <23>;
+   ti,davinci-gpio-unbanked = <0>;
+   power-domains = <&k3_pds 79 TI_SCI_PD_EXCLUSIVE>;
+   clocks = <&k3_clks 79 0>;
+   clock-names = "gpio";
+   };
 };
-- 
2.17.1



Re: [PATCH v5 1/2] dt-bindings: Add doc for FriendlyARM NanoPi R4S

2021-03-18 Thread Tianling Shen
Sorry everyone, please ignore these patches as I forgot to update them...
New patches were sent.

On 2021-03-19 13:10, Tianling Shen  wrote:
>
> Add devicetree binding documentation for the FriendlyARM NanoPi R4S.
>
> Changes in v5:
> - Dropped the empty PCIe node
> - Dropped useless `/delete-property/`
> - Renamed LED nodes
>
> Changes in v4:
> - Correctly dropped `display-subsystem` node
> - Dropped meaningless `pwm-fan` node
> - Dropped wrong `sdmmc` node
> - Disabled `i2c4` and `uart0` as they don't exist in the design
> - Format fixes
>
> Changes in v3:
> - Dropped non-existent node `display_subsystem`
>
> Changes in v2:
> - Disable display for NanoPi R4S (reference commit: 74532de460ec)
> - Light "sys" LED on NanoPi R4S (reference commit: 833821eeab91)
>
> Signed-off-by: Tianling Shen 
> ---
>  Documentation/devicetree/bindings/arm/rockchip.yaml | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/Documentation/devicetree/bindings/arm/rockchip.yaml 
> b/Documentation/devicetree/bindings/arm/rockchip.yaml
> index c3036f95c7bc..4a6f772c1043 100644
> --- a/Documentation/devicetree/bindings/arm/rockchip.yaml
> +++ b/Documentation/devicetree/bindings/arm/rockchip.yaml
> @@ -134,6 +134,7 @@ properties:
>- friendlyarm,nanopi-m4
>- friendlyarm,nanopi-m4b
>- friendlyarm,nanopi-neo4
> +  - friendlyarm,nanopi-r4s
>- const: rockchip,rk3399
>
>- description: GeekBuying GeekBox
> --
> 2.17.1
>


Re: [PATCH v2 0/2] AM64: Add support for GPIO

2021-03-18 Thread Aswath Govindraju
Hi Nishanth,

On 09/03/21 9:28 pm, Nishanth Menon wrote:
> On 21:20-20210309, Aswath Govindraju wrote:
>> Hi Nishanth,
>>
>> On 09/03/21 8:13 pm, Nishanth Menon wrote:
>>> On 16:59-20210304, Aswath Govindraju wrote:
 The following series of patches adds support for gpio on AM642 evm/sk.

 Changes since v1:
 - Added DT for gpio subsystem present in MCU domain
 - reserved the mcu gpio for firmware usage

 This series of patches depend on,
 https://patchwork.kernel.org/project/linux-arm-kernel/list/?series=439039
 https://patchwork.kernel.org/project/linux-arm-kernel/list/?series=439153


 Aswath Govindraju (2):
   arm64: dts: ti: k3-am64: Add GPIO DT nodes
   arm64: dts: ti: k3-am642: reserve gpio in mcu domain for firmware
 usage

  arch/arm64/boot/dts/ti/k3-am64-main.dtsi | 45 
  arch/arm64/boot/dts/ti/k3-am64-mcu.dtsi  | 27 ++
  arch/arm64/boot/dts/ti/k3-am642-evm.dts  |  5 +++
  arch/arm64/boot/dts/ti/k3-am642-sk.dts   |  5 +++
  4 files changed, 82 insertions(+)

 -- 
 2.17.1

>>>
>>>
>>> Based on your offline comment:
>>> -
>>>
>>> On going through the bootlogs before posting for I found the following
>>> errors,
>>>
>>> [1.091117] davinci_gpio 601000.gpio: IRQ index 2 not found
>>> [1.101522] davinci_gpio 601000.gpio: error -ENXIO: IRQ not populated
>>>
>>> Some issues in allocating interrupts in case of main_gpio1. I
>>> accumulated the gpio with interrupt numbers. I'll try to debug the
>>> reason behind it and update you with its status. (bootlogs of ti-sdk,
>>> also have this error).
>>>
>>> -
>>>
>>> I am going to drop this off my queue, please update if the fixup is some
>>> system configuration error or repost with fix.
>>>
>>
>> This is expected to be a fixup in the system configuration and not a bug
>> in the patch series. So, can you please have these patches in your queue
>> ? I'll soon post the test results indicating the functioning of GPIOs.
> 
> 
> Thanks for clarifying. I will wait till the test results are posted.
> Thanks in advance for digging into this and detailed testing.
> 

I've posted a respin(v3) of this series after rebasing on top of
ti-k3-dts-next branch and adding the GPIO test logs.

Thanks,
Aswath


Re: [PATCH] futex: use wake_up_process() instead of wake_up_state()

2021-03-18 Thread Mike Galbraith
On Fri, 2021-03-19 at 10:59 +0800, Wang Qing wrote:
> Using wake_up_process() is more simpler and friendly,
> and it is more convenient for analysis and statistics

I likely needn't bother, and don't have a NAK to paste on this thing,
but here's another copy of my NOPE for yet another gratuitous change
with complete BS justification.

>
> Signed-off-by: Wang Qing 
> ---
>  kernel/futex.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/futex.c b/kernel/futex.c
> index e68db77..078a1f9
> --- a/kernel/futex.c
> +++ b/kernel/futex.c
> @@ -1820,7 +1820,7 @@ void requeue_pi_wake_futex(struct futex_q *q, union 
> futex_key *key,
>
>   q->lock_ptr = &hb->lock;
>
> - wake_up_state(q->task, TASK_NORMAL);
> + wake_up_process(q->task);
>  }
>
>  /**



RE: [PATCH 11/11] i2c: imx-lpi2c: add edma mode support

2021-03-18 Thread Aisheng Dong
> From: Clark Wang 
> Sent: Wednesday, March 17, 2021 2:54 PM
> 
> Add eDMA receive and send mode support.
> Support to read and write data larger than 256 bytes in one frame.
> 
> Signed-off-by: Clark Wang 
> Reviewed-by: Li Jun 
> ---
>  drivers/i2c/busses/i2c-imx-lpi2c.c | 291 -

Pease update dt-binding first

>  1 file changed, 289 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-imx-lpi2c.c
> b/drivers/i2c/busses/i2c-imx-lpi2c.c
> index 1e26672d47bf..6d920bf0dbd4 100644
> --- a/drivers/i2c/busses/i2c-imx-lpi2c.c
> +++ b/drivers/i2c/busses/i2c-imx-lpi2c.c
> @@ -8,6 +8,8 @@
>  #include 
>  #include 
>  #include 
> +#include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -31,6 +33,7 @@
>  #define LPI2C_MCR0x10/* i2c contrl register */
>  #define LPI2C_MSR0x14/* i2c status register */
>  #define LPI2C_MIER   0x18/* i2c interrupt enable */
> +#define LPI2C_MDER   0x1C/* i2c DMA enable */
>  #define LPI2C_MCFGR0 0x20/* i2c master configuration */
>  #define LPI2C_MCFGR1 0x24/* i2c master configuration */
>  #define LPI2C_MCFGR2 0x28/* i2c master configuration */
> @@ -72,11 +75,15 @@
>  #define MCFGR1_AUTOSTOP  BIT(8)
>  #define MCFGR1_IGNACKBIT(9)
>  #define MRDR_RXEMPTY BIT(14)
> +#define MDER_TDDEBIT(0)
> +#define MDER_RDDEBIT(1)
> 
>  #define I2C_CLK_RATIO24 / 59
>  #define CHUNK_DATA   256
> 
>  #define I2C_PM_TIMEOUT   1000 /* ms */
> +#define I2C_DMA_THRESHOLD16 /* bytes */
> +#define I2C_USE_PIO  (-150)

Can you clarify a bit why need using this strange value?

> 
>  enum lpi2c_imx_mode {
>   STANDARD,   /* <=100Kbps */
> @@ -95,6 +102,7 @@ enum lpi2c_imx_pincfg {
> 
>  struct lpi2c_imx_struct {
>   struct i2c_adapter  adapter;
> + resource_size_t phy_addr;
>   int irq;
>   struct clk  *clk_per;
>   struct clk  *clk_ipg;
> @@ -114,6 +122,17 @@ struct lpi2c_imx_struct {
>   struct pinctrl *pinctrl;
>   struct pinctrl_state *pinctrl_pins_default;
>   struct pinctrl_state *pinctrl_pins_gpio;
> +
> + boolcan_use_dma;
> + boolusing_dma;
> + boolxferred;
> + struct i2c_msg  *msg;
> + dma_addr_t  dma_addr;
> + struct dma_chan *dma_tx;
> + struct dma_chan *dma_rx;
> + enum dma_data_direction dma_direction;
> + u8  *dma_buf;
> + unsigned intdma_len;
>  };
> 
>  static void lpi2c_imx_intctrl(struct lpi2c_imx_struct *lpi2c_imx, @@ -289,6
> +308,9 @@ static int lpi2c_imx_master_enable(struct lpi2c_imx_struct
> *lpi2c_imx)
>   if (ret)
>   goto rpm_put;
> 
> + if (lpi2c_imx->can_use_dma)
> + writel(MDER_TDDE | MDER_RDDE, lpi2c_imx->base + LPI2C_MDER);
> +
>   temp = readl(lpi2c_imx->base + LPI2C_MCR);
>   temp |= MCR_MEN;
>   writel(temp, lpi2c_imx->base + LPI2C_MCR); @@ -462,6 +484,154 @@
> static void lpi2c_imx_read(struct lpi2c_imx_struct *lpi2c_imx,
>   lpi2c_imx_intctrl(lpi2c_imx, MIER_RDIE | MIER_NDIE);  }
> 
> +static void lpi2c_dma_unmap(struct lpi2c_imx_struct *lpi2c_imx) {
> + struct dma_chan *chan = lpi2c_imx->dma_direction ==
> DMA_FROM_DEVICE
> + ? lpi2c_imx->dma_rx : lpi2c_imx->dma_tx;
> +
> + dma_unmap_single(chan->device->dev, lpi2c_imx->dma_addr,
> +  lpi2c_imx->dma_len, lpi2c_imx->dma_direction);
> +
> + lpi2c_imx->dma_direction = DMA_NONE;
> +}
> +
> +static void lpi2c_cleanup_dma(struct lpi2c_imx_struct *lpi2c_imx) {
> + if (lpi2c_imx->dma_direction == DMA_NONE)
> + return;
> + else if (lpi2c_imx->dma_direction == DMA_FROM_DEVICE)
> + dmaengine_terminate_all(lpi2c_imx->dma_rx);
> + else if (lpi2c_imx->dma_direction == DMA_TO_DEVICE)
> + dmaengine_terminate_all(lpi2c_imx->dma_tx);
> +
> + lpi2c_dma_unmap(lpi2c_imx);
> +}
> +
> +static void lpi2c_dma_callback(void *data) {
> + struct lpi2c_imx_struct *lpi2c_imx = (struct lpi2c_imx_struct *)data;
> +
> + lpi2c_dma_unmap(lpi2c_imx);
> + writel(GEN_STOP << 8, lpi2c_imx->base + LPI2C_MTDR);
> + lpi2c_imx->xferred = true;
> +
> + complete(&lpi2c_imx->complete);
> +}
> +
> +static int lpi2c_dma_submit(struct lpi2c_imx_struct *lpi2c_imx,
> +struct i2c_msg *msg)
> +{
> + bool read = msg->flags & I2C_M_RD;
> + enum dma_data_direction dir = read ? DMA_FROM_DEVICE :
> DMA_TO_DEVICE;
> + struct dma_chan *chan = read ? lpi2c_imx->dma_rx : lpi2c_imx->dma_tx;
> + struct dma_async_tx_descriptor *txdesc;
> + dma_cookie_t cookie;
> +
> + lpi2c_imx->dma_len = read ? msg->len - 1 : msg->len;
> + lpi2c_imx->msg = msg;
> + lpi2c_imx->dma_direction = dir;
> +
> + if (IS_ERR(chan))
> + return PTR_ERR(chan);
> +
> + 

[PATCH] w1: slaves: Typo fixes

2021-03-18 Thread Bhaskar Chowdhury
s/mesured/measured/  ...twice

Signed-off-by: Bhaskar Chowdhury 
---
 drivers/w1/slaves/w1_therm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/w1/slaves/w1_therm.c b/drivers/w1/slaves/w1_therm.c
index 976eea28f268..d3b4ceb07622 100644
--- a/drivers/w1/slaves/w1_therm.c
+++ b/drivers/w1/slaves/w1_therm.c
@@ -63,8 +63,8 @@ static u16 bulk_read_device_counter; /* =0 as per C standard 
*/
 #define EEPROM_CMD_READ "restore"  /* cmd for read eeprom sysfs */
 #define BULK_TRIGGER_CMD"trigger"  /* cmd to trigger a bulk read */

-#define MIN_TEMP   -55 /* min temperature that can be mesured */
-#define MAX_TEMP   125 /* max temperature that can be mesured */
+#define MIN_TEMP   -55 /* min temperature that can be measured */
+#define MAX_TEMP   125 /* max temperature that can be measured */

 /* Allowed values for sysfs conv_time attribute */
 #define CONV_TIME_DEFAULT 0
--
2.26.2



[PATCH] io_uring: Try to merge io requests only for regular files

2021-03-18 Thread Dmitry Monakhov
Otherwise we may endup blocking on pipe or socket.

Fixes: 6d5d5ac ("io_uring: extend async work merge")
Testcase: 
https://github.com/dmonakhov/liburing/commit/16d171b6ef9d68e6db66650a83d98c5c721d01f6
Signed-off-by: Dmitry Monakhov 
---
 fs/io_uring.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 478df7e..848657c 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -2183,6 +2183,9 @@ static int __io_submit_sqe(struct io_ring_ctx *ctx, 
struct io_kiocb *req,
 static struct async_list *io_async_list_from_req(struct io_ring_ctx *ctx,
 struct io_kiocb *req)
 {
+   if (!(req->flags & REQ_F_ISREG))
+   return NULL;
+
switch (req->submit.opcode) {
case IORING_OP_READV:
case IORING_OP_READ_FIXED:
-- 
2.7.4



Re: [PATCH v8] i2c: virtio: add a virtio i2c frontend driver

2021-03-18 Thread Jie Deng



On 2021/3/19 11:54, Viresh Kumar wrote:

On 18-03-21, 15:52, Arnd Bergmann wrote:

Allowing multiple virtio-i2c controllers in one system, and multiple i2c
devices attached to each controller is clearly something that has to work.

Good.


I don't actually see a limitation though. Viresh, what is the problem
you see for having multiple controllers?

I thought this would be a problem in that case as we are using the global
virtio_adapter here.

+   vi->adap = &virtio_adapter;
+   i2c_set_adapdata(vi->adap, vi);

Multiple calls to probe() will end up updating the same pointer inside adap.

+   vi->adap->dev.parent = &vdev->dev;

Same here, overwrite.

+   /* Setup ACPI node for controlled devices which will be probed through 
ACPI */
+   ACPI_COMPANION_SET(&vi->adap->dev, ACPI_COMPANION(pdev));
+   vi->adap->timeout = HZ / 10;

These may be fine, but still not ideal I believe.

+   ret = i2c_add_adapter(vi->adap);
i
This should be a problem as well, we must be adding this to some sort of list,
doing some RPM stuff, etc ?

Jie, the solution is to allocate memory for adap at runtime in probe and remove
the virtio_adapter structure completely.



If you want to support that. Then I think we don't need to change the 
following at all.



+    .algo = &virtio_algorithm,
+
+    return ret;
+
+    vi->adap = virtio_adapter;

This is strange, why are you allocating memory for adapter twice ?
Once for virtio_adapter and once for vi->adap ? Either fill the fields
directly for v->adap here and remove virtio_adapter or make vi->adap a
pointer.




RE: [PATCH 02/11] i2c: imx-lpi2c: add runtime pm support

2021-03-18 Thread Clark Wang

> -Original Message-
> From: Aisheng Dong 
> Sent: Friday, March 19, 2021 12:40
> To: Clark Wang ; shawn...@kernel.org;
> s.ha...@pengutronix.de
> Cc: ker...@pengutronix.de; feste...@gmail.com; dl-linux-imx  i...@nxp.com>; sumit.sem...@linaro.org; christian.koe...@amd.com;
> linux-...@vger.kernel.org; linux-arm-ker...@lists.infradead.org; linux-
> ker...@vger.kernel.org
> Subject: RE: [PATCH 02/11] i2c: imx-lpi2c: add runtime pm support
> 
> > From: Clark Wang 
> > Sent: Wednesday, March 17, 2021 2:54 PM
> > Subject: [PATCH 02/11] i2c: imx-lpi2c: add runtime pm support
> >
> > - Add runtime pm support to dynamicly manage the clock.
> > - Put the suspend to suspend_noirq.
> > - Call .pm_runtime_force_suspend() to force runtime pm suspended
> >   in .suspend_noirq().
> >
> 
> The patch title needs to be improved as the driver already supports rpm.
> And do one thing in one patch.

Thanks. I will split this patch into several and resend.

Best Regards,
Clark Wang
> 
> > Signed-off-by: Fugang Duan 
> > Signed-off-by: Gao Pan 
> > Reviewed-by: Anson Huang 
> 
> Please add your sign-off.
> 
> > ---
> >  drivers/i2c/busses/i2c-imx-lpi2c.c | 50
> > --
> >  1 file changed, 33 insertions(+), 17 deletions(-)
> >
> > diff --git a/drivers/i2c/busses/i2c-imx-lpi2c.c
> > b/drivers/i2c/busses/i2c-imx-lpi2c.c
> > index bbf44ac95021..1e920e7ac7c1 100644
> > --- a/drivers/i2c/busses/i2c-imx-lpi2c.c
> > +++ b/drivers/i2c/busses/i2c-imx-lpi2c.c
> > @@ -574,7 +574,8 @@ static int lpi2c_imx_probe(struct platform_device
> > *pdev)
> > if (ret)
> > lpi2c_imx->bitrate = I2C_MAX_STANDARD_MODE_FREQ;
> >
> > -   ret = devm_request_irq(&pdev->dev, irq, lpi2c_imx_isr, 0,
> > +   ret = devm_request_irq(&pdev->dev, irq, lpi2c_imx_isr,
> > +  IRQF_NO_SUSPEND,
> 
> This belongs to a separate patch
> 
> >pdev->name, lpi2c_imx);
> > if (ret) {
> > dev_err(&pdev->dev, "can't claim irq %d\n", irq); @@ -
> 584,35
> > +585,32 @@ static int lpi2c_imx_probe(struct platform_device *pdev)
> > i2c_set_adapdata(&lpi2c_imx->adapter, lpi2c_imx);
> > platform_set_drvdata(pdev, lpi2c_imx);
> >
> > -   ret = clk_prepare_enable(lpi2c_imx->clk);
> > -   if (ret) {
> > -   dev_err(&pdev->dev, "clk enable failed %d\n", ret);
> > -   return ret;
> > -   }
> > -
> > pm_runtime_set_autosuspend_delay(&pdev->dev,
> I2C_PM_TIMEOUT);
> > pm_runtime_use_autosuspend(&pdev->dev);
> > -   pm_runtime_get_noresume(&pdev->dev);
> > -   pm_runtime_set_active(&pdev->dev);
> > pm_runtime_enable(&pdev->dev);
> >
> > +   ret = pm_runtime_get_sync(&pdev->dev);
> > +   if (ret < 0) {
> > +   pm_runtime_put_noidle(&pdev->dev);
> > +   dev_err(&pdev->dev, "failed to enable clock\n");
> > +   return ret;
> > +   }
> 
> Can't current clk control via rpm work well?
> Please describe why need change.
> 
> > +
> > temp = readl(lpi2c_imx->base + LPI2C_PARAM);
> > lpi2c_imx->txfifosize = 1 << (temp & 0x0f);
> > lpi2c_imx->rxfifosize = 1 << ((temp >> 8) & 0x0f);
> >
> > +   pm_runtime_put(&pdev->dev);
> > +
> > ret = i2c_add_adapter(&lpi2c_imx->adapter);
> > if (ret)
> > goto rpm_disable;
> >
> > -   pm_runtime_mark_last_busy(&pdev->dev);
> > -   pm_runtime_put_autosuspend(&pdev->dev);
> > -
> > dev_info(&lpi2c_imx->adapter.dev, "LPI2C adapter registered\n");
> >
> > return 0;
> >
> >  rpm_disable:
> > -   pm_runtime_put(&pdev->dev);
> > pm_runtime_disable(&pdev->dev);
> > pm_runtime_dont_use_autosuspend(&pdev->dev);
> >
> > @@ -636,7 +634,7 @@ static int __maybe_unused
> > lpi2c_runtime_suspend(struct device *dev)
> > struct lpi2c_imx_struct *lpi2c_imx = dev_get_drvdata(dev);
> >
> > clk_disable_unprepare(lpi2c_imx->clk);
> > -   pinctrl_pm_select_sleep_state(dev);
> > +   pinctrl_pm_select_idle_state(dev);
> 
> This belongs to a separate patch
> 
> >
> > return 0;
> >  }
> > @@ -649,16 +647,34 @@ static int __maybe_unused
> > lpi2c_runtime_resume(struct device *dev)
> > pinctrl_pm_select_default_state(dev);
> > ret = clk_prepare_enable(lpi2c_imx->clk);
> > if (ret) {
> > -   dev_err(dev, "failed to enable I2C clock, ret=%d\n", ret);
> > +   dev_err(dev, "can't enable I2C clock, ret=%d\n", ret);
> 
> Probably unnecessary change
> 
> > return ret;
> > }
> >
> > +   return ret;
> > +}
> > +
> > +static int lpi2c_suspend_noirq(struct device *dev) {
> > +   int ret;
> > +
> > +   ret = pm_runtime_force_suspend(dev);
> > +   if (ret)
> > +   return ret;
> > +
> > +   pinctrl_pm_select_sleep_state(dev);
> > +
> > return 0;
> >  }
> >
> > +static int lpi2c_resume_noirq(struct device *dev) {
> > +   return pm_runtime_force_resume(dev); }
> > +
> >  static const struct dev_pm_ops lpi2c_pm_ops = {
> > -   SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
> > - pm_runtime_

Re: [PATCHv2 3/3] media: uvcvideo: add UVC 1.5 ROI control

2021-03-18 Thread Sergey Senozhatsky
On (21/03/18 22:19), Ricardo Ribalda wrote:
> >
> > May I please ask for more opinions on this?
> 
> Could you try setting the roi in a loop in your device and verify that
> it accepts all the values with no modification. If so we can implement
> the set/get as a quirk for other devices.

Tested on two (very) different devices.

Firmware D:

   CLAP all passed, we are cool

Firmware H:

   CLAP all passed, we are cool


Code sample

---
   in_selection.target = V4L2_SEL_TGT_ROI;
   in_selection.flags  = V4L2_SEL_FLAG_ROI_AUTO_EXPOSURE;

   for (int i = 0; i < 1001; i++) {
   in_selection.r.left = 0 + i;
   in_selection.r.top  = 0 + i;
   in_selection.r.width= 42 + i;
   in_selection.r.height   = 42 + i;

   ret = doioctl(fd, VIDIOC_S_SELECTION, &in_selection);
   if (ret) {
   fprintf(stderr, "BOOM %d\n", ret);
   exit(1);
   }

   ret = doioctl(fd, VIDIOC_G_SELECTION, &in_selection);
   if (ret) {
   fprintf(stderr, "BANG %d\n", ret);
   exit(2);
   }

   if (in_selection.r.left != i ||
   in_selection.r.top != i ||
   in_selection.r.width != i + 42 ||
   in_selection.r.height != i + 42) {

   fprintf(stderr, "SNAP %d %d %d %d != %d %d %d %d\n",
   i, i, i + 42, i + 42,
   in_selection.r.left,
   in_selection.r.top,
   in_selection.r.width,
   in_selection.r.height);
   exit(3);
   }
   }

   fprintf(stderr, "CLAP all passed, we are cool\n");
---


Re: [PATCH] selftests/sgx: improve error detection and messages

2021-03-18 Thread Jarkko Sakkinen
On Thu, Mar 18, 2021 at 12:43:01PM -0700, Dave Hansen wrote:
> 
> From: Dave Hansen 
> 
> The SGX device file (/dev/sgx_enclave) is unusual in that it requires
> execute permissions.  It has to be both "chmod +x" *and* be on a
> filesystem without 'noexec'.
> 
> In the future, udev and systemd should get updates to set up systems
> automatically.  But, for now, nobody's systems do this automatically,
> and everybody gets error messages like this when running ./test_sgx:
> 
>   0x 0x2000 0x03
>   0x2000 0x1000 0x05
>   0x3000 0x3000 0x03
>   mmap() failed, errno=1.
> 
> That isn't very user friendly, even for forgetful kernel developers.
> 
> Further, the test case is rather haphazard about its use of fprintf()
> versus perror().
> 
> Improve the error messages.  Use perror() where possible.  Lastly,
> do some sanity checks on opening and mmap()ing the device file so
> that we can get a decent error message out to the user.
> 
> Now, if your user doesn't have permission, you'll get the following:
> 
>   $ ls -l /dev/sgx_enclave
>   crw--- 1 root root 10, 126 Mar 18 11:29 /dev/sgx_enclave
>   $ ./test_sgx
>   Unable to open /dev/sgx_enclave: Permission denied
> 
> If you then 'chown dave:dave /dev/sgx_enclave' (or whatever), but
> you leave execute permissions off, you'll get:
> 
>   $ ls -l /dev/sgx_enclave
>   crw--- 1 dave dave 10, 126 Mar 18 11:29 /dev/sgx_enclave
>   $ ./test_sgx
>   no execute permissions on device file
> 
> If you fix that with "chmod ug+x /dev/sgx" but you leave /dev as
> noexec, you'll get this:
> 
>   $ mount | grep "/dev .*noexec"
>   udev on /dev type devtmpfs (rw,nosuid,noexec,...)
>   $ ./test_sgx
>   ERROR: mmap for exec: Operation not permitted
>   mmap() succeeded for PROT_READ, but failed for PROT_EXEC
>   check that user has execute permissions on /dev/sgx_enclave and
>   that /dev does not have noexec set: 'mount | grep "/dev .*noexec"'
> 
> That can be fixed with:
> 
>   mount -o remount,noexec /devESC
> 
> Hopefully, the combination of better error messages and the search
> engines indexing this message will help people fix their systems
> until we do this properly.
> 
> Signed-off-by: Dave Hansen 
> Cc: Jarkko Sakkinen 
> Cc: Shuah Khan 
> Cc: Borislav Petkov 
> Cc: x...@kernel.org
> Cc: linux-...@vger.kernel.org
> Cc: linux-kselft...@vger.kernel.org


Reviewed-by: Jarkko Sakkinen 

> ---
> 
>  b/tools/testing/selftests/sgx/load.c |   66 
> +++
>  b/tools/testing/selftests/sgx/main.c |2 -
>  2 files changed, 53 insertions(+), 15 deletions(-)
> 
> diff -puN tools/testing/selftests/sgx/load.c~sgx-selftest-err-rework 
> tools/testing/selftests/sgx/load.c
> --- a/tools/testing/selftests/sgx/load.c~sgx-selftest-err-rework  
> 2021-03-18 12:18:38.649828215 -0700
> +++ b/tools/testing/selftests/sgx/load.c  2021-03-18 12:40:46.388824904 
> -0700
> @@ -45,19 +45,19 @@ static bool encl_map_bin(const char *pat
>  
>   fd = open(path, O_RDONLY);
>   if (fd == -1)  {
> - perror("open()");
> + perror("enclave executable open()");
>   return false;
>   }
>  
>   ret = stat(path, &sb);
>   if (ret) {
> - perror("stat()");
> + perror("enclave executable stat()");
>   goto err;
>   }
>  
>   bin = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
>   if (bin == MAP_FAILED) {
> - perror("mmap()");
> + perror("enclave executable mmap()");
>   goto err;
>   }
>  
> @@ -90,8 +90,7 @@ static bool encl_ioc_create(struct encl
>   ioc.src = (unsigned long)secs;
>   rc = ioctl(encl->fd, SGX_IOC_ENCLAVE_CREATE, &ioc);
>   if (rc) {
> - fprintf(stderr, "SGX_IOC_ENCLAVE_CREATE failed: errno=%d\n",
> - errno);
> + perror("SGX_IOC_ENCLAVE_CREATE failed");
>   munmap((void *)secs->base, encl->encl_size);
>   return false;
>   }
> @@ -116,31 +115,69 @@ static bool encl_ioc_add_pages(struct en
>  
>   rc = ioctl(encl->fd, SGX_IOC_ENCLAVE_ADD_PAGES, &ioc);
>   if (rc < 0) {
> - fprintf(stderr, "SGX_IOC_ENCLAVE_ADD_PAGES failed: errno=%d.\n",
> - errno);
> + perror("SGX_IOC_ENCLAVE_ADD_PAGES failed");
>   return false;
>   }
>  
>   return true;
>  }
>  
> +
> +
>  bool encl_load(const char *path, struct encl *encl)
>  {
> + const char device_path[] = "/dev/sgx_enclave";
>   Elf64_Phdr *phdr_tbl;
>   off_t src_offset;
>   Elf64_Ehdr *ehdr;
> + struct stat sb;
> + void *ptr;
>   int i, j;
>   int ret;
> + int fd = -1;
>  
>   memset(encl, 0, sizeof(*encl));
>  
> - ret = open("/dev/sgx_enclave", O_RDWR);
> - if (ret < 0) {
> - fprintf(stderr, "

Re: [PATCH] x86/sgx: fix uninitialized 'nid' variable

2021-03-18 Thread Jarkko Sakkinen
On Thu, Mar 18, 2021 at 02:49:33PM -0700, Dave Hansen wrote:
> The NUMA fallback in __sgx_alloc_epc_page() recently grew an
> additional 'nid' variable to prevent extra trips through the
> fallback loop in case where the thread is migrated around.
> 
> But, the new copy is not properly initialized.  Fix it.
> 
> This was found by some fancy clang that 0day runs.  My gcc
> does not detect it.
> 
> Fixes: 5b8719504e3a ("x86/sgx: Add a basic NUMA allocation scheme to 
> sgx_alloc_epc_page()")
> Reported-by: kernel test robot 
> Signed-off-by: Dave Hansen 
> Cc: Jarkko Sakkinen 
> Cc: Borislav Petkov 
> Cc: x...@kernel.org
> Cc: linux-...@vger.kernel.org


Reviewed-by: Jarkko Sakkinen 

> ---
>  arch/x86/kernel/cpu/sgx/main.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c
> index 2a0031e4a4dc..1b4d8a0e0915 100644
> --- a/arch/x86/kernel/cpu/sgx/main.c
> +++ b/arch/x86/kernel/cpu/sgx/main.c
> @@ -489,7 +489,7 @@ struct sgx_epc_page *__sgx_alloc_epc_page(void)
>  {
>   struct sgx_epc_page *page;
>   int nid_of_current = numa_node_id();
> - int nid;
> + int nid = nid_of_current;
>  
>   if (node_isset(nid_of_current, sgx_numa_mask)) {
>   page = __sgx_alloc_epc_page_from_node(nid_of_current);
> -- 
> 2.19.1
> 
> 

/Jarkko


Re: [PATCH 06/11] i2c: imx-lpi2c: improve i2c driver probe priority

2021-03-18 Thread Wolfram Sang
On Wed, Mar 17, 2021 at 02:53:54PM +0800, Clark Wang wrote:
> From: Gao Pan 
> 
> use subsys_initcall for i2c driver to improve i2c driver probe priority
> 
> Signed-off-by: Gao Pan 

I usually don't take subsys_initcall patches anymore. In most cases, the
client drivers can be fixed instead. If this is not the case for you,
you need to state that explicitly in the commit message.



signature.asc
Description: PGP signature


Re: [PATCH v8] i2c: virtio: add a virtio i2c frontend driver

2021-03-18 Thread Viresh Kumar
On 19-03-21, 13:31, Jie Deng wrote:
> 
> On 2021/3/19 11:54, Viresh Kumar wrote:
> > On 18-03-21, 15:52, Arnd Bergmann wrote:
> > > Allowing multiple virtio-i2c controllers in one system, and multiple i2c
> > > devices attached to each controller is clearly something that has to work.
> > Good.
> > 
> > > I don't actually see a limitation though. Viresh, what is the problem
> > > you see for having multiple controllers?
> > I thought this would be a problem in that case as we are using the global
> > virtio_adapter here.
> > 
> > +   vi->adap = &virtio_adapter;
> > +   i2c_set_adapdata(vi->adap, vi);
> > 
> > Multiple calls to probe() will end up updating the same pointer inside adap.
> > 
> > +   vi->adap->dev.parent = &vdev->dev;
> > 
> > Same here, overwrite.
> > 
> > +   /* Setup ACPI node for controlled devices which will be probed 
> > through ACPI */
> > +   ACPI_COMPANION_SET(&vi->adap->dev, ACPI_COMPANION(pdev));
> > +   vi->adap->timeout = HZ / 10;
> > 
> > These may be fine, but still not ideal I believe.
> > 
> > +   ret = i2c_add_adapter(vi->adap);
> > i
> > This should be a problem as well, we must be adding this to some sort of 
> > list,
> > doing some RPM stuff, etc ?
> > 
> > Jie, the solution is to allocate memory for adap at runtime in probe and 
> > remove
> > the virtio_adapter structure completely.
> 
> 
> If you want to support that. Then I think we don't need to change the
> following at all.
> 
> > +    .algo = &virtio_algorithm,
> > +
> > +    return ret;
> > +
> > +    vi->adap = virtio_adapter;
> This is strange, why are you allocating memory for adapter twice ?
> Once for virtio_adapter and once for vi->adap ? Either fill the fields
> directly for v->adap here and remove virtio_adapter or make vi->adap a
> pointer.

Yes, your previous version was partly okay but you don't need the
virtio_algorithm structure to be allocated. There are only 4 fields you are
updating here, just fill them directly in vi->adap.

(FWIW, I also suggested the same when I said
"Either fill the fields directly for v->adap here and remove virtio_adapter".
)

See how drivers/i2c/busses/i2c-versatile.c and most of the other drivers have
done it.

-- 
viresh


Re: remove the legacy ide driver

2021-03-18 Thread Christoph Hellwig
On Fri, Mar 19, 2021 at 12:43:48PM +1100, Finn Thain wrote:
> A few months ago I wrote another patch to move some more platforms away 
> from macide but it has not been tested yet. That is not to say you should 
> wait. However, my patch does have some changes that are missing from your 
> patch series, relating to ide platform devices in arch/m68k/mac/config.c. 
> I hope to be able to test this patch before the 5.13 merge window closes.

Normally we do not remove drivers for hardware that is still used.  So
at leat for macide my plan was not to take it away unless the users 
are sufficiently happy.  Or in other words:  I think waiting it the
right choice, but hopefully we can make that wait as short as possible.


Re: [PATCH] x86/sgx: Avoid returning NULL in __sgx_alloc_epc_page()

2021-03-18 Thread Jarkko Sakkinen
On Fri, Mar 19, 2021 at 05:06:02PM +1300, Kai Huang wrote:
> Below kernel bug happened when running simple SGX application when EPC
> is under pressure.  The root cause is with commit 5b8719504e3a
> ("x86/sgx: Add a basic NUMA allocation scheme to sgx_alloc_epc_page()"),
> __sgx_alloc_epc_page() returns NULL when there's no free EPC page can be
> allocated, while old behavior was it always returned ERR_PTR(-ENOMEM) in
> such case.
> 
> Fix by directly returning the page if __sgx_alloc_epc_page_from_node()
> allocates a valid page in fallback to non-local allocation, and always
> returning ERR_PTR(-ENOMEM) if no EPC page can be allocated.
> 
> [  253.474764] BUG: kernel NULL pointer dereference, address: 0008
> [  253.500101] #PF: supervisor write access in kernel mode
> [  253.525462] #PF: error_code(0x0002) - not-present page
> ...
> [  254.102041] Call Trace:
> [  254.126699]  sgx_ioc_enclave_add_pages+0x241/0x770
> [  254.151305]  sgx_ioctl+0x194/0x4b0
> [  254.174976]  ? handle_mm_fault+0xd0/0x260
> [  254.198470]  ? do_user_addr_fault+0x1ef/0x570
> [  254.221827]  __x64_sys_ioctl+0x91/0xc0
> [  254.244546]  do_syscall_64+0x38/0x90
> [  254.266728]  entry_SYSCALL_64_after_hwframe+0x44/0xae
> [  254.289232] RIP: 0033:0x7fdc4cf4031b
> ...
> [  254.711480] CR2: 0008
> [  254.735494] ---[ end trace 970dce6d4cdf7f64 ]---
> [  254.759915] RIP: 0010:sgx_alloc_epc_page+0x46/0x152
> ...
> 
> Fixes: 5b8719504e3a("x86/sgx: Add a basic NUMA allocation scheme to 
> sgx_alloc_epc_page()")
> Signed-off-by: Kai Huang 


Reviewed-by: Jarkko Sakkinen 

> ---
>  arch/x86/kernel/cpu/sgx/main.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c
> index fe26e7e91c25..7105e34da530 100644
> --- a/arch/x86/kernel/cpu/sgx/main.c
> +++ b/arch/x86/kernel/cpu/sgx/main.c
> @@ -508,10 +508,10 @@ struct sgx_epc_page *__sgx_alloc_epc_page(void)
>  
>   page = __sgx_alloc_epc_page_from_node(nid);
>   if (page)
> - break;
> + return page;
>   }
>  
> - return page;
> + return ERR_PTR(-ENOMEM);
>  }
>  
>  /**
> -- 
> 2.30.2
> 
> 

/Jarkko


[PATCH] drm/amd/display: Set AMDGPU_DM_DEFAULT_MIN_BACKLIGHT to 0

2021-03-18 Thread Evan Benn
AMDGPU_DM_DEFAULT_MIN_BACKLIGHT was set to the value of 12
to ensure no display backlight will flicker at low user brightness
settings. However this value is quite bright, so for devices that do not
implement the ACPI ATIF
ATIF_FUNCTION_QUERY_BRIGHTNESS_TRANSFER_CHARACTERISTICS
functionality the user cannot set the brightness to a low level even if
the display would support such a low PWM.

This ATIF feature is not implemented on for example AMD grunt chromebooks.

Signed-off-by: Evan Benn 

---
I could not find a justification for the reason for the value. It has
caused some noticable regression for users: 
https://bugzilla.kernel.org/show_bug.cgi?id=203439

Maybe this can be either user controlled or userspace configured, but
preventing users from turning their backlight dim seems wrong.

Also reviewed here: 
https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/2748377

 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c 
b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
index 573cf17262da..0129bd69b94e 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -3151,7 +3151,7 @@ static int amdgpu_dm_mode_config_init(struct 
amdgpu_device *adev)
return 0;
 }
 
-#define AMDGPU_DM_DEFAULT_MIN_BACKLIGHT 12
+#define AMDGPU_DM_DEFAULT_MIN_BACKLIGHT 0
 #define AMDGPU_DM_DEFAULT_MAX_BACKLIGHT 255
 #define AUX_BL_DEFAULT_TRANSITION_TIME_MS 50
 
-- 
2.31.0.291.g576ba9dcdaf-goog



[PATCH] MAINTAINERS: update Senozhatsky email address

2021-03-18 Thread Sergey Senozhatsky
I don't check my @gmail.com addresses often enough these days.

Signed-off-by: Sergey Senozhatsky 
---
 MAINTAINERS | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index b2baeb5e4a68..01b000cd5774 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -14433,7 +14433,7 @@ F:  kernel/sched/psi.c
 
 PRINTK
 M: Petr Mladek 
-M: Sergey Senozhatsky 
+M: Sergey Senozhatsky 
 R: Steven Rostedt 
 R: John Ogness 
 S: Maintained
@@ -19293,7 +19293,7 @@ F:  drivers/net/vrf.c
 VSPRINTF
 M: Petr Mladek 
 M: Steven Rostedt 
-M: Sergey Senozhatsky 
+M: Sergey Senozhatsky 
 R: Andy Shevchenko 
 R: Rasmus Villemoes 
 S: Maintained
@@ -19944,7 +19944,7 @@ F:  drivers/staging/media/zoran/
 ZRAM COMPRESSED RAM BLOCK DEVICE DRVIER
 M: Minchan Kim 
 M: Nitin Gupta 
-R: Sergey Senozhatsky 
+R: Sergey Senozhatsky 
 L: linux-kernel@vger.kernel.org
 S: Maintained
 F: Documentation/admin-guide/blockdev/zram.rst
@@ -19958,7 +19958,7 @@ F:  drivers/tty/serial/zs.*
 ZSMALLOC COMPRESSED SLAB MEMORY ALLOCATOR
 M: Minchan Kim 
 M: Nitin Gupta 
-R: Sergey Senozhatsky 
+R: Sergey Senozhatsky 
 L: linux...@kvack.org
 S: Maintained
 F: Documentation/vm/zsmalloc.rst
-- 
2.31.0.rc2.261.g7f71774620-goog



[PATCH 1/2] mm: memcontrol: don't allocate cgroup swap arrays when memcg is disabled

2021-03-18 Thread Johannes Weiner
Since commit 2d1c498072de ("mm: memcontrol: make swap tracking an
integral part of memory control"), the cgroup swap arrays are used to
track memory ownership at the time of swap readahead and swapoff, even
if swap space *accounting* has been turned off by the user via
swapaccount=0 (which sets cgroup_memory_noswap).

However, the patch was overzealous: by simply dropping the
cgroup_memory_noswap conditionals in the swapon, swapoff and uncharge
path, it caused the cgroup arrays being allocated even when the memory
controller as a whole is disabled. This is a waste of that memory.

Restore mem_cgroup_disabled() checks, implied previously by
cgroup_memory_noswap, in the swapon, swapoff, and swap_entry_free
callbacks.

Fixes: 2d1c498072de ("mm: memcontrol: make swap tracking an integral part of 
memory control")
Reported-by: Hugh Dickins 
Signed-off-by: Johannes Weiner 
---
 mm/memcontrol.c  | 3 +++
 mm/swap_cgroup.c | 6 ++
 2 files changed, 9 insertions(+)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 668d1d7c2645..49bdcf603af1 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -7101,6 +7101,9 @@ void mem_cgroup_uncharge_swap(swp_entry_t entry, unsigned 
int nr_pages)
struct mem_cgroup *memcg;
unsigned short id;
 
+   if (mem_cgroup_disabled())
+   return;
+
id = swap_cgroup_record(entry, 0, nr_pages);
rcu_read_lock();
memcg = mem_cgroup_from_id(id);
diff --git a/mm/swap_cgroup.c b/mm/swap_cgroup.c
index 7f34343c075a..08c3246f9269 100644
--- a/mm/swap_cgroup.c
+++ b/mm/swap_cgroup.c
@@ -171,6 +171,9 @@ int swap_cgroup_swapon(int type, unsigned long max_pages)
unsigned long length;
struct swap_cgroup_ctrl *ctrl;
 
+   if (mem_cgroup_disabled())
+   return 0;
+
length = DIV_ROUND_UP(max_pages, SC_PER_PAGE);
array_size = length * sizeof(void *);
 
@@ -206,6 +209,9 @@ void swap_cgroup_swapoff(int type)
unsigned long i, length;
struct swap_cgroup_ctrl *ctrl;
 
+   if (mem_cgroup_disabled())
+   return;
+
mutex_lock(&swap_cgroup_mutex);
ctrl = &swap_cgroup_ctrl[type];
map = ctrl->map;
-- 
2.30.1



[PATCH 2/2] mm: memcontrol: deprecate swapaccounting=0 mode

2021-03-18 Thread Johannes Weiner
The swapaccounting= commandline option already does very little
today. To close a trivial containment failure case, the swap ownership
tracking part of the swap controller has recently become mandatory
(see commit 2d1c498072de ("mm: memcontrol: make swap tracking an
integral part of memory control") for details), which makes up the
majority of the work during swapout, swapin, and the swap slot map.

The only thing left under this flag is the page_counter operations and
the visibility of the swap control files in the first place, which are
rather meager savings. There also aren't many scenarios, if any, where
controlling the memory of a cgroup while allowing it unlimited access
to a global swap space is a workable resource isolation stragegy.

On the other hand, there have been several bugs and confusion around
the many possible swap controller states (cgroup1 vs cgroup2 behavior,
memory accounting without swap accounting, memcg runtime disabled).

This puts the maintenance overhead of retaining the toggle above its
practical benefits. Deprecate it.

Suggested-by: Shakeel Butt 
Signed-off-by: Johannes Weiner 
---
 .../admin-guide/kernel-parameters.txt |  5 --
 include/linux/memcontrol.h|  4 --
 mm/memcontrol.c   | 48 ++-
 3 files changed, 15 insertions(+), 42 deletions(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt 
b/Documentation/admin-guide/kernel-parameters.txt
index 942bbef8f128..986d45dd8c37 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -5322,11 +5322,6 @@
This parameter controls use of the Protected
Execution Facility on pSeries.
 
-   swapaccount=[0|1]
-   [KNL] Enable accounting of swap in memory resource
-   controller if no parameter or 1 is given or disable
-   it if 0 is given (See 
Documentation/admin-guide/cgroup-v1/memory.rst)
-
swiotlb=[ARM,IA-64,PPC,MIPS,X86]
Format: {  | force | noforce }
 -- Number of I/O TLB slabs
diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 4064c9dda534..ef9613538d36 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -874,10 +874,6 @@ struct mem_cgroup *mem_cgroup_get_oom_group(struct 
task_struct *victim,
struct mem_cgroup *oom_domain);
 void mem_cgroup_print_oom_group(struct mem_cgroup *memcg);
 
-#ifdef CONFIG_MEMCG_SWAP
-extern bool cgroup_memory_noswap;
-#endif
-
 void lock_page_memcg(struct page *page);
 void unlock_page_memcg(struct page *page);
 
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 49bdcf603af1..b036c4fb0fa7 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -85,13 +85,6 @@ static bool cgroup_memory_nosocket;
 /* Kernel memory accounting disabled? */
 static bool cgroup_memory_nokmem;
 
-/* Whether the swap controller is active */
-#ifdef CONFIG_MEMCG_SWAP
-bool cgroup_memory_noswap __read_mostly;
-#else
-#define cgroup_memory_noswap   1
-#endif
-
 #ifdef CONFIG_CGROUP_WRITEBACK
 static DECLARE_WAIT_QUEUE_HEAD(memcg_cgwb_frn_waitq);
 #endif
@@ -99,7 +92,11 @@ static DECLARE_WAIT_QUEUE_HEAD(memcg_cgwb_frn_waitq);
 /* Whether legacy memory+swap accounting is active */
 static bool do_memsw_account(void)
 {
-   return !cgroup_subsys_on_dfl(memory_cgrp_subsys) && 
!cgroup_memory_noswap;
+   /* cgroup2 doesn't do mem+swap accounting */
+   if (cgroup_subsys_on_dfl(memory_cgrp_subsys))
+   return false;
+
+   return true;
 }
 
 #define THRESHOLDS_EVENTS_TARGET 128
@@ -7019,7 +7016,7 @@ void mem_cgroup_swapout(struct page *page, swp_entry_t 
entry)
if (!mem_cgroup_is_root(memcg))
page_counter_uncharge(&memcg->memory, nr_entries);
 
-   if (!cgroup_memory_noswap && memcg != swap_memcg) {
+   if (memcg != swap_memcg) {
if (!mem_cgroup_is_root(swap_memcg))
page_counter_charge(&swap_memcg->memsw, nr_entries);
page_counter_uncharge(&memcg->memsw, nr_entries);
@@ -7073,7 +7070,7 @@ int mem_cgroup_try_charge_swap(struct page *page, 
swp_entry_t entry)
 
memcg = mem_cgroup_id_get_online(memcg);
 
-   if (!cgroup_memory_noswap && !mem_cgroup_is_root(memcg) &&
+   if (!mem_cgroup_is_root(memcg) &&
!page_counter_try_charge(&memcg->swap, nr_pages, &counter)) {
memcg_memory_event(memcg, MEMCG_SWAP_MAX);
memcg_memory_event(memcg, MEMCG_SWAP_FAIL);
@@ -7108,7 +7105,7 @@ void mem_cgroup_uncharge_swap(swp_entry_t entry, unsigned 
int nr_pages)
rcu_read_lock();
memcg = mem_cgroup_from_id(id);
if (memcg) {
-   if (!cgroup_memory_noswap && !mem_cgroup_is_root(memcg)) {
+   if (!mem_cgroup_is_root(memcg)) {
 

Re: [PATCH 1/1] leds: lgm: Improve Kconfig help

2021-03-18 Thread Rahul Tanwar
Hi Pavel,

On 19/3/2021 4:37 am, Pavel Machek wrote:
> Hi!
> 
> 
>  > > > help
>  > > > - Parallel to serial conversion, which is also called SSO
>  > > > controller,
>  > > > - can drive external shift register for LED outputs.
>  > > > - This enables LED support for Serial Shift Output controller(SSO).
>  > > > + This option enables support for LEDs connected to GPIO lines on
>  > > > + Lightning Mountain(LGM) SoC. These LEDs are driven by a Serial
>  > > > + Shift Output(SSO) controller. The driver supports hardware
>  > >
>  > > What is Lightning Mountain? The codename is not widely known. Where
>  > > can we find that hardware? Notebooks? Phones? Only some development
>  > > boards?
>  > >
>  >
>  > Lightning Mountain is generically a network processor with a primary
>  > targeted application as Gateway SoC. It has already been added as a
>  > valid Intel Atom processor variant in
>  > arch/x86/include/asm/intel-family.h as below:
> 
> Yep, but Kconfig users are not going to read header files.
> 
> If the SoC is not shipping in any products, state so.
> 


Got your point. Will update the help text.


>  > > > *
>  > > > - * Copyright (c) 2020 Intel Corporation.
>  > > > + * Copyright (c) 2021 MaxLinear, Inc.
>  > > > */
>  > > >
>  > >
>  > > I don't think you can do that, and I don't think you should be doing
>  > > it in the same patch.
>  >
>  > Well noted. Will revert it back now and update later in a separate
>  > patch. Thanks.
> 
> Don't. You can't update copyright like that.
>

Well noted.

Regards,
Rahul


> Pavel
> -- 
> http://www.livejournal.com/~pavelmachek 
> 





Re: [PATCH] fs/cifs/: fix misspellings using codespell tool

2021-03-18 Thread Steve French
merged into cifs-2.6.git for-next

On Thu, Mar 18, 2021 at 7:50 PM  wrote:
>
> From: Liu xuzhi 
>
> A typo is found out by codespell tool in 251th lines of cifs_swn.c:
>
> $ codespell ./fs/cifs/
> ./cifs_swn.c:251: funciton  ==> function
>
> Fix a typo found by codespell.
>
> Signed-off-by: Liu xuzhi 
> ---
>  fs/cifs/cifs_swn.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/cifs/cifs_swn.c b/fs/cifs/cifs_swn.c
> index f2d730fffccb..d829b8bf833e 100644
> --- a/fs/cifs/cifs_swn.c
> +++ b/fs/cifs/cifs_swn.c
> @@ -248,7 +248,7 @@ static int cifs_swn_send_unregister_message(struct 
> cifs_swn_reg *swnreg)
>
>  /*
>   * Try to find a matching registration for the tcon's server name and share 
> name.
> - * Calls to this funciton must be protected by cifs_swnreg_idr_mutex.
> + * Calls to this function must be protected by cifs_swnreg_idr_mutex.
>   * TODO Try to avoid memory allocations
>   */
>  static struct cifs_swn_reg *cifs_find_swn_reg(struct cifs_tcon *tcon)
> --
> 2.25.1
>


-- 
Thanks,

Steve


Re: [PATCH v8] i2c: virtio: add a virtio i2c frontend driver

2021-03-18 Thread Viresh Kumar
On 16-03-21, 18:35, Jie Deng wrote:
> +++ b/drivers/i2c/busses/i2c-virtio.c
> +static int virtio_i2c_send_reqs(struct virtqueue *vq,
> + struct virtio_i2c_req *reqs,
> + struct i2c_msg *msgs, int nr)
> +{
> + struct scatterlist *sgs[3], out_hdr, msg_buf, in_hdr;
> + int i, outcnt, incnt, err = 0;
> +
> + for (i = 0; i < nr; i++) {
> + if (!msgs[i].len)
> + break;
> +
> + /*
> +  * Only 7-bit mode supported for this moment. For the address 
> format,
> +  * Please check the Virtio I2C Specification.
> +  */
> + reqs[i].out_hdr.addr = cpu_to_le16(msgs[i].addr << 1);
> +
> + if (i != nr - 1)
> + reqs[i].out_hdr.flags = 
> cpu_to_le32(VIRTIO_I2C_FLAGS_FAIL_NEXT);
> +
> + outcnt = incnt = 0;
> + sg_init_one(&out_hdr, &reqs[i].out_hdr, 
> sizeof(reqs[i].out_hdr));
> + sgs[outcnt++] = &out_hdr;
> +
> + reqs[i].buf = i2c_get_dma_safe_msg_buf(&msgs[i], 1);

You allocate a buffer here, lets see if they are freeing properly or not (I
remember that I gave same feedback earlier as well, but anyway).

> + if (!reqs[i].buf)
> + break;
> +
> + sg_init_one(&msg_buf, reqs[i].buf, msgs[i].len);
> +
> + if (msgs[i].flags & I2C_M_RD)
> + sgs[outcnt + incnt++] = &msg_buf;
> + else
> + sgs[outcnt++] = &msg_buf;
> +
> + sg_init_one(&in_hdr, &reqs[i].in_hdr, sizeof(reqs[i].in_hdr));
> + sgs[outcnt + incnt++] = &in_hdr;
> +
> + err = virtqueue_add_sgs(vq, sgs, outcnt, incnt, &reqs[i], 
> GFP_KERNEL);
> + if (err < 0) {
> + pr_err("failed to add msg[%d] to virtqueue.\n", i);
> + i2c_put_dma_safe_msg_buf(reqs[i].buf, &msgs[i], false);

On failure here, you freed the buffers for request "i" but not others..

> + break;
> + }
> + }
> +
> + return i;
> +}
> +
> +static int virtio_i2c_complete_reqs(struct virtqueue *vq,
> + struct virtio_i2c_req *reqs,
> + struct i2c_msg *msgs, int nr)
> +{
> + struct virtio_i2c_req *req;
> + unsigned int len;
> + int i, j;
> +
> + for (i = 0; i < nr; i++) {
> + req = virtqueue_get_buf(vq, &len);
> + if (!(req && req == &reqs[i])) {
> + pr_err("msg[%d]: addr=0x%x is out of order.\n", i, 
> msgs[i].addr);
> + break;

Since you break here, what will happen to the buffer ? I thought
virtqueue_get_buf() will return a req only once and then you can't access it ?

> + }
> +
> + if (req->in_hdr.status != VIRTIO_I2C_MSG_OK) {
> + pr_err("msg[%d]: addr=0x%x backend error.\n", i, 
> msgs[i].addr);
> + break;
> + }
> +
> + i2c_put_dma_safe_msg_buf(req->buf, &msgs[i], true);
> + }
> +
> + /*
> +  * Detach all the used buffers from the vq and
> +  * Release unused DMA safe buffer if any.
> +  */
> + for (j = i; j < nr; j++) {
> + req = virtqueue_get_buf(vq, &len);
> + if (req)
> + i2c_put_dma_safe_msg_buf(req->buf, &msgs[j], false);

This will come in play only if something failed in the earlier loop ? Or my
understanding incorrect ? Also this should be merged with the above for loop
itself, it is just doing part of it.

> + }
> +
> + return i;
> +}
> +
> +static int virtio_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, 
> int num)
> +{
> + struct virtio_i2c *vi = i2c_get_adapdata(adap);
> + struct virtqueue *vq = vi->vq;
> + struct virtio_i2c_req *reqs;
> + unsigned long time_left;
> + int ret, nr;
> +
> + reqs = kcalloc(num, sizeof(*reqs), GFP_KERNEL);
> + if (!reqs)
> + return -ENOMEM;
> +
> + mutex_lock(&vi->lock);
> +
> + ret = virtio_i2c_send_reqs(vq, reqs, msgs, num);
> + if (ret == 0)
> + goto err_unlock_free;
> +
> + nr = ret;
> + reinit_completion(&vi->completion);
> + virtqueue_kick(vq);
> +
> + time_left = wait_for_completion_timeout(&vi->completion, adap->timeout);
> + if (!time_left) {

On error here, we will surely not free the buffers, isn't it ?

> + dev_err(&adap->dev, "virtio i2c backend timeout.\n");
> + ret = -ETIMEDOUT;
> + goto err_unlock_free;
> + }
> +
> + ret = virtio_i2c_complete_reqs(vq, reqs, msgs, nr);
> +
> +err_unlock_free:
> + mutex_unlock(&vi->lock);
> + kfree(reqs);
> + return ret;
> +}
-- 
viresh


[PATCHv3 1/6] media: v4l UAPI: add ROI selection targets

2021-03-18 Thread Sergey Senozhatsky
UVC 1.5 requires Region Of Interest control to implement
GET_CUR, GET_DEF, GET_MIN and GET_MAX requests. This patch
adds new V4L2 selection API targets that will implement
those ROI requests.

Signed-off-by: Sergey Senozhatsky 
---
 include/uapi/linux/v4l2-common.h | 8 
 1 file changed, 8 insertions(+)

diff --git a/include/uapi/linux/v4l2-common.h b/include/uapi/linux/v4l2-common.h
index 7d21c1634b4d..3651ebb8cb23 100644
--- a/include/uapi/linux/v4l2-common.h
+++ b/include/uapi/linux/v4l2-common.h
@@ -78,6 +78,14 @@
 #define V4L2_SEL_TGT_COMPOSE_BOUNDS0x0102
 /* Current composing area plus all padding pixels */
 #define V4L2_SEL_TGT_COMPOSE_PADDED0x0103
+/* Current Region of Interest area */
+#define V4L2_SEL_TGT_ROI   0x0200
+/* Default Region of Interest area */
+#define V4L2_SEL_TGT_ROI_DEFAULT   0x0201
+/* Region of Interest minimum values */
+#define V4L2_SEL_TGT_ROI_BOUNDS_MIN0x0202
+/* Region of Interest maximum values */
+#define V4L2_SEL_TGT_ROI_BOUNDS_MAX0x0203
 
 /* Selection flags */
 #define V4L2_SEL_FLAG_GE   (1 << 0)
-- 
2.31.0.rc2.261.g7f71774620-goog



[PATCHv3 0/6] media: uvcvideo: implement UVC 1.5 ROI

2021-03-18 Thread Sergey Senozhatsky
Hello,

This patch set implements UVC 1.5 ROI using v4l2_selection API.

V3:
- reimplemented ROI. We dont' use split controls anymore.
- Ricardo's feedback

Sergey Senozhatsky (6):
  media: v4l UAPI: add ROI selection targets
  media: v4l UAPI: document ROI selection targets
  media: v4l UAPI: add ROI auto-controls flags
  media: v4l UAPI: document ROI auto-controls flags
  media: uvcvideo: add UVC 1.5 ROI control
  MAINTAINERS: update Senozhatsky email address

 .../media/v4l/selection-api-configuration.rst |  22 +++
 .../media/v4l/selection-api-examples.rst  |  28 
 .../media/v4l/v4l2-selection-flags.rst|  40 +
 .../media/v4l/v4l2-selection-targets.rst  |  24 +++
 MAINTAINERS   |   8 +-
 drivers/media/usb/uvc/uvc_v4l2.c  | 147 +-
 include/uapi/linux/usb/video.h|   1 +
 include/uapi/linux/v4l2-common.h  |  18 +++
 8 files changed, 281 insertions(+), 7 deletions(-)

-- 
2.31.0.rc2.261.g7f71774620-goog



[PATCHv3 5/6] media: uvcvideo: add UVC 1.5 ROI control

2021-03-18 Thread Sergey Senozhatsky
This patch implements UVC 1.5 Region of Interest (ROI) control.

Note that, UVC 1.5 defines CT_DIGITAL_WINDOW_CONTROL controls
and mentions that ROI rectangle coordinates "must be within
the current Digital Window as specified by the CT_WINDOW control."
(4.2.2.1.20 Digital Region of Interest (ROI) Control).

It's is not entirely clear if we need to implement WINDOW_CONTROL.
ROI is naturally limited by GET_MIN and GET_MAX rectangles.

Another thing to note is that ROI support is implemented as
V4L2 selection target: selection rectangle represents ROI
rectangle and selection flags represent ROI auto-controls.
User-space is required to set valid values for both rectangle
and auto-controls every time SET_CUR is issued.

Usage example:

   struct v4l2_selection roi = {0, };

   roi.target = V4L2_SEL_TGT_ROI;
   roi.r.left = 0;
   roi.r.top  = 0;
   roi.r.width= 42;
   roi.r.height   = 42;
   roi.flags  = V4L2_SEL_FLAG_ROI_AUTO_EXPOSURE;

   ioctl(fd, VIDIOC_S_SELECTION, &roi);

Signed-off-by: Sergey Senozhatsky 
---
 drivers/media/usb/uvc/uvc_v4l2.c | 147 ++-
 include/uapi/linux/usb/video.h   |   1 +
 2 files changed, 145 insertions(+), 3 deletions(-)

diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c
index 252136cc885c..d0fe6c33fab6 100644
--- a/drivers/media/usb/uvc/uvc_v4l2.c
+++ b/drivers/media/usb/uvc/uvc_v4l2.c
@@ -1139,14 +1139,66 @@ static int uvc_ioctl_querymenu(struct file *file, void 
*fh,
return uvc_query_v4l2_menu(chain, qm);
 }
 
-static int uvc_ioctl_g_selection(struct file *file, void *fh,
-struct v4l2_selection *sel)
+/* UVC 1.5 ROI rectangle is half the size of v4l2_rect */
+struct uvc_roi_rect {
+   __u16   top;
+   __u16   left;
+   __u16   bottom;
+   __u16   right;
+   __u16   auto_controls;
+} __packed;
+
+static int uvc_ioctl_g_roi_target(struct file *file, void *fh,
+ struct v4l2_selection *sel)
 {
struct uvc_fh *handle = fh;
struct uvc_streaming *stream = handle->stream;
+   struct uvc_roi_rect *roi;
+   u8 query;
+   int ret;
 
-   if (sel->type != stream->type)
+   switch (sel->target) {
+   case V4L2_SEL_TGT_ROI:
+   query = UVC_GET_CUR;
+   break;
+   case V4L2_SEL_TGT_ROI_DEFAULT:
+   query = UVC_GET_DEF;
+   break;
+   case V4L2_SEL_TGT_ROI_BOUNDS_MIN:
+   query = UVC_GET_MAX;
+   break;
+   case V4L2_SEL_TGT_ROI_BOUNDS_MAX:
+   query = UVC_GET_MAX;
+   break;
+   default:
return -EINVAL;
+   }
+
+   roi = kzalloc(sizeof(struct uvc_roi_rect), GFP_KERNEL);
+   if (!roi)
+   return -ENOMEM;
+
+   ret = uvc_query_ctrl(stream->dev, query, 1, stream->dev->intfnum,
+UVC_CT_REGION_OF_INTEREST_CONTROL, roi,
+sizeof(struct uvc_roi_rect));
+   if (!ret) {
+   /* ROI left, top, right, bottom are global coordinates. */
+   sel->r.left = roi->left;
+   sel->r.top  = roi->top;
+   sel->r.width= roi->right - roi->left + 1;
+   sel->r.height   = roi->bottom - roi->top + 1;
+   sel->flags  = roi->auto_controls;
+   }
+
+   kfree(roi);
+   return ret;
+}
+
+static int uvc_ioctl_g_sel_target(struct file *file, void *fh,
+ struct v4l2_selection *sel)
+{
+   struct uvc_fh *handle = fh;
+   struct uvc_streaming *stream = handle->stream;
 
switch (sel->target) {
case V4L2_SEL_TGT_CROP_DEFAULT:
@@ -1173,6 +1225,94 @@ static int uvc_ioctl_g_selection(struct file *file, void 
*fh,
return 0;
 }
 
+static int uvc_ioctl_g_selection(struct file *file, void *fh,
+struct v4l2_selection *sel)
+{
+   struct uvc_fh *handle = fh;
+   struct uvc_streaming *stream = handle->stream;
+
+   if (sel->type != stream->type)
+   return -EINVAL;
+
+   switch (sel->target) {
+   case V4L2_SEL_TGT_CROP_DEFAULT:
+   case V4L2_SEL_TGT_CROP_BOUNDS:
+   case V4L2_SEL_TGT_COMPOSE_DEFAULT:
+   case V4L2_SEL_TGT_COMPOSE_BOUNDS:
+   return uvc_ioctl_g_sel_target(file, fh, sel);
+   case V4L2_SEL_TGT_ROI:
+   case V4L2_SEL_TGT_ROI_DEFAULT:
+   case V4L2_SEL_TGT_ROI_BOUNDS_MIN:
+   case V4L2_SEL_TGT_ROI_BOUNDS_MAX:
+   return uvc_ioctl_g_roi_target(file, fh, sel);
+   }
+
+   return -EINVAL;
+}
+
+static bool validate_roi_bounds(struct uvc_streaming *stream,
+   struct v4l2_selection *sel)
+{
+   if (sel->r.left > USHRT_MAX ||
+   sel->r.top > USHRT_MAX ||
+   (sel->r.width + se

[PATCHv3 2/6] media: v4l UAPI: document ROI selection targets

2021-03-18 Thread Sergey Senozhatsky
Document V4L2 selection targets that will be used to ROI
implementation.

Signed-off-by: Sergey Senozhatsky 
---
 .../media/v4l/selection-api-configuration.rst | 22 +++
 .../media/v4l/selection-api-examples.rst  | 28 +++
 .../media/v4l/v4l2-selection-targets.rst  | 24 
 3 files changed, 74 insertions(+)

diff --git 
a/Documentation/userspace-api/media/v4l/selection-api-configuration.rst 
b/Documentation/userspace-api/media/v4l/selection-api-configuration.rst
index fee49bf1a1c0..b5fdd765e2db 100644
--- a/Documentation/userspace-api/media/v4l/selection-api-configuration.rst
+++ b/Documentation/userspace-api/media/v4l/selection-api-configuration.rst
@@ -135,3 +135,25 @@ and the height of rectangles obtained using 
``V4L2_SEL_TGT_CROP`` and
 ``V4L2_SEL_TGT_COMPOSE`` targets. If these are not equal then the
 scaling is applied. The application can compute the scaling ratios using
 these values.
+
+Configuration of Region of Interest (ROI)
+=
+
+The range of auto-controls values and of coordinates of the top left
+corner, width and height of areas that can be ROI is given by the
+``V4L2_SEL_TGT_ROI_BOUNDS_MIN`` and ``V4L2_SEL_TGT_ROI_BOUNDS_MAX``
+targets. It is recommended for the driver developers to put the top/left
+corner at position ``(0,0)``.
+
+The top left corner, width and height of the Region of Interest area
+and auto-controls currently being employed by the device are given by
+the ``V4L2_SEL_TGT_ROI`` target. It uses the same coordinate system
+as ``V4L2_SEL_TGT_ROI_BOUNDS_MIN`` and ``V4L2_SEL_TGT_ROI_BOUNDS_MAX``.
+
+In order to change active ROI top left, width and height coordinates
+and ROI auto-controls use ``V4L2_SEL_TGT_ROI`` target.
+
+Each capture device has a default ROI rectangle and auto-controls
+value given by the ``V4L2_SEL_TGT_ROI_DEFAULT`` target. Drivers shall
+set the ROI rectangle to the default when the driver is first loaded,
+but not later.
diff --git a/Documentation/userspace-api/media/v4l/selection-api-examples.rst 
b/Documentation/userspace-api/media/v4l/selection-api-examples.rst
index 5f8e8a1f59d7..ad2664888700 100644
--- a/Documentation/userspace-api/media/v4l/selection-api-examples.rst
+++ b/Documentation/userspace-api/media/v4l/selection-api-examples.rst
@@ -82,3 +82,31 @@ Example: Querying for scaling factors
/* computing scaling factors */
hscale = (double)compose.r.width / crop.r.width;
vscale = (double)compose.r.height / crop.r.height;
+
+Setting Region Of Interest area to half of the default value
+
+Example: Simple ROI
+===
+
+.. code-block:: c
+
+   struct v4l2_selection roi = {
+   .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
+   .target = V4L2_SEL_TGT_ROI_DEFAULT,
+   };
+   struct v4l2_rect r;
+
+   ret = ioctl(fd, VIDIOC_G_SELECTION, &roi);
+   if (ret)
+   exit(-1);
+   /* setting smaller ROI rectangle */
+   r.width = roi.r.width / 2;
+   r.height = roi.r.height / 2;
+   r.left = roi.r.width / 4;
+   r.top = roi.r.height / 4;
+   roi.r = r;
+   roi.target = V4L2_SEL_TGT_ROI;
+   roi.flags = V4L2_SEL_FLAG_ROI_AUTO_EXPOSURE;
+   ret = ioctl(fd, VIDIOC_S_SELECTION, &roi);
+   if (ret)
+   exit(-1);
diff --git a/Documentation/userspace-api/media/v4l/v4l2-selection-targets.rst 
b/Documentation/userspace-api/media/v4l/v4l2-selection-targets.rst
index b46bae984f35..d1dc9c50eb05 100644
--- a/Documentation/userspace-api/media/v4l/v4l2-selection-targets.rst
+++ b/Documentation/userspace-api/media/v4l/v4l2-selection-targets.rst
@@ -75,6 +75,30 @@ of the two interfaces they are used.
modified by hardware.
   - Yes
   - No
+* - ``V4L2_SEL_TGT_ROI``
+  - 0x0200
+  - Current Region of Interest rectangle and auto-controls value.
+  - Yes
+  - No
+* - ``V4L2_SEL_TGT_ROI_DEFAULT``
+  - 0x0201
+  - Suggested Region of Interest rectangle and auto-controls value.
+  - Yes
+  - No
+* - ``V4L2_SEL_TGT_ROI_BOUNDS_MIN``
+  - 0x0202
+  - Minimum bounds of the Region of Interest rectangle and minimum
+   auto-controls value. All valid ROI rectangles and auto-controls
+   should be within minimum-maximum range.
+  - Yes
+  - No
+* - ``V4L2_SEL_TGT_ROI_BOUNDS_MAX``
+  - 0x0203
+  - Maximum bounds of the Region of Interest rectangle and maximum
+   auto-controls value. All valid ROI rectangles and auto-controls
+   should be within minimum-maximum range.
+  - Yes
+  - No
 
 .. raw:: latex
 
-- 
2.31.0.rc2.261.g7f71774620-goog



[PATCHv3 4/6] media: v4l UAPI: document ROI auto-controls flags

2021-03-18 Thread Sergey Senozhatsky
Document ROI auto controls.

Signed-off-by: Sergey Senozhatsky 
---
 .../media/v4l/v4l2-selection-flags.rst| 40 +++
 1 file changed, 40 insertions(+)

diff --git a/Documentation/userspace-api/media/v4l/v4l2-selection-flags.rst 
b/Documentation/userspace-api/media/v4l/v4l2-selection-flags.rst
index 1cb1531c1e52..536d29a6c4a5 100644
--- a/Documentation/userspace-api/media/v4l/v4l2-selection-flags.rst
+++ b/Documentation/userspace-api/media/v4l/v4l2-selection-flags.rst
@@ -48,6 +48,46 @@ Selection flags
inside the subdevice to all further processing steps.
   - No
   - Yes
+* - ``V4L2_SEL_FLAG_ROI_AUTO_EXPOSURE``
+  - (1 << 0)
+  - Auto Exposure.
+  - Yes
+  - No
+* - ``V4L2_SEL_FLAG_ROI_AUTO_IRIS``
+  - (1 << 1)
+  - Auto Iris.
+  - Yes
+  - No
+* - ``V4L2_SEL_FLAG_ROI_AUTO_WHITE_BALANCE``
+  - (1 << 2)
+  - Auto White Balance.
+  - Yes
+  - No
+* - ``V4L2_SEL_FLAG_ROI_AUTO_FOCUS``
+  - (1 << 3)
+  - Auto Focus.
+  - Yes
+  - No
+* - ``V4L2_SEL_FLAG_ROI_AUTO_FACE_DETECT``
+  - (1 << 4)
+  - Auto Face Detect.
+  - Yes
+  - No
+* - ``V4L2_SEL_FLAG_ROI_AUTO_DETECT_AND_TRACK``
+  - (1 << 5)
+  - Auto Detect and Track.
+  - Yes
+  - No
+* - ``V4L2_SEL_FLAG_ROI_AUTO_IMAGE_STABILIXATION``
+  - (1 << 6)
+  - Image Stabilization.
+  - Yes
+  - No
+* - ``V4L2_SEL_FLAG_ROI_AUTO_HIGHER_QUALITY``
+  - (1 << 7)
+  - Higher Quality.
+  - Yes
+  - No
 
 .. raw:: latex
 
-- 
2.31.0.rc2.261.g7f71774620-goog



[PATCHv3 6/6] MAINTAINERS: update Senozhatsky email address

2021-03-18 Thread Sergey Senozhatsky
I don't check my @gmail.com addresses often enough these days.

Signed-off-by: Sergey Senozhatsky 
---
 MAINTAINERS | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index b2baeb5e4a68..01b000cd5774 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -14433,7 +14433,7 @@ F:  kernel/sched/psi.c
 
 PRINTK
 M: Petr Mladek 
-M: Sergey Senozhatsky 
+M: Sergey Senozhatsky 
 R: Steven Rostedt 
 R: John Ogness 
 S: Maintained
@@ -19293,7 +19293,7 @@ F:  drivers/net/vrf.c
 VSPRINTF
 M: Petr Mladek 
 M: Steven Rostedt 
-M: Sergey Senozhatsky 
+M: Sergey Senozhatsky 
 R: Andy Shevchenko 
 R: Rasmus Villemoes 
 S: Maintained
@@ -19944,7 +19944,7 @@ F:  drivers/staging/media/zoran/
 ZRAM COMPRESSED RAM BLOCK DEVICE DRVIER
 M: Minchan Kim 
 M: Nitin Gupta 
-R: Sergey Senozhatsky 
+R: Sergey Senozhatsky 
 L: linux-kernel@vger.kernel.org
 S: Maintained
 F: Documentation/admin-guide/blockdev/zram.rst
@@ -19958,7 +19958,7 @@ F:  drivers/tty/serial/zs.*
 ZSMALLOC COMPRESSED SLAB MEMORY ALLOCATOR
 M: Minchan Kim 
 M: Nitin Gupta 
-R: Sergey Senozhatsky 
+R: Sergey Senozhatsky 
 L: linux...@kvack.org
 S: Maintained
 F: Documentation/vm/zsmalloc.rst
-- 
2.31.0.rc2.261.g7f71774620-goog



[PATCHv3 3/6] media: v4l UAPI: add ROI auto-controls flags

2021-03-18 Thread Sergey Senozhatsky
UVC 1.5 defines the following Region Of Interest auto controls:

D0: Auto Exposure
D1: Auto Iris
D2: Auto White Balance
D3: Auto Focus
D4: Auto Face Detect
D5: Auto Detect and Track
D6: Image Stabilization
D7: Higher Quality
D8 – D15: Reserved, set to zero

Signed-off-by: Sergey Senozhatsky 
---
 include/uapi/linux/v4l2-common.h | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/include/uapi/linux/v4l2-common.h b/include/uapi/linux/v4l2-common.h
index 3651ebb8cb23..34f1c262d6aa 100644
--- a/include/uapi/linux/v4l2-common.h
+++ b/include/uapi/linux/v4l2-common.h
@@ -92,6 +92,16 @@
 #define V4L2_SEL_FLAG_LE   (1 << 1)
 #define V4L2_SEL_FLAG_KEEP_CONFIG  (1 << 2)
 
+/* ROI auto-controls flags */
+#define V4L2_SEL_FLAG_ROI_AUTO_EXPOSURE(1 << 0)
+#define V4L2_SEL_FLAG_ROI_AUTO_IRIS(1 << 1)
+#define V4L2_SEL_FLAG_ROI_AUTO_WHITE_BALANCE   (1 << 2)
+#define V4L2_SEL_FLAG_ROI_AUTO_FOCUS   (1 << 3)
+#define V4L2_SEL_FLAG_ROI_AUTO_FACE_DETECT (1 << 4)
+#define V4L2_SEL_FLAG_ROI_AUTO_DETECT_AND_TRACK(1 << 5)
+#define V4L2_SEL_FLAG_ROI_AUTO_IMAGE_STABILIXATION (1 << 6)
+#define V4L2_SEL_FLAG_ROI_AUTO_HIGHER_QUALITY  (1 << 7)
+
 struct v4l2_edid {
__u32 pad;
__u32 start_block;
-- 
2.31.0.rc2.261.g7f71774620-goog



[PATCH] power: supply: charger-manager: Fix a typo

2021-03-18 Thread Bhaskar Chowdhury
s/systme/system/

Signed-off-by: Bhaskar Chowdhury 
---
 drivers/power/supply/charger-manager.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/power/supply/charger-manager.c 
b/drivers/power/supply/charger-manager.c
index 4dea8ecd70bc..45da870aecca 100644
--- a/drivers/power/supply/charger-manager.c
+++ b/drivers/power/supply/charger-manager.c
@@ -1604,7 +1604,7 @@ static int charger_manager_probe(struct platform_device 
*pdev)
mutex_unlock(&cm_list_mtx);

/*
-* Charger-manager is capable of waking up the systme from sleep
+* Charger-manager is capable of waking up the system from sleep
 * when event is happened through cm_notify_event()
 */
device_init_wakeup(&pdev->dev, true);
--
2.26.2



Re: [PATCHv3 6/6] MAINTAINERS: update Senozhatsky email address

2021-03-18 Thread Sergey Senozhatsky
On (21/03/19 14:53), Sergey Senozhatsky wrote:
> 
> I don't check my @gmail.com addresses often enough these days.
> 

Please ignore this one. It's a different story and does not belong
to this series.

-ss


csky-linux-gcc: error: unrecognized command line option '-mbacktrace'; did you mean

2021-03-18 Thread kernel test robot
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
master
head:   8b12a62a4e3ed4ae99c715034f557eb391d6b196
commit: 000591f1ca3312d9a29e15a9e3fe5c4171f75586 csky: Enable LOCKDEP_SUPPORT
date:   12 months ago
config: csky-randconfig-r012-20210318 (attached as .config)
compiler: csky-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=000591f1ca3312d9a29e15a9e3fe5c4171f75586
git remote add linus 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
git fetch --no-tags linus master
git checkout 000591f1ca3312d9a29e15a9e3fe5c4171f75586
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross 
ARCH=csky 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot 

All errors (new ones prefixed by >>):

>> csky-linux-gcc: error: unrecognized command line option '-mbacktrace'; did 
>> you mean '-fbacktrace'?
--
>> csky-linux-gcc: error: unrecognized command line option '-mbacktrace'; did 
>> you mean '-fbacktrace'?
   /usr/bin/ld: scripts/dtc/dtc-parser.tab.o:(.bss+0x20): multiple definition 
of `yylloc'; scripts/dtc/dtc-lexer.lex.o:(.bss+0x0): first defined here
   collect2: error: ld returned 1 exit status
   make[2]: *** [scripts/Makefile.host:116: scripts/dtc/dtc] Error 1
   make[2]: Target '__build' not remade because of errors.
   make[1]: *** [Makefile:1260: scripts_dtc] Error 2
   make[1]: Target 'prepare' not remade because of errors.
   make: *** [Makefile:180: sub-make] Error 2
   make: Target 'prepare' not remade because of errors.

Kconfig warnings: (for reference only)
   WARNING: unmet direct dependencies detected for FRAME_POINTER
   Depends on DEBUG_KERNEL && (M68K || UML || SUPERH) || 
ARCH_WANT_FRAME_POINTERS
   Selected by
   - LOCKDEP && DEBUG_KERNEL && LOCK_DEBUGGING_SUPPORT && !MIPS && !PPC && !ARM 
&& !S390 && !MICROBLAZE && !ARC && !X86

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-...@lists.01.org


.config.gz
Description: application/gzip


[PATCH] bfq: silence lockdep for bfqd/ioc lock inversion

2021-03-18 Thread Khazhismel Kumykov
lockdep warns of circular locking due to inversion between
bfq_insert_requests and bfq_exit_icq. If we end freeing a request when
merging, we *may* grab an ioc->lock if that request is the last refcount
to that ioc. bfq_bio_merge also potentially could have this ordering.
bfq_exit_icq, conversely, grabs bfqd but is always called with ioc->lock
held.

bfq_exit_icq may either be called from put_io_context_active with ioc
refcount raised, ioc_release_fn after the last refcount was already
dropped, or ioc_clear_queue, which is only called while queue is
quiesced or exiting, so the inverted orderings should never conflict.

Fixes: aee69d78dec0 ("block, bfq: introduce the BFQ-v0 I/O scheduler as
an extra scheduler")

Signed-off-by: Khazhismel Kumykov 
---
 block/bfq-iosched.c | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

Noticed this lockdep running xfstests (generic/464) on top of a bfq
block device. I was also able to tease it out w/ binary trying to issue
requests that would end up merging while rapidly swapping the active
scheduler. As far as I could see, the deadlock would not actually occur,
so this patch opts to change lock class for the inverted case.

bfqd -> ioc :
[ 2995.524557] __lock_acquire+0x18f5/0x2660
[ 2995.524562] lock_acquire+0xb4/0x3a0
[ 2995.524565] _raw_spin_lock_irqsave+0x3f/0x60
[ 2995.524569] put_io_context+0x33/0x90.  -> ioc->lock grabbed
[ 2995.524573] blk_mq_free_request+0x51/0x140
[ 2995.524577] blk_put_request+0xe/0x10
[ 2995.524580] blk_attempt_req_merge+0x1d/0x30
[ 2995.524585] elv_attempt_insert_merge+0x56/0xa0
[ 2995.524590] blk_mq_sched_try_insert_merge+0x4b/0x60
[ 2995.524595] bfq_insert_requests+0x9e/0x18c0.    -> bfqd->lock grabbed
[ 2995.524598] blk_mq_sched_insert_requests+0xd6/0x2b0
[ 2995.524602] blk_mq_flush_plug_list+0x154/0x280
[ 2995.524606] blk_finish_plug+0x40/0x60
[ 2995.524609] ext4_writepages+0x696/0x1320
[ 2995.524614] do_writepages+0x1c/0x80
[ 2995.524621] __filemap_fdatawrite_range+0xd7/0x120
[ 2995.524625] sync_file_range+0xac/0xf0
[ 2995.524642] __x64_sys_sync_file_range+0x44/0x70
[ 2995.524646] do_syscall_64+0x31/0x40
[ 2995.524649] entry_SYSCALL_64_after_hwframe+0x44/0xae

ioc -> bfqd
[ 2995.524490] _raw_spin_lock_irqsave+0x3f/0x60
[ 2995.524498] bfq_exit_icq+0xa3/0xe0 -> bfqd->lock grabbed
[ 2995.524512] put_io_context_active+0x78/0xb0 -> ioc->lock grabbed
[ 2995.524516] exit_io_context+0x48/0x50
[ 2995.524519] do_exit+0x7e9/0xdd0
[ 2995.524526] do_group_exit+0x54/0xc0
[ 2995.524530] __x64_sys_exit_group+0x18/0x20
[ 2995.524534] do_syscall_64+0x31/0x40
[ 2995.524537] entry_SYSCALL_64_after_hwframe+0x44/0xae

Another trace where we grab ioc -> bfqd through bfq_exit_icq is when
changing elevator
               -> #1 (&(&bfqd->lock)->rlock){-.-.}:
[  646.890820]        lock_acquire+0x9b/0x140
[  646.894868]        _raw_spin_lock_irqsave+0x3b/0x50
[  646.899707]        bfq_exit_icq_bfqq+0x47/0x1f0
[  646.904196]        bfq_exit_icq+0x21/0x30
[  646.908160]        ioc_destroy_icq+0xf3/0x130
[  646.912466]        ioc_clear_queue+0xb8/0x140
[  646.916771]        elevator_switch_mq+0xa4/0x3c0
[  646.921333]        elevator_switch+0x5f/0x340

diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c
index 95586137194e..cb50ac0ffe80 100644
--- a/block/bfq-iosched.c
+++ b/block/bfq-iosched.c
@@ -5027,7 +5027,14 @@ static void bfq_exit_icq_bfqq(struct bfq_io_cq *bic, 
bool is_sync)
if (bfqq && bfqd) {
unsigned long flags;
 
-   spin_lock_irqsave(&bfqd->lock, flags);
+   /* bfq_exit_icq is usually called with ioc->lock held, which is
+* inverse order from elsewhere, which may grab ioc->lock
+* under bfqd->lock if we merge requests and drop the last ioc
+* refcount. Since exit_icq is either called with a refcount,
+* or with queue quiesced, use a differnet lock class to
+* silence lockdep
+*/
+   spin_lock_irqsave_nested(&bfqd->lock, flags, 1);
bfqq->bic = NULL;
bfq_exit_bfqq(bfqd, bfqq);
bic_set_bfqq(bic, NULL, is_sync);
-- 
2.31.0.rc2.261.g7f71774620-goog



linux-next: manual merge of the akpm tree with the security tree

2021-03-18 Thread Stephen Rothwell
Hi all,

FIXME: Add owner of second tree to To:
   Add author(s)/SOB of conflicting commits.

Today's linux-next merge of the akpm tree got conflicts in:

  arch/x86/entry/syscalls/syscall_32.tbl
  arch/x86/entry/syscalls/syscall_64.tbl
  include/linux/syscalls.h
  include/uapi/asm-generic/unistd.h

between commit:

  c5eafae25eb5 ("landlock: Add syscall implementations")

from the security tree and patch:

  "arch, mm: wire up memfd_secret system call where relevant"

from the akpm tree.

I fixed it up (see below) and can carry the fix as necessary. This
is now fixed as far as linux-next is concerned, but any non trivial
conflicts should be mentioned to your upstream maintainer when your tree
is submitted for merging.  You may also want to consider cooperating
with the maintainer of the conflicting tree to minimise any particularly
complex conflicts.

-- 
Cheers,
Stephen Rothwell

diff --cc arch/x86/entry/syscalls/syscall_32.tbl
index 28a1423ce32e,524a076e79ca..
--- a/arch/x86/entry/syscalls/syscall_32.tbl
+++ b/arch/x86/entry/syscalls/syscall_32.tbl
@@@ -448,6 -448,4 +448,7 @@@
  441   i386epoll_pwait2sys_epoll_pwait2
compat_sys_epoll_pwait2
  442   i386mount_setattr   sys_mount_setattr
  443   i386quotactl_path   sys_quotactl_path
 -444   i386memfd_secretsys_memfd_secret
 +444   i386landlock_create_ruleset sys_landlock_create_ruleset
 +445   i386landlock_add_rule   sys_landlock_add_rule
 +446   i386landlock_restrict_self  sys_landlock_restrict_self
++447   i386memfd_secretsys_memfd_secret
diff --cc arch/x86/entry/syscalls/syscall_64.tbl
index ecd551b08d05,440467ca352d..
--- a/arch/x86/entry/syscalls/syscall_64.tbl
+++ b/arch/x86/entry/syscalls/syscall_64.tbl
@@@ -365,9 -365,7 +365,10 @@@
  441   common  epoll_pwait2sys_epoll_pwait2
  442   common  mount_setattr   sys_mount_setattr
  443   common  quotactl_path   sys_quotactl_path
 -444   common  memfd_secretsys_memfd_secret
 +444   common  landlock_create_ruleset sys_landlock_create_ruleset
 +445   common  landlock_add_rule   sys_landlock_add_rule
 +446   common  landlock_restrict_self  sys_landlock_restrict_self
++447   common  memfd_secretsys_memfd_secret
  
  #
  # Due to a historical design error, certain syscalls are numbered differently
diff --cc include/linux/syscalls.h
index 050511e8f1f8,019a1d876eb1..
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@@ -1045,11 -1043,7 +1045,12 @@@ asmlinkage long sys_pidfd_send_signal(i
   siginfo_t __user *info,
   unsigned int flags);
  asmlinkage long sys_pidfd_getfd(int pidfd, int fd, unsigned int flags);
 +asmlinkage long sys_landlock_create_ruleset(const struct 
landlock_ruleset_attr __user *attr,
 +  size_t size, __u32 flags);
 +asmlinkage long sys_landlock_add_rule(int ruleset_fd, enum landlock_rule_type 
rule_type,
 +  const void __user *rule_attr, __u32 flags);
 +asmlinkage long sys_landlock_restrict_self(int ruleset_fd, __u32 flags);
+ asmlinkage long sys_memfd_secret(unsigned long flags);
  
  /*
   * Architecture-specific system calls
diff --cc include/uapi/asm-generic/unistd.h
index 67093382a4e6,77d89b24341f..
--- a/include/uapi/asm-generic/unistd.h
+++ b/include/uapi/asm-generic/unistd.h
@@@ -865,15 -865,13 +865,19 @@@ __SC_COMP(__NR_epoll_pwait2, sys_epoll_
  __SYSCALL(__NR_mount_setattr, sys_mount_setattr)
  #define __NR_quotactl_path 443
  __SYSCALL(__NR_quotactl_path, sys_quotactl_path)
 +#define __NR_landlock_create_ruleset 444
 +__SYSCALL(__NR_landlock_create_ruleset, sys_landlock_create_ruleset)
 +#define __NR_landlock_add_rule 445
 +__SYSCALL(__NR_landlock_add_rule, sys_landlock_add_rule)
 +#define __NR_landlock_restrict_self 446
 +__SYSCALL(__NR_landlock_restrict_self, sys_landlock_restrict_self)
+ #ifdef __ARCH_WANT_MEMFD_SECRET
 -#define __NR_memfd_secret 444
++#define __NR_memfd_secret 447
+ __SYSCALL(__NR_memfd_secret, sys_memfd_secret)
+ #endif
  
  #undef __NR_syscalls
- #define __NR_syscalls 447
 -#define __NR_syscalls 445
++#define __NR_syscalls 448
  
  /*
   * 32 bit systems traditionally used different


pgp3YEAryspbA.pgp
Description: OpenPGP digital signature


[PATCH v3 0/3] Fixes & a new supplementary feature to SPRD mailbox driver

2021-03-18 Thread Orson Zhai
From: Orson Zhai 


Fix a real problem for SPRD's mailbox driver in patch 1/3.
Add supplementary inbox support for newly added sc9863a in patch 3/3 and
change dt bindings yaml accordingly in patch 2/3.

Changes Log:
V3:
- Add Reviewed-by tag from Baolin for driver code.
- Change interrupt-names syntax in dt-bindings according to Rob's comment.

V2:
- Change patches order. (Yaml go to the head of dirver)
- Remove unnecessary initializing refcnt to zero. 
- Add fix of possible crash caused by NULL of chan->cl. (Actually move from
  changes to sprd-mailbox.c of patch v1)
- Remove unnecessary "inline" for do_inbox_isr().
- Fix yaml errors from Rob's robot checking.
- Add sc9863a compatible string for real supplementary inbox usage. (sc9860
  is not supported by supp-inbox)
- Add more details to supp-inbox in commit messages.

Orson Zhai (3):
  mailbox: sprd: Introduce refcnt when clients requests/free channels
  mailbox: sprd: Add supplementary inbox support
  dt-bindings: mailbox: Add interrupt-names to SPRD mailbox

 .../devicetree/bindings/mailbox/sprd-mailbox.yaml  |  13 +-
 drivers/mailbox/sprd-mailbox.c | 135 -
 2 files changed, 113 insertions(+), 35 deletions(-)

-- 
2.7.4



[PATCH v3 1/3] mailbox: sprd: Introduce refcnt when clients requests/free channels

2021-03-18 Thread Orson Zhai
From: Orson Zhai 

Unisoc mailbox has no way to be enabled/disabled for any single channel.
They can only be set to startup or shutdown as a whole device at same time.

Add a variable to count references to avoid mailbox FIFO being reset
unexpectedly when clients are requesting or freeing channels.

Also add a lock to dismiss possible conflicts from register r/w in
different startup or shutdown threads. And fix the crash problem when early
interrupts come from channel which has not been requested by client yet.

Fixes: ca27fc26cd22 ("mailbox: sprd: Add Spreadtrum mailbox driver")
Signed-off-by: Orson Zhai 
Reviewed-by: Baolin Wang 
---
 drivers/mailbox/sprd-mailbox.c | 43 --
 1 file changed, 29 insertions(+), 14 deletions(-)

diff --git a/drivers/mailbox/sprd-mailbox.c b/drivers/mailbox/sprd-mailbox.c
index 4c32530..94d9067d 100644
--- a/drivers/mailbox/sprd-mailbox.c
+++ b/drivers/mailbox/sprd-mailbox.c
@@ -60,6 +60,8 @@ struct sprd_mbox_priv {
struct clk  *clk;
u32 outbox_fifo_depth;
 
+   struct mutexlock;
+   u32 refcnt;
struct mbox_chanchan[SPRD_MBOX_CHAN_MAX];
 };
 
@@ -115,7 +117,11 @@ static irqreturn_t sprd_mbox_outbox_isr(int irq, void 
*data)
id = readl(priv->outbox_base + SPRD_MBOX_ID);
 
chan = &priv->chan[id];
-   mbox_chan_received_data(chan, (void *)msg);
+   if (chan->cl)
+   mbox_chan_received_data(chan, (void *)msg);
+   else
+   dev_warn_ratelimited(priv->dev,
+   "message's been dropped at ch[%d]\n", id);
 
/* Trigger to update outbox FIFO pointer */
writel(0x1, priv->outbox_base + SPRD_MBOX_TRIGGER);
@@ -215,18 +221,22 @@ static int sprd_mbox_startup(struct mbox_chan *chan)
struct sprd_mbox_priv *priv = to_sprd_mbox_priv(chan->mbox);
u32 val;
 
-   /* Select outbox FIFO mode and reset the outbox FIFO status */
-   writel(0x0, priv->outbox_base + SPRD_MBOX_FIFO_RST);
+   mutex_lock(&priv->lock);
+   if (priv->refcnt++ == 0) {
+   /* Select outbox FIFO mode and reset the outbox FIFO status */
+   writel(0x0, priv->outbox_base + SPRD_MBOX_FIFO_RST);
 
-   /* Enable inbox FIFO overflow and delivery interrupt */
-   val = readl(priv->inbox_base + SPRD_MBOX_IRQ_MSK);
-   val &= ~(SPRD_INBOX_FIFO_OVERFLOW_IRQ | SPRD_INBOX_FIFO_DELIVER_IRQ);
-   writel(val, priv->inbox_base + SPRD_MBOX_IRQ_MSK);
+   /* Enable inbox FIFO overflow and delivery interrupt */
+   val = readl(priv->inbox_base + SPRD_MBOX_IRQ_MSK);
+   val &= ~(SPRD_INBOX_FIFO_OVERFLOW_IRQ | 
SPRD_INBOX_FIFO_DELIVER_IRQ);
+   writel(val, priv->inbox_base + SPRD_MBOX_IRQ_MSK);
 
-   /* Enable outbox FIFO not empty interrupt */
-   val = readl(priv->outbox_base + SPRD_MBOX_IRQ_MSK);
-   val &= ~SPRD_OUTBOX_FIFO_NOT_EMPTY_IRQ;
-   writel(val, priv->outbox_base + SPRD_MBOX_IRQ_MSK);
+   /* Enable outbox FIFO not empty interrupt */
+   val = readl(priv->outbox_base + SPRD_MBOX_IRQ_MSK);
+   val &= ~SPRD_OUTBOX_FIFO_NOT_EMPTY_IRQ;
+   writel(val, priv->outbox_base + SPRD_MBOX_IRQ_MSK);
+   }
+   mutex_unlock(&priv->lock);
 
return 0;
 }
@@ -235,9 +245,13 @@ static void sprd_mbox_shutdown(struct mbox_chan *chan)
 {
struct sprd_mbox_priv *priv = to_sprd_mbox_priv(chan->mbox);
 
-   /* Disable inbox & outbox interrupt */
-   writel(SPRD_INBOX_FIFO_IRQ_MASK, priv->inbox_base + SPRD_MBOX_IRQ_MSK);
-   writel(SPRD_OUTBOX_FIFO_IRQ_MASK, priv->outbox_base + 
SPRD_MBOX_IRQ_MSK);
+   mutex_lock(&priv->lock);
+   if (--priv->refcnt == 0) {
+   /* Disable inbox & outbox interrupt */
+   writel(SPRD_INBOX_FIFO_IRQ_MASK, priv->inbox_base + 
SPRD_MBOX_IRQ_MSK);
+   writel(SPRD_OUTBOX_FIFO_IRQ_MASK, priv->outbox_base + 
SPRD_MBOX_IRQ_MSK);
+   }
+   mutex_unlock(&priv->lock);
 }
 
 static const struct mbox_chan_ops sprd_mbox_ops = {
@@ -266,6 +280,7 @@ static int sprd_mbox_probe(struct platform_device *pdev)
return -ENOMEM;
 
priv->dev = dev;
+   mutex_init(&priv->lock);
 
/*
 * The Spreadtrum mailbox uses an inbox to send messages to the target
-- 
2.7.4



[PATCH v3 2/3] dt-bindings: mailbox: Add interrupt-names to SPRD mailbox

2021-03-18 Thread Orson Zhai
From: Orson Zhai 

We add an optional supp-outbox interrupt support to SPRD mailbox driver
with newly added sc9863a support and change to configure interrupts with
names in device tree files.

Signed-off-by: Orson Zhai 
---
 Documentation/devicetree/bindings/mailbox/sprd-mailbox.yaml | 13 +++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/mailbox/sprd-mailbox.yaml 
b/Documentation/devicetree/bindings/mailbox/sprd-mailbox.yaml
index 26a5cca..80feba8 100644
--- a/Documentation/devicetree/bindings/mailbox/sprd-mailbox.yaml
+++ b/Documentation/devicetree/bindings/mailbox/sprd-mailbox.yaml
@@ -15,6 +15,7 @@ properties:
   compatible:
 enum:
   - sprd,sc9860-mailbox
+  - sprd,sc9863a-mailbox
 
   reg:
 items:
@@ -22,9 +23,15 @@ properties:
   - description: outbox registers' base address
 
   interrupts:
+minItems: 2
+maxItems: 3
+
+  interrupt-names:
+minItems: 2
 items:
-  - description: inbox interrupt
-  - description: outbox interrupt
+  - const: inbox
+  - const: outbox
+  - const: supp-outbox
 
   clocks:
 maxItems: 1
@@ -40,6 +47,7 @@ required:
   - compatible
   - reg
   - interrupts
+  - interrupt-names
   - "#mbox-cells"
   - clocks
   - clock-names
@@ -56,5 +64,6 @@ examples:
   clock-names = "enable";
   clocks = <&aon_gate 53>;
   interrupts = , ;
+  interrupt-names = "inbox", "outbox";
 };
 ...
-- 
2.7.4



RE: [PATCH 02/11] i2c: imx-lpi2c: add runtime pm support

2021-03-18 Thread Clark Wang

> -Original Message-
> From: Aisheng Dong 
> Sent: Friday, March 19, 2021 12:40
> To: Clark Wang ; shawn...@kernel.org;
> s.ha...@pengutronix.de
> Cc: ker...@pengutronix.de; feste...@gmail.com; dl-linux-imx  i...@nxp.com>; sumit.sem...@linaro.org; christian.koe...@amd.com;
> linux-...@vger.kernel.org; linux-arm-ker...@lists.infradead.org; linux-
> ker...@vger.kernel.org
> Subject: RE: [PATCH 02/11] i2c: imx-lpi2c: add runtime pm support
>
> > From: Clark Wang 
> > Sent: Wednesday, March 17, 2021 2:54 PM
> > Subject: [PATCH 02/11] i2c: imx-lpi2c: add runtime pm support
> >
> > - Add runtime pm support to dynamicly manage the clock.
> > - Put the suspend to suspend_noirq.
> > - Call .pm_runtime_force_suspend() to force runtime pm suspended
> >   in .suspend_noirq().
> >
>
> The patch title needs to be improved as the driver already supports rpm.
> And do one thing in one patch.
>
> > Signed-off-by: Fugang Duan 
> > Signed-off-by: Gao Pan 
> > Reviewed-by: Anson Huang 
>
> Please add your sign-off.
>
> > ---
> >  drivers/i2c/busses/i2c-imx-lpi2c.c | 50
> > --
> >  1 file changed, 33 insertions(+), 17 deletions(-)
> >
> > diff --git a/drivers/i2c/busses/i2c-imx-lpi2c.c
> > b/drivers/i2c/busses/i2c-imx-lpi2c.c
> > index bbf44ac95021..1e920e7ac7c1 100644
> > --- a/drivers/i2c/busses/i2c-imx-lpi2c.c
> > +++ b/drivers/i2c/busses/i2c-imx-lpi2c.c
> > @@ -574,7 +574,8 @@ static int lpi2c_imx_probe(struct platform_device
> > *pdev)
> > if (ret)
> > lpi2c_imx->bitrate = I2C_MAX_STANDARD_MODE_FREQ;
> >
> > -   ret = devm_request_irq(&pdev->dev, irq, lpi2c_imx_isr, 0,
> > +   ret = devm_request_irq(&pdev->dev, irq, lpi2c_imx_isr,
> > +  IRQF_NO_SUSPEND,
>
> This belongs to a separate patch
>
> >pdev->name, lpi2c_imx);
> > if (ret) {
> > dev_err(&pdev->dev, "can't claim irq %d\n", irq); @@ -
> 584,35
> > +585,32 @@ static int lpi2c_imx_probe(struct platform_device *pdev)
> > i2c_set_adapdata(&lpi2c_imx->adapter, lpi2c_imx);
> > platform_set_drvdata(pdev, lpi2c_imx);
> >
> > -   ret = clk_prepare_enable(lpi2c_imx->clk);
> > -   if (ret) {
> > -   dev_err(&pdev->dev, "clk enable failed %d\n", ret);
> > -   return ret;
> > -   }
> > -
> > pm_runtime_set_autosuspend_delay(&pdev->dev,
> I2C_PM_TIMEOUT);
> > pm_runtime_use_autosuspend(&pdev->dev);
> > -   pm_runtime_get_noresume(&pdev->dev);
> > -   pm_runtime_set_active(&pdev->dev);
> > pm_runtime_enable(&pdev->dev);
> >
> > +   ret = pm_runtime_get_sync(&pdev->dev);
> > +   if (ret < 0) {
> > +   pm_runtime_put_noidle(&pdev->dev);
> > +   dev_err(&pdev->dev, "failed to enable clock\n");
> > +   return ret;
> > +   }
>
> Can't current clk control via rpm work well?
> Please describe why need change.

I think the previous patch maker might want to use the return value of 
pm_runtime_get_sync to check whether the clock has been turned on correctly to 
avoid the kernel panic.
Maybe I can change to the method like this.
pm_runtime_get_noresume(&pdev->dev);
ret = pm_runtime_set_active(&pdev->dev);
if (ret < 0)
goto out;
pm_runtime_enable(&pdev->dev);

Best Regards,
Clark Wang



smime.p7s
Description: S/MIME cryptographic signature


[PATCH v3 3/3] mailbox: sprd: Add supplementary inbox support

2021-03-18 Thread Orson Zhai
From: Orson Zhai 

Some sensors connected to Unisoc mailbox will send data very frequently.
This makes channel 0 very busy and the messages from other remote cores
not able to be handled as soon as possible.

It's a trick (un-documented) from Unisoc ASIC designers to resolve this
special requirement that an inbox assigned to one of the remote cores
before was modified to be exposed to host cpu core.

Then from host side, a supplementary inbox is added for transferring mass
but not emergency messages from the remote cores, such as step counting
sensor, with an independent FIFO and interrupt which is as same as channel
0. Meanwihle, inbox part of this channel is still kept for original remote
core to use.

Signed-off-by: Orson Zhai 
Reviewed-by: Baolin Wang 
---
 drivers/mailbox/sprd-mailbox.c | 88 ++
 1 file changed, 71 insertions(+), 17 deletions(-)

diff --git a/drivers/mailbox/sprd-mailbox.c b/drivers/mailbox/sprd-mailbox.c
index 94d9067d..0a1449d 100644
--- a/drivers/mailbox/sprd-mailbox.c
+++ b/drivers/mailbox/sprd-mailbox.c
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -50,13 +51,17 @@
 #define SPRD_OUTBOX_FIFO_NOT_EMPTY_IRQ BIT(0)
 #define SPRD_OUTBOX_FIFO_IRQ_MASK  GENMASK(4, 0)
 
+#define SPRD_OUTBOX_BASE_SPAN  0x1000
 #define SPRD_MBOX_CHAN_MAX 8
+#define SPRD_SUPP_INBOX_ID_SC9863A 7
 
 struct sprd_mbox_priv {
struct mbox_controller  mbox;
struct device   *dev;
void __iomem*inbox_base;
void __iomem*outbox_base;
+   /*  Base register address for supplementary outbox */
+   void __iomem*supp_base;
struct clk  *clk;
u32 outbox_fifo_depth;
 
@@ -96,14 +101,13 @@ static u32 sprd_mbox_get_fifo_len(struct sprd_mbox_priv 
*priv, u32 fifo_sts)
return fifo_len;
 }
 
-static irqreturn_t sprd_mbox_outbox_isr(int irq, void *data)
+static irqreturn_t do_outbox_isr(void __iomem *base, struct sprd_mbox_priv 
*priv)
 {
-   struct sprd_mbox_priv *priv = data;
struct mbox_chan *chan;
u32 fifo_sts, fifo_len, msg[2];
int i, id;
 
-   fifo_sts = readl(priv->outbox_base + SPRD_MBOX_FIFO_STS);
+   fifo_sts = readl(base + SPRD_MBOX_FIFO_STS);
 
fifo_len = sprd_mbox_get_fifo_len(priv, fifo_sts);
if (!fifo_len) {
@@ -112,9 +116,9 @@ static irqreturn_t sprd_mbox_outbox_isr(int irq, void *data)
}
 
for (i = 0; i < fifo_len; i++) {
-   msg[0] = readl(priv->outbox_base + SPRD_MBOX_MSG_LOW);
-   msg[1] = readl(priv->outbox_base + SPRD_MBOX_MSG_HIGH);
-   id = readl(priv->outbox_base + SPRD_MBOX_ID);
+   msg[0] = readl(base + SPRD_MBOX_MSG_LOW);
+   msg[1] = readl(base + SPRD_MBOX_MSG_HIGH);
+   id = readl(base + SPRD_MBOX_ID);
 
chan = &priv->chan[id];
if (chan->cl)
@@ -124,15 +128,29 @@ static irqreturn_t sprd_mbox_outbox_isr(int irq, void 
*data)
"message's been dropped at ch[%d]\n", id);
 
/* Trigger to update outbox FIFO pointer */
-   writel(0x1, priv->outbox_base + SPRD_MBOX_TRIGGER);
+   writel(0x1, base + SPRD_MBOX_TRIGGER);
}
 
/* Clear irq status after reading all message. */
-   writel(SPRD_MBOX_IRQ_CLR, priv->outbox_base + SPRD_MBOX_IRQ_STS);
+   writel(SPRD_MBOX_IRQ_CLR, base + SPRD_MBOX_IRQ_STS);
 
return IRQ_HANDLED;
 }
 
+static irqreturn_t sprd_mbox_outbox_isr(int irq, void *data)
+{
+   struct sprd_mbox_priv *priv = data;
+
+   return do_outbox_isr(priv->outbox_base, priv);
+}
+
+static irqreturn_t sprd_mbox_supp_isr(int irq, void *data)
+{
+   struct sprd_mbox_priv *priv = data;
+
+   return do_outbox_isr(priv->supp_base, priv);
+}
+
 static irqreturn_t sprd_mbox_inbox_isr(int irq, void *data)
 {
struct sprd_mbox_priv *priv = data;
@@ -235,6 +253,14 @@ static int sprd_mbox_startup(struct mbox_chan *chan)
val = readl(priv->outbox_base + SPRD_MBOX_IRQ_MSK);
val &= ~SPRD_OUTBOX_FIFO_NOT_EMPTY_IRQ;
writel(val, priv->outbox_base + SPRD_MBOX_IRQ_MSK);
+
+   /* Enable supplementary outbox as the fundamental one */
+   if (priv->supp_base) {
+   writel(0x0, priv->supp_base + SPRD_MBOX_FIFO_RST);
+   val = readl(priv->supp_base + SPRD_MBOX_IRQ_MSK);
+   val &= ~SPRD_OUTBOX_FIFO_NOT_EMPTY_IRQ;
+   writel(val, priv->supp_base + SPRD_MBOX_IRQ_MSK);
+   }
}
mutex_unlock(&priv->lock);
 
@@ -250,6 +276,10 @@ static void sprd_mbox_shutdown(struct mbox_chan *chan)
/* Disable inbox & outbox interrupt */
writel(SPRD_INBOX_FIFO_IRQ_MASK, 

Re: [syzbot] KASAN: use-after-free Read in kill_pending_fw_fallback_reqs

2021-03-18 Thread Dmitry Vyukov
On Fri, Mar 19, 2021 at 7:08 AM Hillf Danton  wrote:
>
> On Thu, 18 Mar 2021 08:10:19 -0700
> > Hello,
> >
> > syzbot found the following issue on:
> >
> > HEAD commit:6417f031 module: remove never implemented MODULE_SUPPORTED..
> > git tree:   upstream
> > console output: https://syzkaller.appspot.com/x/log.txt?x=16293a7cd0
> > kernel config:  https://syzkaller.appspot.com/x/.config?x=ab2c8a4eaedddecd
> > dashboard link: https://syzkaller.appspot.com/bug?extid=6e23e12624dbacf657bc
> >
> > Unfortunately, I don't have any reproducer for this issue yet.
>
> Looks like the same cause as
> Reported-by: syzbot+de271708674e20930...@syzkaller.appspotmail.com

Hi Hillf,

Let's tell syzbot about this then:

#syz dup: KASAN: use-after-free Read in firmware_fallback_sysfs

Please see http://bit.do/syzbot#communication-with-syzbot for details
on communicating with syzbot.
(and please don't CC more than 1 syzbot+HASH emails, it may cause
havoc, syzbot won't be able to figure out what bug people are talking
about).


> > IMPORTANT: if you fix the issue, please add the following tag to the commit:
> > Reported-by: syzbot+6e23e12624dbacf65...@syzkaller.appspotmail.com
> >
> > ==
> > BUG: KASAN: use-after-free in kill_pending_fw_fallback_reqs+0x2fb/0x370 
> > drivers/base/firmware_loader/fallback.c:116
> > Read of size 8 at addr 8880757caac0 by task syz-executor.1/14981
> >
> > CPU: 0 PID: 14981 Comm: syz-executor.1 Not tainted 5.12.0-rc3-syzkaller #0
> > Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS 
> > Google 01/01/2011
> > Call Trace:
> >  __dump_stack lib/dump_stack.c:79 [inline]
> >  dump_stack+0x141/0x1d7 lib/dump_stack.c:120
> >  print_address_description.constprop.0.cold+0x5b/0x2f8 mm/kasan/report.c:232
> >  __kasan_report mm/kasan/report.c:399 [inline]
> >  kasan_report.cold+0x7c/0xd8 mm/kasan/report.c:416
> >  kill_pending_fw_fallback_reqs+0x2fb/0x370 
> > drivers/base/firmware_loader/fallback.c:116
> >  fw_pm_notify+0xa2/0x150 drivers/base/firmware_loader/main.c:1448
> >  notifier_call_chain+0xb5/0x200 kernel/notifier.c:83
> >  notifier_call_chain_robust kernel/notifier.c:118 [inline]
> >  blocking_notifier_call_chain_robust kernel/notifier.c:302 [inline]
> >  blocking_notifier_call_chain_robust+0xc4/0x160 kernel/notifier.c:290
> >  pm_notifier_call_chain_robust+0x26/0x60 kernel/power/main.c:87
> >  snapshot_open+0x190/0x2a0 kernel/power/user.c:75
> >  misc_open+0x372/0x4a0 drivers/char/misc.c:141
> >  chrdev_open+0x266/0x770 fs/char_dev.c:414
> >  do_dentry_open+0x4b9/0x11b0 fs/open.c:826
> >  do_open fs/namei.c:3365 [inline]
> >  path_openat+0x1c0e/0x27e0 fs/namei.c:3498
> >  do_filp_open+0x17e/0x3c0 fs/namei.c:3525
> >  do_sys_openat2+0x16d/0x420 fs/open.c:1187
> >  do_sys_open fs/open.c:1203 [inline]
> >  __do_sys_openat fs/open.c:1219 [inline]
> >  __se_sys_openat fs/open.c:1214 [inline]
> >  __x64_sys_openat+0x13f/0x1f0 fs/open.c:1214
> >  do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46
> >  entry_SYSCALL_64_after_hwframe+0x44/0xae
> > RIP: 0033:0x465f69
> > Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 48 89 f8 48 89 f7 
> > 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff 
> > ff 73 01 c3 48 c7 c1 bc ff ff ff f7 d8 64 89 01 48
> > RSP: 002b:7f9819e12188 EFLAGS: 0246 ORIG_RAX: 0101
> > RAX: ffda RBX: 0056bf60 RCX: 00465f69
> > RDX:  RSI: 2ac0 RDI: ff9c
> > RBP: 004bfa8f R08:  R09: 
> > R10:  R11: 0246 R12: 0056bf60
> > R13: 7ffd557c11df R14: 7f9819e12300 R15: 00022000
> >
> > Allocated by task 13418:
> >  kasan_save_stack+0x1b/0x40 mm/kasan/common.c:38
> >  kasan_set_track mm/kasan/common.c:46 [inline]
> >  set_alloc_info mm/kasan/common.c:427 [inline]
> >  kasan_kmalloc mm/kasan/common.c:506 [inline]
> >  kasan_kmalloc mm/kasan/common.c:465 [inline]
> >  __kasan_kmalloc+0x99/0xc0 mm/kasan/common.c:515
> >  kmalloc include/linux/slab.h:554 [inline]
> >  kzalloc include/linux/slab.h:684 [inline]
> >  __allocate_fw_priv drivers/base/firmware_loader/main.c:186 [inline]
> >  alloc_lookup_fw_priv drivers/base/firmware_loader/main.c:250 [inline]
> >  _request_firmware_prepare drivers/base/firmware_loader/main.c:744 [inline]
> >  _request_firmware+0x2de/0xe80 drivers/base/firmware_loader/main.c:806
> >  request_firmware+0x32/0x50 drivers/base/firmware_loader/main.c:875
> >  reg_reload_regdb+0x7a/0x240 net/wireless/reg.c:1095
> >  genl_family_rcv_msg_doit+0x228/0x320 net/netlink/genetlink.c:739
> >  genl_family_rcv_msg net/netlink/genetlink.c:783 [inline]
> >  genl_rcv_msg+0x328/0x580 net/netlink/genetlink.c:800
> >  netlink_rcv_skb+0x153/0x420 net/netlink/af_netlink.c:2502
> >  genl_rcv+0x24/0x40 net/netlink/genetlink.c:811
> >  netlink_unicast_kernel net/netlink/af_netlink.c:1312 [in

[PATCH -next] drm/rockchip: remove unused variable 'old_state'

2021-03-18 Thread Bixuan Cui
Fix the warning:

drivers/gpu/drm/rockchip/rockchip_drm_vop.c:882:26:warning: unused variable 
‘old_state’ [-Wunused-variable]
  struct drm_plane_state *old_state = drm_atomic_get_old_plane_state(state,

Signed-off-by: Bixuan Cui 
---
 drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c 
b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
index 81c70d7a0471..64469439ddf2 100644
--- a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
+++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
@@ -879,8 +879,6 @@ static void vop_plane_atomic_disable(struct drm_plane 
*plane,
 static void vop_plane_atomic_update(struct drm_plane *plane,
struct drm_atomic_state *state)
 {
-   struct drm_plane_state *old_state = 
drm_atomic_get_old_plane_state(state,
-  
plane);
struct drm_plane_state *new_state = 
drm_atomic_get_new_plane_state(state,
   
plane);
struct drm_crtc *crtc = new_state->crtc;
-- 
2.17.1



arch/powerpc/lib/sstep.c:1172:21: error: variable 'suffix' set but not used

2021-03-18 Thread kernel test robot
Hi Jordan,

FYI, the error/warning still remains.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
master
head:   8b12a62a4e3ed4ae99c715034f557eb391d6b196
commit: 650b55b707fdfa764e9f2b81314d3eb4216fb962 powerpc: Add prefixed 
instructions to instruction data type
date:   10 months ago
config: powerpc-mpc866_ads_defconfig (attached as .config)
compiler: powerpc-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=650b55b707fdfa764e9f2b81314d3eb4216fb962
git remote add linus 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
git fetch --no-tags linus master
git checkout 650b55b707fdfa764e9f2b81314d3eb4216fb962
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross 
ARCH=powerpc 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot 

All errors (new ones prefixed by >>):

   arch/powerpc/lib/sstep.c: In function 'analyse_instr':
>> arch/powerpc/lib/sstep.c:1172:21: error: variable 'suffix' set but not used 
>> [-Werror=unused-but-set-variable]
1172 |  unsigned int word, suffix;
 | ^~
   arch/powerpc/lib/sstep.c:1168:31: error: variable 'rc' set but not used 
[-Werror=unused-but-set-variable]
1168 |  unsigned int opcode, ra, rb, rc, rd, spr, u;
 |   ^~
   cc1: all warnings being treated as errors


vim +/suffix +1172 arch/powerpc/lib/sstep.c

  1153  
  1154  /*
  1155   * Decode an instruction, and return information about it in *op
  1156   * without changing *regs.
  1157   * Integer arithmetic and logical instructions, branches, and barrier
  1158   * instructions can be emulated just using the information in *op.
  1159   *
  1160   * Return value is 1 if the instruction can be emulated just by
  1161   * updating *regs with the information in *op, -1 if we need the
  1162   * GPRs but *regs doesn't contain the full register set, or 0
  1163   * otherwise.
  1164   */
  1165  int analyse_instr(struct instruction_op *op, const struct pt_regs *regs,
  1166struct ppc_inst instr)
  1167  {
  1168  unsigned int opcode, ra, rb, rc, rd, spr, u;
  1169  unsigned long int imm;
  1170  unsigned long int val, val2;
  1171  unsigned int mb, me, sh;
> 1172  unsigned int word, suffix;
  1173  long ival;
  1174  
  1175  word = ppc_inst_val(instr);
  1176  suffix = ppc_inst_suffix(instr);
  1177  
  1178  op->type = COMPUTE;
  1179  
  1180  opcode = ppc_inst_primary_opcode(instr);
  1181  switch (opcode) {
  1182  case 16:/* bc */
  1183  op->type = BRANCH;
  1184  imm = (signed short)(word & 0xfffc);
  1185  if ((word & 2) == 0)
  1186  imm += regs->nip;
  1187  op->val = truncate_if_32bit(regs->msr, imm);
  1188  if (word & 1)
  1189  op->type |= SETLK;
  1190  if (branch_taken(word, regs, op))
  1191  op->type |= BRTAKEN;
  1192  return 1;
  1193  #ifdef CONFIG_PPC64
  1194  case 17:/* sc */
  1195  if ((word & 0xfe2) == 2)
  1196  op->type = SYSCALL;
  1197  else
  1198  op->type = UNKNOWN;
  1199  return 0;
  1200  #endif
  1201  case 18:/* b */
  1202  op->type = BRANCH | BRTAKEN;
  1203  imm = word & 0x03fc;
  1204  if (imm & 0x0200)
  1205  imm -= 0x0400;
  1206  if ((word & 2) == 0)
  1207  imm += regs->nip;
  1208  op->val = truncate_if_32bit(regs->msr, imm);
  1209  if (word & 1)
  1210  op->type |= SETLK;
  1211  return 1;
  1212  case 19:
  1213  switch ((word >> 1) & 0x3ff) {
  1214  case 0: /* mcrf */
  1215  op->type = COMPUTE + SETCC;
  1216  rd = 7 - ((word >> 23) & 0x7);
  1217  ra = 7 - ((word >> 18) & 0x7);
  1218  rd *= 4;
  1219  ra *= 4;
  1220  val = (regs->ccr >> ra) & 0xf;
  1221  op->ccval = (regs->ccr & ~(0xfUL << rd)) | (val 
<< rd);
  1222  return 1;
  1223  
  1224  case 16:/* bclr */
  1225  case 528:   /*

[PATCH v2 00/21] ipmi: Allow raw access to KCS devices

2021-03-18 Thread Andrew Jeffery
Hello,

This series is a bit of a mix of things, but its primary purpose is to
expose BMC KCS IPMI devices to userspace in a way that enables userspace
to talk to host firmware using protocols that are not IPMI.

v1 can be found here:

https://lore.kernel.org/openbmc/20210219142523.3464540-1-and...@aj.id.au/

Changes in v2 include:

* A rebase onto v5.12-rc2
* Incorporation of off-list feedback on SerIRQ configuration from
  Chiawei
* Further validation on hardware for ASPEED KCS devices 2, 3 and 4
* Lifting the existing single-open constraint of the IPMI chardev
* Fixes addressing Rob's feedback on the conversion of the ASPEED KCS
  binding to dt-schema
* Fixes addressing Rob's feedback on the new aspeed,lpc-interrupts
  property definition for the ASPEED KCS binding

A new chardev device is added whose implementation exposes the Input
Data Register (IDR), Output Data Register (ODR) and Status Register
(STR) via read() and write(), and implements poll() for event
monitoring.

The existing /dev/ipmi-kcs* chardev interface exposes the KCS devices in
a way which encoded the IPMI protocol in its behaviour. However, as
LPC[0] KCS devices give us bi-directional interrupts between the host
and a BMC with both a data and status byte, they are useful for purposes
beyond IPMI.

As a concrete example, libmctp[1] implements a vendor-defined MCTP[2]
binding using a combination of LPC Firmware cycles for bulk data
transfer and a KCS device via LPC IO cycles for out-of-band protocol
control messages[3]. This gives a throughput improvement over the
standard KCS binding[4] while continuing to exploit the ease of setup of
the LPC bus for early boot firmware on the host processor.

The series takes a bit of a winding path to achieve its aim:

1. It begins with patches 1-5 put together by Chia-Wei, which I've
rebased on v5.12-rc2. These fix the ASPEED LPC bindings and other
non-KCS LPC-related ASPEED device drivers in a way that enables the
SerIRQ patches at the end of the series. With Joel's review I'm hoping
these 5 can go through the aspeed tree, and that the rest can go through
the IPMI tree.

2. Next, patches 6-13 fairly heavily refactor the KCS support in the
IPMI part of the tree, re-architecting things such that it's possible to
support multiple chardev implementations sitting on top of the ASPEED
and Nuvoton device drivers. However, the KCS code didn't really have
great separation of concerns as it stood, so even if we disregard the
multiple-chardev support I think the cleanups are worthwhile.

3. Patch 14 adds some interrupt management capabilities to the KCS
device drivers in preparation for patch 16, which introduces the new
"raw" KCS device interface. I'm not stoked about the device name/path,
so if people are looking to bikeshed something then feel free to lay
into that.

4. The remaining patches switch the ASPEED KCS devicetree binding to
dt-schema, add a new interrupt property to describe the SerIRQ behaviour
of the device and finally clean up Serial IRQ support in the ASPEED KCS
driver.

Rob: The dt-binding patches still come before the relevant driver
changes, I tried to keep the two close together in the series, hence the
bindings changes not being patches 1 and 2.

I've exercised the series under qemu with the rainier-bmc machine plus
additional patches for KCS support[5]. I've also substituted this series in
place of a hacky out-of-tree driver that we've been using for the
libmctp stack and successfully booted the host processor under our
internal full-platform simulation tools for a Rainier system.

Note that this work touches the Nuvoton driver as well as ASPEED's, but
I don't have the capability to test those changes or the IPMI chardev
path. Tested-by tags would be much appreciated if you can exercise one
or both.

Please review!

Andrew

[0] 
https://www.intel.com/content/dam/www/program/design/us/en/documents/low-pin-count-interface-specification.pdf
[1] https://github.com/openbmc/libmctp/
[2] 
https://www.dmtf.org/sites/default/files/standards/documents/DSP0236_1.3.1.pdf
[3] 
https://github.com/openbmc/libmctp/blob/master/docs/bindings/vendor-astlpc.md
[4] 
https://www.dmtf.org/sites/default/files/standards/documents/DSP0254_1.0.0.pdf
[5] https://lore.kernel.org/qemu-devel/20210309131641.2709380-1-...@kaod.org/

Andrew Jeffery (16):
  ipmi: kcs_bmc_aspeed: Use of match data to extract KCS properties
  ipmi: kcs_bmc: Make status update atomic
  ipmi: kcs_bmc: Rename {read,write}_{status,data}() functions
  ipmi: kcs_bmc: Split out kcs_bmc_cdev_ipmi
  ipmi: kcs_bmc: Turn the driver data-structures inside-out
  ipmi: kcs_bmc: Split headers into device and client
  ipmi: kcs_bmc: Strip private client data from struct kcs_bmc
  ipmi: kcs_bmc: Decouple the IPMI chardev from the core
  ipmi: kcs_bmc: Allow clients to control KCS IRQ state
  ipmi: kcs_bmc: Don't enforce single-open policy in the kernel
  ipmi: kcs_bmc: Add a "raw" character device interface
  dt-bindings: ipmi: Convert ASPEED KCS binding 

RE: [PATCH 03/11] i2c: imx-lpi2c: add ipg clk for lpi2c driver

2021-03-18 Thread Clark Wang

> -Original Message-
> From: Aisheng Dong 
> Sent: Friday, March 19, 2021 12:46
> To: Clark Wang ; shawn...@kernel.org;
> s.ha...@pengutronix.de
> Cc: ker...@pengutronix.de; feste...@gmail.com; dl-linux-imx  i...@nxp.com>; sumit.sem...@linaro.org; christian.koe...@amd.com;
> linux-...@vger.kernel.org; linux-arm-ker...@lists.infradead.org; linux-
> ker...@vger.kernel.org
> Subject: RE: [PATCH 03/11] i2c: imx-lpi2c: add ipg clk for lpi2c driver
>
> > From: Clark Wang 
> > Sent: Wednesday, March 17, 2021 2:54 PM
> >
> > The lpi2c IP needs two clks: ipg clk and per clk. The old lpi2c driver
> > missed ipg clk. This patch adds ipg clk for lpi2c driver.
> >
>
> Pleas also update dt-binding and sent along with this patchset.(before this
> one)

Okay, thanks.

>
> > Signed-off-by: Gao Pan 
> > Signed-off-by: Clark Wang 
> > Acked-by: Fugang Duan 
>
> You can drop the Ack tag if the patch was changed
>
> > ---
> >  drivers/i2c/busses/i2c-imx-lpi2c.c | 28 +---
> >  1 file changed, 21 insertions(+), 7 deletions(-)
> >
> > diff --git a/drivers/i2c/busses/i2c-imx-lpi2c.c
> > b/drivers/i2c/busses/i2c-imx-lpi2c.c
> > index 1e920e7ac7c1..664fcc0dba51 100644
> > --- a/drivers/i2c/busses/i2c-imx-lpi2c.c
> > +++ b/drivers/i2c/busses/i2c-imx-lpi2c.c
> > @@ -94,7 +94,8 @@ enum lpi2c_imx_pincfg {
> >
> >  struct lpi2c_imx_struct {
> > struct i2c_adapter  adapter;
> > -   struct clk  *clk;
> > +   struct clk  *clk_per;
> > +   struct clk  *clk_ipg;
> > void __iomem*base;
> > __u8*rx_buf;
> > __u8*tx_buf;
> > @@ -563,10 +564,16 @@ static int lpi2c_imx_probe(struct
> > platform_device
> > *pdev)
> > strlcpy(lpi2c_imx->adapter.name, pdev->name,
> > sizeof(lpi2c_imx->adapter.name));
> >
> > -   lpi2c_imx->clk = devm_clk_get(&pdev->dev, NULL);
> > -   if (IS_ERR(lpi2c_imx->clk)) {
> > +   lpi2c_imx->clk_per = devm_clk_get(&pdev->dev, "per");
> > +   if (IS_ERR(lpi2c_imx->clk_per)) {
> > dev_err(&pdev->dev, "can't get I2C peripheral clock\n");
> > -   return PTR_ERR(lpi2c_imx->clk);
> > +   return PTR_ERR(lpi2c_imx->clk_per);
> > +   }
> > +
> > +   lpi2c_imx->clk_ipg = devm_clk_get(&pdev->dev, "ipg");
> > +   if (IS_ERR(lpi2c_imx->clk_ipg)) {
> > +   dev_err(&pdev->dev, "can't get I2C ipg clock\n");
> > +   return PTR_ERR(lpi2c_imx->clk_ipg);
> > }
>
> Will this break exist dts?

It will not break the build. But will break the lpi2c probe for imx7ulp and 
imx8qxp/qm.
I will send two patches to update dts in V2.

Best Regards,
Clark Wang

>
> Regards
> Aisheng
>
> >
> > ret = of_property_read_u32(pdev->dev.of_node,
> > @@ -633,7 +640,8 @@ static int __maybe_unused
> > lpi2c_runtime_suspend(struct device *dev)  {
> > struct lpi2c_imx_struct *lpi2c_imx = dev_get_drvdata(dev);
> >
> > -   clk_disable_unprepare(lpi2c_imx->clk);
> > +   clk_disable_unprepare(lpi2c_imx->clk_ipg);
> > +   clk_disable_unprepare(lpi2c_imx->clk_per);
> > pinctrl_pm_select_idle_state(dev);
> >
> > return 0;
> > @@ -645,12 +653,18 @@ static int __maybe_unused
> > lpi2c_runtime_resume(struct device *dev)
> > int ret;
> >
> > pinctrl_pm_select_default_state(dev);
> > -   ret = clk_prepare_enable(lpi2c_imx->clk);
> > +   ret = clk_prepare_enable(lpi2c_imx->clk_per);
> > if (ret) {
> > -   dev_err(dev, "can't enable I2C clock, ret=%d\n", ret);
> > +   dev_err(dev, "can't enable I2C per clock, ret=%d\n", ret);
> > return ret;
> > }
> >
> > +   ret = clk_prepare_enable(lpi2c_imx->clk_ipg);
> > +   if (ret) {
> > +   clk_disable_unprepare(lpi2c_imx->clk_per);
> > +   dev_err(dev, "can't enable I2C ipg clock, ret=%d\n", ret);
> > +   }
> > +
> > return ret;
> >  }
> >
> > --
> > 2.25.1



smime.p7s
Description: S/MIME cryptographic signature


Re: [PATCH v3 1/2] arm64: dts: ti: k3-am64: Add GPIO DT nodes

2021-03-18 Thread Lokesh Vutla



On 19/03/21 10:49 am, Aswath Govindraju wrote:
> Add device tree nodes for GPIO modules and interrupt controller in main
> and mcu domains.
> 
> Signed-off-by: Aswath Govindraju 

Reviewed-by: Lokesh Vutla 

Thanks and regards,
Lokesh

> ---
>  arch/arm64/boot/dts/ti/k3-am64-main.dtsi | 45 
>  arch/arm64/boot/dts/ti/k3-am64-mcu.dtsi  | 27 ++
>  2 files changed, 72 insertions(+)
> 
> diff --git a/arch/arm64/boot/dts/ti/k3-am64-main.dtsi 
> b/arch/arm64/boot/dts/ti/k3-am64-main.dtsi
> index a03b66456062..b997d13f9ec5 100644
> --- a/arch/arm64/boot/dts/ti/k3-am64-main.dtsi
> +++ b/arch/arm64/boot/dts/ti/k3-am64-main.dtsi
> @@ -373,6 +373,51 @@
>   clocks = <&k3_clks 145 0>;
>   };
>  
> + main_gpio_intr: interrupt-controller0 {
> + compatible = "ti,sci-intr";
> + ti,intr-trigger-type = <1>;
> + interrupt-controller;
> + interrupt-parent = <&gic500>;
> + #interrupt-cells = <1>;
> + ti,sci = <&dmsc>;
> + ti,sci-dev-id = <3>;
> + ti,interrupt-ranges = <0 32 16>;
> + };
> +
> + main_gpio0: gpio@60 {
> + compatible = "ti,am64-gpio", "ti,keystone-gpio";
> + reg = <0x0 0x0060 0x0 0x100>;
> + gpio-controller;
> + #gpio-cells = <2>;
> + interrupt-parent = <&main_gpio_intr>;
> + interrupts = <190>, <191>, <192>,
> +  <193>, <194>, <195>;
> + interrupt-controller;
> + #interrupt-cells = <2>;
> + ti,ngpio = <87>;
> + ti,davinci-gpio-unbanked = <0>;
> + power-domains = <&k3_pds 77 TI_SCI_PD_EXCLUSIVE>;
> + clocks = <&k3_clks 77 0>;
> + clock-names = "gpio";
> + };
> +
> + main_gpio1: gpio@601000 {
> + compatible = "ti,am64-gpio", "ti,keystone-gpio";
> + reg = <0x0 0x00601000 0x0 0x100>;
> + gpio-controller;
> + #gpio-cells = <2>;
> + interrupt-parent = <&main_gpio_intr>;
> + interrupts = <180>, <181>, <182>,
> +  <183>, <184>, <185>;
> + interrupt-controller;
> + #interrupt-cells = <2>;
> + ti,ngpio = <88>;
> + ti,davinci-gpio-unbanked = <0>;
> + power-domains = <&k3_pds 78 TI_SCI_PD_EXCLUSIVE>;
> + clocks = <&k3_clks 78 0>;
> + clock-names = "gpio";
> + };
> +
>   sdhci0: mmc@fa1 {
>   compatible = "ti,am64-sdhci-8bit";
>   reg = <0x00 0xfa1 0x00 0x260>, <0x00 0xfa18000 0x00 0x134>;
> diff --git a/arch/arm64/boot/dts/ti/k3-am64-mcu.dtsi 
> b/arch/arm64/boot/dts/ti/k3-am64-mcu.dtsi
> index 1d2be485a669..99e94dee1bd4 100644
> --- a/arch/arm64/boot/dts/ti/k3-am64-mcu.dtsi
> +++ b/arch/arm64/boot/dts/ti/k3-am64-mcu.dtsi
> @@ -73,4 +73,31 @@
>   power-domains = <&k3_pds 148 TI_SCI_PD_EXCLUSIVE>;
>   clocks = <&k3_clks 148 0>;
>   };
> +
> + mcu_gpio_intr: interrupt-controller1 {
> + compatible = "ti,sci-intr";
> + ti,intr-trigger-type = <1>;
> + interrupt-controller;
> + interrupt-parent = <&gic500>;
> + #interrupt-cells = <1>;
> + ti,sci = <&dmsc>;
> + ti,sci-dev-id = <5>;
> + ti,interrupt-ranges = <0 104 4>;
> + };
> +
> + mcu_gpio0: gpio@4201000 {
> + compatible = "ti,am64-gpio", "keystone-gpio";
> + reg = <0x0 0x4201000 0x0 0x100>;
> + gpio-controller;
> + #gpio-cells = <2>;
> + interrupt-parent = <&mcu_gpio_intr>;
> + interrupts = <30>, <31>;
> + interrupt-controller;
> + #interrupt-cells = <2>;
> + ti,ngpio = <23>;
> + ti,davinci-gpio-unbanked = <0>;
> + power-domains = <&k3_pds 79 TI_SCI_PD_EXCLUSIVE>;
> + clocks = <&k3_clks 79 0>;
> + clock-names = "gpio";
> + };
>  };
> 


Re: [PATCH v3 2/2] arm64: dts: ti: k3-am642: reserve gpio in mcu domain for firmware usage

2021-03-18 Thread Lokesh Vutla



On 19/03/21 10:49 am, Aswath Govindraju wrote:
> The gpio0 subsystem present in MCU domain might be used by firmware and is
> not pinned out in evm/sk. Therefore, reserve it for MCU firmware.
> 
> Signed-off-by: Aswath Govindraju 

Reviewed-by: Lokesh Vutla 

Thanks and regards,
Lokesh



[PATCH v2 01/21] dt-bindings: aspeed-lpc: Remove LPC partitioning

2021-03-18 Thread Andrew Jeffery
From: "Chia-Wei, Wang" 

The LPC controller has no concept of the BMC and the Host partitions.
This patch fixes the documentation by removing the description on LPC
partitions. The register offsets illustrated in the DTS node examples
are also fixed to adapt to the LPC DTS change.

Signed-off-by: Chia-Wei Wang 
Reviewed-by: Andrew Jeffery 
Acked-by: Rob Herring 
Acked-by: Lee Jones 
---
 .../devicetree/bindings/mfd/aspeed-lpc.txt| 100 +-
 1 file changed, 25 insertions(+), 75 deletions(-)

diff --git a/Documentation/devicetree/bindings/mfd/aspeed-lpc.txt 
b/Documentation/devicetree/bindings/mfd/aspeed-lpc.txt
index d0a38ba8b9ce..936aa108eab4 100644
--- a/Documentation/devicetree/bindings/mfd/aspeed-lpc.txt
+++ b/Documentation/devicetree/bindings/mfd/aspeed-lpc.txt
@@ -9,13 +9,7 @@ primary use case of the Aspeed LPC controller is as a slave on 
the bus
 conditions it can also take the role of bus master.
 
 The LPC controller is represented as a multi-function device to account for the
-mix of functionality it provides. The principle split is between the register
-layout at the start of the I/O space which is, to quote the Aspeed datasheet,
-"basically compatible with the [LPC registers from the] popular BMC controller
-H8S/2168[1]", and everything else, where everything else is an eclectic
-collection of functions with a esoteric register layout. "Everything else",
-here labeled the "host" portion of the controller, includes, but is not limited
-to:
+mix of functionality, which includes, but is not limited to:
 
 * An IPMI Block Transfer[2] Controller
 
@@ -44,80 +38,36 @@ Required properties
 ===
 
 - compatible:  One of:
-   "aspeed,ast2400-lpc", "simple-mfd"
-   "aspeed,ast2500-lpc", "simple-mfd"
-   "aspeed,ast2600-lpc", "simple-mfd"
+   "aspeed,ast2400-lpc-v2", "simple-mfd", "syscon"
+   "aspeed,ast2500-lpc-v2", "simple-mfd", "syscon"
+   "aspeed,ast2600-lpc-v2", "simple-mfd", "syscon"
 
 - reg: contains the physical address and length values of the Aspeed
 LPC memory region.
 
 - #address-cells: <1>
 - #size-cells: <1>
-- ranges:  Maps 0 to the physical address and length of the LPC memory
-region
-
-Required LPC Child nodes
-
-
-BMC Node
-
-
-- compatible:  One of:
-   "aspeed,ast2400-lpc-bmc"
-   "aspeed,ast2500-lpc-bmc"
-   "aspeed,ast2600-lpc-bmc"
-
-- reg: contains the physical address and length values of the
-H8S/2168-compatible LPC controller memory region
-
-Host Node
--
-
-- compatible:   One of:
-   "aspeed,ast2400-lpc-host", "simple-mfd", "syscon"
-   "aspeed,ast2500-lpc-host", "simple-mfd", "syscon"
-   "aspeed,ast2600-lpc-host", "simple-mfd", "syscon"
-
-- reg: contains the address and length values of the host-related
-register space for the Aspeed LPC controller
-
-- #address-cells: <1>
-- #size-cells: <1>
-- ranges:  Maps 0 to the address and length of the host-related LPC memory
+- ranges:  Maps 0 to the physical address and length of the LPC memory
 region
 
 Example:
 
 lpc: lpc@1e789000 {
-   compatible = "aspeed,ast2500-lpc", "simple-mfd";
+   compatible = "aspeed,ast2500-lpc-v2", "simple-mfd", "syscon";
reg = <0x1e789000 0x1000>;
 
#address-cells = <1>;
#size-cells = <1>;
ranges = <0x0 0x1e789000 0x1000>;
 
-   lpc_bmc: lpc-bmc@0 {
-   compatible = "aspeed,ast2500-lpc-bmc";
+   lpc_snoop: lpc-snoop@0 {
+   compatible = "aspeed,ast2600-lpc-snoop";
reg = <0x0 0x80>;
-   };
-
-   lpc_host: lpc-host@80 {
-   compatible = "aspeed,ast2500-lpc-host", "simple-mfd", "syscon";
-   reg = <0x80 0x1e0>;
-   reg-io-width = <4>;
-
-   #address-cells = <1>;
-   #size-cells = <1>;
-   ranges = <0x0 0x80 0x1e0>;
+   interrupts = ;
+   snoop-ports = <0x80>;
};
 };
 
-BMC Node Children
-==
-
-
-Host Node Children
-==
 
 LPC Host Interface Controller
 ---
@@ -149,14 +99,12 @@ Optional properties:
 
 Example:
 
-lpc-host@80 {
-   lpc_ctrl: lpc-ctrl@0 {
-   compatible = "aspeed,ast2500-lpc-ctrl";
-   reg = <0x0 0x80>;
-   clocks = <&syscon ASPEED_CLK_GATE_LCLK>;
-   memory-region = <&flash_memory>;
-   flash = <&spi>;
-   };
+lpc_ctrl: lpc-ctrl@80 {
+   compatible = "aspeed,ast2500-lpc-ctrl";
+   reg = <0x80 0x80>;
+   clocks = <&syscon ASPEED_CLK_GATE_LCLK>;
+   memory-region = <&flash_memory>;
+   flash = <&spi>;
 };
 
 LPC Host Controller
@@ -179,9 +127,9 @@ Required properties:
 
 Example:
 
-lhc: lhc@20 {
+lhc: lhc@a0 {
compatibl

[PATCH v2 02/21] ARM: dts: Remove LPC BMC and Host partitions

2021-03-18 Thread Andrew Jeffery
From: "Chia-Wei, Wang" 

The LPC controller has no concept of the BMC and the Host partitions.

A concrete instance is that the HICRB[5:4] are for the I/O port address
configurtaion of KCS channel 1/2. However, the KCS driver cannot access
HICRB for channel 1/2 initialization via syscon regmap interface due to
the parition boundary. (i.e. offset 80h)

In addition, for the HW design backward compatibility, a newly added HW
control bit could be located at any reserved one over the LPC addressing
space. Thereby, this patch removes the lpc-bmc and lpc-host child node
and thus the LPC partitioning.

Note that this change requires the synchronization between device tree
change and the driver change. To prevent the misuse of old devicetrees
with new drivers, or vice versa, the v2 compatible strings are adopted
for the LPC device as listed:

"aspeed,ast2400-lpc-v2"
"aspeed,ast2500-lpc-v2"
"aspeed,ast2600-lpc-v2"

Signed-off-by: Chia-Wei Wang 
Reviewed-by: Andrew Jeffery 
---
 arch/arm/boot/dts/aspeed-g4.dtsi |  70 +++---
 arch/arm/boot/dts/aspeed-g5.dtsi | 121 +-
 arch/arm/boot/dts/aspeed-g6.dtsi | 123 +--
 3 files changed, 133 insertions(+), 181 deletions(-)

diff --git a/arch/arm/boot/dts/aspeed-g4.dtsi b/arch/arm/boot/dts/aspeed-g4.dtsi
index e7a45ba18fc9..c5aeb3cf3a09 100644
--- a/arch/arm/boot/dts/aspeed-g4.dtsi
+++ b/arch/arm/boot/dts/aspeed-g4.dtsi
@@ -343,59 +343,45 @@ vuart: serial@1e787000 {
};
 
lpc: lpc@1e789000 {
-   compatible = "aspeed,ast2400-lpc", "simple-mfd";
+   compatible = "aspeed,ast2400-lpc-v2", 
"simple-mfd", "syscon";
reg = <0x1e789000 0x1000>;
+   reg-io-width = <4>;
 
#address-cells = <1>;
#size-cells = <1>;
ranges = <0x0 0x1e789000 0x1000>;
 
-   lpc_bmc: lpc-bmc@0 {
-   compatible = "aspeed,ast2400-lpc-bmc";
-   reg = <0x0 0x80>;
+   lpc_ctrl: lpc-ctrl@80 {
+   compatible = "aspeed,ast2400-lpc-ctrl";
+   reg = <0x80 0x10>;
+   clocks = <&syscon ASPEED_CLK_GATE_LCLK>;
+   status = "disabled";
};
 
-   lpc_host: lpc-host@80 {
-   compatible = "aspeed,ast2400-lpc-host", 
"simple-mfd", "syscon";
-   reg = <0x80 0x1e0>;
-   reg-io-width = <4>;
-
-   #address-cells = <1>;
-   #size-cells = <1>;
-   ranges = <0x0 0x80 0x1e0>;
-
-   lpc_ctrl: lpc-ctrl@0 {
-   compatible = 
"aspeed,ast2400-lpc-ctrl";
-   reg = <0x0 0x10>;
-   clocks = <&syscon 
ASPEED_CLK_GATE_LCLK>;
-   status = "disabled";
-   };
-
-   lpc_snoop: lpc-snoop@10 {
-   compatible = 
"aspeed,ast2400-lpc-snoop";
-   reg = <0x10 0x8>;
-   interrupts = <8>;
-   clocks = <&syscon 
ASPEED_CLK_GATE_LCLK>;
-   status = "disabled";
-   };
+   lpc_snoop: lpc-snoop@90 {
+   compatible = "aspeed,ast2400-lpc-snoop";
+   reg = <0x90 0x8>;
+   interrupts = <8>;
+   clocks = <&syscon ASPEED_CLK_GATE_LCLK>;
+   status = "disabled";
+   };
 
-   lhc: lhc@20 {
-   compatible = 
"aspeed,ast2400-lhc";
-   reg = <0x20 0x24 0x48 0x8>;
-   };
+   lhc: lhc@a0 {
+   compatible = "aspeed,ast2400-lhc";
+   reg = <0xa0 0x24 0xc8 0x8>;
+   };
 
-   lpc_reset: reset-controller@18 {
-   

[PATCH v2 04/21] pinctrl: aspeed-g5: Adapt to new LPC device tree layout

2021-03-18 Thread Andrew Jeffery
From: "Chia-Wei, Wang" 

Add check against LPC device v2 compatible string to
ensure that the fixed device tree layout is adopted.
The LPC register offsets are also fixed accordingly.

Signed-off-by: Chia-Wei Wang 
Reviewed-by: Andrew Jeffery 
Acked-by: Linus Walleij 
---
 drivers/pinctrl/aspeed/pinctrl-aspeed-g5.c | 17 +++--
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/drivers/pinctrl/aspeed/pinctrl-aspeed-g5.c 
b/drivers/pinctrl/aspeed/pinctrl-aspeed-g5.c
index 0cab4c2576e2..996ebcba4d38 100644
--- a/drivers/pinctrl/aspeed/pinctrl-aspeed-g5.c
+++ b/drivers/pinctrl/aspeed/pinctrl-aspeed-g5.c
@@ -60,7 +60,7 @@
 #define COND2  { ASPEED_IP_SCU, SCU94, GENMASK(1, 0), 0, 0 }
 
 /* LHCR0 is offset from the end of the H8S/2168-compatible registers */
-#define LHCR0  0x20
+#define LHCR0  0xa0
 #define GFX064 0x64
 
 #define B14 0
@@ -2648,14 +2648,19 @@ static struct regmap *aspeed_g5_acquire_regmap(struct 
aspeed_pinmux_data *ctx,
}
 
if (ip == ASPEED_IP_LPC) {
-   struct device_node *node;
+   struct device_node *np;
struct regmap *map;
 
-   node = of_parse_phandle(ctx->dev->of_node,
+   np = of_parse_phandle(ctx->dev->of_node,
"aspeed,external-nodes", 1);
-   if (node) {
-   map = syscon_node_to_regmap(node->parent);
-   of_node_put(node);
+   if (np) {
+   if (!of_device_is_compatible(np->parent, 
"aspeed,ast2400-lpc-v2") &&
+   !of_device_is_compatible(np->parent, 
"aspeed,ast2500-lpc-v2") &&
+   !of_device_is_compatible(np->parent, 
"aspeed,ast2600-lpc-v2"))
+   return ERR_PTR(-ENODEV);
+
+   map = syscon_node_to_regmap(np->parent);
+   of_node_put(np);
if (IS_ERR(map))
return map;
} else
-- 
2.27.0



[PATCH v2 03/21] ipmi: kcs: aspeed: Adapt to new LPC DTS layout

2021-03-18 Thread Andrew Jeffery
From: "Chia-Wei, Wang" 

Add check against LPC device v2 compatible string to
ensure that the fixed device tree layout is adopted.
The LPC register offsets are also fixed accordingly.

Signed-off-by: Chia-Wei Wang 
Reviewed-by: Andrew Jeffery 
Acked-by: Haiyue Wang 
---
 drivers/char/ipmi/kcs_bmc_aspeed.c | 27 ---
 1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/drivers/char/ipmi/kcs_bmc_aspeed.c 
b/drivers/char/ipmi/kcs_bmc_aspeed.c
index a140203c079b..eefe362f65f0 100644
--- a/drivers/char/ipmi/kcs_bmc_aspeed.c
+++ b/drivers/char/ipmi/kcs_bmc_aspeed.c
@@ -27,7 +27,6 @@
 
 #define KCS_CHANNEL_MAX 4
 
-/* mapped to lpc-bmc@0 IO space */
 #define LPC_HICR00x000
 #define LPC_HICR0_LPC3E  BIT(7)
 #define LPC_HICR0_LPC2E  BIT(6)
@@ -52,15 +51,13 @@
 #define LPC_STR1 0x03C
 #define LPC_STR2 0x040
 #define LPC_STR3 0x044
-
-/* mapped to lpc-host@80 IO space */
-#define LPC_HICRB0x080
+#define LPC_HICRB0x100
 #define LPC_HICRB_IBFIF4 BIT(1)
 #define LPC_HICRB_LPC4E  BIT(0)
-#define LPC_LADR40x090
-#define LPC_IDR4 0x094
-#define LPC_ODR4 0x098
-#define LPC_STR4 0x09C
+#define LPC_LADR40x110
+#define LPC_IDR4 0x114
+#define LPC_ODR4 0x118
+#define LPC_STR4 0x11C
 
 struct aspeed_kcs_bmc {
struct regmap *map;
@@ -348,12 +345,20 @@ static int aspeed_kcs_probe(struct platform_device *pdev)
struct device_node *np;
int rc;
 
-   np = pdev->dev.of_node;
+   np = dev->of_node->parent;
+   if (!of_device_is_compatible(np, "aspeed,ast2400-lpc-v2") &&
+   !of_device_is_compatible(np, "aspeed,ast2500-lpc-v2") &&
+   !of_device_is_compatible(np, "aspeed,ast2600-lpc-v2")) {
+   dev_err(dev, "unsupported LPC device binding\n");
+   return -ENODEV;
+   }
+
+   np = dev->of_node;
if (of_device_is_compatible(np, "aspeed,ast2400-kcs-bmc") ||
-   of_device_is_compatible(np, "aspeed,ast2500-kcs-bmc"))
+   of_device_is_compatible(np, "aspeed,ast2500-kcs-bmc"))
kcs_bmc = aspeed_kcs_probe_of_v1(pdev);
else if (of_device_is_compatible(np, "aspeed,ast2400-kcs-bmc-v2") ||
-   of_device_is_compatible(np, 
"aspeed,ast2500-kcs-bmc-v2"))
+of_device_is_compatible(np, "aspeed,ast2500-kcs-bmc-v2"))
kcs_bmc = aspeed_kcs_probe_of_v2(pdev);
else
return -EINVAL;
-- 
2.27.0



[PATCH] iio: adc: ad7292: Modify the bool initialization assignment

2021-03-18 Thread Guoqing chi
From: Guoqing Chi 

A bool initializer is best assigned to false rather than 0.

Signed-off-by: Guoqing Chi 
---
 drivers/iio/adc/ad7292.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/adc/ad7292.c b/drivers/iio/adc/ad7292.c
index 70e33dd1c9f7..3271a31afde1 100644
--- a/drivers/iio/adc/ad7292.c
+++ b/drivers/iio/adc/ad7292.c
@@ -260,7 +260,7 @@ static int ad7292_probe(struct spi_device *spi)
struct ad7292_state *st;
struct iio_dev *indio_dev;
struct device_node *child;
-   bool diff_channels = 0;
+   bool diff_channels = false;
int ret;
 
indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
-- 
2.17.1




[PATCH v2 06/21] ipmi: kcs_bmc_aspeed: Use of match data to extract KCS properties

2021-03-18 Thread Andrew Jeffery
Unpack and remove the aspeed_kcs_probe_of_v[12]() functions to aid
rearranging how the private device-driver memory is allocated.

Signed-off-by: Andrew Jeffery 
---
 drivers/char/ipmi/kcs_bmc_aspeed.c | 146 ++---
 1 file changed, 68 insertions(+), 78 deletions(-)

diff --git a/drivers/char/ipmi/kcs_bmc_aspeed.c 
b/drivers/char/ipmi/kcs_bmc_aspeed.c
index eefe362f65f0..061f53676206 100644
--- a/drivers/char/ipmi/kcs_bmc_aspeed.c
+++ b/drivers/char/ipmi/kcs_bmc_aspeed.c
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -63,6 +64,10 @@ struct aspeed_kcs_bmc {
struct regmap *map;
 };
 
+struct aspeed_kcs_of_ops {
+   int (*get_channel)(struct platform_device *pdev);
+   int (*get_io_address)(struct platform_device *pdev);
+};
 
 static u8 aspeed_kcs_inb(struct kcs_bmc *kcs_bmc, u32 reg)
 {
@@ -231,13 +236,10 @@ static const struct kcs_ioreg 
ast_kcs_bmc_ioregs[KCS_CHANNEL_MAX] = {
{ .idr = LPC_IDR4, .odr = LPC_ODR4, .str = LPC_STR4 },
 };
 
-static struct kcs_bmc *aspeed_kcs_probe_of_v1(struct platform_device *pdev)
+static int aspeed_kcs_of_v1_get_channel(struct platform_device *pdev)
 {
-   struct aspeed_kcs_bmc *priv;
struct device_node *np;
-   struct kcs_bmc *kcs;
u32 channel;
-   u32 slave;
int rc;
 
np = pdev->dev.of_node;
@@ -245,105 +247,78 @@ static struct kcs_bmc *aspeed_kcs_probe_of_v1(struct 
platform_device *pdev)
rc = of_property_read_u32(np, "kcs_chan", &channel);
if ((rc != 0) || (channel == 0 || channel > KCS_CHANNEL_MAX)) {
dev_err(&pdev->dev, "no valid 'kcs_chan' configured\n");
-   return ERR_PTR(-EINVAL);
+   return -EINVAL;
}
 
-   kcs = kcs_bmc_alloc(&pdev->dev, sizeof(struct aspeed_kcs_bmc), channel);
-   if (!kcs)
-   return ERR_PTR(-ENOMEM);
+   return channel;
+}
 
-   priv = kcs_bmc_priv(kcs);
-   priv->map = syscon_node_to_regmap(pdev->dev.parent->of_node);
-   if (IS_ERR(priv->map)) {
-   dev_err(&pdev->dev, "Couldn't get regmap\n");
-   return ERR_PTR(-ENODEV);
-   }
+static int aspeed_kcs_of_v1_get_io_address(struct platform_device *pdev)
+{
+   u32 slave;
+   int rc;
 
-   rc = of_property_read_u32(np, "kcs_addr", &slave);
-   if (rc) {
+   rc = of_property_read_u32(pdev->dev.of_node, "kcs_addr", &slave);
+   if (rc || slave > 0x) {
dev_err(&pdev->dev, "no valid 'kcs_addr' configured\n");
-   return ERR_PTR(-EINVAL);
+   return -EINVAL;
}
 
-   kcs->ioreg = ast_kcs_bmc_ioregs[channel - 1];
-   aspeed_kcs_set_address(kcs, slave);
-
-   return kcs;
-}
-
-static int aspeed_kcs_calculate_channel(const struct kcs_ioreg *regs)
-{
-   int i;
-
-   for (i = 0; i < ARRAY_SIZE(ast_kcs_bmc_ioregs); i++) {
-   if (!memcmp(&ast_kcs_bmc_ioregs[i], regs, sizeof(*regs)))
-   return i + 1;
-   }
-
-   return -EINVAL;
+   return slave;
 }
 
-static struct kcs_bmc *aspeed_kcs_probe_of_v2(struct platform_device *pdev)
+static int aspeed_kcs_of_v2_get_channel(struct platform_device *pdev)
 {
-   struct aspeed_kcs_bmc *priv;
struct device_node *np;
struct kcs_ioreg ioreg;
-   struct kcs_bmc *kcs;
const __be32 *reg;
-   int channel;
-   u32 slave;
-   int rc;
+   int i;
 
np = pdev->dev.of_node;
 
/* Don't translate addresses, we want offsets for the regmaps */
reg = of_get_address(np, 0, NULL, NULL);
if (!reg)
-   return ERR_PTR(-EINVAL);
+   return -EINVAL;
ioreg.idr = be32_to_cpup(reg);
 
reg = of_get_address(np, 1, NULL, NULL);
if (!reg)
-   return ERR_PTR(-EINVAL);
+   return -EINVAL;
ioreg.odr = be32_to_cpup(reg);
 
reg = of_get_address(np, 2, NULL, NULL);
if (!reg)
-   return ERR_PTR(-EINVAL);
+   return -EINVAL;
ioreg.str = be32_to_cpup(reg);
 
-   channel = aspeed_kcs_calculate_channel(&ioreg);
-   if (channel < 0)
-   return ERR_PTR(channel);
-
-   kcs = kcs_bmc_alloc(&pdev->dev, sizeof(struct aspeed_kcs_bmc), channel);
-   if (!kcs)
-   return ERR_PTR(-ENOMEM);
-
-   kcs->ioreg = ioreg;
-
-   priv = kcs_bmc_priv(kcs);
-   priv->map = syscon_node_to_regmap(pdev->dev.parent->of_node);
-   if (IS_ERR(priv->map)) {
-   dev_err(&pdev->dev, "Couldn't get regmap\n");
-   return ERR_PTR(-ENODEV);
+   for (i = 0; i < ARRAY_SIZE(ast_kcs_bmc_ioregs); i++) {
+   if (!memcmp(&ast_kcs_bmc_ioregs[i], &ioreg, sizeof(ioreg)))
+   return i + 1;
}
 
-   rc = of_property_read_u32(np, "aspeed,lpc-io-reg", &slave);
-   if (rc)
-   return ERR_PTR(rc);
+   retur

[PATCH v2 08/21] ipmi: kcs_bmc: Rename {read,write}_{status,data}() functions

2021-03-18 Thread Andrew Jeffery
Rename the functions in preparation for separating the IPMI chardev out
from the KCS BMC core.

Signed-off-by: Andrew Jeffery 
---
 drivers/char/ipmi/kcs_bmc.c | 52 ++---
 1 file changed, 25 insertions(+), 27 deletions(-)

diff --git a/drivers/char/ipmi/kcs_bmc.c b/drivers/char/ipmi/kcs_bmc.c
index 58fb1a7bd50d..c4336c1f2d6d 100644
--- a/drivers/char/ipmi/kcs_bmc.c
+++ b/drivers/char/ipmi/kcs_bmc.c
@@ -45,42 +45,42 @@ enum kcs_states {
 #define KCS_CMD_WRITE_END 0x62
 #define KCS_CMD_READ_BYTE 0x68
 
-static inline u8 read_data(struct kcs_bmc *kcs_bmc)
+static inline u8 kcs_bmc_read_data(struct kcs_bmc *kcs_bmc)
 {
return kcs_bmc->io_inputb(kcs_bmc, kcs_bmc->ioreg.idr);
 }
 
-static inline void write_data(struct kcs_bmc *kcs_bmc, u8 data)
+static inline void kcs_bmc_write_data(struct kcs_bmc *kcs_bmc, u8 data)
 {
kcs_bmc->io_outputb(kcs_bmc, kcs_bmc->ioreg.odr, data);
 }
 
-static inline u8 read_status(struct kcs_bmc *kcs_bmc)
+static inline u8 kcs_bmc_read_status(struct kcs_bmc *kcs_bmc)
 {
return kcs_bmc->io_inputb(kcs_bmc, kcs_bmc->ioreg.str);
 }
 
-static inline void write_status(struct kcs_bmc *kcs_bmc, u8 data)
+static inline void kcs_bmc_write_status(struct kcs_bmc *kcs_bmc, u8 data)
 {
kcs_bmc->io_outputb(kcs_bmc, kcs_bmc->ioreg.str, data);
 }
 
-static void update_status_bits(struct kcs_bmc *kcs_bmc, u8 mask, u8 val)
+static void kcs_bmc_update_status(struct kcs_bmc *kcs_bmc, u8 mask, u8 val)
 {
kcs_bmc->io_updateb(kcs_bmc, kcs_bmc->ioreg.str, mask, val);
 }
 
 static inline void set_state(struct kcs_bmc *kcs_bmc, u8 state)
 {
-   update_status_bits(kcs_bmc, KCS_STATUS_STATE_MASK,
+   kcs_bmc_update_status(kcs_bmc, KCS_STATUS_STATE_MASK,
KCS_STATUS_STATE(state));
 }
 
 static void kcs_force_abort(struct kcs_bmc *kcs_bmc)
 {
set_state(kcs_bmc, ERROR_STATE);
-   read_data(kcs_bmc);
-   write_data(kcs_bmc, KCS_ZERO_DATA);
+   kcs_bmc_read_data(kcs_bmc);
+   kcs_bmc_write_data(kcs_bmc, KCS_ZERO_DATA);
 
kcs_bmc->phase = KCS_PHASE_ERROR;
kcs_bmc->data_in_avail = false;
@@ -99,9 +99,9 @@ static void kcs_bmc_handle_data(struct kcs_bmc *kcs_bmc)
case KCS_PHASE_WRITE_DATA:
if (kcs_bmc->data_in_idx < KCS_MSG_BUFSIZ) {
set_state(kcs_bmc, WRITE_STATE);
-   write_data(kcs_bmc, KCS_ZERO_DATA);
+   kcs_bmc_write_data(kcs_bmc, KCS_ZERO_DATA);
kcs_bmc->data_in[kcs_bmc->data_in_idx++] =
-   read_data(kcs_bmc);
+   kcs_bmc_read_data(kcs_bmc);
} else {
kcs_force_abort(kcs_bmc);
kcs_bmc->error = KCS_LENGTH_ERROR;
@@ -112,7 +112,7 @@ static void kcs_bmc_handle_data(struct kcs_bmc *kcs_bmc)
if (kcs_bmc->data_in_idx < KCS_MSG_BUFSIZ) {
set_state(kcs_bmc, READ_STATE);
kcs_bmc->data_in[kcs_bmc->data_in_idx++] =
-   read_data(kcs_bmc);
+   kcs_bmc_read_data(kcs_bmc);
kcs_bmc->phase = KCS_PHASE_WRITE_DONE;
kcs_bmc->data_in_avail = true;
wake_up_interruptible(&kcs_bmc->queue);
@@ -126,34 +126,34 @@ static void kcs_bmc_handle_data(struct kcs_bmc *kcs_bmc)
if (kcs_bmc->data_out_idx == kcs_bmc->data_out_len)
set_state(kcs_bmc, IDLE_STATE);
 
-   data = read_data(kcs_bmc);
+   data = kcs_bmc_read_data(kcs_bmc);
if (data != KCS_CMD_READ_BYTE) {
set_state(kcs_bmc, ERROR_STATE);
-   write_data(kcs_bmc, KCS_ZERO_DATA);
+   kcs_bmc_write_data(kcs_bmc, KCS_ZERO_DATA);
break;
}
 
if (kcs_bmc->data_out_idx == kcs_bmc->data_out_len) {
-   write_data(kcs_bmc, KCS_ZERO_DATA);
+   kcs_bmc_write_data(kcs_bmc, KCS_ZERO_DATA);
kcs_bmc->phase = KCS_PHASE_IDLE;
break;
}
 
-   write_data(kcs_bmc,
+   kcs_bmc_write_data(kcs_bmc,
kcs_bmc->data_out[kcs_bmc->data_out_idx++]);
break;
 
case KCS_PHASE_ABORT_ERROR1:
set_state(kcs_bmc, READ_STATE);
-   read_data(kcs_bmc);
-   write_data(kcs_bmc, kcs_bmc->error);
+   kcs_bmc_read_data(kcs_bmc);
+   kcs_bmc_write_data(kcs_bmc, kcs_bmc->error);
kcs_bmc->phase = KCS_PHASE_ABORT_ERROR2;
break;
 
case KCS_PHASE_ABORT_ERROR2:
set_state(kcs_bmc, IDLE_STATE);
-   r

[PATCH v2 07/21] ipmi: kcs_bmc: Make status update atomic

2021-03-18 Thread Andrew Jeffery
Enable more efficient implementation of read-modify-write sequences.
Both device drivers for the KCS BMC stack use regmaps. The new callback
allows us to exploit regmap_update_bits().

Signed-off-by: Andrew Jeffery 
---
 drivers/char/ipmi/kcs_bmc.c |  7 +--
 drivers/char/ipmi/kcs_bmc.h |  1 +
 drivers/char/ipmi/kcs_bmc_aspeed.c  |  9 +
 drivers/char/ipmi/kcs_bmc_npcm7xx.c | 10 ++
 4 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/drivers/char/ipmi/kcs_bmc.c b/drivers/char/ipmi/kcs_bmc.c
index f292e74bd4a5..58fb1a7bd50d 100644
--- a/drivers/char/ipmi/kcs_bmc.c
+++ b/drivers/char/ipmi/kcs_bmc.c
@@ -67,12 +67,7 @@ static inline void write_status(struct kcs_bmc *kcs_bmc, u8 
data)
 
 static void update_status_bits(struct kcs_bmc *kcs_bmc, u8 mask, u8 val)
 {
-   u8 tmp = read_status(kcs_bmc);
-
-   tmp &= ~mask;
-   tmp |= val & mask;
-
-   write_status(kcs_bmc, tmp);
+   kcs_bmc->io_updateb(kcs_bmc, kcs_bmc->ioreg.str, mask, val);
 }
 
 static inline void set_state(struct kcs_bmc *kcs_bmc, u8 state)
diff --git a/drivers/char/ipmi/kcs_bmc.h b/drivers/char/ipmi/kcs_bmc.h
index eb9ea4ce78b8..970f53892f2d 100644
--- a/drivers/char/ipmi/kcs_bmc.h
+++ b/drivers/char/ipmi/kcs_bmc.h
@@ -76,6 +76,7 @@ struct kcs_bmc {
struct kcs_ioreg ioreg;
u8 (*io_inputb)(struct kcs_bmc *kcs_bmc, u32 reg);
void (*io_outputb)(struct kcs_bmc *kcs_bmc, u32 reg, u8 b);
+   void (*io_updateb)(struct kcs_bmc *kcs_bmc, u32 reg, u8 mask, u8 val);
 
enum kcs_phases phase;
enum kcs_errors error;
diff --git a/drivers/char/ipmi/kcs_bmc_aspeed.c 
b/drivers/char/ipmi/kcs_bmc_aspeed.c
index 061f53676206..630cf095560e 100644
--- a/drivers/char/ipmi/kcs_bmc_aspeed.c
+++ b/drivers/char/ipmi/kcs_bmc_aspeed.c
@@ -90,6 +90,14 @@ static void aspeed_kcs_outb(struct kcs_bmc *kcs_bmc, u32 
reg, u8 data)
WARN(rc != 0, "regmap_write() failed: %d\n", rc);
 }
 
+static void aspeed_kcs_updateb(struct kcs_bmc *kcs_bmc, u32 reg, u8 mask, u8 
val)
+{
+   struct aspeed_kcs_bmc *priv = kcs_bmc_priv(kcs_bmc);
+   int rc;
+
+   rc = regmap_update_bits(priv->map, reg, mask, val);
+   WARN(rc != 0, "regmap_update_bits() failed: %d\n", rc);
+}
 
 /*
  * AST_usrGuide_KCS.pdf
@@ -342,6 +350,7 @@ static int aspeed_kcs_probe(struct platform_device *pdev)
kcs_bmc->ioreg = ast_kcs_bmc_ioregs[channel - 1];
kcs_bmc->io_inputb = aspeed_kcs_inb;
kcs_bmc->io_outputb = aspeed_kcs_outb;
+   kcs_bmc->io_updateb = aspeed_kcs_updateb;
 
addr = ops->get_io_address(pdev);
if (addr < 0)
diff --git a/drivers/char/ipmi/kcs_bmc_npcm7xx.c 
b/drivers/char/ipmi/kcs_bmc_npcm7xx.c
index 722f7391fe1f..1f44aadec9e8 100644
--- a/drivers/char/ipmi/kcs_bmc_npcm7xx.c
+++ b/drivers/char/ipmi/kcs_bmc_npcm7xx.c
@@ -97,6 +97,15 @@ static void npcm7xx_kcs_outb(struct kcs_bmc *kcs_bmc, u32 
reg, u8 data)
WARN(rc != 0, "regmap_write() failed: %d\n", rc);
 }
 
+static void npcm7xx_kcs_updateb(struct kcs_bmc *kcs_bmc, u32 reg, u8 mask, u8 
data)
+{
+   struct npcm7xx_kcs_bmc *priv = kcs_bmc_priv(kcs_bmc);
+   int rc;
+
+   rc = regmap_update_bits(priv->map, reg, mask, data);
+   WARN(rc != 0, "regmap_update_bits() failed: %d\n", rc);
+}
+
 static void npcm7xx_kcs_enable_channel(struct kcs_bmc *kcs_bmc, bool enable)
 {
struct npcm7xx_kcs_bmc *priv = kcs_bmc_priv(kcs_bmc);
@@ -163,6 +172,7 @@ static int npcm7xx_kcs_probe(struct platform_device *pdev)
kcs_bmc->ioreg.str = priv->reg->sts;
kcs_bmc->io_inputb = npcm7xx_kcs_inb;
kcs_bmc->io_outputb = npcm7xx_kcs_outb;
+   kcs_bmc->io_updateb = npcm7xx_kcs_updateb;
 
dev_set_drvdata(dev, kcs_bmc);
 
-- 
2.27.0



[PATCH v2 05/21] soc: aspeed: Adapt to new LPC device tree layout

2021-03-18 Thread Andrew Jeffery
From: "Chia-Wei, Wang" 

Add check against LPC device v2 compatible string to
ensure that the fixed device tree layout is adopted.
The LPC register offsets are also fixed accordingly.

Signed-off-by: Chia-Wei Wang 
Reviewed-by: Andrew Jeffery 
---
 drivers/soc/aspeed/aspeed-lpc-ctrl.c  | 20 ++--
 drivers/soc/aspeed/aspeed-lpc-snoop.c | 23 +++
 2 files changed, 29 insertions(+), 14 deletions(-)

diff --git a/drivers/soc/aspeed/aspeed-lpc-ctrl.c 
b/drivers/soc/aspeed/aspeed-lpc-ctrl.c
index 439bcd6b8c4a..c557ffd0992c 100644
--- a/drivers/soc/aspeed/aspeed-lpc-ctrl.c
+++ b/drivers/soc/aspeed/aspeed-lpc-ctrl.c
@@ -18,15 +18,15 @@
 
 #define DEVICE_NAME"aspeed-lpc-ctrl"
 
-#define HICR5 0x0
+#define HICR5 0x80
 #define HICR5_ENL2HBIT(8)
 #define HICR5_ENFWHBIT(10)
 
-#define HICR6 0x4
+#define HICR6 0x84
 #define SW_FWH2AHB BIT(17)
 
-#define HICR7 0x8
-#define HICR8 0xc
+#define HICR7 0x88
+#define HICR8 0x8c
 
 struct aspeed_lpc_ctrl {
struct miscdevice   miscdev;
@@ -215,6 +215,7 @@ static int aspeed_lpc_ctrl_probe(struct platform_device 
*pdev)
struct device_node *node;
struct resource resm;
struct device *dev;
+   struct device_node *np;
int rc;
 
dev = &pdev->dev;
@@ -270,8 +271,15 @@ static int aspeed_lpc_ctrl_probe(struct platform_device 
*pdev)
}
}
 
-   lpc_ctrl->regmap = syscon_node_to_regmap(
-   pdev->dev.parent->of_node);
+   np = pdev->dev.parent->of_node;
+   if (!of_device_is_compatible(np, "aspeed,ast2400-lpc-v2") &&
+   !of_device_is_compatible(np, "aspeed,ast2500-lpc-v2") &&
+   !of_device_is_compatible(np, "aspeed,ast2600-lpc-v2")) {
+   dev_err(dev, "unsupported LPC device binding\n");
+   return -ENODEV;
+   }
+
+   lpc_ctrl->regmap = syscon_node_to_regmap(np);
if (IS_ERR(lpc_ctrl->regmap)) {
dev_err(dev, "Couldn't get regmap\n");
return -ENODEV;
diff --git a/drivers/soc/aspeed/aspeed-lpc-snoop.c 
b/drivers/soc/aspeed/aspeed-lpc-snoop.c
index 20acac6342ef..210455efb321 100644
--- a/drivers/soc/aspeed/aspeed-lpc-snoop.c
+++ b/drivers/soc/aspeed/aspeed-lpc-snoop.c
@@ -29,26 +29,25 @@
 #define NUM_SNOOP_CHANNELS 2
 #define SNOOP_FIFO_SIZE 2048
 
-#define HICR5  0x0
+#define HICR5  0x80
 #define HICR5_EN_SNP0W BIT(0)
 #define HICR5_ENINT_SNP0W  BIT(1)
 #define HICR5_EN_SNP1W BIT(2)
 #define HICR5_ENINT_SNP1W  BIT(3)
-
-#define HICR6  0x4
+#define HICR6  0x84
 #define HICR6_STR_SNP0WBIT(0)
 #define HICR6_STR_SNP1WBIT(1)
-#define SNPWADR0x10
+#define SNPWADR0x90
 #define SNPWADR_CH0_MASK   GENMASK(15, 0)
 #define SNPWADR_CH0_SHIFT  0
 #define SNPWADR_CH1_MASK   GENMASK(31, 16)
 #define SNPWADR_CH1_SHIFT  16
-#define SNPWDR 0x14
+#define SNPWDR 0x94
 #define SNPWDR_CH0_MASKGENMASK(7, 0)
 #define SNPWDR_CH0_SHIFT   0
 #define SNPWDR_CH1_MASKGENMASK(15, 8)
 #define SNPWDR_CH1_SHIFT   8
-#define HICRB  0x80
+#define HICRB  0x100
 #define HICRB_ENSNP0D  BIT(14)
 #define HICRB_ENSNP1D  BIT(15)
 
@@ -260,6 +259,7 @@ static int aspeed_lpc_snoop_probe(struct platform_device 
*pdev)
 {
struct aspeed_lpc_snoop *lpc_snoop;
struct device *dev;
+   struct device_node *np;
u32 port;
int rc;
 
@@ -269,8 +269,15 @@ static int aspeed_lpc_snoop_probe(struct platform_device 
*pdev)
if (!lpc_snoop)
return -ENOMEM;
 
-   lpc_snoop->regmap = syscon_node_to_regmap(
-   pdev->dev.parent->of_node);
+   np = pdev->dev.parent->of_node;
+   if (!of_device_is_compatible(np, "aspeed,ast2400-lpc-v2") &&
+   !of_device_is_compatible(np, "aspeed,ast2500-lpc-v2") &&
+   !of_device_is_compatible(np, "aspeed,ast2600-lpc-v2")) {
+   dev_err(dev, "unsupported LPC device binding\n");
+   return -ENODEV;
+   }
+
+   lpc_snoop->regmap = syscon_node_to_regmap(np);
if (IS_ERR(lpc_snoop->regmap)) {
dev_err(dev, "Couldn't get regmap\n");
return -ENODEV;
-- 
2.27.0



[PATCH v2 09/21] ipmi: kcs_bmc: Split out kcs_bmc_cdev_ipmi

2021-03-18 Thread Andrew Jeffery
Take steps towards defining a coherent API to separate the KCS device
drivers from the userspace interface. Decreasing the coupling will
improve the separation of concerns and enable the introduction of
alternative userspace interfaces.

For now, simply split the chardev logic out to a separate file. The code
continues to build into the same module.

Signed-off-by: Andrew Jeffery 
---
 drivers/char/ipmi/Makefile|   2 +-
 drivers/char/ipmi/kcs_bmc.c   | 423 +
 drivers/char/ipmi/kcs_bmc.h   |  10 +-
 drivers/char/ipmi/kcs_bmc_cdev_ipmi.c | 428 ++
 4 files changed, 451 insertions(+), 412 deletions(-)
 create mode 100644 drivers/char/ipmi/kcs_bmc_cdev_ipmi.c

diff --git a/drivers/char/ipmi/Makefile b/drivers/char/ipmi/Makefile
index 0822adc2ec41..a302bc865370 100644
--- a/drivers/char/ipmi/Makefile
+++ b/drivers/char/ipmi/Makefile
@@ -22,7 +22,7 @@ obj-$(CONFIG_IPMI_SSIF) += ipmi_ssif.o
 obj-$(CONFIG_IPMI_POWERNV) += ipmi_powernv.o
 obj-$(CONFIG_IPMI_WATCHDOG) += ipmi_watchdog.o
 obj-$(CONFIG_IPMI_POWEROFF) += ipmi_poweroff.o
-obj-$(CONFIG_IPMI_KCS_BMC) += kcs_bmc.o
+obj-$(CONFIG_IPMI_KCS_BMC) += kcs_bmc.o kcs_bmc_cdev_ipmi.o
 obj-$(CONFIG_ASPEED_BT_IPMI_BMC) += bt-bmc.o
 obj-$(CONFIG_ASPEED_KCS_IPMI_BMC) += kcs_bmc_aspeed.o
 obj-$(CONFIG_NPCM7XX_KCS_IPMI_BMC) += kcs_bmc_npcm7xx.o
diff --git a/drivers/char/ipmi/kcs_bmc.c b/drivers/char/ipmi/kcs_bmc.c
index c4336c1f2d6d..ef5c48ffe74a 100644
--- a/drivers/char/ipmi/kcs_bmc.c
+++ b/drivers/char/ipmi/kcs_bmc.c
@@ -3,446 +3,51 @@
  * Copyright (c) 2015-2018, Intel Corporation.
  */
 
-#define pr_fmt(fmt) "kcs-bmc: " fmt
-
-#include 
-#include 
-#include 
 #include 
-#include 
-#include 
-#include 
-#include 
 
 #include "kcs_bmc.h"
 
-#define DEVICE_NAME "ipmi-kcs"
-
-#define KCS_MSG_BUFSIZ1000
-
-#define KCS_ZERO_DATA 0
-
-
-/* IPMI 2.0 - Table 9-1, KCS Interface Status Register Bits */
-#define KCS_STATUS_STATE(state) (state << 6)
-#define KCS_STATUS_STATE_MASK   GENMASK(7, 6)
-#define KCS_STATUS_CMD_DAT  BIT(3)
-#define KCS_STATUS_SMS_ATN  BIT(2)
-#define KCS_STATUS_IBF  BIT(1)
-#define KCS_STATUS_OBF  BIT(0)
-
-/* IPMI 2.0 - Table 9-2, KCS Interface State Bits */
-enum kcs_states {
-   IDLE_STATE  = 0,
-   READ_STATE  = 1,
-   WRITE_STATE = 2,
-   ERROR_STATE = 3,
-};
-
-/* IPMI 2.0 - Table 9-3, KCS Interface Control Codes */
-#define KCS_CMD_GET_STATUS_ABORT  0x60
-#define KCS_CMD_WRITE_START   0x61
-#define KCS_CMD_WRITE_END 0x62
-#define KCS_CMD_READ_BYTE 0x68
-
-static inline u8 kcs_bmc_read_data(struct kcs_bmc *kcs_bmc)
+u8 kcs_bmc_read_data(struct kcs_bmc *kcs_bmc)
 {
return kcs_bmc->io_inputb(kcs_bmc, kcs_bmc->ioreg.idr);
 }
+EXPORT_SYMBOL(kcs_bmc_read_data);
 
-static inline void kcs_bmc_write_data(struct kcs_bmc *kcs_bmc, u8 data)
+void kcs_bmc_write_data(struct kcs_bmc *kcs_bmc, u8 data)
 {
kcs_bmc->io_outputb(kcs_bmc, kcs_bmc->ioreg.odr, data);
 }
+EXPORT_SYMBOL(kcs_bmc_write_data);
 
-static inline u8 kcs_bmc_read_status(struct kcs_bmc *kcs_bmc)
+u8 kcs_bmc_read_status(struct kcs_bmc *kcs_bmc)
 {
return kcs_bmc->io_inputb(kcs_bmc, kcs_bmc->ioreg.str);
 }
+EXPORT_SYMBOL(kcs_bmc_read_status);
 
-static inline void kcs_bmc_write_status(struct kcs_bmc *kcs_bmc, u8 data)
+void kcs_bmc_write_status(struct kcs_bmc *kcs_bmc, u8 data)
 {
kcs_bmc->io_outputb(kcs_bmc, kcs_bmc->ioreg.str, data);
 }
+EXPORT_SYMBOL(kcs_bmc_write_status);
 
-static void kcs_bmc_update_status(struct kcs_bmc *kcs_bmc, u8 mask, u8 val)
+void kcs_bmc_update_status(struct kcs_bmc *kcs_bmc, u8 mask, u8 val)
 {
kcs_bmc->io_updateb(kcs_bmc, kcs_bmc->ioreg.str, mask, val);
 }
+EXPORT_SYMBOL(kcs_bmc_update_status);
 
-static inline void set_state(struct kcs_bmc *kcs_bmc, u8 state)
-{
-   kcs_bmc_update_status(kcs_bmc, KCS_STATUS_STATE_MASK,
-   KCS_STATUS_STATE(state));
-}
-
-static void kcs_force_abort(struct kcs_bmc *kcs_bmc)
-{
-   set_state(kcs_bmc, ERROR_STATE);
-   kcs_bmc_read_data(kcs_bmc);
-   kcs_bmc_write_data(kcs_bmc, KCS_ZERO_DATA);
-
-   kcs_bmc->phase = KCS_PHASE_ERROR;
-   kcs_bmc->data_in_avail = false;
-   kcs_bmc->data_in_idx = 0;
-}
-
-static void kcs_bmc_handle_data(struct kcs_bmc *kcs_bmc)
-{
-   u8 data;
-
-   switch (kcs_bmc->phase) {
-   case KCS_PHASE_WRITE_START:
-   kcs_bmc->phase = KCS_PHASE_WRITE_DATA;
-   fallthrough;
-
-   case KCS_PHASE_WRITE_DATA:
-   if (kcs_bmc->data_in_idx < KCS_MSG_BUFSIZ) {
-   set_state(kcs_bmc, WRITE_STATE);
-   kcs_bmc_write_data(kcs_bmc, KCS_ZERO_DATA);
-   kcs_bmc->data_in[kcs_bmc->data_in_idx++] =
-   kcs_bmc_read_data(kcs_bmc);
-   } else {
-   kcs_force_abort(kcs_bmc);
-   kcs_bmc

[PATCH v2 11/21] ipmi: kcs_bmc: Split headers into device and client

2021-03-18 Thread Andrew Jeffery
Strengthen the distinction between code that abstracts the
implementation of the KCS behaviours (device drivers) and code that
exploits KCS behaviours (clients). Neither needs to know about the APIs
required by the other, so provide separate headers.

Signed-off-by: Andrew Jeffery 
---
 drivers/char/ipmi/kcs_bmc.c   | 21 ++-
 drivers/char/ipmi/kcs_bmc.h   | 30 ++---
 drivers/char/ipmi/kcs_bmc_aspeed.c| 20 +-
 drivers/char/ipmi/kcs_bmc_cdev_ipmi.c | 39 ++-
 drivers/char/ipmi/kcs_bmc_client.h| 29 
 drivers/char/ipmi/kcs_bmc_device.h| 19 +
 drivers/char/ipmi/kcs_bmc_npcm7xx.c   | 20 +-
 7 files changed, 129 insertions(+), 49 deletions(-)
 create mode 100644 drivers/char/ipmi/kcs_bmc_client.h
 create mode 100644 drivers/char/ipmi/kcs_bmc_device.h

diff --git a/drivers/char/ipmi/kcs_bmc.c b/drivers/char/ipmi/kcs_bmc.c
index 709b6bdec165..1046ce2bbefc 100644
--- a/drivers/char/ipmi/kcs_bmc.c
+++ b/drivers/char/ipmi/kcs_bmc.c
@@ -1,46 +1,52 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
  * Copyright (c) 2015-2018, Intel Corporation.
+ * Copyright (c) 2021, IBM Corp.
  */
 
 #include 
 
 #include "kcs_bmc.h"
 
+/* Implement both the device and client interfaces here */
+#include "kcs_bmc_device.h"
+#include "kcs_bmc_client.h"
+
+/* Consumer data access */
+
 u8 kcs_bmc_read_data(struct kcs_bmc *kcs_bmc)
 {
-   return kcs_bmc->io_inputb(kcs_bmc, kcs_bmc->ioreg.idr);
+   return kcs_bmc->ops->io_inputb(kcs_bmc, kcs_bmc->ioreg.idr);
 }
 EXPORT_SYMBOL(kcs_bmc_read_data);
 
 void kcs_bmc_write_data(struct kcs_bmc *kcs_bmc, u8 data)
 {
-   kcs_bmc->io_outputb(kcs_bmc, kcs_bmc->ioreg.odr, data);
+   kcs_bmc->ops->io_outputb(kcs_bmc, kcs_bmc->ioreg.odr, data);
 }
 EXPORT_SYMBOL(kcs_bmc_write_data);
 
 u8 kcs_bmc_read_status(struct kcs_bmc *kcs_bmc)
 {
-   return kcs_bmc->io_inputb(kcs_bmc, kcs_bmc->ioreg.str);
+   return kcs_bmc->ops->io_inputb(kcs_bmc, kcs_bmc->ioreg.str);
 }
 EXPORT_SYMBOL(kcs_bmc_read_status);
 
 void kcs_bmc_write_status(struct kcs_bmc *kcs_bmc, u8 data)
 {
-   kcs_bmc->io_outputb(kcs_bmc, kcs_bmc->ioreg.str, data);
+   kcs_bmc->ops->io_outputb(kcs_bmc, kcs_bmc->ioreg.str, data);
 }
 EXPORT_SYMBOL(kcs_bmc_write_status);
 
 void kcs_bmc_update_status(struct kcs_bmc *kcs_bmc, u8 mask, u8 val)
 {
-   kcs_bmc->io_updateb(kcs_bmc, kcs_bmc->ioreg.str, mask, val);
+   kcs_bmc->ops->io_updateb(kcs_bmc, kcs_bmc->ioreg.str, mask, val);
 }
 EXPORT_SYMBOL(kcs_bmc_update_status);
 
-int kcs_bmc_ipmi_event(struct kcs_bmc *kcs_bmc);
 int kcs_bmc_handle_event(struct kcs_bmc *kcs_bmc)
 {
-   return kcs_bmc_ipmi_event(kcs_bmc);
+   return kcs_bmc->client.ops->event(&kcs_bmc->client);
 }
 EXPORT_SYMBOL(kcs_bmc_handle_event);
 
@@ -60,4 +66,5 @@ EXPORT_SYMBOL(kcs_bmc_remove_device);
 
 MODULE_LICENSE("GPL v2");
 MODULE_AUTHOR("Haiyue Wang ");
+MODULE_AUTHOR("Andrew Jeffery ");
 MODULE_DESCRIPTION("KCS BMC to handle the IPMI request from system software");
diff --git a/drivers/char/ipmi/kcs_bmc.h b/drivers/char/ipmi/kcs_bmc.h
index bf0ae327997f..a1350e567723 100644
--- a/drivers/char/ipmi/kcs_bmc.h
+++ b/drivers/char/ipmi/kcs_bmc.h
@@ -8,6 +8,15 @@
 
 #include 
 
+#include "kcs_bmc_client.h"
+
+#define KCS_BMC_EVENT_NONE 0
+#define KCS_BMC_EVENT_HANDLED  1
+
+#define KCS_BMC_STR_OBFBIT(0)
+#define KCS_BMC_STR_IBFBIT(1)
+#define KCS_BMC_STR_CMD_DATBIT(3)
+
 /* Different phases of the KCS BMC module.
  *  KCS_PHASE_IDLE:
  *BMC should not be expecting nor sending any data.
@@ -66,19 +75,21 @@ struct kcs_ioreg {
u32 str;
 };
 
+struct kcs_bmc_device_ops;
+
 struct kcs_bmc {
struct device *dev;
 
+   const struct kcs_bmc_device_ops *ops;
+
+   struct kcs_bmc_client client;
+
spinlock_t lock;
 
u32 channel;
int running;
 
-   /* Setup by BMC KCS controller driver */
struct kcs_ioreg ioreg;
-   u8 (*io_inputb)(struct kcs_bmc *kcs_bmc, u32 reg);
-   void (*io_outputb)(struct kcs_bmc *kcs_bmc, u32 reg, u8 b);
-   void (*io_updateb)(struct kcs_bmc *kcs_bmc, u32 reg, u8 mask, u8 val);
 
enum kcs_phases phase;
enum kcs_errors error;
@@ -97,15 +108,4 @@ struct kcs_bmc {
 
struct miscdevice miscdev;
 };
-
-int kcs_bmc_handle_event(struct kcs_bmc *kcs_bmc);
-int kcs_bmc_add_device(struct kcs_bmc *kcs_bmc);
-int kcs_bmc_remove_device(struct kcs_bmc *kcs_bmc);
-
-u8 kcs_bmc_read_data(struct kcs_bmc *kcs_bmc);
-void kcs_bmc_write_data(struct kcs_bmc *kcs_bmc, u8 data);
-u8 kcs_bmc_read_status(struct kcs_bmc *kcs_bmc);
-void kcs_bmc_write_status(struct kcs_bmc *kcs_bmc, u8 data);
-void kcs_bmc_update_status(struct kcs_bmc *kcs_bmc, u8 mask, u8 val);
-
 #endif /* __KCS_BMC_H__ */
diff --git a/drivers/char/ipmi/kcs_bmc_aspeed.c 
b/drivers/char/ipmi/kcs_bmc_aspeed.c
index 0416ac78ce68..1b313355b1c8 100644
--- a/drivers/

[PATCH v2 12/21] ipmi: kcs_bmc: Strip private client data from struct kcs_bmc

2021-03-18 Thread Andrew Jeffery
Move all client-private data out of `struct kcs_bmc` into the KCS client
implementation.

With this change the KCS BMC core code now only concerns itself with
abstract `struct kcs_bmc` and `struct kcs_bmc_client` types, achieving
expected separation of concerns. Further, the change clears the path for
implementation of alternative userspace interfaces.

The chardev data-structures are rearranged in the same manner applied to
the KCS device driver data-structures in an earlier patch - `struct
kcs_bmc_client` is embedded in the client's private data and we exploit
container_of() to translate as required.

Finally, now that it is free of client data, `struct kcs_bmc` is renamed
to `struct kcs_bmc_device` to contrast `struct kcs_bmc_client`.

Signed-off-by: Andrew Jeffery 
---
 drivers/char/ipmi/kcs_bmc.c   |  68 +++-
 drivers/char/ipmi/kcs_bmc.h   |  86 +-
 drivers/char/ipmi/kcs_bmc_aspeed.c|  22 +-
 drivers/char/ipmi/kcs_bmc_cdev_ipmi.c | 428 --
 drivers/char/ipmi/kcs_bmc_client.h|  28 +-
 drivers/char/ipmi/kcs_bmc_device.h|  12 +-
 drivers/char/ipmi/kcs_bmc_npcm7xx.c   |  20 +-
 7 files changed, 368 insertions(+), 296 deletions(-)

diff --git a/drivers/char/ipmi/kcs_bmc.c b/drivers/char/ipmi/kcs_bmc.c
index 1046ce2bbefc..266ebec71d6f 100644
--- a/drivers/char/ipmi/kcs_bmc.c
+++ b/drivers/char/ipmi/kcs_bmc.c
@@ -4,6 +4,7 @@
  * Copyright (c) 2021, IBM Corp.
  */
 
+#include 
 #include 
 
 #include "kcs_bmc.h"
@@ -14,51 +15,96 @@
 
 /* Consumer data access */
 
-u8 kcs_bmc_read_data(struct kcs_bmc *kcs_bmc)
+u8 kcs_bmc_read_data(struct kcs_bmc_device *kcs_bmc)
 {
return kcs_bmc->ops->io_inputb(kcs_bmc, kcs_bmc->ioreg.idr);
 }
 EXPORT_SYMBOL(kcs_bmc_read_data);
 
-void kcs_bmc_write_data(struct kcs_bmc *kcs_bmc, u8 data)
+void kcs_bmc_write_data(struct kcs_bmc_device *kcs_bmc, u8 data)
 {
kcs_bmc->ops->io_outputb(kcs_bmc, kcs_bmc->ioreg.odr, data);
 }
 EXPORT_SYMBOL(kcs_bmc_write_data);
 
-u8 kcs_bmc_read_status(struct kcs_bmc *kcs_bmc)
+u8 kcs_bmc_read_status(struct kcs_bmc_device *kcs_bmc)
 {
return kcs_bmc->ops->io_inputb(kcs_bmc, kcs_bmc->ioreg.str);
 }
 EXPORT_SYMBOL(kcs_bmc_read_status);
 
-void kcs_bmc_write_status(struct kcs_bmc *kcs_bmc, u8 data)
+void kcs_bmc_write_status(struct kcs_bmc_device *kcs_bmc, u8 data)
 {
kcs_bmc->ops->io_outputb(kcs_bmc, kcs_bmc->ioreg.str, data);
 }
 EXPORT_SYMBOL(kcs_bmc_write_status);
 
-void kcs_bmc_update_status(struct kcs_bmc *kcs_bmc, u8 mask, u8 val)
+void kcs_bmc_update_status(struct kcs_bmc_device *kcs_bmc, u8 mask, u8 val)
 {
kcs_bmc->ops->io_updateb(kcs_bmc, kcs_bmc->ioreg.str, mask, val);
 }
 EXPORT_SYMBOL(kcs_bmc_update_status);
 
-int kcs_bmc_handle_event(struct kcs_bmc *kcs_bmc)
+int kcs_bmc_handle_event(struct kcs_bmc_device *kcs_bmc)
 {
-   return kcs_bmc->client.ops->event(&kcs_bmc->client);
+   struct kcs_bmc_client *client;
+   int rc;
+
+   spin_lock(&kcs_bmc->lock);
+   client = kcs_bmc->client;
+   if (client) {
+   rc = client->ops->event(client);
+   } else {
+   u8 status;
+
+   status = kcs_bmc_read_status(kcs_bmc);
+   if (status & KCS_BMC_STR_IBF) {
+   /* Ack the event by reading the data */
+   kcs_bmc_read_data(kcs_bmc);
+   rc = KCS_BMC_EVENT_HANDLED;
+   } else {
+   rc = KCS_BMC_EVENT_NONE;
+   }
+   }
+   spin_unlock(&kcs_bmc->lock);
+
+   return rc;
 }
 EXPORT_SYMBOL(kcs_bmc_handle_event);
 
-int kcs_bmc_ipmi_attach_cdev(struct kcs_bmc *kcs_bmc);
-int kcs_bmc_add_device(struct kcs_bmc *kcs_bmc)
+int kcs_bmc_enable_device(struct kcs_bmc_device *kcs_bmc, struct 
kcs_bmc_client *client)
+{
+   int rc;
+
+   spin_lock_irq(&kcs_bmc->lock);
+   if (kcs_bmc->client) {
+   rc = -EBUSY;
+   } else {
+   kcs_bmc->client = client;
+   rc = 0;
+   }
+   spin_unlock_irq(&kcs_bmc->lock);
+
+   return rc;
+}
+EXPORT_SYMBOL(kcs_bmc_enable_device);
+
+void kcs_bmc_disable_device(struct kcs_bmc_device *kcs_bmc, struct 
kcs_bmc_client *client)
+{
+   spin_lock_irq(&kcs_bmc->lock);
+   if (client == kcs_bmc->client)
+   kcs_bmc->client = NULL;
+   spin_unlock_irq(&kcs_bmc->lock);
+}
+EXPORT_SYMBOL(kcs_bmc_disable_device);
+
+int kcs_bmc_add_device(struct kcs_bmc_device *kcs_bmc)
 {
return kcs_bmc_ipmi_attach_cdev(kcs_bmc);
 }
 EXPORT_SYMBOL(kcs_bmc_add_device);
 
-int kcs_bmc_ipmi_detach_cdev(struct kcs_bmc *kcs_bmc);
-int kcs_bmc_remove_device(struct kcs_bmc *kcs_bmc)
+int kcs_bmc_remove_device(struct kcs_bmc_device *kcs_bmc)
 {
return kcs_bmc_ipmi_detach_cdev(kcs_bmc);
 }
diff --git a/drivers/char/ipmi/kcs_bmc.h b/drivers/char/ipmi/kcs_bmc.h
index a1350e567723..3f266740c759 100644
--- a/drivers/char/ipmi/kcs_bmc.h
+++ b/drivers/char/ipmi/kcs_bmc.h
@@ -6,9 +6,7 @@
 #ifn

[PATCH v2 13/21] ipmi: kcs_bmc: Decouple the IPMI chardev from the core

2021-03-18 Thread Andrew Jeffery
Now that we have untangled the data-structures, split the userspace
interface out into its own module. Userspace interfaces and drivers are
registered to the KCS BMC core to support arbitrary binding of either.

Signed-off-by: Andrew Jeffery 
---
 drivers/char/ipmi/Kconfig | 13 +
 drivers/char/ipmi/Makefile|  3 +-
 drivers/char/ipmi/kcs_bmc.c   | 78 ++-
 drivers/char/ipmi/kcs_bmc.h   |  4 --
 drivers/char/ipmi/kcs_bmc_cdev_ipmi.c | 33 +---
 drivers/char/ipmi/kcs_bmc_client.h| 14 +
 6 files changed, 132 insertions(+), 13 deletions(-)

diff --git a/drivers/char/ipmi/Kconfig b/drivers/char/ipmi/Kconfig
index 07847d9a459a..bc5f81899b62 100644
--- a/drivers/char/ipmi/Kconfig
+++ b/drivers/char/ipmi/Kconfig
@@ -124,6 +124,19 @@ config NPCM7XX_KCS_IPMI_BMC
  This support is also available as a module.  If so, the module
  will be called kcs_bmc_npcm7xx.
 
+config IPMI_KCS_BMC_CDEV_IPMI
+   depends on IPMI_KCS_BMC
+   tristate "IPMI character device interface for BMC KCS devices"
+   help
+ Provides a BMC-side character device implementing IPMI
+ semantics for KCS IPMI devices.
+
+ Say YES if you wish to expose KCS devices on the BMC for IPMI
+ purposes.
+
+ This support is also available as a module. The module will be
+ called kcs_bmc_cdev_ipmi.
+
 config ASPEED_BT_IPMI_BMC
depends on ARCH_ASPEED || COMPILE_TEST
depends on REGMAP && REGMAP_MMIO && MFD_SYSCON
diff --git a/drivers/char/ipmi/Makefile b/drivers/char/ipmi/Makefile
index a302bc865370..fcfa676afddb 100644
--- a/drivers/char/ipmi/Makefile
+++ b/drivers/char/ipmi/Makefile
@@ -22,7 +22,8 @@ obj-$(CONFIG_IPMI_SSIF) += ipmi_ssif.o
 obj-$(CONFIG_IPMI_POWERNV) += ipmi_powernv.o
 obj-$(CONFIG_IPMI_WATCHDOG) += ipmi_watchdog.o
 obj-$(CONFIG_IPMI_POWEROFF) += ipmi_poweroff.o
-obj-$(CONFIG_IPMI_KCS_BMC) += kcs_bmc.o kcs_bmc_cdev_ipmi.o
+obj-$(CONFIG_IPMI_KCS_BMC) += kcs_bmc.o
+obj-$(CONFIG_IPMI_KCS_BMC_CDEV_IPMI) += kcs_bmc_cdev_ipmi.o
 obj-$(CONFIG_ASPEED_BT_IPMI_BMC) += bt-bmc.o
 obj-$(CONFIG_ASPEED_KCS_IPMI_BMC) += kcs_bmc_aspeed.o
 obj-$(CONFIG_NPCM7XX_KCS_IPMI_BMC) += kcs_bmc_npcm7xx.o
diff --git a/drivers/char/ipmi/kcs_bmc.c b/drivers/char/ipmi/kcs_bmc.c
index 266ebec71d6f..694db6ee2a92 100644
--- a/drivers/char/ipmi/kcs_bmc.c
+++ b/drivers/char/ipmi/kcs_bmc.c
@@ -5,7 +5,9 @@
  */
 
 #include 
+#include 
 #include 
+#include 
 
 #include "kcs_bmc.h"
 
@@ -13,6 +15,11 @@
 #include "kcs_bmc_device.h"
 #include "kcs_bmc_client.h"
 
+/* Record probed devices and cdevs */
+static DEFINE_MUTEX(kcs_bmc_lock);
+static LIST_HEAD(kcs_bmc_devices);
+static LIST_HEAD(kcs_bmc_cdevs);
+
 /* Consumer data access */
 
 u8 kcs_bmc_read_data(struct kcs_bmc_device *kcs_bmc)
@@ -100,16 +107,83 @@ EXPORT_SYMBOL(kcs_bmc_disable_device);
 
 int kcs_bmc_add_device(struct kcs_bmc_device *kcs_bmc)
 {
-   return kcs_bmc_ipmi_attach_cdev(kcs_bmc);
+   struct kcs_bmc_cdev *cdev;
+   int rc;
+
+   spin_lock_init(&kcs_bmc->lock);
+   kcs_bmc->client = NULL;
+
+   mutex_lock(&kcs_bmc_lock);
+   list_add(&kcs_bmc->entry, &kcs_bmc_devices);
+   list_for_each_entry(cdev, &kcs_bmc_cdevs, entry) {
+   rc = cdev->ops->add_device(kcs_bmc);
+   if (rc)
+   dev_err(kcs_bmc->dev, "Failed to add chardev for KCS 
channel %d: %d",
+   kcs_bmc->channel, rc);
+   }
+   mutex_unlock(&kcs_bmc_lock);
+
+   return 0;
 }
 EXPORT_SYMBOL(kcs_bmc_add_device);
 
 int kcs_bmc_remove_device(struct kcs_bmc_device *kcs_bmc)
 {
-   return kcs_bmc_ipmi_detach_cdev(kcs_bmc);
+   struct kcs_bmc_cdev *cdev;
+   int rc;
+
+   mutex_lock(&kcs_bmc_lock);
+   list_del(&kcs_bmc->entry);
+   list_for_each_entry(cdev, &kcs_bmc_cdevs, entry) {
+   rc = cdev->ops->remove_device(kcs_bmc);
+   if (rc)
+   dev_err(kcs_bmc->dev, "Failed to remove chardev for KCS 
channel %d: %d",
+   kcs_bmc->channel, rc);
+   }
+   mutex_unlock(&kcs_bmc_lock);
+
+   return 0;
 }
 EXPORT_SYMBOL(kcs_bmc_remove_device);
 
+int kcs_bmc_register_cdev(struct kcs_bmc_cdev *cdev)
+{
+   struct kcs_bmc_device *kcs_bmc;
+   int rc;
+
+   mutex_lock(&kcs_bmc_lock);
+   list_add(&cdev->entry, &kcs_bmc_cdevs);
+   list_for_each_entry(kcs_bmc, &kcs_bmc_devices, entry) {
+   rc = cdev->ops->add_device(kcs_bmc);
+   if (rc)
+   dev_err(kcs_bmc->dev, "Failed to add chardev for KCS 
channel %d: %d",
+   kcs_bmc->channel, rc);
+   }
+   mutex_unlock(&kcs_bmc_lock);
+
+   return 0;
+}
+EXPORT_SYMBOL(kcs_bmc_register_cdev);
+
+int kcs_bmc_unregister_cdev(struct kcs_bmc_cdev *cdev)
+{
+   struct kcs_bmc_device *kcs_bmc;
+   int rc;
+
+   mutex_lock(&kcs_bmc_lock);

[PATCH v2 10/21] ipmi: kcs_bmc: Turn the driver data-structures inside-out

2021-03-18 Thread Andrew Jeffery
Make the KCS device drivers responsible for allocating their own memory.

Until now the private data for the device driver was allocated internal
to the private data for the chardev interface. This coupling required
the slightly awkward API of passing through the struct size for the
driver private data to the chardev constructor, and then retrieving a
pointer to the driver private data from the allocated chardev memory.

In addition to being awkward, the arrangement prevents the
implementation of alternative userspace interfaces as the device driver
private data is not independent.

Peel a layer off the onion and turn the data-structures inside out by
exploiting container_of() and embedding `struct kcs_device` in the
driver private data.

Signed-off-by: Andrew Jeffery 
---
 drivers/char/ipmi/kcs_bmc.c   | 15 +--
 drivers/char/ipmi/kcs_bmc.h   | 12 ++
 drivers/char/ipmi/kcs_bmc_aspeed.c| 60 ---
 drivers/char/ipmi/kcs_bmc_cdev_ipmi.c | 60 ++-
 drivers/char/ipmi/kcs_bmc_npcm7xx.c   | 37 ++---
 5 files changed, 113 insertions(+), 71 deletions(-)

diff --git a/drivers/char/ipmi/kcs_bmc.c b/drivers/char/ipmi/kcs_bmc.c
index ef5c48ffe74a..709b6bdec165 100644
--- a/drivers/char/ipmi/kcs_bmc.c
+++ b/drivers/char/ipmi/kcs_bmc.c
@@ -44,12 +44,19 @@ int kcs_bmc_handle_event(struct kcs_bmc *kcs_bmc)
 }
 EXPORT_SYMBOL(kcs_bmc_handle_event);
 
-struct kcs_bmc *kcs_bmc_ipmi_alloc(struct device *dev, int sizeof_priv, u32 
channel);
-struct kcs_bmc *kcs_bmc_alloc(struct device *dev, int sizeof_priv, u32 channel)
+int kcs_bmc_ipmi_attach_cdev(struct kcs_bmc *kcs_bmc);
+int kcs_bmc_add_device(struct kcs_bmc *kcs_bmc)
 {
-   return kcs_bmc_ipmi_alloc(dev, sizeof_priv, channel);
+   return kcs_bmc_ipmi_attach_cdev(kcs_bmc);
 }
-EXPORT_SYMBOL(kcs_bmc_alloc);
+EXPORT_SYMBOL(kcs_bmc_add_device);
+
+int kcs_bmc_ipmi_detach_cdev(struct kcs_bmc *kcs_bmc);
+int kcs_bmc_remove_device(struct kcs_bmc *kcs_bmc)
+{
+   return kcs_bmc_ipmi_detach_cdev(kcs_bmc);
+}
+EXPORT_SYMBOL(kcs_bmc_remove_device);
 
 MODULE_LICENSE("GPL v2");
 MODULE_AUTHOR("Haiyue Wang ");
diff --git a/drivers/char/ipmi/kcs_bmc.h b/drivers/char/ipmi/kcs_bmc.h
index febea0c8deb4..bf0ae327997f 100644
--- a/drivers/char/ipmi/kcs_bmc.h
+++ b/drivers/char/ipmi/kcs_bmc.h
@@ -67,6 +67,8 @@ struct kcs_ioreg {
 };
 
 struct kcs_bmc {
+   struct device *dev;
+
spinlock_t lock;
 
u32 channel;
@@ -94,17 +96,11 @@ struct kcs_bmc {
u8 *kbuffer;
 
struct miscdevice miscdev;
-
-   unsigned long priv[];
 };
 
-static inline void *kcs_bmc_priv(struct kcs_bmc *kcs_bmc)
-{
-   return kcs_bmc->priv;
-}
-
 int kcs_bmc_handle_event(struct kcs_bmc *kcs_bmc);
-struct kcs_bmc *kcs_bmc_alloc(struct device *dev, int sizeof_priv, u32 
channel);
+int kcs_bmc_add_device(struct kcs_bmc *kcs_bmc);
+int kcs_bmc_remove_device(struct kcs_bmc *kcs_bmc);
 
 u8 kcs_bmc_read_data(struct kcs_bmc *kcs_bmc);
 void kcs_bmc_write_data(struct kcs_bmc *kcs_bmc, u8 data);
diff --git a/drivers/char/ipmi/kcs_bmc_aspeed.c 
b/drivers/char/ipmi/kcs_bmc_aspeed.c
index 630cf095560e..0416ac78ce68 100644
--- a/drivers/char/ipmi/kcs_bmc_aspeed.c
+++ b/drivers/char/ipmi/kcs_bmc_aspeed.c
@@ -61,6 +61,8 @@
 #define LPC_STR4 0x11C
 
 struct aspeed_kcs_bmc {
+   struct kcs_bmc kcs_bmc;
+
struct regmap *map;
 };
 
@@ -69,9 +71,14 @@ struct aspeed_kcs_of_ops {
int (*get_io_address)(struct platform_device *pdev);
 };
 
+static inline struct aspeed_kcs_bmc *to_aspeed_kcs_bmc(struct kcs_bmc *kcs_bmc)
+{
+   return container_of(kcs_bmc, struct aspeed_kcs_bmc, kcs_bmc);
+}
+
 static u8 aspeed_kcs_inb(struct kcs_bmc *kcs_bmc, u32 reg)
 {
-   struct aspeed_kcs_bmc *priv = kcs_bmc_priv(kcs_bmc);
+   struct aspeed_kcs_bmc *priv = to_aspeed_kcs_bmc(kcs_bmc);
u32 val = 0;
int rc;
 
@@ -83,7 +90,7 @@ static u8 aspeed_kcs_inb(struct kcs_bmc *kcs_bmc, u32 reg)
 
 static void aspeed_kcs_outb(struct kcs_bmc *kcs_bmc, u32 reg, u8 data)
 {
-   struct aspeed_kcs_bmc *priv = kcs_bmc_priv(kcs_bmc);
+   struct aspeed_kcs_bmc *priv = to_aspeed_kcs_bmc(kcs_bmc);
int rc;
 
rc = regmap_write(priv->map, reg, data);
@@ -92,7 +99,7 @@ static void aspeed_kcs_outb(struct kcs_bmc *kcs_bmc, u32 reg, 
u8 data)
 
 static void aspeed_kcs_updateb(struct kcs_bmc *kcs_bmc, u32 reg, u8 mask, u8 
val)
 {
-   struct aspeed_kcs_bmc *priv = kcs_bmc_priv(kcs_bmc);
+   struct aspeed_kcs_bmc *priv = to_aspeed_kcs_bmc(kcs_bmc);
int rc;
 
rc = regmap_update_bits(priv->map, reg, mask, val);
@@ -114,7 +121,7 @@ static void aspeed_kcs_updateb(struct kcs_bmc *kcs_bmc, u32 
reg, u8 mask, u8 val
  */
 static void aspeed_kcs_set_address(struct kcs_bmc *kcs_bmc, u16 addr)
 {
-   struct aspeed_kcs_bmc *priv = kcs_bmc_priv(kcs_bmc);
+   struct aspeed_kcs_bmc *priv = to_aspeed_kcs_bmc(kcs_bmc);
 
switch (kcs_bmc->channel) {
   

[PATCH v2 15/21] ipmi: kcs_bmc: Don't enforce single-open policy in the kernel

2021-03-18 Thread Andrew Jeffery
Soon it will be possible for one KCS device to have multiple associated
chardevs exposed to userspace (for IPMI and raw-style access). However,
don't prevent userspace from:

1. Opening more than one chardev at a time, or
2. Opening the same chardev more than once.

System behaviour is undefined for both classes of multiple access, so
userspace must manage itself accordingly.

The implementation delivers IBF and OBF events to the first chardev
client to associate with the KCS device. An open on a related chardev
cannot associate its client with the KCS device and so will not
receive notification of events. However, any fd on any chardev may race
their accesses to the data and status registers.

Signed-off-by: Andrew Jeffery 
---
 drivers/char/ipmi/kcs_bmc.c | 34 ++---
 drivers/char/ipmi/kcs_bmc_aspeed.c  |  3 +--
 drivers/char/ipmi/kcs_bmc_npcm7xx.c |  3 +--
 3 files changed, 14 insertions(+), 26 deletions(-)

diff --git a/drivers/char/ipmi/kcs_bmc.c b/drivers/char/ipmi/kcs_bmc.c
index 05bbb72418b2..2fafa9541934 100644
--- a/drivers/char/ipmi/kcs_bmc.c
+++ b/drivers/char/ipmi/kcs_bmc.c
@@ -55,24 +55,12 @@ EXPORT_SYMBOL(kcs_bmc_update_status);
 int kcs_bmc_handle_event(struct kcs_bmc_device *kcs_bmc)
 {
struct kcs_bmc_client *client;
-   int rc;
+   int rc = KCS_BMC_EVENT_NONE;
 
spin_lock(&kcs_bmc->lock);
client = kcs_bmc->client;
-   if (client) {
+   if (!WARN_ON_ONCE(!client))
rc = client->ops->event(client);
-   } else {
-   u8 status;
-
-   status = kcs_bmc_read_status(kcs_bmc);
-   if (status & KCS_BMC_STR_IBF) {
-   /* Ack the event by reading the data */
-   kcs_bmc_read_data(kcs_bmc);
-   rc = KCS_BMC_EVENT_HANDLED;
-   } else {
-   rc = KCS_BMC_EVENT_NONE;
-   }
-   }
spin_unlock(&kcs_bmc->lock);
 
return rc;
@@ -81,26 +69,28 @@ EXPORT_SYMBOL(kcs_bmc_handle_event);
 
 int kcs_bmc_enable_device(struct kcs_bmc_device *kcs_bmc, struct 
kcs_bmc_client *client)
 {
-   int rc;
-
spin_lock_irq(&kcs_bmc->lock);
-   if (kcs_bmc->client) {
-   rc = -EBUSY;
-   } else {
+   if (!kcs_bmc->client) {
+   u8 mask = KCS_BMC_EVENT_TYPE_IBF;
+
kcs_bmc->client = client;
-   rc = 0;
+   kcs_bmc_update_event_mask(kcs_bmc, mask, mask);
}
spin_unlock_irq(&kcs_bmc->lock);
 
-   return rc;
+   return 0;
 }
 EXPORT_SYMBOL(kcs_bmc_enable_device);
 
 void kcs_bmc_disable_device(struct kcs_bmc_device *kcs_bmc, struct 
kcs_bmc_client *client)
 {
spin_lock_irq(&kcs_bmc->lock);
-   if (client == kcs_bmc->client)
+   if (client == kcs_bmc->client) {
+   u8 mask = KCS_BMC_EVENT_TYPE_IBF | KCS_BMC_EVENT_TYPE_OBE;
+
+   kcs_bmc_update_event_mask(kcs_bmc, mask, 0);
kcs_bmc->client = NULL;
+   }
spin_unlock_irq(&kcs_bmc->lock);
 }
 EXPORT_SYMBOL(kcs_bmc_disable_device);
diff --git a/drivers/char/ipmi/kcs_bmc_aspeed.c 
b/drivers/char/ipmi/kcs_bmc_aspeed.c
index 5f26471c038c..271845eb2e26 100644
--- a/drivers/char/ipmi/kcs_bmc_aspeed.c
+++ b/drivers/char/ipmi/kcs_bmc_aspeed.c
@@ -419,8 +419,7 @@ static int aspeed_kcs_probe(struct platform_device *pdev)
 
platform_set_drvdata(pdev, priv);
 
-   aspeed_kcs_irq_mask_update(kcs_bmc, (KCS_BMC_EVENT_TYPE_IBF | 
KCS_BMC_EVENT_TYPE_OBE),
-  KCS_BMC_EVENT_TYPE_IBF);
+   aspeed_kcs_irq_mask_update(kcs_bmc, (KCS_BMC_EVENT_TYPE_IBF | 
KCS_BMC_EVENT_TYPE_OBE), 0);
aspeed_kcs_enable_channel(kcs_bmc, true);
 
rc = kcs_bmc_add_device(&priv->kcs_bmc);
diff --git a/drivers/char/ipmi/kcs_bmc_npcm7xx.c 
b/drivers/char/ipmi/kcs_bmc_npcm7xx.c
index c2032728a03d..fdf35cad2eba 100644
--- a/drivers/char/ipmi/kcs_bmc_npcm7xx.c
+++ b/drivers/char/ipmi/kcs_bmc_npcm7xx.c
@@ -207,8 +207,7 @@ static int npcm7xx_kcs_probe(struct platform_device *pdev)
if (rc)
return rc;
 
-   npcm7xx_kcs_irq_mask_update(kcs_bmc, (KCS_BMC_EVENT_TYPE_IBF | 
KCS_BMC_EVENT_TYPE_OBE),
-   KCS_BMC_EVENT_TYPE_IBF);
+   npcm7xx_kcs_irq_mask_update(kcs_bmc, (KCS_BMC_EVENT_TYPE_IBF | 
KCS_BMC_EVENT_TYPE_OBE), 0);
npcm7xx_kcs_enable_channel(kcs_bmc, true);
 
pr_info("channel=%u idr=0x%x odr=0x%x str=0x%x\n",
-- 
2.27.0



<    4   5   6   7   8   9   10   11   >