mbox series

[00/11] Add support for RaspberryPi RP1 PCI device using a DT overlay

Message ID cover.1724159867.git.andrea.porta@suse.com (mailing list archive)
Headers show
Series Add support for RaspberryPi RP1 PCI device using a DT overlay | expand

Message

Andrea della Porta Aug. 20, 2024, 2:36 p.m. UTC
RP1 is an MFD chipset that acts as a south-bridge PCIe endpoint sporting
a pletora of subdevices (i.e.  Ethernet, USB host controller, I2C, PWM, 
etc.) whose registers are all reachable starting from an offset from the
BAR address.  The main point here is that while the RP1 as an endpoint
itself is discoverable via usual PCI enumeraiton, the devices it contains
are not discoverable and must be declared e.g. via the devicetree.

This patchset is an attempt to provide a minimum infrastructure to allow
the RP1 chipset to be discovered and perpherals it contains to be added
from a devictree overlay loaded during RP1 PCI endpoint enumeration.
Followup patches should add support for the several peripherals contained
in RP1.

This work is based upon dowstream drivers code and the proposal from RH
et al. (see [1] and [2]). A similar approach is also pursued in [3].

The patches are ordered as follows:

-PATCHES 1 and 2: add binding schemas for clock and gpio peripherals 
 found in RP1. They are needed to support the other peripherals, e.g.
 the ethernet mac depends on a clock generated by RP1 and the phy is
 reset though the on-board gpio controller.

-PATCHES 3, 4 and 5: preparatory patches that fix the address mapping
 translation (especially wrt dma-ranges) and permit to place the dtbo
 binary blob to be put in non transient section.

-PATCH 6 and 7: add clock and gpio device drivers.

-PATCH 8: this is the main patch to support RP1 chipset and peripherals
 enabling through dtb overlay. It contains the dtso since its intimately
 coupled with the driver and will be linked in as binary blob in the driver
 obj, but of course it can be easily split in a separate patch if the
 maintainer feels it so. The real dtso is in devicetree folder while
 the dtso in driver folder is just a placeholder to include the real dtso.
 In this way it is possible to check the dtso against dt-bindings.

-PATCH 9: add the relevant kernel CONFIG_ options to defconfig.

-PATCHES 10 and 11: these (still unpolished) patches are not intended to
 be upstreamed (yet), they serve just as a test reference to be able to
 use the ethernet MAC contained in RP1.

This patchset is also a first attempt to be more agnostic wrt hardware
description standards such as OF devicetree and ACPI, where 'agnostic'
means "using DT in coexistence with ACPI", as been alredy promoted
by e.g. AL (see [4]). Although there's currently no evidence it will also
run out of the box on purely ACPI system, it is a first step towards
that direction.

Please note that albeit this patchset has no prerequisites in order to
be applied cleanly, it still depends on Stanimir's WIP patchset for BCM2712
PCIe controller (see [5]) in order to work at runtime.

Many thanks,
Andrea della Porta

Link:
- [1]: https://lpc.events/event/17/contributions/1421/attachments/1337/2680/LPC2023%20Non-discoverable%20devices%20in%20PCI.pdf
- [2]: https://lore.kernel.org/lkml/20230419231155.GA899497-robh@kernel.org/t/
- [3]: https://lore.kernel.org/all/20240808154658.247873-1-herve.codina@bootlin.com/#t
- [4]: https://lore.kernel.org/all/73e05c77-6d53-4aae-95ac-415456ff0ae4@lunn.ch/
- [5]: https://lore.kernel.org/all/20240626104544.14233-1-svarbanov@suse.de/

Andrea della Porta (11):
  dt-bindings: clock: Add RaspberryPi RP1 clock bindings
  dt-bindings: pinctrl: Add RaspberryPi RP1 gpio/pinctrl/pinmux bindings
  PCI: of_property: Sanitize 32 bit PCI address parsed from DT
  of: address: Preserve the flags portion on 1:1 dma-ranges mapping
  vmlinux.lds.h: Preserve DTB sections from being discarded after init
  clk: rp1: Add support for clocks provided by RP1
  pinctrl: rp1: Implement RaspberryPi RP1 gpio support
  misc: rp1: RaspberryPi RP1 misc driver
  arm64: defconfig: Enable RP1 misc/clock/gpio drivers as built-in
  net: macb: Add support for RP1's MACB variant
  arm64: dts: rp1: Add support for MACB contained in RP1

 .../clock/raspberrypi,rp1-clocks.yaml         |   87 +
 .../pinctrl/raspberrypi,rp1-gpio.yaml         |  177 ++
 MAINTAINERS                                   |   12 +
 arch/arm64/boot/dts/broadcom/rp1.dtso         |  175 ++
 arch/arm64/configs/defconfig                  |    3 +
 drivers/clk/Kconfig                           |    9 +
 drivers/clk/Makefile                          |    1 +
 drivers/clk/clk-rp1.c                         | 1655 +++++++++++++++++
 drivers/misc/Kconfig                          |    1 +
 drivers/misc/Makefile                         |    1 +
 drivers/misc/rp1/Kconfig                      |   20 +
 drivers/misc/rp1/Makefile                     |    3 +
 drivers/misc/rp1/rp1-pci.c                    |  333 ++++
 drivers/misc/rp1/rp1-pci.dtso                 |    8 +
 drivers/net/ethernet/cadence/macb.h           |   25 +
 drivers/net/ethernet/cadence/macb_main.c      |  152 +-
 drivers/of/address.c                          |    3 +-
 drivers/pci/of_property.c                     |    5 +-
 drivers/pci/quirks.c                          |    1 +
 drivers/pinctrl/Kconfig                       |   10 +
 drivers/pinctrl/Makefile                      |    1 +
 drivers/pinctrl/pinctrl-rp1.c                 |  719 +++++++
 include/asm-generic/vmlinux.lds.h             |    2 +-
 include/dt-bindings/clock/rp1.h               |   56 +
 include/dt-bindings/misc/rp1.h                |  235 +++
 include/linux/pci_ids.h                       |    3 +
 26 files changed, 3692 insertions(+), 5 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/clock/raspberrypi,rp1-clocks.yaml
 create mode 100644 Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.yaml
 create mode 100644 arch/arm64/boot/dts/broadcom/rp1.dtso
 create mode 100644 drivers/clk/clk-rp1.c
 create mode 100644 drivers/misc/rp1/Kconfig
 create mode 100644 drivers/misc/rp1/Makefile
 create mode 100644 drivers/misc/rp1/rp1-pci.c
 create mode 100644 drivers/misc/rp1/rp1-pci.dtso
 create mode 100644 drivers/pinctrl/pinctrl-rp1.c
 create mode 100644 include/dt-bindings/clock/rp1.h
 create mode 100644 include/dt-bindings/misc/rp1.h

Comments

Krzysztof Kozlowski Aug. 21, 2024, 1:42 p.m. UTC | #1
On 20/08/2024 16:36, Andrea della Porta wrote:
> RP1 is an MFD chipset that acts as a south-bridge PCIe endpoint sporting
> a pletora of subdevices (i.e.  Ethernet, USB host controller, I2C, PWM, 
> etc.) whose registers are all reachable starting from an offset from the
> BAR address.  The main point here is that while the RP1 as an endpoint
> itself is discoverable via usual PCI enumeraiton, the devices it contains
> are not discoverable and must be declared e.g. via the devicetree.
> 
> This patchset is an attempt to provide a minimum infrastructure to allow
> the RP1 chipset to be discovered and perpherals it contains to be added
> from a devictree overlay loaded during RP1 PCI endpoint enumeration.
> Followup patches should add support for the several peripherals contained
> in RP1.
> 
> This work is based upon dowstream drivers code and the proposal from RH
> et al. (see [1] and [2]). A similar approach is also pursued in [3].

Looking briefly at findings it seems this was not really tested by
automation and you expect reviewers to find issues which are pointed out
by tools. That's not nice approach. Reviewer's time is limited, while
tools do it for free. And the tools are free - you can use them without
any effort.

It does not look like you tested the DTS against bindings. Please run
`make dtbs_check W=1` (see
Documentation/devicetree/bindings/writing-schema.rst or
https://www.linaro.org/blog/tips-and-tricks-for-validating-devicetree-sources-with-the-devicetree-schema/
for instructions).

Please run standard kernel tools for static analysis, like coccinelle,
smatch and sparse, and fix reported warnings. Also please check for
warnings when building with W=1. Most of these commands (checks or W=1
build) can build specific targets, like some directory, to narrow the
scope to only your code. The code here looks like it needs a fix. Feel
free to get in touch if the warning is not clear.

Please run scripts/checkpatch.pl and fix reported warnings. Then please
run `scripts/checkpatch.pl --strict` and (probably) fix more warnings.
Some warnings can be ignored, especially from --strict run, but the code
here looks like it needs a fix. Feel free to get in touch if the warning
is not clear.


Best regards,
Krzysztof
Andrea della Porta Aug. 22, 2024, 9:05 a.m. UTC | #2
Hi Krzysztof,

On 15:42 Wed 21 Aug     , Krzysztof Kozlowski wrote:
> On 20/08/2024 16:36, Andrea della Porta wrote:
> > RP1 is an MFD chipset that acts as a south-bridge PCIe endpoint sporting
> > a pletora of subdevices (i.e.  Ethernet, USB host controller, I2C, PWM, 
> > etc.) whose registers are all reachable starting from an offset from the
> > BAR address.  The main point here is that while the RP1 as an endpoint
> > itself is discoverable via usual PCI enumeraiton, the devices it contains
> > are not discoverable and must be declared e.g. via the devicetree.
> > 
> > This patchset is an attempt to provide a minimum infrastructure to allow
> > the RP1 chipset to be discovered and perpherals it contains to be added
> > from a devictree overlay loaded during RP1 PCI endpoint enumeration.
> > Followup patches should add support for the several peripherals contained
> > in RP1.
> > 
> > This work is based upon dowstream drivers code and the proposal from RH
> > et al. (see [1] and [2]). A similar approach is also pursued in [3].
> 
> Looking briefly at findings it seems this was not really tested by
> automation and you expect reviewers to find issues which are pointed out
> by tools. That's not nice approach. Reviewer's time is limited, while
> tools do it for free. And the tools are free - you can use them without
> any effort.

Sorry if I gave you that impression, but this is not obviously the case.
I've spent quite a bit of time in trying to deliver a patchset that ease
your and others work, at least to the best I can. In fact, I've used many
of the checking facilities you mentioned before sending it, solving all
of the reported issues, except the ones for which there are strong reasons
to leave untouched, as explained below.

> 
> It does not look like you tested the DTS against bindings. Please run
> `make dtbs_check W=1` (see
> Documentation/devicetree/bindings/writing-schema.rst or
> https://www.linaro.org/blog/tips-and-tricks-for-validating-devicetree-sources-with-the-devicetree-schema/
> for instructions).

#> make W=1 dt_binding_check DT_SCHEMA_FILES=raspberrypi,rp1-gpio.yaml
   CHKDT   Documentation/devicetree/bindings
   LINT    Documentation/devicetree/bindings
   DTEX    Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.example.dts
   DTC_CHK Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.example.dtb

#> make W=1 dt_binding_check DT_SCHEMA_FILES=raspberrypi,rp1-clocks.yaml
   CHKDT   Documentation/devicetree/bindings
   LINT    Documentation/devicetree/bindings
   DTEX    Documentation/devicetree/bindings/clock/raspberrypi,rp1-clocks.example.dts
   DTC_CHK Documentation/devicetree/bindings/clock/raspberrypi,rp1-clocks.example.dtb

I see no issues here, in case you've found something different, I kindly ask you to post
the results.

#> make W=1 CHECK_DTBS=y broadcom/rp1.dtbo
   DTC     arch/arm64/boot/dts/broadcom/rp1.dtbo
   arch/arm64/boot/dts/broadcom/rp1.dtso:37.24-42.7: Warning (simple_bus_reg): /fragment@0/__overlay__/rp1@0/clk_xosc: missing or empty reg/ranges property
   arch/arm64/boot/dts/broadcom/rp1.dtso:44.26-49.7: Warning (simple_bus_reg): /fragment@0/__overlay__/rp1@0/macb_pclk: missing or empty reg/ranges property
   arch/arm64/boot/dts/broadcom/rp1.dtso:51.26-56.7: Warning (simple_bus_reg): /fragment@0/__overlay__/rp1@0/macb_hclk: missing or empty reg/ranges property
   arch/arm64/boot/dts/broadcom/rp1.dtso:14.15-173.5: Warning (avoid_unnecessary_addr_size): /fragment@0/__overlay__: unnecessary #address-cells/#size-cells without "ranges", "dma-ranges" or child "reg" property 

I believe that These warnings are unavoidable, and stem from the fact that this
is quite a peculiar setup (PCI endpoint which dynamically loads platform driver
addressable via BAR).
The missing reg/ranges in the threee clocks are due to the simple-bus of the
containing node to which I believe they should belong: I did a test to place
those clocks in the same dtso under root or /clocks node but AFAIK it doesn't
seems to work. I could move them in a separate dtso to be loaded before the main
one but this is IMHO even more cumbersome than having a couple of warnings in
CHECK_DTBS.
Of course, if you have any suggestion on how to improve it I would be glad to
discuss.
About the last warning about the address/size-cells, if I drop those two lines
in the _overlay_ node it generates even more warning, so again it's a "don't fix"
one.

> 
> Please run standard kernel tools for static analysis, like coccinelle,
> smatch and sparse, and fix reported warnings. Also please check for
> warnings when building with W=1. Most of these commands (checks or W=1
> build) can build specific targets, like some directory, to narrow the
> scope to only your code. The code here looks like it needs a fix. Feel
> free to get in touch if the warning is not clear.

I didn't run those static analyzers since I've preferred a more "manual" aproach
by carfeully checking the code, but I agree that something can escape even the
more carefully executed code inspection so I will add them to my arsenal from
now on. Thanks for the heads up.

> 
> Please run scripts/checkpatch.pl and fix reported warnings. Then please
> run `scripts/checkpatch.pl --strict` and (probably) fix more warnings.
> Some warnings can be ignored, especially from --strict run, but the code
> here looks like it needs a fix. Feel free to get in touch if the warning
> is not clear.
>

Again, most of checkpatch's complaints have been addressed, the remaining
ones I deemed as not worth fixing, for example:

#> scripts/checkpatch.pl --strict --codespell tmp/*.patch

WARNING: please write a help paragraph that fully describes the config symbol
#42: FILE: drivers/clk/Kconfig:91:
+config COMMON_CLK_RP1
+       tristate "Raspberry Pi RP1-based clock support"
+       depends on PCI || COMPILE_TEST
+       depends on COMMON_CLK
+       help
+         Enable common clock framework support for Raspberry Pi RP1.
+         This mutli-function device has 3 main PLLs and several clock
+         generators to drive the internal sub-peripherals.
+

I don't understand this warning, the paragraph is there and is more or less similar
to many in the same file that are already upstream. Checkpatch bug?


CHECK: Alignment should match open parenthesis
#1541: FILE: drivers/clk/clk-rp1.c:1470:
+       if (WARN_ON_ONCE(clock_data->num_std_parents > AUX_SEL &&
+           strcmp("-", clock_data->parents[AUX_SEL])))

This would have worsen the code readability.


WARNING: ENOTSUPP is not a SUSV4 error code, prefer EOPNOTSUPP
#673: FILE: drivers/pinctrl/pinctrl-rp1.c:600:
+                               return -ENOTSUPP;

This I must investigate: I've already tried to fix it before sending the patchset
but for some reason it wouldn't work, so I planned to fix it in the upcoming 
releases.


WARNING: externs should be avoided in .c files
#331: FILE: drivers/misc/rp1/rp1-pci.c:58:
+extern char __dtbo_rp1_pci_begin[];

True, but in this case we don't have a symbol that should be exported to other
translation units, it just needs to be referenced inside the driver and
consumed locally. Hence it would be better to place the extern in .c file.


Apologies for a couple of other warnings that I could have seen in the first
place, but honestly they don't seems to be a big deal (one typo and on over
100 chars comment, that will be fixed in next patch version). 
 
> 
> Best regards,
> Krzysztof
>

Many thanks,
Andrea
Krzysztof Kozlowski Aug. 22, 2024, 9:50 a.m. UTC | #3
On 22/08/2024 11:05, Andrea della Porta wrote:
> Hi Krzysztof,
> 
> On 15:42 Wed 21 Aug     , Krzysztof Kozlowski wrote:
>> On 20/08/2024 16:36, Andrea della Porta wrote:
>>> RP1 is an MFD chipset that acts as a south-bridge PCIe endpoint sporting
>>> a pletora of subdevices (i.e.  Ethernet, USB host controller, I2C, PWM, 
>>> etc.) whose registers are all reachable starting from an offset from the
>>> BAR address.  The main point here is that while the RP1 as an endpoint
>>> itself is discoverable via usual PCI enumeraiton, the devices it contains
>>> are not discoverable and must be declared e.g. via the devicetree.
>>>
>>> This patchset is an attempt to provide a minimum infrastructure to allow
>>> the RP1 chipset to be discovered and perpherals it contains to be added
>>> from a devictree overlay loaded during RP1 PCI endpoint enumeration.
>>> Followup patches should add support for the several peripherals contained
>>> in RP1.
>>>
>>> This work is based upon dowstream drivers code and the proposal from RH
>>> et al. (see [1] and [2]). A similar approach is also pursued in [3].
>>
>> Looking briefly at findings it seems this was not really tested by
>> automation and you expect reviewers to find issues which are pointed out
>> by tools. That's not nice approach. Reviewer's time is limited, while
>> tools do it for free. And the tools are free - you can use them without
>> any effort.
> 
> Sorry if I gave you that impression, but this is not obviously the case.

Just look at number of reports... so many sparse reports that I wonder
how it is not the case.

And many kbuild reports.

> I've spent quite a bit of time in trying to deliver a patchset that ease
> your and others work, at least to the best I can. In fact, I've used many
> of the checking facilities you mentioned before sending it, solving all
> of the reported issues, except the ones for which there are strong reasons
> to leave untouched, as explained below.
> 
>>
>> It does not look like you tested the DTS against bindings. Please run
>> `make dtbs_check W=1` (see
>> Documentation/devicetree/bindings/writing-schema.rst or
>> https://www.linaro.org/blog/tips-and-tricks-for-validating-devicetree-sources-with-the-devicetree-schema/
>> for instructions).
> 
> #> make W=1 dt_binding_check DT_SCHEMA_FILES=raspberrypi,rp1-gpio.yaml
>    CHKDT   Documentation/devicetree/bindings
>    LINT    Documentation/devicetree/bindings
>    DTEX    Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.example.dts
>    DTC_CHK Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.example.dtb
> 
> #> make W=1 dt_binding_check DT_SCHEMA_FILES=raspberrypi,rp1-clocks.yaml
>    CHKDT   Documentation/devicetree/bindings
>    LINT    Documentation/devicetree/bindings
>    DTEX    Documentation/devicetree/bindings/clock/raspberrypi,rp1-clocks.example.dts
>    DTC_CHK Documentation/devicetree/bindings/clock/raspberrypi,rp1-clocks.example.dtb
> 
> I see no issues here, in case you've found something different, I kindly ask you to post
> the results.
> 
> #> make W=1 CHECK_DTBS=y broadcom/rp1.dtbo
>    DTC     arch/arm64/boot/dts/broadcom/rp1.dtbo
>    arch/arm64/boot/dts/broadcom/rp1.dtso:37.24-42.7: Warning (simple_bus_reg): /fragment@0/__overlay__/rp1@0/clk_xosc: missing or empty reg/ranges property
>    arch/arm64/boot/dts/broadcom/rp1.dtso:44.26-49.7: Warning (simple_bus_reg): /fragment@0/__overlay__/rp1@0/macb_pclk: missing or empty reg/ranges property
>    arch/arm64/boot/dts/broadcom/rp1.dtso:51.26-56.7: Warning (simple_bus_reg): /fragment@0/__overlay__/rp1@0/macb_hclk: missing or empty reg/ranges property
>    arch/arm64/boot/dts/broadcom/rp1.dtso:14.15-173.5: Warning (avoid_unnecessary_addr_size): /fragment@0/__overlay__: unnecessary #address-cells/#size-cells without "ranges", "dma-ranges" or child "reg" property 
> 
> I believe that These warnings are unavoidable, and stem from the fact that this
> is quite a peculiar setup (PCI endpoint which dynamically loads platform driver
> addressable via BAR).
> The missing reg/ranges in the threee clocks are due to the simple-bus of the
> containing node to which I believe they should belong: I did a test to place

This is not the place where they belong. non-MMIO nodes should not be
under simple-bus.

> those clocks in the same dtso under root or /clocks node but AFAIK it doesn't
> seems to work. I could move them in a separate dtso to be loaded before the main

Well... who instantiates them? If they are in top-level, then
CLK_OF_DECLARE which is not called at your point?

You must instantiate clocks different way, since they are not part of
"rp1". That's another bogus DT description... external oscilator is not
part of RP1.


> one but this is IMHO even more cumbersome than having a couple of warnings in
> CHECK_DTBS.
> Of course, if you have any suggestion on how to improve it I would be glad to
> discuss.
> About the last warning about the address/size-cells, if I drop those two lines
> in the _overlay_ node it generates even more warning, so again it's a "don't fix"
> one.
> 
>>
>> Please run standard kernel tools for static analysis, like coccinelle,
>> smatch and sparse, and fix reported warnings. Also please check for
>> warnings when building with W=1. Most of these commands (checks or W=1
>> build) can build specific targets, like some directory, to narrow the
>> scope to only your code. The code here looks like it needs a fix. Feel
>> free to get in touch if the warning is not clear.
> 
> I didn't run those static analyzers since I've preferred a more "manual" aproach
> by carfeully checking the code, but I agree that something can escape even the
> more carefully executed code inspection so I will add them to my arsenal from
> now on. Thanks for the heads up.

I don't care if you do not run static analyzers if you produce good
code. But if you produce bugs which could have been easily spotted with
sparser, than it is different thing.

Start running static checkers instead of asking reviewers to do that.

> 
>>
>> Please run scripts/checkpatch.pl and fix reported warnings. Then please
>> run `scripts/checkpatch.pl --strict` and (probably) fix more warnings.
>> Some warnings can be ignored, especially from --strict run, but the code
>> here looks like it needs a fix. Feel free to get in touch if the warning
>> is not clear.
>>
> 
> Again, most of checkpatch's complaints have been addressed, the remaining
> ones I deemed as not worth fixing, for example:>
> #> scripts/checkpatch.pl --strict --codespell tmp/*.patch
> 
> WARNING: please write a help paragraph that fully describes the config symbol
> #42: FILE: drivers/clk/Kconfig:91:
> +config COMMON_CLK_RP1
> +       tristate "Raspberry Pi RP1-based clock support"
> +       depends on PCI || COMPILE_TEST
> +       depends on COMMON_CLK
> +       help
> +         Enable common clock framework support for Raspberry Pi RP1.
> +         This mutli-function device has 3 main PLLs and several clock
> +         generators to drive the internal sub-peripherals.
> +
> 
> I don't understand this warning, the paragraph is there and is more or less similar
> to many in the same file that are already upstream. Checkpatch bug?
> 
> 
> CHECK: Alignment should match open parenthesis
> #1541: FILE: drivers/clk/clk-rp1.c:1470:
> +       if (WARN_ON_ONCE(clock_data->num_std_parents > AUX_SEL &&
> +           strcmp("-", clock_data->parents[AUX_SEL])))
> 
> This would have worsen the code readability.
> 
> 
> WARNING: ENOTSUPP is not a SUSV4 error code, prefer EOPNOTSUPP
> #673: FILE: drivers/pinctrl/pinctrl-rp1.c:600:
> +                               return -ENOTSUPP;
> 
> This I must investigate: I've already tried to fix it before sending the patchset
> but for some reason it wouldn't work, so I planned to fix it in the upcoming 
> releases.
> 
> 
> WARNING: externs should be avoided in .c files
> #331: FILE: drivers/misc/rp1/rp1-pci.c:58:
> +extern char __dtbo_rp1_pci_begin[];
> 
> True, but in this case we don't have a symbol that should be exported to other
> translation units, it just needs to be referenced inside the driver and
> consumed locally. Hence it would be better to place the extern in .c file.
> 
> 
> Apologies for a couple of other warnings that I could have seen in the first
> place, but honestly they don't seems to be a big deal (one typo and on over
> 100 chars comment, that will be fixed in next patch version). 

Again, judging by number of reports from checkers that is a big deal,
because it is your task to run the tools.

Best regards,
Krzysztof
Andrew Lunn Aug. 22, 2024, 1:04 p.m. UTC | #4
> WARNING: ENOTSUPP is not a SUSV4 error code, prefer EOPNOTSUPP
> #673: FILE: drivers/pinctrl/pinctrl-rp1.c:600:
> +                               return -ENOTSUPP;
> 
> This I must investigate: I've already tried to fix it before sending the patchset
> but for some reason it wouldn't work, so I planned to fix it in the upcoming 
> releases.

ENOTSUPP is an NFS error. It should not be used outside for NFS. You
want EOPNOTSUPP.

 
> WARNING: externs should be avoided in .c files
> #331: FILE: drivers/misc/rp1/rp1-pci.c:58:
> +extern char __dtbo_rp1_pci_begin[];
> 
> True, but in this case we don't have a symbol that should be exported to other
> translation units, it just needs to be referenced inside the driver and
> consumed locally. Hence it would be better to place the extern in .c file.
 
Did you try making it static.

	Andrew
Andrea della Porta Aug. 29, 2024, 12:01 p.m. UTC | #5
Hi Andrew,

On 15:04 Thu 22 Aug     , Andrew Lunn wrote:
> > WARNING: ENOTSUPP is not a SUSV4 error code, prefer EOPNOTSUPP
> > #673: FILE: drivers/pinctrl/pinctrl-rp1.c:600:
> > +                               return -ENOTSUPP;
> > 
> > This I must investigate: I've already tried to fix it before sending the patchset
> > but for some reason it wouldn't work, so I planned to fix it in the upcoming 
> > releases.
> 
> ENOTSUPP is an NFS error. It should not be used outside for NFS. You
> want EOPNOTSUPP.

Ack.

> 
>  
> > WARNING: externs should be avoided in .c files
> > #331: FILE: drivers/misc/rp1/rp1-pci.c:58:
> > +extern char __dtbo_rp1_pci_begin[];
> > 
> > True, but in this case we don't have a symbol that should be exported to other
> > translation units, it just needs to be referenced inside the driver and
> > consumed locally. Hence it would be better to place the extern in .c file.
>  
> Did you try making it static.

The dtso is compiled into an obj and linked with the driver which is in
a different transaltion unit. I'm not aware on other ways to include that
symbol without declaring it extern (the exception being some hackery 
trick that compile the dtso into a .c file to be included into the driver
main source file). 
Or probably I'm not seeing what you are proposing, could you please elaborate
on that?

Many thanks,
Andrea

> 
> 	Andrew
Andrew Lunn Aug. 29, 2024, 1:04 p.m. UTC | #6
> > > WARNING: externs should be avoided in .c files
> > > #331: FILE: drivers/misc/rp1/rp1-pci.c:58:
> > > +extern char __dtbo_rp1_pci_begin[];
> > > 
> > > True, but in this case we don't have a symbol that should be exported to other
> > > translation units, it just needs to be referenced inside the driver and
> > > consumed locally. Hence it would be better to place the extern in .c file.
> >  
> > Did you try making it static.
> 
> The dtso is compiled into an obj and linked with the driver which is in
> a different transaltion unit. I'm not aware on other ways to include that
> symbol without declaring it extern (the exception being some hackery 
> trick that compile the dtso into a .c file to be included into the driver
> main source file). 
> Or probably I'm not seeing what you are proposing, could you please elaborate
> on that?

Sorry, i jumped to the wrong conclusion. Often it is missing static
keyword which causes warnings. However, you say it needs to be global
scope.

Reading the warning again:

> > > WARNING: externs should be avoided in .c files

It is wanting you to put it in a .h file, which then gets
included by the two users.

	Andrew
Andrea della Porta Aug. 29, 2024, 1:11 p.m. UTC | #7
Hi Krzysztof,

On 11:50 Thu 22 Aug     , Krzysztof Kozlowski wrote:
> On 22/08/2024 11:05, Andrea della Porta wrote:
> > Hi Krzysztof,
> > 
> > On 15:42 Wed 21 Aug     , Krzysztof Kozlowski wrote:
> >> On 20/08/2024 16:36, Andrea della Porta wrote:
> >>> RP1 is an MFD chipset that acts as a south-bridge PCIe endpoint sporting
> >>> a pletora of subdevices (i.e.  Ethernet, USB host controller, I2C, PWM, 
> >>> etc.) whose registers are all reachable starting from an offset from the
> >>> BAR address.  The main point here is that while the RP1 as an endpoint
> >>> itself is discoverable via usual PCI enumeraiton, the devices it contains
> >>> are not discoverable and must be declared e.g. via the devicetree.
> >>>
> >>> This patchset is an attempt to provide a minimum infrastructure to allow
> >>> the RP1 chipset to be discovered and perpherals it contains to be added
> >>> from a devictree overlay loaded during RP1 PCI endpoint enumeration.
> >>> Followup patches should add support for the several peripherals contained
> >>> in RP1.
> >>>
> >>> This work is based upon dowstream drivers code and the proposal from RH
> >>> et al. (see [1] and [2]). A similar approach is also pursued in [3].
> >>
> >> Looking briefly at findings it seems this was not really tested by
> >> automation and you expect reviewers to find issues which are pointed out
> >> by tools. That's not nice approach. Reviewer's time is limited, while
> >> tools do it for free. And the tools are free - you can use them without
> >> any effort.
> > 
> > Sorry if I gave you that impression, but this is not obviously the case.
> 
> Just look at number of reports... so many sparse reports that I wonder
> how it is not the case.
> 
> And many kbuild reports.

Ack.

> 
> > I've spent quite a bit of time in trying to deliver a patchset that ease
> > your and others work, at least to the best I can. In fact, I've used many
> > of the checking facilities you mentioned before sending it, solving all
> > of the reported issues, except the ones for which there are strong reasons
> > to leave untouched, as explained below.
> > 
> >>
> >> It does not look like you tested the DTS against bindings. Please run
> >> `make dtbs_check W=1` (see
> >> Documentation/devicetree/bindings/writing-schema.rst or
> >> https://www.linaro.org/blog/tips-and-tricks-for-validating-devicetree-sources-with-the-devicetree-schema/
> >> for instructions).
> > 
> > #> make W=1 dt_binding_check DT_SCHEMA_FILES=raspberrypi,rp1-gpio.yaml
> >    CHKDT   Documentation/devicetree/bindings
> >    LINT    Documentation/devicetree/bindings
> >    DTEX    Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.example.dts
> >    DTC_CHK Documentation/devicetree/bindings/pinctrl/raspberrypi,rp1-gpio.example.dtb
> > 
> > #> make W=1 dt_binding_check DT_SCHEMA_FILES=raspberrypi,rp1-clocks.yaml
> >    CHKDT   Documentation/devicetree/bindings
> >    LINT    Documentation/devicetree/bindings
> >    DTEX    Documentation/devicetree/bindings/clock/raspberrypi,rp1-clocks.example.dts
> >    DTC_CHK Documentation/devicetree/bindings/clock/raspberrypi,rp1-clocks.example.dtb
> > 
> > I see no issues here, in case you've found something different, I kindly ask you to post
> > the results.
> > 
> > #> make W=1 CHECK_DTBS=y broadcom/rp1.dtbo
> >    DTC     arch/arm64/boot/dts/broadcom/rp1.dtbo
> >    arch/arm64/boot/dts/broadcom/rp1.dtso:37.24-42.7: Warning (simple_bus_reg): /fragment@0/__overlay__/rp1@0/clk_xosc: missing or empty reg/ranges property
> >    arch/arm64/boot/dts/broadcom/rp1.dtso:44.26-49.7: Warning (simple_bus_reg): /fragment@0/__overlay__/rp1@0/macb_pclk: missing or empty reg/ranges property
> >    arch/arm64/boot/dts/broadcom/rp1.dtso:51.26-56.7: Warning (simple_bus_reg): /fragment@0/__overlay__/rp1@0/macb_hclk: missing or empty reg/ranges property
> >    arch/arm64/boot/dts/broadcom/rp1.dtso:14.15-173.5: Warning (avoid_unnecessary_addr_size): /fragment@0/__overlay__: unnecessary #address-cells/#size-cells without "ranges", "dma-ranges" or child "reg" property 
> > 
> > I believe that These warnings are unavoidable, and stem from the fact that this
> > is quite a peculiar setup (PCI endpoint which dynamically loads platform driver
> > addressable via BAR).
> > The missing reg/ranges in the threee clocks are due to the simple-bus of the
> > containing node to which I believe they should belong: I did a test to place
> 
> This is not the place where they belong. non-MMIO nodes should not be
> under simple-bus.

Ack.

> 
> > those clocks in the same dtso under root or /clocks node but AFAIK it doesn't
> > seems to work. I could move them in a separate dtso to be loaded before the main
> 
> Well... who instantiates them? If they are in top-level, then
> CLK_OF_DECLARE which is not called at your point?
> 
> You must instantiate clocks different way, since they are not part of
> "rp1". That's another bogus DT description... external oscilator is not
> part of RP1.
>

Ok, I'll dive into that and see what I can come up with. Many thanks for
this feedback.
 
> 
> > one but this is IMHO even more cumbersome than having a couple of warnings in
> > CHECK_DTBS.
> > Of course, if you have any suggestion on how to improve it I would be glad to
> > discuss.
> > About the last warning about the address/size-cells, if I drop those two lines
> > in the _overlay_ node it generates even more warning, so again it's a "don't fix"
> > one.
> > 
> >>
> >> Please run standard kernel tools for static analysis, like coccinelle,
> >> smatch and sparse, and fix reported warnings. Also please check for
> >> warnings when building with W=1. Most of these commands (checks or W=1
> >> build) can build specific targets, like some directory, to narrow the
> >> scope to only your code. The code here looks like it needs a fix. Feel
> >> free to get in touch if the warning is not clear.
> > 
> > I didn't run those static analyzers since I've preferred a more "manual" aproach
> > by carfeully checking the code, but I agree that something can escape even the
> > more carefully executed code inspection so I will add them to my arsenal from
> > now on. Thanks for the heads up.
> 
> I don't care if you do not run static analyzers if you produce good
> code. But if you produce bugs which could have been easily spotted with
> sparser, than it is different thing.
> 
> Start running static checkers instead of asking reviewers to do that.

Ack.

> 
> > 
> >>
> >> Please run scripts/checkpatch.pl and fix reported warnings. Then please
> >> run `scripts/checkpatch.pl --strict` and (probably) fix more warnings.
> >> Some warnings can be ignored, especially from --strict run, but the code
> >> here looks like it needs a fix. Feel free to get in touch if the warning
> >> is not clear.
> >>
> > 
> > Again, most of checkpatch's complaints have been addressed, the remaining
> > ones I deemed as not worth fixing, for example:>
> > #> scripts/checkpatch.pl --strict --codespell tmp/*.patch
> > 
> > WARNING: please write a help paragraph that fully describes the config symbol
> > #42: FILE: drivers/clk/Kconfig:91:
> > +config COMMON_CLK_RP1
> > +       tristate "Raspberry Pi RP1-based clock support"
> > +       depends on PCI || COMPILE_TEST
> > +       depends on COMMON_CLK
> > +       help
> > +         Enable common clock framework support for Raspberry Pi RP1.
> > +         This mutli-function device has 3 main PLLs and several clock
> > +         generators to drive the internal sub-peripherals.
> > +
> > 
> > I don't understand this warning, the paragraph is there and is more or less similar
> > to many in the same file that are already upstream. Checkpatch bug?
> > 
> > 
> > CHECK: Alignment should match open parenthesis
> > #1541: FILE: drivers/clk/clk-rp1.c:1470:
> > +       if (WARN_ON_ONCE(clock_data->num_std_parents > AUX_SEL &&
> > +           strcmp("-", clock_data->parents[AUX_SEL])))
> > 
> > This would have worsen the code readability.
> > 
> > 
> > WARNING: ENOTSUPP is not a SUSV4 error code, prefer EOPNOTSUPP
> > #673: FILE: drivers/pinctrl/pinctrl-rp1.c:600:
> > +                               return -ENOTSUPP;
> > 
> > This I must investigate: I've already tried to fix it before sending the patchset
> > but for some reason it wouldn't work, so I planned to fix it in the upcoming 
> > releases.
> > 
> > 
> > WARNING: externs should be avoided in .c files
> > #331: FILE: drivers/misc/rp1/rp1-pci.c:58:
> > +extern char __dtbo_rp1_pci_begin[];
> > 
> > True, but in this case we don't have a symbol that should be exported to other
> > translation units, it just needs to be referenced inside the driver and
> > consumed locally. Hence it would be better to place the extern in .c file.
> > 
> > 
> > Apologies for a couple of other warnings that I could have seen in the first
> > place, but honestly they don't seems to be a big deal (one typo and on over
> > 100 chars comment, that will be fixed in next patch version). 
> 
> Again, judging by number of reports from checkers that is a big deal,
> because it is your task to run the tools.

Ack.

Many thanks,
Andrea

> 
> Best regards,
> Krzysztof
>
Andrea della Porta Aug. 29, 2024, 1:13 p.m. UTC | #8
Hi Andrew,

On 15:04 Thu 29 Aug     , Andrew Lunn wrote:
> > > > WARNING: externs should be avoided in .c files
> > > > #331: FILE: drivers/misc/rp1/rp1-pci.c:58:
> > > > +extern char __dtbo_rp1_pci_begin[];
> > > > 
> > > > True, but in this case we don't have a symbol that should be exported to other
> > > > translation units, it just needs to be referenced inside the driver and
> > > > consumed locally. Hence it would be better to place the extern in .c file.
> > >  
> > > Did you try making it static.
> > 
> > The dtso is compiled into an obj and linked with the driver which is in
> > a different transaltion unit. I'm not aware on other ways to include that
> > symbol without declaring it extern (the exception being some hackery 
> > trick that compile the dtso into a .c file to be included into the driver
> > main source file). 
> > Or probably I'm not seeing what you are proposing, could you please elaborate
> > on that?
> 
> Sorry, i jumped to the wrong conclusion. Often it is missing static
> keyword which causes warnings. However, you say it needs to be global
> scope.
> 
> Reading the warning again:
> 
> > > > WARNING: externs should be avoided in .c files
> 
> It is wanting you to put it in a .h file, which then gets
> included by the two users.

Ah I see now what you were referring to, thanks.
I'll put the extern into an header file, although there are no two users
of that, the only one being rp1-pci.c.

Many thanks,
Andrea

> 
> 	Andrew
Andrea della Porta Aug. 30, 2024, 5:21 a.m. UTC | #9
Hi Andrew,

On 15:04 Thu 29 Aug     , Andrew Lunn wrote:
> > > > WARNING: externs should be avoided in .c files
> > > > #331: FILE: drivers/misc/rp1/rp1-pci.c:58:
> > > > +extern char __dtbo_rp1_pci_begin[];
> > > > 
> > > > True, but in this case we don't have a symbol that should be exported to other
> > > > translation units, it just needs to be referenced inside the driver and
> > > > consumed locally. Hence it would be better to place the extern in .c file.
> > >  
> > > Did you try making it static.
> > 
> > The dtso is compiled into an obj and linked with the driver which is in
> > a different transaltion unit. I'm not aware on other ways to include that
> > symbol without declaring it extern (the exception being some hackery 
> > trick that compile the dtso into a .c file to be included into the driver
> > main source file). 
> > Or probably I'm not seeing what you are proposing, could you please elaborate
> > on that?
> 
> Sorry, i jumped to the wrong conclusion. Often it is missing static
> keyword which causes warnings. However, you say it needs to be global
> scope.
> 
> Reading the warning again:
> 
> > > > WARNING: externs should be avoided in .c files
> 
> It is wanting you to put it in a .h file, which then gets
> included by the two users.

On a second thought, are you really sure we want to proceed with the header file?
After all the only line in it would be the extern declaration and the only one to
include it would be rp1-dev.c. Moreover, an header file would convey the false
premise that you can include it and use that symbol while in fact it should be
only used inside the driver.
OTOH, not creating that header file will continue to trigger the warning...

Many thanks,
Andrea

> 
> 	Andrew
Andrew Lunn Aug. 30, 2024, 2:10 p.m. UTC | #10
> On a second thought, are you really sure we want to proceed with the header file?
> After all the only line in it would be the extern declaration and the only one to
> include it would be rp1-dev.c. Moreover, an header file would convey the false
> premise that you can include it and use that symbol while in fact it should be
> only used inside the driver.
> OTOH, not creating that header file will continue to trigger the warning...

The header file does not need to be in global scope. It could be in
the driver source directory. As such, nothing outside of the driver
can use it.

Headers like this have multiple proposes. One is they make a symbol
visible to the linker. But having two different .c files include the
header enables type checking, which for long term maintenance is just
as important. So a one line header is fine.

	Andrew
Andrea della Porta Sept. 2, 2024, 9:21 a.m. UTC | #11
Hi Andrew,

On 16:10 Fri 30 Aug     , Andrew Lunn wrote:
> > On a second thought, are you really sure we want to proceed with the header file?
> > After all the only line in it would be the extern declaration and the only one to
> > include it would be rp1-dev.c. Moreover, an header file would convey the false
> > premise that you can include it and use that symbol while in fact it should be
> > only used inside the driver.
> > OTOH, not creating that header file will continue to trigger the warning...
> 
> The header file does not need to be in global scope. It could be in
> the driver source directory. As such, nothing outside of the driver
> can use it.

Ack.

> 
> Headers like this have multiple proposes. One is they make a symbol
> visible to the linker. But having two different .c files include the

Hmm... not sure what second file is including it, since only rp1_pci.c needs it.

> header enables type checking, which for long term maintenance is just
> as important. So a one line header is fine.

Done.

Cheers,
Andrea

> 
> 	Andrew
>