RE: [EXT] Re: [PATCH net-next 6/9] net: phy: add backplane kr driver support

From: Florinel Iordache
Date: Fri Mar 27 2020 - 09:02:36 EST


> > +static u32 le_ioread32(void __iomem *reg) {
> > + return ioread32(reg);
> > +}
> > +
> > +static void le_iowrite32(u32 value, void __iomem *reg) {
> > + iowrite32(value, reg);
> > +}
> > +
> > +static u32 be_ioread32(void __iomem *reg) {
> > + return ioread32be(reg);
> > +}
> > +
> > +static void be_iowrite32(u32 value, void __iomem *reg) {
> > + iowrite32be(value, reg);
> > +}
>
> This is very surprising to me. I've not got my head around the structure of this
> code yet, but i'm surprised to see memory mapped access functions in generic
> code.
>
> Andrew

Hi Andrew,

This is part of the framework used to automatically setup desired I/O
callbacks for memory access according to device specific endianness
which is specified in the specific device tree (DTS).
This approach (explained below) was used to avoid the potential
redundant code related to memory access LE/BE which should be
similar for all devices.

This portion of code is just preparing these four static IO routines
for specific endianness access LE/BE which are then installed as
callbacks by the generic driver on generic DT parsing routine:
backplane_parse_dt according to endianness flag:
+ /* setup ioread/iowrite according to endianness */
+ if (bp_phy->bp_dev.is_little_endian) {
+ bp_phy->bp_dev.io.read32 = le_ioread32;
+ bp_phy->bp_dev.io.write32 = le_iowrite32;
+ } else {
+ bp_phy->bp_dev.io.read32 = be_ioread32;
+ bp_phy->bp_dev.io.write32 = be_iowrite32;
+ }

These io callbacks are setup in the following structure:
+/* Endianness specific memory I/O operations */
struct mem_io_ops {

which is part of generic structure:
+/* Backplane device info */
+struct backplane_dev_info {
+. . .
+ struct mem_io_ops io;

which in the end will be used directly by the device specific code for
specific memory access according to specific endianness specified
in the DTS.

The endianness flag must be correctly set by the device specific code
before calling the generic function backplane_parse_dt, according to
device specific endianness specified in the specific device tree DTS:
+bp_phy->bp_dev.is_little_endian = of_property_read_bool(serdes_node,
"little-endian");

This action to setup desired IO callbacks could also be performed in the
specific device code but by using this framework the process is more
automatic, it's reusing the logic and therefore decreasing the overall
LOC required.
If any specific device is doing this action by itself (which is a similar
action regardless the specific device) then we will end up with a lot of
redundant code.

Florin.