Re: [PATCH] I2C: JZ4780: Fix bug for Ingenic X1000.

2021-03-18 Thread Zhou Yanjie

Hi Wolfram,


Sorry, please forgive my carefulness, I wrongly sent the version that 
did not clean up, resulting in missing the reporter's information and 
some errors in formats.



On 2021/3/19 上午1:06, Wolfram Sang wrote:

On Fri, Mar 19, 2021 at 12:25:43AM +0800, 周琰杰 (Zhou Yanjie) wrote:

Only send "X1000_I2C_DC_STOP" when last byte, or it will cause
error when I2C write operation.

Any write operation? I wonder then why nobody noticed before?



The standard I2C communication should look like this:

Read:

device_addr + w, reg_addr, device_addr + r, data;

Write:

device_addr + w, reg_addr, data;


But without this patch, it looks like this:

Read:

device_addr + w, reg_addr, device_addr + r, data;

Write:

device_addr + w, reg_addr, device_addr + w, data;

This is clearly not correct.


When I added support for X1000 to this driver, the hardware used was 
CU1000-Neo. On this hardware, there was an ADS7830 that communicated 
through I2C, but the operation of ADS7830 only involved read operations, 
so I was at that time failed to realize the problem with the write 
operation.
In addition, because X1000 did not implement relatively complete support 
in the mainline until the second half of 2020, there are still a large 
number of users who are still using the old SDK (kernel 3.10 and 
kernel4.4) provided by Ingenics, which may also be indirectly delayed 
exposure of this problem.




-   while ((i2c_sta & JZ4780_I2C_STA_TFNF) &&
-   (i2c->wt_len > 0)) {
+   while ((i2c_sta & JZ4780_I2C_STA_TFNF) && (i2c->wt_len 
> 0)) {

This is a cosmetic change only IIUC. Shouldn't be in a bugfix.



My fault, I will remove it in the next version.


Thanks and best regards!




Re: [PATCH v2] smp: kernel/panic.c - silence warnings

2021-03-18 Thread Christophe Leroy

+Andrew

Le 19/03/2021 à 02:39, heying (H) a écrit :

Dear Ingo, Peter and Christophe,


I'm a bit confused. All of you have a good reason but have opposite opinions.


As far as I understand Ingo is willing to follow the existing "style" of the 
file.

In include/linux/smp.h we have:

- The following functions flagged 'extern':

__smp_call_single_queue()
smp_send_stop()
smp_send_reschedule()
smp_prepare_cpus()
__cpu_up()
smp_cpus_done()
setup_nr_cpu_ids()
smp_init()
up_late_init()
debug_smp_processor_id()
arch_disable_smp_support()
arch_thaw_secondary_cpus_begin()
arch_thaw_secondary_cpus_end()

- The following functions not flagged 'extern':

smp_call_function_single()
on_each_cpu()
on_each_cpu_mask()
on_each_cpu_cond()
on_each_cpu_cond_mask()
smp_call_function_single_async()
smp_call_function()
smp_call_function_many()
smp_call_function_any()
kick_all_cpus_sync()
wake_up_all_idle_cpus()
call_function_init()
generic_smp_call_function_single_interrupt()
smp_prepare_boot_cpu()
smp_setup_processor_id()
smp_call_on_cpu()
smpcfd_prepare_cpu()
smpcfd_dead_cpu()
smpcfd_dying_cpu()


Summary: 13 are 'extern' and 18 are _not_ 'extern'




If I don't add 'extern', can you accept it? Please let me know.


Who is going to merge that ? I'd expect it to be merged by Andrew as it is related to kernel/panic.c 
and most changes to kernel/panic.c are merged by Andrew.


Christophe




Thanks,

He Ying

在 2021/3/18 13:53, Christophe Leroy 写道:



Le 17/03/2021 à 18:37, Peter Zijlstra a écrit :

On Wed, Mar 17, 2021 at 06:17:26PM +0100, Christophe Leroy wrote:



Le 17/03/2021 à 13:23, Peter Zijlstra a écrit :

On Wed, Mar 17, 2021 at 12:00:29PM +0100, Christophe Leroy wrote:

What do you mean ? 'extern' prototype is pointless for function prototypes
and deprecated, no new function prototypes should be added with the 'extern'
keyword.

checkpatch.pl tells you: "extern prototypes should be avoided in .h files"


I have a very strong preference for extern on function decls, to match
the extern on variable decl.


You mean you also do 'static inline' variable declarations ?


That's a func definition, not a declaration. And you _can_ do static
variable definitions in a header file just fine, although that's
typically not what you'd want. Although sometimes I've seen people do:

static const int my_var = 10;

inline is an attribute that obviously doesn't work on variables.


Using the extern keyword on function prototypes is superfluous visual
noise so suggest removing it.


I don't agree; and I think the C spec is actually wrong there (too).

The thing is that it distinguishes between a forward declaration of a
function in the same TU and an external declaration for a function in
another TU.

That is; if I see:

void ponies(int legs);

I expect that function to be defined later in the same TU. IOW it's a
forward declaration. OTOH if I see:

extern void ponies(int legs);

I know I won't find it in this TU and the linker will end up involved.


Yes I can understand that for a .c file where you want to distinguish between forward declaration 
of functions defined in the file and functions declared outside. There, it is definitely an added 
value.


But in .h, all functions must be defined somewhere else, otherwise you have another problem. So 
all functions would have the 'extern' keyword according to your reasoning. Therefore that's just 
useless and I fully agree with Checkpatch's commit that in that case that's "superfluous visual 
noise" impeding readability and making it more difficult to fit the prototype on a single line.





Now, the C people figured that distinction was useless and allowed
sloppiness. But I still think there's merrit to that. And as mentioned
earlier, it is consistent with variable declarations.


.


RE: [RFC PATCH v5 1/4] topology: Represent clusters of CPUs within a die

2021-03-18 Thread Song Bao Hua (Barry Song)



> -Original Message-
> From: Greg KH [mailto:gre...@linuxfoundation.org]
> Sent: Friday, March 19, 2021 7:35 PM
> To: Song Bao Hua (Barry Song) 
> Cc: tim.c.c...@linux.intel.com; catalin.mari...@arm.com; w...@kernel.org;
> r...@rjwysocki.net; vincent.guit...@linaro.org; b...@alien8.de;
> t...@linutronix.de; mi...@redhat.com; l...@kernel.org; pet...@infradead.org;
> dietmar.eggem...@arm.com; rost...@goodmis.org; bseg...@google.com;
> mgor...@suse.de; msys.miz...@gmail.com; valentin.schnei...@arm.com; Jonathan
> Cameron ; juri.le...@redhat.com;
> mark.rutl...@arm.com; sudeep.ho...@arm.com; aubrey...@linux.intel.com;
> linux-arm-ker...@lists.infradead.org; linux-kernel@vger.kernel.org;
> linux-a...@vger.kernel.org; x...@kernel.org; xuwei (O) ;
> Zengtao (B) ; guodong...@linaro.org; yangyicong
> ; Liguozhu (Kenneth) ;
> linux...@openeuler.org; h...@zytor.com
> Subject: Re: [RFC PATCH v5 1/4] topology: Represent clusters of CPUs within
> a die
> 
> On Fri, Mar 19, 2021 at 05:16:15PM +1300, Barry Song wrote:
> > diff --git a/Documentation/admin-guide/cputopology.rst
> b/Documentation/admin-guide/cputopology.rst
> > index b90dafc..f9d3745 100644
> > --- a/Documentation/admin-guide/cputopology.rst
> > +++ b/Documentation/admin-guide/cputopology.rst
> > @@ -24,6 +24,12 @@ core_id:
> > identifier (rather than the kernel's).  The actual value is
> > architecture and platform dependent.
> >
> > +cluster_id:
> > +
> > +   the Cluster ID of cpuX.  Typically it is the hardware platform's
> > +   identifier (rather than the kernel's).  The actual value is
> > +   architecture and platform dependent.
> > +
> >  book_id:
> >
> > the book ID of cpuX. Typically it is the hardware platform's
> > @@ -56,6 +62,14 @@ package_cpus_list:
> > human-readable list of CPUs sharing the same physical_package_id.
> > (deprecated name: "core_siblings_list")
> >
> > +cluster_cpus:
> > +
> > +   internal kernel map of CPUs within the same cluster.
> > +
> > +cluster_cpus_list:
> > +
> > +   human-readable list of CPUs within the same cluster.
> > +
> >  die_cpus:
> >
> > internal kernel map of CPUs within the same die.
> 
> Why are these sysfs files in this file, and not in a Documentation/ABI/
> file which can be correctly parsed and shown to userspace?

Well. Those ABIs have been there for much a long time. It is like:

[root@ceph1 topology]# ls
core_id  core_siblings  core_siblings_list  physical_package_id thread_siblings 
 thread_siblings_list
[root@ceph1 topology]# pwd
/sys/devices/system/cpu/cpu100/topology
[root@ceph1 topology]# cat core_siblings_list
64-127
[root@ceph1 topology]#

> 
> Any chance you can fix that up here as well?

Yes. we will send a separate patch to address this, which won't
be in this patchset. This patchset will base on that one.

> 
> Also note that "list" is not something that goes in sysfs, sysfs is "one
> value per file", and a list is not "one value".  How do you prevent
> overflowing the buffer of the sysfs file if you have a "list"?
> 

At a glance, the list is using "-" rather than a real list
[root@ceph1 topology]# cat core_siblings_list
64-127

Anyway, I will take a look if it has any chance to overflow.

> thanks,
> 
> greg k-h

Thanks
Barry



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

2021-03-18 Thread Jie Deng



On 2021/3/19 14:35, Viresh Kumar wrote:

On 19-03-21, 14:29, Jie Deng wrote:

I also see example drivers/i2c/busses/i2c-xiic.c. Some people might think
this way is more clearer than

updating each member in probe. Basically, I think it's just a matter of
personal preference which doesn't

Memory used by one instance of struct i2c_adapter (on arm64):

struct i2c_adapter {
 struct module *owner;/* 0 8 */
 unsigned int   class;/* 8 4 */

 /* XXX 4 bytes hole, try to pack */

 const struct i2c_algorithm  * algo;  /*16 8 */
 void * algo_data;/*24 8 */
 const struct i2c_lock_operations  * lock_ops;/*32 8 */
 struct rt_mutexbus_lock; /*4032 */
 /* --- cacheline 1 boundary (64 bytes) was 8 bytes ago --- */
 struct rt_mutexmux_lock; /*7232 */
 inttimeout;  /*   104 4 */
 intretries;  /*   108 4 */
 struct device  dev;  /*   112   744 */

 /* XXX last struct has 7 bytes of padding */

 /* --- cacheline 13 boundary (832 bytes) was 24 bytes ago --- */
 long unsigned int  locked_flags; /*   856 8 */
 intnr;   /*   864 4 */
 char   name[48]; /*   86848 */

 /* XXX 4 bytes hole, try to pack */

 /* --- cacheline 14 boundary (896 bytes) was 24 bytes ago --- */
 struct completion  dev_released; /*   92032 */
 struct mutex   userspace_clients_lock; /*   95232 */
 /* --- cacheline 15 boundary (960 bytes) was 24 bytes ago --- */
 struct list_head   userspace_clients;/*   98416 */
 struct i2c_bus_recovery_info * bus_recovery_info; /*  1000 8 */
 const struct i2c_adapter_quirks  * quirks;   /*  1008 8 */
 struct irq_domain *host_notify_domain;   /*  1016 8 */
 /* --- cacheline 16 boundary (1024 bytes) --- */

 /* size: 1024, cachelines: 16, members: 19 */
 /* sum members: 1016, holes: 2, sum holes: 8 */
 /* paddings: 1, sum paddings: 7 */
};

So, this extra instance that i2c-xiic.c is creating (and that you want to
create) is going to waste 1KB of memory and it will never be used.

This is bad coding practice IMHO and it is not really about personal preference.



I will remove that structure and update the members in probe.




[PATCH] scsi: ufs: Don't check UFSHCD_CAP_WB_EN capability in ufshcd_wb_toggle{_flush}

2021-03-18 Thread Yue Hu
From: Yue Hu 

There are several redundant calls to ufshcd_is_wb_allowed() as below:

ufshcd_wb_config()
  |-> ufshcd_is_wb_allowed()
  |-> ufshcd_wb_toggle() -> ufshcd_is_wb_allowed()
  |-> ufshcd_wb_toggle_flush() -> ufshcd_is_wb_allowed()

wb_on_store()
  |-> ufshcd_is_wb_allowed()
  |-> ufshcd_wb_toggle() -> ufshcd_is_wb_allowed()

Considering code handling in wb_on_store(), let's remove needless
ufshcd_is_wb_allowed() in ufshcd_wb_toggle(). Meanwhile, keep the
check in caller ufshcd_devfreq_scale(). Accordingly, also remove
the redundant check in ufshcd_wb_toggle_flush().

Signed-off-by: Yue Hu 
---
 drivers/scsi/ufs/ufshcd.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index b6bfc80..ee71cba 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -1260,7 +1260,8 @@ static int ufshcd_devfreq_scale(struct ufs_hba *hba, bool 
scale_up)
/* Enable Write Booster if we have scaled up else disable it */
downgrade_write(&hba->clk_scaling_lock);
is_writelock = false;
-   ufshcd_wb_toggle(hba, scale_up);
+   if (ufshcd_is_wb_allowed(hba))
+   ufshcd_wb_toggle(hba, scale_up);
 
 out_unprepare:
ufshcd_clock_scaling_unprepare(hba, is_writelock);
@@ -5438,9 +5439,6 @@ int ufshcd_wb_toggle(struct ufs_hba *hba, bool enable)
 {
int ret;
 
-   if (!ufshcd_is_wb_allowed(hba))
-   return 0;
-
if (!(enable ^ hba->dev_info.wb_enabled))
return 0;
 
@@ -5477,8 +5475,7 @@ static inline void ufshcd_wb_toggle_flush(struct ufs_hba 
*hba, bool enable)
 {
int ret;
 
-   if (!ufshcd_is_wb_allowed(hba) ||
-   hba->dev_info.wb_buf_flush_enabled == enable)
+   if (hba->dev_info.wb_buf_flush_enabled == enable)
return;
 
ret = __ufshcd_wb_toggle(hba, enable, QUERY_FLAG_IDN_WB_BUFF_FLUSH_EN);
-- 
1.9.1



Partnership

2021-03-18 Thread M Faraz
Hello there,

Good day. I sent you an email a few days ago but I did not 
receive a reply. I am not sure if you got that email or not. I am 
Muhammad Faraz. I got your contact from an online business 
directory and I am contacting you because I have a proposition 
that could be of great interest to you. I want you to keep an 
open mind while reading this proposal. I represent the interest 
of my brother in-law who was a former minister in the Syrian 
Government. As you probably know, there is a lot of crisis going 
on currently in that part of the world and my brother in-law has 
been one of the few people to publicly oppose the Government's 
policy on this senseless war and killings of innocent citizens 
and have been trying to advocate for a more peaceful and 
prosperous country. Unfortunately, his unwavering support for the 
rebels who are fighting to put an end to the war has caused him 
to fall out with the ruling party and he now has reasons to be 
believe that his life is at risk. In order to ensure that his 
family is taken care of and protected incase anything happens to 
him, he has asked me to help him find a foreign partner with good 
business acumen that can help him secure and invest his assets 
that he has in Europe. This is why I have contacted you. I 
searched online and saw your profile so I thought you would be 
interested in this opportunity.

Do you have investment ideas or business projects that these 
funds can be invested into? Please note that he wants this done 
very discretely and I will be acting as his eyes and ears during 
the course of this transaction. He is also prepared to compensate 
you very much for your efforts so this would be worth your time. 
If this proposal interests you, kindly respond so that I can give 
you more details.

Regards,

Muhammad.


Re: [PATCH] rtl8188eu: Removed Unnecessary ftrace-like logging

2021-03-18 Thread Greg KH
On Thu, Mar 18, 2021 at 08:05:27PM +, Paul McQuade wrote:
> prefer using ftrace

You need to say more here than just this please.

Also please fix up your subject line to have "staging:" in it, otherwise
it gets easily lost.

thanks,

greg k-h


[PATCH net-next 4/4] net: hinic: convert strlcpy to strscpy

2021-03-18 Thread Daode Huang
Usage of strlcpy in linux kernel has been recently
deprecated[1], so convert hinic driver to strscpy

[1] https://lore.kernel.org/lkml/CAHk-=wgfRnXz0W3D37d01q3JFkr_i_uTL
=v6a6g1ouzcprm...@mail.gmail.com/

Signed-off-by: Daode Huang 
---
 drivers/net/ethernet/huawei/hinic/hinic_ethtool.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/huawei/hinic/hinic_ethtool.c 
b/drivers/net/ethernet/huawei/hinic/hinic_ethtool.c
index c340d9a..c7848c3 100644
--- a/drivers/net/ethernet/huawei/hinic/hinic_ethtool.c
+++ b/drivers/net/ethernet/huawei/hinic/hinic_ethtool.c
@@ -543,8 +543,8 @@ static void hinic_get_drvinfo(struct net_device *netdev,
struct hinic_hwif *hwif = hwdev->hwif;
int err;
 
-   strlcpy(info->driver, HINIC_DRV_NAME, sizeof(info->driver));
-   strlcpy(info->bus_info, pci_name(hwif->pdev), sizeof(info->bus_info));
+   strscpy(info->driver, HINIC_DRV_NAME, sizeof(info->driver));
+   strscpy(info->bus_info, pci_name(hwif->pdev), sizeof(info->bus_info));
 
err = hinic_get_mgmt_version(nic_dev, mgmt_ver);
if (err)
-- 
2.8.1



[PATCH net-next 3/4] net: hinic: remove the repeat word "the" in comment.

2021-03-18 Thread Daode Huang
There is a duplicate "the" in the comment, so delete it.

Signed-off-by: Daode Huang 
---
 drivers/net/ethernet/huawei/hinic/hinic_hw_if.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/huawei/hinic/hinic_hw_if.c 
b/drivers/net/ethernet/huawei/hinic/hinic_hw_if.c
index efbaed3..cab38ff 100644
--- a/drivers/net/ethernet/huawei/hinic/hinic_hw_if.c
+++ b/drivers/net/ethernet/huawei/hinic/hinic_hw_if.c
@@ -334,7 +334,7 @@ static void set_dma_attr(struct hinic_hwif *hwif, u32 
entry_idx,
 }
 
 /**
- * dma_attr_table_init - initialize the the default dma attributes
+ * dma_attr_table_init - initialize the default dma attributes
  * @hwif: the HW interface of a pci function device
  **/
 static void dma_attr_init(struct hinic_hwif *hwif)
-- 
2.8.1



[PATCH net-next 1/4] net: hinic: Remove unnecessary 'out of memory' message

2021-03-18 Thread Daode Huang
This patch removes unnecessary out of memory message in hinic driver,
fixes the following checkpatch.pl warning:
"WARNING: Possible unnecessary 'out of memory' message"

Signed-off-by: Daode Huang 
---
 drivers/net/ethernet/huawei/hinic/hinic_hw_api_cmd.c | 8 ++--
 drivers/net/ethernet/huawei/hinic/hinic_hw_mgmt.c| 5 +
 drivers/net/ethernet/huawei/hinic/hinic_hw_qp.c  | 1 -
 drivers/net/ethernet/huawei/hinic/hinic_rx.c | 8 ++--
 4 files changed, 5 insertions(+), 17 deletions(-)

diff --git a/drivers/net/ethernet/huawei/hinic/hinic_hw_api_cmd.c 
b/drivers/net/ethernet/huawei/hinic/hinic_hw_api_cmd.c
index 4e4029d..0658617 100644
--- a/drivers/net/ethernet/huawei/hinic/hinic_hw_api_cmd.c
+++ b/drivers/net/ethernet/huawei/hinic/hinic_hw_api_cmd.c
@@ -629,10 +629,8 @@ static int alloc_cmd_buf(struct hinic_api_cmd_chain *chain,
 
cmd_vaddr = dma_alloc_coherent(&pdev->dev, API_CMD_BUF_SIZE,
   &cmd_paddr, GFP_KERNEL);
-   if (!cmd_vaddr) {
-   dev_err(&pdev->dev, "Failed to allocate API CMD DMA memory\n");
+   if (!cmd_vaddr)
return -ENOMEM;
-   }
 
cell_ctxt = &chain->cell_ctxt[cell_idx];
 
@@ -679,10 +677,8 @@ static int api_cmd_create_cell(struct hinic_api_cmd_chain 
*chain,
 
node = dma_alloc_coherent(&pdev->dev, chain->cell_size, &node_paddr,
  GFP_KERNEL);
-   if (!node) {
-   dev_err(&pdev->dev, "Failed to allocate dma API CMD cell\n");
+   if (!node)
return -ENOMEM;
-   }
 
node->read.hw_wb_resp_paddr = 0;
 
diff --git a/drivers/net/ethernet/huawei/hinic/hinic_hw_mgmt.c 
b/drivers/net/ethernet/huawei/hinic/hinic_hw_mgmt.c
index 819fa13..6b9b94a 100644
--- a/drivers/net/ethernet/huawei/hinic/hinic_hw_mgmt.c
+++ b/drivers/net/ethernet/huawei/hinic/hinic_hw_mgmt.c
@@ -443,15 +443,12 @@ static void mgmt_recv_msg_handler(struct hinic_pf_to_mgmt 
*pf_to_mgmt,
struct pci_dev *pdev = pf_to_mgmt->hwif->pdev;
 
mgmt_work = kzalloc(sizeof(*mgmt_work), GFP_KERNEL);
-   if (!mgmt_work) {
-   dev_err(&pdev->dev, "Allocate mgmt work memory failed\n");
+   if (!mgmt_work)
return;
-   }
 
if (recv_msg->msg_len) {
mgmt_work->msg = kzalloc(recv_msg->msg_len, GFP_KERNEL);
if (!mgmt_work->msg) {
-   dev_err(&pdev->dev, "Allocate mgmt msg memory 
failed\n");
kfree(mgmt_work);
return;
}
diff --git a/drivers/net/ethernet/huawei/hinic/hinic_hw_qp.c 
b/drivers/net/ethernet/huawei/hinic/hinic_hw_qp.c
index fcf7bfe..dcba4d0 100644
--- a/drivers/net/ethernet/huawei/hinic/hinic_hw_qp.c
+++ b/drivers/net/ethernet/huawei/hinic/hinic_hw_qp.c
@@ -414,7 +414,6 @@ int hinic_init_rq(struct hinic_rq *rq, struct hinic_hwif 
*hwif,
rq->pi_virt_addr = dma_alloc_coherent(&pdev->dev, pi_size,
  &rq->pi_dma_addr, GFP_KERNEL);
if (!rq->pi_virt_addr) {
-   dev_err(&pdev->dev, "Failed to allocate PI address\n");
err = -ENOMEM;
goto err_pi_virt;
}
diff --git a/drivers/net/ethernet/huawei/hinic/hinic_rx.c 
b/drivers/net/ethernet/huawei/hinic/hinic_rx.c
index 070a7cc..cce0864 100644
--- a/drivers/net/ethernet/huawei/hinic/hinic_rx.c
+++ b/drivers/net/ethernet/huawei/hinic/hinic_rx.c
@@ -137,10 +137,8 @@ static struct sk_buff *rx_alloc_skb(struct hinic_rxq *rxq,
int err;
 
skb = netdev_alloc_skb_ip_align(rxq->netdev, rxq->rq->buf_sz);
-   if (!skb) {
-   netdev_err(rxq->netdev, "Failed to allocate Rx SKB\n");
+   if (!skb)
return NULL;
-   }
 
addr = dma_map_single(&pdev->dev, skb->data, rxq->rq->buf_sz,
  DMA_FROM_DEVICE);
@@ -212,10 +210,8 @@ static int rx_alloc_pkts(struct hinic_rxq *rxq)
 
for (i = 0; i < free_wqebbs; i++) {
skb = rx_alloc_skb(rxq, &dma_addr);
-   if (!skb) {
-   netdev_err(rxq->netdev, "Failed to alloc Rx skb\n");
+   if (!skb)
goto skb_out;
-   }
 
hinic_set_sge(&sge, dma_addr, skb->len);
 
-- 
2.8.1



[PATCH net-next 2/4] net: hinic: add a blank line after declarations

2021-03-18 Thread Daode Huang
There should be a blank line after declarations, so just add it.

Signed-off-by: Daode Huang 
---
 drivers/net/ethernet/huawei/hinic/hinic_tx.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/ethernet/huawei/hinic/hinic_tx.c 
b/drivers/net/ethernet/huawei/hinic/hinic_tx.c
index 8da7d46..710c4ff 100644
--- a/drivers/net/ethernet/huawei/hinic/hinic_tx.c
+++ b/drivers/net/ethernet/huawei/hinic/hinic_tx.c
@@ -377,6 +377,7 @@ static int offload_csum(struct hinic_sq_task *task, u32 
*queue_info,
} else if (ip.v4->version == 6) {
unsigned char *exthdr;
__be16 frag_off;
+
l3_type = IPV6_PKT;
tunnel_type = TUNNEL_UDP_CSUM;
exthdr = ip.hdr + sizeof(*ip.v6);
-- 
2.8.1



[PATCH net-next 0/4] net: hinic; make some cleanup for hinic

2021-03-18 Thread Daode Huang
This set try to remove the unnecessary output message, add a blank line,
remove the dupliate word and change the deprecated strlcp functions in
hinic driver, for details, please refer to each patch.

Daode Huang (4):
  net: hinic: Remove unnecessary 'out of memory' message
  net: hinic: add a blank line after declarations
  net: hinic: remove the repeat word "the" in comment.
  net: hinic: convert strlcpy to strscpy

 drivers/net/ethernet/huawei/hinic/hinic_ethtool.c| 4 ++--
 drivers/net/ethernet/huawei/hinic/hinic_hw_api_cmd.c | 8 ++--
 drivers/net/ethernet/huawei/hinic/hinic_hw_if.c  | 2 +-
 drivers/net/ethernet/huawei/hinic/hinic_hw_mgmt.c| 5 +
 drivers/net/ethernet/huawei/hinic/hinic_hw_qp.c  | 1 -
 drivers/net/ethernet/huawei/hinic/hinic_rx.c | 8 ++--
 drivers/net/ethernet/huawei/hinic/hinic_tx.c | 1 +
 7 files changed, 9 insertions(+), 20 deletions(-)

-- 
2.8.1



Re: [PATCH] X86: __set_clr_pte_enc() miscalculates physical address

2021-03-18 Thread Greg KH
On Thu, Mar 18, 2021 at 01:26:57PM -0700, Isaku Yamahata wrote:
> __set_clr_pte_enc() miscalculates physical address to operate.
> pfn is in unit of PG_LEVEL_4K, not PGL_LEVEL_{2M, 1G}.
> Shift size to get physical address should be PAGE_SHIFT,
> not page_level_shift().
> 
> Fixes: dfaaec9033b8 ("x86: Add support for changing memory encryption 
> attribute in early boot")
> Reviewed-by: Kirill A. Shutemov 
> Signed-off-by: Isaku Yamahata 
> ---
>  arch/x86/mm/mem_encrypt.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)



This is not the correct way to submit patches for inclusion in the
stable kernel tree.  Please read:
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.




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

2021-03-18 Thread Greg KH
On Fri, Mar 19, 2021 at 05:28:59AM +, Dmitry Monakhov wrote:
> 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(+)




This is not the correct way to submit patches for inclusion in the
stable kernel tree.  Please read:
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.




RE: [PATCH] tty: serial: samsung_tty: remove spinlock flags in interrupt handlers

2021-03-18 Thread Song Bao Hua (Barry Song)


> -Original Message-
> From: Andy Shevchenko [mailto:andy.shevche...@gmail.com]
> Sent: Tuesday, March 16, 2021 10:41 PM
> To: Johan Hovold ; Finn Thain ;
> Song Bao Hua (Barry Song) 
> Cc: Krzysztof Kozlowski ; Greg
> Kroah-Hartman ; Jiri Slaby ;
> linux-arm Mailing List ; Linux Samsung
> SOC ; open list:SERIAL DRIVERS
> ; Linux Kernel Mailing List
> ; Hector Martin ; Arnd
> Bergmann 
> Subject: Re: [PATCH] tty: serial: samsung_tty: remove spinlock flags in
> interrupt handlers
> 
> On Tue, Mar 16, 2021 at 11:02 AM Johan Hovold  wrote:
> >
> > On Mon, Mar 15, 2021 at 07:12:12PM +0100, Krzysztof Kozlowski wrote:
> > > Since interrupt handler is called with disabled local interrupts, there
> > > is no need to use the spinlock primitives disabling interrupts as well.
> >
> > This isn't generally true due to "threadirqs" and that can lead to
> > deadlocks if the console code is called from hard irq context.
> >
> > Now, this is *not* the case for this particular driver since it doesn't
> > even bother to take the port lock in console_write(). That should
> > probably be fixed instead.
> >
> > See https://lore.kernel.org/r/X7kviiRwuxvPxC8O@localhost.
> 
> Finn, Barry, something to check I think?

My understanding is that spin_lock_irqsave can't protect the context
the console_write() is called in hardirq for threaded_irq case mainly
for preempt-rt scenarios as spin_lock_irqsave doesn't disable irq in
that case at all.
See:
https://www.kernel.org/doc/html/latest/locking/locktypes.html
spinlock_t and PREEMPT_RT
On a PREEMPT_RT kernel spinlock_t is mapped to a separate implementation
based on rt_mutex which changes the semantics:
Preemption is not disabled.
The hard interrupt related suffixes for spin_lock / spin_unlock operations
(_irq, _irqsave / _irqrestore) do not affect the CPU’s interrupt disabled
state.

So if console_write() can interrupt our code in hardirq, we should
move to raw_spin_lock_irqsave for this driver.

I think it is almost always wrong to call spin_lock_irqsave in hardirq.

> 
> --
> With Best Regards,
> Andy Shevchenko

Thanks
Barry


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

2021-03-18 Thread Viresh Kumar
On 19-03-21, 14:29, Jie Deng wrote:
> I also see example drivers/i2c/busses/i2c-xiic.c. Some people might think
> this way is more clearer than
> 
> updating each member in probe. Basically, I think it's just a matter of
> personal preference which doesn't

Memory used by one instance of struct i2c_adapter (on arm64):

struct i2c_adapter {
struct module *owner;/* 0 8 */
unsigned int   class;/* 8 4 */

/* XXX 4 bytes hole, try to pack */

const struct i2c_algorithm  * algo;  /*16 8 */
void * algo_data;/*24 8 */
const struct i2c_lock_operations  * lock_ops;/*32 8 */
struct rt_mutexbus_lock; /*4032 */
/* --- cacheline 1 boundary (64 bytes) was 8 bytes ago --- */
struct rt_mutexmux_lock; /*7232 */
inttimeout;  /*   104 4 */
intretries;  /*   108 4 */
struct device  dev;  /*   112   744 */

/* XXX last struct has 7 bytes of padding */

/* --- cacheline 13 boundary (832 bytes) was 24 bytes ago --- */
long unsigned int  locked_flags; /*   856 8 */
intnr;   /*   864 4 */
char   name[48]; /*   86848 */

/* XXX 4 bytes hole, try to pack */

/* --- cacheline 14 boundary (896 bytes) was 24 bytes ago --- */
struct completion  dev_released; /*   92032 */
struct mutex   userspace_clients_lock; /*   95232 */
/* --- cacheline 15 boundary (960 bytes) was 24 bytes ago --- */
struct list_head   userspace_clients;/*   98416 */
struct i2c_bus_recovery_info * bus_recovery_info; /*  1000 8 */
const struct i2c_adapter_quirks  * quirks;   /*  1008 8 */
struct irq_domain *host_notify_domain;   /*  1016 8 */
/* --- cacheline 16 boundary (1024 bytes) --- */

/* size: 1024, cachelines: 16, members: 19 */
/* sum members: 1016, holes: 2, sum holes: 8 */
/* paddings: 1, sum paddings: 7 */
};

So, this extra instance that i2c-xiic.c is creating (and that you want to
create) is going to waste 1KB of memory and it will never be used.

This is bad coding practice IMHO and it is not really about personal preference.

-- 
viresh


[PATCH v6 5/5] drm/bridge: anx7625: add HDMI audio function

2021-03-18 Thread Xin Ji
Add audio HDMI codec function support, enable it through device true flag
"analogix,audio-enable".

Reported-by: kernel test robot 
Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 227 ++
 drivers/gpu/drm/bridge/analogix/anx7625.h |   5 +
 2 files changed, 232 insertions(+)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index b424a570effa..02bb169d9c57 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -30,6 +30,8 @@
 #include 
 #include 
 
+#include 
+
 #include 
 
 #include "anx7625.h"
@@ -150,6 +152,20 @@ static int anx7625_write_and(struct anx7625_data *ctx,
return anx7625_reg_write(ctx, client, offset, (val & (mask)));
 }
 
+static int anx7625_write_and_or(struct anx7625_data *ctx,
+   struct i2c_client *client,
+   u8 offset, u8 and_mask, u8 or_mask)
+{
+   int val;
+
+   val = anx7625_reg_read(ctx, client, offset);
+   if (val < 0)
+   return val;
+
+   return anx7625_reg_write(ctx, client,
+offset, (val & and_mask) | (or_mask));
+}
+
 static int anx7625_config_bit_matrix(struct anx7625_data *ctx)
 {
int i, ret;
@@ -1498,6 +1514,9 @@ static int anx7625_parse_dt(struct device *dev,
else
DRM_DEV_DEBUG_DRIVER(dev, "found MIPI DSI host node.\n");
 
+   if (of_property_read_bool(np, "analogix,audio-enable"))
+   pdata->audio_en = 1;
+
ret = drm_of_find_panel_or_bridge(np, 1, 0, &panel, NULL);
if (ret < 0) {
if (ret == -ENODEV)
@@ -1568,6 +1587,208 @@ static enum drm_connector_status 
anx7625_sink_detect(struct anx7625_data *ctx)
 connector_status_disconnected;
 }
 
+static int anx7625_audio_hw_params(struct device *dev, void *data,
+  struct hdmi_codec_daifmt *fmt,
+  struct hdmi_codec_params *params)
+{
+   struct anx7625_data *ctx = dev_get_drvdata(dev);
+   int wl, ch, rate;
+   int ret = 0;
+
+   if (fmt->fmt != HDMI_DSP_A) {
+   DRM_DEV_ERROR(dev, "only supports DSP_A\n");
+   return -EINVAL;
+   }
+
+   DRM_DEV_DEBUG_DRIVER(dev, "setting %d Hz, %d bit, %d channels\n",
+params->sample_rate, params->sample_width,
+params->cea.channels);
+
+   ret |= anx7625_write_and_or(ctx, ctx->i2c.tx_p2_client,
+   AUDIO_CHANNEL_STATUS_6,
+   ~I2S_SLAVE_MODE,
+   TDM_SLAVE_MODE);
+
+   /* Word length */
+   switch (params->sample_width) {
+   case 16:
+   wl = AUDIO_W_LEN_16_20MAX;
+   break;
+   case 18:
+   wl = AUDIO_W_LEN_18_20MAX;
+   break;
+   case 20:
+   wl = AUDIO_W_LEN_20_20MAX;
+   break;
+   case 24:
+   wl = AUDIO_W_LEN_24_24MAX;
+   break;
+   default:
+   DRM_DEV_DEBUG_DRIVER(dev, "wordlength: %d bit not support",
+params->sample_width);
+   return -EINVAL;
+   }
+   ret |= anx7625_write_and_or(ctx, ctx->i2c.tx_p2_client,
+   AUDIO_CHANNEL_STATUS_5,
+   0xf0, wl);
+
+   /* Channel num */
+   switch (params->cea.channels) {
+   case 2:
+   ch = I2S_CH_2;
+   break;
+   case 4:
+   ch = TDM_CH_4;
+   break;
+   case 6:
+   ch = TDM_CH_6;
+   break;
+   case 8:
+   ch = TDM_CH_8;
+   break;
+   default:
+   DRM_DEV_DEBUG_DRIVER(dev, "channel number: %d not support",
+params->cea.channels);
+   return -EINVAL;
+   }
+   ret |= anx7625_write_and_or(ctx, ctx->i2c.tx_p2_client,
+  AUDIO_CHANNEL_STATUS_6, 0x1f, ch << 5);
+   if (ch > I2S_CH_2)
+   ret |= anx7625_write_or(ctx, ctx->i2c.tx_p2_client,
+   AUDIO_CHANNEL_STATUS_6, AUDIO_LAYOUT);
+   else
+   ret |= anx7625_write_and(ctx, ctx->i2c.tx_p2_client,
+   AUDIO_CHANNEL_STATUS_6, ~AUDIO_LAYOUT);
+
+   /* FS */
+   switch (params->sample_rate) {
+   case 32000:
+   rate = AUDIO_FS_32K;
+   break;
+   case 44100:
+   rate = AUDIO_FS_441K;
+   break;
+   case 48000:
+   rate = AUDIO_FS_48K;
+   break;
+   case 88200:
+   rate = AUDIO_FS_882K;
+   break;
+   case 96000:
+   rate = AUDIO_FS_96K;
+   break;
+ 

Re: [RFC PATCH v5 1/4] topology: Represent clusters of CPUs within a die

2021-03-18 Thread Greg KH
On Fri, Mar 19, 2021 at 05:16:15PM +1300, Barry Song wrote:
> diff --git a/Documentation/admin-guide/cputopology.rst 
> b/Documentation/admin-guide/cputopology.rst
> index b90dafc..f9d3745 100644
> --- a/Documentation/admin-guide/cputopology.rst
> +++ b/Documentation/admin-guide/cputopology.rst
> @@ -24,6 +24,12 @@ core_id:
>   identifier (rather than the kernel's).  The actual value is
>   architecture and platform dependent.
>  
> +cluster_id:
> +
> + the Cluster ID of cpuX.  Typically it is the hardware platform's
> + identifier (rather than the kernel's).  The actual value is
> + architecture and platform dependent.
> +
>  book_id:
>  
>   the book ID of cpuX. Typically it is the hardware platform's
> @@ -56,6 +62,14 @@ package_cpus_list:
>   human-readable list of CPUs sharing the same physical_package_id.
>   (deprecated name: "core_siblings_list")
>  
> +cluster_cpus:
> +
> + internal kernel map of CPUs within the same cluster.
> +
> +cluster_cpus_list:
> +
> + human-readable list of CPUs within the same cluster.
> +
>  die_cpus:
>  
>   internal kernel map of CPUs within the same die.

Why are these sysfs files in this file, and not in a Documentation/ABI/
file which can be correctly parsed and shown to userspace?

Any chance you can fix that up here as well?

Also note that "list" is not something that goes in sysfs, sysfs is "one
value per file", and a list is not "one value".  How do you prevent
overflowing the buffer of the sysfs file if you have a "list"?

thanks,

greg k-h


[PATCH v6] powerpc/irq: inline call_do_irq() and call_do_softirq() on PPC32

2021-03-18 Thread Christophe Leroy
call_do_irq() and call_do_softirq() are simple enough to be
worth inlining.

Inlining them avoids an mflr/mtlr pair plus a save/reload on stack.
It also allows GCC to keep the saved ksp_limit in an nonvolatile reg.

This is inspired from S390 arch. Several other arches do more or
less the same. The way sparc arch does seems odd thought.

For the time being this is limited to PPC32 because there are
incertainties on the handling of r2 which is the TOC on PPC64,
see discussion at https://patchwork.ozlabs.org/patch/1174288/

Signed-off-by: Christophe Leroy 
Reviewed-by: Segher Boessenkool 
---
v2: no change.
v3: no change.
v4:
- comment reminding the purpose of the inline asm block.
- added r2 as clobbered reg
v5:
- Limiting the change to PPC32 for now.
- removed r2 from the clobbered regs list (on PPC32 r2 points to current all 
the time)
- Removed patch 1 and merged ksp_limit handling in here.
v6:
- Rebase on top of merge-test (ca6e327fefb2).
- Remove the ksp_limit stuff as it's doesn't exist anymore.
---
 arch/powerpc/include/asm/irq.h |  2 ++
 arch/powerpc/kernel/irq.c  | 34 ++
 arch/powerpc/kernel/misc_32.S  | 25 -
 3 files changed, 36 insertions(+), 25 deletions(-)

diff --git a/arch/powerpc/include/asm/irq.h b/arch/powerpc/include/asm/irq.h
index f3f264e441a7..23c28974ca29 100644
--- a/arch/powerpc/include/asm/irq.h
+++ b/arch/powerpc/include/asm/irq.h
@@ -53,8 +53,10 @@ extern void *mcheckirq_ctx[NR_CPUS];
 extern void *hardirq_ctx[NR_CPUS];
 extern void *softirq_ctx[NR_CPUS];
 
+#ifdef CONFIG_PPC64
 void call_do_softirq(void *sp);
 void call_do_irq(struct pt_regs *regs, void *sp);
+#endif
 extern void do_IRQ(struct pt_regs *regs);
 extern void __init init_IRQ(void);
 extern void __do_irq(struct pt_regs *regs);
diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
index 5b72abbff96c..327422c57ae8 100644
--- a/arch/powerpc/kernel/irq.c
+++ b/arch/powerpc/kernel/irq.c
@@ -667,6 +667,40 @@ static inline void check_stack_overflow(void)
}
 }
 
+#ifdef CONFIG_PPC32
+static inline void call_do_softirq(const void *sp)
+{
+   register unsigned long ret asm("r3");
+
+   /* Temporarily switch r1 to sp, call __do_softirq() then restore r1. */
+   asm volatile(
+   "   "PPC_STLU"  1, %2(%1);\n"
+   "   mr  1, %1;\n"
+   "   bl  %3;\n"
+   "   "PPC_LL"1, 0(1);\n" :
+   "=r"(ret) :
+   "b"(sp), "i"(THREAD_SIZE - STACK_FRAME_OVERHEAD), 
"i"(__do_softirq) :
+   "lr", "xer", "ctr", "memory", "cr0", "cr1", "cr5", "cr6", "cr7",
+   "r0", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12");
+}
+
+static inline void call_do_irq(struct pt_regs *regs, void *sp)
+{
+   register unsigned long r3 asm("r3") = (unsigned long)regs;
+
+   /* Temporarily switch r1 to sp, call __do_irq() then restore r1. */
+   asm volatile(
+   "   "PPC_STLU"  1, %2(%1);\n"
+   "   mr  1, %1;\n"
+   "   bl  %3;\n"
+   "   "PPC_LL"1, 0(1);\n" :
+   "+r"(r3) :
+   "b"(sp), "i"(THREAD_SIZE - STACK_FRAME_OVERHEAD), "i"(__do_irq) 
:
+   "lr", "xer", "ctr", "memory", "cr0", "cr1", "cr5", "cr6", "cr7",
+   "r0", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12");
+}
+#endif
+
 void __do_irq(struct pt_regs *regs)
 {
unsigned int irq;
diff --git a/arch/powerpc/kernel/misc_32.S b/arch/powerpc/kernel/misc_32.S
index acc410043b96..6a076bef2932 100644
--- a/arch/powerpc/kernel/misc_32.S
+++ b/arch/powerpc/kernel/misc_32.S
@@ -27,31 +27,6 @@
 
.text
 
-_GLOBAL(call_do_softirq)
-   mflrr0
-   stw r0,4(r1)
-   stwur1,THREAD_SIZE-STACK_FRAME_OVERHEAD(r3)
-   mr  r1,r3
-   bl  __do_softirq
-   lwz r1,0(r1)
-   lwz r0,4(r1)
-   mtlrr0
-   blr
-
-/*
- * void call_do_irq(struct pt_regs *regs, void *sp);
- */
-_GLOBAL(call_do_irq)
-   mflrr0
-   stw r0,4(r1)
-   stwur1,THREAD_SIZE-STACK_FRAME_OVERHEAD(r4)
-   mr  r1,r4
-   bl  __do_irq
-   lwz r1,0(r1)
-   lwz r0,4(r1)
-   mtlrr0
-   blr
-
 /*
  * This returns the high 64 bits of the product of two 64-bit numbers.
  */
-- 
2.25.0



[PATCH v6 4/5] drm/bridge: anx7625: add HDCP support

2021-03-18 Thread Xin Ji
Add HDCP feature, enable HDCP function through chip internal key
and downstream's capability.

Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 147 ++
 drivers/gpu/drm/bridge/analogix/anx7625.h |  36 ++
 2 files changed, 183 insertions(+)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index 8c514b46d361..b424a570effa 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -633,6 +633,150 @@ static int anx7625_dpi_config(struct anx7625_data *ctx)
return ret;
 }
 
+static int anx7625_aux_dpcd_read(struct anx7625_data *ctx,
+u8 addrh, u8 addrm, u8 addrl,
+u8 len, u8 *buf)
+{
+   struct device *dev = &ctx->client->dev;
+   int ret;
+   u8 cmd;
+
+   if (len > MAX_DPCD_BUFFER_SIZE) {
+   DRM_DEV_ERROR(dev, "exceed aux buffer len.\n");
+   return -E2BIG;
+   }
+
+   cmd = ((len - 1) << 4) | 0x09;
+
+   /* Set command and length */
+   ret = anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+   AP_AUX_COMMAND, cmd);
+
+   /* Set aux access address */
+   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+AP_AUX_ADDR_7_0, addrl);
+   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+AP_AUX_ADDR_15_8, addrm);
+   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+AP_AUX_ADDR_19_16, addrh);
+
+   /* Enable aux access */
+   ret |= anx7625_write_or(ctx, ctx->i2c.rx_p0_client,
+   AP_AUX_CTRL_STATUS, AP_AUX_CTRL_OP_EN);
+
+   if (ret < 0) {
+   DRM_DEV_ERROR(dev, "cannot access aux related register.\n");
+   return -EIO;
+   }
+
+   usleep_range(2000, 2100);
+
+   ret = wait_aux_op_finish(ctx);
+   if (ret) {
+   DRM_DEV_ERROR(dev, "aux IO error: wait aux op finish.\n");
+   return ret;
+   }
+
+   ret = anx7625_reg_block_read(ctx, ctx->i2c.rx_p0_client,
+AP_AUX_BUFF_START, len, buf);
+   if (ret < 0) {
+   DRM_DEV_ERROR(dev, "read dpcd register failed\n");
+   return -EIO;
+   }
+
+   return 0;
+}
+
+static int anx7625_read_flash_status(struct anx7625_data *ctx)
+{
+   return anx7625_reg_read(ctx, ctx->i2c.rx_p0_client, R_RAM_CTRL);
+}
+
+static int anx7625_hdcp_key_probe(struct anx7625_data *ctx)
+{
+   int ret, val;
+   struct device *dev = &ctx->client->dev;
+   u8 ident[32];
+
+   ret = anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+   FLASH_ADDR_HIGH, 0x91);
+   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+FLASH_ADDR_LOW, 0xA0);
+   if (ret < 0) {
+   DRM_DEV_ERROR(dev, "IO error : set key flash address.\n");
+   return ret;
+   }
+
+   ret = anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+   FLASH_LEN_HIGH, (FLASH_BUF_LEN - 1) >> 8);
+   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+FLASH_LEN_LOW, (FLASH_BUF_LEN - 1) & 0xFF);
+   if (ret < 0) {
+   DRM_DEV_ERROR(dev, "IO error : set key flash len.\n");
+   return ret;
+   }
+
+   ret = anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+   R_FLASH_RW_CTRL, FLASH_READ);
+   ret |= readx_poll_timeout(anx7625_read_flash_status,
+ ctx, val,
+ ((val & FLASH_DONE) || (val < 0)),
+ 2000,
+ 2000 * 150);
+   if (ret) {
+   DRM_DEV_ERROR(dev, "flash read access fail!\n");
+   return -EIO;
+   }
+
+   ret = anx7625_reg_block_read(ctx, ctx->i2c.rx_p0_client,
+FLASH_BUF_BASE_ADDR,
+FLASH_BUF_LEN, ident);
+   if (ret < 0) {
+   DRM_DEV_ERROR(dev, "read flash data fail!\n");
+   return -EIO;
+   }
+
+   if (ident[29] == 0xFF && ident[30] == 0xFF && ident[31] == 0xFF)
+   return -EINVAL;
+
+   return 0;
+}
+
+static int anx7625_hdcp_setting(struct anx7625_data *ctx)
+{
+   u8 bcap;
+   int ret;
+   struct device *dev = &ctx->client->dev;
+
+   ret = anx7625_hdcp_key_probe(ctx);
+   if (ret) {
+   DRM_DEV_DEBUG_DRIVER(dev, "disable HDCP by config\n");
+   return anx7625_write_and(ctx, ctx->i2c.rx_p1_client,
+0xee, 0x9f);
+   }
+
+   anx7625_aux_dpcd_read(ctx, 0x06, 0x80, 0x28, 1, &bcap);
+   if (!(bcap & 0x01)) {
+   DRM_DEV_DEBUG_DRI

[PATCH v6 3/5] drm/bridge: anx7625: add MIPI DPI input feature support

2021-03-18 Thread Xin Ji
Add MIPI rx DPI input support.

Reported-by: kernel test robot 
Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 245 --
 drivers/gpu/drm/bridge/analogix/anx7625.h |  18 +-
 2 files changed, 203 insertions(+), 60 deletions(-)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index 04536cc7afe7..8c514b46d361 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -150,18 +150,18 @@ static int anx7625_write_and(struct anx7625_data *ctx,
return anx7625_reg_write(ctx, client, offset, (val & (mask)));
 }
 
-static int anx7625_write_and_or(struct anx7625_data *ctx,
-   struct i2c_client *client,
-   u8 offset, u8 and_mask, u8 or_mask)
+static int anx7625_config_bit_matrix(struct anx7625_data *ctx)
 {
-   int val;
+   int i, ret;
 
-   val = anx7625_reg_read(ctx, client, offset);
-   if (val < 0)
-   return val;
+   ret = anx7625_write_or(ctx, ctx->i2c.tx_p2_client,
+  AUDIO_CONTROL_REGISTER, 0x80);
+   for (i = 0; i < 13; i++)
+   ret |= anx7625_reg_write(ctx, ctx->i2c.tx_p2_client,
+VIDEO_BIT_MATRIX_12 + i,
+0x18 + i);
 
-   return anx7625_reg_write(ctx, client,
-offset, (val & and_mask) | (or_mask));
+   return ret;
 }
 
 static int anx7625_read_ctrl_status_p0(struct anx7625_data *ctx)
@@ -219,38 +219,6 @@ static int anx7625_video_mute_control(struct anx7625_data 
*ctx,
return ret;
 }
 
-static int anx7625_config_audio_input(struct anx7625_data *ctx)
-{
-   struct device *dev = &ctx->client->dev;
-   int ret;
-
-   /* Channel num */
-   ret = anx7625_reg_write(ctx, ctx->i2c.tx_p2_client,
-   AUDIO_CHANNEL_STATUS_6, I2S_CH_2 << 5);
-
-   /* FS */
-   ret |= anx7625_write_and_or(ctx, ctx->i2c.tx_p2_client,
-   AUDIO_CHANNEL_STATUS_4,
-   0xf0, AUDIO_FS_48K);
-   /* Word length */
-   ret |= anx7625_write_and_or(ctx, ctx->i2c.tx_p2_client,
-   AUDIO_CHANNEL_STATUS_5,
-   0xf0, AUDIO_W_LEN_24_24MAX);
-   /* I2S */
-   ret |= anx7625_write_or(ctx, ctx->i2c.tx_p2_client,
-   AUDIO_CHANNEL_STATUS_6, I2S_SLAVE_MODE);
-   ret |= anx7625_write_and(ctx, ctx->i2c.tx_p2_client,
-AUDIO_CONTROL_REGISTER, ~TDM_TIMING_MODE);
-   /* Audio change flag */
-   ret |= anx7625_write_or(ctx, ctx->i2c.rx_p0_client,
-   AP_AV_STATUS, AP_AUDIO_CHG);
-
-   if (ret < 0)
-   DRM_DEV_ERROR(dev, "fail to config audio.\n");
-
-   return ret;
-}
-
 /* Reduction of fraction a/b */
 static void anx7625_reduction_of_a_fraction(unsigned long *a, unsigned long *b)
 {
@@ -410,7 +378,7 @@ static int anx7625_dsi_video_timing_config(struct 
anx7625_data *ctx)
ret |= anx7625_write_and(ctx, ctx->i2c.rx_p1_client,
MIPI_LANE_CTRL_0, 0xfc);
ret |= anx7625_write_or(ctx, ctx->i2c.rx_p1_client,
-   MIPI_LANE_CTRL_0, 3);
+   MIPI_LANE_CTRL_0, ctx->pdata.mipi_lanes - 1);
 
/* Htotal */
htotal = ctx->dt.hactive.min + ctx->dt.hfront_porch.min +
@@ -595,6 +563,76 @@ static int anx7625_dsi_config(struct anx7625_data *ctx)
return ret;
 }
 
+static int anx7625_api_dpi_config(struct anx7625_data *ctx)
+{
+   struct device *dev = &ctx->client->dev;
+   u16 freq = ctx->dt.pixelclock.min / 1000;
+   int ret;
+
+   /* configure pixel clock */
+   ret = anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+   PIXEL_CLOCK_L, freq & 0xFF);
+   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+PIXEL_CLOCK_H, (freq >> 8));
+
+   /* set DPI mode */
+   /* set to DPI PLL module sel */
+   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p1_client,
+MIPI_DIGITAL_PLL_9, 0x20);
+   /* power down MIPI */
+   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p1_client,
+MIPI_LANE_CTRL_10, 0x08);
+   /* enable DPI mode */
+   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p1_client,
+MIPI_DIGITAL_PLL_18, 0x1C);
+   /* set first edge */
+   ret |= anx7625_reg_write(ctx, ctx->i2c.tx_p2_client,
+VIDEO_CONTROL_0, 0x06);
+   if (ret < 0)
+   DRM_DEV_ERROR(dev, "IO error : dpi phy set failed.\n");
+
+   return ret;
+}
+
+static int anx7625_dpi_config(struct anx7625_data *ctx)
+{
+   struct device *dev = &ctx->client-

[PATCH v6 2/5] drm/bridge: anx7625: fix not correct return value

2021-03-18 Thread Xin Ji
At some time, the original code may return non zero value, force return 0
if operation finished.

Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index 65cc05982f82..04536cc7afe7 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -189,10 +189,10 @@ static int wait_aux_op_finish(struct anx7625_data *ctx)
   AP_AUX_CTRL_STATUS);
if (val < 0 || (val & 0x0F)) {
DRM_DEV_ERROR(dev, "aux status %02x\n", val);
-   val = -EIO;
+   return -EIO;
}
 
-   return val;
+   return 0;
 }
 
 static int anx7625_video_mute_control(struct anx7625_data *ctx,
-- 
2.25.1



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

2021-03-18 Thread qianli zhao
Hi,Eric

> As I understand it this patch has two purposes:
> 1. Avoid the BUG_ON in zap_pid_ns_processes when !CONFIG_PID_NS
> 2. panic as early as possible so exiting threads don't removing
>   interesting debugging state.

Your understanding is very correct,this is what my patch wants to do

> I think if we are going to move the decrement of signal->live that
> should be it's own patch and be accompanied with a good description of
> why it is safe instead of having the decrement of signal->live be there
> as a side effect of another change.

I will think about the risks of movement of the decrement of
signal->live before exit_signal().
If is difficult to judge movement of the decrement of signal->live is
safe,how about only test 'signal->live==1' not use group_dead?

Such as:
diff --git a/kernel/exit.c b/kernel/exit.c
index 04029e3..87f3595 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -767,6 +767,17 @@ void __noreturn do_exit(long code)
validate_creds_for_do_exit(tsk);

/*
+* If global init has exited,
+* panic immediately to get a useable coredump.
+*/
+   if (unlikely(is_global_init(tsk) &&
+   ((atomic_read(&tsk->signal->live) == 1) ||/*current is
last init thread*/
+(tsk->signal->flags & SIGNAL_GROUP_EXIT {
+   panic("Attempted to kill init! exitcode=0x%08x\n",
+   tsk->signal->group_exit_code ?: (int)code);
+   }
+
+   /*
 * We're taking recursive faults here in do_exit. Safest is to just
 * leave this task alone and wait for reboot.
 */
@@ -784,16 +795,9 @@ void __noreturn do_exit(long code)
if (tsk->mm)
sync_mm_rss(tsk->mm);
acct_update_integrals(tsk);
+
group_dead = atomic_dec_and_test(&tsk->signal->live);
if (group_dead) {
-   /*
-* If the last thread of global init has exited, panic
-* immediately to get a useable coredump.
-*/
-   if (unlikely(is_global_init(tsk)))
-   panic("Attempted to kill init! exitcode=0x%08x\n",
-   tsk->signal->group_exit_code ?: (int)code);
-

Eric W. Biederman  于2021年3月19日周五 上午3:09写道:
>
> Oleg Nesterov  writes:
>
> > 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?
>
> That is my understanding.
>
> As I understand it this patch has two purposes:
> 1. Avoid the BUG_ON in zap_pid_ns_processes when !CONFIG_PID_NS
> 2. panic as early as possible so exiting threads don't removing
>interesting debugging state.
>
>
> It is a bit tricky to tell if the movement of the decrement of
> signal->live is safe.  That affects current_is_single threaded
> which is used by unshare, setns of the time namespace, and setting
> the selinux part of creds.
>
> The usage in kernel/cgroup/cgroup.c:css_task_iter_advance seems safe.
> Hmm, Maybe not.  Today cgroup_thread_change_begin is held around
> setting PF_EXITING before signal->live is decremented.  So there seem to
> be some subtle cgroup dependencies.
>
> The usages of group_dead in do_exit seem safe, as except for the new
> one everything is the same.
>
> We could definitely take advantage of knowing group_dead in exit_signals
> to simplify it's optimization to not rerouting signals to living
> threads.
>
>
> I think if we are going to move the decrement of signal->live that
> should be it's own patch and be accompanied with a good desc

[PATCH v6 1/5] dt-bindings:drm/bridge:anx7625:add vendor define flags

2021-03-18 Thread Xin Ji
Add 'bus-type' and 'data-lanes' define for port0. Define DP tx lane0,
lane1 swing register array define, and audio enable flag.

Signed-off-by: Xin Ji 
---
 .../display/bridge/analogix,anx7625.yaml  | 58 ++-
 1 file changed, 57 insertions(+), 1 deletion(-)

diff --git 
a/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml 
b/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
index c789784efe30..3f54d5876982 100644
--- a/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
+++ b/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
@@ -34,6 +34,26 @@ properties:
 description: used for reset chip control, RESET_N pin B7.
 maxItems: 1
 
+  analogix,lane0-swing:
+$ref: /schemas/types.yaml#/definitions/uint32-array
+minItems: 1
+maxItems: 20
+description:
+  an array of swing register setting for DP tx lane0 PHY, please don't
+  add this property, or contact vendor.
+
+  analogix,lane1-swing:
+$ref: /schemas/types.yaml#/definitions/uint32-array
+minItems: 1
+maxItems: 20
+description:
+  an array of swing register setting for DP tx lane1 PHY, please don't
+  add this property, or contact vendor.
+
+  analogix,audio-enable:
+type: boolean
+description: let the driver enable audio HDMI codec function or not.
+
   ports:
 $ref: /schemas/graph.yaml#/properties/ports
 
@@ -41,13 +61,43 @@ properties:
   port@0:
 $ref: /schemas/graph.yaml#/properties/port
 description:
-  Video port for MIPI DSI input.
+  MIPI DSI/DPI input.
+
+properties:
+  endpoint:
+$ref: /schemas/media/video-interfaces.yaml#
+type: object
+additionalProperties: false
+
+properties:
+  remote-endpoint: true
+  bus-type: true
+  data-lanes: true
+
+required:
+  - remote-endpoint
+
+required:
+  - endpoint
+
 
   port@1:
 $ref: /schemas/graph.yaml#/properties/port
 description:
   Video port for panel or connector.
 
+properties:
+  endpoint:
+$ref: /schemas/media/video-interfaces.yaml#
+type: object
+additionalProperties: false
+
+properties:
+  remote-endpoint: true
+
+required:
+  - remote-endpoint
+
 required:
   - port@0
   - port@1
@@ -73,6 +123,10 @@ examples:
 enable-gpios = <&pio 45 GPIO_ACTIVE_HIGH>;
 reset-gpios = <&pio 73 GPIO_ACTIVE_HIGH>;
 
+analogix,audio-enable;
+analogix,lane0-swing = <0x14 0x54 0x64 0x74 0x29 0x7b 0x77 0x5b>;
+analogix,lane1-swing = <0x14 0x54 0x64 0x74 0x29 0x7b 0x77 0x5b>;
+
 ports {
 #address-cells = <1>;
 #size-cells = <0>;
@@ -81,6 +135,8 @@ examples:
 reg = <0>;
 anx7625_in: endpoint {
 remote-endpoint = <&mipi_dsi>;
+bus-type = <5>;
+data-lanes = <0 1 2 3>;
 };
 };
 
-- 
2.25.1



[PATCH v6 0/5] Add MIPI rx DPI support

2021-03-18 Thread Xin Ji
Hi all, this patch series implement MIPI rx DPI feature. Please help to review.

This is the v6 version, any mistakes, please let me know,
I'll fix it in the next series.

Change history:
v6: Fix kernel robot compile warning

v5: Fix Rob Herring, Hsin-Yi, Robert Foss comments
 - Rebase code on the branch 'drm-misc-next', refer video-interfaces.yaml
 - Seprate HDCP function to a new patch
 - Fix driver not correctly get 'bus-type' 'data-lanes'
 - Add audio HDMI codec function support

v4: Fix Rob Herring comment
 - Rebase code on the branch 'drm-misc-next'
 - Change 'analogix,hdcp-support' type to boolean

v3: Fix Rob Herring, Dan Carpenter, Nicolas comment
 - Split the patch, fix not correct return data
 - Fix several coding format
 - Split DP tx swing register setting to two property
 - Add HDCP support vender flag
 - remove 'analogix,swing-setting' and 'analogix,mipi-dpi-in' property

v2: Fix Rob Herring comment
 - Fix yamllint warnings/errors in analogix,anx7625.yaml
 - Fix kernel robot compile warning

v1: initial MIPI rx DPI feature support


Xin Ji (5):
  dt-bindings:drm/bridge:anx7625:add vendor define flags
  drm/bridge: anx7625: fix not correct return value
  drm/bridge: anx7625: add MIPI DPI input feature support
  drm/bridge: anx7625: add HDCP support
  drm/bridge: anx7625: add HDMI audio function

 .../display/bridge/analogix,anx7625.yaml  |  58 +-
 drivers/gpu/drm/bridge/analogix/anx7625.c | 603 --
 drivers/gpu/drm/bridge/analogix/anx7625.h |  59 +-
 3 files changed, 667 insertions(+), 53 deletions(-)

-- 
2.25.1



[PATCH v2 21/21] ipmi: kcs_bmc_aspeed: Optionally apply status address

2021-03-18 Thread Andrew Jeffery
Some Aspeed KCS devices can derive the status register address from the
address of the data register. As such, the address of the status
register can be implicit in the configuration if desired. On the other
hand, sometimes address schemes might be requested that are incompatible
with the default addressing scheme. Allow these requests where possible
if the devicetree specifies the status register address.

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

diff --git a/drivers/char/ipmi/kcs_bmc_aspeed.c 
b/drivers/char/ipmi/kcs_bmc_aspeed.c
index 7334b1f51dcc..98789b837690 100644
--- a/drivers/char/ipmi/kcs_bmc_aspeed.c
+++ b/drivers/char/ipmi/kcs_bmc_aspeed.c
@@ -83,6 +83,8 @@
 #define LPC_STR2 0x040
 #define LPC_STR3 0x044
 #define LPC_HICRB0x100
+#define LPC_HICRB_EN16LADR2  BIT(5)
+#define LPC_HICRB_EN16LADR1  BIT(4)
 #define LPC_HICRB_IBFIE4 BIT(1)
 #define LPC_HICRB_LPC4E  BIT(0)
 #define LPC_HICRC0x104
@@ -96,6 +98,11 @@
 #define LPC_IDR4 0x114
 #define LPC_ODR4 0x118
 #define LPC_STR4 0x11C
+#define LPC_LSADR12 0x120
+#define LPC_LSADR12_LSADR2_MASK  GENMASK(31, 16)
+#define LPC_LSADR12_LSADR2_SHIFT 16
+#define LPC_LSADR12_LSADR1_MASK  GENMASK(15, 0)
+#define LPC_LSADR12_LSADR1_SHIFT 0
 
 #define OBE_POLL_PERIOD (HZ / 2)
 
@@ -123,7 +130,7 @@ struct aspeed_kcs_bmc {
 
 struct aspeed_kcs_of_ops {
int (*get_channel)(struct platform_device *pdev);
-   int (*get_io_address)(struct platform_device *pdev);
+   int (*get_io_address)(struct platform_device *pdev, u32 addrs[2]);
 };
 
 static inline struct aspeed_kcs_bmc *to_aspeed_kcs_bmc(struct kcs_bmc_device 
*kcs_bmc)
@@ -217,38 +224,64 @@ static void aspeed_kcs_updateb(struct kcs_bmc_device 
*kcs_bmc, u32 reg, u8 mask,
  * C. KCS4
  *D / C : CA4h / CA5h
  */
-static void aspeed_kcs_set_address(struct kcs_bmc_device *kcs_bmc, u16 addr)
+static int aspeed_kcs_set_address(struct kcs_bmc_device *kcs_bmc, u32 
addrs[2], int nr_addrs)
 {
struct aspeed_kcs_bmc *priv = to_aspeed_kcs_bmc(kcs_bmc);
 
-   switch (kcs_bmc->channel) {
+   if (WARN_ON(nr_addrs < 1 || nr_addrs > 2))
+   return -EINVAL;
+
+   switch (priv->kcs_bmc.channel) {
case 1:
-   regmap_update_bits(priv->map, LPC_HICR4,
-   LPC_HICR4_LADR12AS, 0);
-   regmap_write(priv->map, LPC_LADR12H, addr >> 8);
-   regmap_write(priv->map, LPC_LADR12L, addr & 0xFF);
+   regmap_update_bits(priv->map, LPC_HICR4, LPC_HICR4_LADR12AS, 0);
+   regmap_write(priv->map, LPC_LADR12H, addrs[0] >> 8);
+   regmap_write(priv->map, LPC_LADR12L, addrs[0] & 0xFF);
+   if (nr_addrs == 2) {
+   regmap_update_bits(priv->map, LPC_LSADR12, 
LPC_LSADR12_LSADR1_MASK,
+  addrs[1] << 
LPC_LSADR12_LSADR1_SHIFT);
+
+   regmap_update_bits(priv->map, LPC_HICRB, 
LPC_HICRB_EN16LADR1,
+  LPC_HICRB_EN16LADR1);
+   }
break;
 
case 2:
-   regmap_update_bits(priv->map, LPC_HICR4,
-   LPC_HICR4_LADR12AS, LPC_HICR4_LADR12AS);
-   regmap_write(priv->map, LPC_LADR12H, addr >> 8);
-   regmap_write(priv->map, LPC_LADR12L, addr & 0xFF);
+   regmap_update_bits(priv->map, LPC_HICR4, LPC_HICR4_LADR12AS, 
LPC_HICR4_LADR12AS);
+   regmap_write(priv->map, LPC_LADR12H, addrs[0] >> 8);
+   regmap_write(priv->map, LPC_LADR12L, addrs[0] & 0xFF);
+   if (nr_addrs == 2) {
+   regmap_update_bits(priv->map, LPC_LSADR12, 
LPC_LSADR12_LSADR2_MASK,
+  addrs[1] << 
LPC_LSADR12_LSADR2_SHIFT);
+
+   regmap_update_bits(priv->map, LPC_HICRB, 
LPC_HICRB_EN16LADR2,
+  LPC_HICRB_EN16LADR2);
+   }
break;
 
case 3:
-   regmap_write(priv->map, LPC_LADR3H, addr >> 8);
-   regmap_write(priv->map, LPC_LADR3L, addr & 0xFF);
+   if (nr_addrs == 2) {
+   dev_err(priv->kcs_bmc.dev,
+   "Channel 3 only supports inferred status IO 
address\n");
+   return -EINVAL;
+   }
+
+   regmap_write(priv->map, LPC_LADR3H, addrs[0] >> 8);
+   regmap_write(priv->map, LPC_LADR3L, addrs[0] & 0xFF);
break;
 
case 4:
-   regmap_write(priv->map, LPC_LADR4, ((addr + 1) << 16) |
-   addr);
+   if (nr_addrs == 1)
+   regmap_wr

[PATCH v2 20/21] ipmi: kcs_bmc_aspeed: Fix IBFIE typo from datasheet

2021-03-18 Thread Andrew Jeffery
Input Buffer Full Interrupt Enable (IBFIE) is typoed as IBFIF for some
registers in the datasheet. Fix the driver to use the sensible acronym.

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

diff --git a/drivers/char/ipmi/kcs_bmc_aspeed.c 
b/drivers/char/ipmi/kcs_bmc_aspeed.c
index 3782aef4eb73..7334b1f51dcc 100644
--- a/drivers/char/ipmi/kcs_bmc_aspeed.c
+++ b/drivers/char/ipmi/kcs_bmc_aspeed.c
@@ -50,9 +50,9 @@
 #define LPC_HICR0_LPC2E  BIT(6)
 #define LPC_HICR0_LPC1E  BIT(5)
 #define LPC_HICR20x008
-#define LPC_HICR2_IBFIF3 BIT(3)
-#define LPC_HICR2_IBFIF2 BIT(2)
-#define LPC_HICR2_IBFIF1 BIT(1)
+#define LPC_HICR2_IBFIE3 BIT(3)
+#define LPC_HICR2_IBFIE2 BIT(2)
+#define LPC_HICR2_IBFIE1 BIT(1)
 #define LPC_HICR40x010
 #define LPC_HICR4_LADR12AS   BIT(7)
 #define LPC_HICR4_KCSENBLBIT(2)
@@ -83,7 +83,7 @@
 #define LPC_STR2 0x040
 #define LPC_STR3 0x044
 #define LPC_HICRB0x100
-#define LPC_HICRB_IBFIF4 BIT(1)
+#define LPC_HICRB_IBFIE4 BIT(1)
 #define LPC_HICRB_LPC4E  BIT(0)
 #define LPC_HICRC0x104
 #define LPC_HICRC_ID4IRQX_MASK   GENMASK(7, 4)
@@ -383,20 +383,20 @@ static void aspeed_kcs_irq_mask_update(struct 
kcs_bmc_device *kcs_bmc, u8 mask,
 
switch (kcs_bmc->channel) {
case 1:
-   regmap_update_bits(priv->map, LPC_HICR2, 
LPC_HICR2_IBFIF1,
-  enable * LPC_HICR2_IBFIF1);
+   regmap_update_bits(priv->map, LPC_HICR2, 
LPC_HICR2_IBFIE1,
+  enable * LPC_HICR2_IBFIE1);
return;
case 2:
-   regmap_update_bits(priv->map, LPC_HICR2, 
LPC_HICR2_IBFIF2,
-  enable * LPC_HICR2_IBFIF2);
+   regmap_update_bits(priv->map, LPC_HICR2, 
LPC_HICR2_IBFIE2,
+  enable * LPC_HICR2_IBFIE2);
return;
case 3:
-   regmap_update_bits(priv->map, LPC_HICR2, 
LPC_HICR2_IBFIF3,
-  enable * LPC_HICR2_IBFIF3);
+   regmap_update_bits(priv->map, LPC_HICR2, 
LPC_HICR2_IBFIE3,
+  enable * LPC_HICR2_IBFIE3);
return;
case 4:
-   regmap_update_bits(priv->map, LPC_HICRB, 
LPC_HICRB_IBFIF4,
-  enable * LPC_HICRB_IBFIF4);
+   regmap_update_bits(priv->map, LPC_HICRB, 
LPC_HICRB_IBFIE4,
+  enable * LPC_HICRB_IBFIE4);
return;
default:
pr_warn("%s: Unsupported channel: %d", __func__, 
kcs_bmc->channel);
-- 
2.27.0



[PATCH v2 19/21] ipmi: kcs_bmc_aspeed: Implement KCS SerIRQ configuration

2021-03-18 Thread Andrew Jeffery
Apply the SerIRQ ID and level/sense behaviours from the devicetree if
provided.

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

diff --git a/drivers/char/ipmi/kcs_bmc_aspeed.c 
b/drivers/char/ipmi/kcs_bmc_aspeed.c
index 271845eb2e26..3782aef4eb73 100644
--- a/drivers/char/ipmi/kcs_bmc_aspeed.c
+++ b/drivers/char/ipmi/kcs_bmc_aspeed.c
@@ -9,6 +9,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -28,6 +29,22 @@
 
 #define KCS_CHANNEL_MAX 4
 
+/*
+ * Field class descriptions
+ *
+ * LPCyE   Enable LPC channel y
+ * IBFIEy  Input Buffer Full IRQ Enable for LPC channel y
+ * IRQxEy  Assert SerIRQ x for LPC channel y (Deprecated, use IDyIRQX, 
IRQXEy)
+ * IDyIRQX Use the specified 4-bit SerIRQ for LPC channel y
+ * SELyIRQXSerIRQ polarity for LPC channel y (low: 0, high: 1)
+ * IRQXEy  Assert the SerIRQ specified in IDyIRQX for LPC channel y
+ */
+
+#define LPC_TYIRQX_LOW   0b00
+#define LPC_TYIRQX_HIGH  0b01
+#define LPC_TYIRQX_RSVD  0b10
+#define LPC_TYIRQX_RISING0b11
+
 #define LPC_HICR00x000
 #define LPC_HICR0_LPC3E  BIT(7)
 #define LPC_HICR0_LPC2E  BIT(6)
@@ -39,6 +56,19 @@
 #define LPC_HICR40x010
 #define LPC_HICR4_LADR12AS   BIT(7)
 #define LPC_HICR4_KCSENBLBIT(2)
+#define LPC_SIRQCR0 0x070
+/* IRQ{12,1}E1 are deprecated as of AST2600 A3 but necessary for prior chips */
+#define LPC_SIRQCR0_IRQ12E1 BIT(1)
+#define LPC_SIRQCR0_IRQ1E1  BIT(0)
+#define LPC_HICR5   0x080
+#define LPC_HICR5_ID3IRQX_MASK   GENMASK(23, 20)
+#define LPC_HICR5_ID3IRQX_SHIFT  20
+#define LPC_HICR5_ID2IRQX_MASK   GENMASK(19, 16)
+#define LPC_HICR5_ID2IRQX_SHIFT  16
+#define LPC_HICR5_SEL3IRQX   BIT(15)
+#define LPC_HICR5_IRQXE3 BIT(14)
+#define LPC_HICR5_SEL2IRQX   BIT(13)
+#define LPC_HICR5_IRQXE2 BIT(12)
 #define LPC_LADR3H   0x014
 #define LPC_LADR3L   0x018
 #define LPC_LADR12H  0x01C
@@ -55,6 +85,13 @@
 #define LPC_HICRB0x100
 #define LPC_HICRB_IBFIF4 BIT(1)
 #define LPC_HICRB_LPC4E  BIT(0)
+#define LPC_HICRC0x104
+#define LPC_HICRC_ID4IRQX_MASK   GENMASK(7, 4)
+#define LPC_HICRC_ID4IRQX_SHIFT  4
+#define LPC_HICRC_TY4IRQX_MASK   GENMASK(3, 2)
+#define LPC_HICRC_TY4IRQX_SHIFT  2
+#define LPC_HICRC_OBF4_AUTO_CLR  BIT(1)
+#define LPC_HICRC_IRQXE4 BIT(0)
 #define LPC_LADR40x110
 #define LPC_IDR4 0x114
 #define LPC_ODR4 0x118
@@ -62,11 +99,21 @@
 
 #define OBE_POLL_PERIOD (HZ / 2)
 
+enum aspeed_kcs_irq_mode {
+   aspeed_kcs_irq_none,
+   aspeed_kcs_irq_serirq,
+};
+
 struct aspeed_kcs_bmc {
struct kcs_bmc_device kcs_bmc;
 
struct regmap *map;
 
+   struct {
+   enum aspeed_kcs_irq_mode mode;
+   int id;
+   } upstream_irq;
+
struct {
spinlock_t lock;
bool remove;
@@ -103,6 +150,49 @@ static void aspeed_kcs_outb(struct kcs_bmc_device 
*kcs_bmc, u32 reg, u8 data)
 
rc = regmap_write(priv->map, reg, data);
WARN(rc != 0, "regmap_write() failed: %d\n", rc);
+
+   /* Trigger the upstream IRQ on ODR writes, if enabled */
+
+   switch (reg) {
+   case LPC_ODR1:
+   case LPC_ODR2:
+   case LPC_ODR3:
+   case LPC_ODR4:
+   break;
+   default:
+   return;
+   }
+
+   if (priv->upstream_irq.mode != aspeed_kcs_irq_serirq)
+   return;
+
+   switch (kcs_bmc->channel) {
+   case 1:
+   switch (priv->upstream_irq.id) {
+   case 12:
+   regmap_update_bits(priv->map, LPC_SIRQCR0, 
LPC_SIRQCR0_IRQ12E1,
+  LPC_SIRQCR0_IRQ12E1);
+   break;
+   case 1:
+   regmap_update_bits(priv->map, LPC_SIRQCR0, 
LPC_SIRQCR0_IRQ1E1,
+  LPC_SIRQCR0_IRQ1E1);
+   break;
+   default:
+   break;
+   }
+   break;
+   case 2:
+   regmap_update_bits(priv->map, LPC_HICR5, LPC_HICR5_IRQXE2, 
LPC_HICR5_IRQXE2);
+   break;
+   case 3:
+   regmap_update_bits(priv->map, LPC_HICR5, LPC_HICR5_IRQXE3, 
LPC_HICR5_IRQXE3);
+   break;
+   case 4:
+   regmap_update_bits(priv->map, LPC_HICRC, LPC_HICRC_IRQXE4, 
LPC_HICRC_IRQXE4);
+   break;
+   default:
+   break;
+   }
 }
 
 static void aspeed_kcs_updateb(struct kcs_bmc_device *kcs_bmc, u32 reg, u8 
mask, u8 val)
@@ -161,6 +251,73 @@ static void aspeed_kcs_set_address(struct kcs_bmc_device 
*kcs_bmc, u1

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

2021-03-18 Thread Jie Deng



On 2021/3/19 13:40, Viresh Kumar wrote:

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.
I also see example drivers/i2c/busses/i2c-xiic.c. Some people might 
think this way is more clearer than


updating each member in probe. Basically, I think it's just a matter of 
personal preference which doesn't


solve any problems.




[PATCH v2 17/21] dt-bindings: ipmi: Convert ASPEED KCS binding to schema

2021-03-18 Thread Andrew Jeffery
Given the deprecated binding, improve the ability to detect issues in
the platform devicetrees. Further, a subsequent patch will introduce a
new interrupts property for specifying SerIRQ behaviour, so convert
before we do any further additions.

Signed-off-by: Andrew Jeffery 
---
 .../bindings/ipmi/aspeed,ast2400-kcs-bmc.yaml | 92 +++
 .../bindings/ipmi/aspeed-kcs-bmc.txt  | 33 ---
 2 files changed, 92 insertions(+), 33 deletions(-)
 create mode 100644 
Documentation/devicetree/bindings/ipmi/aspeed,ast2400-kcs-bmc.yaml
 delete mode 100644 Documentation/devicetree/bindings/ipmi/aspeed-kcs-bmc.txt

diff --git a/Documentation/devicetree/bindings/ipmi/aspeed,ast2400-kcs-bmc.yaml 
b/Documentation/devicetree/bindings/ipmi/aspeed,ast2400-kcs-bmc.yaml
new file mode 100644
index ..697ca575454f
--- /dev/null
+++ b/Documentation/devicetree/bindings/ipmi/aspeed,ast2400-kcs-bmc.yaml
@@ -0,0 +1,92 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/ipmi/aspeed,ast2400-kcs-bmc.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: ASPEED BMC KCS Devices
+
+maintainers:
+  - Andrew Jeffery 
+
+description: |
+  The Aspeed BMC SoCs typically use the Keyboard-Controller-Style (KCS)
+  interfaces on the LPC bus for in-band IPMI communication with their host.
+
+properties:
+  compatible:
+oneOf:
+  - description: Channel ID derived from reg
+items:
+  enum:
+- aspeed,ast2400-kcs-bmc-v2
+- aspeed,ast2500-kcs-bmc-v2
+- aspeed,ast2600-kcs-bmc
+
+  - description: Old-style with explicit channel ID, no reg
+deprecated: true
+items:
+  enum:
+- aspeed,ast2400-kcs-bmc
+- aspeed,ast2500-kcs-bmc
+
+  interrupts:
+maxItems: 1
+
+  reg:
+# maxItems: 3
+items:
+  - description: IDR register
+  - description: ODR register
+  - description: STR register
+
+  aspeed,lpc-io-reg:
+$ref: '/schemas/types.yaml#/definitions/uint32-array'
+minItems: 1
+maxItems: 2
+description: |
+  The host CPU LPC IO data and status addresses for the device. For most
+  channels the status address is derived from the data address, but the
+  status address may be optionally provided.
+
+  kcs_chan:
+deprecated: true
+$ref: '/schemas/types.yaml#/definitions/uint32'
+description: The LPC channel number in the controller
+
+  kcs_addr:
+deprecated: true
+$ref: '/schemas/types.yaml#/definitions/uint32'
+description: The host CPU IO map address
+
+required:
+  - compatible
+  - interrupts
+
+additionalProperties: false
+
+allOf:
+  - if:
+  properties:
+compatible:
+  contains:
+enum:
+  - aspeed,ast2400-kcs-bmc
+  - aspeed,ast2500-kcs-bmc
+then:
+  required:
+- kcs_chan
+- kcs_addr
+else:
+  required:
+- reg
+- aspeed,lpc-io-reg
+
+examples:
+  - |
+kcs3: kcs@24 {
+compatible = "aspeed,ast2600-kcs-bmc";
+reg = <0x24 0x1>, <0x30 0x1>, <0x3c 0x1>;
+aspeed,lpc-io-reg = <0xca2>;
+interrupts = <8>;
+};
diff --git a/Documentation/devicetree/bindings/ipmi/aspeed-kcs-bmc.txt 
b/Documentation/devicetree/bindings/ipmi/aspeed-kcs-bmc.txt
deleted file mode 100644
index 193e71ca96b0..
--- a/Documentation/devicetree/bindings/ipmi/aspeed-kcs-bmc.txt
+++ /dev/null
@@ -1,33 +0,0 @@
-# Aspeed KCS (Keyboard Controller Style) IPMI interface
-
-The Aspeed SOCs (AST2400 and AST2500) are commonly used as BMCs
-(Baseboard Management Controllers) and the KCS interface can be
-used to perform in-band IPMI communication with their host.
-
-## v1
-Required properties:
-- compatible : should be one of
-"aspeed,ast2400-kcs-bmc"
-"aspeed,ast2500-kcs-bmc"
-- interrupts : interrupt generated by the controller
-- kcs_chan : The LPC channel number in the controller
-- kcs_addr : The host CPU IO map address
-
-## v2
-Required properties:
-- compatible : should be one of
-"aspeed,ast2400-kcs-bmc-v2"
-"aspeed,ast2500-kcs-bmc-v2"
-- reg : The address and size of the IDR, ODR and STR registers
-- interrupts : interrupt generated by the controller
-- aspeed,lpc-io-reg : The host CPU LPC IO address for the device
-
-Example:
-
-kcs3: kcs@24 {
-compatible = "aspeed,ast2500-kcs-bmc-v2";
-reg = <0x24 0x1>, <0x30 0x1>, <0x3c 0x1>;
-aspeed,lpc-reg = <0xca2>;
-interrupts = <8>;
-status = "okay";
-};
-- 
2.27.0



[PATCH v2 18/21] dt-bindings: ipmi: Add optional SerIRQ property to ASPEED KCS devices

2021-03-18 Thread Andrew Jeffery
Allocating IO and IRQ resources to LPC devices is in-theory an operation
for the host, however ASPEED don't appear to expose this capability
outside the BMC (e.g. SuperIO). Instead, we are left with BMC-internal
registers for managing these resources, so introduce a devicetree
property for KCS devices to describe SerIRQ properties.

Signed-off-by: Andrew Jeffery 
---
 .../bindings/ipmi/aspeed,ast2400-kcs-bmc.yaml  | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/Documentation/devicetree/bindings/ipmi/aspeed,ast2400-kcs-bmc.yaml 
b/Documentation/devicetree/bindings/ipmi/aspeed,ast2400-kcs-bmc.yaml
index 697ca575454f..4ff6fabfcb30 100644
--- a/Documentation/devicetree/bindings/ipmi/aspeed,ast2400-kcs-bmc.yaml
+++ b/Documentation/devicetree/bindings/ipmi/aspeed,ast2400-kcs-bmc.yaml
@@ -49,6 +49,18 @@ properties:
   channels the status address is derived from the data address, but the
   status address may be optionally provided.
 
+  aspeed,lpc-interrupts:
+$ref: "/schemas/types.yaml#/definitions/uint32-array"
+minItems: 2
+maxItems: 2
+description: |
+  A 2-cell property expressing the LPC SerIRQ number and the interrupt
+  level/sense encoding (specified in the standard fashion).
+
+  Note that the generated interrupt is issued from the BMC to the host, and
+  thus the target interrupt controller is not captured by the BMC's
+  devicetree.
+
   kcs_chan:
 deprecated: true
 $ref: '/schemas/types.yaml#/definitions/uint32'
@@ -84,9 +96,11 @@ allOf:
 
 examples:
   - |
+#include 
 kcs3: kcs@24 {
 compatible = "aspeed,ast2600-kcs-bmc";
 reg = <0x24 0x1>, <0x30 0x1>, <0x3c 0x1>;
 aspeed,lpc-io-reg = <0xca2>;
+aspeed,lpc-interrupts = <11 IRQ_TYPE_LEVEL_LOW>;
 interrupts = <8>;
 };
-- 
2.27.0



[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



[PATCH v2 16/21] ipmi: kcs_bmc: Add a "raw" character device interface

2021-03-18 Thread Andrew Jeffery
The existing IPMI chardev encodes IPMI behaviours as the name suggests.
However, KCS devices are useful beyond IPMI (or keyboards), as they
provide a means to generate IRQs and exchange arbitrary data between a
BMC and its host system.

Implement a "raw" KCS character device that exposes the IDR, ODR and STR
registers to userspace via read() and write() implemented on a character
device:

+++-+
| Offset | read() | write() |
+++-+
|   0|   IDR  |   ODR   |
+++-+
|   1|   STR  |   STR   |
+++-+

This interface allows userspace to implement arbitrary (though somewhat
inefficient) protocols for exchanging information between a BMC and host
firmware. Conceptually the KCS interface can be used as an out-of-band
machanism for interrupt-signaled control messages while bulk data
transfers occur over more appropriate interfaces between the BMC and the
host (which may lack their own interrupt mechanism, e.g. LPC FW cycles).

poll() is provided, which will wait for IBF or OBE conditions for data
reads and writes respectively. Reads of STR on its own never blocks,
though accessing both offsets in the one system call may block if the
data registers are not ready.

Signed-off-by: Andrew Jeffery 
---
 Documentation/ABI/testing/dev-raw-kcs |  25 ++
 drivers/char/ipmi/Kconfig |  17 +
 drivers/char/ipmi/Makefile|   1 +
 drivers/char/ipmi/kcs_bmc_cdev_raw.c  | 443 ++
 4 files changed, 486 insertions(+)
 create mode 100644 Documentation/ABI/testing/dev-raw-kcs
 create mode 100644 drivers/char/ipmi/kcs_bmc_cdev_raw.c

diff --git a/Documentation/ABI/testing/dev-raw-kcs 
b/Documentation/ABI/testing/dev-raw-kcs
new file mode 100644
index ..06e7e2071562
--- /dev/null
+++ b/Documentation/ABI/testing/dev-raw-kcs
@@ -0,0 +1,25 @@
+What:  /dev/raw-kcs*
+Date:  2021-02-15
+KernelVersion: 5.13
+Contact:   open...@lists.ozlabs.org
+Contact:   openipmi-develo...@lists.sourceforge.net
+Contact:   Andrew Jeffery 
+Description:   ``/dev/raw-kcs*`` exposes to userspace the data and
+   status registers of Keyboard-Controller-Style (KCS) IPMI
+   interfaces via read() and write() syscalls. Direct
+   exposure of the data and status registers enables
+   inefficient but arbitrary protocols to be implemented
+   over the device. A typical approach is to use KCS
+   devices for out-of-band signalling for bulk data
+   transfers over other interfaces between a Baseboard
+   Management Controller and its host.
+
+   +++-+
+   | Offset | read() | write() |
+   +++-+
+   |   0|   IDR  |   ODR   |
+   +++-+
+   |   1|   STR  |   STR   |
+   +++-+
+
+Users: libmctp: https://github.com/openbmc/libmctp
diff --git a/drivers/char/ipmi/Kconfig b/drivers/char/ipmi/Kconfig
index bc5f81899b62..273ac1a1f870 100644
--- a/drivers/char/ipmi/Kconfig
+++ b/drivers/char/ipmi/Kconfig
@@ -137,6 +137,23 @@ config IPMI_KCS_BMC_CDEV_IPMI
  This support is also available as a module. The module will be
  called kcs_bmc_cdev_ipmi.
 
+config IPMI_KCS_BMC_CDEV_RAW
+   depends on IPMI_KCS_BMC
+   tristate "Raw character device interface for BMC KCS devices"
+   help
+ Provides a BMC-side character device directly exposing the
+ data and status registers of a KCS device to userspace. While
+ KCS devices are commonly used to implement IPMI message
+ passing, they provide a general interface for exchange of
+ interrupts, data and status information between the BMC and
+ its host.
+
+ Say YES if you wish to use the KCS devices to implement
+ protocols that are not IPMI.
+
+ This support is also available as a module. The module will be
+ called kcs_bmc_cdev_raw.
+
 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 fcfa676afddb..c8cc248ddd90 100644
--- a/drivers/char/ipmi/Makefile
+++ b/drivers/char/ipmi/Makefile
@@ -24,6 +24,7 @@ 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_CDEV_IPMI) += kcs_bmc_cdev_ipmi.o
+obj-$(CONFIG_IPMI_KCS_BMC_CDEV_RAW) += kcs_bmc_cdev_raw.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_cdev_raw.c 
b/drivers/char/ipmi/kcs_bmc_cdev_raw.c
new file mode 100644
index 

[PATCH v2 14/21] ipmi: kcs_bmc: Allow clients to control KCS IRQ state

2021-03-18 Thread Andrew Jeffery
Add a mechanism for controlling whether the client associated with a
KCS device will receive Input Buffer Full (IBF) and Output Buffer Empty
(OBE) events. This enables an abstract implementation of poll() for KCS
devices.

A wart in the implementation is that the ASPEED KCS devices don't
support an OBE interrupt for the BMC. Instead we pretend it has one by
polling the status register waiting for the Output Buffer Full (OBF) bit
to clear, and generating an event when OBE is observed.

Signed-off-by: Andrew Jeffery 
---
 drivers/char/ipmi/kcs_bmc.c |   6 ++
 drivers/char/ipmi/kcs_bmc.h |   3 +
 drivers/char/ipmi/kcs_bmc_aspeed.c  | 150 ++--
 drivers/char/ipmi/kcs_bmc_client.h  |   2 +
 drivers/char/ipmi/kcs_bmc_device.h  |   1 +
 drivers/char/ipmi/kcs_bmc_npcm7xx.c |  25 -
 6 files changed, 130 insertions(+), 57 deletions(-)

diff --git a/drivers/char/ipmi/kcs_bmc.c b/drivers/char/ipmi/kcs_bmc.c
index 694db6ee2a92..05bbb72418b2 100644
--- a/drivers/char/ipmi/kcs_bmc.c
+++ b/drivers/char/ipmi/kcs_bmc.c
@@ -184,6 +184,12 @@ int kcs_bmc_unregister_cdev(struct kcs_bmc_cdev *cdev)
 }
 EXPORT_SYMBOL(kcs_bmc_unregister_cdev);
 
+void kcs_bmc_update_event_mask(struct kcs_bmc_device *kcs_bmc, u8 mask, u8 
events)
+{
+   kcs_bmc->ops->irq_mask_update(kcs_bmc, mask, events);
+}
+EXPORT_SYMBOL(kcs_bmc_update_event_mask);
+
 MODULE_LICENSE("GPL v2");
 MODULE_AUTHOR("Haiyue Wang ");
 MODULE_AUTHOR("Andrew Jeffery ");
diff --git a/drivers/char/ipmi/kcs_bmc.h b/drivers/char/ipmi/kcs_bmc.h
index 5deb9a0b8e60..11fff935218c 100644
--- a/drivers/char/ipmi/kcs_bmc.h
+++ b/drivers/char/ipmi/kcs_bmc.h
@@ -11,6 +11,9 @@
 #define KCS_BMC_EVENT_NONE 0
 #define KCS_BMC_EVENT_HANDLED  1
 
+#define KCS_BMC_EVENT_TYPE_OBE BIT(0)
+#define KCS_BMC_EVENT_TYPE_IBF BIT(1)
+
 #define KCS_BMC_STR_OBFBIT(0)
 #define KCS_BMC_STR_IBFBIT(1)
 #define KCS_BMC_STR_CMD_DATBIT(3)
diff --git a/drivers/char/ipmi/kcs_bmc_aspeed.c 
b/drivers/char/ipmi/kcs_bmc_aspeed.c
index 6f26e7366c0b..5f26471c038c 100644
--- a/drivers/char/ipmi/kcs_bmc_aspeed.c
+++ b/drivers/char/ipmi/kcs_bmc_aspeed.c
@@ -60,10 +60,18 @@
 #define LPC_ODR4 0x118
 #define LPC_STR4 0x11C
 
+#define OBE_POLL_PERIOD (HZ / 2)
+
 struct aspeed_kcs_bmc {
struct kcs_bmc_device kcs_bmc;
 
struct regmap *map;
+
+   struct {
+   spinlock_t lock;
+   bool remove;
+   struct timer_list timer;
+   } obe;
 };
 
 struct aspeed_kcs_of_ops {
@@ -159,68 +167,89 @@ static void aspeed_kcs_enable_channel(struct 
kcs_bmc_device *kcs_bmc, bool enabl
 
switch (kcs_bmc->channel) {
case 1:
-   if (enable) {
-   regmap_update_bits(priv->map, LPC_HICR2,
-   LPC_HICR2_IBFIF1, LPC_HICR2_IBFIF1);
-   regmap_update_bits(priv->map, LPC_HICR0,
-   LPC_HICR0_LPC1E, LPC_HICR0_LPC1E);
-   } else {
-   regmap_update_bits(priv->map, LPC_HICR0,
-   LPC_HICR0_LPC1E, 0);
-   regmap_update_bits(priv->map, LPC_HICR2,
-   LPC_HICR2_IBFIF1, 0);
-   }
-   break;
-
+   regmap_update_bits(priv->map, LPC_HICR0, LPC_HICR0_LPC1E, 
enable * LPC_HICR0_LPC1E);
+   return;
case 2:
-   if (enable) {
-   regmap_update_bits(priv->map, LPC_HICR2,
-   LPC_HICR2_IBFIF2, LPC_HICR2_IBFIF2);
-   regmap_update_bits(priv->map, LPC_HICR0,
-   LPC_HICR0_LPC2E, LPC_HICR0_LPC2E);
-   } else {
-   regmap_update_bits(priv->map, LPC_HICR0,
-   LPC_HICR0_LPC2E, 0);
-   regmap_update_bits(priv->map, LPC_HICR2,
-   LPC_HICR2_IBFIF2, 0);
-   }
-   break;
-
+   regmap_update_bits(priv->map, LPC_HICR0, LPC_HICR0_LPC2E, 
enable * LPC_HICR0_LPC2E);
+   return;
case 3:
-   if (enable) {
-   regmap_update_bits(priv->map, LPC_HICR2,
-   LPC_HICR2_IBFIF3, LPC_HICR2_IBFIF3);
-   regmap_update_bits(priv->map, LPC_HICR0,
-   LPC_HICR0_LPC3E, LPC_HICR0_LPC3E);
-   regmap_update_bits(priv->map, LPC_HICR4,
-   LPC_HICR4_KCSENBL, LPC_HICR4_KCSENBL);
-   } else {
-   regmap_update_bits(priv->map, LPC_HICR0,
-   LPC_HICR0_LPC3E, 0);
-   regmap_update_bits(priv->map, LPC_HICR4,
-   LPC_HICR4_

[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 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] 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 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 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 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

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



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 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


[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 

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 -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



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 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, 

[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 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 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



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] 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



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


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


[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



[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 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 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



[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 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



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


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 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 
> 





[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)) {
 

[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] 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



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


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: [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] 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: [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 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: [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.




[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 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



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 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
>


[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



[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] 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 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



  1   2   3   4   5   6   7   8   9   10   >