Need help converting usb/faraday,fotg210.yaml to yaml

2021-04-16 Thread Corentin Labbe
Hello

I am converting Documentation/devicetree/bindings/usb/faraday,fotg210.txt to 
yaml with the patch attached below.
But validating it give me:
Documentation/devicetree/bindings/usb/faraday,fotg210.example.dt.yaml: 
usb@6800: 'syscon', 'wakeup-source' do not match any of the regexes: 
'pinctrl-[0-9]+'

I dont know from where came this pinctrl regex.
I think this is perhaps due to the if not matched, but still didnt find any 
solution.

Thanks

--- a/Documentation/devicetree/bindings/usb/faraday,fotg210.txt
+++ /dev/null
@@ -1,35 +0,0 @@
-Faraday FOTG Host controller
-
-This OTG-capable USB host controller is found in Cortina Systems
-Gemini and other SoC products.
-
-Required properties:
-- compatible: should be one of:
-  "faraday,fotg210"
-  "cortina,gemini-usb", "faraday,fotg210"
-- reg: should contain one register range i.e. start and length
-- interrupts: description of the interrupt line
-
-Optional properties:
-- clocks: should contain the IP block clock
-- clock-names: should be "PCLK" for the IP block clock
-
-Required properties for "cortina,gemini-usb" compatible:
-- syscon: a phandle to the system controller to access PHY registers
-
-Optional properties for "cortina,gemini-usb" compatible:
-- cortina,gemini-mini-b: boolean property that indicates that a Mini-B
-  OTG connector is in use
-- wakeup-source: see power/wakeup-source.txt
-
-Example for Gemini:
-
-usb@6800 {
-   compatible = "cortina,gemini-usb", "faraday,fotg210";
-   reg = <0x6800 0x1000>;
-   interrupts = <10 IRQ_TYPE_LEVEL_HIGH>;
-   clocks = < 12>;
-   clock-names = "PCLK";
-   syscon = <>;
-   wakeup-source;
-};
diff --git a/Documentation/devicetree/bindings/usb/faraday,fotg210.yaml 
b/Documentation/devicetree/bindings/usb/faraday,fotg210.yaml
new file mode 100644
index ..b5418f29745e
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/faraday,fotg210.yaml
@@ -0,0 +1,78 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/usb/faraday,fotg210.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Faraday FOTG Host controller
+
+maintainers:
+  - Linus Walleij 
+
+description: |
+This OTG-capable USB host controller is found in Cortina Systems
+Gemini and other SoC products.
+
+properties:
+  compatible:
+oneOf:
+  - const: faraday,fotg210
+  - items:
+- const: cortina,gemini-usb
+- const: faraday,fotg210
+
+  reg:
+maxItems: 1
+
+  interrupts:
+maxItems: 1
+
+  clocks:
+maxItems: 1
+
+  clock-names:
+const: PCLK
+
+  resets:
+maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - interrupts
+
+if:
+  properties:
+compatible:
+  contains:
+const: cortina,gemini-usb
+then:
+  properties:
+syscon:
+  maxItems: 1
+  $ref: /schemas/types.yaml#/definitions/phandle
+  description: Phandle to the system controller to access PHY registers
+cortina,gemini-mini-b:
+  type: boolean
+  description: boolean property that indicates that a Mini-B OTG connector 
is in use
+wakeup-source:
+  type: boolean
+  description: see power/wakeup-source.txt
+  required:
+- syscon
+
+additionalProperties: false
+
+examples:
+  - |
+#include 
+usb@6800 {
+  compatible = "cortina,gemini-usb", "faraday,fotg210";
+  reg = <0x6800 0x1000>;
+  interrupts = <10 IRQ_TYPE_LEVEL_HIGH>;
+  clocks = < 12>;
+  clock-names = "PCLK";
+  syscon = <>;
+  wakeup-source;
+};
+...



[PATCH] MAINTAINERS: gemini: add missing dts pattern

2021-04-16 Thread Corentin Labbe
The MAINTAINERS entry for cortina/gemini miss all dts of this platform.

Signed-off-by: Corentin Labbe 
---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index f64a75945b06..927fa29f05ed 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1816,6 +1816,7 @@ F:Documentation/devicetree/bindings/arm/gemini.txt
 F: Documentation/devicetree/bindings/net/cortina,gemini-ethernet.txt
 F: Documentation/devicetree/bindings/pinctrl/cortina,gemini-pinctrl.txt
 F: Documentation/devicetree/bindings/rtc/faraday,ftrtc010.txt
+F: arch/arm/boot/dts/gemini*
 F: arch/arm/mach-gemini/
 F: drivers/net/ethernet/cortina/
 F: drivers/pinctrl/pinctrl-gemini.c
-- 
2.26.3



Re: crashkernel reservation failed - No suitable area found on a cortina/gemini SoC

2021-04-09 Thread Corentin Labbe
Le Fri, Apr 09, 2021 at 04:53:13PM +0200, Corentin Labbe a écrit :
> Le Wed, Apr 07, 2021 at 07:59:27AM -0700, Bruce Mitchell a écrit :
> > On 4/7/2021 07:48, Corentin Labbe wrote:
> > > Le Wed, Apr 07, 2021 at 07:28:26AM -0700, Bruce Mitchell a écrit :
> > >> On 4/7/2021 07:23, Corentin Labbe wrote:
> > >>> Le Wed, Apr 07, 2021 at 07:13:04AM -0700, Bruce Mitchell a écrit :
> > >>>> On 4/7/2021 05:54, Corentin Labbe wrote:
> > >>>>> Hello
> > >>>>>
> > >>>>> I try to do kexec on a cortina/gemini SoC.
> > >>>>> On a "normal" boot, kexec fail to find memory so I added 
> > >>>>> crashkernel=8M to cmdline. (kernel size is ~6M).
> > >>>>> But now, kernel fail to reserve memory:
> > >>>>> Load Kern image from 0x3002 to 0x80 size 7340032
> > >>>>> Booting Linux on physical CPU 0x0
> > >>>>> Linux version 5.12.0-rc5-next-20210401+ (compile@Red) 
> > >>>>> (armv7a-unknown-linux-gnueabihf-gcc (Gentoo 9.3.0-r2 p4) 9.3.0, GNU 
> > >>>>> ld (Gentoo 2.34 p6) 2.34.0) #98 PREEMPT Wed Apr 7 14:14:08 CEST 2021
> > >>>>> CPU: FA526 [66015261] revision 1 (ARMv4), cr=397f
> > >>>>> CPU: VIVT data cache, VIVT instruction cache
> > >>>>> OF: fdt: Machine model: Edimax NS-2502
> > >>>>> Memory policy: Data cache writeback
> > >>>>> Zone ranges:
> > >>>>>  Normal   [mem 0x-0x07ff]
> > >>>>>  HighMem  empty
> > >>>>> Movable zone start for each node
> > >>>>> Early memory node ranges
> > >>>>>  node   0: [mem 0x-0x07ff]
> > >>>>> Initmem setup node 0 [mem 0x-0x07ff]
> > >>>>> crashkernel reservation failed - No suitable area found.
> > >>>>> Built 1 zonelists, mobility grouping on.  Total pages: 32512
> > >>>>> Kernel command line: console=ttyS0,19200n8 ip=dhcp crashkernel=8M
> > >>>>> Dentry cache hash table entries: 16384 (order: 4, 65536 bytes, linear)
> > >>>>> Inode-cache hash table entries: 8192 (order: 3, 32768 bytes, linear)
> > >>>>> mem auto-init: stack:off, heap alloc:off, heap free:off
> > >>>>> Memory: 119476K/131072K available (5034K kernel code, 579K rwdata, 
> > >>>>> 1372K rodata, 3020K init, 210K bss, 11596K reserved, 0K cma-reserved, 
> > >>>>> 0K highmem)
> > >>>>> SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
> > >>>>>
> > >>>>> What can I do ?
> > >>>>>
> > >>>>> Thanks
> > >>>>> Regards
> > >>>>>
> > >>>>> ___
> > >>>>> kexec mailing list
> > >>>>> ke...@lists.infradead.org
> > >>>>> http://lists.infradead.org/mailman/listinfo/kexec
> > >>>>>
> > >>>>
> > >>>> Hello Corentin,
> > >>>>
> > >>>> I see much larger crashkernel=xxM being shown here
> > >>>> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/admin-guide/kdump/kdump.rst
> > >>>> and from many of my other searches.
> > >>>>
> > >>>> Here is an interesting article on kdump for ARM-32
> > >>>> https://kaiwantech.wordpress.com/2017/07/13/setting-up-kdump-and-crash-for-arm-32-an-ongoing-saga/
> > >>>>
> > >>>>
> > >>>> Here is the kernel command line reference
> > >>>> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/admin-guide/kernel-parameters.txt?h=v5.11#n732
> > >>>>
> > >>>> I feel your frustrations too.
> > >>>
> > >>> Hello
> > >>>
> > >>> Thanks but I have already read those documentation.
> > >>> I search to know why the kernel cannot find 8M of memory ouf of 128.
> > >>>
> > >>> Regards
> > >>>
> > >>
> > >> How much more memory does the kernel and initrd above and beyond just
> > >> their physical size?  (heaps, stacks, buffers, virt

Re: crashkernel reservation failed - No suitable area found on a cortina/gemini SoC

2021-04-09 Thread Corentin Labbe
Le Wed, Apr 07, 2021 at 07:59:27AM -0700, Bruce Mitchell a écrit :
> On 4/7/2021 07:48, Corentin Labbe wrote:
> > Le Wed, Apr 07, 2021 at 07:28:26AM -0700, Bruce Mitchell a écrit :
> >> On 4/7/2021 07:23, Corentin Labbe wrote:
> >>> Le Wed, Apr 07, 2021 at 07:13:04AM -0700, Bruce Mitchell a écrit :
> >>>> On 4/7/2021 05:54, Corentin Labbe wrote:
> >>>>> Hello
> >>>>>
> >>>>> I try to do kexec on a cortina/gemini SoC.
> >>>>> On a "normal" boot, kexec fail to find memory so I added crashkernel=8M 
> >>>>> to cmdline. (kernel size is ~6M).
> >>>>> But now, kernel fail to reserve memory:
> >>>>> Load Kern image from 0x3002 to 0x80 size 7340032
> >>>>> Booting Linux on physical CPU 0x0
> >>>>> Linux version 5.12.0-rc5-next-20210401+ (compile@Red) 
> >>>>> (armv7a-unknown-linux-gnueabihf-gcc (Gentoo 9.3.0-r2 p4) 9.3.0, GNU ld 
> >>>>> (Gentoo 2.34 p6) 2.34.0) #98 PREEMPT Wed Apr 7 14:14:08 CEST 2021
> >>>>> CPU: FA526 [66015261] revision 1 (ARMv4), cr=397f
> >>>>> CPU: VIVT data cache, VIVT instruction cache
> >>>>> OF: fdt: Machine model: Edimax NS-2502
> >>>>> Memory policy: Data cache writeback
> >>>>> Zone ranges:
> >>>>>  Normal   [mem 0x-0x07ff]
> >>>>>  HighMem  empty
> >>>>> Movable zone start for each node
> >>>>> Early memory node ranges
> >>>>>  node   0: [mem 0x-0x07ff]
> >>>>> Initmem setup node 0 [mem 0x-0x07ff]
> >>>>> crashkernel reservation failed - No suitable area found.
> >>>>> Built 1 zonelists, mobility grouping on.  Total pages: 32512
> >>>>> Kernel command line: console=ttyS0,19200n8 ip=dhcp crashkernel=8M
> >>>>> Dentry cache hash table entries: 16384 (order: 4, 65536 bytes, linear)
> >>>>> Inode-cache hash table entries: 8192 (order: 3, 32768 bytes, linear)
> >>>>> mem auto-init: stack:off, heap alloc:off, heap free:off
> >>>>> Memory: 119476K/131072K available (5034K kernel code, 579K rwdata, 
> >>>>> 1372K rodata, 3020K init, 210K bss, 11596K reserved, 0K cma-reserved, 
> >>>>> 0K highmem)
> >>>>> SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
> >>>>>
> >>>>> What can I do ?
> >>>>>
> >>>>> Thanks
> >>>>> Regards
> >>>>>
> >>>>> ___
> >>>>> kexec mailing list
> >>>>> ke...@lists.infradead.org
> >>>>> http://lists.infradead.org/mailman/listinfo/kexec
> >>>>>
> >>>>
> >>>> Hello Corentin,
> >>>>
> >>>> I see much larger crashkernel=xxM being shown here
> >>>> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/admin-guide/kdump/kdump.rst
> >>>> and from many of my other searches.
> >>>>
> >>>> Here is an interesting article on kdump for ARM-32
> >>>> https://kaiwantech.wordpress.com/2017/07/13/setting-up-kdump-and-crash-for-arm-32-an-ongoing-saga/
> >>>>
> >>>>
> >>>> Here is the kernel command line reference
> >>>> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/admin-guide/kernel-parameters.txt?h=v5.11#n732
> >>>>
> >>>> I feel your frustrations too.
> >>>
> >>> Hello
> >>>
> >>> Thanks but I have already read those documentation.
> >>> I search to know why the kernel cannot find 8M of memory ouf of 128.
> >>>
> >>> Regards
> >>>
> >>
> >> How much more memory does the kernel and initrd above and beyond just
> >> their physical size?  (heaps, stacks, buffers, virtual filesystems)
> > 
> > The kernel size include a rootfs.cpio.lzma of 3MB and dtb is appended.
> > The total kernel size is 7MB.
> > The uncompressed size of the kernel is 13M (size of vmlinux)
> > The uncompressed size of rootfs is 11M.
> > 
> > cat /proc/meminfo
> > MemTotal: 122496 kB
> > MemFree:  103700 kB
> > MemAvailable: 101936 kB
> > 

Re: crashkernel reservation failed - No suitable area found on a cortina/gemini SoC

2021-04-07 Thread Corentin Labbe
Le Wed, Apr 07, 2021 at 07:28:26AM -0700, Bruce Mitchell a écrit :
> On 4/7/2021 07:23, Corentin Labbe wrote:
> > Le Wed, Apr 07, 2021 at 07:13:04AM -0700, Bruce Mitchell a écrit :
> >> On 4/7/2021 05:54, Corentin Labbe wrote:
> >>> Hello
> >>>
> >>> I try to do kexec on a cortina/gemini SoC.
> >>> On a "normal" boot, kexec fail to find memory so I added crashkernel=8M 
> >>> to cmdline. (kernel size is ~6M).
> >>> But now, kernel fail to reserve memory:
> >>> Load Kern image from 0x3002 to 0x80 size 7340032
> >>> Booting Linux on physical CPU 0x0
> >>> Linux version 5.12.0-rc5-next-20210401+ (compile@Red) 
> >>> (armv7a-unknown-linux-gnueabihf-gcc (Gentoo 9.3.0-r2 p4) 9.3.0, GNU ld 
> >>> (Gentoo 2.34 p6) 2.34.0) #98 PREEMPT Wed Apr 7 14:14:08 CEST 2021
> >>> CPU: FA526 [66015261] revision 1 (ARMv4), cr=397f
> >>> CPU: VIVT data cache, VIVT instruction cache
> >>> OF: fdt: Machine model: Edimax NS-2502
> >>> Memory policy: Data cache writeback
> >>> Zone ranges:
> >>> Normal   [mem 0x-0x07ff]
> >>> HighMem  empty
> >>> Movable zone start for each node
> >>> Early memory node ranges
> >>> node   0: [mem 0x-0x07ff]
> >>> Initmem setup node 0 [mem 0x-0x07ff]
> >>> crashkernel reservation failed - No suitable area found.
> >>> Built 1 zonelists, mobility grouping on.  Total pages: 32512
> >>> Kernel command line: console=ttyS0,19200n8 ip=dhcp crashkernel=8M
> >>> Dentry cache hash table entries: 16384 (order: 4, 65536 bytes, linear)
> >>> Inode-cache hash table entries: 8192 (order: 3, 32768 bytes, linear)
> >>> mem auto-init: stack:off, heap alloc:off, heap free:off
> >>> Memory: 119476K/131072K available (5034K kernel code, 579K rwdata, 1372K 
> >>> rodata, 3020K init, 210K bss, 11596K reserved, 0K cma-reserved, 0K 
> >>> highmem)
> >>> SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
> >>>
> >>> What can I do ?
> >>>
> >>> Thanks
> >>> Regards
> >>>
> >>> ___
> >>> kexec mailing list
> >>> ke...@lists.infradead.org
> >>> http://lists.infradead.org/mailman/listinfo/kexec
> >>>
> >>
> >> Hello Corentin,
> >>
> >> I see much larger crashkernel=xxM being shown here
> >> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/admin-guide/kdump/kdump.rst
> >> and from many of my other searches.
> >>
> >> Here is an interesting article on kdump for ARM-32
> >> https://kaiwantech.wordpress.com/2017/07/13/setting-up-kdump-and-crash-for-arm-32-an-ongoing-saga/
> >>
> >>
> >> Here is the kernel command line reference
> >> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/admin-guide/kernel-parameters.txt?h=v5.11#n732
> >>
> >> I feel your frustrations too.
> > 
> > Hello
> > 
> > Thanks but I have already read those documentation.
> > I search to know why the kernel cannot find 8M of memory ouf of 128.
> > 
> > Regards
> > 
> 
> How much more memory does the kernel and initrd above and beyond just 
> their physical size?  (heaps, stacks, buffers, virtual filesystems)

The kernel size include a rootfs.cpio.lzma of 3MB and dtb is appended.
The total kernel size is 7MB.
The uncompressed size of the kernel is 13M (size of vmlinux)
The uncompressed size of rootfs is 11M.

cat /proc/meminfo 
MemTotal: 122496 kB
MemFree:  103700 kB
MemAvailable: 101936 kB
Buffers:   0 kB
Cached:10904 kB
SwapCached:0 kB
Active: 4304 kB
Inactive:   8012 kB
Active(anon):   4304 kB
Inactive(anon): 8012 kB
Active(file):  0 kB
Inactive(file):0 kB
Unevictable:   0 kB
Mlocked:   0 kB
HighTotal: 0 kB
HighFree:  0 kB
LowTotal: 122496 kB
LowFree:  103700 kB
SwapTotal: 0 kB
SwapFree:  0 kB
Dirty: 0 kB
Writeback: 0 kB
AnonPages:  1428 kB
Mapped: 3552 kB
Shmem: 10904 kB
KReclaimable:608 kB
Slab:   2960 kB
SReclaimable:608 kB
SUnreclaim: 2352 kB
KernelStack: 312 kB
PageTables:  136 kB
NFS_Unstable:  0 kB
Bounce:0 kB
WritebackTmp:  0 kB
CommitLimit:   61248 kB
Committed_AS:  14336 kB
VmallocTotal: 901120 kB
VmallocUsed:  64 kB
VmallocChunk:  0 kB
Percpu:   32 kB
CmaTotal:  0 kB
CmaFree:   0 kB



Re: crashkernel reservation failed - No suitable area found on a cortina/gemini SoC

2021-04-07 Thread Corentin Labbe
Le Wed, Apr 07, 2021 at 07:13:04AM -0700, Bruce Mitchell a écrit :
> On 4/7/2021 05:54, Corentin Labbe wrote:
> > Hello
> > 
> > I try to do kexec on a cortina/gemini SoC.
> > On a "normal" boot, kexec fail to find memory so I added crashkernel=8M to 
> > cmdline. (kernel size is ~6M).
> > But now, kernel fail to reserve memory:
> > Load Kern image from 0x3002 to 0x80 size 7340032
> > Booting Linux on physical CPU 0x0
> > Linux version 5.12.0-rc5-next-20210401+ (compile@Red) 
> > (armv7a-unknown-linux-gnueabihf-gcc (Gentoo 9.3.0-r2 p4) 9.3.0, GNU ld 
> > (Gentoo 2.34 p6) 2.34.0) #98 PREEMPT Wed Apr 7 14:14:08 CEST 2021
> > CPU: FA526 [66015261] revision 1 (ARMv4), cr=397f
> > CPU: VIVT data cache, VIVT instruction cache
> > OF: fdt: Machine model: Edimax NS-2502
> > Memory policy: Data cache writeback
> > Zone ranges:
> >Normal   [mem 0x-0x07ff]
> >HighMem  empty
> > Movable zone start for each node
> > Early memory node ranges
> >node   0: [mem 0x-0x07ff]
> > Initmem setup node 0 [mem 0x-0x07ff]
> > crashkernel reservation failed - No suitable area found.
> > Built 1 zonelists, mobility grouping on.  Total pages: 32512
> > Kernel command line: console=ttyS0,19200n8 ip=dhcp crashkernel=8M
> > Dentry cache hash table entries: 16384 (order: 4, 65536 bytes, linear)
> > Inode-cache hash table entries: 8192 (order: 3, 32768 bytes, linear)
> > mem auto-init: stack:off, heap alloc:off, heap free:off
> > Memory: 119476K/131072K available (5034K kernel code, 579K rwdata, 1372K 
> > rodata, 3020K init, 210K bss, 11596K reserved, 0K cma-reserved, 0K highmem)
> > SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
> > 
> > What can I do ?
> > 
> > Thanks
> > Regards
> > 
> > ___
> > kexec mailing list
> > ke...@lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/kexec
> > 
> 
> Hello Corentin,
> 
> I see much larger crashkernel=xxM being shown here
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/admin-guide/kdump/kdump.rst
> and from many of my other searches.
> 
> Here is an interesting article on kdump for ARM-32
> https://kaiwantech.wordpress.com/2017/07/13/setting-up-kdump-and-crash-for-arm-32-an-ongoing-saga/
> 
> 
> Here is the kernel command line reference
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/admin-guide/kernel-parameters.txt?h=v5.11#n732
> 
> I feel your frustrations too.

Hello

Thanks but I have already read those documentation.
I search to know why the kernel cannot find 8M of memory ouf of 128.

Regards


crashkernel reservation failed - No suitable area found on a cortina/gemini SoC

2021-04-07 Thread Corentin Labbe
Hello

I try to do kexec on a cortina/gemini SoC.
On a "normal" boot, kexec fail to find memory so I added crashkernel=8M to 
cmdline. (kernel size is ~6M).
But now, kernel fail to reserve memory:
Load Kern image from 0x3002 to 0x80 size 7340032

Booting Linux on physical CPU 0x0   

Linux version 5.12.0-rc5-next-20210401+ (compile@Red) 
(armv7a-unknown-linux-gnueabihf-gcc (Gentoo 9.3.0-r2 p4) 9.3.0, GNU ld (Gentoo 
2.34 p6) 2.34.0) #98 PREEMPT Wed Apr 7 14:14:08 CEST 2021
CPU: FA526 [66015261] revision 1 (ARMv4), cr=397f   

CPU: VIVT data cache, VIVT instruction cache

OF: fdt: Machine model: Edimax NS-2502  

Memory policy: Data cache writeback 

Zone ranges:

  Normal   [mem 0x-0x07ff]  

  HighMem  empty

Movable zone start for each node

Early memory node ranges

  node   0: [mem 0x-0x07ff] 

Initmem setup node 0 [mem 0x-0x07ff]

crashkernel reservation failed - No suitable area found.

Built 1 zonelists, mobility grouping on.  Total pages: 32512

Kernel command line: console=ttyS0,19200n8 ip=dhcp crashkernel=8M   

Dentry cache hash table entries: 16384 (order: 4, 65536 bytes, linear)  

Inode-cache hash table entries: 8192 (order: 3, 32768 bytes, linear)

mem auto-init: stack:off, heap alloc:off, heap free:off 

Memory: 119476K/131072K available (5034K kernel code, 579K rwdata, 1372K 
rodata, 3020K init, 210K bss, 11596K reserved, 0K cma-reserved, 0K highmem)
SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1  


What can I do ?

Thanks
Regards


Re: gemini: sl3516: Mainlining of NS 2502

2021-04-06 Thread Corentin Labbe
Le Tue, Apr 06, 2021 at 10:15:51AM +0200, Linus Walleij a écrit :
> On Mon, Apr 5, 2021 at 8:39 PM Corentin Labbe  
> wrote:
> 
> > I own an Edimax NS 2502, which is a NAS based on StormLinix 3516.
> > I successfully upgraded it with a recent Linux.
> 
> Pretty cool!
> 
> > mdio0: ethernet-phy {
> > compatible = "virtual,mdio-gpio";
> > gpios = < 22 GPIO_ACTIVE_HIGH>, /* MDC */
> > < 21 GPIO_ACTIVE_HIGH>; /* MDIO */
> > #address-cells = <1>;
> > #size-cells = <0>;
> > phy0: ethernet-phy@1 {
> > reg = <1>;
> > device_type = "ethernet-phy";
> > };
> > };
> 
> This looks like the most typical way to attach an MDIO phy.
> 
> I always try to identify the exact component used on the board. Do you have
>  a high res board photo?
> 

Hello

You could find photos at http://kernel.montjoie.ovh/gemini/
There are also photos of another SL3516 SoC based device (a SSI 1328 NAS), but 
I fail to setup a serial on it, so I keep it for later. 

> Realtek RTL82111 is the most common configuration.
> 
> Compare to the D-Linux DNS-313 DTS:
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm/boot/dts/gemini-dlink-dns-313.dts
> 
> Try just copying the whole pinctrl-gmii section!
> 
> 
> > syscon: syscon@4000 {
> > pinctrl {
> > /*
> >  * gpio0agrp cover line 0-4
> >  * gpio0bgrp cover line 5
> >  */
> > gpio0_default_pins: pinctrl-gpio0 {
> > mux {
> > function = "gpio0";
> > groups = "gpio0agrp",
> > "gpio0bgrp";
> > };
> > };
> 
> Change groups to
> 
> groups = "gpio0agrp", "gpio0bgrp", "gpio0hgrp";
> 
> So you mux in group h which is where the GPIO 21, 22 go out
> to the MDIO on 3516 IIUC. The right mux out is pretty important,
> if you have vendor source code, please share so I can check how
> they set it up.
> 

No change, probably due to all pinctrl-gemini 4000.syscon:pinctrl: could 
not map pin config for "R8 GMAC0 RXDV"
Please see http://kernel.montjoie.ovh/gemini/bootlog6.txt , I have added some 
pr_info in gmac.
I have put in the directory, the final dtb which I use.

The vendor source could be found at 
https://www.edimax.com/edimax/mw/cufiles/files/download/OpenSourceCode/transfer/Wireless/NAS/NAS-GPL-source.zip

> > BUT neither ethernet nor USB works.
> 
> For USB try this patch:
> https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-nomadik.git/commit/?h=gemini-usb=cbaf6cdf770b90de5f10bfa5112c679f1dffe948
> 

One of the USB port is now working.

> Pls report progress! I hope we can mainline this device.
> 

I hope too.
Note that I have also started to work on the gemini crypto driver.

Thanks for your help


Re: gemini: sl3516: Mainlining of NS 2502

2021-04-06 Thread Corentin Labbe
Le Mon, Apr 05, 2021 at 10:36:32PM +0200, Andrew Lunn a écrit :
> On Mon, Apr 05, 2021 at 08:39:54PM +0200, Corentin Labbe wrote:
[ ... ]
> > libphy: Fixed MDIO Bus: probed
> > mdio-gpio ethernet-phy: failed to get alias id
> 
> That does not look too good. But it is just a warning.
> 
> if (pdev->dev.of_node) {
> bus_id = of_alias_get_id(pdev->dev.of_node, "mdio-gpio");
> if (bus_id < 0) {
> dev_warn(>dev, "failed to get alias id\n");
> bus_id = 0;
> }
> 
> If you look at the example in the documentation, it has
> 
> aliases {
> mdio-gpio0 = 
> };
> 
> If you add that, i guess this will go away.
>   

Hello

Yes it go away with this

> > gemini-ethernet-port 6000c000.ethernet-port: probe 6000c000.ethernet-port 
> > ID 1
> > gemini-ethernet-port 6000c000.ethernet-port: using a random ethernet address
> > gemini-ethernet-port 6000c000.ethernet-port (unnamed net_device) 
> > (uninitialized): PHY init failed
> 
> And now it seems to of all gone horribly wrong :-(
> 
> This is the second Ethernet interface, the one you have commented as 
> 
> /* Not used in this platform */
> 
> I _think_ you just need to delete the entry, otherwise it tried to
> probe it. And then that probe fails, it looks like it also fails the
> working interface :-(

Deleting the entry did no change. It still try to probe it.
I will try to delete second interface in gemini.dtsi just in case...


> > # udhcpc -i eth0
> > udhcpc: started, v1.33.0
> > udhcpc: socket: Address family not supported by protocol
> 
> That suggests the kernel you have build does not have PF_PACKET.
> Enable CONFIG_PACKET_DIAG.

Yes adding it fixed this error message.

Thanks


gemini: sl3516: Mainlining of NS 2502

2021-04-05 Thread Corentin Labbe
Hello

I own an Edimax NS 2502, which is a NAS based on StormLinix 3516.

I successfully upgraded it with a recent Linux.
The DTB I use is the following:
/dts-v1/;
#include "gemini.dtsi"
#include 
/ {
model = "Edimax NS-2502";
compatible = "edimax,ns-2502", "cortina,gemini";
#address-cells = <1>;
#size-cells = <1>;
memory@0 {
/* 128 MB */
device_type = "memory";
reg = <0x 0x800>;
};
chosen {
bootargs = "console=ttyS0,19200n8";
stdout-path = 
};
mdio0: ethernet-phy {
compatible = "virtual,mdio-gpio";
gpios = < 22 GPIO_ACTIVE_HIGH>, /* MDC */
< 21 GPIO_ACTIVE_HIGH>; /* MDIO */
#address-cells = <1>;
#size-cells = <0>;
phy0: ethernet-phy@1 {
reg = <1>;
device_type = "ethernet-phy";
};
};
soc {
flash@3000 {
status = "okay";
/* 8MB of flash */
reg = <0x3000 0x0080>;
partition@0 {
label = "RedBoot";
reg = <0x 0x0002>;
read-only;
};
partition@2 {
label = "kernel";
reg = <0x0002 0x0070>;
};
partition@72 {
label = "VCTL";
reg = <0x0072 0x0002>;
read-only;
};
partition@74 {
label = "CurConf";
reg = <0x0074 0x000a>;
read-only;
};
partition@7e {
label = "FIS";
reg = <0x007e 0x0001>;
read-only;
};
};
syscon: syscon@4000 {
pinctrl {
/*
 * gpio0agrp cover line 0-4
 * gpio0bgrp cover line 5
 */
gpio0_default_pins: pinctrl-gpio0 {
mux {
function = "gpio0";
groups = "gpio0agrp",
"gpio0bgrp";
};
};
};
};
gpio0: gpio@4d00 {
pinctrl-names = "default";
pinctrl-0 = <_default_pins>;
};
ethernet@6000 {
status = "okay";
ethernet-port@0 {
phy-mode = "rgmii";
phy-handle = <>;
};
ethernet-port@1 {
/* Not used in this platform */
};
};
usb@6800 {
status = "okay";
};
usb@6900 {
status = "okay";
};
};
};

This is a bit of copy paste of other DTB.
With it I boot successfully to a shell.

BUT neither ethernet nor USB works.
This is the bootlog:
Flash Block Size = 65536

Storlink SL351x Boot Loader [Linux], version 1.0.9
Built by linux, 10:50:46, Aug  6 2008

Processor: SL3516c2
CPU Rate: 3
AHB Bus Clock:150MHzRatio:2/1
MAC 1 Address: 00:00:25:02:00:00
MAC 2 Address: 00:01:25:02:00:00
inet addr: 192.168.1.237/255.255.255.0
==> enter ^C to abort booting within 2 seconds ..
Load Kern image from 0x3002 to 0x80 size 7340032
Booting Linux on physical CPU 0x0
Linux version 5.12.0-rc5-next-20210401+ (compile@Red) 
(armv7a-unknown-linux-gnueabihf-gcc (Gentoo 9.3.0-r2 p4) 9.3.0, GNU ld (Gentoo 
2.34 p6) 2.34.0) #47 PREEMPT Mon Apr 5 20:20:27 CEST 2021
CPU: FA526 [66015261] revision 1 (ARMv4), cr=397f
CPU: VIVT data cache, VIVT instruction cache
OF: fdt: Machine model: Edimax NS-2502
Memory policy: Data cache writeback
Zone ranges:
  Normal   [mem 0x-0x07ff]
  HighMem  empty
Movable zone start for each node
Early memory node ranges
  node   0: [mem 0x-0x07ff]
Initmem setup node 0 [mem 0x-0x07ff]
Built 1 

Re: [PATCH][next] crypto: sun8i-ss: Fix memory leak of pad

2021-04-02 Thread Corentin Labbe
Le Thu, Apr 01, 2021 at 04:18:27PM +0100, Colin King a écrit :
> From: Colin Ian King 
> 
> It appears there are several failure return paths that don't seem
> to be free'ing pad. Fix these.
> 
> Addresses-Coverity: ("Resource leak")
> Fixes: d9b45418a917 ("crypto: sun8i-ss - support hash algorithms")
> Signed-off-by: Colin Ian King 
> ---

Hello

Acked-by: Corentin Labbe 
Tested-by: Corentin Labbe 
Tested-on: sun8i-a83t-bananapi-m3

Thanks


[PATCH] crypto: allwinner: add missing CRYPTO_ prefix

2021-03-29 Thread Corentin Labbe
Some CONFIG select miss CRYPTO_.

Reported-by: Chen-Yu Tsai 
Fixes: 56f6d5aee88d1 ("crypto: sun8i-ce - support hash algorithms")
Fixes: d9b45418a9177 ("crypto: sun8i-ss - support hash algorithms")
Signed-off-by: Corentin Labbe 
---
 drivers/crypto/allwinner/Kconfig | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/crypto/allwinner/Kconfig b/drivers/crypto/allwinner/Kconfig
index 7e2d2738b237..ef7ed21b053e 100644
--- a/drivers/crypto/allwinner/Kconfig
+++ b/drivers/crypto/allwinner/Kconfig
@@ -90,10 +90,10 @@ config CRYPTO_DEV_SUN8I_CE_DEBUG
 config CRYPTO_DEV_SUN8I_CE_HASH
bool "Enable support for hash on sun8i-ce"
depends on CRYPTO_DEV_SUN8I_CE
-   select MD5
-   select SHA1
-   select SHA256
-   select SHA512
+   select CRYPTO_MD5
+   select CRYPTO_SHA1
+   select CRYPTO_SHA256
+   select CRYPTO_SHA512
help
  Say y to enable support for hash algorithms.
 
@@ -159,8 +159,8 @@ config CRYPTO_DEV_SUN8I_SS_PRNG
 config CRYPTO_DEV_SUN8I_SS_HASH
bool "Enable support for hash on sun8i-ss"
depends on CRYPTO_DEV_SUN8I_SS
-   select MD5
-   select SHA1
-   select SHA256
+   select CRYPTO_MD5
+   select CRYPTO_SHA1
+   select CRYPTO_SHA256
help
  Say y to enable support for hash algorithms.
-- 
2.26.3



[PATCH] net: stmmac: dwmac-sun8i: Provide TX and RX fifo sizes

2021-03-19 Thread Corentin Labbe
MTU cannot be changed on dwmac-sun8i. (ip link set eth0 mtu xxx returning 
EINVAL)
This is due to tx_fifo_size being 0, since this value is used to compute valid
MTU range.
Like dwmac-sunxi (with commit 806fd188ce2a ("net: stmmac: dwmac-sunxi: Provide 
TX and RX fifo sizes"))
dwmac-sun8i need to have tx and rx fifo sizes set.
I have used values from datasheets.
After this patch, setting a non-default MTU (like 1000) value works and network 
is still useable.

Tested-on: sun8i-h3-orangepi-pc
Tested-on: sun8i-r40-bananapi-m2-ultra
Tested-on: sun50i-a64-bananapi-m64
Tested-on: sun50i-h5-nanopi-neo-plus2
Tested-on: sun50i-h6-pine-h64
Fixes: 9f93ac8d408 ("net-next: stmmac: Add dwmac-sun8i")
Reported-by: Belisko Marek 
Signed-off-by: Corentin Labbe 
---
 drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c 
b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
index 6b75cf2603ff..e62efd166ec8 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
@@ -1214,6 +1214,8 @@ static int sun8i_dwmac_probe(struct platform_device *pdev)
plat_dat->init = sun8i_dwmac_init;
plat_dat->exit = sun8i_dwmac_exit;
plat_dat->setup = sun8i_dwmac_setup;
+   plat_dat->tx_fifo_size = 4096;
+   plat_dat->rx_fifo_size = 16384;
 
ret = sun8i_dwmac_set_syscon(>dev, plat_dat);
if (ret)
-- 
2.26.2



Re: set mtu size broken for dwmac-sun8i

2021-03-17 Thread Corentin Labbe
Le Wed, Mar 17, 2021 at 12:37:48PM +0100, Belisko Marek a écrit :
> On Wed, Mar 17, 2021 at 12:33 PM Corentin Labbe
>  wrote:
> >
> > Le Wed, Mar 17, 2021 at 10:19:26AM +0100, Belisko Marek a écrit :
> > > Hi,
> > >
> > > I'm hunting an issue when setting mtu failed for dwmac-sun8i driver.
> > > Basically adding more debug shows that in stmmac_change_mtu
> > > tx_fifo_size is 0 and in this case EINVAL is reported. Isaw there was
> > > fix for similar driver dwmac-sunxi driver by:
> > > 806fd188ce2a4f8b587e83e73c478e6484fbfa55
> > >
> > > IIRC dwmac-sun8i should get tx and rx fifo size from dma but seems
> > > it's not the case. I'm using 5.4 kernel LTS release. Any ideas?
> > >
> > > Thanks and BR,
> > >
> > > marek
> > >
> >
> > Hello
> >
> > Could you provide exact command line you tried to change mtu ?
> > Along with all MTU values you tried.
> I tried with ifconfig eth0 down && ifconfig eth0 mtu 1400 return:
> ifconfig: SIOCSIFMTU: Invalid argument
> 
> btw board is orange-pi-pc-plus
> >
> > Thanks
> > Regards
> 

I have added as CC sunxi maintainers

I can confirm that dwmac-sun8i need the same fix as 
806fd188ce2a4f8b587e83e73c478e6484fbfa55.
With the patch below, I successfully changed MTU ... and the network is still 
working.
My first test was on orange-pi-pc which is the same SoC than your board.
I test this patch on all other sunxi SoCs and I send it upstream after.

@netdev, does there is some specific MTU values interesting to test ? (I 
curently try 68 500 1000 1200 1400 1500 1600 9000)

Regards

Author: Corentin Labbe 
Date:   Wed Mar 17 16:49:50 2021 +0100

net: stmmac: dwmac-sun8i: Provide TX and RX fifo sizes

MTU cannot be changed on dwmac-sun8i.
This is due to tx_fifo_size being 0.
Like dwmac-sunxi (with 806fd188ce2a ("net: stmmac: dwmac-sunxi: Provide TX 
and RX fifo sizes"))
dwmac-sun8i need to have tx and rx fifo sizes set.

Fixes: 9f93ac8d408 ("net-next: stmmac: Add dwmac-sun8i")
Reported-by: Belisko Marek 
Signed-off-by: Corentin Labbe 

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c 
b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
index 6b75cf2603ff..e62efd166ec8 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
@@ -1214,6 +1214,8 @@ static int sun8i_dwmac_probe(struct platform_device *pdev)
plat_dat->init = sun8i_dwmac_init;
plat_dat->exit = sun8i_dwmac_exit;
plat_dat->setup = sun8i_dwmac_setup;
+   plat_dat->tx_fifo_size = 4096;
+   plat_dat->rx_fifo_size = 16384;
 
ret = sun8i_dwmac_set_syscon(>dev, plat_dat);
if (ret)



sensors-detect: Found unknown chip with ID 0x0404

2021-03-11 Thread Corentin Labbe
Hello

I have a server where sensors-detecte gives:
Some Super I/O chips contain embedded sensors. We have to write to
standard I/O ports to probe them. This is usually safe.
Do you want to scan for Super I/O sensors? (YES/no): 
Probing for Super-I/O at 0x2e/0x2f
Trying family `National Semiconductor/ITE'...   Yes
Found unknown chip with ID 0x0404

I have tried to search on the motherboard but didnt find any visible NS nor ITE 
chip. (could it be embeded in chipset or BMC for example ?)
Furthermore, with another OS (a buildroot with more recent kernel), 
sensors-detect give that the ID is 0x0101.
Any hope there is a real hwmon chip behind ?

Regards


rtc: rtc-m48t59: rtc-m48t59.0: IRQ index 0 not found

2021-03-10 Thread Corentin Labbe
Hello

On my SPARC sunblade 100, I got this:
[   13.613727] rtc-m48t59 rtc-m48t59.0: IRQ index 0 not found
[   13.805777] rtc-m48t59 rtc-m48t59.0: registered as rtc0
[   14.385092] rtc-m48t59 rtc-m48t59.0: setting system clock to 
2021-03-01T05:34:33 UTC (1614576873)

The IRQ index 0 message is found after 5.5

Testing rtc via hwclock give:
hwclock: ioctl(3, RTC_UIE_ON, 0) to /dev/rtc0 failed: Input/output error
But this hwclock behavior is present also on earlier kernel (tested 4.9.260, 
4.19.179 and 4.14.224).

Does this Input/output error is normal ? (I think no)

Regards


Re: [PATCH] crypto: sun8i-ss: Fix memory leak of object d when dma_iv fails to map

2021-03-08 Thread Corentin Labbe
Le Tue, Mar 02, 2021 at 04:34:46PM +, Colin King a écrit :
> From: Colin Ian King 
> 
> In the case where the dma_iv mapping fails, the return error path leaks
> the memory allocated to object d.  Fix this by adding a new error return
> label and jumping to this to ensure d is free'd before the return.
> 
> Addresses-Coverity: ("Resource leak")
> Fixes: ac2614d721de ("crypto: sun8i-ss - Add support for the PRNG")
> Signed-off-by: Colin Ian King 
> ---
>  drivers/crypto/allwinner/sun8i-ss/sun8i-ss-prng.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-prng.c 
> b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-prng.c
> index 08a1473b2145..3191527928e4 100644
> --- a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-prng.c
> +++ b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-prng.c
> @@ -103,7 +103,8 @@ int sun8i_ss_prng_generate(struct crypto_rng *tfm, const 
> u8 *src,
>   dma_iv = dma_map_single(ss->dev, ctx->seed, ctx->slen, DMA_TO_DEVICE);
>   if (dma_mapping_error(ss->dev, dma_iv)) {
>   dev_err(ss->dev, "Cannot DMA MAP IV\n");
> - return -EFAULT;
> + err = -EFAULT;
> + goto err_free;
>   }
>  
>   dma_dst = dma_map_single(ss->dev, d, todo, DMA_FROM_DEVICE);
> @@ -167,6 +168,7 @@ int sun8i_ss_prng_generate(struct crypto_rng *tfm, const 
> u8 *src,
>   memcpy(ctx->seed, d + dlen, ctx->slen);
>   }
>       memzero_explicit(d, todo);
> +err_free:
>   kfree(d);
>  
>   return err;
> -- 
> 2.30.0
> 
Hello

Tested-by: Corentin Labbe 
Acked-by: Corentin Labbe 

Thanks


Re: [PATCH] crypto: allwinner: sun8i-ce: fix error return code in sun8i_ce_prng_generate()

2021-03-08 Thread Corentin Labbe
Le Thu, Mar 04, 2021 at 05:57:17PM -0800, Jia-Ju Bai a écrit :
> When dma_mapping_error() returns an error, no error return code of 
> sun8i_ce_prng_generate() is assigned.
> To fix this bug, err is assigned with -EFAULT as error return code.
> 
> Reported-by: TOTE Robot 
> Signed-off-by: Jia-Ju Bai 
> ---
>  drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c 
> b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c
> index cfde9ee4356b..cd1baee424a1 100644
> --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c
> +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c
> @@ -99,6 +99,7 @@ int sun8i_ce_prng_generate(struct crypto_rng *tfm, const u8 
> *src,
>   dma_iv = dma_map_single(ce->dev, ctx->seed, ctx->slen, DMA_TO_DEVICE);
>   if (dma_mapping_error(ce->dev, dma_iv)) {
>   dev_err(ce->dev, "Cannot DMA MAP IV\n");
> + err = -EFAULT;
>   goto err_iv;
>   }
>  
> -- 
> 2.17.1
> 

Hello

Tested-by: Corentin Labbe 
Acked-by: Corentin Labbe 

Thanks


[PATCH] sparc: sparc64_defconfig: remove duplicate CONFIGs

2021-03-08 Thread Corentin Labbe
After my patch there is CONFIG_ATA defined twice.
Remove the duplicate one.
Same problem for CONFIG_HAPPYMEAL, except I added as builtin for boot
test with NFS.

Reported-by: Stephen Rothwell 
Fixes: a57cdeb369ef ("sparc: sparc64_defconfig: add necessary configs for qemu")
Signed-off-by: Corentin Labbe 
---
 arch/sparc/configs/sparc64_defconfig | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/arch/sparc/configs/sparc64_defconfig 
b/arch/sparc/configs/sparc64_defconfig
index 148f44b33890..12a4fb0bd52a 100644
--- a/arch/sparc/configs/sparc64_defconfig
+++ b/arch/sparc/configs/sparc64_defconfig
@@ -93,7 +93,7 @@ CONFIG_NETDEVICES=y
 CONFIG_NET_ETHERNET=y
 CONFIG_MII=m
 CONFIG_SUNLANCE=m
-CONFIG_HAPPYMEAL=m
+CONFIG_HAPPYMEAL=y
 CONFIG_SUNGEM=m
 CONFIG_SUNVNET=m
 CONFIG_LDMVSW=m
@@ -234,9 +234,7 @@ CONFIG_CRYPTO_TWOFISH=m
 CONFIG_CRC16=m
 CONFIG_LIBCRC32C=m
 CONFIG_VCC=m
-CONFIG_ATA=y
 CONFIG_PATA_CMD64X=y
-CONFIG_HAPPYMEAL=y
 CONFIG_IP_PNP=y
 CONFIG_IP_PNP_DHCP=y
 CONFIG_DEVTMPFS=y
-- 
2.26.2



[PATCH] crypto: sun8i-ss: fix result memory leak on error path

2021-03-02 Thread Corentin Labbe
This patch fixes a memory leak on an error path.

Fixes: d9b45418a917 ("crypto: sun8i-ss - support hash algorithms")
Reported-by: kernel test robot 
Reported-by: Dan Carpenter 
Signed-off-by: Corentin Labbe 
---
 drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c 
b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c
index 11cbcbc83a7b..0b9aa24a5edd 100644
--- a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c
+++ b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c
@@ -438,8 +438,8 @@ int sun8i_ss_hash_run(struct crypto_engine *engine, void 
*breq)
kfree(pad);
 
memcpy(areq->result, result, algt->alg.hash.halg.digestsize);
-   kfree(result);
 theend:
+   kfree(result);
crypto_finalize_hash_request(engine, breq, err);
return 0;
 }
-- 
2.26.2



Re: [PATCH] crypto: sun8i-ss: Fix memory leak of object d when dma_iv fails to map

2021-03-02 Thread Corentin Labbe
Le Tue, Mar 02, 2021 at 04:34:46PM +, Colin King a écrit :
> From: Colin Ian King 
> 
> In the case where the dma_iv mapping fails, the return error path leaks
> the memory allocated to object d.  Fix this by adding a new error return
> label and jumping to this to ensure d is free'd before the return.
> 
> Addresses-Coverity: ("Resource leak")
> Fixes: ac2614d721de ("crypto: sun8i-ss - Add support for the PRNG")
> Signed-off-by: Colin Ian King 
> ---

Acked-by: Corentin Labbe 

Thanks!


[PATCH] crypto: sun8i-ss: fix result memory leak on error path

2021-02-12 Thread Corentin Labbe
This patch fixes a memory leak on an error path.

Fixes: d9b45418a917 ("crypto: sun8i-ss - support hash algorithms")
Reported-by: kernel test robot 
Reported-by: Dan Carpenter 
Signed-off-by: Corentin Labbe 
---
 drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c 
b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c
index 11cbcbc83a7b..0b9aa24a5edd 100644
--- a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c
+++ b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c
@@ -438,8 +438,8 @@ int sun8i_ss_hash_run(struct crypto_engine *engine, void 
*breq)
kfree(pad);
 
memcpy(areq->result, result, algt->alg.hash.halg.digestsize);
-   kfree(result);
 theend:
+   kfree(result);
crypto_finalize_hash_request(engine, breq, err);
return 0;
 }
-- 
2.26.2



Fail to boot on bpim3 with next-20210128

2021-01-30 Thread Corentin Labbe
Hello

next-20210128 cannot be booted on my bpim3.
It start booting then freeze.

[0.00] Linux version 5.11.0-rc5-03084-g7426957d237f (compile@Red) 
(armv7a-unknown-linux-gnueabihf-gcc (Gentoo 9.3.0-r2 p4) 9.3.0, GNU ld (Gentoo 
2.34 p6) 2.34.0) #390 SMP Sat Jan 30 14:59:48 CET 2021
[0.00] CPU: ARMv7 Processor [410fc075] revision 5 (ARMv7), cr=10c5387d
[0.00] CPU: div instructions available: patching division code
[0.00] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing 
instruction cache
[0.00] OF: fdt: Machine model: Banana Pi BPI-M3
[0.00] earlycon: uart0 at MMIO32 0x01c28000 (options '')
[0.00] printk: bootconsole [uart0] enabled
[0.00] Memory policy: Data cache writealloc
[0.00] cma: Reserved 16 MiB at 0xbf00
[0.00] Zone ranges:
[0.00]   Normal   [mem 0x4000-0x6fff]
[0.00]   HighMem  [mem 0x7000-0xbfff]
[0.00] Movable zone start for each node
[0.00] Early memory node ranges
[0.00]   node   0: [mem 0x4000-0xbfff]
[0.00] Initmem setup node 0 [mem 0x4000-0xbfff]
[0.00] percpu: Embedded 15 pages/cpu s31244 r8192 d22004 u61440
[0.00] Built 1 zonelists, mobility grouping on.  Total pages: 522752
[0.00] Kernel command line: console=ttyS0,115200n8 root=/dev/ram0 
earlycon=uart,mmio32,0x01c28000 ip=dhcp
[0.00] Dentry cache hash table entries: 131072 (order: 7, 524288 bytes, 
linear)
[0.00] Inode-cache hash table entries: 65536 (order: 6, 262144 bytes, 
linear)
[0.00] mem auto-init: stack:off, heap alloc:off, heap free:off
[0.00] Memory: 2021376K/2097152K available (7168K kernel code, 934K 
rwdata, 2316K rodata, 1024K init, 240K bss, 59392K reserved, 16384K 
cma-reserved, 1294336K highmem)
[0.00] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=8, Nodes=1
[0.00] rcu: Hierarchical RCU implementation.
[0.00] rcu: RCU event tracing is enabled.
[0.00] rcu: RCU calculated value of scheduler-enlistment delay is 10 
jiffies.
[0.00] NR_IRQS: 16, nr_irqs: 16, preallocated irqs: 16
[0.00] random: get_random_bytes called from start_kernel+0x350/0x4e0 
with crng_init=0
[0.00] arch_timer: cp15 timer(s) running at 24.00MHz (virt).
[0.00] clocksource: arch_sys_counter: mask: 0xff 
max_cycles: 0x588fe9dc0, max_idle_ns: 440795202592 ns
[0.03] sched_clock: 56 bits at 24MHz, resolution 41ns, wraps every 
4398046511097ns
[0.008640] Switching to timer-based delay loop, resolution 41ns
[0.015437] clocksource: timer: mask: 0x max_cycles: 0x, 
max_idle_ns: 79635851949 ns
[0.025858] Console: colour dummy device 80x30
[0.030736] Calibrating delay loop (skipped), value calculated using timer 
frequency.. 48.00 BogoMIPS (lpj=24)
[0.041941] pid_max: default: 32768 minimum: 301
[0.047080] Mount-cache hash table entries: 2048 (order: 1, 8192 bytes, 
linear)
[0.054990] Mountpoint-cache hash table entries: 2048 (order: 1, 8192 bytes, 
linear)
[0.064421] CPU: Testing write buffer coherency: ok
[0.070242] /cpus/cpu@0 missing clock-frequency property
[0.076025] /cpus/cpu@1 missing clock-frequency property
[0.081805] /cpus/cpu@2 missing clock-frequency property
[0.087546] /cpus/cpu@3 missing clock-frequency property
[0.093300] /cpus/cpu@100 missing clock-frequency property
[0.099227] /cpus/cpu@101 missing clock-frequency property
[0.105173] /cpus/cpu@102 missing clock-frequency property
[0.11] /cpus/cpu@103 missing clock-frequency property
[0.117026] CPU0: thread -1, cpu 0, socket 0, mpidr 8000
[0.123888] Setting up static identity map for 0x4010 - 0x40100060
[0.131237] ARM CCI driver probed
[0.135530] sunxi multi cluster SMP support installed
[0.141501] rcu: Hierarchical SRCU implementation.
[0.147277] smp: Bringing up secondary CPUs ...
[0.153237] CPU1: thread -1, cpu 1, socket 0, mpidr 8001
[0.154443] CPU2: thread -1, cpu 2, socket 0, mpidr 8002
[0.155544] CPU3: thread -1, cpu 3, socket 0, mpidr 8003
[0.156837] CPU4: thread -1, cpu 0, socket 1, mpidr 8100
[0.158221] CPU5: thread -1, cpu 1, socket 1, mpidr 8101
[0.159456] CPU6: thread -1, cpu 2, socket 1, mpidr 8102
[0.160663] CPU7: thread -1, cpu 3, socket 1, mpidr 8103
[0.160825] smp: Brought up 1 node, 8 CPUs
[0.207953] SMP: Total of 8 processors activated (384.00 BogoMIPS).
[0.214714] CPU: All CPU(s) started in SVC mode.
[0.221355] devtmpfs: initialized
[0.232737] VFP support v0.3: implementor 41 architecture 2 part 30 variant 
7 rev 5
[0.241442] clocksource: jiffies: mask: 0x max_cycles: 0x, 
max_idle_ns: 1911260446275 ns
[0.252094] futex hash table entries: 2048 (order: 5, 131072 bytes, linear)
[

arm: sunxi: &83t: WARNING: CPU: 2 PID: 57 at drivers/thermal/thermal_core.c:563 thermal_zone_device_update

2021-01-30 Thread Corentin Labbe
Hello

When booting next-20210128, I got the following warning on by bpim3
6.148421] [ cut here ]
[6.153145] WARNING: CPU: 2 PID: 57 at drivers/thermal/thermal_core.c:563 
thermal_zone_device_update+0x134/0x154
[6.163378] 'thermal_zone_device_update' must not be called without 
'get_temp' ops set
[6.171300] Modules linked in: sha256_generic libsha256
[6.176553] CPU: 2 PID: 57 Comm: kworker/2:1 Not tainted 
5.11.0-rc1-00042-gf3788af62cfe #399
[6.184984] Hardware name: Allwinner A83t board
[6.189517] Workqueue: events deferred_probe_work_func
[6.194686] [] (unwind_backtrace) from [] 
(show_stack+0x10/0x14)
[6.202438] [] (show_stack) from [] 
(dump_stack+0x98/0xac)
[6.209666] [] (dump_stack) from [] (__warn+0xc0/0xd8)
[6.216545] [] (__warn) from [] 
(warn_slowpath_fmt+0x98/0xc0)
[6.224030] [] (warn_slowpath_fmt) from [] 
(thermal_zone_device_update+0x134/0x154)
[6.233426] [] (thermal_zone_device_update) from [] 
(__thermal_cooling_device_register+0x334/0x35c)
[6.244204] [] (__thermal_cooling_device_register) from 
[] (__cpufreq_cooling_register.constprop.0+0x184/0x294)
[6.256026] [] (__cpufreq_cooling_register.constprop.0) from 
[] (of_cpufreq_cooling_register+0x40/0x7c)
[6.267153] [] (of_cpufreq_cooling_register) from [] 
(cpufreq_online+0x2b4/0x8f4)
[6.276379] [] (cpufreq_online) from [] 
(cpufreq_add_dev+0x6c/0x78)
[6.284383] [] (cpufreq_add_dev) from [] 
(subsys_interface_register+0xa4/0xf0)
[6.293344] [] (subsys_interface_register) from [] 
(cpufreq_register_driver+0x144/0x2dc)
[6.303169] [] (cpufreq_register_driver) from [] 
(dt_cpufreq_probe+0x298/0x3b8)
[6.312215] [] (dt_cpufreq_probe) from [] 
(platform_probe+0x5c/0xb8)
[6.320313] [] (platform_probe) from [] 
(really_probe+0x1dc/0x3b8)
[6.328231] [] (really_probe) from [] 
(driver_probe_device+0x5c/0xb4)
[6.336406] [] (driver_probe_device) from [] 
(bus_for_each_drv+0x84/0xc8)
[6.344928] [] (bus_for_each_drv) from [] 
(__device_attach+0xe8/0x154)
[6.353189] [] (__device_attach) from [] 
(bus_probe_device+0x84/0x8c)
[6.361365] [] (bus_probe_device) from [] 
(deferred_probe_work_func+0x64/0x90)
[6.370321] [] (deferred_probe_work_func) from [] 
(process_one_work+0x1dc/0x438)
[6.379456] [] (process_one_work) from [] 
(worker_thread+0x25c/0x55c)
[6.387632] [] (worker_thread) from [] 
(kthread+0x124/0x150)
[6.395032] [] (kthread) from [] 
(ret_from_fork+0x14/0x24)
[6.402256] Exception stack(0xc12d1fb0 to 0xc12d1ff8)
[6.407307] 1fa0:   
 
[6.415478] 1fc0:       
 
[6.423648] 1fe0:     0013 
[6.430301] ---[ end trace bd63a5c976f3611c ]---

I bisected the problem to
ARM: dts: sunxi: Remove thermal zones without trip points

Reverting this commit remove the warning.

Regards


Re: Fail to boot qemu xlnx-zcu102 due to lot of drivers not probing

2021-01-25 Thread Corentin Labbe
Le Fri, Jan 22, 2021 at 11:51:53AM +0100, Edgar E. Iglesias a écrit :
> On Fri, Jan 22, 2021 at 10:52:18AM +0100, Michal Simek wrote:
> > Hi,
> > 
> > On 1/22/21 10:24 AM, Corentin Labbe wrote:
> > > Hello
> > > 
> > > With at least qemu 5.1.0 (and later), the xlnx-zcu102 machine boot lead 
> > > to a panic due to missing console.
> > > qemu-system-aarch64 -kernel Image -nographic -machine xlnx-zcu102 -device 
> > > ide-hd,drive=lavatest -serial mon:stdio -serial null -append 
> > > 'earlycon=cdns,mmio,0xFF00,115200n8 console=ttyPS0 root=/dev/ram0 
> > > ip=dhcp' -dtb zynqmp-zcu102-rev1.0.dtb -m 2048 -nic 
> > > user,model=cadence_gem,mac=52:54:00:12:34:58 -drive 
> > > format=qcow2,file=disk.img,if=none,id=lavatest -initrd rootfs.cpio.gz
> > > [0.00] Booting Linux on physical CPU 0x00 [0x410fd034]
> > > [0.00] Linux version 5.5.0-rc1-4-g9c8a47b484ed 
> > > (clabbe@arnold) (gcc version 7.5.0 (Linaro GCC 7.5-2019.12)) #17 SMP 
> > > PREEMPT Fri Jan 22 09:19:31 UTC 2021
> > > [0.00] Machine model: ZynqMP ZCU102 Rev1.0
> > > [0.00] earlycon: cdns0 at MMIO 0xff00 (options 
> > > '115200n8')
> > > [0.00] printk: bootconsole [cdns0] enabled
> > > [0.00] efi: Getting EFI parameters from FDT:
> > > [0.00] efi: UEFI not found.
> > > [0.00] cma: Reserved 32 MiB at 0x7e00
> > > [0.00] NUMA: No NUMA configuration found
> > > [0.00] NUMA: Faking a node at [mem 
> > > 0x-0x7fff]
> > > [0.00] NUMA: NODE_DATA [mem 0x7dbe0100-0x7dbe1fff]
> > > [0.00] Zone ranges:
> > > [0.00]   DMA  [mem 0x-0x3fff]
> > > [0.00]   DMA32[mem 0x4000-0x7fff]
> > > [0.00]   Normal   empty
> > > [0.00] Movable zone start for each node
> > > [0.00] Early memory node ranges
> > > [0.00]   node   0: [mem 0x-0x7fff]
> > > [0.00] Initmem setup node 0 [mem 
> > > 0x-0x7fff]
> > > [0.00] psci: probing for conduit method from DT.
> > > [0.00] psci: PSCIv0.2 detected in firmware.
> > > [0.00] psci: Using standard PSCI v0.2 function IDs
> > > [0.00] psci: Trusted OS migration not required
> > > [0.00] percpu: Embedded 22 pages/cpu s53016 r8192 d28904 u90112
> > > [0.00] Detected VIPT I-cache on CPU0
> > > [0.00] CPU features: detected: ARM erratum 845719
> > > [0.00] CPU features: detected: ARM erratum 843419
> > > [0.00] Built 1 zonelists, mobility grouping on.  Total pages: 
> > > 516096
> > > [0.00] Policy zone: DMA32
> > > [0.00] Kernel command line: 
> > > earlycon=cdns,mmio,0xFF00,115200n8 console=ttyPS0 root=/dev/ram0 
> > > ip=dhcp
> > > [0.00] Dentry cache hash table entries: 262144 (order: 9, 2097152 
> > > bytes, linear)
> > > [0.00] Inode-cache hash table entries: 131072 (order: 8, 1048576 
> > > bytes, linear)
> > > [0.00] mem auto-init: stack:off, heap alloc:off, heap free:off
> > > [0.00] software IO TLB: mapped [mem 0x3bfff000-0x3000] (64MB)
> > > [0.00] Memory: 1907172K/2097152K available (12092K kernel code, 
> > > 1896K rwdata, 6640K rodata, 5120K init, 456K bss, 157212K reserved, 
> > > 32768K cma-reserved)
> > > [0.00] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=4, Nodes=1
> > > [0.00] rcu: Preemptible hierarchical RCU implementation.
> > > [0.00] rcu:   RCU restricting CPUs from NR_CPUS=256 to 
> > > nr_cpu_ids=4.
> > > [0.00]Tasks RCU enabled.
> > > [0.00] rcu: RCU calculated value of scheduler-enlistment delay is 
> > > 25 jiffies.
> > > [0.00] rcu: Adjusting geometry for rcu_fanout_leaf=16, 
> > > nr_cpu_ids=4
> > > [0.00] NR_IRQS: 64, nr_irqs: 64, preallocated irqs: 0
> > > [0.00] random: get_random_bytes called from 
> > > start_kernel+0x2b8/0x454 with crng_init=0
> > > [0.00] arch_timer: cp15 timer(s) running at 62.50MHz (virt).
> > > [0.00] clocksource: arch_sys_counter: mask: 0xff 
> > > max_cycles: 0x1cd42e208c, max_idle_ns: 881590405314 ns
> > > [0.000118] sched_clock: 56 bits at 62MHz, re

Fail to boot qemu xlnx-zcu102 due to lot of drivers not probing

2021-01-22 Thread Corentin Labbe
Hello

With at least qemu 5.1.0 (and later), the xlnx-zcu102 machine boot lead to a 
panic due to missing console.
qemu-system-aarch64 -kernel Image -nographic -machine xlnx-zcu102 -device 
ide-hd,drive=lavatest -serial mon:stdio -serial null -append 
'earlycon=cdns,mmio,0xFF00,115200n8 console=ttyPS0 root=/dev/ram0 ip=dhcp' 
-dtb zynqmp-zcu102-rev1.0.dtb -m 2048 -nic 
user,model=cadence_gem,mac=52:54:00:12:34:58 -drive 
format=qcow2,file=disk.img,if=none,id=lavatest -initrd rootfs.cpio.gz
[0.00] Booting Linux on physical CPU 0x00 [0x410fd034]
[0.00] Linux version 5.5.0-rc1-4-g9c8a47b484ed (clabbe@arnold) (gcc 
version 7.5.0 (Linaro GCC 7.5-2019.12)) #17 SMP PREEMPT Fri Jan 22 09:19:31 UTC 
2021
[0.00] Machine model: ZynqMP ZCU102 Rev1.0
[0.00] earlycon: cdns0 at MMIO 0xff00 (options '115200n8')
[0.00] printk: bootconsole [cdns0] enabled
[0.00] efi: Getting EFI parameters from FDT:
[0.00] efi: UEFI not found.
[0.00] cma: Reserved 32 MiB at 0x7e00
[0.00] NUMA: No NUMA configuration found
[0.00] NUMA: Faking a node at [mem 
0x-0x7fff]
[0.00] NUMA: NODE_DATA [mem 0x7dbe0100-0x7dbe1fff]
[0.00] Zone ranges:
[0.00]   DMA  [mem 0x-0x3fff]
[0.00]   DMA32[mem 0x4000-0x7fff]
[0.00]   Normal   empty
[0.00] Movable zone start for each node
[0.00] Early memory node ranges
[0.00]   node   0: [mem 0x-0x7fff]
[0.00] Initmem setup node 0 [mem 0x-0x7fff]
[0.00] psci: probing for conduit method from DT.
[0.00] psci: PSCIv0.2 detected in firmware.
[0.00] psci: Using standard PSCI v0.2 function IDs
[0.00] psci: Trusted OS migration not required
[0.00] percpu: Embedded 22 pages/cpu s53016 r8192 d28904 u90112
[0.00] Detected VIPT I-cache on CPU0
[0.00] CPU features: detected: ARM erratum 845719
[0.00] CPU features: detected: ARM erratum 843419
[0.00] Built 1 zonelists, mobility grouping on.  Total pages: 516096
[0.00] Policy zone: DMA32
[0.00] Kernel command line: earlycon=cdns,mmio,0xFF00,115200n8 
console=ttyPS0 root=/dev/ram0 ip=dhcp
[0.00] Dentry cache hash table entries: 262144 (order: 9, 2097152 
bytes, linear)
[0.00] Inode-cache hash table entries: 131072 (order: 8, 1048576 bytes, 
linear)
[0.00] mem auto-init: stack:off, heap alloc:off, heap free:off
[0.00] software IO TLB: mapped [mem 0x3bfff000-0x3000] (64MB)
[0.00] Memory: 1907172K/2097152K available (12092K kernel code, 1896K 
rwdata, 6640K rodata, 5120K init, 456K bss, 157212K reserved, 32768K 
cma-reserved)
[0.00] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=4, Nodes=1
[0.00] rcu: Preemptible hierarchical RCU implementation.
[0.00] rcu: RCU restricting CPUs from NR_CPUS=256 to nr_cpu_ids=4.
[0.00]  Tasks RCU enabled.
[0.00] rcu: RCU calculated value of scheduler-enlistment delay is 25 
jiffies.
[0.00] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=4
[0.00] NR_IRQS: 64, nr_irqs: 64, preallocated irqs: 0
[0.00] random: get_random_bytes called from start_kernel+0x2b8/0x454 
with crng_init=0
[0.00] arch_timer: cp15 timer(s) running at 62.50MHz (virt).
[0.00] clocksource: arch_sys_counter: mask: 0xff 
max_cycles: 0x1cd42e208c, max_idle_ns: 881590405314 ns
[0.000118] sched_clock: 56 bits at 62MHz, resolution 16ns, wraps every 
4398046511096ns
[0.006458] Console: colour dummy device 80x25
[0.008026] Calibrating delay loop (skipped), value calculated using timer 
frequency.. 125.00 BogoMIPS (lpj=25)
[0.008182] pid_max: default: 32768 minimum: 301
[0.009157] LSM: Security Framework initializing
[0.010014] Mount-cache hash table entries: 4096 (order: 3, 32768 bytes, 
linear)
[0.010106] Mountpoint-cache hash table entries: 4096 (order: 3, 32768 
bytes, linear)
[0.060263] ASID allocator initialised with 32768 entries
[0.067849] rcu: Hierarchical SRCU implementation.
[0.079370] EFI services will not be available.
[0.088702] smp: Bringing up secondary CPUs ...
[0.118904] Detected VIPT I-cache on CPU1
[0.119921] CPU1: Booted secondary processor 0x01 [0x410fd034]
[0.156284] Detected VIPT I-cache on CPU2
[0.156514] CPU2: Booted secondary processor 0x02 [0x410fd034]
[0.189310] Detected VIPT I-cache on CPU3
[0.189472] CPU3: Booted secondary processor 0x03 [0x410fd034]
[0.189921] smp: Brought up 1 node, 4 CPUs
[0.190504] SMP: Total of 4 processors activated.
[0.190633] CPU features: detected: 32-bit EL0 Support
[0.190817] CPU features: detected: CRC32 instructions
[0.297754] CPU: All CPU(s) started 

[PATCH] alpha: defconfig: add necessary configs for boot testing

2021-01-18 Thread Corentin Labbe
Gentoo's KernelCI will soon boot test alpha kernel and we need
CONFIG_DEVTMPFS=y to be set for that.
Note that CONFIG_DEVTMPFS=y is already necessary for lot of other
distribution/tools like recent udev/systemd.

Signed-off-by: Corentin Labbe 
---
 arch/alpha/configs/defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/alpha/configs/defconfig b/arch/alpha/configs/defconfig
index 6293675db164..b52ed626ab55 100644
--- a/arch/alpha/configs/defconfig
+++ b/arch/alpha/configs/defconfig
@@ -72,3 +72,4 @@ CONFIG_DEBUG_INFO=y
 CONFIG_ALPHA_LEGACY_START_ADDRESS=y
 CONFIG_MATHEMU=y
 CONFIG_CRYPTO_HMAC=y
+CONFIG_DEVTMPFS=y
-- 
2.26.2



[PATCH v2] sparc: sparc64_defconfig: add necessary configs for qemu

2021-01-18 Thread Corentin Labbe
The sparc64 qemu machines uses sunhme network hardware by default, so for
simple NFS boot testing using qemu, having CONFIG_HAPPYMEAL is useful.
And so we need also IP_PNP_DHCP for NFS boot.
For the same reason we need to enable its storage which is a PATA_CMD64.
And finally, we need CONFIG_DEVTMPFS for handling recent udev/systemd.

All those options will permit to enable boot testing in both kernelCI
and gentoo's kernelCI.

Signed-off-by: Corentin Labbe 
---
Changes since v1:
- Added CONFIG_DEVTMPFS for udev
- Changed PCNET32 to HAPPYMEAL, as the default netword card is sunhme

 arch/sparc/configs/sparc64_defconfig | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/arch/sparc/configs/sparc64_defconfig 
b/arch/sparc/configs/sparc64_defconfig
index bde4d21a8ac8..439ec8bc6dca 100644
--- a/arch/sparc/configs/sparc64_defconfig
+++ b/arch/sparc/configs/sparc64_defconfig
@@ -236,3 +236,9 @@ CONFIG_CRYPTO_TWOFISH=m
 CONFIG_CRC16=m
 CONFIG_LIBCRC32C=m
 CONFIG_VCC=m
+CONFIG_ATA=y
+CONFIG_PATA_CMD64X=y
+CONFIG_HAPPYMEAL=y
+CONFIG_IP_PNP=y
+CONFIG_IP_PNP_DHCP=y
+CONFIG_DEVTMPFS=y
-- 
2.26.2



Re: r8a77950-salvator-x does nto boot since cfa7ede20f133cc81cef01dc3a516dda3a9721ee arm64: set TEXT_OFFSET to 0x0 in preparation for removing it entirely

2021-01-05 Thread Corentin Labbe
Le Tue, Jan 05, 2021 at 11:13:03AM +0100, Geert Uytterhoeven a écrit :
> Hi Corentin,
> 
> On Tue, Jan 5, 2021 at 10:52 AM Corentin Labbe
>  wrote:
> > Due to DTB renaming, salvatorX was not booted since a long time in kernelCI.
> > Now the rename is handled, the board fail to boot.
> >
> > I have bisected the problem:
> 
> > # first bad commit: [cfa7ede20f133cc81cef01dc3a516dda3a9721ee] arm64: set 
> > TEXT_OFFSET to 0x0 in preparation for removing it entirely
> >
> > This is the interesting part of uboot log:
> > [0.000292] NOTI[0.000292] NOTICE:  BL2: R-Car Gen3 Initial Program 
> > Loader(CA57) Rev.1.0.16
> > [0.005855] NOTICE:  BL2: PRR is R-Car H3 Ver1.1
> > [0.010437] NOTICE:  BL2: Board is Salvator-X Rev1.0
> > [0.015379] NOTICE:  BL2: Boot device is HyperFlash(80MHz)
> > [0.020804] NOTICE:  BL2: LCM state is CM
> > [0.024847] NOTICE:  BL2: AVS setting succeeded. DVFS_SetVID=0x53
> > [0.030891] NOTICE:  BL2: DDR1600(rev.0.27)NOTICE:  [COLD_BOOT]NOTICE:  
> > ..0
> > [0.066311] NOTICE:  BL2: DRAM Split is 4ch
> > [0.070195] NOTICE:  BL2: QoS is default setting(rev.0.37)
> > [0.075697] NOTICE:  BL2: Lossy Decomp areas
> > [0.079872] NOTICE:   Entry 0: DCMPAREACRAx:0x8540 
> > DCMPAREACRBx:0x570
> > [0.086957] NOTICE:   Entry 1: DCMPAREACRAx:0x4000 
> > DCMPAREACRBx:0x0
> > [0.093869] NOTICE:   Entry 2: DCMPAREACRAx:0x2000 
> > DCMPAREACRBx:0x0
> > [0.100785] NOTICE:  BL2: v1.3(release):b330e0e
> > [0.105274] NOTICE:  BL2: Built : 15:26:51, Dec  6 2017
> > [0.110462] NOTICE:  BL2: Normal boot
> > [0.114103] NOTICE:  BL2: dst=0xe6320208 src=0x818 len=512(0x200)
> > [0.120652] NOTICE:  BL2: dst=0x43f0 src=0x8180400 len=6144(0x1800)
> > [0.127110] NOTICE:  BL2: dst=0x4400 src=0x81c len=65536(0x1)
> > [0.134336] NOTICE:  BL2: dst=0x4410 src=0x820 
> > len=524288(0x8)
> > [0.144816] NOTICE:  BL2: dst=0x5000 src=0x864 
> > len=1048576(0x10)
> > U-Boot 2015.04 (Dec 06 2017 - 15:26:59)
> > CPU: Renesas Electronics R8A7795 rev 1.1
> > Board: Salvator-X
> > I2C:   ready
> > DRAM:  3.9 GiB
> > MMC:   sh-sdhi: 0, sh-sdhi: 1, sh-sdhi: 2
> > In:serial
> > Out:   serial
> > Err:   serial
> > Net:   ravb
> >
> > [...]
> >
> > booti 0x4808 0x4a00 0x4800
>  ^
> I take it this is the problem?
> 
> For R-Car H3 ES1.0, I currently use the addresses below:
> 
> tftpboot 0x6000 h3-salvator-x/Image
> tftpboot 0x6800 h3-salvator-x/r8a77950-salvator-x.dtb
> booti 0x6000 - 0x6800
> 
> For R-Car H3 ES2.0 (and other R-Car Gen3 SoCs), I use other addresses:
> 
> tftpboot 0x5000 h3-salvator-xs/Image
> tftpboot 0x5800 h3-salvator-xs/r8a77951-salvator-xs.dtb
> booti 0x5000 - 0x5800
> 
> The firmware on your H3 ES1.1 board (Rev.1.0.16) is newer than on my
> ES1.0 board (Rev.1.0.12), so it's possible the second version works on
> your board, too.
> 
> If these work for you, I'll update 
> https://elinux.org/R-Car/Boards/Salvator-X[S]
> 

Hello

Thanks, changing kernel/dtb address made it boot.
when testing, I have also discovered that r8a7796-m3ulcb hit the same issue 
than the salvatorX and that thoses address made it boot.

Regards


r8a77950-salvator-x does nto boot since cfa7ede20f133cc81cef01dc3a516dda3a9721ee arm64: set TEXT_OFFSET to 0x0 in preparation for removing it entirely

2021-01-05 Thread Corentin Labbe
Hello

Due to DTB renaming, salvatorX was not booted since a long time in kernelCI.
Now the rename is handled, the board fail to boot.

I have bisected the problem:
git bisect start
# good: [6b9830fecd4a87d7ebb4d93484fef00f46d0fa0f] Linux 5.7.19
git bisect good 6b9830fecd4a87d7ebb4d93484fef00f46d0fa0f
# bad: [ab435ce49bd1d02e33dfec24f76955dc1196970b] Linux 5.8.18
git bisect bad ab435ce49bd1d02e33dfec24f76955dc1196970b
# good: [3d77e6a8804abcc0504c904bd6e5cdf3a5cf8162] Linux 5.7
git bisect good 3d77e6a8804abcc0504c904bd6e5cdf3a5cf8162
# bad: [7ae77150d94d3b535c7b85e6b3647113095e79bf] Merge tag 'powerpc-5.8-1' of 
git://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux
git bisect bad 7ae77150d94d3b535c7b85e6b3647113095e79bf
# bad: [2e63f6ce7ed2c4ff83ba30ad9ccad422289a6c63] Merge branch 'uaccess.comedi' 
of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
git bisect bad 2e63f6ce7ed2c4ff83ba30ad9ccad422289a6c63
# bad: [cfa3b8068b09f25037146bfd5eed041b78878bee] Merge tag 'for-linus-hmm' of 
git://git.kernel.org/pub/scm/linux/kernel/git/rdma/rdma
git bisect bad cfa3b8068b09f25037146bfd5eed041b78878bee
# good: [17e0a7cb6a254c6d086562e7adf8b7ac24d267f3] Merge tag 
'x86-cleanups-2020-06-01' of 
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
git bisect good 17e0a7cb6a254c6d086562e7adf8b7ac24d267f3
# bad: [17839856fd588f4ab6b789f482ed3ffd7c403e1f] gup: document and work around 
"COW can break either way" issue
git bisect bad 17839856fd588f4ab6b789f482ed3ffd7c403e1f
# bad: [c2b0fc847f3122e5a4176c3772626a7a8facced0] Merge tag 'for-linus' of 
git://git.armlinux.org.uk/~rmk/linux-arm
git bisect bad c2b0fc847f3122e5a4176c3772626a7a8facced0
# bad: [342403bcb4dfe41324a0f6f4cb5a8d324f31c725] Merge branches 
'for-next/acpi', 'for-next/bpf', 'for-next/cpufeature', 'for-next/docs', 
'for-next/kconfig', 'for-next/misc', 'for-next/perf', 'for-next/ptr-auth', 
'for-next/sdei', 'for-next/smccc' and 'for-next/vdso' into for-next/core
git bisect bad 342403bcb4dfe41324a0f6f4cb5a8d324f31c725
# good: [b130a8f70cbbf907c399799bd1073a78763ca0e7] KVM: arm64: Check advertised 
Stage-2 page size capability
git bisect good b130a8f70cbbf907c399799bd1073a78763ca0e7
# bad: [4fc92254bf86b19ac1ef81f61f4e690fccfcba4a] arm64: mm: Add 
asid_gen_match() helper
git bisect bad 4fc92254bf86b19ac1ef81f61f4e690fccfcba4a
# bad: [9d2d75ede59bc1edd8561f2ee9d4702a5ea0ae30] arm64/kernel: Fix range on 
invalidating dcache for boot page tables
git bisect bad 9d2d75ede59bc1edd8561f2ee9d4702a5ea0ae30
# good: [0dd2334fd5b99e610ceccba0e5263e6969207880] arm64: entry: remove 
unneeded semicolon in el1_sync_handler()
git bisect good 0dd2334fd5b99e610ceccba0e5263e6969207880
# good: [68ecabd0e680a4ceaf950ae189a55d4730d10c64] arm64/mm: Use phys_to_page() 
to access pgtable memory
git bisect good 68ecabd0e680a4ceaf950ae189a55d4730d10c64
# bad: [cfa7ede20f133cc81cef01dc3a516dda3a9721ee] arm64: set TEXT_OFFSET to 0x0 
in preparation for removing it entirely
git bisect bad cfa7ede20f133cc81cef01dc3a516dda3a9721ee
# good: [30218da5974ceb29c913e53296577526cb742a7e] arm64: lib: Consistently 
enable crc32 extension
git bisect good 30218da5974ceb29c913e53296577526cb742a7e
# first bad commit: [cfa7ede20f133cc81cef01dc3a516dda3a9721ee] arm64: set 
TEXT_OFFSET to 0x0 in preparation for removing it entirely

This is the interesting part of uboot log:
[0.000292] NOTI[0.000292] NOTICE:  BL2: R-Car Gen3 Initial Program 
Loader(CA57) Rev.1.0.16
[0.005855] NOTICE:  BL2: PRR is R-Car H3 Ver1.1
[0.010437] NOTICE:  BL2: Board is Salvator-X Rev1.0
[0.015379] NOTICE:  BL2: Boot device is HyperFlash(80MHz)
[0.020804] NOTICE:  BL2: LCM state is CM
[0.024847] NOTICE:  BL2: AVS setting succeeded. DVFS_SetVID=0x53
[0.030891] NOTICE:  BL2: DDR1600(rev.0.27)NOTICE:  [COLD_BOOT]NOTICE:  ..0
[0.066311] NOTICE:  BL2: DRAM Split is 4ch
[0.070195] NOTICE:  BL2: QoS is default setting(rev.0.37)
[0.075697] NOTICE:  BL2: Lossy Decomp areas
[0.079872] NOTICE:   Entry 0: DCMPAREACRAx:0x8540 DCMPAREACRBx:0x570
[0.086957] NOTICE:   Entry 1: DCMPAREACRAx:0x4000 DCMPAREACRBx:0x0
[0.093869] NOTICE:   Entry 2: DCMPAREACRAx:0x2000 DCMPAREACRBx:0x0
[0.100785] NOTICE:  BL2: v1.3(release):b330e0e
[0.105274] NOTICE:  BL2: Built : 15:26:51, Dec  6 2017
[0.110462] NOTICE:  BL2: Normal boot
[0.114103] NOTICE:  BL2: dst=0xe6320208 src=0x818 len=512(0x200)
[0.120652] NOTICE:  BL2: dst=0x43f0 src=0x8180400 len=6144(0x1800)
[0.127110] NOTICE:  BL2: dst=0x4400 src=0x81c len=65536(0x1)
[0.134336] NOTICE:  BL2: dst=0x4410 src=0x820 len=524288(0x8)
[0.144816] NOTICE:  BL2: dst=0x5000 src=0x864 len=1048576(0x10)
U-Boot 2015.04 (Dec 06 2017 - 15:26:59)
CPU: Renesas Electronics R8A7795 rev 1.1
Board: Salvator-X
I2C:   ready
DRAM:  3.9 GiB
MMC:   sh-sdhi: 0, sh-sdhi: 1, sh-sdhi: 2
In:serial
Out:   serial
Err:   serial
Net:   ravb

[...]

booti 0x4808 

[PATCH RESEND] ARM: configs: sunxi: enable brcm wireless

2020-12-27 Thread Corentin Labbe
Lot of sunxi boards have BRCM wireless device, so let's enable necessary
options for it in our defconfig.

Signed-off-by: Corentin Labbe 
---
 arch/arm/configs/sunxi_defconfig | 23 ++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/arch/arm/configs/sunxi_defconfig b/arch/arm/configs/sunxi_defconfig
index a60c134c5e04..4891aefdef7d 100644
--- a/arch/arm/configs/sunxi_defconfig
+++ b/arch/arm/configs/sunxi_defconfig
@@ -52,7 +52,28 @@ CONFIG_STMMAC_ETH=y
 # CONFIG_NET_VENDOR_WIZNET is not set
 CONFIG_MICREL_PHY=y
 CONFIG_REALTEK_PHY=y
-# CONFIG_WLAN is not set
+CONFIG_WLAN=y
+# CONFIG_WLAN_VENDOR_ADMTEK is not set
+# CONFIG_WLAN_VENDOR_ATH is not set
+# CONFIG_WLAN_VENDOR_ATMEL is not set
+CONFIG_WLAN_VENDOR_BROADCOM=y
+# CONFIG_WLAN_VENDOR_CISCO is not set
+# CONFIG_WLAN_VENDOR_INTEL is not set
+# CONFIG_WLAN_VENDOR_INTERSIL is not set
+# CONFIG_WLAN_VENDOR_MARVELL is not set
+# CONFIG_WLAN_VENDOR_MEDIATEK is not set
+# CONFIG_WLAN_VENDOR_MICROCHIP is not set
+# CONFIG_WLAN_VENDOR_RALINK is not set
+# CONFIG_WLAN_VENDOR_REALTEK is not set
+# CONFIG_WLAN_VENDOR_RSI is not set
+# CONFIG_WLAN_VENDOR_ST is not set
+# CONFIG_WLAN_VENDOR_TI is not set
+# CONFIG_WLAN_VENDOR_ZYDAS is not set
+# CONFIG_WLAN_VENDOR_QUANTENNA is not set
+CONFIG_CFG80211=y
+CONFIG_CFG80211_WEXT=y
+CONFIG_MAC80211=y
+CONFIG_BRCMFMAC=y
 CONFIG_INPUT_EVDEV=y
 CONFIG_KEYBOARD_SUN4I_LRADC=y
 # CONFIG_INPUT_MOUSE is not set
-- 
2.26.2



[PATCH v4 5/8] crypto: sun4i-ss: initialize need_fallback

2020-12-14 Thread Corentin Labbe
The need_fallback is never initialized and seem to be always true at runtime.
So all hardware operations are always bypassed.

Fixes: 0ae1f46c55f87 ("crypto: sun4i-ss - fallback when length is not multiple 
of blocksize")
Cc: 
Signed-off-by: Corentin Labbe 
---
 drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c 
b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
index e097f4c3e68f..5759fa79f293 100644
--- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
+++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
@@ -179,7 +179,7 @@ static int sun4i_ss_cipher_poll(struct skcipher_request 
*areq)
unsigned int obo = 0;   /* offset in bufo*/
unsigned int obl = 0;   /* length of data in bufo */
unsigned long flags;
-   bool need_fallback;
+   bool need_fallback = false;
 
if (!areq->cryptlen)
return 0;
-- 
2.26.2



[PATCH v4 4/8] crypto: sun4i-ss: handle BigEndian for cipher

2020-12-14 Thread Corentin Labbe
Ciphers produce invalid results on BE.
Key and IV need to be written in LE.

Fixes: 6298e948215f2 ("crypto: sunxi-ss - Add Allwinner Security System crypto 
accelerator")
Cc: 
Signed-off-by: Corentin Labbe 
---
 drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c 
b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
index c7bf731dad7b..e097f4c3e68f 100644
--- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
+++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
@@ -52,13 +52,13 @@ static int noinline_for_stack sun4i_ss_opti_poll(struct 
skcipher_request *areq)
 
spin_lock_irqsave(>slock, flags);
 
-   for (i = 0; i < op->keylen; i += 4)
-   writel(*(op->key + i / 4), ss->base + SS_KEY0 + i);
+   for (i = 0; i < op->keylen / 4; i++)
+   writesl(ss->base + SS_KEY0 + i * 4, >key[i], 1);
 
if (areq->iv) {
for (i = 0; i < 4 && i < ivsize / 4; i++) {
v = *(u32 *)(areq->iv + i * 4);
-   writel(v, ss->base + SS_IV0 + i * 4);
+   writesl(ss->base + SS_IV0 + i * 4, , 1);
}
}
writel(mode, ss->base + SS_CTL);
@@ -223,13 +223,13 @@ static int sun4i_ss_cipher_poll(struct skcipher_request 
*areq)
 
spin_lock_irqsave(>slock, flags);
 
-   for (i = 0; i < op->keylen; i += 4)
-   writel(*(op->key + i / 4), ss->base + SS_KEY0 + i);
+   for (i = 0; i < op->keylen / 4; i++)
+   writesl(ss->base + SS_KEY0 + i * 4, >key[i], 1);
 
if (areq->iv) {
for (i = 0; i < 4 && i < ivsize / 4; i++) {
v = *(u32 *)(areq->iv + i * 4);
-   writel(v, ss->base + SS_IV0 + i * 4);
+   writesl(ss->base + SS_IV0 + i * 4, , 1);
}
}
writel(mode, ss->base + SS_CTL);
-- 
2.26.2



[PATCH v4 8/8] crypto: sun4i-ss: add SPDX header and remove blank lines

2020-12-14 Thread Corentin Labbe
This patchs fixes some remaining style issue.

Signed-off-by: Corentin Labbe 
Signed-off-by: Corentin Labbe 
---
 drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c | 3 ---
 drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c   | 1 +
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c 
b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
index d5275d914d09..c2e6f5ed1d79 100644
--- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
+++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
@@ -148,7 +148,6 @@ static int noinline_for_stack sun4i_ss_opti_poll(struct 
skcipher_request *areq)
return err;
 }
 
-
 static int noinline_for_stack sun4i_ss_cipher_poll_fallback(struct 
skcipher_request *areq)
 {
struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq);
@@ -562,7 +561,6 @@ int sun4i_ss_cipher_init(struct crypto_tfm *tfm)
sizeof(struct sun4i_cipher_req_ctx) +
crypto_skcipher_reqsize(op->fallback_tfm));
 
-
err = pm_runtime_get_sync(op->ss->dev);
if (err < 0)
goto error_pm;
@@ -649,5 +647,4 @@ int sun4i_ss_des3_setkey(struct crypto_skcipher *tfm, const 
u8 *key,
crypto_skcipher_set_flags(op->fallback_tfm, tfm->base.crt_flags & 
CRYPTO_TFM_REQ_MASK);
 
return crypto_skcipher_setkey(op->fallback_tfm, key, keylen);
-
 }
diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c 
b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c
index 152841076e3a..443160a114bb 100644
--- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c
+++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 #include "sun4i-ss.h"
 
 int sun4i_ss_prng_seed(struct crypto_rng *tfm, const u8 *seed,
-- 
2.26.2



[PATCH v4 7/8] crypto: sun4i-ss: enabled stats via debugfs

2020-12-14 Thread Corentin Labbe
This patch enable to access usage stats for each algorithm.

Signed-off-by: Corentin Labbe 
---
 drivers/crypto/allwinner/Kconfig  |  9 
 .../allwinner/sun4i-ss/sun4i-ss-cipher.c  | 20 +++
 .../crypto/allwinner/sun4i-ss/sun4i-ss-core.c | 52 +++
 .../crypto/allwinner/sun4i-ss/sun4i-ss-hash.c |  6 +++
 .../crypto/allwinner/sun4i-ss/sun4i-ss-prng.c |  5 ++
 drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h  |  6 +++
 6 files changed, 98 insertions(+)

diff --git a/drivers/crypto/allwinner/Kconfig b/drivers/crypto/allwinner/Kconfig
index 3bd917584754..16eb42140e28 100644
--- a/drivers/crypto/allwinner/Kconfig
+++ b/drivers/crypto/allwinner/Kconfig
@@ -51,6 +51,15 @@ config CRYPTO_DEV_SUN4I_SS_PRNG
  Select this option if you want to provide kernel-side support for
  the Pseudo-Random Number Generator found in the Security System.
 
+config CRYPTO_DEV_SUN4I_SS_DEBUG
+   bool "Enable sun4i-ss stats"
+   depends on CRYPTO_DEV_SUN4I_SS
+   depends on DEBUG_FS
+   help
+ Say y to enable sun4i-ss debug stats.
+ This will create /sys/kernel/debug/sun4i-ss/stats for displaying
+ the number of requests per algorithm.
+
 config CRYPTO_DEV_SUN8I_CE
tristate "Support for Allwinner Crypto Engine cryptographic offloader"
select CRYPTO_SKCIPHER
diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c 
b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
index ffa628c89e21..d5275d914d09 100644
--- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
+++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
@@ -36,6 +36,8 @@ static int noinline_for_stack sun4i_ss_opti_poll(struct 
skcipher_request *areq)
struct sg_mapping_iter mi, mo;
unsigned int oi, oo; /* offset for in and out */
unsigned long flags;
+   struct skcipher_alg *alg = crypto_skcipher_alg(tfm);
+   struct sun4i_ss_alg_template *algt;
 
if (!areq->cryptlen)
return 0;
@@ -52,6 +54,12 @@ static int noinline_for_stack sun4i_ss_opti_poll(struct 
skcipher_request *areq)
scatterwalk_map_and_copy(backup_iv, areq->src, areq->cryptlen - 
ivsize, ivsize, 0);
}
 
+   if (IS_ENABLED(CONFIG_CRYPTO_DEV_SUN4I_SS_DEBUG)) {
+   algt = container_of(alg, struct sun4i_ss_alg_template, 
alg.crypto);
+   algt->stat_opti++;
+   algt->stat_bytes += areq->cryptlen;
+   }
+
spin_lock_irqsave(>slock, flags);
 
for (i = 0; i < op->keylen / 4; i++)
@@ -147,6 +155,13 @@ static int noinline_for_stack 
sun4i_ss_cipher_poll_fallback(struct skcipher_requ
struct sun4i_tfm_ctx *op = crypto_skcipher_ctx(tfm);
struct sun4i_cipher_req_ctx *ctx = skcipher_request_ctx(areq);
int err;
+   struct skcipher_alg *alg = crypto_skcipher_alg(tfm);
+   struct sun4i_ss_alg_template *algt;
+
+   if (IS_ENABLED(CONFIG_CRYPTO_DEV_SUN4I_SS_DEBUG)) {
+   algt = container_of(alg, struct sun4i_ss_alg_template, 
alg.crypto);
+   algt->stat_fb++;
+   }
 
skcipher_request_set_tfm(>fallback_req, op->fallback_tfm);
skcipher_request_set_callback(>fallback_req, areq->base.flags,
@@ -236,6 +251,11 @@ static int sun4i_ss_cipher_poll(struct skcipher_request 
*areq)
scatterwalk_map_and_copy(backup_iv, areq->src, areq->cryptlen - 
ivsize, ivsize, 0);
}
 
+   if (IS_ENABLED(CONFIG_CRYPTO_DEV_SUN4I_SS_DEBUG)) {
+   algt->stat_req++;
+   algt->stat_bytes += areq->cryptlen;
+   }
+
spin_lock_irqsave(>slock, flags);
 
for (i = 0; i < op->keylen / 4; i++)
diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-core.c 
b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-core.c
index a2b67f7f8a81..709905ec4680 100644
--- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-core.c
+++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-core.c
@@ -10,6 +10,7 @@
  */
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -234,6 +235,51 @@ static struct sun4i_ss_alg_template ss_algs[] = {
 #endif
 };
 
+static int sun4i_ss_dbgfs_read(struct seq_file *seq, void *v)
+{
+   unsigned int i;
+
+   for (i = 0; i < ARRAY_SIZE(ss_algs); i++) {
+   if (!ss_algs[i].ss)
+   continue;
+   switch (ss_algs[i].type) {
+   case CRYPTO_ALG_TYPE_SKCIPHER:
+   seq_printf(seq, "%s %s reqs=%lu opti=%lu fallback=%lu 
tsize=%lu\n",
+  ss_algs[i].alg.crypto.base.cra_driver_name,
+  ss_algs[i].alg.crypto.base.cra_name,
+  ss_algs[i].stat_req, ss_algs[i].stat_opti, 
ss_algs[i].stat_fb,
+  ss_algs[i].stat_bytes);
+   break;
+ 

[PATCH v4 6/8] crypto: sun4i-ss: fix kmap usage

2020-12-14 Thread Corentin Labbe
With the recent kmap change, some tests which were conditional on
CONFIG_DEBUG_HIGHMEM now are enabled by default.
This permit to detect a problem in sun4i-ss usage of kmap.

sun4i-ss uses two kmap via sg_miter (one for input, one for output), but
using two kmap at the same time is hard:
"the ordering has to be correct and with sg_miter that's probably hard to get
right." (quoting Tlgx)

So the easiest solution is to never have two sg_miter/kmap open at the same 
time.
After each use of sg_miter, I store the current index, for being able to
resume sg_miter to the right place.

Fixes: 6298e948215f ("crypto: sunxi-ss - Add Allwinner Security System crypto 
accelerator")
Signed-off-by: Corentin Labbe 
---
 .../allwinner/sun4i-ss/sun4i-ss-cipher.c  | 109 +++---
 1 file changed, 65 insertions(+), 44 deletions(-)

diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c 
b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
index 5759fa79f293..ffa628c89e21 100644
--- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
+++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
@@ -31,6 +31,8 @@ static int noinline_for_stack sun4i_ss_opti_poll(struct 
skcipher_request *areq)
unsigned int ileft = areq->cryptlen;
unsigned int oleft = areq->cryptlen;
unsigned int todo;
+   unsigned long pi = 0, po = 0; /* progress for in and out */
+   bool miter_err;
struct sg_mapping_iter mi, mo;
unsigned int oi, oo; /* offset for in and out */
unsigned long flags;
@@ -63,39 +65,51 @@ static int noinline_for_stack sun4i_ss_opti_poll(struct 
skcipher_request *areq)
}
writel(mode, ss->base + SS_CTL);
 
-   sg_miter_start(, areq->src, sg_nents(areq->src),
-  SG_MITER_FROM_SG | SG_MITER_ATOMIC);
-   sg_miter_start(, areq->dst, sg_nents(areq->dst),
-  SG_MITER_TO_SG | SG_MITER_ATOMIC);
-   sg_miter_next();
-   sg_miter_next();
-   if (!mi.addr || !mo.addr) {
-   dev_err_ratelimited(ss->dev, "ERROR: sg_miter return null\n");
-   err = -EINVAL;
-   goto release_ss;
-   }
 
ileft = areq->cryptlen / 4;
oleft = areq->cryptlen / 4;
oi = 0;
oo = 0;
do {
-   todo = min(rx_cnt, ileft);
-   todo = min_t(size_t, todo, (mi.length - oi) / 4);
-   if (todo) {
-   ileft -= todo;
-   writesl(ss->base + SS_RXFIFO, mi.addr + oi, todo);
-   oi += todo * 4;
-   }
-   if (oi == mi.length) {
-   sg_miter_next();
-   oi = 0;
+   if (ileft) {
+   sg_miter_start(, areq->src, sg_nents(areq->src),
+   SG_MITER_FROM_SG | SG_MITER_ATOMIC);
+   if (pi)
+   sg_miter_skip(, pi);
+   miter_err = sg_miter_next();
+   if (!miter_err || !mi.addr) {
+   dev_err_ratelimited(ss->dev, "ERROR: sg_miter 
return null\n");
+   err = -EINVAL;
+   goto release_ss;
+   }
+   todo = min(rx_cnt, ileft);
+   todo = min_t(size_t, todo, (mi.length - oi) / 4);
+   if (todo) {
+   ileft -= todo;
+   writesl(ss->base + SS_RXFIFO, mi.addr + oi, 
todo);
+   oi += todo * 4;
+   }
+   if (oi == mi.length) {
+   pi += mi.length;
+   oi = 0;
+   }
+   sg_miter_stop();
}
 
spaces = readl(ss->base + SS_FCSR);
rx_cnt = SS_RXFIFO_SPACES(spaces);
tx_cnt = SS_TXFIFO_SPACES(spaces);
 
+   sg_miter_start(, areq->dst, sg_nents(areq->dst),
+  SG_MITER_TO_SG | SG_MITER_ATOMIC);
+   if (po)
+   sg_miter_skip(, po);
+   miter_err = sg_miter_next();
+   if (!miter_err || !mo.addr) {
+   dev_err_ratelimited(ss->dev, "ERROR: sg_miter return 
null\n");
+   err = -EINVAL;
+   goto release_ss;
+   }
todo = min(tx_cnt, oleft);
todo = min_t(size_t, todo, (mo.length - oo) / 4);
if (todo) {
@@ -104,9 +118,10 @@ static int noinline_for_stack sun4i_ss_opti_poll(struct 
skcipher_request *areq)
oo += todo * 4;
}
if (oo == mo.length) {
-

[PATCH v4 3/8] crypto: sun4i-ss: IV register does not work on A10 and A13

2020-12-14 Thread Corentin Labbe
Allwinner A10 and A13 SoC have a version of the SS which produce
invalid IV in IVx register.

Instead of adding a variant for those, let's convert SS to produce IV
directly from data.
Fixes: 6298e948215f2 ("crypto: sunxi-ss - Add Allwinner Security System crypto 
accelerator")
Cc: 
Signed-off-by: Corentin Labbe 
---
 .../allwinner/sun4i-ss/sun4i-ss-cipher.c  | 34 +++
 1 file changed, 28 insertions(+), 6 deletions(-)

diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c 
b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
index f49797588329..c7bf731dad7b 100644
--- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
+++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
@@ -20,6 +20,7 @@ static int noinline_for_stack sun4i_ss_opti_poll(struct 
skcipher_request *areq)
unsigned int ivsize = crypto_skcipher_ivsize(tfm);
struct sun4i_cipher_req_ctx *ctx = skcipher_request_ctx(areq);
u32 mode = ctx->mode;
+   void *backup_iv = NULL;
/* when activating SS, the default FIFO space is SS_RX_DEFAULT(32) */
u32 rx_cnt = SS_RX_DEFAULT;
u32 tx_cnt = 0;
@@ -42,6 +43,13 @@ static int noinline_for_stack sun4i_ss_opti_poll(struct 
skcipher_request *areq)
return -EINVAL;
}
 
+   if (areq->iv && ivsize > 0 && mode & SS_DECRYPTION) {
+   backup_iv = kzalloc(ivsize, GFP_KERNEL);
+   if (!backup_iv)
+   return -ENOMEM;
+   scatterwalk_map_and_copy(backup_iv, areq->src, areq->cryptlen - 
ivsize, ivsize, 0);
+   }
+
spin_lock_irqsave(>slock, flags);
 
for (i = 0; i < op->keylen; i += 4)
@@ -102,9 +110,12 @@ static int noinline_for_stack sun4i_ss_opti_poll(struct 
skcipher_request *areq)
} while (oleft);
 
if (areq->iv) {
-   for (i = 0; i < 4 && i < ivsize / 4; i++) {
-   v = readl(ss->base + SS_IV0 + i * 4);
-   *(u32 *)(areq->iv + i * 4) = v;
+   if (mode & SS_DECRYPTION) {
+   memcpy(areq->iv, backup_iv, ivsize);
+   kfree_sensitive(backup_iv);
+   } else {
+   scatterwalk_map_and_copy(areq->iv, areq->dst, 
areq->cryptlen - ivsize,
+ivsize, 0);
}
}
 
@@ -161,6 +172,7 @@ static int sun4i_ss_cipher_poll(struct skcipher_request 
*areq)
unsigned int ileft = areq->cryptlen;
unsigned int oleft = areq->cryptlen;
unsigned int todo;
+   void *backup_iv = NULL;
struct sg_mapping_iter mi, mo;
unsigned int oi, oo;/* offset for in and out */
unsigned int ob = 0;/* offset in buf */
@@ -202,6 +214,13 @@ static int sun4i_ss_cipher_poll(struct skcipher_request 
*areq)
if (need_fallback)
return sun4i_ss_cipher_poll_fallback(areq);
 
+   if (areq->iv && ivsize > 0 && mode & SS_DECRYPTION) {
+   backup_iv = kzalloc(ivsize, GFP_KERNEL);
+   if (!backup_iv)
+   return -ENOMEM;
+   scatterwalk_map_and_copy(backup_iv, areq->src, areq->cryptlen - 
ivsize, ivsize, 0);
+   }
+
spin_lock_irqsave(>slock, flags);
 
for (i = 0; i < op->keylen; i += 4)
@@ -322,9 +341,12 @@ static int sun4i_ss_cipher_poll(struct skcipher_request 
*areq)
}
}
if (areq->iv) {
-   for (i = 0; i < 4 && i < ivsize / 4; i++) {
-   v = readl(ss->base + SS_IV0 + i * 4);
-   *(u32 *)(areq->iv + i * 4) = v;
+   if (mode & SS_DECRYPTION) {
+   memcpy(areq->iv, backup_iv, ivsize);
+   kfree_sensitive(backup_iv);
+   } else {
+   scatterwalk_map_and_copy(areq->iv, areq->dst, 
areq->cryptlen - ivsize,
+ivsize, 0);
}
}
 
-- 
2.26.2



[PATCH v4 1/8] crypto: sun4i-ss: linearize buffers content must be kept

2020-12-14 Thread Corentin Labbe
When running the non-optimized cipher function, SS produce partial random
output.
This is due to linearize buffers being reseted after each loop.

For preserving stack, instead of moving them back to start of function,
I move them in sun4i_ss_ctx.

Fixes: 8d3bcb9900ca ("crypto: sun4i-ss - reduce stack usage")
Signed-off-by: Corentin Labbe 
---
 drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c | 12 
 drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h|  2 ++
 2 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c 
b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
index b72de8939497..19f1aa577ed4 100644
--- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
+++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
@@ -233,8 +233,6 @@ static int sun4i_ss_cipher_poll(struct skcipher_request 
*areq)
 
while (oleft) {
if (ileft) {
-   char buf[4 * SS_RX_MAX];/* buffer for linearize SG src 
*/
-
/*
 * todo is the number of consecutive 4byte word that we
 * can read from current SG
@@ -256,12 +254,12 @@ static int sun4i_ss_cipher_poll(struct skcipher_request 
*areq)
 */
todo = min(rx_cnt * 4 - ob, ileft);
todo = min_t(size_t, todo, mi.length - oi);
-   memcpy(buf + ob, mi.addr + oi, todo);
+   memcpy(ss->buf + ob, mi.addr + oi, todo);
ileft -= todo;
oi += todo;
ob += todo;
if (!(ob % 4)) {
-   writesl(ss->base + SS_RXFIFO, buf,
+   writesl(ss->base + SS_RXFIFO, ss->buf,
ob / 4);
ob = 0;
}
@@ -295,13 +293,11 @@ static int sun4i_ss_cipher_poll(struct skcipher_request 
*areq)
oo = 0;
}
} else {
-   char bufo[4 * SS_TX_MAX]; /* buffer for linearize SG 
dst */
-
/*
 * read obl bytes in bufo, we read at maximum for
 * emptying the device
 */
-   readsl(ss->base + SS_TXFIFO, bufo, tx_cnt);
+   readsl(ss->base + SS_TXFIFO, ss->bufo, tx_cnt);
obl = tx_cnt * 4;
obo = 0;
do {
@@ -313,7 +309,7 @@ static int sun4i_ss_cipher_poll(struct skcipher_request 
*areq)
 */
todo = min_t(size_t,
 mo.length - oo, obl - obo);
-   memcpy(mo.addr + oo, bufo + obo, todo);
+   memcpy(mo.addr + oo, ss->bufo + obo, todo);
oleft -= todo;
obo += todo;
oo += todo;
diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h 
b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h
index 5c291e4a6857..c242fccb2ab6 100644
--- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h
+++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h
@@ -148,6 +148,8 @@ struct sun4i_ss_ctx {
struct reset_control *reset;
struct device *dev;
struct resource *res;
+   char buf[4 * SS_RX_MAX];/* buffer for linearize SG src */
+   char bufo[4 * SS_TX_MAX]; /* buffer for linearize SG dst */
spinlock_t slock; /* control the use of the device */
 #ifdef CONFIG_CRYPTO_DEV_SUN4I_SS_PRNG
u32 seed[SS_SEED_LEN / BITS_PER_LONG];
-- 
2.26.2



[PATCH v4 0/8] crypto: sun4i-ss: prevent always fallback for ciphers

2020-12-14 Thread Corentin Labbe
Hello

For help testing on "crypto: sun4i-ss - Fix sparse endianness markers",
I have added "stats" support like other allwinner's crypto drivers.
Seeing stats showed a clear problem, the ciphers function were not used
at all.
This is due to the not-inialized need_fallback which is "init" as true
everytime.
So basicly, since the patch introduced it, this probem hidden some bugs.

This serie fixes all hidden problems, then fix the initialization of
"need_fallback" and then add the stats like other allwinner drivers.

Regards

changes since v3:
- patch #2: Rewrite test as suggested by David Laight
- patch #7: removed all ifdef CONFIG_CRYPTO_DEV_SUN4I_SS_DEBUG
- added kmap patch

Changes since v2:
- patch #1: move buf/bufo out of function for reducing stack usage
- patch #4: use writesl()
- patch #6: use IS_ENABLED instead of #ifdef

Changes since v1:
- patch #4 is sufficient to fix BE problem (removed todo)

Corentin Labbe (8):
  crypto: sun4i-ss: linearize buffers content must be kept
  crypto: sun4i-ss: checking sg length is not sufficient
  crypto: sun4i-ss: IV register does not work on A10 and A13
  crypto: sun4i-ss: handle BigEndian for cipher
  crypto: sun4i-ss: initialize need_fallback
  crypto: sun4i-ss: fix kmap usage
  crypto: sun4i-ss: enabled stats via debugfs
  crypto: sun4i-ss: add SPDX header and remove blank lines

 drivers/crypto/allwinner/Kconfig  |   9 +
 .../allwinner/sun4i-ss/sun4i-ss-cipher.c  | 196 +++---
 .../crypto/allwinner/sun4i-ss/sun4i-ss-core.c |  52 +
 .../crypto/allwinner/sun4i-ss/sun4i-ss-hash.c |   6 +
 .../crypto/allwinner/sun4i-ss/sun4i-ss-prng.c |   6 +
 drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h  |   8 +
 6 files changed, 207 insertions(+), 70 deletions(-)

-- 
2.26.2



[PATCH v4 2/8] crypto: sun4i-ss: checking sg length is not sufficient

2020-12-14 Thread Corentin Labbe
The optimized cipher function need length multiple of 4 bytes.
But it get sometimes odd length.
This is due to SG data could be stored with an offset.

So the fix is to check also if the offset is aligned with 4 bytes.
Fixes: 6298e948215f2 ("crypto: sunxi-ss - Add Allwinner Security System crypto 
accelerator")
Cc: 
Signed-off-by: Corentin Labbe 
---
 drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c 
b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
index 19f1aa577ed4..f49797588329 100644
--- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
+++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
@@ -186,12 +186,12 @@ static int sun4i_ss_cipher_poll(struct skcipher_request 
*areq)
 * we can use the SS optimized function
 */
while (in_sg && no_chunk == 1) {
-   if (in_sg->length % 4)
+   if ((in_sg->length | in_sg->offset) & 3u)
no_chunk = 0;
in_sg = sg_next(in_sg);
}
while (out_sg && no_chunk == 1) {
-   if (out_sg->length % 4)
+   if ((out_sg->length | out_sg->offset) & 3u)
no_chunk = 0;
out_sg = sg_next(out_sg);
}
-- 
2.26.2



Re: crypto: sun4i-ss: error with kmap

2020-12-07 Thread Corentin Labbe
On Mon, Dec 07, 2020 at 01:15:49AM +0100, Thomas Gleixner wrote:
> On Sun, Dec 06 2020 at 22:40, Corentin Labbe wrote:
> > On Sat, Dec 05, 2020 at 08:48:15PM +0100, Thomas Gleixner wrote:
> >> So this maps two pages and unmaps the first one. That's all called from
> >> sun4i_ss_opti_poll() and the bug is clearly visible there:
> >> 
> >>sg_miter_next();
> >>sg_miter_next();
> >> 
> >> release_ss:
> >>sg_miter_stop();
> >>sg_miter_stop();
> >> 
> >> Written by yourself :) Same issue in sun4i_ss_cipher_poll()
> >> 
> >> Fix below.
> >> 
> >
> > Unfortunatly, the crash still happen with the fix.
> > See http://kernel.montjoie.ovh/131321.log
> 
> And why are you not looking for the reason of this problem in your own
> code yourself? It's not a regression caused by my work.
> 
> Turn on CONFIG_DEBUG_HIGHMEM on 5.10-rcX or older kernels and you will
> get the very same crashes. My work just made these checks unconditional.
> 
> This was broken forever and it's not my problem that you did not enable
> mandatory debug options when developing this thing.
> 
> I gave you tons of hints by now how to debug this and what to look
> for. Obviously I overlooked something and here is the final hint:
> 
>   sg_miter_next();
>   sg_miter_next();
> 
> do {
>
>if (cond1)
>sg_miter_next();  <--- HINT
>
>if (cond2)
>sg_miter_next();
>  
> release_ss:
>   sg_miter_stop();
>   sg_miter_stop();
> 
> So yes, I overlooked the obvious, but as I said above it's not something
> which my is failing due to my changes. It was broken forever, it just
> was not tested properly. Don't blame the messenger.
> 

Hello

I wasnt blaming you, I set you in TO: since you worked on kmap recently just in 
case of.
I tryed to debug myself, but since it worked before I was sure the problem was 
outside my code.

So if I understand correctly, basicly I cannot have two atomic kmap at the same 
time since it made unmapping them in the right order complex.

I am not sure to have well understood your hint, but could you give me what you 
think about the following patch which fix (at least) the crash.
Instead of holding SGmiter (and so two kmap), I use only one at a time.

Thanks for your help.

diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c 
b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
index 99a415e8a13c..4f25e76dc269 100644
--- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
+++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
@@ -36,6 +36,8 @@ static int noinline_for_stack sun4i_ss_opti_poll(struct 
skcipher_request *areq)
unsigned long flags;
struct skcipher_alg *alg = crypto_skcipher_alg(tfm);
struct sun4i_ss_alg_template *algt;
+   unsigned long toi = 0, too = 0;
+   bool miter_err;
 
if (!areq->cryptlen)
return 0;
@@ -71,39 +73,51 @@ static int noinline_for_stack sun4i_ss_opti_poll(struct 
skcipher_request *areq)
}
writel(mode, ss->base + SS_CTL);
 
-   sg_miter_start(, areq->src, sg_nents(areq->src),
-  SG_MITER_FROM_SG | SG_MITER_ATOMIC);
-   sg_miter_start(, areq->dst, sg_nents(areq->dst),
-  SG_MITER_TO_SG | SG_MITER_ATOMIC);
-   sg_miter_next();
-   sg_miter_next();
-   if (!mi.addr || !mo.addr) {
-   dev_err_ratelimited(ss->dev, "ERROR: sg_miter return null\n");
-   err = -EINVAL;
-   goto release_ss;
-   }
 
ileft = areq->cryptlen / 4;
oleft = areq->cryptlen / 4;
oi = 0;
oo = 0;
do {
-   todo = min(rx_cnt, ileft);
-   todo = min_t(size_t, todo, (mi.length - oi) / 4);
-   if (todo) {
-   ileft -= todo;
-   writesl(ss->base + SS_RXFIFO, mi.addr + oi, todo);
-   oi += todo * 4;
-   }
-   if (oi == mi.length) {
-   sg_miter_next();
-   oi = 0;
+   if (ileft) {
+   sg_miter_start(, areq->src, sg_nents(areq->src),
+   SG_MITER_FROM_SG | SG_MITER_ATOMIC);
+   if (toi)
+   sg_miter_skip(, toi);
+   miter_err = sg_miter_next();
+   if (!miter_err || !mi.addr) {
+   dev_err_ratelimited(ss->dev, "ERROR: sg_miter 
return null\n");
+   err = -EINVAL;
+   goto release_ss;
+   

Re: crypto: sun4i-ss: error with kmap

2020-12-06 Thread Corentin Labbe
On Sat, Dec 05, 2020 at 08:48:15PM +0100, Thomas Gleixner wrote:
> Corentin,
> 
> On Sat, Dec 05 2020 at 19:43, Corentin Labbe wrote:
> > On Fri, Dec 04, 2020 at 09:58:21PM +0100, Thomas Gleixner wrote:
> >> Can you please replace the debug patch with the one below and try again?
> >> That stops the trace right on the condition.
> >
> > Hello, the result could be found at http://kernel.montjoie.ovh/130739.log
> 
> Thanks for providing this. This is clearly showing where stuff goes
> wrong. It starts here at 729.550001. I removed the uninteresting parts:
> 
> 0d..2 147103293us : __kmap_local_page_prot <-sg_miter_next
> 0d..3 147103308us :__kmap_local_pfn_prot: kmap_local_pfn: 1 ffefd000
> 
> 0d..3 147103311us : __kmap_local_page_prot <-sg_miter_next
> 0d..4 147103325us : __kmap_local_pfn_prot: kmap_local_pfn: 3 ffefb000
> 
> 0d..3 147103429us : kunmap_local_indexed <-sg_miter_stop
> 0d..4 147103433us : kunmap_local_indexed: kunmap_local: 3 ffefd000
> 
> So this maps two pages and unmaps the first one. That's all called from
> sun4i_ss_opti_poll() and the bug is clearly visible there:
> 
>   sg_miter_next();
>   sg_miter_next();
> 
> release_ss:
>   sg_miter_stop();
>   sg_miter_stop();
> 
> Written by yourself :) Same issue in sun4i_ss_cipher_poll()
> 
> Fix below.
> 

Unfortunatly, the crash still happen with the fix.
See http://kernel.montjoie.ovh/131321.log


Re: crypto: sun4i-ss: error with kmap

2020-12-05 Thread Corentin Labbe
On Fri, Dec 04, 2020 at 09:58:21PM +0100, Thomas Gleixner wrote:
> On Fri, Dec 04 2020 at 20:27, Corentin Labbe wrote:
> > On Fri, Dec 04, 2020 at 04:08:27PM +0100, Thomas Gleixner wrote:
> >> On Fri, Dec 04 2020 at 14:26, Corentin Labbe wrote:
> >> > On Fri, Dec 04, 2020 at 12:34:05AM +0100, Thomas Gleixner wrote:
> >> >> The unmap comes from sg_miter_stop() and looking at the previous
> >> >> map/unmap cycles there are never nested maps.
> >> >> 
> >> >> [  996.943030] cryptset-316   0d..4 73943317us : 
> >> >> __kmap_local_pfn_prot: kmap_local_pfn: 1 ffefd000
> >> >> 
> >> >> is the first event which allocates a nested map. 
> >> >> 
> >> >> So something goes south either in sg_miter or in the crypto maze.
> >> >> 
> >> >> Enabling CONFIG_DEBUG_KMAP_LOCAL and function tracing might give us 
> >> >> more clue.
> >> >
> >> > Done, http://kernel.montjoie.ovh/130466.log
> >> 
> >> Does not provide more information with the debug enabled. So can you
> >> please enable CONFIG_FUNCTION_TRACER and add 'ftrace=function' to the
> >> command line?
> >
> > Done, http://kernel.montjoie.ovh/130490.log
> 
> Aaargh. That overwrites everything while printing out that
> warning.
> 
> Can you please replace the debug patch with the one below and try again?
> That stops the trace right on the condition.
> 
> Thanks,
> 
> tglx
> ---
> diff --git a/mm/highmem.c b/mm/highmem.c
> index b49364a306b8..8f8862f79d23 100644
> --- a/mm/highmem.c
> +++ b/mm/highmem.c
> @@ -485,6 +485,7 @@ static inline bool kmap_high_unmap_local(unsigned long 
> vaddr)
>  {
>  #ifdef ARCH_NEEDS_KMAP_HIGH_GET
>   if (vaddr >= PKMAP_ADDR(0) && vaddr < PKMAP_ADDR(LAST_PKMAP)) {
> + trace_printk("kunmap_high: %lx\n", vaddr);
>   kunmap_high(pte_page(pkmap_page_table[PKMAP_NR(vaddr)]));
>   return true;
>   }
> @@ -520,6 +521,7 @@ void *__kmap_local_pfn_prot(unsigned long pfn, pgprot_t 
> prot)
>   preempt_disable();
>   idx = arch_kmap_local_map_idx(kmap_local_idx_push(), pfn);
>   vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
> + trace_printk("kmap_local_pfn: %d %lx\n", idx, (unsigned long) vaddr);
>   BUG_ON(!pte_none(*(kmap_pte - idx)));
>   pteval = pfn_pte(pfn, prot);
>   set_pte_at(_mm, vaddr, kmap_pte - idx, pteval);
> @@ -545,8 +547,10 @@ void *__kmap_local_page_prot(struct page *page, pgprot_t 
> prot)
>  
>   /* Try kmap_high_get() if architecture has it enabled */
>   kmap = arch_kmap_local_high_get(page);
> - if (kmap)
> + if (kmap) {
> + trace_printk("kmap_local_high_get: %lx\n", (unsigned long) 
> kmap);
>   return kmap;
> + }
>  
>   return __kmap_local_pfn_prot(page_to_pfn(page), prot);
>  }
> @@ -578,7 +582,11 @@ void kunmap_local_indexed(void *vaddr)
>  
>   preempt_disable();
>   idx = arch_kmap_local_unmap_idx(kmap_local_idx(), addr);
> - WARN_ON_ONCE(addr != __fix_to_virt(FIX_KMAP_BEGIN + idx));
> + trace_printk("kunmap_local: %i %lx\n", idx, (unsigned long) vaddr);
> + if (addr != __fix_to_virt(FIX_KMAP_BEGIN + idx)) {
> + tracing_off();
> + BUG();
> + }
>  
>   arch_kmap_local_pre_unmap(addr);
>   pte_clear(_mm, addr, kmap_pte - idx);
> 

Hello, the result could be found at http://kernel.montjoie.ovh/130739.log

Thanks


Re: crypto: sun4i-ss: error with kmap

2020-12-04 Thread Corentin Labbe
On Fri, Dec 04, 2020 at 04:08:27PM +0100, Thomas Gleixner wrote:
> On Fri, Dec 04 2020 at 14:26, Corentin Labbe wrote:
> > On Fri, Dec 04, 2020 at 12:34:05AM +0100, Thomas Gleixner wrote:
> >> The unmap comes from sg_miter_stop() and looking at the previous
> >> map/unmap cycles there are never nested maps.
> >> 
> >> [  996.943030] cryptset-316   0d..4 73943317us : 
> >> __kmap_local_pfn_prot: kmap_local_pfn: 1 ffefd000
> >> 
> >> is the first event which allocates a nested map. 
> >> 
> >> So something goes south either in sg_miter or in the crypto maze.
> >> 
> >> Enabling CONFIG_DEBUG_KMAP_LOCAL and function tracing might give us more 
> >> clue.
> >
> > Done, http://kernel.montjoie.ovh/130466.log
> 
> Does not provide more information with the debug enabled. So can you
> please enable CONFIG_FUNCTION_TRACER and add 'ftrace=function' to the
> command line?
> 

Done, http://kernel.montjoie.ovh/130490.log


Re: crypto: sun4i-ss: error with kmap

2020-12-04 Thread Corentin Labbe
On Fri, Dec 04, 2020 at 12:34:05AM +0100, Thomas Gleixner wrote:
> On Thu, Dec 03 2020 at 18:38, Corentin Labbe wrote:
> > On Wed, Dec 02, 2020 at 09:59:36PM +0100, Thomas Gleixner wrote:
> >> On Wed, Dec 02 2020 at 20:55, Corentin Labbe wrote:
> >> > On Tue, Dec 01, 2020 at 04:15:08PM +0100, Thomas Gleixner wrote:
> >> >
> >> > The result could be seen at http://kernel.montjoie.ovh/129768.log
> >> > The log is 9Mb, but the ftrace dump seems not terminated, tell me if you 
> >> > need more.
> >> 
> >> Correct, the interesting entries right before the crash are missing. Can
> >> you try to make the trace buffers smaller or wait longer before
> >> terminating the thing?
> >> 
> >> 16k buffer size per CPU should be completely sufficient. That should
> >> give us roughly the last 100 entries per CPU.
> >> 
> >> 'trace_buf_size=16k'
> >> 
> >> is the command line option for that.
> >
> > I have set a longer timeout and now the job end with the crash:
> > http://kernel.montjoie.ovh/130094.log
> 
> Ok. So here is the problem:
> 
> [  996.933980] cryptset-316   0d..3 73943313us : __kmap_local_pfn_prot: 
> kmap_local_pfn: 0 ffefe000
> [  996.943030] cryptset-316   0d..4 73943317us : __kmap_local_pfn_prot: 
> kmap_local_pfn: 1 ffefd000
> [  996.952080] cryptset-316   0d..4 73943419us : kunmap_local_indexed: 
> kunmap_local: 1 ffefe000
> 
> There are two maps:
> 
>1) index 0 vaddr 0xffefe000
>2) index 1 vaddr 0xffefd000
> 
> Now comes the unmap and unmaps 0xffefe000 which is the first map and not
> the second one. -> Fail
> 
> [   74.017103] [] (kunmap_local_indexed) from [] 
> (sg_miter_stop+0xb4/0x164)
> [   74.025535] [] (sg_miter_stop) from [] 
> (sg_miter_next+0xc/0xe4)
> [   74.033191] [] (sg_miter_next) from [] 
> (sun4i_ss_opti_poll+0x278/0x40c)
> [   74.041539] [] (sun4i_ss_opti_poll) from [] 
> (sun4i_ss_cipher_poll+0x4f4/0x5e4)
> [   74.050497] [] (sun4i_ss_cipher_poll) from [] 
> (crypto_skcipher_encrypt+0x38/0x5c)
> [   74.059713] [] (crypto_skcipher_encrypt) from [] 
> (xts_encrypt+0x8c/0xd4)
> [   74.068146] [] (xts_encrypt) from [] 
> (crypto_skcipher_encrypt+0x38/0x5c)
> [   74.076581] [] (crypto_skcipher_encrypt) from [] 
> (skcipher_recvmsg+0x364/0x43c)
> [   74.085625] [] (skcipher_recvmsg) from [] 
> (sock_read_iter+0xa8/0xf8)
> [   74.093713] [] (sock_read_iter) from [] 
> (vfs_read+0x2b8/0x2d8)
> [   74.101279] [] (vfs_read) from [] (ksys_read+0xb0/0xe4)
> [   74.108237] [] (ksys_read) from [] 
> (ret_fast_syscall+0x0/0x58)
> 
> The unmap comes from sg_miter_stop() and looking at the previous
> map/unmap cycles there are never nested maps.
> 
> [  996.943030] cryptset-316   0d..4 73943317us : __kmap_local_pfn_prot: 
> kmap_local_pfn: 1 ffefd000
> 
> is the first event which allocates a nested map. 
> 
> So something goes south either in sg_miter or in the crypto maze.
> 
> Enabling CONFIG_DEBUG_KMAP_LOCAL and function tracing might give us more clue.

Done, http://kernel.montjoie.ovh/130466.log


Re: crypto: sun4i-ss: error with kmap

2020-12-03 Thread Corentin Labbe
On Wed, Dec 02, 2020 at 09:59:36PM +0100, Thomas Gleixner wrote:
> On Wed, Dec 02 2020 at 20:55, Corentin Labbe wrote:
> > On Tue, Dec 01, 2020 at 04:15:08PM +0100, Thomas Gleixner wrote:
> >
> > The result could be seen at http://kernel.montjoie.ovh/129768.log
> > The log is 9Mb, but the ftrace dump seems not terminated, tell me if you 
> > need more.
> 
> Correct, the interesting entries right before the crash are missing. Can
> you try to make the trace buffers smaller or wait longer before
> terminating the thing?
> 
> 16k buffer size per CPU should be completely sufficient. That should
> give us roughly the last 100 entries per CPU.
> 
> 'trace_buf_size=16k'
> 
> is the command line option for that.
> 

I have set a longer timeout and now the job end with the crash:
http://kernel.montjoie.ovh/130094.log


Re: crypto: sun4i-ss: error with kmap

2020-12-02 Thread Corentin Labbe
On Tue, Dec 01, 2020 at 04:15:08PM +0100, Thomas Gleixner wrote:
> On Tue, Dec 01 2020 at 15:45, Corentin Labbe wrote:
> > On Tue, Dec 01, 2020 at 03:16:36PM +0100, Thomas Gleixner wrote:
> > In fact the warn was a bit later so I added:
> >preempt_disable();
> > idx = arch_kmap_local_unmap_idx(kmap_local_idx(), addr);
> > -   WARN_ON_ONCE(addr != __fix_to_virt(FIX_KMAP_BEGIN + idx));
> > +   if (WARN_ON_ONCE(addr != __fix_to_virt(FIX_KMAP_BEGIN + idx)))
> > +   pr_err("kunmap_local: vaddr %lx\n", (unsigned long) vaddr);
> >  
> > arch_kmap_local_pre_unmap(addr);
> > pte_clear(_mm, addr, kmap_pte - idx);
> >
> > and this give kunmap_local: vaddr ffefe000
> 
> which looks like a valid one.
> 
> Can you apply the patch below and add 'ftrace_dump_on_oops' on the
> command line or enable it in /proc/sys/kernel/ftrace_dump_on_oops before
> starting the test.
> 
> That should spill out the trace after crashing.
> 
> Thanks,
> 
> tglx
> ---
> diff --git a/mm/highmem.c b/mm/highmem.c
> index b49364a306b8..461fe2c26107 100644
> --- a/mm/highmem.c
> +++ b/mm/highmem.c
> @@ -485,6 +485,7 @@ static inline bool kmap_high_unmap_local(unsigned long 
> vaddr)
>  {
>  #ifdef ARCH_NEEDS_KMAP_HIGH_GET
>   if (vaddr >= PKMAP_ADDR(0) && vaddr < PKMAP_ADDR(LAST_PKMAP)) {
> + trace_printk("kunmap_high: %lx\n", vaddr);
>   kunmap_high(pte_page(pkmap_page_table[PKMAP_NR(vaddr)]));
>   return true;
>   }
> @@ -520,6 +521,7 @@ void *__kmap_local_pfn_prot(unsigned long pfn, pgprot_t 
> prot)
>   preempt_disable();
>   idx = arch_kmap_local_map_idx(kmap_local_idx_push(), pfn);
>   vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
> + trace_printk("kmap_local_pfn: %d %lx\n", idx, (unsigned long) vaddr);
>   BUG_ON(!pte_none(*(kmap_pte - idx)));
>   pteval = pfn_pte(pfn, prot);
>   set_pte_at(_mm, vaddr, kmap_pte - idx, pteval);
> @@ -545,8 +547,10 @@ void *__kmap_local_page_prot(struct page *page, pgprot_t 
> prot)
>  
>   /* Try kmap_high_get() if architecture has it enabled */
>   kmap = arch_kmap_local_high_get(page);
> - if (kmap)
> + if (kmap) {
> + trace_printk("kmap_local_high_get: %lx\n", (unsigned long) 
> kmap);
>   return kmap;
> + }
>  
>   return __kmap_local_pfn_prot(page_to_pfn(page), prot);
>  }
> @@ -578,6 +582,7 @@ void kunmap_local_indexed(void *vaddr)
>  
>   preempt_disable();
>   idx = arch_kmap_local_unmap_idx(kmap_local_idx(), addr);
> + trace_printk("kunmap_local: %i %lx\n", idx, (unsigned long) vaddr);
>   WARN_ON_ONCE(addr != __fix_to_virt(FIX_KMAP_BEGIN + idx));
>  
>   arch_kmap_local_pre_unmap(addr);
> 

The result could be seen at http://kernel.montjoie.ovh/129768.log
The log is 9Mb, but the ftrace dump seems not terminated, tell me if you need 
more.

Regards


Re: crypto: sun4i-ss: error with kmap

2020-12-01 Thread Corentin Labbe
On Tue, Dec 01, 2020 at 03:16:36PM +0100, Thomas Gleixner wrote:
> On Tue, Dec 01 2020 at 14:52, Corentin Labbe wrote:
> > On Tue, Dec 01, 2020 at 02:28:54PM +0100, Thomas Gleixner wrote:
> > The patch made the board too busy logging and fail to boot until the test.
> 
> Stupid me. Of course this wants to be conditional.
> 
> Thanks,
> 
> tglx
> ---
> diff --git a/mm/highmem.c b/mm/highmem.c
> index b49364a306b8..178b126ab4f6 100644
> --- a/mm/highmem.c
> +++ b/mm/highmem.c
> @@ -571,8 +571,10 @@ void kunmap_local_indexed(void *vaddr)
>* PAGE_OFFSET. Warn for all other addresses which are in
>* the user space part of the virtual address space.
>*/
> - if (!kmap_high_unmap_local(addr))
> - WARN_ON_ONCE(addr < PAGE_OFFSET);
> + if (!kmap_high_unmap_local(addr)) {
> + if (WARN_ON_ONCE(addr < PAGE_OFFSET))
> + pr_err("kunmap_local: vaddr %lx\n", (unsigned 
> long) vaddr);
> + }
>   return;
>   }
>  

In fact the warn was a bit later so I added:
   preempt_disable();
idx = arch_kmap_local_unmap_idx(kmap_local_idx(), addr);
-   WARN_ON_ONCE(addr != __fix_to_virt(FIX_KMAP_BEGIN + idx));
+   if (WARN_ON_ONCE(addr != __fix_to_virt(FIX_KMAP_BEGIN + idx)))
+   pr_err("kunmap_local: vaddr %lx\n", (unsigned long) vaddr);
 
arch_kmap_local_pre_unmap(addr);
pte_clear(_mm, addr, kmap_pte - idx);

and this give kunmap_local: vaddr ffefe000

full dump:
+[  215.602507] [ cut here ]
+[  215.602563] WARNING: CPU: 0 PID: 18429 at mm/highmem.c:584 
kunmap_local_indexed+0x204/0x228
+[  215.602570] Modules linked in: sm4_generic authenc vmac xcbc hmac 
streebog_generic sm3_generic sha3_generic crct10dif_generic crct10dif_common 
seed rmd320 rmd256 rmd160 rmd128 cts lzo lzo_compress salsa20_generic 
camellia_generic fcrypt pcbc tgr192 anubis wp512 khazad tea michael_mic arc4 
cast6_generic cast5_generic cast_common deflate zlib_deflate sha512_generic cfb 
ofb serpent_generic lrw twofish_generic twofish_common blowfish_generic 
blowfish_common md4
+[  215.602767] CPU: 0 PID: 18429 Comm: cryptsetup Tainted: GW 
5.10.0-rc5-next-20201130-00059-gf7ecf0611042-dirty #247
+[  215.602772] Hardware name: Allwinner sun7i (A20) Family
+[  215.602805] [] (unwind_backtrace) from [] 
(show_stack+0x10/0x14)
+[  215.602821] [] (show_stack) from [] 
(dump_stack+0x98/0xac)
+[  215.602834] [] (dump_stack) from [] (__warn+0xc0/0xd8)
+[  215.602846] [] (__warn) from [] 
(warn_slowpath_fmt+0x64/0xc0)
+[  215.602860] [] (warn_slowpath_fmt) from [] 
(kunmap_local_indexed+0x204/0x228)
+[  215.602879] [] (kunmap_local_indexed) from [] 
(sg_miter_stop+0xb4/0x164)
+[  215.602895] [] (sg_miter_stop) from [] 
(sg_miter_next+0xc/0xe4)
+[  215.602913] [] (sg_miter_next) from [] 
(sun4i_ss_opti_poll+0x278/0x40c)
+[  215.602929] [] (sun4i_ss_opti_poll) from [] 
(sun4i_ss_cipher_poll+0x4f4/0x5e4)
+[  215.602944] [] (sun4i_ss_cipher_poll) from [] 
(crypto_skcipher_encrypt+0x38/0x5c)
+[  215.602958] [] (crypto_skcipher_encrypt) from [] 
(xts_encrypt+0x8c/0xd4)
+[  215.602971] [] (xts_encrypt) from [] 
(crypto_skcipher_encrypt+0x38/0x5c)
+[  215.602984] [] (crypto_skcipher_encrypt) from [] 
(skcipher_recvmsg+0x364/0x43c)
+[  215.602999] [] (skcipher_recvmsg) from [] 
(sock_read_iter+0xa8/0xf8)
+[  215.603017] [] (sock_read_iter) from [] 
(vfs_read+0x2b8/0x2d8)
+[  215.603030] [] (vfs_read) from [] (ksys_read+0xb0/0xe4)
+[  215.603042] [] (ksys_read) from [] 
(ret_fast_syscall+0x0/0x58)
+[  215.603050] Exception stack(0xc4de9fa8 to 0xc4de9ff0)
+[  215.603061] 9fa0:   0006 b6fea4d0 0006 b48ce000 
0001 
+[  215.603073] 9fc0: 0006 b6fea4d0 0001 0003 0030 bebad9bc 
0010 bebad9fc
+[  215.603082] 9fe0: b6f1809c bebad958 b6daa504 b6daa51c
+[  215.603091] ---[ end trace d5a2f8d9794ce46d ]---
+[  215.603098] kunmap_local: vaddr ffefe000
+[  215.604643] 8<--- cut here ---
+[  215.604650] Unable to handle kernel paging request at virtual address 
ffefdf70
+[  215.604661] pgd = b4af32d8
+[  215.604667] [ffefdf70] *pgd=6ffce861, *pte=, *ppte=
+[  215.604692] Internal error: Oops: 837 [#1] SMP ARM
+[  215.609490] Modules linked in: sm4_generic authenc vmac xcbc hmac 
streebog_generic sm3_generic sha3_generic crct10dif_generic crct10dif_common 
seed rmd320 rmd256 rmd160 rmd128 cts lzo lzo_compress salsa20_generic 
camellia_generic fcrypt pcbc tgr192 anubis wp512 khazad tea michael_mic arc4 
cast6_generic cast5_generic cast_common deflate zlib_deflate sha512_generic cfb 
ofb serpent_generic lrw twofish_generic twofish_common blowfish_generic 
blowfish_common md4
+[  215.650069] CPU: 0 PID: 18429 Comm: cryptsetup Tainted: G   

Re: crypto: sun4i-ss: error with kmap

2020-12-01 Thread Corentin Labbe
On Tue, Dec 01, 2020 at 02:28:54PM +0100, Thomas Gleixner wrote:
> On Tue, Dec 01 2020 at 14:01, Corentin Labbe wrote:
> > +[  213.050152] [ cut here ]
> > +[  213.050207] WARNING: CPU: 0 PID: 18430 at mm/highmem.c:581 
> > kunmap_local_indexed+0x194/0x1d4
> > +[  213.050214] Modules linked in: sm4_generic authenc vmac xcbc hmac 
> > streebog_generic sm3_generic sha3_generic crct10dif_generic 
> > crct10dif_common seed rmd320 rmd256 rmd160 rmd128 cts lzo lzo_compress 
> > salsa20_generic camellia_generic fcrypt pcbc tgr192 anubis wp512 khazad tea 
> > michael_mic arc4 cast6_generic cast5_generic cast_common deflate 
> > zlib_deflate sha512_generic cfb ofb serpent_generic lrw twofish_generic 
> > twofish_common blowfish_generic blowfish_common md4
> > +[  213.050410] CPU: 0 PID: 18430 Comm: cryptsetup Not tainted 
> > 5.10.0-rc5-next-20201130-00059-gf7ecf0611042-dirty #242
> > +[  213.050416] Hardware name: Allwinner sun7i (A20) Family
> > +[  213.050448] [] (unwind_backtrace) from [] 
> > (show_stack+0x10/0x14)
> > +[  213.050465] [] (show_stack) from [] 
> > (dump_stack+0x98/0xac)
> > +[  213.050479] [] (dump_stack) from [] 
> > (__warn+0xc0/0xd8)
> > +[  213.050491] [] (__warn) from [] 
> > (warn_slowpath_fmt+0x64/0xc0)
> > +[  213.050505] [] (warn_slowpath_fmt) from [] 
> > (kunmap_local_indexed+0x194/0x1d4)
> > +[  213.050525] [] (kunmap_local_indexed) from [] 
> > (sg_miter_stop+0xb4/0x164)
> > +[  213.050541] [] (sg_miter_stop) from [] 
> > (sg_miter_next+0xc/0xe4)
> > +[  213.050560] [] (sg_miter_next) from [] 
> > (sun4i_ss_opti_poll+0x278/0x40c)
> > +[  213.050575] [] (sun4i_ss_opti_poll) from [] 
> > (sun4i_ss_cipher_poll+0x4f4/0x5e4)
> > +[  213.050590] [] (sun4i_ss_cipher_poll) from [] 
> > (crypto_skcipher_encrypt+0x38/0x5c)
> > +[  213.050604] [] (crypto_skcipher_encrypt) from [] 
> > (xts_encrypt+0x8c/0xd4)
> > +[  213.050617] [] (xts_encrypt) from [] 
> > (crypto_skcipher_encrypt+0x38/0x5c)
> > +[  213.050631] [] (crypto_skcipher_encrypt) from [] 
> > (skcipher_recvmsg+0x364/0x43c)
> > +[  213.050646] [] (skcipher_recvmsg) from [] 
> > (sock_read_iter+0xa8/0xf8)
> > +[  213.050663] [] (sock_read_iter) from [] 
> > (vfs_read+0x2b8/0x2d8)
> > +[  213.050676] [] (vfs_read) from [] 
> > (ksys_read+0xb0/0xe4)
> > +[  213.050688] [] (ksys_read) from [] 
> > (ret_fast_syscall+0x0/0x58)
> > +[  213.050695] Exception stack(0xc4d13fa8 to 0xc4d13ff0)
> > +[  213.050707] 3fa0:   0006 b6f084d0 0006 b47ff000 
> > 0001 
> > +[  213.050718] 3fc0: 0006 b6f084d0 0001 0003 0030 beb6e9bc 
> > 0010 beb6e9fc
> > +[  213.050727] 3fe0: b6e3609c beb6e958 b6cc8504 b6cc851c
> > +[  213.050735] ---[ end trace 915906e6b0e8a55d ]---
> 
> Hmm. No registers there. Can you apply the patch below so we can see the
> address?
> 
> Thanks,
> 
> tglx
> ---
> diff --git a/mm/highmem.c b/mm/highmem.c
> index b49364a306b8..240fc6e5bfb4 100644
> --- a/mm/highmem.c
> +++ b/mm/highmem.c
> @@ -571,8 +571,10 @@ void kunmap_local_indexed(void *vaddr)
>* PAGE_OFFSET. Warn for all other addresses which are in
>* the user space part of the virtual address space.
>*/
> - if (!kmap_high_unmap_local(addr))
> + if (!kmap_high_unmap_local(addr)) {
> + pr_err("kunmap_local: vaddr %lx\n", (unsigned long) 
> vaddr);
>   WARN_ON_ONCE(addr < PAGE_OFFSET);
> + }
>   return;
>   }
>  

The patch made the board too busy logging and fail to boot until the test.

Regards


crypto: sun4i-ss: error with kmap

2020-12-01 Thread Corentin Labbe
Hello

When testing 20201130, I hit this problem:

+[  213.050152] [ cut here ]
+[  213.050207] WARNING: CPU: 0 PID: 18430 at mm/highmem.c:581 
kunmap_local_indexed+0x194/0x1d4
+[  213.050214] Modules linked in: sm4_generic authenc vmac xcbc hmac 
streebog_generic sm3_generic sha3_generic crct10dif_generic crct10dif_common 
seed rmd320 rmd256 rmd160 rmd128 cts lzo lzo_compress salsa20_generic 
camellia_generic fcrypt pcbc tgr192 anubis wp512 khazad tea michael_mic arc4 
cast6_generic cast5_generic cast_common deflate zlib_deflate sha512_generic cfb 
ofb serpent_generic lrw twofish_generic twofish_common blowfish_generic 
blowfish_common md4
+[  213.050410] CPU: 0 PID: 18430 Comm: cryptsetup Not tainted 
5.10.0-rc5-next-20201130-00059-gf7ecf0611042-dirty #242
+[  213.050416] Hardware name: Allwinner sun7i (A20) Family
+[  213.050448] [] (unwind_backtrace) from [] 
(show_stack+0x10/0x14)
+[  213.050465] [] (show_stack) from [] 
(dump_stack+0x98/0xac)
+[  213.050479] [] (dump_stack) from [] (__warn+0xc0/0xd8)
+[  213.050491] [] (__warn) from [] 
(warn_slowpath_fmt+0x64/0xc0)
+[  213.050505] [] (warn_slowpath_fmt) from [] 
(kunmap_local_indexed+0x194/0x1d4)
+[  213.050525] [] (kunmap_local_indexed) from [] 
(sg_miter_stop+0xb4/0x164)
+[  213.050541] [] (sg_miter_stop) from [] 
(sg_miter_next+0xc/0xe4)
+[  213.050560] [] (sg_miter_next) from [] 
(sun4i_ss_opti_poll+0x278/0x40c)
+[  213.050575] [] (sun4i_ss_opti_poll) from [] 
(sun4i_ss_cipher_poll+0x4f4/0x5e4)
+[  213.050590] [] (sun4i_ss_cipher_poll) from [] 
(crypto_skcipher_encrypt+0x38/0x5c)
+[  213.050604] [] (crypto_skcipher_encrypt) from [] 
(xts_encrypt+0x8c/0xd4)
+[  213.050617] [] (xts_encrypt) from [] 
(crypto_skcipher_encrypt+0x38/0x5c)
+[  213.050631] [] (crypto_skcipher_encrypt) from [] 
(skcipher_recvmsg+0x364/0x43c)
+[  213.050646] [] (skcipher_recvmsg) from [] 
(sock_read_iter+0xa8/0xf8)
+[  213.050663] [] (sock_read_iter) from [] 
(vfs_read+0x2b8/0x2d8)
+[  213.050676] [] (vfs_read) from [] (ksys_read+0xb0/0xe4)
+[  213.050688] [] (ksys_read) from [] 
(ret_fast_syscall+0x0/0x58)
+[  213.050695] Exception stack(0xc4d13fa8 to 0xc4d13ff0)
+[  213.050707] 3fa0:   0006 b6f084d0 0006 b47ff000 
0001 
+[  213.050718] 3fc0: 0006 b6f084d0 0001 0003 0030 beb6e9bc 
0010 beb6e9fc
+[  213.050727] 3fe0: b6e3609c beb6e958 b6cc8504 b6cc851c
+[  213.050735] ---[ end trace 915906e6b0e8a55d ]---
+[  213.052281] 8<--- cut here ---
+[  213.052288] Unable to handle kernel paging request at virtual address 
ffefdf70
+[  213.052299] pgd = f9321c11
+[  213.052306] [ffefdf70] *pgd=6ffce861, *pte=, *ppte=
+[  213.052330] Internal error: Oops: 837 [#1] SMP ARM
+[  213.057127] Modules linked in: sm4_generic authenc vmac xcbc hmac 
streebog_generic sm3_generic sha3_generic crct10dif_generic crct10dif_common 
seed rmd320 rmd256 rmd160 rmd128 cts lzo lzo_compress salsa20_generic 
camellia_generic fcrypt pcbc tgr192 anubis wp512 khazad tea michael_mic arc4 
cast6_generic cast5_generic cast_common deflate zlib_deflate sha512_generic cfb 
ofb serpent_generic lrw twofish_generic twofish_common blowfish_generic 
blowfish_common md4
+[  213.097705] CPU: 0 PID: 18430 Comm: cryptsetup Tainted: GW 
5.10.0-rc5-next-20201130-00059-gf7ecf0611042-dirty #242
+[  213.109424] Hardware name: Allwinner sun7i (A20) Family
+[  213.114651] PC is at __raw_readsl+0x30/0x100
+[  213.118917] LR is at 0xe63d133d
+[  213.122056] pc : []lr : []psr: 2093
+[  213.128314] sp : c4d13ca0  ip : 52cee82d  fp : 
+[  213.133533] r10: c4d12000  r9 : c4fb0240  r8 : 
+[  213.138752] r7 : 0fa0  r6 : c506fa40  r5 : 0018  r4 : 13eb444f
+[  213.145271] r3 : 2394c9a0  r2 : 0004  r1 : ffefdf70  r0 : f08ea204
+[  213.151791] Flags: nzCv  IRQs off  FIQs on  Mode SVC_32  ISA ARM  Segment 
none
+[  213.159004] Control: 10c5387d  Table: 44f8806a  DAC: 0051
+[  213.164744] Process cryptsetup (pid: 18430, stack limit = 0x41d2aece)
+[  213.171176] Stack: (0xc4d13ca0 to 0xc4d14000)
+[  213.175535] 3ca0: 000d c06b2d88 eff19a00 8013 0038 0001 
 c506fb64
+[  213.183705] 3cc0: 6013  c4d0b900    
 
+[  213.191875] 3ce0:   0001 1000  0005 
efef0a60 ffefd000
+[  213.200046] 3d00: 1000 1000 c4fb00f8  0001 0001 
 1000
+[  213.208216] 3d20: 0003 d1b3a700 efef06a0 c0dd81c0 c51d6d00 c506fa40 
 c4fb0240
+[  213.216387] 3d40: c4fb0008   c06b338c 793d365f c0201500 
c4d13da8 ff9735a0
+[  213.224557] 3d60: c4d12000  0001 c0399a28 c4d13da8  
 c0399fe8
+[  213.232728] 3d80: 44272f52 004bf960 b4c30b1c 310de6b4 c4fb01c0 c03aa018 
 c4d12000
+[  213.240899] 3da0: 0001  ef864000 c4d8 efef0a60 ffefe000 
c50463f0 1000
+[  213.249069] 3dc0:  c4fb00f8 1000 

[PATCH v2] x86/defconfigs: enable HDA realtek codec

2020-11-16 Thread Corentin Labbe
I have lot of board booting with "hdaudio hdaudioC0D2: Unable to bind the 
codec".
This is, for all of them, due to missing the HDA realtek codec.

In fact CONFIG_SND_HDA_CODEC_REALTEK was already enabled via commit 
5cb04df8d3f0 ("x86: defconfig updates")
but removed later via commit 8b1bb90701f9 ("defconfig reduction")

Anyway, one of those system is part of kernelCI and having
CONFIG_SND_HDA_CODEC_REALTEK back will permit more testing.

Signed-off-by: Corentin Labbe 
---
Change since v1:
- Do the same change on i386, to keep them sync.

 arch/x86/configs/i386_defconfig   | 1 +
 arch/x86/configs/x86_64_defconfig | 1 +
 2 files changed, 2 insertions(+)

diff --git a/arch/x86/configs/i386_defconfig b/arch/x86/configs/i386_defconfig
index 78210793d357..070615a63308 100644
--- a/arch/x86/configs/i386_defconfig
+++ b/arch/x86/configs/i386_defconfig
@@ -196,6 +196,7 @@ CONFIG_SND_HRTIMER=y
 CONFIG_SND_SEQUENCER=y
 CONFIG_SND_SEQ_DUMMY=y
 CONFIG_SND_HDA_INTEL=y
+CONFIG_SND_HDA_CODEC_REALTEK=y
 CONFIG_SND_HDA_HWDEP=y
 CONFIG_HIDRAW=y
 CONFIG_HID_GYRATION=y
diff --git a/arch/x86/configs/x86_64_defconfig 
b/arch/x86/configs/x86_64_defconfig
index 9936528e1939..830e4af263a2 100644
--- a/arch/x86/configs/x86_64_defconfig
+++ b/arch/x86/configs/x86_64_defconfig
@@ -190,6 +190,7 @@ CONFIG_SND_HRTIMER=y
 CONFIG_SND_SEQUENCER=y
 CONFIG_SND_SEQ_DUMMY=y
 CONFIG_SND_HDA_INTEL=y
+CONFIG_SND_HDA_CODEC_REALTEK=y
 CONFIG_SND_HDA_HWDEP=y
 CONFIG_HIDRAW=y
 CONFIG_HID_GYRATION=y
-- 
2.26.2



[PATCH v3 0/7] crypto: sun4i-ss: prevent always fallback for ciphers

2020-11-16 Thread Corentin Labbe
Hello

For help testing on "crypto: sun4i-ss - Fix sparse endianness markers",
I have added "stats" support like other allwinner's crypto drivers.
Seeing stats showed a clear problem, the ciphers function were not used
at all.
This is due to the not-inialized need_fallback which is "init" as true
everytime.
So basicly, since the patch introduced it, this probem hidden some bugs.

This serie fixes all hidden problems, then fix the initialization of
"need_fallback" and then add the stats like other allwinner drivers.

Regards

Changes since v2:
- patch #1: move buf/bufo out of function for reducing stack usage
- patch #4: use writesl()
- patch #6: use IS_ENABLED instead of #ifdef

Changes since v1:
- patch #4 is sufficient to fix BE problem (removed todo)

Corentin Labbe (7):
  crypto: sun4i-ss: linearize buffers content must be kept
  crypto: sun4i-ss: checking sg length is not sufficient
  crypto: sun4i-ss: IV register does not work on A10 and A13
  crypto: sun4i-ss: handle BigEndian for cipher
  crypto: sun4i-ss: initialize need_fallback
  crypto: sun4i-ss: enabled stats via debugfs
  crypto: sun4i-ss: add SPDX header and remove blank lines

 drivers/crypto/allwinner/Kconfig  |  9 ++
 .../allwinner/sun4i-ss/sun4i-ss-cipher.c  | 87 +--
 .../crypto/allwinner/sun4i-ss/sun4i-ss-core.c | 56 
 .../crypto/allwinner/sun4i-ss/sun4i-ss-hash.c |  6 ++
 .../crypto/allwinner/sun4i-ss/sun4i-ss-prng.c |  6 ++
 drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h  |  8 ++
 6 files changed, 146 insertions(+), 26 deletions(-)

-- 
2.26.2



[PATCH v3 2/7] crypto: sun4i-ss: checking sg length is not sufficient

2020-11-16 Thread Corentin Labbe
The optimized cipher function need length multiple of 4 bytes.
But it get sometimes odd length.
This is due to SG data could be stored with an offset.

So the fix is to check also if the offset is aligned with 4 bytes.
Fixes: 6298e948215f2 ("crypto: sunxi-ss - Add Allwinner Security System crypto 
accelerator")
Cc: 
Signed-off-by: Corentin Labbe 
---
 drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c 
b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
index 19f1aa577ed4..4dd736ee5a4d 100644
--- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
+++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
@@ -186,12 +186,12 @@ static int sun4i_ss_cipher_poll(struct skcipher_request 
*areq)
 * we can use the SS optimized function
 */
while (in_sg && no_chunk == 1) {
-   if (in_sg->length % 4)
+   if (in_sg->length % 4 || !IS_ALIGNED(in_sg->offset, 
sizeof(u32)))
no_chunk = 0;
in_sg = sg_next(in_sg);
}
while (out_sg && no_chunk == 1) {
-   if (out_sg->length % 4)
+   if (out_sg->length % 4 || !IS_ALIGNED(out_sg->offset, 
sizeof(u32)))
no_chunk = 0;
out_sg = sg_next(out_sg);
}
-- 
2.26.2



[PATCH v3 4/7] crypto: sun4i-ss: handle BigEndian for cipher

2020-11-16 Thread Corentin Labbe
Ciphers produce invalid results on BE.
Key and IV need to be written in LE.

Fixes: 6298e948215f2 ("crypto: sunxi-ss - Add Allwinner Security System crypto 
accelerator")
Cc: 
Signed-off-by: Corentin Labbe 
---
 drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c 
b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
index 53478c3feca6..8f4621826330 100644
--- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
+++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
@@ -52,13 +52,13 @@ static int noinline_for_stack sun4i_ss_opti_poll(struct 
skcipher_request *areq)
 
spin_lock_irqsave(>slock, flags);
 
-   for (i = 0; i < op->keylen; i += 4)
-   writel(*(op->key + i / 4), ss->base + SS_KEY0 + i);
+   for (i = 0; i < op->keylen / 4; i++)
+   writesl(ss->base + SS_KEY0 + i * 4, >key[i], 1);
 
if (areq->iv) {
for (i = 0; i < 4 && i < ivsize / 4; i++) {
v = *(u32 *)(areq->iv + i * 4);
-   writel(v, ss->base + SS_IV0 + i * 4);
+   writesl(ss->base + SS_IV0 + i * 4, , 1);
}
}
writel(mode, ss->base + SS_CTL);
@@ -223,13 +223,13 @@ static int sun4i_ss_cipher_poll(struct skcipher_request 
*areq)
 
spin_lock_irqsave(>slock, flags);
 
-   for (i = 0; i < op->keylen; i += 4)
-   writel(*(op->key + i / 4), ss->base + SS_KEY0 + i);
+   for (i = 0; i < op->keylen / 4; i++)
+   writesl(ss->base + SS_KEY0 + i * 4, >key[i], 1);
 
if (areq->iv) {
for (i = 0; i < 4 && i < ivsize / 4; i++) {
v = *(u32 *)(areq->iv + i * 4);
-   writel(v, ss->base + SS_IV0 + i * 4);
+   writesl(ss->base + SS_IV0 + i * 4, , 1);
}
}
writel(mode, ss->base + SS_CTL);
-- 
2.26.2



[PATCH v3 5/7] crypto: sun4i-ss: initialize need_fallback

2020-11-16 Thread Corentin Labbe
The need_fallback is never initialized and seem to be always true at runtime.
So all hardware operations are always bypassed.

Fixes: 0ae1f46c55f87 ("crypto: sun4i-ss - fallback when length is not multiple 
of blocksize")
Cc: 
Signed-off-by: Corentin Labbe 
---
 drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c 
b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
index 8f4621826330..7f4c97cc9627 100644
--- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
+++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
@@ -179,7 +179,7 @@ static int sun4i_ss_cipher_poll(struct skcipher_request 
*areq)
unsigned int obo = 0;   /* offset in bufo*/
unsigned int obl = 0;   /* length of data in bufo */
unsigned long flags;
-   bool need_fallback;
+   bool need_fallback = false;
 
if (!areq->cryptlen)
return 0;
-- 
2.26.2



[PATCH v3 7/7] crypto: sun4i-ss: add SPDX header and remove blank lines

2020-11-16 Thread Corentin Labbe
This patchs fixes some remaining style issue.

Signed-off-by: Corentin Labbe 
Signed-off-by: Corentin Labbe 
---
 drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c | 3 ---
 drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c   | 1 +
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c 
b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
index 5af404f74a98..94b9952b16f3 100644
--- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
+++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
@@ -135,7 +135,6 @@ static int noinline_for_stack sun4i_ss_opti_poll(struct 
skcipher_request *areq)
return err;
 }
 
-
 static int noinline_for_stack sun4i_ss_cipher_poll_fallback(struct 
skcipher_request *areq)
 {
struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq);
@@ -541,7 +540,6 @@ int sun4i_ss_cipher_init(struct crypto_tfm *tfm)
sizeof(struct sun4i_cipher_req_ctx) +
crypto_skcipher_reqsize(op->fallback_tfm));
 
-
err = pm_runtime_get_sync(op->ss->dev);
if (err < 0)
goto error_pm;
@@ -628,5 +626,4 @@ int sun4i_ss_des3_setkey(struct crypto_skcipher *tfm, const 
u8 *key,
crypto_skcipher_set_flags(op->fallback_tfm, tfm->base.crt_flags & 
CRYPTO_TFM_REQ_MASK);
 
return crypto_skcipher_setkey(op->fallback_tfm, key, keylen);
-
 }
diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c 
b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c
index 152841076e3a..443160a114bb 100644
--- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c
+++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 #include "sun4i-ss.h"
 
 int sun4i_ss_prng_seed(struct crypto_rng *tfm, const u8 *seed,
-- 
2.26.2



[PATCH v3 3/7] crypto: sun4i-ss: IV register does not work on A10 and A13

2020-11-16 Thread Corentin Labbe
Allwinner A10 and A13 SoC have a version of the SS which produce
invalid IV in IVx register.

Instead of adding a variant for those, let's convert SS to produce IV
directly from data.
Fixes: 6298e948215f2 ("crypto: sunxi-ss - Add Allwinner Security System crypto 
accelerator")
Cc: 
Signed-off-by: Corentin Labbe 
---
 .../allwinner/sun4i-ss/sun4i-ss-cipher.c  | 34 +++
 1 file changed, 28 insertions(+), 6 deletions(-)

diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c 
b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
index 4dd736ee5a4d..53478c3feca6 100644
--- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
+++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
@@ -20,6 +20,7 @@ static int noinline_for_stack sun4i_ss_opti_poll(struct 
skcipher_request *areq)
unsigned int ivsize = crypto_skcipher_ivsize(tfm);
struct sun4i_cipher_req_ctx *ctx = skcipher_request_ctx(areq);
u32 mode = ctx->mode;
+   void *backup_iv = NULL;
/* when activating SS, the default FIFO space is SS_RX_DEFAULT(32) */
u32 rx_cnt = SS_RX_DEFAULT;
u32 tx_cnt = 0;
@@ -42,6 +43,13 @@ static int noinline_for_stack sun4i_ss_opti_poll(struct 
skcipher_request *areq)
return -EINVAL;
}
 
+   if (areq->iv && ivsize > 0 && mode & SS_DECRYPTION) {
+   backup_iv = kzalloc(ivsize, GFP_KERNEL);
+   if (!backup_iv)
+   return -ENOMEM;
+   scatterwalk_map_and_copy(backup_iv, areq->src, areq->cryptlen - 
ivsize, ivsize, 0);
+   }
+
spin_lock_irqsave(>slock, flags);
 
for (i = 0; i < op->keylen; i += 4)
@@ -102,9 +110,12 @@ static int noinline_for_stack sun4i_ss_opti_poll(struct 
skcipher_request *areq)
} while (oleft);
 
if (areq->iv) {
-   for (i = 0; i < 4 && i < ivsize / 4; i++) {
-   v = readl(ss->base + SS_IV0 + i * 4);
-   *(u32 *)(areq->iv + i * 4) = v;
+   if (mode & SS_DECRYPTION) {
+   memcpy(areq->iv, backup_iv, ivsize);
+   kfree_sensitive(backup_iv);
+   } else {
+   scatterwalk_map_and_copy(areq->iv, areq->dst, 
areq->cryptlen - ivsize,
+ivsize, 0);
}
}
 
@@ -161,6 +172,7 @@ static int sun4i_ss_cipher_poll(struct skcipher_request 
*areq)
unsigned int ileft = areq->cryptlen;
unsigned int oleft = areq->cryptlen;
unsigned int todo;
+   void *backup_iv = NULL;
struct sg_mapping_iter mi, mo;
unsigned int oi, oo;/* offset for in and out */
unsigned int ob = 0;/* offset in buf */
@@ -202,6 +214,13 @@ static int sun4i_ss_cipher_poll(struct skcipher_request 
*areq)
if (need_fallback)
return sun4i_ss_cipher_poll_fallback(areq);
 
+   if (areq->iv && ivsize > 0 && mode & SS_DECRYPTION) {
+   backup_iv = kzalloc(ivsize, GFP_KERNEL);
+   if (!backup_iv)
+   return -ENOMEM;
+   scatterwalk_map_and_copy(backup_iv, areq->src, areq->cryptlen - 
ivsize, ivsize, 0);
+   }
+
spin_lock_irqsave(>slock, flags);
 
for (i = 0; i < op->keylen; i += 4)
@@ -322,9 +341,12 @@ static int sun4i_ss_cipher_poll(struct skcipher_request 
*areq)
}
}
if (areq->iv) {
-   for (i = 0; i < 4 && i < ivsize / 4; i++) {
-   v = readl(ss->base + SS_IV0 + i * 4);
-   *(u32 *)(areq->iv + i * 4) = v;
+   if (mode & SS_DECRYPTION) {
+   memcpy(areq->iv, backup_iv, ivsize);
+   kfree_sensitive(backup_iv);
+   } else {
+   scatterwalk_map_and_copy(areq->iv, areq->dst, 
areq->cryptlen - ivsize,
+ivsize, 0);
}
}
 
-- 
2.26.2



[PATCH v3 1/7] crypto: sun4i-ss: linearize buffers content must be kept

2020-11-16 Thread Corentin Labbe
When running the non-optimized cipher function, SS produce partial random
output.
This is due to linearize buffers being reseted after each loop.

For preserving stack, instead of moving them back to start of function,
I move them in sun4i_ss_ctx.

Fixes: 8d3bcb9900ca ("crypto: sun4i-ss - reduce stack usage")
Signed-off-by: Corentin Labbe 
---
 drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c | 12 
 drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h|  2 ++
 2 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c 
b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
index b72de8939497..19f1aa577ed4 100644
--- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
+++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
@@ -233,8 +233,6 @@ static int sun4i_ss_cipher_poll(struct skcipher_request 
*areq)
 
while (oleft) {
if (ileft) {
-   char buf[4 * SS_RX_MAX];/* buffer for linearize SG src 
*/
-
/*
 * todo is the number of consecutive 4byte word that we
 * can read from current SG
@@ -256,12 +254,12 @@ static int sun4i_ss_cipher_poll(struct skcipher_request 
*areq)
 */
todo = min(rx_cnt * 4 - ob, ileft);
todo = min_t(size_t, todo, mi.length - oi);
-   memcpy(buf + ob, mi.addr + oi, todo);
+   memcpy(ss->buf + ob, mi.addr + oi, todo);
ileft -= todo;
oi += todo;
ob += todo;
if (!(ob % 4)) {
-   writesl(ss->base + SS_RXFIFO, buf,
+   writesl(ss->base + SS_RXFIFO, ss->buf,
ob / 4);
ob = 0;
}
@@ -295,13 +293,11 @@ static int sun4i_ss_cipher_poll(struct skcipher_request 
*areq)
oo = 0;
}
} else {
-   char bufo[4 * SS_TX_MAX]; /* buffer for linearize SG 
dst */
-
/*
 * read obl bytes in bufo, we read at maximum for
 * emptying the device
 */
-   readsl(ss->base + SS_TXFIFO, bufo, tx_cnt);
+   readsl(ss->base + SS_TXFIFO, ss->bufo, tx_cnt);
obl = tx_cnt * 4;
obo = 0;
do {
@@ -313,7 +309,7 @@ static int sun4i_ss_cipher_poll(struct skcipher_request 
*areq)
 */
todo = min_t(size_t,
 mo.length - oo, obl - obo);
-   memcpy(mo.addr + oo, bufo + obo, todo);
+   memcpy(mo.addr + oo, ss->bufo + obo, todo);
oleft -= todo;
obo += todo;
oo += todo;
diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h 
b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h
index 163962f9e284..02105b39fbfe 100644
--- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h
+++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h
@@ -148,6 +148,8 @@ struct sun4i_ss_ctx {
struct reset_control *reset;
struct device *dev;
struct resource *res;
+   char buf[4 * SS_RX_MAX];/* buffer for linearize SG src */
+   char bufo[4 * SS_TX_MAX]; /* buffer for linearize SG dst */
spinlock_t slock; /* control the use of the device */
 #ifdef CONFIG_CRYPTO_DEV_SUN4I_SS_PRNG
u32 seed[SS_SEED_LEN / BITS_PER_LONG];
-- 
2.26.2



[PATCH v3 6/7] crypto: sun4i-ss: enabled stats via debugfs

2020-11-16 Thread Corentin Labbe
This patch enable to access usage stats for each algorithm.

Signed-off-by: Corentin Labbe 
---
 drivers/crypto/allwinner/Kconfig  |  9 +++
 .../allwinner/sun4i-ss/sun4i-ss-cipher.c  | 20 +++
 .../crypto/allwinner/sun4i-ss/sun4i-ss-core.c | 56 +++
 .../crypto/allwinner/sun4i-ss/sun4i-ss-hash.c |  6 ++
 .../crypto/allwinner/sun4i-ss/sun4i-ss-prng.c |  5 ++
 drivers/crypto/allwinner/sun4i-ss/sun4i-ss.h  |  6 ++
 6 files changed, 102 insertions(+)

diff --git a/drivers/crypto/allwinner/Kconfig b/drivers/crypto/allwinner/Kconfig
index 0e72543ad1f1..e9b7f7e3d307 100644
--- a/drivers/crypto/allwinner/Kconfig
+++ b/drivers/crypto/allwinner/Kconfig
@@ -51,6 +51,15 @@ config CRYPTO_DEV_SUN4I_SS_PRNG
  Select this option if you want to provide kernel-side support for
  the Pseudo-Random Number Generator found in the Security System.
 
+config CRYPTO_DEV_SUN4I_SS_DEBUG
+   bool "Enable sun4i-ss stats"
+   depends on CRYPTO_DEV_SUN4I_SS
+   depends on DEBUG_FS
+   help
+ Say y to enable sun4i-ss debug stats.
+ This will create /sys/kernel/debug/sun4i-ss/stats for displaying
+ the number of requests per algorithm.
+
 config CRYPTO_DEV_SUN8I_CE
tristate "Support for Allwinner Crypto Engine cryptographic offloader"
select CRYPTO_SKCIPHER
diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c 
b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
index 7f4c97cc9627..5af404f74a98 100644
--- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
+++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
@@ -34,6 +34,8 @@ static int noinline_for_stack sun4i_ss_opti_poll(struct 
skcipher_request *areq)
struct sg_mapping_iter mi, mo;
unsigned int oi, oo; /* offset for in and out */
unsigned long flags;
+   struct skcipher_alg *alg = crypto_skcipher_alg(tfm);
+   struct sun4i_ss_alg_template *algt;
 
if (!areq->cryptlen)
return 0;
@@ -50,6 +52,12 @@ static int noinline_for_stack sun4i_ss_opti_poll(struct 
skcipher_request *areq)
scatterwalk_map_and_copy(backup_iv, areq->src, areq->cryptlen - 
ivsize, ivsize, 0);
}
 
+   if (IS_ENABLED(CONFIG_CRYPTO_DEV_SUN4I_SS_DEBUG)) {
+   algt = container_of(alg, struct sun4i_ss_alg_template, 
alg.crypto);
+   algt->stat_opti++;
+   algt->stat_bytes += areq->cryptlen;
+   }
+
spin_lock_irqsave(>slock, flags);
 
for (i = 0; i < op->keylen / 4; i++)
@@ -134,6 +142,13 @@ static int noinline_for_stack 
sun4i_ss_cipher_poll_fallback(struct skcipher_requ
struct sun4i_tfm_ctx *op = crypto_skcipher_ctx(tfm);
struct sun4i_cipher_req_ctx *ctx = skcipher_request_ctx(areq);
int err;
+   struct skcipher_alg *alg = crypto_skcipher_alg(tfm);
+   struct sun4i_ss_alg_template *algt;
+
+   if (IS_ENABLED(CONFIG_CRYPTO_DEV_SUN4I_SS_DEBUG)) {
+   algt = container_of(alg, struct sun4i_ss_alg_template, 
alg.crypto);
+   algt->stat_fb++;
+   }
 
skcipher_request_set_tfm(>fallback_req, op->fallback_tfm);
skcipher_request_set_callback(>fallback_req, areq->base.flags,
@@ -221,6 +236,11 @@ static int sun4i_ss_cipher_poll(struct skcipher_request 
*areq)
scatterwalk_map_and_copy(backup_iv, areq->src, areq->cryptlen - 
ivsize, ivsize, 0);
}
 
+   if (IS_ENABLED(CONFIG_CRYPTO_DEV_SUN4I_SS_DEBUG)) {
+   algt->stat_req++;
+   algt->stat_bytes += areq->cryptlen;
+   }
+
spin_lock_irqsave(>slock, flags);
 
for (i = 0; i < op->keylen / 4; i++)
diff --git a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-core.c 
b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-core.c
index a2b67f7f8a81..9a8a5e246d87 100644
--- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-core.c
+++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-core.c
@@ -10,6 +10,7 @@
  */
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -234,6 +235,53 @@ static struct sun4i_ss_alg_template ss_algs[] = {
 #endif
 };
 
+#ifdef CONFIG_CRYPTO_DEV_SUN4I_SS_DEBUG
+static int sun4i_ss_dbgfs_read(struct seq_file *seq, void *v)
+{
+   unsigned int i;
+
+   for (i = 0; i < ARRAY_SIZE(ss_algs); i++) {
+   if (!ss_algs[i].ss)
+   continue;
+   switch (ss_algs[i].type) {
+   case CRYPTO_ALG_TYPE_SKCIPHER:
+   seq_printf(seq, "%s %s reqs=%lu opti=%lu fallback=%lu 
tsize=%lu\n",
+  ss_algs[i].alg.crypto.base.cra_driver_name,
+  ss_algs[i].alg.crypto.base.cra_name,
+  ss_algs[i].stat_req, ss_algs[i].stat_opti, 
ss_algs[i].stat_fb,
+  ss_algs[i].stat_bytes);
+

[PATCH] ARM: configs: sunxi: enable brcm wireless

2020-11-15 Thread Corentin Labbe
Lot of sunxi boards have BRCM wireless device, so let's enable necessary
options for it in our defconfig.

Signed-off-by: Corentin Labbe 
---
 arch/arm/configs/sunxi_defconfig | 23 ++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/arch/arm/configs/sunxi_defconfig b/arch/arm/configs/sunxi_defconfig
index 05f7f4ed8ded..084c48f5dce3 100644
--- a/arch/arm/configs/sunxi_defconfig
+++ b/arch/arm/configs/sunxi_defconfig
@@ -52,7 +52,28 @@ CONFIG_STMMAC_ETH=y
 # CONFIG_NET_VENDOR_WIZNET is not set
 CONFIG_MICREL_PHY=y
 CONFIG_REALTEK_PHY=y
-# CONFIG_WLAN is not set
+CONFIG_WLAN=y
+# CONFIG_WLAN_VENDOR_ADMTEK is not set
+# CONFIG_WLAN_VENDOR_ATH is not set
+# CONFIG_WLAN_VENDOR_ATMEL is not set
+CONFIG_WLAN_VENDOR_BROADCOM=y
+# CONFIG_WLAN_VENDOR_CISCO is not set
+# CONFIG_WLAN_VENDOR_INTEL is not set
+# CONFIG_WLAN_VENDOR_INTERSIL is not set
+# CONFIG_WLAN_VENDOR_MARVELL is not set
+# CONFIG_WLAN_VENDOR_MEDIATEK is not set
+# CONFIG_WLAN_VENDOR_MICROCHIP is not set
+# CONFIG_WLAN_VENDOR_RALINK is not set
+# CONFIG_WLAN_VENDOR_REALTEK is not set
+# CONFIG_WLAN_VENDOR_RSI is not set
+# CONFIG_WLAN_VENDOR_ST is not set
+# CONFIG_WLAN_VENDOR_TI is not set
+# CONFIG_WLAN_VENDOR_ZYDAS is not set
+# CONFIG_WLAN_VENDOR_QUANTENNA is not set
+CONFIG_CFG80211=y
+CONFIG_CFG80211_WEXT=y
+CONFIG_MAC80211=y
+CONFIG_BRCMFMAC=y
 CONFIG_INPUT_EVDEV=y
 CONFIG_KEYBOARD_SUN4I_LRADC=y
 # CONFIG_INPUT_MOUSE is not set
-- 
2.26.2



[PATCH] hwmon: drivetemp: fix typo temperatire => temperature

2020-11-15 Thread Corentin Labbe
This patch fix a trivial typo temperatire => temperature.

Signed-off-by: Corentin Labbe 
---
 drivers/hwmon/drivetemp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hwmon/drivetemp.c b/drivers/hwmon/drivetemp.c
index 72c760373957..1eb37106a220 100644
--- a/drivers/hwmon/drivetemp.c
+++ b/drivers/hwmon/drivetemp.c
@@ -10,7 +10,7 @@
  *hwmon: Driver for SCSI/ATA temperature sensors
  *by Constantin Baranov , submitted September 2009
  *
- * This drive supports reporting the temperatire of SATA drives. It can be
+ * This drive supports reporting the temperature of SATA drives. It can be
  * easily extended to report the temperature of SCSI drives.
  *
  * The primary means to read drive temperatures and temperature limits
-- 
2.26.2



[PATCH] crypto: allwinner: sun8i-ce: fix two error path's memory leak

2020-11-15 Thread Corentin Labbe
This patch fixes the following smatch warnings:
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c:412
sun8i_ce_hash_run() warn: possible memory leak of 'result'
Note: "buf" is leaked as well.

Furthermore, in case of ENOMEM, crypto_finalize_hash_request() was not
called which was an error.

Fixes: 56f6d5aee88d ("crypto: sun8i-ce - support hash algorithms")
Reported-by: kernel test robot 
Reported-by: Dan Carpenter 
Signed-off-by: Corentin Labbe 
---
 .../crypto/allwinner/sun8i-ce/sun8i-ce-hash.c | 20 +++
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c 
b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c
index a94bf28f858a..4c5a2c11d714 100644
--- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c
+++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c
@@ -262,13 +262,13 @@ int sun8i_ce_hash_run(struct crypto_engine *engine, void 
*breq)
u32 common;
u64 byte_count;
__le32 *bf;
-   void *buf;
+   void *buf = NULL;
int j, i, todo;
int nbw = 0;
u64 fill, min_fill;
__be64 *bebits;
__le64 *lebits;
-   void *result;
+   void *result = NULL;
u64 bs;
int digestsize;
dma_addr_t addr_res, addr_pad;
@@ -285,13 +285,17 @@ int sun8i_ce_hash_run(struct crypto_engine *engine, void 
*breq)
 
/* the padding could be up to two block. */
buf = kzalloc(bs * 2, GFP_KERNEL | GFP_DMA);
-   if (!buf)
-   return -ENOMEM;
+   if (!buf) {
+   err = -ENOMEM;
+   goto theend;
+   }
bf = (__le32 *)buf;
 
result = kzalloc(digestsize, GFP_KERNEL | GFP_DMA);
-   if (!result)
-   return -ENOMEM;
+   if (!result) {
+   err = -ENOMEM;
+   goto theend;
+   }
 
flow = rctx->flow;
chan = >chanlist[flow];
@@ -403,11 +407,11 @@ int sun8i_ce_hash_run(struct crypto_engine *engine, void 
*breq)
dma_unmap_sg(ce->dev, areq->src, nr_sgs, DMA_TO_DEVICE);
dma_unmap_single(ce->dev, addr_res, digestsize, DMA_FROM_DEVICE);
 
-   kfree(buf);
 
memcpy(areq->result, result, algt->alg.hash.halg.digestsize);
-   kfree(result);
 theend:
+   kfree(buf);
+   kfree(result);
crypto_finalize_hash_request(engine, breq, err);
return 0;
 }
-- 
2.26.2



[PATCH] x86/defconfigs: enable HDA realtek codec

2020-11-15 Thread Corentin Labbe
I have lot of board booting with "hdaudio hdaudioC0D2: Unable to bind the 
codec".
This is, for all of them, due to missing the HDA realtek codec.

In fact CONFIG_SND_HDA_CODEC_REALTEK was already enabled via commit 
5cb04df8d3f0 ("x86: defconfig updates")
but removed later via commit 8b1bb90701f9 ("defconfig reduction")

Anyway, one of those system is part of kernelCI and having
CONFIG_SND_HDA_CODEC_REALTEK back will permit more testing.

Signed-off-by: Corentin Labbe 
---
 arch/x86/configs/x86_64_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/x86/configs/x86_64_defconfig 
b/arch/x86/configs/x86_64_defconfig
index 9936528e1939..830e4af263a2 100644
--- a/arch/x86/configs/x86_64_defconfig
+++ b/arch/x86/configs/x86_64_defconfig
@@ -190,6 +190,7 @@ CONFIG_SND_HRTIMER=y
 CONFIG_SND_SEQUENCER=y
 CONFIG_SND_SEQ_DUMMY=y
 CONFIG_SND_HDA_INTEL=y
+CONFIG_SND_HDA_CODEC_REALTEK=y
 CONFIG_SND_HDA_HWDEP=y
 CONFIG_HIDRAW=y
 CONFIG_HID_GYRATION=y
-- 
2.26.2



[PATCH] ARM: configs: sunxi: enable Realtek PHY

2020-11-12 Thread Corentin Labbe
Lot of sunxi boards has a Realtek PHY, so let's enable it.

Signed-off-by: Corentin Labbe 
---
 arch/arm/configs/sunxi_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/configs/sunxi_defconfig b/arch/arm/configs/sunxi_defconfig
index 244126172fd6..05f7f4ed8ded 100644
--- a/arch/arm/configs/sunxi_defconfig
+++ b/arch/arm/configs/sunxi_defconfig
@@ -51,6 +51,7 @@ CONFIG_STMMAC_ETH=y
 # CONFIG_NET_VENDOR_VIA is not set
 # CONFIG_NET_VENDOR_WIZNET is not set
 CONFIG_MICREL_PHY=y
+CONFIG_REALTEK_PHY=y
 # CONFIG_WLAN is not set
 CONFIG_INPUT_EVDEV=y
 CONFIG_KEYBOARD_SUN4I_LRADC=y
-- 
2.26.2



Re: [BUG] Error applying setting, reverse things back on lot of devices

2020-11-01 Thread Corentin Labbe
On Sun, Nov 01, 2020 at 02:31:15AM +0100, Ondřej Jirman wrote:
> Hello Michał,
> 
> On Sat, Oct 24, 2020 at 01:53:07PM +0200, Michał Mirosław wrote:
> > On Fri, Oct 23, 2020 at 10:39:43PM +0200, Corentin Labbe wrote:
> > > On Fri, Oct 23, 2020 at 03:42:01PM +0200, Corentin Labbe wrote:
> > > > On Wed, Oct 21, 2020 at 08:31:49PM +0200, Corentin Labbe wrote:
> > > > > [5.796585] dcdc4: supplied by regulator-dummy
> > > > > [5.801647] vcc-dram: supplied by regulator-dummy
> > > > > [5.806470] vcc-gmac-phy: failed to get the current voltage: 
> > > > > -EINVAL
> > > > > [5.812839] axp20x-regulator axp20x-regulator: Failed to register 
> > > > > dc1sw
> > > > > [5.820291] axp20x-regulator: probe of axp20x-regulator failed 
> > > > > with error -22
> > > > 
> > > > I have just saw thoses 3 lines which are probably the real problem.
> > > > I have started a new bisect with this error, but it is hitting the same 
> > > > "crash range" the first one.
> > > > 
> > > 
> > > I have bisected the problem to commit 
> > > aea6cb99703e17019e025aa71643b4d3e0a24413 ("regulator: resolve supply 
> > > after creating regulator")
> > > Reverting this fix my problem.
> > 
> > Can you try the hack below?
> > 
> > Best Regards,
> > Michał Mirosław
> > 
> > diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
> > index a4ffd71696da..9ad091f5f1ab 100644
> > --- a/drivers/regulator/core.c
> > +++ b/drivers/regulator/core.c
> > @@ -1169,6 +1169,9 @@ static int machine_constraints_voltage(struct 
> > regulator_dev *rdev,
> > }
> >  
> > if (current_uV < 0) {
> > +   if (current_uV == -EINVAL && rdev->supply_name)
> > +   return -EPROBE_DEFER;
> > +
> > rdev_err(rdev,
> >  "failed to get the current voltage: %pe\n",
> >  ERR_PTR(current_uV));
> 
> I did hit the same problem on sun8i-a83t-tbs-a711.dts tablet.
> 
> The patch helps on top of v5.9.2, and on linus/master.
> 

Hello

Sorry I didnt get your original email.

Tested on top of next-20201030.
I have added a debug """rdev_info(rdev, "%s DEFER\n", __func__);""" and I 
confirm this hack is used since I got "vcc-gmac-phy: 
machine_constraints_voltage DEFER"

So if you send the patch you can add:
Tested-by: Corentin Labbe 
Tested-on: sun8i-r40-bananapi-m2-ultra

Regards


Re: [linux-sunxi] [PATCH v2] arm64: dts: allwinner: h6: PineH64 model B: Add wifi

2020-10-31 Thread Corentin Labbe
On Fri, Oct 30, 2020 at 06:25:30PM +0100, Jernej Skrabec wrote:
> PineH64 model B contains RTL8723CS wifi+bt combo module.
> 
> Since bluetooth support is not yet squared away, only wifi is enabled
> for now.
> 
> Acked-by: Chen-Yu Tsai 
> Signed-off-by: Jernej Skrabec 
> ---
> Changes from v1:
> - added Chen-Yu tag
> - added vqmmc-supply
> 
>  .../dts/allwinner/sun50i-h6-pine-h64-model-b.dts  | 15 +++
>  1 file changed, 15 insertions(+)
> 
> diff --git a/arch/arm64/boot/dts/allwinner/sun50i-h6-pine-h64-model-b.dts 
> b/arch/arm64/boot/dts/allwinner/sun50i-h6-pine-h64-model-b.dts
> index f4c8966a6497..7fea1e4e2d49 100644
> --- a/arch/arm64/boot/dts/allwinner/sun50i-h6-pine-h64-model-b.dts
> +++ b/arch/arm64/boot/dts/allwinner/sun50i-h6-pine-h64-model-b.dts
> @@ -10,6 +10,12 @@ / {
>   compatible = "pine64,pine-h64-model-b", "allwinner,sun50i-h6";
>  
>   /delete-node/ reg_gmac_3v3;
> +
> + wifi_pwrseq: wifi_pwrseq {
> + compatible = "mmc-pwrseq-simple";
> + reset-gpios = <_pio 1 3 GPIO_ACTIVE_LOW>; /* PM3 */
> + post-power-on-delay-ms = <200>;
> + };
>  };
>  
>  _connector {
> @@ -19,3 +25,12 @@ _connector {
>   {
>   phy-supply = <_aldo2>;
>  };
> +
> + {
> + vmmc-supply = <_cldo3>;
> + vqmmc-supply = <_aldo1>;
> + mmc-pwrseq = <_pwrseq>;
> + bus-width = <4>;
> + non-removable;
> + status = "okay";
> +};
> -- 

Hello

Tested-by: 
RTL8723CS driver probe and related iwlist commands works. (like listing 
availlable channels)
But connecting to a wireless network was not successfully tested yet. (I need 
to set a test network).

Regards


Re: [linux-sunxi] [PATCH 10/10] arm64: dts: allwinner: a64: bananapi-m64: Enable RGMII RX/TX delay on PHY

2020-10-24 Thread Corentin Labbe
On Sun, Oct 25, 2020 at 12:25:15AM +0800, Chen-Yu Tsai wrote:
> From: Chen-Yu Tsai 
> 
> The Ethernet PHY on the Bananapi M64 has the RX and TX delays
> enabled on the PHY, using pull-ups on the RXDLY and TXDLY pins.
> 
> Fix the phy-mode description to correct reflect this so that the
> implementation doesn't reconfigure the delays incorrectly. This
> happened with commit bbc4d71d6354 ("net: phy: realtek: fix rtl8211e
> rx/tx delay config").
> 
> Fixes: e7295499903d ("arm64: allwinner: bananapi-m64: Enable dwmac-sun8i")
> Fixes: 94f442886711 ("arm64: dts: allwinner: A64: Restore EMAC changes")
> Signed-off-by: Chen-Yu Tsai 
> ---
>  arch/arm64/boot/dts/allwinner/sun50i-a64-bananapi-m64.dts | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/arm64/boot/dts/allwinner/sun50i-a64-bananapi-m64.dts 
> b/arch/arm64/boot/dts/allwinner/sun50i-a64-bananapi-m64.dts
> index 3ea5182ca489..e5e840b9fbb4 100644
> --- a/arch/arm64/boot/dts/allwinner/sun50i-a64-bananapi-m64.dts
> +++ b/arch/arm64/boot/dts/allwinner/sun50i-a64-bananapi-m64.dts
> @@ -105,7 +105,7 @@  {
>   {
>   pinctrl-names = "default";
>   pinctrl-0 = <_pins>;
> - phy-mode = "rgmii";
> + phy-mode = "rgmii-id";
>   phy-handle = <_rgmii_phy>;
>   phy-supply = <_dc1sw>;
>   status = "okay";
> -- 
> 2.28.0

Tested-by: Corentin Labbe 

Thanks


Re: [BUG] Error applying setting, reverse things back on lot of devices

2020-10-23 Thread Corentin Labbe
On Fri, Oct 23, 2020 at 03:42:01PM +0200, Corentin Labbe wrote:
> On Wed, Oct 21, 2020 at 08:31:49PM +0200, Corentin Labbe wrote:
> > Hello
> > 
> > On next-20201016, booting my sun8i-r40-bananapi-m2-ultra, the boot end 
> > without at least stmmac working.
> > [0.00] Booting Linux on physical CPU 0x0
> > [0.00] Linux version 5.9.0-next-20201016-00055-g98489213ff7c-dirty 
> > (compile@Red) (armv7a-unknown-linux-gnueabihf-gcc (Gentoo 9.3.0-r1 p3) 
> > 9.3.0, GNU ld (Gentoo 2.33.1 p2) 2.33.1) #162 SMP Tue Oct 20 08:10:25 CEST 
> > 2020
> > [0.00] CPU: ARMv7 Processor [410fc075] revision 5 (ARMv7), 
> > cr=10c5387d
> > [0.00] CPU: div instructions available: patching division code
> > [0.00] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing 
> > instruction cache
> > [0.00] OF: fdt: Machine model: Banana Pi BPI-M2-Ultra
> > [0.00] Memory policy: Data cache writealloc
> > [0.00] cma: Reserved 16 MiB at 0xbec0
> > [0.00] Zone ranges:
> > [0.00]   Normal   [mem 0x4000-0x6fff]
> > [0.00]   HighMem  [mem 0x7000-0xbfff]
> > [0.00] Movable zone start for each node
> > [0.00] Early memory node ranges
> > [0.00]   node   0: [mem 0x4000-0xbfff]
> > [0.00] Initmem setup node 0 [mem 
> > 0x4000-0xbfff]
> > [0.00] psci: probing for conduit method from DT.
> > [0.00] psci: Using PSCI v0.1 Function IDs from DT
> > [0.00] percpu: Embedded 15 pages/cpu s30924 r8192 d22324 u61440
> > [0.00] Built 1 zonelists, mobility grouping on.  Total pages: 522752
> > [0.00] Kernel command line: console=ttyS0,115200n8 root=/dev/ram0 
> > ip=dhcp trace_event=initcall:*,module:* trace_options=stacktrace ip=dhcp
> > [0.00] Dentry cache hash table entries: 131072 (order: 7, 524288 
> > bytes, linear)
> > [0.00] Inode-cache hash table entries: 65536 (order: 6, 262144 
> > bytes, linear)
> > [0.00] mem auto-init: stack:off, heap alloc:off, heap free:off
> > [0.00] Memory: 2020320K/2097152K available (7168K kernel code, 934K 
> > rwdata, 2252K rodata, 1024K init, 248K bss, 60448K reserved, 16384K 
> > cma-reserved, 1294324K highmem)
> > [0.00] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=4, Nodes=1
> > [0.00] rcu: Hierarchical RCU implementation.
> > [0.00] rcu: RCU event tracing is enabled.
> > [0.00] rcu: RCU restricting CPUs from NR_CPUS=8 to 
> > nr_cpu_ids=4.
> > [0.00] rcu: RCU calculated value of scheduler-enlistment delay is 
> > 10 jiffies.
> > [0.00] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=4
> > [0.00] NR_IRQS: 16, nr_irqs: 16, preallocated irqs: 16
> > [0.00] GIC: Using split EOI/Deactivate mode
> > [0.00] random: get_random_bytes called from 
> > start_kernel+0x320/0x4ac with crng_init=0
> > [0.00] arch_timer: cp15 timer(s) running at 24.00MHz (phys).
> > [0.00] clocksource: arch_sys_counter: mask: 0xff 
> > max_cycles: 0x588fe9dc0, max_idle_ns: 440795202592 ns
> > [0.07] sched_clock: 56 bits at 24MHz, resolution 41ns, wraps every 
> > 4398046511097ns
> > [0.20] Switching to timer-based delay loop, resolution 41ns
> > [0.000176] Console: colour dummy device 80x30
> > [0.000230] Calibrating delay loop (skipped), value calculated using 
> > timer frequency.. 48.00 BogoMIPS (lpj=24)
> > [0.000251] pid_max: default: 32768 minimum: 301
> > [0.000395] Mount-cache hash table entries: 2048 (order: 1, 8192 bytes, 
> > linear)
> > [0.000414] Mountpoint-cache hash table entries: 2048 (order: 1, 8192 
> > bytes, linear)
> > [0.001117] CPU: Testing write buffer coherency: ok
> > [0.001420] /cpus/cpu@0 missing clock-frequency property
> > [0.001442] /cpus/cpu@1 missing clock-frequency property
> > [0.001459] /cpus/cpu@2 missing clock-frequency property
> > [0.001477] /cpus/cpu@3 missing clock-frequency property
> > [0.001490] CPU0: thread -1, cpu 0, socket 0, mpidr 8000
> > [0.002001] Setting up static identity map for 0x4010 - 0x40100060
> > [0.002119] rcu: Hierarchical SRCU implementation.
> > [0.002580] smp: Bringing up secondary CPUs ...
> > [0.013271] CPU1: thread -1, cpu 1, socket 0, mpidr 8001
> > [0.024063] CPU2: thread -1, cpu 2, socket 0, mpidr 8002
> 

Re: [BUG] Error applying setting, reverse things back on lot of devices

2020-10-23 Thread Corentin Labbe
On Wed, Oct 21, 2020 at 08:31:49PM +0200, Corentin Labbe wrote:
> Hello
> 
> On next-20201016, booting my sun8i-r40-bananapi-m2-ultra, the boot end 
> without at least stmmac working.
> [0.00] Booting Linux on physical CPU 0x0
> [0.00] Linux version 5.9.0-next-20201016-00055-g98489213ff7c-dirty 
> (compile@Red) (armv7a-unknown-linux-gnueabihf-gcc (Gentoo 9.3.0-r1 p3) 9.3.0, 
> GNU ld (Gentoo 2.33.1 p2) 2.33.1) #162 SMP Tue Oct 20 08:10:25 CEST 2020
> [0.00] CPU: ARMv7 Processor [410fc075] revision 5 (ARMv7), cr=10c5387d
> [0.00] CPU: div instructions available: patching division code
> [0.00] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing 
> instruction cache
> [0.00] OF: fdt: Machine model: Banana Pi BPI-M2-Ultra
> [0.00] Memory policy: Data cache writealloc
> [0.00] cma: Reserved 16 MiB at 0xbec0
> [0.00] Zone ranges:
> [0.00]   Normal   [mem 0x4000-0x6fff]
> [0.00]   HighMem  [mem 0x7000-0xbfff]
> [0.00] Movable zone start for each node
> [0.00] Early memory node ranges
> [0.00]   node   0: [mem 0x4000-0xbfff]
> [0.00] Initmem setup node 0 [mem 
> 0x4000-0xbfff]
> [0.00] psci: probing for conduit method from DT.
> [0.00] psci: Using PSCI v0.1 Function IDs from DT
> [0.00] percpu: Embedded 15 pages/cpu s30924 r8192 d22324 u61440
> [0.00] Built 1 zonelists, mobility grouping on.  Total pages: 522752
> [0.00] Kernel command line: console=ttyS0,115200n8 root=/dev/ram0 
> ip=dhcp trace_event=initcall:*,module:* trace_options=stacktrace ip=dhcp
> [0.00] Dentry cache hash table entries: 131072 (order: 7, 524288 
> bytes, linear)
> [0.00] Inode-cache hash table entries: 65536 (order: 6, 262144 bytes, 
> linear)
> [0.00] mem auto-init: stack:off, heap alloc:off, heap free:off
> [0.00] Memory: 2020320K/2097152K available (7168K kernel code, 934K 
> rwdata, 2252K rodata, 1024K init, 248K bss, 60448K reserved, 16384K 
> cma-reserved, 1294324K highmem)
> [0.00] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=4, Nodes=1
> [0.00] rcu: Hierarchical RCU implementation.
> [0.00] rcu:   RCU event tracing is enabled.
> [0.00] rcu:   RCU restricting CPUs from NR_CPUS=8 to nr_cpu_ids=4.
> [0.00] rcu: RCU calculated value of scheduler-enlistment delay is 10 
> jiffies.
> [0.00] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=4
> [0.00] NR_IRQS: 16, nr_irqs: 16, preallocated irqs: 16
> [0.00] GIC: Using split EOI/Deactivate mode
> [0.00] random: get_random_bytes called from start_kernel+0x320/0x4ac 
> with crng_init=0
> [0.00] arch_timer: cp15 timer(s) running at 24.00MHz (phys).
> [0.00] clocksource: arch_sys_counter: mask: 0xff 
> max_cycles: 0x588fe9dc0, max_idle_ns: 440795202592 ns
> [0.07] sched_clock: 56 bits at 24MHz, resolution 41ns, wraps every 
> 4398046511097ns
> [0.20] Switching to timer-based delay loop, resolution 41ns
> [0.000176] Console: colour dummy device 80x30
> [0.000230] Calibrating delay loop (skipped), value calculated using timer 
> frequency.. 48.00 BogoMIPS (lpj=24)
> [0.000251] pid_max: default: 32768 minimum: 301
> [0.000395] Mount-cache hash table entries: 2048 (order: 1, 8192 bytes, 
> linear)
> [0.000414] Mountpoint-cache hash table entries: 2048 (order: 1, 8192 
> bytes, linear)
> [0.001117] CPU: Testing write buffer coherency: ok
> [0.001420] /cpus/cpu@0 missing clock-frequency property
> [0.001442] /cpus/cpu@1 missing clock-frequency property
> [0.001459] /cpus/cpu@2 missing clock-frequency property
> [0.001477] /cpus/cpu@3 missing clock-frequency property
> [0.001490] CPU0: thread -1, cpu 0, socket 0, mpidr 8000
> [0.002001] Setting up static identity map for 0x4010 - 0x40100060
> [0.002119] rcu: Hierarchical SRCU implementation.
> [0.002580] smp: Bringing up secondary CPUs ...
> [0.013271] CPU1: thread -1, cpu 1, socket 0, mpidr 8001
> [0.024063] CPU2: thread -1, cpu 2, socket 0, mpidr 8002
> [0.034784] CPU3: thread -1, cpu 3, socket 0, mpidr 8003
> [0.034880] smp: Brought up 1 node, 4 CPUs
> [0.034904] SMP: Total of 4 processors activated (192.00 BogoMIPS).
> [0.034912] CPU: All CPU(s) started in HYP mode.
> [0.034919] CPU: Virtualization extensions available.
> [0.035754] devtmpfs: initialized
> [0.041021] VFP support v0.3: implementor 41 architecture 2 part 30 
> variant 7 rev 5
> [0.041258] clocksource: ji

[BUG] Error applying setting, reverse things back on lot of devices

2020-10-21 Thread Corentin Labbe
Hello

On next-20201016, booting my sun8i-r40-bananapi-m2-ultra, the boot end without 
at least stmmac working.
[0.00] Booting Linux on physical CPU 0x0
[0.00] Linux version 5.9.0-next-20201016-00055-g98489213ff7c-dirty 
(compile@Red) (armv7a-unknown-linux-gnueabihf-gcc (Gentoo 9.3.0-r1 p3) 9.3.0, 
GNU ld (Gentoo 2.33.1 p2) 2.33.1) #162 SMP Tue Oct 20 08:10:25 CEST 2020
[0.00] CPU: ARMv7 Processor [410fc075] revision 5 (ARMv7), cr=10c5387d
[0.00] CPU: div instructions available: patching division code
[0.00] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing 
instruction cache
[0.00] OF: fdt: Machine model: Banana Pi BPI-M2-Ultra
[0.00] Memory policy: Data cache writealloc
[0.00] cma: Reserved 16 MiB at 0xbec0
[0.00] Zone ranges:
[0.00]   Normal   [mem 0x4000-0x6fff]
[0.00]   HighMem  [mem 0x7000-0xbfff]
[0.00] Movable zone start for each node
[0.00] Early memory node ranges
[0.00]   node   0: [mem 0x4000-0xbfff]
[0.00] Initmem setup node 0 [mem 0x4000-0xbfff]
[0.00] psci: probing for conduit method from DT.
[0.00] psci: Using PSCI v0.1 Function IDs from DT
[0.00] percpu: Embedded 15 pages/cpu s30924 r8192 d22324 u61440
[0.00] Built 1 zonelists, mobility grouping on.  Total pages: 522752
[0.00] Kernel command line: console=ttyS0,115200n8 root=/dev/ram0 
ip=dhcp trace_event=initcall:*,module:* trace_options=stacktrace ip=dhcp
[0.00] Dentry cache hash table entries: 131072 (order: 7, 524288 bytes, 
linear)
[0.00] Inode-cache hash table entries: 65536 (order: 6, 262144 bytes, 
linear)
[0.00] mem auto-init: stack:off, heap alloc:off, heap free:off
[0.00] Memory: 2020320K/2097152K available (7168K kernel code, 934K 
rwdata, 2252K rodata, 1024K init, 248K bss, 60448K reserved, 16384K 
cma-reserved, 1294324K highmem)
[0.00] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=4, Nodes=1
[0.00] rcu: Hierarchical RCU implementation.
[0.00] rcu: RCU event tracing is enabled.
[0.00] rcu: RCU restricting CPUs from NR_CPUS=8 to nr_cpu_ids=4.
[0.00] rcu: RCU calculated value of scheduler-enlistment delay is 10 
jiffies.
[0.00] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=4
[0.00] NR_IRQS: 16, nr_irqs: 16, preallocated irqs: 16
[0.00] GIC: Using split EOI/Deactivate mode
[0.00] random: get_random_bytes called from start_kernel+0x320/0x4ac 
with crng_init=0
[0.00] arch_timer: cp15 timer(s) running at 24.00MHz (phys).
[0.00] clocksource: arch_sys_counter: mask: 0xff 
max_cycles: 0x588fe9dc0, max_idle_ns: 440795202592 ns
[0.07] sched_clock: 56 bits at 24MHz, resolution 41ns, wraps every 
4398046511097ns
[0.20] Switching to timer-based delay loop, resolution 41ns
[0.000176] Console: colour dummy device 80x30
[0.000230] Calibrating delay loop (skipped), value calculated using timer 
frequency.. 48.00 BogoMIPS (lpj=24)
[0.000251] pid_max: default: 32768 minimum: 301
[0.000395] Mount-cache hash table entries: 2048 (order: 1, 8192 bytes, 
linear)
[0.000414] Mountpoint-cache hash table entries: 2048 (order: 1, 8192 bytes, 
linear)
[0.001117] CPU: Testing write buffer coherency: ok
[0.001420] /cpus/cpu@0 missing clock-frequency property
[0.001442] /cpus/cpu@1 missing clock-frequency property
[0.001459] /cpus/cpu@2 missing clock-frequency property
[0.001477] /cpus/cpu@3 missing clock-frequency property
[0.001490] CPU0: thread -1, cpu 0, socket 0, mpidr 8000
[0.002001] Setting up static identity map for 0x4010 - 0x40100060
[0.002119] rcu: Hierarchical SRCU implementation.
[0.002580] smp: Bringing up secondary CPUs ...
[0.013271] CPU1: thread -1, cpu 1, socket 0, mpidr 8001
[0.024063] CPU2: thread -1, cpu 2, socket 0, mpidr 8002
[0.034784] CPU3: thread -1, cpu 3, socket 0, mpidr 8003
[0.034880] smp: Brought up 1 node, 4 CPUs
[0.034904] SMP: Total of 4 processors activated (192.00 BogoMIPS).
[0.034912] CPU: All CPU(s) started in HYP mode.
[0.034919] CPU: Virtualization extensions available.
[0.035754] devtmpfs: initialized
[0.041021] VFP support v0.3: implementor 41 architecture 2 part 30 variant 
7 rev 5
[0.041258] clocksource: jiffies: mask: 0x max_cycles: 0x, 
max_idle_ns: 1911260446275 ns
[0.041283] futex hash table entries: 1024 (order: 4, 65536 bytes, linear)
[0.042026] pinctrl core: initialized pinctrl subsystem
[0.043049] NET: Registered protocol family 16
[0.044324] DMA: preallocated 256 KiB pool for atomic coherent allocations
[0.045360] thermal_sys: Registered thermal governor 'step_wise'
[0.045788] hw-breakpoint: found 5 (+1 reserved) 

[PATCH] arm64: dts: allwinner: Pine H64: Enable both RGMII RX/TX delay

2020-10-19 Thread Corentin Labbe
Since commit bbc4d71d6354 ("net: phy: realtek: fix rtl8211e rx/tx delay 
config"),
the network is unusable on PineH64 model A.

This is due to phy-mode incorrectly set to rgmii instead of rgmii-id.

Fixes: 729e1ffcf47e ("arm64: allwinner: h6: add support for the Ethernet on 
Pine H64")
Signed-off-by: Corentin Labbe 
---
 arch/arm64/boot/dts/allwinner/sun50i-h6-pine-h64.dts | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/boot/dts/allwinner/sun50i-h6-pine-h64.dts 
b/arch/arm64/boot/dts/allwinner/sun50i-h6-pine-h64.dts
index af85b2074867..961732c52aa0 100644
--- a/arch/arm64/boot/dts/allwinner/sun50i-h6-pine-h64.dts
+++ b/arch/arm64/boot/dts/allwinner/sun50i-h6-pine-h64.dts
@@ -100,7 +100,7 @@  {
  {
pinctrl-names = "default";
pinctrl-0 = <_rgmii_pins>;
-   phy-mode = "rgmii";
+   phy-mode = "rgmii-id";
phy-handle = <_rgmii_phy>;
phy-supply = <_gmac_3v3>;
allwinner,rx-delay-ps = <200>;
-- 
2.26.2



Re: [PATCH 2/2] crypto: sun8x-ce*: update entries to its documentation

2020-10-09 Thread Corentin Labbe
On Fri, Oct 09, 2020 at 02:15:31PM +0200, Mauro Carvalho Chehab wrote:
> The README file was converted to ReST format. Update the
> references for it accordingly.
> 
> Signed-off-by: Mauro Carvalho Chehab 
> ---
>  drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c | 2 +-
>  drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c | 2 +-
>  drivers/crypto/allwinner/sun8i-ce/sun8i-ce-trng.c | 2 +-
>  3 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c 
> b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c
> index fa2f1b4fad7b..a94bf28f858a 100644
> --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c
> +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c
> @@ -7,7 +7,7 @@
>   *
>   * This file add support for MD5 and SHA1/SHA224/SHA256/SHA384/SHA512.
>   *
> - * You could find the datasheet in Documentation/arm/sunxi/README
> + * You could find the datasheet in Documentation/arm/sunxi.rst
>   */
>  #include 
>  #include 
> diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c 
> b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c
> index 78503006949c..cfde9ee4356b 100644
> --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c
> +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c
> @@ -7,7 +7,7 @@
>   *
>   * This file handle the PRNG
>   *
> - * You could find a link for the datasheet in Documentation/arm/sunxi/README
> + * You could find a link for the datasheet in Documentation/arm/sunxi.rst
>   */
>  #include "sun8i-ce.h"
>  #include 
> diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-trng.c 
> b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-trng.c
> index 654328160d19..5b7af4498bd5 100644
> --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-trng.c
> +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-trng.c
> @@ -7,7 +7,7 @@
>   *
>   * This file handle the TRNG
>   *
> - * You could find a link for the datasheet in Documentation/arm/sunxi/README
> + * You could find a link for the datasheet in Documentation/arm/sunxi.rst
>   */
>  #include "sun8i-ce.h"
>  #include 
> -- 
> 2.26.2
> 

Hello

Acked-by: Corentin Labbe 

Thanks


Re: [v2 PATCH] crypto: sun4i-ss - Fix sparse endianness markers

2020-10-08 Thread Corentin Labbe
On Thu, Oct 08, 2020 at 04:52:38PM +1100, Herbert Xu wrote:
> On Thu, Sep 24, 2020 at 03:27:38PM +0200, Corentin Labbe wrote:
> >
> > This is an example on next-20200923+BigEndian
> > alg: ahash: sha1 test failed (wrong result) on test vector \"random: 
> > psize=194 ksize=0\", cfg=\"random: inplace may_sleep use_finup 
> > src_divs=[98.25%@+1124, 1.75%@+5] iv_offset=18\"
> 
> Hmm, the only way I can see this happening is if it was triggered
> by tcrypt.  Were you using tcrypt by any chance?
> 
> Ccing Eric in case he has any insight.
> 
> > === DUMP /proc/crypto ===
> > name : sha1
> > driver   : sha1-sun4i-ss
> > module   : kernel
> > priority : 300
> > refcnt   : 1
> > selftest : passed
> > internal : no
> > type : ahash
> > async: no
> > blocksize: 64
> > digestsize   : 20
> 
> ...
> 
> > name : sha1
> > driver   : sha1-generic
> > module   : kernel
> > priority : 100
> > refcnt   : 1
> > selftest : passed
> > internal : no
> > type : shash
> > blocksize: 64
> > digestsize   : 20
> 
> Thanks,

Yes I use tcrypt to force all algos to be tested.


Re: WARNING: at kernel/workqueue.c:1473 __queue_work+0x3b8/0x3d0

2020-10-07 Thread Corentin Labbe
On Mon, Oct 05, 2020 at 01:09:10PM -0400, Daniel Jordan wrote:
> On Thu, Oct 01, 2020 at 07:50:22PM +0200, Corentin Labbe wrote:
> > On Tue, Mar 03, 2020 at 04:30:17PM -0500, Daniel Jordan wrote:
> > > Barring other ideas, Corentin, would you be willing to boot with
> > > 
> > > trace_event=initcall:*,module:* trace_options=stacktrace
> > > 
> > > and
> > > 
> > > diff --git a/kernel/module.c b/kernel/module.c
> > > index 33569a01d6e1..393be6979a27 100644
> > > --- a/kernel/module.c
> > > +++ b/kernel/module.c
> > > @@ -3604,8 +3604,11 @@ static noinline int do_init_module(struct module 
> > > *mod)
> > >* be cleaned up needs to sync with the queued work - ie
> > >* rcu_barrier()
> > >*/
> > > - if (llist_add(>node, _free_list))
> > > + if (llist_add(>node, _free_list)) {
> > > + pr_warn("%s: schedule_work for mod=%s\n", __func__, mod->name);
> > > + dump_stack();
> > >   schedule_work(_free_wq);
> > > + }
> > >  
> > >   mutex_unlock(_mutex);
> > >   wake_up_all(_wq);
> > > 
> > > but not my earlier fix and share the dmesg and ftrace output to see if the
> > > theory holds?
> > > 
> > > Also, could you attach your config?  Curious now what your crypto options 
> > > look
> > > like after fiddling with some of them today while trying and failing to 
> > > see
> > > this on x86.
> > > 
> > > thanks,
> > > Daniel
> > 
> > Hello
> > 
> > Sorry for the very delayed answer.
> > 
> > I fail to reproduce it on x86 (qemu and  real hw) and arm.
> > It seems to only happen on arm64.
> 
> Thanks for the config and dmesg, but there's no ftrace.  I see it's not
> configured in your kernel, so could you boot with my earlier debug patch plus
> this one and the kernel argument initcall_debug instead?
> 
> I'm trying to see whether it really is a request module call from the crypto
> tests that's triggering this warning.  Preeetty likely that's what's 
> happening,
> but want to be sure since I can't reproduce this.  Then I can post the fix.
> 

I have added CONFIG_FTRACE=y and your second patch.
The boot log can be seen at http://kernel.montjoie.ovh/108789.log

But it seems the latest dump_stack addition flood a bit.
I have started to read ftrace documentation, but if you have a quick what to do 
in /sys/kernel/debug/tracing, it will be helpfull.



Re: [PATCH][next] crypto: sun8i-ss - Fix memory leak in sun8i_ss_prng_generate()

2020-10-02 Thread Corentin Labbe
On Mon, Sep 28, 2020 at 12:59:45PM -0500, Gustavo A. R. Silva wrote:
> Set _err_ to the return error code -EFAULT before jumping to the new
> label err_d, so resources for _d_ can be released before returning
> from function sun8i_ss_prng_generate().
> 
> Addresses-Coverity-ID: 1497459 ("Resource leak")
> Fixes: ac2614d721de ("crypto: sun8i-ss - Add support for the PRNG")
> Signed-off-by: Gustavo A. R. Silva 
> ---
>  drivers/crypto/allwinner/sun8i-ss/sun8i-ss-prng.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-prng.c 
> b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-prng.c
> index 08a1473b2145..0573f6289e8b 100644
> --- a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-prng.c
> +++ b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-prng.c
> @@ -103,7 +103,8 @@ int sun8i_ss_prng_generate(struct crypto_rng *tfm, const 
> u8 *src,
>   dma_iv = dma_map_single(ss->dev, ctx->seed, ctx->slen, DMA_TO_DEVICE);
>   if (dma_mapping_error(ss->dev, dma_iv)) {
>   dev_err(ss->dev, "Cannot DMA MAP IV\n");
> - return -EFAULT;
> + err = -EFAULT;
> + goto err_d;
>   }
>  
>   dma_dst = dma_map_single(ss->dev, d, todo, DMA_FROM_DEVICE);
> @@ -160,7 +161,7 @@ int sun8i_ss_prng_generate(struct crypto_rng *tfm, const 
> u8 *src,
>   dma_unmap_single(ss->dev, dma_dst, todo, DMA_FROM_DEVICE);
>  err_iv:
>   dma_unmap_single(ss->dev, dma_iv, ctx->slen, DMA_TO_DEVICE);
> -
> +err_d:
>   if (!err) {
>   memcpy(dst, d, dlen);
>   /* Update seed */
> -- 
> 2.27.0
> 

Hello

The label could be better placed just before the kfree.
In error case, there are no need to memzero the not used "d".

But a patch with it, was already sent to the ML.
Anyway if you fix it, you could add "Acked-by: Corentin Labbe 
"

Regards


[PATCH RFT/RFC v2 46/47] staging: media: zoran: convert to vb2

2020-09-25 Thread Corentin Labbe
This is it! the ultimate last step, the vb2 conversion.

Signed-off-by: Corentin Labbe 
---
 drivers/staging/media/zoran/Kconfig|2 +-
 drivers/staging/media/zoran/zoran.h|   83 +-
 drivers/staging/media/zoran/zoran_card.c   |   45 +-
 drivers/staging/media/zoran/zoran_device.c |  488 ++-
 drivers/staging/media/zoran/zoran_driver.c | 1453 +---
 5 files changed, 137 insertions(+), 1934 deletions(-)

diff --git a/drivers/staging/media/zoran/Kconfig 
b/drivers/staging/media/zoran/Kconfig
index ddf38a931c01..492507030276 100644
--- a/drivers/staging/media/zoran/Kconfig
+++ b/drivers/staging/media/zoran/Kconfig
@@ -1,6 +1,6 @@
 config VIDEO_ZORAN
tristate "Zoran ZR36057/36067 Video For Linux (Deprecated)"
-   depends on PCI && I2C_ALGOBIT && VIDEO_V4L2 && VIRT_TO_BUS
+   depends on PCI && I2C_ALGOBIT && VIDEO_V4L2
depends on !ALPHA
select VIDEOBUF2_DMA_CONTIG
help
diff --git a/drivers/staging/media/zoran/zoran.h 
b/drivers/staging/media/zoran/zoran.h
index fd27d1968e60..372fadfd9a01 100644
--- a/drivers/staging/media/zoran/zoran.h
+++ b/drivers/staging/media/zoran/zoran.h
@@ -20,7 +20,6 @@
 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -29,13 +28,6 @@
 #define ZR_NORM_NTSC 1
 #define ZR_NORM_SECAM 2
 
-struct zoran_sync {
-   unsigned long frame;/* number of buffer that has been free'd */
-   unsigned long length;   /* number of code bytes in buffer (capture 
only) */
-   unsigned long seq;  /* frame sequence number */
-   u64 ts; /* timestamp */
-};
-
 struct zr_buffer {
/* common v4l buffer stuff -- must be first */
struct vb2_v4l2_buffer  vbuf;
@@ -111,18 +103,10 @@ enum zoran_codec_mode {
BUZ_MODE_STILL_DECOMPRESS   /* still frame conversion */
 };
 
-enum zoran_buffer_state {
-   BUZ_STATE_USER, /* buffer is owned by application */
-   BUZ_STATE_PEND, /* buffer is queued in pend[] ready to feed to 
I/O */
-   BUZ_STATE_DMA,  /* buffer is queued in dma[] for I/O */
-   BUZ_STATE_DONE  /* buffer is ready to return to application */
-};
-
 enum zoran_map_mode {
ZORAN_MAP_MODE_NONE,
ZORAN_MAP_MODE_RAW,
ZORAN_MAP_MODE_JPG_REC,
-#define ZORAN_MAP_MODE_JPG ZORAN_MAP_MODE_JPG_REC
ZORAN_MAP_MODE_JPG_PLAY,
 };
 
@@ -174,45 +158,6 @@ struct zoran_jpg_settings {
struct v4l2_jpegcompression jpg_comp;   /* JPEG-specific capture 
settings */
 };
 
-struct zoran_fh;
-
-struct zoran_mapping {
-   struct zoran_fh *fh;
-   atomic_t count;
-};
-
-struct zoran_buffer {
-   struct zoran_mapping *map;
-   enum zoran_buffer_state state;  /* state: unused/pending/dma/done */
-   struct zoran_sync bs;   /* DONE: info to return to application 
*/
-   union {
-   struct {
-   __le32 *frag_tab;   /* addresses of frag table */
-   u32 frag_tab_bus;   /* same value cached to save 
time in ISR */
-   } jpg;
-   struct {
-   char *fbuffer;  /* virtual address of frame 
buffer */
-   unsigned long fbuffer_phys;/* physical address of frame 
buffer */
-   unsigned long fbuffer_bus;/* bus address of frame 
buffer */
-   } v4l;
-   };
-};
-
-enum zoran_lock_activity {
-   ZORAN_FREE, /* free for use */
-   ZORAN_ACTIVE,   /* active but unlocked */
-   ZORAN_LOCKED,   /* locked */
-};
-
-/* buffer collections */
-struct zoran_buffer_col {
-   enum zoran_lock_activity active;/* feature currently in use? */
-   unsigned int num_buffers;
-   struct zoran_buffer buffer[MAX_FRAME];  /* buffers */
-   u8 allocated;   /* Flag if buffers are allocated */
-   u8 need_contiguous; /* Flag if contiguous buffers are needed */
-   /* only applies to jpg buffers, raw buffers are always contiguous */
-};
 
 struct zoran;
 
@@ -220,10 +165,6 @@ struct zoran;
 struct zoran_fh {
struct v4l2_fh fh;
struct zoran *zr;
-
-   enum zoran_map_mode map_mode;   /* Flag which bufferset will 
map by next mmap() */
-
-   struct zoran_buffer_col buffers;/* buffers' info */
 };
 
 struct card_info {
@@ -281,7 +222,6 @@ struct zoran {
struct mutex lock;  /* file ops serialize lock */
 
u8 initialized; /* flag if zoran has been correctly initialized 
*/
-   int user;   /* number of current users */
struct card_info card;
const struct tvnorm *timing;
 
@@ -300,28 +240,12 @@ struct zoran {
/* Current buffer params */
unsigned int buffer_size;
 
-   wait_queue_head_t v4l_capq;
-
-   int v4l_memgrab_active; /* Memory grab is activated */
-
-   int v4l_grab_

[PATCH RFT/RFC v2 45/47] staging: media: zoran: remove deprecated .vidioc_g_jpegcomp

2020-09-25 Thread Corentin Labbe
This patchs removed the deprecated .vidioc_g_jpegcomp and replace it
with corresponding v4l2_ctrl_ops code.

Signed-off-by: Corentin Labbe 
---
 drivers/staging/media/zoran/zoran_card.c   | 22 ++
 drivers/staging/media/zoran/zoran_driver.c | 49 --
 2 files changed, 22 insertions(+), 49 deletions(-)

diff --git a/drivers/staging/media/zoran/zoran_card.c 
b/drivers/staging/media/zoran/zoran_card.c
index d7b3efa9e39f..fe52be4292fe 100644
--- a/drivers/staging/media/zoran/zoran_card.c
+++ b/drivers/staging/media/zoran/zoran_card.c
@@ -1066,6 +1066,25 @@ static void zoran_subdev_notify(struct v4l2_subdev *sd, 
unsigned int cmd, void *
GPIO(zr, 7, 1);
 }
 
+static int zoran_video_set_ctrl(struct v4l2_ctrl *ctrl)
+{
+   struct zoran *zr = container_of(ctrl->handler, struct zoran, hdl);
+
+   switch (ctrl->id) {
+   case V4L2_CID_JPEG_COMPRESSION_QUALITY:
+   zr->jpg_settings.jpg_comp.quality = ctrl->val;
+   return zoran_check_jpg_settings(zr, >jpg_settings, 0);
+   default:
+   return -EINVAL;
+   }
+
+   return 0;
+}
+
+static const struct v4l2_ctrl_ops zoran_video_ctrl_ops = {
+   .s_ctrl = zoran_video_set_ctrl,
+};
+
 /*
  *   Scan for a Buz card (actually for the PCI controller ZR36057),
  *   request the irq and map the io memory
@@ -1106,6 +1125,9 @@ static int zoran_probe(struct pci_dev *pdev, const struct 
pci_device_id *ent)
if (v4l2_ctrl_handler_init(>hdl, 10))
goto zr_unreg;
zr->v4l2_dev.ctrl_handler = >hdl;
+   v4l2_ctrl_new_std(>hdl, _video_ctrl_ops,
+ V4L2_CID_JPEG_COMPRESSION_QUALITY, 0,
+ 100, 1, 50);
spin_lock_init(>spinlock);
mutex_init(>lock);
if (pci_enable_device(pdev))
diff --git a/drivers/staging/media/zoran/zoran_driver.c 
b/drivers/staging/media/zoran/zoran_driver.c
index ab9eec50abad..a6fb41d03186 100644
--- a/drivers/staging/media/zoran/zoran_driver.c
+++ b/drivers/staging/media/zoran/zoran_driver.c
@@ -1849,53 +1849,6 @@ static int zoran_s_selection(struct file *file, void 
*__fh, struct v4l2_selectio
return res;
 }
 
-static int zoran_g_jpegcomp(struct file *file, void *__fh,
-   struct v4l2_jpegcompression *params)
-{
-   struct zoran *zr = video_drvdata(file);
-
-   memset(params, 0, sizeof(*params));
-
-   params->quality = zr->jpg_settings.jpg_comp.quality;
-   params->APPn = zr->jpg_settings.jpg_comp.APPn;
-   memcpy(params->APP_data, zr->jpg_settings.jpg_comp.APP_data,
-  zr->jpg_settings.jpg_comp.APP_len);
-   params->APP_len = zr->jpg_settings.jpg_comp.APP_len;
-   memcpy(params->COM_data, zr->jpg_settings.jpg_comp.COM_data,
-  zr->jpg_settings.jpg_comp.COM_len);
-   params->COM_len = zr->jpg_settings.jpg_comp.COM_len;
-   params->jpeg_markers = zr->jpg_settings.jpg_comp.jpeg_markers;
-
-   return 0;
-}
-
-static int zoran_s_jpegcomp(struct file *file, void *__fh,
-   const struct v4l2_jpegcompression *params)
-{
-   struct zoran_fh *fh = __fh;
-   struct zoran *zr = fh->zr;
-   int res = 0;
-   struct zoran_jpg_settings settings;
-
-   settings = zr->jpg_settings;
-
-   settings.jpg_comp = *params;
-
-   if (fh->buffers.active != ZORAN_FREE) {
-   pci_warn(zr->pci_dev, "VIDIOC_S_JPEGCOMP called while in 
playback/capture mode\n");
-   res = -EBUSY;
-   return res;
-   }
-
-   res = zoran_check_jpg_settings(zr, , 0);
-   if (res)
-   return res;
-   if (!fh->buffers.allocated)
-   zr->buffer_size = zoran_v4l2_calc_bufsize(>jpg_settings);
-   zr->jpg_settings.jpg_comp = settings.jpg_comp;
-   return res;
-}
-
 static __poll_t zoran_poll(struct file *file, poll_table  *wait)
 {
struct zoran_fh *fh = file->private_data;
@@ -2176,8 +2129,6 @@ static const struct v4l2_ioctl_ops zoran_ioctl_ops = {
.vidioc_s_output= zoran_s_output,*/
.vidioc_g_std   = zoran_g_std,
.vidioc_s_std   = zoran_s_std,
-   .vidioc_g_jpegcomp  = zoran_g_jpegcomp,
-   .vidioc_s_jpegcomp  = zoran_s_jpegcomp,
.vidioc_reqbufs = zoran_reqbufs,
.vidioc_querybuf= zoran_querybuf,
.vidioc_qbuf= zoran_qbuf,
-- 
2.26.2



[PATCH RFT/RFC v2 47/47] staging: media: zoran: update TODO

2020-09-25 Thread Corentin Labbe
Update the TODO of the zoran driver

Signed-off-by: Corentin Labbe 
---
 drivers/staging/media/zoran/TODO | 23 +++
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/media/zoran/TODO b/drivers/staging/media/zoran/TODO
index 54464095d0d7..6992540d3e53 100644
--- a/drivers/staging/media/zoran/TODO
+++ b/drivers/staging/media/zoran/TODO
@@ -1,4 +1,19 @@
-The zoran driver is marked deprecated. It will be removed
-around May 2019 unless someone is willing to update this
-driver to the latest V4L2 frameworks (especially the vb2
-framework).
+
+How to test the zoran driver:
+- RAW capture
+   mplayer tv:///dev/video0 -tv driver=v4l2
+
+- MJPEG capture (compression)
+   mplayer tv:///dev/video0 -tv driver=v4l2:outfmt=mjpeg
+   TODO: need two test for both Dcim path
+
+- MJPEG play (decompression)
+   ffmpeg -i test.avi -vcodec mjpeg -an -f v4l2 /dev/video0
+   Note: only recent ffmpeg has the ability of sending non-raw video via 
v4l2
+
+   The original way of sending video was via mplayer vo_zr/vo_zr2, but it 
does not compile
+   anymore and is a dead end (usage of some old private ffmpeg structures).
+
+TODO
+- fix the v4l compliance "TRY_FMT cannot handle an invalid pixelformat"
+- Filter JPEG data to made output work
-- 
2.26.2



[PATCH RFT/RFC v2 44/47] staging: media: zoran: fix some compliance test

2020-09-25 Thread Corentin Labbe
Add TODO for "TRY_FMT cannot handle an invalid pixelformat"

We need to set pixelformat in some case.
We should also handle some minimum requirement.

Signed-off-by: Corentin Labbe 
---
 drivers/staging/media/zoran/zoran_driver.c | 12 +++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/media/zoran/zoran_driver.c 
b/drivers/staging/media/zoran/zoran_driver.c
index 021073ba08e6..ab9eec50abad 100644
--- a/drivers/staging/media/zoran/zoran_driver.c
+++ b/drivers/staging/media/zoran/zoran_driver.c
@@ -1217,9 +1217,12 @@ static int zoran_try_fmt_vid_cap(struct file *file, void 
*__fh,
if (zoran_formats[i].fourcc == fmt->fmt.pix.pixelformat)
break;
 
-   if (i == NUM_FORMATS)
+   if (i == NUM_FORMATS) {
+   /* TODO do not return here to fix the TRY_FMT cannot handle an 
invalid pixelformat*/
return -EINVAL;
+   }
 
+   fmt->fmt.pix.pixelformat = zoran_formats[i].fourcc;
fmt->fmt.pix.colorspace = zoran_formats[i].colorspace;
if (BUZ_MAX_HEIGHT < (fmt->fmt.pix.height * 2))
fmt->fmt.pix.field = V4L2_FIELD_INTERLACED;
@@ -1332,6 +1335,7 @@ static int zoran_s_fmt_vid_cap(struct file *file, void 
*__fh,
if (i == NUM_FORMATS) {
pci_err(zr->pci_dev, "VIDIOC_S_FMT - unknown/unsupported format 
0x%x\n",
fmt->fmt.pix.pixelformat);
+   /* TODO do not return here to fix the TRY_FMT cannot handle an 
invalid pixelformat*/
return -EINVAL;
}
 
@@ -1341,10 +1345,16 @@ static int zoran_s_fmt_vid_cap(struct file *file, void 
*__fh,
res = -EBUSY;
return res;
}
+
+   fmt->fmt.pix.pixelformat = zoran_formats[i].fourcc;
if (fmt->fmt.pix.height > BUZ_MAX_HEIGHT)
fmt->fmt.pix.height = BUZ_MAX_HEIGHT;
if (fmt->fmt.pix.width > BUZ_MAX_WIDTH)
fmt->fmt.pix.width = BUZ_MAX_WIDTH;
+   if (fmt->fmt.pix.height < BUZ_MIN_HEIGHT)
+   fmt->fmt.pix.height = BUZ_MIN_HEIGHT;
+   if (fmt->fmt.pix.width < BUZ_MIN_WIDTH)
+   fmt->fmt.pix.width = BUZ_MIN_WIDTH;
 
map_mode_raw(fh);
 
-- 
2.26.2



[PATCH RFT/RFC v2 38/47] staging: media: zoran: device support only 32bit DMA address

2020-09-25 Thread Corentin Labbe
The zoran device only supports 32bit DMA address.

Signed-off-by: Corentin Labbe 
---
 drivers/staging/media/zoran/zoran_card.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/staging/media/zoran/zoran_card.c 
b/drivers/staging/media/zoran/zoran_card.c
index dbdb1c4b0515..0a193283eefc 100644
--- a/drivers/staging/media/zoran/zoran_card.c
+++ b/drivers/staging/media/zoran/zoran_card.c
@@ -,6 +,12 @@ static int zoran_probe(struct pci_dev *pdev, const 
struct pci_device_id *ent)
int card_num;
const char *codec_name, *vfe_name;
unsigned int nr;
+   int err;
+
+   err = dma_set_mask_and_coherent(>dev, DMA_BIT_MASK(32));
+   if (err)
+   return -ENODEV;
+   vb2_dma_contig_set_max_seg_size(>dev, DMA_BIT_MASK(32));
 
nr = zoran_num++;
if (nr >= BUZ_MAX) {
-- 
2.26.2



[PATCH RFT/RFC v2 42/47] staging: media: zoran: remove test_interrupts

2020-09-25 Thread Corentin Labbe
The test_interrupts function is useless, remove it.

Signed-off-by: Corentin Labbe 
---
 drivers/staging/media/zoran/zoran.h|  3 ---
 drivers/staging/media/zoran/zoran_card.c   | 27 --
 drivers/staging/media/zoran/zoran_device.c | 16 -
 3 files changed, 46 deletions(-)

diff --git a/drivers/staging/media/zoran/zoran.h 
b/drivers/staging/media/zoran/zoran.h
index 0246635e0eac..fd27d1968e60 100644
--- a/drivers/staging/media/zoran/zoran.h
+++ b/drivers/staging/media/zoran/zoran.h
@@ -345,7 +345,6 @@ struct zoran {
struct zoran_buffer_col jpg_buffers;/* MJPEG buffers' info */
 
/* Additional stuff for testing */
-   int testing;
int jpeg_error;
int intr_counter_GIRQ1;
int intr_counter_GIRQ0;
@@ -372,8 +371,6 @@ struct zoran {
int running;
int buf_in_reserve;
 
-   wait_queue_head_t test_q;
-
dma_addr_t p_sc;
__le32 *stat_comb;
dma_addr_t p_scb;
diff --git a/drivers/staging/media/zoran/zoran_card.c 
b/drivers/staging/media/zoran/zoran_card.c
index 28a403257bb9..89fbc114c368 100644
--- a/drivers/staging/media/zoran/zoran_card.c
+++ b/drivers/staging/media/zoran/zoran_card.c
@@ -858,31 +858,6 @@ void zoran_open_init_params(struct zoran *zr)
pci_err(zr->pci_dev, "%s internal error\n", __func__);
 
clear_interrupt_counters(zr);
-   zr->testing = 0;
-}
-
-static void test_interrupts(struct zoran *zr)
-{
-   DEFINE_WAIT(wait);
-   int timeout, icr;
-
-   clear_interrupt_counters(zr);
-
-   zr->testing = 1;
-   icr = btread(ZR36057_ICR);
-   btwrite(0x7800 | ZR36057_ICR_IntPinEn, ZR36057_ICR);
-   prepare_to_wait(>test_q, , TASK_INTERRUPTIBLE);
-   timeout = schedule_timeout(HZ);
-   finish_wait(>test_q, );
-   btwrite(0, ZR36057_ICR);
-   btwrite(0x7800, ZR36057_ISR);
-   zr->testing = 0;
-   pci_info(zr->pci_dev, "Testing interrupts...\n");
-   if (timeout)
-   pci_info(zr->pci_dev, ": time spent: %d\n", 1 * HZ - timeout);
-   if (zr36067_debug > 1)
-   print_interrupts(zr);
-   btwrite(icr, ZR36057_ICR);
 }
 
 static int zr36057_init(struct zoran *zr)
@@ -896,7 +871,6 @@ static int zr36057_init(struct zoran *zr)
 
init_waitqueue_head(>v4l_capq);
init_waitqueue_head(>jpg_capq);
-   init_waitqueue_head(>test_q);
zr->jpg_buffers.allocated = 0;
zr->v4l_buffers.allocated = 0;
 
@@ -977,7 +951,6 @@ static int zr36057_init(struct zoran *zr)
zoran_init_hardware(zr);
if (zr36067_debug > 2)
detect_guest_activity(zr);
-   test_interrupts(zr);
if (!pass_through) {
decoder_call(zr, video, s_stream, 0);
encoder_call(zr, video, s_routing, 2, 0, 0);
diff --git a/drivers/staging/media/zoran/zoran_device.c 
b/drivers/staging/media/zoran/zoran_device.c
index fb318449d784..c090d7166caa 100644
--- a/drivers/staging/media/zoran/zoran_device.c
+++ b/drivers/staging/media/zoran/zoran_device.c
@@ -1109,22 +1109,6 @@ irqreturn_t zoran_irq(int irq, void *dev_id)
struct zoran *zr = dev_id;
unsigned long flags;
 
-   if (zr->testing) {
-   /* Testing interrupts */
-   spin_lock_irqsave(>spinlock, flags);
-   while ((stat = count_reset_interrupt(zr))) {
-   if (count++ > 100) {
-   btand(~ZR36057_ICR_IntPinEn, ZR36057_ICR);
-   pci_err(zr->pci_dev, "IRQ lockup while testing, 
isr=0x%08x, cleared int mask\n",
-   stat);
-   wake_up_interruptible(>test_q);
-   }
-   }
-   zr->last_isr = stat;
-   spin_unlock_irqrestore(>spinlock, flags);
-   return IRQ_HANDLED;
-   }
-
spin_lock_irqsave(>spinlock, flags);
while (1) {
/* get/clear interrupt status bits */
-- 
2.26.2



[PATCH RFT/RFC v2 37/47] staging: media: zoran: disable output

2020-09-25 Thread Corentin Labbe
Zoran is picky about jpeg data it accepts. At least it seems to not support COM 
and APPn.
So until a way to filter data will be done, disable output.

Signed-off-by: Corentin Labbe 
---
 drivers/staging/media/zoran/zoran_card.c   |  2 ++
 drivers/staging/media/zoran/zoran_driver.c | 20 
 2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/media/zoran/zoran_card.c 
b/drivers/staging/media/zoran/zoran_card.c
index fed368ba6fd1..dbdb1c4b0515 100644
--- a/drivers/staging/media/zoran/zoran_card.c
+++ b/drivers/staging/media/zoran/zoran_card.c
@@ -963,6 +963,8 @@ static int zr36057_init(struct zoran *zr)
*zr->video_dev = zoran_template;
zr->video_dev->v4l2_dev = >v4l2_dev;
zr->video_dev->lock = >lock;
+   zr->video_dev->device_caps = V4L2_CAP_STREAMING | 
V4L2_CAP_VIDEO_CAPTURE;
+
strscpy(zr->video_dev->name, ZR_DEVNAME(zr), 
sizeof(zr->video_dev->name));
/*
 * It's not a mem2mem device, but you can both capture and output from 
one and the same
diff --git a/drivers/staging/media/zoran/zoran_driver.c 
b/drivers/staging/media/zoran/zoran_driver.c
index e962fc6c1f9f..43f7c0c02876 100644
--- a/drivers/staging/media/zoran/zoran_driver.c
+++ b/drivers/staging/media/zoran/zoran_driver.c
@@ -1082,8 +1082,7 @@ static int zoran_querycap(struct file *file, void *__fh, 
struct v4l2_capability
strscpy(cap->card, ZR_DEVNAME(zr), sizeof(cap->card));
strscpy(cap->driver, "zoran", sizeof(cap->driver));
snprintf(cap->bus_info, sizeof(cap->bus_info), "PCI:%s", 
pci_name(zr->pci_dev));
-   cap->device_caps = V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_CAPTURE |
-  V4L2_CAP_VIDEO_OUTPUT;
+   cap->device_caps = zr->video_dev->device_caps;
cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
return 0;
 }
@@ -2221,6 +2220,11 @@ static int zoran_mmap(struct file *file, struct 
vm_area_struct *vma)
return res;
 }
 
+/*
+ * Output is disabled temporarily
+ * Zoran is picky about jpeg data it accepts. At least it seems to unsupport 
COM and APPn.
+ * So until a way to filter data will be done, disable output.
+ */
 static const struct v4l2_ioctl_ops zoran_ioctl_ops = {
.vidioc_querycap= zoran_querycap,
.vidioc_s_selection = zoran_s_selection,
@@ -2228,9 +2232,9 @@ static const struct v4l2_ioctl_ops zoran_ioctl_ops = {
.vidioc_enum_input  = zoran_enum_input,
.vidioc_g_input = zoran_g_input,
.vidioc_s_input = zoran_s_input,
-   .vidioc_enum_output = zoran_enum_output,
+/* .vidioc_enum_output = zoran_enum_output,
.vidioc_g_output= zoran_g_output,
-   .vidioc_s_output= zoran_s_output,
+   .vidioc_s_output= zoran_s_output,*/
.vidioc_g_fbuf  = zoran_g_fbuf,
.vidioc_s_fbuf  = zoran_s_fbuf,
.vidioc_g_std   = zoran_g_std,
@@ -2244,13 +2248,13 @@ static const struct v4l2_ioctl_ops zoran_ioctl_ops = {
.vidioc_streamon= zoran_streamon,
.vidioc_streamoff   = zoran_streamoff,
.vidioc_enum_fmt_vid_cap= zoran_enum_fmt_vid_cap,
-   .vidioc_enum_fmt_vid_out= zoran_enum_fmt_vid_out,
+/* .vidioc_enum_fmt_vid_out= zoran_enum_fmt_vid_out,*/
.vidioc_g_fmt_vid_cap   = zoran_g_fmt_vid_cap,
-   .vidioc_g_fmt_vid_out   = zoran_g_fmt_vid_out,
+/* .vidioc_g_fmt_vid_out   = zoran_g_fmt_vid_out,*/
.vidioc_s_fmt_vid_cap   = zoran_s_fmt_vid_cap,
-   .vidioc_s_fmt_vid_out   = zoran_s_fmt_vid_out,
+/* .vidioc_s_fmt_vid_out   = zoran_s_fmt_vid_out,*/
.vidioc_try_fmt_vid_cap = zoran_try_fmt_vid_cap,
-   .vidioc_try_fmt_vid_out = zoran_try_fmt_vid_out,
+/* .vidioc_try_fmt_vid_out = zoran_try_fmt_vid_out,*/
.vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
.vidioc_unsubscribe_event   = v4l2_event_unsubscribe,
 };
-- 
2.26.2



[PATCH RFT/RFC v2 41/47] staging: media: zoran: add vidioc_g_parm

2020-09-25 Thread Corentin Labbe
Adding vidioc_g_parm made v4l compliance happy.

Signed-off-by: Corentin Labbe 
---
 drivers/staging/media/zoran/zoran_driver.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/drivers/staging/media/zoran/zoran_driver.c 
b/drivers/staging/media/zoran/zoran_driver.c
index bcbe2c78ea16..5dacbeac790b 100644
--- a/drivers/staging/media/zoran/zoran_driver.c
+++ b/drivers/staging/media/zoran/zoran_driver.c
@@ -2137,6 +2137,14 @@ static int zoran_mmap(struct file *file, struct 
vm_area_struct *vma)
return res;
 }
 
+static int zoran_g_parm(struct file *file, void *priv, struct v4l2_streamparm 
*parm)
+{
+   if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
+   return -EINVAL;
+
+   return 0;
+}
+
 /*
  * Output is disabled temporarily
  * Zoran is picky about jpeg data it accepts. At least it seems to unsupport 
COM and APPn.
@@ -2144,6 +2152,7 @@ static int zoran_mmap(struct file *file, struct 
vm_area_struct *vma)
  */
 static const struct v4l2_ioctl_ops zoran_ioctl_ops = {
.vidioc_querycap= zoran_querycap,
+   .vidioc_g_parm  = zoran_g_parm,
.vidioc_s_selection = zoran_s_selection,
.vidioc_g_selection = zoran_g_selection,
.vidioc_enum_input  = zoran_enum_input,
-- 
2.26.2



[PATCH RFT/RFC v2 39/47] staging: media: zoran: enable makefile

2020-09-25 Thread Corentin Labbe
This patch enables compilation of the zoran driver.

Signed-off-by: Corentin Labbe 
---
 drivers/staging/media/Makefile | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/staging/media/Makefile b/drivers/staging/media/Makefile
index 25910221b100..965a8b0e6cf2 100644
--- a/drivers/staging/media/Makefile
+++ b/drivers/staging/media/Makefile
@@ -12,3 +12,4 @@ obj-$(CONFIG_VIDEO_HANTRO)+= hantro/
 obj-$(CONFIG_VIDEO_IPU3_IMGU)  += ipu3/
 obj-$(CONFIG_PHY_ROCKCHIP_DPHY_RX0)+= phy-rockchip-dphy-rx0/
 obj-$(CONFIG_VIDEO_ROCKCHIP_ISP1)  += rkisp1/
+obj-$(CONFIG_VIDEO_ZORAN)  += zoran/
-- 
2.26.2



[PATCH RFT/RFC v2 35/47] staging: media: zoran: Add more check for compliance

2020-09-25 Thread Corentin Labbe
The zoran driver miss some sanity checks, and this made v4l compliance
happy.

Signed-off-by: Corentin Labbe 
---
 drivers/staging/media/zoran/zoran_driver.c | 17 +
 1 file changed, 17 insertions(+)

diff --git a/drivers/staging/media/zoran/zoran_driver.c 
b/drivers/staging/media/zoran/zoran_driver.c
index 60bbc8235cff..5ac832eca501 100644
--- a/drivers/staging/media/zoran/zoran_driver.c
+++ b/drivers/staging/media/zoran/zoran_driver.c
@@ -1092,6 +1092,11 @@ static int zoran_enum_fmt(struct zoran *zr, struct 
v4l2_fmtdesc *fmt, int flag)
 {
unsigned int num, i;
 
+   if (fmt->index >= ARRAY_SIZE(zoran_formats))
+   return -EINVAL;
+   if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
+   return -EINVAL;
+
for (num = i = 0; i < NUM_FORMATS; i++) {
if (zoran_formats[i].flags & flag && num++ == fmt->index) {
strscpy(fmt->description, zoran_formats[i].name,
@@ -1255,6 +1260,12 @@ static int zoran_try_fmt_vid_cap(struct file *file, void 
*__fh,
if (i == NUM_FORMATS)
return -EINVAL;
 
+   fmt->fmt.pix.colorspace = zoran_formats[i].colorspace;
+   if (BUZ_MAX_HEIGHT < (fmt->fmt.pix.height * 2))
+   fmt->fmt.pix.field = V4L2_FIELD_INTERLACED;
+   else
+   fmt->fmt.pix.field = V4L2_FIELD_TOP;
+
bpp = DIV_ROUND_UP(zoran_formats[i].depth, 8);
v4l_bound_align_image(>fmt.pix.width, BUZ_MIN_WIDTH, 
BUZ_MAX_WIDTH, bpp == 2 ? 1 : 2,
>fmt.pix.height, BUZ_MIN_HEIGHT, BUZ_MAX_HEIGHT, 0, 0);
@@ -1283,6 +1294,9 @@ static int zoran_s_fmt_vid_out(struct file *file, void 
*__fh,
return res;
}
 
+   if (!fmt->fmt.pix.height || !fmt->fmt.pix.width)
+   return -EINVAL;
+
settings = zr->jpg_settings;
 
/* we actually need to set 'real' parameters now */
@@ -1872,6 +1886,9 @@ static int zoran_s_selection(struct file *file, void 
*__fh, struct v4l2_selectio
sel->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
return -EINVAL;
 
+   if (!sel->r.width || !sel->r.height)
+   return -EINVAL;
+
if (sel->target != V4L2_SEL_TGT_CROP)
return -EINVAL;
 
-- 
2.26.2



[PATCH RFT/RFC v2 34/47] staging: media: zoran: constify codec_name

2020-09-25 Thread Corentin Labbe
The codec_name could be const.

Signed-off-by: Corentin Labbe 
---
 drivers/staging/media/zoran/zoran_card.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/media/zoran/zoran_card.c 
b/drivers/staging/media/zoran/zoran_card.c
index 79783cbb919a..49a1d9e084a8 100644
--- a/drivers/staging/media/zoran/zoran_card.c
+++ b/drivers/staging/media/zoran/zoran_card.c
@@ -254,9 +254,9 @@ static void avs6eyes_init(struct zoran *zr)
GPIO(zr, 7, mux & 4);   /* MUX S2 */
 }
 
-static char *codecid_to_modulename(u16 codecid)
+static const char *codecid_to_modulename(u16 codecid)
 {
-   char *name = NULL;
+   const char *name = NULL;
 
switch (codecid) {
case CODEC_TYPE_ZR36060:
@@ -1102,7 +1102,7 @@ static int zoran_probe(struct pci_dev *pdev, const struct 
pci_device_id *ent)
struct videocodec_master *master_vfe = NULL;
struct videocodec_master *master_codec = NULL;
int card_num;
-   char *codec_name, *vfe_name;
+   const char *codec_name, *vfe_name;
unsigned int nr;
 
nr = zoran_num++;
-- 
2.26.2



[PATCH RFT/RFC v2 36/47] staging: media: zoran: Add vb_queue

2020-09-25 Thread Corentin Labbe
This patchs adds a vb_queue without using it.
This reduce the final VB2 conversion patch.

Signed-off-by: Corentin Labbe 
---
 drivers/staging/media/zoran/Kconfig|   1 +
 drivers/staging/media/zoran/zoran.h|  30 +++
 drivers/staging/media/zoran/zoran_card.c   |   7 +
 drivers/staging/media/zoran/zoran_driver.c | 233 +
 4 files changed, 271 insertions(+)

diff --git a/drivers/staging/media/zoran/Kconfig 
b/drivers/staging/media/zoran/Kconfig
index 34a18135ede0..ddf38a931c01 100644
--- a/drivers/staging/media/zoran/Kconfig
+++ b/drivers/staging/media/zoran/Kconfig
@@ -2,6 +2,7 @@ config VIDEO_ZORAN
tristate "Zoran ZR36057/36067 Video For Linux (Deprecated)"
depends on PCI && I2C_ALGOBIT && VIDEO_V4L2 && VIRT_TO_BUS
depends on !ALPHA
+   select VIDEOBUF2_DMA_CONTIG
help
  Say Y for support for MJPEG capture cards based on the Zoran
  36057/36067 PCI controller chipset. This includes the Iomega
diff --git a/drivers/staging/media/zoran/zoran.h 
b/drivers/staging/media/zoran/zoran.h
index 727ba67afd56..294e52d78e1b 100644
--- a/drivers/staging/media/zoran/zoran.h
+++ b/drivers/staging/media/zoran/zoran.h
@@ -21,6 +21,9 @@
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
 
 #define ZR_NORM_PAL 0
 #define ZR_NORM_NTSC 1
@@ -33,6 +36,18 @@ struct zoran_sync {
u64 ts; /* timestamp */
 };
 
+struct zr_buffer {
+   /* common v4l buffer stuff -- must be first */
+   struct vb2_v4l2_buffer  vbuf;
+   struct list_headqueue;
+};
+
+static inline struct zr_buffer *vb2_to_zr_buffer(struct vb2_buffer *vb)
+{
+   struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+
+   return container_of(vbuf, struct zr_buffer, vbuf);
+}
 
 #define ZORAN_NAME"ZORAN"  /* name of the device */
 
@@ -104,6 +119,7 @@ enum zoran_buffer_state {
 };
 
 enum zoran_map_mode {
+   ZORAN_MAP_MODE_NONE,
ZORAN_MAP_MODE_RAW,
ZORAN_MAP_MODE_JPG_REC,
 #define ZORAN_MAP_MODE_JPG ZORAN_MAP_MODE_JPG_REC
@@ -250,6 +266,7 @@ struct zoran {
struct v4l2_device v4l2_dev;
struct v4l2_ctrl_handler hdl;
struct video_device *video_dev;
+   struct vb2_queue vq;
 
struct i2c_adapter i2c_adapter; /* */
struct i2c_algo_bit_data i2c_algo;  /* */
@@ -320,6 +337,7 @@ struct zoran {
unsigned long jpg_err_seq;  /* last seq_num before error */
unsigned long jpg_err_shift;
unsigned long jpg_queued_num;   /* count of frames queued since 
grab/play started */
+   unsigned long vbseq;
 
/* zr36057's code buffer table */
__le32 *stat_com;   /* stat_com[i] is indexed by 
dma_head/tail & BUZ_MASK_STAT_COM */
@@ -350,15 +368,23 @@ struct zoran {
int num_errors;
int JPEG_max_missed;
int JPEG_min_missed;
+   unsigned int prepared;
+   unsigned int queued;
 
u32 last_isr;
unsigned long frame_num;
+   int running;
+   int buf_in_reserve;
 
wait_queue_head_t test_q;
 
dma_addr_t p_sc;
__le32 *stat_comb;
dma_addr_t p_scb;
+   enum zoran_map_mode map_mode;
+   struct list_head queued_bufs;
+   spinlock_t queued_bufs_lock; /* Protects queued_bufs */
+   struct zr_buffer *inuse[BUZ_NUM_STAT_COM * 2];
 };
 
 static inline struct zoran *to_zoran(struct v4l2_device *v4l2_dev)
@@ -376,3 +402,7 @@ static inline struct zoran *to_zoran(struct v4l2_device 
*v4l2_dev)
 #define btaor(dat, mask, adr) btwrite((dat) | ((mask) & btread(adr)), adr)
 
 #endif
+
+int zoran_queue_init(struct zoran *zr, struct vb2_queue *vq);
+void zoran_queue_exit(struct zoran *zr);
+int zr_set_buf(struct zoran *zr);
diff --git a/drivers/staging/media/zoran/zoran_card.c 
b/drivers/staging/media/zoran/zoran_card.c
index 49a1d9e084a8..fed368ba6fd1 100644
--- a/drivers/staging/media/zoran/zoran_card.c
+++ b/drivers/staging/media/zoran/zoran_card.c
@@ -970,6 +970,9 @@ static int zr36057_init(struct zoran *zr)
 * another day.
 */
zr->video_dev->vfl_dir = VFL_DIR_M2M;
+
+   zoran_queue_init(zr, >vq);
+
err = video_register_device(zr->video_dev, VFL_TYPE_VIDEO, 
video_nr[zr->id]);
if (err < 0)
goto exit_statcomb;
@@ -1005,6 +1008,8 @@ static void zoran_remove(struct pci_dev *pdev)
if (!zr->initialized)
goto exit_free;
 
+   zoran_queue_exit(zr);
+
/* unregister videocodec bus */
if (zr->codec)
videocodec_detach(zr->codec);
@@ -1283,6 +1288,8 @@ static int zoran_probe(struct pci_dev *pdev, const struct 
pci_device_id *ent)
if (zr36057_init(zr) < 0)
goto zr_detach_vfe;
 
+   zr->map_mode = ZORAN_MAP_MODE_RAW;
+
return 0;
 
 zr_detach_vfe:
diff --git a/drivers/staging/media/zoran/zoran_driver.c 

[PATCH RFT/RFC v2 40/47] staging: media: zoran: remove framebuffer support

2020-09-25 Thread Corentin Labbe
The framebuffer support is obsolete, so let's reduce code size.

Signed-off-by: Corentin Labbe 
---
 drivers/staging/media/zoran/zoran.h|  4 -
 drivers/staging/media/zoran/zoran_card.c   |  6 --
 drivers/staging/media/zoran/zoran_driver.c | 85 --
 3 files changed, 95 deletions(-)

diff --git a/drivers/staging/media/zoran/zoran.h 
b/drivers/staging/media/zoran/zoran.h
index 294e52d78e1b..0246635e0eac 100644
--- a/drivers/staging/media/zoran/zoran.h
+++ b/drivers/staging/media/zoran/zoran.h
@@ -299,10 +299,6 @@ struct zoran {
 
/* Current buffer params */
unsigned int buffer_size;
-   void *vbuf_base;
-   int vbuf_height, vbuf_width;
-   int vbuf_depth;
-   int vbuf_bytesperline;
 
wait_queue_head_t v4l_capq;
 
diff --git a/drivers/staging/media/zoran/zoran_card.c 
b/drivers/staging/media/zoran/zoran_card.c
index 0a193283eefc..28a403257bb9 100644
--- a/drivers/staging/media/zoran/zoran_card.c
+++ b/drivers/staging/media/zoran/zoran_card.c
@@ -900,12 +900,6 @@ static int zr36057_init(struct zoran *zr)
zr->jpg_buffers.allocated = 0;
zr->v4l_buffers.allocated = 0;
 
-   zr->vbuf_base = (void *)vidmem;
-   zr->vbuf_width = 0;
-   zr->vbuf_height = 0;
-   zr->vbuf_depth = 0;
-   zr->vbuf_bytesperline = 0;
-
/* Avoid nonsense settings from user for default input/norm */
if (default_norm < 0 || default_norm > 2)
default_norm = 0;
diff --git a/drivers/staging/media/zoran/zoran_driver.c 
b/drivers/staging/media/zoran/zoran_driver.c
index 43f7c0c02876..bcbe2c78ea16 100644
--- a/drivers/staging/media/zoran/zoran_driver.c
+++ b/drivers/staging/media/zoran/zoran_driver.c
@@ -881,48 +881,6 @@ static int zoran_close(struct file *file)
return 0;
 }
 
-static int setup_fbuffer(struct zoran_fh *fh, void *base, const struct 
zoran_format *fmt,
-int width, int height, int bytesperline)
-{
-   struct zoran *zr = fh->zr;
-
-   /* (Ronald) v4l/v4l2 guidelines */
-   if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RAWIO))
-   return -EPERM;
-
-   /*
-* Don't allow frame buffer overlay if PCI or AGP is buggy, or on
-  ALi Magik (that needs very low latency while the card needs a
-  higher value always)
-*/
-
-   if (pci_pci_problems & (PCIPCI_FAIL | PCIAGP_FAIL | PCIPCI_ALIMAGIK))
-   return -ENXIO;
-
-   /* we need a bytesperline value, even if not given */
-   if (!bytesperline)
-   bytesperline = width * ((fmt->depth + 7) & ~7) / 8;
-
-   if (height <= 0 || width <= 0 || bytesperline <= 0) {
-   pci_err(zr->pci_dev, "%s - invalid height/width/bpl value 
(%d|%d|%d)\n",
-   __func__, width, height, bytesperline);
-   return -EINVAL;
-   }
-   if (bytesperline & 3) {
-   pci_err(zr->pci_dev, "%s - bytesperline (%d) must be 4-byte 
aligned\n",
-   __func__, bytesperline);
-   return -EINVAL;
-   }
-
-   zr->vbuf_base = (void *)((unsigned long)base & ~3);
-   zr->vbuf_height = height;
-   zr->vbuf_width = width;
-   zr->vbuf_depth = fmt->depth;
-   zr->vbuf_bytesperline = bytesperline;
-
-   return 0;
-}
-
 /* get the status of a buffer in the clients buffer queue */
 static int zoran_v4l2_buffer_status(struct zoran_fh *fh,
struct v4l2_buffer *buf, int num)
@@ -1403,47 +1361,6 @@ static int zoran_s_fmt_vid_cap(struct file *file, void 
*__fh,
return res;
 }
 
-static int zoran_g_fbuf(struct file *file, void *__fh,
-   struct v4l2_framebuffer *fb)
-{
-   struct zoran *zr = video_drvdata(file);
-
-   memset(fb, 0, sizeof(*fb));
-   fb->base = zr->vbuf_base;
-   fb->fmt.width = zr->vbuf_width;
-   fb->fmt.height = zr->vbuf_height;
-   fb->fmt.bytesperline = zr->vbuf_bytesperline;
-   fb->fmt.colorspace = V4L2_COLORSPACE_SRGB;
-   fb->fmt.field = V4L2_FIELD_INTERLACED;
-   fb->capability = V4L2_FBUF_CAP_LIST_CLIPPING;
-
-   return 0;
-}
-
-static int zoran_s_fbuf(struct file *file, void *__fh,
-   const struct v4l2_framebuffer *fb)
-{
-   struct zoran *zr = video_drvdata(file);
-   struct zoran_fh *fh = __fh;
-   int i, res = 0;
-   __le32 printformat = __cpu_to_le32(fb->fmt.pixelformat);
-
-   for (i = 0; i < NUM_FORMATS; i++)
-   if (zoran_formats[i].fourcc == fb->fmt.pixelformat)
-   break;
-   if (i == NUM_FORMATS) {
-   pci_err(zr->pci_dev, "VIDIOC_S_FBUF - format=0x%x (%4.4s) not 
allowed\n",
-   fb->fmt.pixelformat,
-   (char *));
- 

[PATCH RFT/RFC v2 43/47] staging: media: zoran: fix use of buffer_size and sizeimage

2020-09-25 Thread Corentin Labbe
buffer_size was not set when it should be.
Furthermore, use it instead of recalculate it.

Signed-off-by: Corentin Labbe 
---
 drivers/staging/media/zoran/zoran_card.c   | 2 ++
 drivers/staging/media/zoran/zoran_driver.c | 9 ++---
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/media/zoran/zoran_card.c 
b/drivers/staging/media/zoran/zoran_card.c
index 89fbc114c368..d7b3efa9e39f 100644
--- a/drivers/staging/media/zoran/zoran_card.c
+++ b/drivers/staging/media/zoran/zoran_card.c
@@ -857,6 +857,8 @@ void zoran_open_init_params(struct zoran *zr)
if (i)
pci_err(zr->pci_dev, "%s internal error\n", __func__);
 
+   zr->buffer_size = zr->v4l_settings.bytesperline * 
zr->v4l_settings.height;
+
clear_interrupt_counters(zr);
 }
 
diff --git a/drivers/staging/media/zoran/zoran_driver.c 
b/drivers/staging/media/zoran/zoran_driver.c
index 5dacbeac790b..021073ba08e6 100644
--- a/drivers/staging/media/zoran/zoran_driver.c
+++ b/drivers/staging/media/zoran/zoran_driver.c
@@ -407,6 +407,8 @@ static int zoran_v4l_set_format(struct zoran *zr, int 
width, int height,
 
bpp = (format->depth + 7) / 8;
 
+   zr->buffer_size = height * width * bpp;
+
/* Check against available buffer size */
if (height * width * bpp > zr->buffer_size) {
pci_err(zr->pci_dev, "%s - video buffer size (%d kB) is too 
small\n",
@@ -1100,7 +1102,7 @@ static int zoran_g_fmt_vid_out(struct file *file, void 
*__fh,
fmt->fmt.pix.width = zr->jpg_settings.img_width / 
zr->jpg_settings.HorDcm;
fmt->fmt.pix.height = zr->jpg_settings.img_height * 2 /
(zr->jpg_settings.VerDcm * zr->jpg_settings.TmpDcm);
-   fmt->fmt.pix.sizeimage = zoran_v4l2_calc_bufsize(>jpg_settings);
+   fmt->fmt.pix.sizeimage = zr->buffer_size;
fmt->fmt.pix.pixelformat = V4L2_PIX_FMT_MJPEG;
if (zr->jpg_settings.TmpDcm == 1)
fmt->fmt.pix.field = (zr->jpg_settings.odd_even ?
@@ -1125,7 +1127,7 @@ static int zoran_g_fmt_vid_cap(struct file *file, void 
*__fh,
 
fmt->fmt.pix.width = zr->v4l_settings.width;
fmt->fmt.pix.height = zr->v4l_settings.height;
-   fmt->fmt.pix.sizeimage = zr->v4l_settings.bytesperline * 
zr->v4l_settings.height;
+   fmt->fmt.pix.sizeimage = zr->buffer_size;
fmt->fmt.pix.pixelformat = zr->v4l_settings.format->fourcc;
fmt->fmt.pix.colorspace = zr->v4l_settings.format->colorspace;
fmt->fmt.pix.bytesperline = zr->v4l_settings.bytesperline;
@@ -1194,6 +1196,7 @@ static int zoran_try_fmt_vid_out(struct file *file, void 
*__fh,
V4L2_FIELD_TOP : V4L2_FIELD_BOTTOM);
 
fmt->fmt.pix.sizeimage = zoran_v4l2_calc_bufsize();
+   zr->buffer_size = fmt->fmt.pix.sizeimage;
fmt->fmt.pix.bytesperline = 0;
fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
return res;
@@ -1352,7 +1355,7 @@ static int zoran_s_fmt_vid_cap(struct file *file, void 
*__fh,
 
/* tell the user the results/missing stuff */
fmt->fmt.pix.bytesperline = zr->v4l_settings.bytesperline;
-   fmt->fmt.pix.sizeimage = zr->v4l_settings.height * 
zr->v4l_settings.bytesperline;
+   fmt->fmt.pix.sizeimage = zr->buffer_size;
fmt->fmt.pix.colorspace = zr->v4l_settings.format->colorspace;
if (BUZ_MAX_HEIGHT < (zr->v4l_settings.height * 2))
fmt->fmt.pix.field = V4L2_FIELD_INTERLACED;
-- 
2.26.2



[PATCH RFT/RFC v2 28/47] staging: media: zoran: convert mdelay to udelay

2020-09-25 Thread Corentin Labbe
As asked by checkpath, let's use udelay.

Signed-off-by: Corentin Labbe 
---
 drivers/staging/media/zoran/zoran_device.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/media/zoran/zoran_device.c 
b/drivers/staging/media/zoran/zoran_device.c
index 0ecb044f8e8f..4c9f6eafd130 100644
--- a/drivers/staging/media/zoran/zoran_device.c
+++ b/drivers/staging/media/zoran/zoran_device.c
@@ -1332,9 +1332,9 @@ void zoran_init_hardware(struct zoran *zr)
 void zr36057_restart(struct zoran *zr)
 {
btwrite(0, ZR36057_SPGPPCR);
-   mdelay(1);
+   udelay(1000);
btor(ZR36057_SPGPPCR_SoftReset, ZR36057_SPGPPCR);
-   mdelay(1);
+   udelay(1000);
 
/* assert P_Reset */
btwrite(0, ZR36057_JPC);
-- 
2.26.2



[PATCH RFT/RFC v2 26/47] staging: media: zoran: convert irq to pci irq

2020-09-25 Thread Corentin Labbe
This patch convert zoran to pci_irq functions.

Signed-off-by: Corentin Labbe 
---
 drivers/staging/media/zoran/zoran_card.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/media/zoran/zoran_card.c 
b/drivers/staging/media/zoran/zoran_card.c
index 8be7f8f0a020..706b040f5baa 100644
--- a/drivers/staging/media/zoran/zoran_card.c
+++ b/drivers/staging/media/zoran/zoran_card.c
@@ -1015,7 +1015,7 @@ static void zoran_remove(struct pci_dev *pdev)
zoran_set_pci_master(zr, 0);
/* put chip into reset */
btwrite(0, ZR36057_SPGPPCR);
-   free_irq(zr->pci_dev->irq, zr);
+   pci_free_irq(zr->pci_dev, 0, zr);
/* unmap and free memory */
dma_free_coherent(>pci_dev->dev, BUZ_NUM_STAT_COM * sizeof(u32), 
zr->stat_com, zr->p_sc);
iounmap(zr->zr36057_mem);
@@ -1175,8 +1175,7 @@ static int zoran_probe(struct pci_dev *pdev, const struct 
pci_device_id *ent)
goto zr_unreg;
}
 
-   result = request_irq(zr->pci_dev->irq, zoran_irq,
-IRQF_SHARED, ZR_DEVNAME(zr), zr);
+   result = pci_request_irq(pdev, 0, zoran_irq, NULL, zr, ZR_DEVNAME(zr));
if (result < 0) {
if (result == -EINVAL) {
pci_err(pdev, "%s - bad IRQ number or handler\n", 
__func__);
@@ -1292,7 +1291,7 @@ static int zoran_probe(struct pci_dev *pdev, const struct 
pci_device_id *ent)
zoran_unregister_i2c(zr);
 zr_free_irq:
btwrite(0, ZR36057_SPGPPCR);
-   free_irq(zr->pci_dev->irq, zr);
+   pci_free_irq(zr->pci_dev, 0, zr);
 zr_unmap:
iounmap(zr->zr36057_mem);
 zr_unreg:
-- 
2.26.2



[PATCH RFT/RFC v2 33/47] staging: media: zoran: constify struct tvnorm

2020-09-25 Thread Corentin Labbe
The structure tvnorm could be consified.

Signed-off-by: Corentin Labbe 
---
 drivers/staging/media/zoran/videocodec.h   |  2 +-
 drivers/staging/media/zoran/zoran.h|  4 ++--
 drivers/staging/media/zoran/zoran_card.c   | 24 +++---
 drivers/staging/media/zoran/zoran_device.c |  4 ++--
 drivers/staging/media/zoran/zr36016.c  |  4 ++--
 drivers/staging/media/zoran/zr36050.c  |  4 ++--
 drivers/staging/media/zoran/zr36060.c  |  2 +-
 7 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/drivers/staging/media/zoran/videocodec.h 
b/drivers/staging/media/zoran/videocodec.h
index 553af4ad431e..a049f3c2c68a 100644
--- a/drivers/staging/media/zoran/videocodec.h
+++ b/drivers/staging/media/zoran/videocodec.h
@@ -256,7 +256,7 @@ struct videocodec {
// set compression or decompression (or freeze, stop, standby, etc)
int (*set_mode)(struct videocodec *codec, int mode);
// setup picture size and norm (for the codec's video frontend)
-   int (*set_video)(struct videocodec *codec, struct tvnorm *norm,
+   int (*set_video)(struct videocodec *codec, const struct tvnorm *norm,
 struct vfe_settings *cap, struct vfe_polarity *pol);
// other control commands, also mmap setup etc.
int (*control)(struct videocodec *codec, int type, int size, void 
*data);
diff --git a/drivers/staging/media/zoran/zoran.h 
b/drivers/staging/media/zoran/zoran.h
index c73b7e7fd5e1..727ba67afd56 100644
--- a/drivers/staging/media/zoran/zoran.h
+++ b/drivers/staging/media/zoran/zoran.h
@@ -227,7 +227,7 @@ struct card_info {
} input[BUZ_MAX_INPUT];
 
v4l2_std_id norms;
-   struct tvnorm *tvn[3];  /* supported TV norms */
+   const struct tvnorm *tvn[3];/* supported TV norms */
 
u32 jpeg_int;   /* JPEG interrupt */
u32 vsync_int;  /* VSYNC interrupt */
@@ -266,7 +266,7 @@ struct zoran {
u8 initialized; /* flag if zoran has been correctly initialized 
*/
int user;   /* number of current users */
struct card_info card;
-   struct tvnorm *timing;
+   const struct tvnorm *timing;
 
unsigned short id;  /* number of this device */
char name[32];  /* name of this device */
diff --git a/drivers/staging/media/zoran/zoran_card.c 
b/drivers/staging/media/zoran/zoran_card.c
index 756705a34e2b..79783cbb919a 100644
--- a/drivers/staging/media/zoran/zoran_card.c
+++ b/drivers/staging/media/zoran/zoran_card.c
@@ -277,24 +277,24 @@ static char *codecid_to_modulename(u16 codecid)
 //  u16 Wt, Wa, HStart, HSyncStart, Ht, Ha, VStart;
 // };
 
-static struct tvnorm f50sqpixel = { 944, 768, 83, 880, 625, 576, 16 };
-static struct tvnorm f60sqpixel = { 780, 640, 51, 716, 525, 480, 12 };
-static struct tvnorm f50ccir601 = { 864, 720, 75, 804, 625, 576, 18 };
-static struct tvnorm f60ccir601 = { 858, 720, 57, 788, 525, 480, 16 };
+static const struct tvnorm f50sqpixel = { 944, 768, 83, 880, 625, 576, 16 };
+static const struct tvnorm f60sqpixel = { 780, 640, 51, 716, 525, 480, 12 };
+static const struct tvnorm f50ccir601 = { 864, 720, 75, 804, 625, 576, 18 };
+static const struct tvnorm f60ccir601 = { 858, 720, 57, 788, 525, 480, 16 };
 
-static struct tvnorm f50ccir601_lml33 = { 864, 720, 75 + 34, 804, 625, 576, 18 
};
-static struct tvnorm f60ccir601_lml33 = { 858, 720, 57 + 34, 788, 525, 480, 16 
};
+static const struct tvnorm f50ccir601_lml33 = { 864, 720, 75 + 34, 804, 625, 
576, 18 };
+static const struct tvnorm f60ccir601_lml33 = { 858, 720, 57 + 34, 788, 525, 
480, 16 };
 
 /* The DC10 (57/16/50) uses VActive as HSync, so HStart must be 0 */
-static struct tvnorm f50sqpixel_dc10 = { 944, 768, 0, 880, 625, 576, 0 };
-static struct tvnorm f60sqpixel_dc10 = { 780, 640, 0, 716, 525, 480, 12 };
+static const struct tvnorm f50sqpixel_dc10 = { 944, 768, 0, 880, 625, 576, 0 };
+static const struct tvnorm f60sqpixel_dc10 = { 780, 640, 0, 716, 525, 480, 12 
};
 
 /*
  * FIXME: I cannot swap U and V in saa7114, so i do one pixel left shift in 
zoran (75 -> 74)
  * (Maxim Yevtyushkin )
  */
-static struct tvnorm f50ccir601_lm33r10 = { 864, 720, 74 + 54, 804, 625, 576, 
18 };
-static struct tvnorm f60ccir601_lm33r10 = { 858, 720, 56 + 54, 788, 525, 480, 
16 };
+static const struct tvnorm f50ccir601_lm33r10 = { 864, 720, 74 + 54, 804, 625, 
576, 18 };
+static const struct tvnorm f60ccir601_lm33r10 = { 858, 720, 56 + 54, 788, 525, 
480, 16 };
 
 /*
  * FIXME: The ks0127 seem incapable of swapping U and V, too, which is why I 
copy Maxim's left
@@ -303,8 +303,8 @@ static struct tvnorm f60ccir601_lm33r10 = { 858, 720, 56 + 
54, 788, 525, 480, 16
  * Christer's driver used the unshifted norms, though...
  * /Sam
  */
-static struct tvnorm f50ccir601_avs6eyes = { 864, 720, 74, 804, 625, 576, 18 };
-static struct tvnorm f60ccir601_avs6eyes = { 858, 720, 56, 788, 525, 480, 16 };
+static const struct tvnorm f50ccir601_avs6e

[PATCH RFT/RFC v2 30/47] staging: media: zoran: use pci_request_regions

2020-09-25 Thread Corentin Labbe
Use pci_request_regions so now we can see zoran in /proc/iomem.

Signed-off-by: Corentin Labbe 
---
 drivers/staging/media/zoran/zoran_card.c | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/media/zoran/zoran_card.c 
b/drivers/staging/media/zoran/zoran_card.c
index a3e7b0027d69..f4639324bace 100644
--- a/drivers/staging/media/zoran/zoran_card.c
+++ b/drivers/staging/media/zoran/zoran_card.c
@@ -1011,6 +1011,7 @@ static void zoran_remove(struct pci_dev *pdev)
/* unmap and free memory */
dma_free_coherent(>pci_dev->dev, BUZ_NUM_STAT_COM * sizeof(u32), 
zr->stat_com, zr->p_sc);
iounmap(zr->zr36057_mem);
+   pci_release_regions(pdev);
pci_disable_device(zr->pci_dev);
video_unregister_device(zr->video_dev);
 exit_free:
@@ -1160,10 +1161,14 @@ static int zoran_probe(struct pci_dev *pdev, const 
struct pci_device_id *ent)
snprintf(ZR_DEVNAME(zr), sizeof(ZR_DEVNAME(zr)), "%s[%u]",
 zr->card.name, zr->id);
 
+   err = pci_request_regions(pdev, ZR_DEVNAME(zr));
+   if (err)
+   goto zr_unreg;
+
zr->zr36057_mem = pci_ioremap_bar(zr->pci_dev, 0);
if (!zr->zr36057_mem) {
pci_err(pdev, "%s() - ioremap failed\n", __func__);
-   goto zr_unreg;
+   goto zr_pci_release;
}
 
result = pci_request_irq(pdev, 0, zoran_irq, NULL, zr, ZR_DEVNAME(zr));
@@ -1281,6 +1286,8 @@ static int zoran_probe(struct pci_dev *pdev, const struct 
pci_device_id *ent)
pci_free_irq(zr->pci_dev, 0, zr);
 zr_unmap:
iounmap(zr->zr36057_mem);
+zr_pci_release:
+   pci_release_regions(pdev);
 zr_unreg:
v4l2_ctrl_handler_free(>hdl);
v4l2_device_unregister(>v4l2_dev);
-- 
2.26.2



[PATCH RFT/RFC v2 27/47] staging: media: zoran: convert zoran alloc to devm

2020-09-25 Thread Corentin Labbe
Allocate the zoran structure with devm_ functions permit to simplify
code.

Signed-off-by: Corentin Labbe 
---
 drivers/staging/media/zoran/zoran_card.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/staging/media/zoran/zoran_card.c 
b/drivers/staging/media/zoran/zoran_card.c
index 706b040f5baa..fe0c5a7c967c 100644
--- a/drivers/staging/media/zoran/zoran_card.c
+++ b/drivers/staging/media/zoran/zoran_card.c
@@ -1024,7 +1024,6 @@ static void zoran_remove(struct pci_dev *pdev)
 exit_free:
v4l2_ctrl_handler_free(>hdl);
v4l2_device_unregister(>v4l2_dev);
-   kfree(zr);
 }
 
 void zoran_vdev_release(struct video_device *vdev)
@@ -1109,7 +1108,7 @@ static int zoran_probe(struct pci_dev *pdev, const struct 
pci_device_id *ent)
return -ENOENT;
}
 
-   zr = kzalloc(sizeof(*zr), GFP_KERNEL);
+   zr = devm_kzalloc(>dev, sizeof(*zr), GFP_KERNEL);
if (!zr)
return -ENOMEM;
 
@@ -1298,7 +1297,6 @@ static int zoran_probe(struct pci_dev *pdev, const struct 
pci_device_id *ent)
v4l2_ctrl_handler_free(>hdl);
v4l2_device_unregister(>v4l2_dev);
 zr_free_mem:
-   kfree(zr);
 
return -ENODEV;
 }
-- 
2.26.2



[PATCH RFT/RFC v2 31/47] staging: media: zoran: use devm_ioremap

2020-09-25 Thread Corentin Labbe
Using devm_ioremap simplify code.

Signed-off-by: Corentin Labbe 
---
 drivers/staging/media/zoran/zoran_card.c | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/media/zoran/zoran_card.c 
b/drivers/staging/media/zoran/zoran_card.c
index f4639324bace..147bef1df33c 100644
--- a/drivers/staging/media/zoran/zoran_card.c
+++ b/drivers/staging/media/zoran/zoran_card.c
@@ -1010,7 +1010,6 @@ static void zoran_remove(struct pci_dev *pdev)
pci_free_irq(zr->pci_dev, 0, zr);
/* unmap and free memory */
dma_free_coherent(>pci_dev->dev, BUZ_NUM_STAT_COM * sizeof(u32), 
zr->stat_com, zr->p_sc);
-   iounmap(zr->zr36057_mem);
pci_release_regions(pdev);
pci_disable_device(zr->pci_dev);
video_unregister_device(zr->video_dev);
@@ -1165,7 +1164,7 @@ static int zoran_probe(struct pci_dev *pdev, const struct 
pci_device_id *ent)
if (err)
goto zr_unreg;
 
-   zr->zr36057_mem = pci_ioremap_bar(zr->pci_dev, 0);
+   zr->zr36057_mem = devm_ioremap(>dev, pci_resource_start(pdev, 0), 
pci_resource_len(pdev, 0));
if (!zr->zr36057_mem) {
pci_err(pdev, "%s() - ioremap failed\n", __func__);
goto zr_pci_release;
@@ -1181,7 +1180,7 @@ static int zoran_probe(struct pci_dev *pdev, const struct 
pci_device_id *ent)
} else {
pci_err(pdev, "%s - cannot assign IRQ, error code 
%d\n", __func__, result);
}
-   goto zr_unmap;
+   goto zr_pci_release;
}
 
/* set PCI latency timer */
@@ -1284,8 +1283,6 @@ static int zoran_probe(struct pci_dev *pdev, const struct 
pci_device_id *ent)
 zr_free_irq:
btwrite(0, ZR36057_SPGPPCR);
pci_free_irq(zr->pci_dev, 0, zr);
-zr_unmap:
-   iounmap(zr->zr36057_mem);
 zr_pci_release:
pci_release_regions(pdev);
 zr_unreg:
-- 
2.26.2



[PATCH RFT/RFC v2 29/47] staging: media: zoran: use devm for videocodec_master alloc

2020-09-25 Thread Corentin Labbe
Let's use devm allocations for videocodec, this simplify code.

Signed-off-by: Corentin Labbe 
---
 drivers/staging/media/zoran/zoran_card.c | 22 +-
 1 file changed, 5 insertions(+), 17 deletions(-)

diff --git a/drivers/staging/media/zoran/zoran_card.c 
b/drivers/staging/media/zoran/zoran_card.c
index fe0c5a7c967c..a3e7b0027d69 100644
--- a/drivers/staging/media/zoran/zoran_card.c
+++ b/drivers/staging/media/zoran/zoran_card.c
@@ -996,18 +996,10 @@ static void zoran_remove(struct pci_dev *pdev)
goto exit_free;
 
/* unregister videocodec bus */
-   if (zr->codec) {
-   struct videocodec_master *master = zr->codec->master_data;
-
+   if (zr->codec)
videocodec_detach(zr->codec);
-   kfree(master);
-   }
-   if (zr->vfe) {
-   struct videocodec_master *master = zr->vfe->master_data;
-
+   if (zr->vfe)
videocodec_detach(zr->vfe);
-   kfree(master);
-   }
 
/* unregister i2c bus */
zoran_unregister_i2c(zr);
@@ -1036,7 +1028,7 @@ static struct videocodec_master 
*zoran_setup_videocodec(struct zoran *zr,
 {
struct videocodec_master *m = NULL;
 
-   m = kmalloc(sizeof(*m), GFP_KERNEL);
+   m = devm_kmalloc(>pci_dev->dev, sizeof(*m), GFP_KERNEL);
if (!m)
return m;
 
@@ -1245,7 +1237,7 @@ static int zoran_probe(struct pci_dev *pdev, const struct 
pci_device_id *ent)
zr->codec = videocodec_attach(master_codec);
if (!zr->codec) {
pci_err(pdev, "%s - no codec found\n", __func__);
-   goto zr_free_codec;
+   goto zr_unreg_i2c;
}
if (zr->codec->type != zr->card.video_codec) {
pci_err(pdev, "%s - wrong codec\n", __func__);
@@ -1259,7 +1251,7 @@ static int zoran_probe(struct pci_dev *pdev, const struct 
pci_device_id *ent)
zr->vfe = videocodec_attach(master_vfe);
if (!zr->vfe) {
pci_err(pdev, "%s - no VFE found\n", __func__);
-   goto zr_free_vfe;
+   goto zr_detach_codec;
}
if (zr->vfe->type != zr->card.video_vfe) {
pci_err(pdev, "%s = wrong VFE\n", __func__);
@@ -1280,12 +1272,8 @@ static int zoran_probe(struct pci_dev *pdev, const 
struct pci_device_id *ent)
 
 zr_detach_vfe:
videocodec_detach(zr->vfe);
-zr_free_vfe:
-   kfree(master_vfe);
 zr_detach_codec:
videocodec_detach(zr->codec);
-zr_free_codec:
-   kfree(master_codec);
 zr_unreg_i2c:
zoran_unregister_i2c(zr);
 zr_free_irq:
-- 
2.26.2



[PATCH RFT/RFC v2 32/47] staging: media: zoran: add stat_com buffer

2020-09-25 Thread Corentin Labbe
This patch adds the allocation of the stat_com buffer which be used
later.

Signed-off-by: Corentin Labbe 
---
 drivers/staging/media/zoran/zoran.h  |  2 ++
 drivers/staging/media/zoran/zoran_card.c | 13 -
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/media/zoran/zoran.h 
b/drivers/staging/media/zoran/zoran.h
index 87ca324f6ec2..c73b7e7fd5e1 100644
--- a/drivers/staging/media/zoran/zoran.h
+++ b/drivers/staging/media/zoran/zoran.h
@@ -357,6 +357,8 @@ struct zoran {
wait_queue_head_t test_q;
 
dma_addr_t p_sc;
+   __le32 *stat_comb;
+   dma_addr_t p_scb;
 };
 
 static inline struct zoran *to_zoran(struct v4l2_device *v4l2_dev)
diff --git a/drivers/staging/media/zoran/zoran_card.c 
b/drivers/staging/media/zoran/zoran_card.c
index 147bef1df33c..756705a34e2b 100644
--- a/drivers/staging/media/zoran/zoran_card.c
+++ b/drivers/staging/media/zoran/zoran_card.c
@@ -951,6 +951,14 @@ static int zr36057_init(struct zoran *zr)
for (j = 0; j < BUZ_NUM_STAT_COM; j++)
zr->stat_com[j] = cpu_to_le32(1); /* mark as unavailable to 
zr36057 */
 
+   zr->stat_comb = dma_alloc_coherent(>pci_dev->dev,
+  BUZ_NUM_STAT_COM * sizeof(u32) * 2,
+  >p_scb, GFP_KERNEL);
+   if (!zr->stat_comb) {
+   err = -ENOMEM;
+   goto exit_statcom;
+   }
+
/* Now add the template and register the device unit. */
*zr->video_dev = zoran_template;
zr->video_dev->v4l2_dev = >v4l2_dev;
@@ -964,7 +972,7 @@ static int zr36057_init(struct zoran *zr)
zr->video_dev->vfl_dir = VFL_DIR_M2M;
err = video_register_device(zr->video_dev, VFL_TYPE_VIDEO, 
video_nr[zr->id]);
if (err < 0)
-   goto exit_statcom;
+   goto exit_statcomb;
video_set_drvdata(zr->video_dev, zr);
 
zoran_init_hardware(zr);
@@ -979,6 +987,8 @@ static int zr36057_init(struct zoran *zr)
zr->initialized = 1;
return 0;
 
+exit_statcomb:
+   dma_free_coherent(>pci_dev->dev, BUZ_NUM_STAT_COM * sizeof(u32) * 
2, zr->stat_comb, zr->p_scb);
 exit_statcom:
dma_free_coherent(>pci_dev->dev, BUZ_NUM_STAT_COM * sizeof(u32), 
zr->stat_com, zr->p_sc);
 exit_video:
@@ -1010,6 +1020,7 @@ static void zoran_remove(struct pci_dev *pdev)
pci_free_irq(zr->pci_dev, 0, zr);
/* unmap and free memory */
dma_free_coherent(>pci_dev->dev, BUZ_NUM_STAT_COM * sizeof(u32), 
zr->stat_com, zr->p_sc);
+   dma_free_coherent(>pci_dev->dev, BUZ_NUM_STAT_COM * sizeof(u32) * 
2, zr->stat_comb, zr->p_scb);
pci_release_regions(pdev);
pci_disable_device(zr->pci_dev);
video_unregister_device(zr->video_dev);
-- 
2.26.2



[PATCH RFT/RFC v2 24/47] staging: media: zoran: use ZR_NORM

2020-09-25 Thread Corentin Labbe
Instead of using hardcoded numbers, let's use some define for ZR NORM.

Signed-off-by: Corentin Labbe 
---
 drivers/staging/media/zoran/zoran.h| 4 
 drivers/staging/media/zoran/zoran_card.c   | 8 
 drivers/staging/media/zoran/zoran_driver.c | 6 +++---
 3 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/media/zoran/zoran.h 
b/drivers/staging/media/zoran/zoran.h
index 8f3faa4eb60f..87ca324f6ec2 100644
--- a/drivers/staging/media/zoran/zoran.h
+++ b/drivers/staging/media/zoran/zoran.h
@@ -22,6 +22,10 @@
 #include 
 #include 
 
+#define ZR_NORM_PAL 0
+#define ZR_NORM_NTSC 1
+#define ZR_NORM_SECAM 2
+
 struct zoran_sync {
unsigned long frame;/* number of buffer that has been free'd */
unsigned long length;   /* number of code bytes in buffer (capture 
only) */
diff --git a/drivers/staging/media/zoran/zoran_card.c 
b/drivers/staging/media/zoran/zoran_card.c
index 9fe2bc2b036a..8be7f8f0a020 100644
--- a/drivers/staging/media/zoran/zoran_card.c
+++ b/drivers/staging/media/zoran/zoran_card.c
@@ -911,18 +911,18 @@ static int zr36057_init(struct zoran *zr)
default_norm = 0;
if (default_norm == 0) {
zr->norm = V4L2_STD_PAL;
-   zr->timing = zr->card.tvn[0];
+   zr->timing = zr->card.tvn[ZR_NORM_PAL];
} else if (default_norm == 1) {
zr->norm = V4L2_STD_NTSC;
-   zr->timing = zr->card.tvn[1];
+   zr->timing = zr->card.tvn[ZR_NORM_NTSC];
} else {
zr->norm = V4L2_STD_SECAM;
-   zr->timing = zr->card.tvn[2];
+   zr->timing = zr->card.tvn[ZR_NORM_SECAM];
}
if (!zr->timing) {
pci_warn(zr->pci_dev, "%s - default TV standard not supported 
by hardware. PAL will be used.\n", __func__);
zr->norm = V4L2_STD_PAL;
-   zr->timing = zr->card.tvn[0];
+   zr->timing = zr->card.tvn[ZR_NORM_PAL];
}
 
if (default_input > zr->card.inputs - 1) {
diff --git a/drivers/staging/media/zoran/zoran_driver.c 
b/drivers/staging/media/zoran/zoran_driver.c
index b910ad136b84..858e0910884c 100644
--- a/drivers/staging/media/zoran/zoran_driver.c
+++ b/drivers/staging/media/zoran/zoran_driver.c
@@ -1033,11 +1033,11 @@ static int zoran_set_norm(struct zoran *zr, v4l2_std_id 
norm)
}
 
if (norm & V4L2_STD_SECAM)
-   zr->timing = zr->card.tvn[2];
+   zr->timing = zr->card.tvn[ZR_NORM_SECAM];
else if (norm & V4L2_STD_NTSC)
-   zr->timing = zr->card.tvn[1];
+   zr->timing = zr->card.tvn[ZR_NORM_NTSC];
else
-   zr->timing = zr->card.tvn[0];
+   zr->timing = zr->card.tvn[ZR_NORM_PAL];
 
decoder_call(zr, video, s_std, norm);
encoder_call(zr, video, s_std_output, norm);
-- 
2.26.2



[PATCH RFT/RFC v2 25/47] staging: media: zoran: zoran does not support STD_ALL

2020-09-25 Thread Corentin Labbe
In fact, zoran does not support V4L2_STD_ALL, so let's enumerate what we
support.

Signed-off-by: Corentin Labbe 
---
 drivers/staging/media/zoran/zoran_driver.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/media/zoran/zoran_driver.c 
b/drivers/staging/media/zoran/zoran_driver.c
index 858e0910884c..60bbc8235cff 100644
--- a/drivers/staging/media/zoran/zoran_driver.c
+++ b/drivers/staging/media/zoran/zoran_driver.c
@@ -1765,7 +1765,7 @@ static int zoran_enum_input(struct file *file, void *__fh,
 
strscpy(inp->name, zr->card.input[inp->index].name, sizeof(inp->name));
inp->type = V4L2_INPUT_TYPE_CAMERA;
-   inp->std = V4L2_STD_ALL;
+   inp->std = V4L2_STD_NTSC | V4L2_STD_PAL | V4L2_STD_SECAM;
 
/* Get status of video decoder */
decoder_call(zr, video, g_input_status, >status);
-- 
2.26.2



[PATCH RFT/RFC v2 18/47] staging: media: zoran: move jpg_settings out of zoran_fh

2020-09-25 Thread Corentin Labbe
We need to get rid of zoran_fh, so move the jpg_settings directly in the
zoran structure.
Signed-off-by: Corentin Labbe 
---
 drivers/staging/media/zoran/zoran.h|   2 -
 drivers/staging/media/zoran/zoran_driver.c | 103 ++---
 2 files changed, 47 insertions(+), 58 deletions(-)

diff --git a/drivers/staging/media/zoran/zoran.h 
b/drivers/staging/media/zoran/zoran.h
index a529b49888c6..7e6e03563a2a 100644
--- a/drivers/staging/media/zoran/zoran.h
+++ b/drivers/staging/media/zoran/zoran.h
@@ -216,8 +216,6 @@ struct zoran_fh {
enum zoran_lock_activity overlay_active;/* feature currently in use? */
 
struct zoran_buffer_col buffers;/* buffers' info */
-
-   struct zoran_jpg_settings jpg_settings; /* structure with a lot of 
things to play with */
 };
 
 struct card_info {
diff --git a/drivers/staging/media/zoran/zoran_driver.c 
b/drivers/staging/media/zoran/zoran_driver.c
index e60db53c0359..27dcf899b723 100644
--- a/drivers/staging/media/zoran/zoran_driver.c
+++ b/drivers/staging/media/zoran/zoran_driver.c
@@ -587,9 +587,7 @@ static int zoran_jpg_queue_frame(struct zoran_fh *fh, int 
num,
}
 
/* what is the codec mode right now? */
-   if (zr->codec_mode == BUZ_MODE_IDLE) {
-   zr->jpg_settings = fh->jpg_settings;
-   } else if (zr->codec_mode != mode) {
+   if (zr->codec_mode != BUZ_MODE_IDLE && zr->codec_mode != mode) {
/* wrong codec mode active - invalid */
pci_err(zr->pci_dev, "%s - codec in wrong mode\n", __func__);
return -EINVAL;
@@ -751,9 +749,6 @@ static void zoran_open_init_session(struct zoran_fh *fh)
fh->overlay_settings.format = zr->overlay_settings.format;
fh->overlay_active = ZORAN_FREE;
 
-   /* jpg settings */
-   fh->jpg_settings = zr->jpg_settings;
-
/* buffers */
memset(>buffers, 0, sizeof(fh->buffers));
for (i = 0; i < MAX_FRAME; i++) {
@@ -1237,11 +1232,11 @@ static int zoran_v4l2_buffer_status(struct zoran_fh *fh,
}
 
/* which fields are these? */
-   if (fh->jpg_settings.TmpDcm != 1)
-   buf->field = fh->jpg_settings.odd_even ?
+   if (zr->jpg_settings.TmpDcm != 1)
+   buf->field = zr->jpg_settings.odd_even ?
V4L2_FIELD_TOP : V4L2_FIELD_BOTTOM;
else
-   buf->field = fh->jpg_settings.odd_even ?
+   buf->field = zr->jpg_settings.odd_even ?
V4L2_FIELD_SEQ_TB : V4L2_FIELD_SEQ_BT;
 
break;
@@ -1391,18 +1386,18 @@ static int zoran_enum_fmt_vid_overlay(struct file 
*file, void *__fh,
 static int zoran_g_fmt_vid_out(struct file *file, void *__fh,
   struct v4l2_format *fmt)
 {
-   struct zoran_fh *fh = __fh;
+   struct zoran *zr = video_drvdata(file);
 
-   fmt->fmt.pix.width = fh->jpg_settings.img_width / 
fh->jpg_settings.HorDcm;
-   fmt->fmt.pix.height = fh->jpg_settings.img_height * 2 /
-   (fh->jpg_settings.VerDcm * fh->jpg_settings.TmpDcm);
-   fmt->fmt.pix.sizeimage = zoran_v4l2_calc_bufsize(>jpg_settings);
+   fmt->fmt.pix.width = zr->jpg_settings.img_width / 
zr->jpg_settings.HorDcm;
+   fmt->fmt.pix.height = zr->jpg_settings.img_height * 2 /
+   (zr->jpg_settings.VerDcm * zr->jpg_settings.TmpDcm);
+   fmt->fmt.pix.sizeimage = zoran_v4l2_calc_bufsize(>jpg_settings);
fmt->fmt.pix.pixelformat = V4L2_PIX_FMT_MJPEG;
-   if (fh->jpg_settings.TmpDcm == 1)
-   fmt->fmt.pix.field = (fh->jpg_settings.odd_even ?
+   if (zr->jpg_settings.TmpDcm == 1)
+   fmt->fmt.pix.field = (zr->jpg_settings.odd_even ?
V4L2_FIELD_SEQ_TB : V4L2_FIELD_SEQ_BT);
else
-   fmt->fmt.pix.field = (fh->jpg_settings.odd_even ?
+   fmt->fmt.pix.field = (zr->jpg_settings.odd_even ?
V4L2_FIELD_TOP : V4L2_FIELD_BOTTOM);
fmt->fmt.pix.bytesperline = 0;
fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
@@ -1471,15 +1466,14 @@ static int zoran_try_fmt_vid_overlay(struct file *file, 
void *__fh,
 static int zoran_try_fmt_vid_out(struct file *file, void *__fh,
 struct v4l2_format *fmt)
 {
-   struct zoran_fh *fh = __fh;
-   struct zoran *zr = fh->zr;
+   struct zoran *zr = video_drvdata(file);
struct zoran_jpg_settings settings;
int res = 0;
 
if (fmt->fmt.pix.pixelformat != V4L2_PIX_FMT_MJPEG)
return -EINVAL;
 
-   settings = fh->jpg_settings;
+   settings = zr->jpg_settings;
 
/* we actua

  1   2   3   4   5   6   7   8   9   10   >