Re: [PATCH 1/3] net: Add support for Broadcom GENETv5 Ethernet controller

2019-12-27 Thread Amit Tomer
Hi Sascha,

> Are any other cases i could test ? don't worry, one of three boards i
> could damage ! (but it's better if not ... ;-))

Just curious to know what data transfer rate, you see while tftp?

Thanks
-Amit


Re: [PATCH 1/3] net: Add support for Broadcom GENETv5 Ethernet controller

2019-12-25 Thread Sascha Dewald
thank you :-)

@Andre:
you said it before.

Are any other cases i could test ? don't worry, one of three boards i
could damage ! (but it's better if not ... ;-))

Happy days, people - for all of you :-)

and thank you again

Am Mo., 23. Dez. 2019 um 23:24 Uhr schrieb André Przywara
:
>
> On 23/12/2019 18:42, Stefan Wahren wrote:
>
> Hi Stefan,
>
> > Am 20.12.19 um 20:29 schrieb Stefan Wahren:
> >> Hi Andre,
> >>
> >> Am 18.12.19 um 12:59 schrieb Andre Przywara:
> >>> From: Amit Singh Tomar 
> >>>
> >>> The Broadcom GENET Ethernet MACs are used in several MIPS based SoCs
> >>> and in the Broadcom 2711/2838 SoC used on the Raspberry Pi 4.
> >>> There is no publicly available documentation, so this driver is based
> >>> on the Linux driver. Compared to that the queue management is
> >>> drastically simplified, also we only support version 5 of the IP and
> >>> RGMII connections between MAC and PHY, as used on the RPi4.
> >>>
> >>> Signed-off-by: Amit Singh Tomar 
> >>> Reviewed-by: Andre Przywara 
> >>> [Andre: heavy cleanup and a few fixes]
> >>> Signed-off-by: Andre Przywara 
> >>> ---
> >>>  drivers/net/Kconfig|   7 +
> >>>  drivers/net/Makefile   |   1 +
> >>>  drivers/net/bcmgenet.c | 702 +
> >>>  3 files changed, 710 insertions(+)
> >>>  create mode 100644 drivers/net/bcmgenet.c
> >>>
> >> ...
> >>> +
> >>> +/* We only support RGMII (as used on the RPi4). */
> >>> +static int bcmgenet_interface_set(struct bcmgenet_eth_priv *priv)
> >>> +{
> >>> +   phy_interface_t phy_mode = priv->interface;
> >>> +
> >>> +   switch (phy_mode) {
> >>> +   case PHY_INTERFACE_MODE_RGMII:
> >>> +   writel(PORT_MODE_EXT_GPHY, priv->mac_reg + SYS_PORT_CTRL);
> >>> +   break;
> >> This doesn't match the current Linux upstream kernel / DTS. We consider
> >> the PHY mode in the downstream DTS as wrong. It should be
> >> PHY_INTERFACE_MODE_RGMII_RXID. So please add this to keep compatibility
> >> to the upstream devicetree.
> >>
> >> Please following this series [1] for more information.
> >>
> >> Thank you a lot for this work
> >>
> >> Stefan
> >>
> >> [1] - https://marc.info/?l=linux-netdev&m=157350191805462&w=2
> >
> > Except of this, i noticed another issue with current u-boot. It
> > complains about misaligned access:
>
> Thanks for the report, and yeah: this is one of the things I wanted to
> fix still. But that only happens with the 32-bit build, right?
> The issue goes a bit deeper than it seems at the first glance.
> Can you please try this patch?
> https://lists.denx.de/pipermail/u-boot/2019-December/394174.html
>
> And feel free to join the discussion there ;-)
>
> Cheers,
> Andre
>
> >
> > U-Boot 2020.01-rc5-7-g5111518-dirty (Dec 23 2019 - 19:25:49 +0100)
> >
> > DRAM:  948 MiB
> > RPI 4 Model B (0xc03112)
> > MMC:   sdhci@7e30: 0, emmc2@7e34: 1
> > Loading Environment from FAT... Card did not respond to voltage select!
> > In:serial
> > Out:   serial
> > Err:   serial
> > Net:   eth0: ethernet@7d58
> > Hit any key to stop autoboot:  0
> > Card did not respond to voltage select!
> > switch to partitions #0, OK
> > mmc1 is current device
> > Scanning mmc 1:1...
> > Found U-Boot script /boot.scr
> > 213 bytes read in 73 ms (2 KiB/s)
> > ## Executing script at 0240
> > Card did not respond to voltage select!
> > Wrong Image Format for bootm command
> > ERROR: can't get kernel image!
> > SCRIPT FAILED: continuing...
> > 30395 bytes read in 53 ms (559.6 KiB/s)
> > ethernet@7d58 Waiting for PHY auto negotiation to complete.. done
> > BOOTP broadcast 1
> > CACHE: Misaligned operation at range [3b3ed1c0, 3b3ed316]
> > CACHE: Misaligned operation at range [3b3ed1c0, 3b3ed316]
> > DHCP client bound to address 192.168.1.171 (15 ms)
> > *** Warning: no boot file name; using 'C0A801AB.img'
> > Using ethernet@7d58 device
> > TFTP from server 192.168.1.1; our IP address is 192.168.1.171
> > Filename 'C0A801AB.img'.
> > Load address: 0x20
> > Loading: CACHE: Misaligned operation at range [3b3ec640, 3b3ec66a]
> >
>


Re: [PATCH 1/3] net: Add support for Broadcom GENETv5 Ethernet controller

2019-12-23 Thread André Przywara
On 23/12/2019 18:42, Stefan Wahren wrote:

Hi Stefan,

> Am 20.12.19 um 20:29 schrieb Stefan Wahren:
>> Hi Andre,
>>
>> Am 18.12.19 um 12:59 schrieb Andre Przywara:
>>> From: Amit Singh Tomar 
>>>
>>> The Broadcom GENET Ethernet MACs are used in several MIPS based SoCs
>>> and in the Broadcom 2711/2838 SoC used on the Raspberry Pi 4.
>>> There is no publicly available documentation, so this driver is based
>>> on the Linux driver. Compared to that the queue management is
>>> drastically simplified, also we only support version 5 of the IP and
>>> RGMII connections between MAC and PHY, as used on the RPi4.
>>>
>>> Signed-off-by: Amit Singh Tomar 
>>> Reviewed-by: Andre Przywara 
>>> [Andre: heavy cleanup and a few fixes]
>>> Signed-off-by: Andre Przywara 
>>> ---
>>>  drivers/net/Kconfig|   7 +
>>>  drivers/net/Makefile   |   1 +
>>>  drivers/net/bcmgenet.c | 702 +
>>>  3 files changed, 710 insertions(+)
>>>  create mode 100644 drivers/net/bcmgenet.c
>>>
>> ...
>>> +
>>> +/* We only support RGMII (as used on the RPi4). */
>>> +static int bcmgenet_interface_set(struct bcmgenet_eth_priv *priv)
>>> +{
>>> +   phy_interface_t phy_mode = priv->interface;
>>> +
>>> +   switch (phy_mode) {
>>> +   case PHY_INTERFACE_MODE_RGMII:
>>> +   writel(PORT_MODE_EXT_GPHY, priv->mac_reg + SYS_PORT_CTRL);
>>> +   break;
>> This doesn't match the current Linux upstream kernel / DTS. We consider
>> the PHY mode in the downstream DTS as wrong. It should be
>> PHY_INTERFACE_MODE_RGMII_RXID. So please add this to keep compatibility
>> to the upstream devicetree.
>>
>> Please following this series [1] for more information.
>>
>> Thank you a lot for this work
>>
>> Stefan
>>
>> [1] - https://marc.info/?l=linux-netdev&m=157350191805462&w=2
> 
> Except of this, i noticed another issue with current u-boot. It
> complains about misaligned access:

Thanks for the report, and yeah: this is one of the things I wanted to
fix still. But that only happens with the 32-bit build, right?
The issue goes a bit deeper than it seems at the first glance.
Can you please try this patch?
https://lists.denx.de/pipermail/u-boot/2019-December/394174.html

And feel free to join the discussion there ;-)

Cheers,
Andre

> 
> U-Boot 2020.01-rc5-7-g5111518-dirty (Dec 23 2019 - 19:25:49 +0100)
>  
> DRAM:  948 MiB
> RPI 4 Model B (0xc03112)
> MMC:   sdhci@7e30: 0, emmc2@7e34: 1
> Loading Environment from FAT... Card did not respond to voltage select!
> In:    serial
> Out:   serial
> Err:   serial
> Net:   eth0: ethernet@7d58
> Hit any key to stop autoboot:  0
> Card did not respond to voltage select!
> switch to partitions #0, OK
> mmc1 is current device
> Scanning mmc 1:1...
> Found U-Boot script /boot.scr
> 213 bytes read in 73 ms (2 KiB/s)
> ## Executing script at 0240
> Card did not respond to voltage select!
> Wrong Image Format for bootm command
> ERROR: can't get kernel image!
> SCRIPT FAILED: continuing...
> 30395 bytes read in 53 ms (559.6 KiB/s)
> ethernet@7d58 Waiting for PHY auto negotiation to complete.. done
> BOOTP broadcast 1
> CACHE: Misaligned operation at range [3b3ed1c0, 3b3ed316]
> CACHE: Misaligned operation at range [3b3ed1c0, 3b3ed316]
> DHCP client bound to address 192.168.1.171 (15 ms)
> *** Warning: no boot file name; using 'C0A801AB.img'
> Using ethernet@7d58 device
> TFTP from server 192.168.1.1; our IP address is 192.168.1.171
> Filename 'C0A801AB.img'.
> Load address: 0x20
> Loading: CACHE: Misaligned operation at range [3b3ec640, 3b3ec66a]
> 



Re: [PATCH 1/3] net: Add support for Broadcom GENETv5 Ethernet controller

2019-12-23 Thread Stefan Wahren
Am 20.12.19 um 20:29 schrieb Stefan Wahren:
> Hi Andre,
>
> Am 18.12.19 um 12:59 schrieb Andre Przywara:
>> From: Amit Singh Tomar 
>>
>> The Broadcom GENET Ethernet MACs are used in several MIPS based SoCs
>> and in the Broadcom 2711/2838 SoC used on the Raspberry Pi 4.
>> There is no publicly available documentation, so this driver is based
>> on the Linux driver. Compared to that the queue management is
>> drastically simplified, also we only support version 5 of the IP and
>> RGMII connections between MAC and PHY, as used on the RPi4.
>>
>> Signed-off-by: Amit Singh Tomar 
>> Reviewed-by: Andre Przywara 
>> [Andre: heavy cleanup and a few fixes]
>> Signed-off-by: Andre Przywara 
>> ---
>>  drivers/net/Kconfig|   7 +
>>  drivers/net/Makefile   |   1 +
>>  drivers/net/bcmgenet.c | 702 +
>>  3 files changed, 710 insertions(+)
>>  create mode 100644 drivers/net/bcmgenet.c
>>
> ...
>> +
>> +/* We only support RGMII (as used on the RPi4). */
>> +static int bcmgenet_interface_set(struct bcmgenet_eth_priv *priv)
>> +{
>> +phy_interface_t phy_mode = priv->interface;
>> +
>> +switch (phy_mode) {
>> +case PHY_INTERFACE_MODE_RGMII:
>> +writel(PORT_MODE_EXT_GPHY, priv->mac_reg + SYS_PORT_CTRL);
>> +break;
> This doesn't match the current Linux upstream kernel / DTS. We consider
> the PHY mode in the downstream DTS as wrong. It should be
> PHY_INTERFACE_MODE_RGMII_RXID. So please add this to keep compatibility
> to the upstream devicetree.
>
> Please following this series [1] for more information.
>
> Thank you a lot for this work
>
> Stefan
>
> [1] - https://marc.info/?l=linux-netdev&m=157350191805462&w=2

Except of this, i noticed another issue with current u-boot. It
complains about misaligned access:

U-Boot 2020.01-rc5-7-g5111518-dirty (Dec 23 2019 - 19:25:49 +0100)
 
DRAM:  948 MiB
RPI 4 Model B (0xc03112)
MMC:   sdhci@7e30: 0, emmc2@7e34: 1
Loading Environment from FAT... Card did not respond to voltage select!
In:    serial
Out:   serial
Err:   serial
Net:   eth0: ethernet@7d58
Hit any key to stop autoboot:  0
Card did not respond to voltage select!
switch to partitions #0, OK
mmc1 is current device
Scanning mmc 1:1...
Found U-Boot script /boot.scr
213 bytes read in 73 ms (2 KiB/s)
## Executing script at 0240
Card did not respond to voltage select!
Wrong Image Format for bootm command
ERROR: can't get kernel image!
SCRIPT FAILED: continuing...
30395 bytes read in 53 ms (559.6 KiB/s)
ethernet@7d58 Waiting for PHY auto negotiation to complete.. done
BOOTP broadcast 1
CACHE: Misaligned operation at range [3b3ed1c0, 3b3ed316]
CACHE: Misaligned operation at range [3b3ed1c0, 3b3ed316]
DHCP client bound to address 192.168.1.171 (15 ms)
*** Warning: no boot file name; using 'C0A801AB.img'
Using ethernet@7d58 device
TFTP from server 192.168.1.1; our IP address is 192.168.1.171
Filename 'C0A801AB.img'.
Load address: 0x20
Loading: CACHE: Misaligned operation at range [3b3ec640, 3b3ec66a]



Re: [PATCH 1/3] net: Add support for Broadcom GENETv5 Ethernet controller

2019-12-20 Thread Florian Fainelli



On 12/19/2019 4:58 AM, Daniel Schwierzeck wrote:
> Hi Andre,
> 
> Am 19.12.19 um 12:42 schrieb Andre Przywara:
>> On Thu, 19 Dec 2019 12:32:06 +0100
>> Daniel Schwierzeck  wrote:
>>
>> Hi Daniel,
>>
>> many thanks for your valuable comments! Do you have access to a MIPS board 
>> using a GENETv5 MAC? I would be very curious to see if the driver works 
>> there, and am happy to make adjustments.
> 
> No, I have not. I was only triggered by your commit message that this
> MAC is also used on some MIPS based Broadcom SoC's ;)

GENET v1, v2 and v3 are used exclusively used on MIPS-based Broadcom STB
chips. GENET v4 is used exclusively used on ARM (32-bit) Broadcom STB
chips and finally GENET v5 is used exclusively used on ARM 64-bit based
chips, including 2711. Unlike other peripherals (SPI, NAND, I2C,
Ethernet switches and PHYs) this Ethernet MAC is only used on STB chips
and no other business unit within Broadcom has used it AFAICT so the
chances of finding GENET in a non STB chips are close to zero at this point.

The GENET data path goes through a proprietary bus called SCB which for
MIPS and ARM 32-bit was configurable to be little, big or automatically
follow the CPU's endian which is the default. With the latest 64-bit ARM
chips it was decided to drop the endian configuration and hard code the
bus to be little endian. The register interface goes through a
proprietary bus called GISB which always follows the CPU's endian and is
not configurable AFAICT (there are other properties, like no
re-ordering, no posting, which is why "raw" accessors are correct, too).
Therefore using native endian accessors is the right thing to do here to
guarantee maximum portability between all SoCs where this controller can
be used.

Only MIPS-based STB chips support a boot strap to select the CPU's
endian and when that happens the SCB and GISB buses remain native endian
as indicated earlier. We did some work to ensure that an ARM BE kernel
would work:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=69d2ea9c798983c4a7157278ec84ff969d1cd8e8

but that was just for making sure there were no obvious problem and is
not a configuration we support or want to support and only the kernel
and userland were made BE for testing, it was booted from the LE boot
loader.

> 
>> Does your board use a PHY connected via RGMII? Because this is something we 
>> are relying on at the moment. But without any ways of testing this I'd 
>> rather not support other transports at this time.
>>
>> I think your points below are all valid, so thanks for bringing this up. 
>> Will test this later on and post a v2 in due time then.
>>
> 
> We had a similar scenario a few months ago, where a newly supported ARM
> based Broadcom SoC could simply reuse various drivers initially added
> for MIPS based Broadcom SoC's. So if someone wants to use your driver
> with a MIPS based Broadcom SoC in the future, likely some tweaking of
> the driver is required. But at least the basic cross-arch compatibility
> should be given.

Agreed. I am not sure if such a situation will ever arise in the future
because those MIPS-based chips are reasonably old now, and few if any
people have shown interest in using something different than CFE
(Broadcom's own boot loader) or their own third stage, but hey, someone
might see the light at some point :).
-- 
Florian


Re: [PATCH 1/3] net: Add support for Broadcom GENETv5 Ethernet controller

2019-12-20 Thread Stefan Wahren
Hi Andre,

Am 18.12.19 um 12:59 schrieb Andre Przywara:
> From: Amit Singh Tomar 
>
> The Broadcom GENET Ethernet MACs are used in several MIPS based SoCs
> and in the Broadcom 2711/2838 SoC used on the Raspberry Pi 4.
> There is no publicly available documentation, so this driver is based
> on the Linux driver. Compared to that the queue management is
> drastically simplified, also we only support version 5 of the IP and
> RGMII connections between MAC and PHY, as used on the RPi4.
>
> Signed-off-by: Amit Singh Tomar 
> Reviewed-by: Andre Przywara 
> [Andre: heavy cleanup and a few fixes]
> Signed-off-by: Andre Przywara 
> ---
>  drivers/net/Kconfig|   7 +
>  drivers/net/Makefile   |   1 +
>  drivers/net/bcmgenet.c | 702 +
>  3 files changed, 710 insertions(+)
>  create mode 100644 drivers/net/bcmgenet.c
>
...
> +
> +/* We only support RGMII (as used on the RPi4). */
> +static int bcmgenet_interface_set(struct bcmgenet_eth_priv *priv)
> +{
> + phy_interface_t phy_mode = priv->interface;
> +
> + switch (phy_mode) {
> + case PHY_INTERFACE_MODE_RGMII:
> + writel(PORT_MODE_EXT_GPHY, priv->mac_reg + SYS_PORT_CTRL);
> + break;

This doesn't match the current Linux upstream kernel / DTS. We consider
the PHY mode in the downstream DTS as wrong. It should be
PHY_INTERFACE_MODE_RGMII_RXID. So please add this to keep compatibility
to the upstream devicetree.

Please following this series [1] for more information.

Thank you a lot for this work

Stefan

[1] - https://marc.info/?l=linux-netdev&m=157350191805462&w=2


> + default:
> + printf("unknown phy mode: %d\n", priv->interface);
> + return -EINVAL;
> + }
> +
> + return 0;
> +}
> +




Re: [PATCH 1/3] net: Add support for Broadcom GENETv5 Ethernet controller

2019-12-20 Thread Andre Przywara
On Thu, 19 Dec 2019 13:58:24 +0100
Daniel Schwierzeck  wrote:

Hi Daniel,

> Am 19.12.19 um 12:42 schrieb Andre Przywara:
> > On Thu, 19 Dec 2019 12:32:06 +0100
> > Daniel Schwierzeck  wrote:
> > 
> > Hi Daniel,
> > 
> > many thanks for your valuable comments! Do you have access to a MIPS board 
> > using a GENETv5 MAC? I would be very curious to see if the driver works 
> > there, and am happy to make adjustments.  
> 
> No, I have not. I was only triggered by your commit message that this
> MAC is also used on some MIPS based Broadcom SoC's ;)

Well, actually I am not sure about it, I just saw *previous* generations (up to 
v3) used in MIPS .dts files in the kernel. Might as well be that v5 was never 
used with a MIPS core.
 
> > Does your board use a PHY connected via RGMII? Because this is something we 
> > are relying on at the moment. But without any ways of testing this I'd 
> > rather not support other transports at this time.
> > 
> > I think your points below are all valid, so thanks for bringing this up. 
> > Will test this later on and post a v2 in due time then.
> >   
> 
> We had a similar scenario a few months ago, where a newly supported ARM
> based Broadcom SoC could simply reuse various drivers initially added
> for MIPS based Broadcom SoC's. So if someone wants to use your driver
> with a MIPS based Broadcom SoC in the future, likely some tweaking of
> the driver is required. But at least the basic cross-arch compatibility
> should be given.

Yeah, and especially the fdt vs. ofnode comments were very justified.

One thing I was wondering about: on ARM the bus is always little-endian, 
regardless of the current CPU state. That's why we routinely use _le32 function 
for hardware accesses. A comment in the Linux driver[1] suggests that this is 
not the case for MIPS, do you know anything about it?
I used the native endian version as you suggested, as I am not aware that 
anyone is running U-Boot in BE on ARM.

So I addressed your comments already, you can have a look here [2] (top three 
commits).
I will try if I can fix some of the known shortcomings (PHY timeout etc) before 
posting a v2.

Cheers,
Andre.

[1] 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/net/ethernet/broadcom/genet/bcmgenet.c#n72
[2] https://github.com/apritzel/u-boot/commits/rpi4-eth


Re: [PATCH 1/3] net: Add support for Broadcom GENETv5 Ethernet controller

2019-12-19 Thread Matthias Brugger



On 18/12/2019 12:59, Andre Przywara wrote:
> From: Amit Singh Tomar 
> 
> The Broadcom GENET Ethernet MACs are used in several MIPS based SoCs
> and in the Broadcom 2711/2838 SoC used on the Raspberry Pi 4.
> There is no publicly available documentation, so this driver is based
> on the Linux driver. Compared to that the queue management is
> drastically simplified, also we only support version 5 of the IP and
> RGMII connections between MAC and PHY, as used on the RPi4.
> 
> Signed-off-by: Amit Singh Tomar 
> Reviewed-by: Andre Przywara 
> [Andre: heavy cleanup and a few fixes]
> Signed-off-by: Andre Przywara 

Tested-by: Matthias Brugger 

Thanks a lot.

Joe I suppose that this patch goes through your tree, please keep me in the
loop, I'll take patch 2 and 3 through my tree then.

Regards,
Matthias

> ---
>  drivers/net/Kconfig|   7 +
>  drivers/net/Makefile   |   1 +
>  drivers/net/bcmgenet.c | 702 +
>  3 files changed, 710 insertions(+)
>  create mode 100644 drivers/net/bcmgenet.c
> 
> diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
> index 142a2c6953..999714dd39 100644
> --- a/drivers/net/Kconfig
> +++ b/drivers/net/Kconfig
> @@ -136,6 +136,13 @@ config BCM6368_ETH
>   help
> This driver supports the BCM6368 Ethernet MAC.
>  
> +config BCMGENET
> + bool "BCMGENET V5 support"
> + depends on DM_ETH
> + select PHYLIB
> + help
> +   This driver supports the BCMGENET Ethernet MAC.
> +
>  config DWC_ETH_QOS
>   bool "Synopsys DWC Ethernet QOS device support"
>   depends on DM_ETH
> diff --git a/drivers/net/Makefile b/drivers/net/Makefile
> index 30991834ec..6e0a68834d 100644
> --- a/drivers/net/Makefile
> +++ b/drivers/net/Makefile
> @@ -8,6 +8,7 @@ obj-$(CONFIG_AG7XXX) += ag7xxx.o
>  obj-$(CONFIG_ARMADA100_FEC) += armada100_fec.o
>  obj-$(CONFIG_BCM6348_ETH) += bcm6348-eth.o
>  obj-$(CONFIG_BCM6368_ETH) += bcm6368-eth.o
> +obj-$(CONFIG_BCMGENET) += bcmgenet.o
>  obj-$(CONFIG_DRIVER_AT91EMAC) += at91_emac.o
>  obj-$(CONFIG_DRIVER_AX88180) += ax88180.o
>  obj-$(CONFIG_BCM_SF2_ETH) += bcm-sf2-eth.o
> diff --git a/drivers/net/bcmgenet.c b/drivers/net/bcmgenet.c
> new file mode 100644
> index 00..24b025d804
> --- /dev/null
> +++ b/drivers/net/bcmgenet.c
> @@ -0,0 +1,702 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Copyright (C) 2019 Amit Singh Tomar 
> + *
> + * Driver for Broadcom GENETv5 Ethernet controller (as found on the RPi4)
> + * This driver is based on the Linux driver:
> + *  drivers/net/ethernet/broadcom/genet/bcmgenet.c
> + *  which is: Copyright (c) 2014-2017 Broadcom
> + *
> + * The hardware supports multiple queues (16 priority queues and one
> + * default queue), both for RX and TX. There are 256 DMA descriptors (both
> + * for TX and RX), and they live in MMIO registers. The hardware allows
> + * assigning descriptor ranges to queues, but we choose the most simple 
> setup:
> + * All 256 descriptors are assigned to the default queue (#16).
> + * Also the Linux driver supports multiple generations of the MAC, whereas
> + * we only support v5, as used in the Raspberry Pi 4.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +/* Register definitions derived from Linux source */
> +#define SYS_REV_CTRL 0x00
> +
> +#define SYS_PORT_CTRL0x04
> +#define PORT_MODE_EXT_GPHY   3
> +
> +#define GENET_SYS_OFF0x
> +#define SYS_RBUF_FLUSH_CTRL  (GENET_SYS_OFF  + 0x08)
> +#define SYS_TBUF_FLUSH_CTRL  (GENET_SYS_OFF  + 0x0c)
> +
> +#define GENET_EXT_OFF0x0080
> +#define EXT_RGMII_OOB_CTRL   (GENET_EXT_OFF + 0x0c)
> +#define RGMII_LINK   BIT(4)
> +#define OOB_DISABLE  BIT(5)
> +#define RGMII_MODE_ENBIT(6)
> +#define ID_MODE_DIS  BIT(16)
> +
> +#define GENET_RBUF_OFF   0x0300
> +#define RBUF_TBUF_SIZE_CTRL  (GENET_RBUF_OFF + 0xb4)
> +#define RBUF_CTRL(GENET_RBUF_OFF + 0x00)
> +#define RBUF_ALIGN_2BBIT(1)
> +
> +#define GENET_UMAC_OFF   0x0800
> +#define UMAC_MIB_CTRL(GENET_UMAC_OFF + 0x580)
> +#define UMAC_MAX_FRAME_LEN   (GENET_UMAC_OFF + 0x014)
> +#define UMAC_MAC0(GENET_UMAC_OFF + 0x00c)
> +#define UMAC_MAC1(GENET_UMAC_OFF + 0x010)
> +#define UMAC_CMD (GENET_UMAC_OFF + 0x008)
> +#define MDIO_CMD (GENET_UMAC_OFF + 0x614)
> +#define UMAC_TX_FLUSH(GENET_UMAC_OFF + 0x334)
> +#define MDIO_START_BUSY  BIT(29)
> +#define MDIO_READ_FAIL   BIT(28)
> +#define MDIO_RD  

Re: [PATCH 1/3] net: Add support for Broadcom GENETv5 Ethernet controller

2019-12-19 Thread Daniel Schwierzeck
Hi Andre,

Am 19.12.19 um 12:42 schrieb Andre Przywara:
> On Thu, 19 Dec 2019 12:32:06 +0100
> Daniel Schwierzeck  wrote:
> 
> Hi Daniel,
> 
> many thanks for your valuable comments! Do you have access to a MIPS board 
> using a GENETv5 MAC? I would be very curious to see if the driver works 
> there, and am happy to make adjustments.

No, I have not. I was only triggered by your commit message that this
MAC is also used on some MIPS based Broadcom SoC's ;)

> Does your board use a PHY connected via RGMII? Because this is something we 
> are relying on at the moment. But without any ways of testing this I'd rather 
> not support other transports at this time.
> 
> I think your points below are all valid, so thanks for bringing this up. Will 
> test this later on and post a v2 in due time then.
> 

We had a similar scenario a few months ago, where a newly supported ARM
based Broadcom SoC could simply reuse various drivers initially added
for MIPS based Broadcom SoC's. So if someone wants to use your driver
with a MIPS based Broadcom SoC in the future, likely some tweaking of
the driver is required. But at least the basic cross-arch compatibility
should be given.

-- 
- Daniel


Re: [PATCH 1/3] net: Add support for Broadcom GENETv5 Ethernet controller

2019-12-19 Thread Andre Przywara
On Thu, 19 Dec 2019 12:32:06 +0100
Daniel Schwierzeck  wrote:

Hi Daniel,

many thanks for your valuable comments! Do you have access to a MIPS board 
using a GENETv5 MAC? I would be very curious to see if the driver works there, 
and am happy to make adjustments.
Does your board use a PHY connected via RGMII? Because this is something we are 
relying on at the moment. But without any ways of testing this I'd rather not 
support other transports at this time.

I think your points below are all valid, so thanks for bringing this up. Will 
test this later on and post a v2 in due time then.

Cheers,
Andre.

> Am 18.12.19 um 12:59 schrieb Andre Przywara:
> > From: Amit Singh Tomar 
> > 
> > The Broadcom GENET Ethernet MACs are used in several MIPS based SoCs
> > and in the Broadcom 2711/2838 SoC used on the Raspberry Pi 4.
> > There is no publicly available documentation, so this driver is based
> > on the Linux driver. Compared to that the queue management is
> > drastically simplified, also we only support version 5 of the IP and
> > RGMII connections between MAC and PHY, as used on the RPi4.
> > 
> > Signed-off-by: Amit Singh Tomar 
> > Reviewed-by: Andre Przywara 
> > [Andre: heavy cleanup and a few fixes]
> > Signed-off-by: Andre Przywara 
> > ---
> >  drivers/net/Kconfig|   7 +
> >  drivers/net/Makefile   |   1 +
> >  drivers/net/bcmgenet.c | 702 +
> >  3 files changed, 710 insertions(+)
> >  create mode 100644 drivers/net/bcmgenet.c
> > 
> > diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
> > index 142a2c6953..999714dd39 100644
> > --- a/drivers/net/Kconfig
> > +++ b/drivers/net/Kconfig
> > @@ -136,6 +136,13 @@ config BCM6368_ETH
> > help
> >   This driver supports the BCM6368 Ethernet MAC.
> >  
> > +config BCMGENET
> > +   bool "BCMGENET V5 support"
> > +   depends on DM_ETH
> > +   select PHYLIB
> > +   help
> > + This driver supports the BCMGENET Ethernet MAC.
> > +
> >  config DWC_ETH_QOS
> > bool "Synopsys DWC Ethernet QOS device support"
> > depends on DM_ETH
> > diff --git a/drivers/net/Makefile b/drivers/net/Makefile
> > index 30991834ec..6e0a68834d 100644
> > --- a/drivers/net/Makefile
> > +++ b/drivers/net/Makefile
> > @@ -8,6 +8,7 @@ obj-$(CONFIG_AG7XXX) += ag7xxx.o
> >  obj-$(CONFIG_ARMADA100_FEC) += armada100_fec.o
> >  obj-$(CONFIG_BCM6348_ETH) += bcm6348-eth.o
> >  obj-$(CONFIG_BCM6368_ETH) += bcm6368-eth.o
> > +obj-$(CONFIG_BCMGENET) += bcmgenet.o
> >  obj-$(CONFIG_DRIVER_AT91EMAC) += at91_emac.o
> >  obj-$(CONFIG_DRIVER_AX88180) += ax88180.o
> >  obj-$(CONFIG_BCM_SF2_ETH) += bcm-sf2-eth.o
> > diff --git a/drivers/net/bcmgenet.c b/drivers/net/bcmgenet.c
> > new file mode 100644
> > index 00..24b025d804
> > --- /dev/null
> > +++ b/drivers/net/bcmgenet.c
> > @@ -0,0 +1,702 @@
> > +// SPDX-License-Identifier: GPL-2.0+
> > +/*
> > + * Copyright (C) 2019 Amit Singh Tomar 
> > + *
> > + * Driver for Broadcom GENETv5 Ethernet controller (as found on the RPi4)
> > + * This driver is based on the Linux driver:
> > + *  drivers/net/ethernet/broadcom/genet/bcmgenet.c
> > + *  which is: Copyright (c) 2014-2017 Broadcom
> > + *
> > + * The hardware supports multiple queues (16 priority queues and one
> > + * default queue), both for RX and TX. There are 256 DMA descriptors (both
> > + * for TX and RX), and they live in MMIO registers. The hardware allows
> > + * assigning descriptor ranges to queues, but we choose the most simple 
> > setup:
> > + * All 256 descriptors are assigned to the default queue (#16).
> > + * Also the Linux driver supports multiple generations of the MAC, whereas
> > + * we only support v5, as used in the Raspberry Pi 4.
> > + */
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +/* Register definitions derived from Linux source */
> > +#define SYS_REV_CTRL   0x00
> > +
> > +#define SYS_PORT_CTRL  0x04
> > +#define PORT_MODE_EXT_GPHY 3
> > +
> > +#define GENET_SYS_OFF  0x
> > +#define SYS_RBUF_FLUSH_CTRL(GENET_SYS_OFF  + 0x08)
> > +#define SYS_TBUF_FLUSH_CTRL(GENET_SYS_OFF  + 0x0c)
> > +
> > +#define GENET_EXT_OFF  0x0080
> > +#define EXT_RGMII_OOB_CTRL (GENET_EXT_OFF + 0x0c)
> > +#define RGMII_LINK BIT(4)
> > +#define OOB_DISABLEBIT(5)
> > +#define RGMII_MODE_EN  BIT(6)
> > +#define ID_MODE_DISBIT(16)
> > +
> > +#define GENET_RBUF_OFF 0x0300
> > +#define RBUF_TBUF_SIZE_CTRL(GENET_RBUF_OFF + 0xb4)
> > +#define RBUF_CTRL  (GENET_RBUF_OFF + 0x00)
> > +#define RBUF_ALIGN_2B  BIT(1)
> > +
> > +#define GENET_UMAC_OFF

Re: [PATCH 1/3] net: Add support for Broadcom GENETv5 Ethernet controller

2019-12-19 Thread Daniel Schwierzeck



Am 18.12.19 um 12:59 schrieb Andre Przywara:
> From: Amit Singh Tomar 
> 
> The Broadcom GENET Ethernet MACs are used in several MIPS based SoCs
> and in the Broadcom 2711/2838 SoC used on the Raspberry Pi 4.
> There is no publicly available documentation, so this driver is based
> on the Linux driver. Compared to that the queue management is
> drastically simplified, also we only support version 5 of the IP and
> RGMII connections between MAC and PHY, as used on the RPi4.
> 
> Signed-off-by: Amit Singh Tomar 
> Reviewed-by: Andre Przywara 
> [Andre: heavy cleanup and a few fixes]
> Signed-off-by: Andre Przywara 
> ---
>  drivers/net/Kconfig|   7 +
>  drivers/net/Makefile   |   1 +
>  drivers/net/bcmgenet.c | 702 +
>  3 files changed, 710 insertions(+)
>  create mode 100644 drivers/net/bcmgenet.c
> 
> diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
> index 142a2c6953..999714dd39 100644
> --- a/drivers/net/Kconfig
> +++ b/drivers/net/Kconfig
> @@ -136,6 +136,13 @@ config BCM6368_ETH
>   help
> This driver supports the BCM6368 Ethernet MAC.
>  
> +config BCMGENET
> + bool "BCMGENET V5 support"
> + depends on DM_ETH
> + select PHYLIB
> + help
> +   This driver supports the BCMGENET Ethernet MAC.
> +
>  config DWC_ETH_QOS
>   bool "Synopsys DWC Ethernet QOS device support"
>   depends on DM_ETH
> diff --git a/drivers/net/Makefile b/drivers/net/Makefile
> index 30991834ec..6e0a68834d 100644
> --- a/drivers/net/Makefile
> +++ b/drivers/net/Makefile
> @@ -8,6 +8,7 @@ obj-$(CONFIG_AG7XXX) += ag7xxx.o
>  obj-$(CONFIG_ARMADA100_FEC) += armada100_fec.o
>  obj-$(CONFIG_BCM6348_ETH) += bcm6348-eth.o
>  obj-$(CONFIG_BCM6368_ETH) += bcm6368-eth.o
> +obj-$(CONFIG_BCMGENET) += bcmgenet.o
>  obj-$(CONFIG_DRIVER_AT91EMAC) += at91_emac.o
>  obj-$(CONFIG_DRIVER_AX88180) += ax88180.o
>  obj-$(CONFIG_BCM_SF2_ETH) += bcm-sf2-eth.o
> diff --git a/drivers/net/bcmgenet.c b/drivers/net/bcmgenet.c
> new file mode 100644
> index 00..24b025d804
> --- /dev/null
> +++ b/drivers/net/bcmgenet.c
> @@ -0,0 +1,702 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Copyright (C) 2019 Amit Singh Tomar 
> + *
> + * Driver for Broadcom GENETv5 Ethernet controller (as found on the RPi4)
> + * This driver is based on the Linux driver:
> + *  drivers/net/ethernet/broadcom/genet/bcmgenet.c
> + *  which is: Copyright (c) 2014-2017 Broadcom
> + *
> + * The hardware supports multiple queues (16 priority queues and one
> + * default queue), both for RX and TX. There are 256 DMA descriptors (both
> + * for TX and RX), and they live in MMIO registers. The hardware allows
> + * assigning descriptor ranges to queues, but we choose the most simple 
> setup:
> + * All 256 descriptors are assigned to the default queue (#16).
> + * Also the Linux driver supports multiple generations of the MAC, whereas
> + * we only support v5, as used in the Raspberry Pi 4.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +/* Register definitions derived from Linux source */
> +#define SYS_REV_CTRL 0x00
> +
> +#define SYS_PORT_CTRL0x04
> +#define PORT_MODE_EXT_GPHY   3
> +
> +#define GENET_SYS_OFF0x
> +#define SYS_RBUF_FLUSH_CTRL  (GENET_SYS_OFF  + 0x08)
> +#define SYS_TBUF_FLUSH_CTRL  (GENET_SYS_OFF  + 0x0c)
> +
> +#define GENET_EXT_OFF0x0080
> +#define EXT_RGMII_OOB_CTRL   (GENET_EXT_OFF + 0x0c)
> +#define RGMII_LINK   BIT(4)
> +#define OOB_DISABLE  BIT(5)
> +#define RGMII_MODE_ENBIT(6)
> +#define ID_MODE_DIS  BIT(16)
> +
> +#define GENET_RBUF_OFF   0x0300
> +#define RBUF_TBUF_SIZE_CTRL  (GENET_RBUF_OFF + 0xb4)
> +#define RBUF_CTRL(GENET_RBUF_OFF + 0x00)
> +#define RBUF_ALIGN_2BBIT(1)
> +
> +#define GENET_UMAC_OFF   0x0800
> +#define UMAC_MIB_CTRL(GENET_UMAC_OFF + 0x580)
> +#define UMAC_MAX_FRAME_LEN   (GENET_UMAC_OFF + 0x014)
> +#define UMAC_MAC0(GENET_UMAC_OFF + 0x00c)
> +#define UMAC_MAC1(GENET_UMAC_OFF + 0x010)
> +#define UMAC_CMD (GENET_UMAC_OFF + 0x008)
> +#define MDIO_CMD (GENET_UMAC_OFF + 0x614)
> +#define UMAC_TX_FLUSH(GENET_UMAC_OFF + 0x334)
> +#define MDIO_START_BUSY  BIT(29)
> +#define MDIO_READ_FAIL   BIT(28)
> +#define MDIO_RD  (2 << 26)
> +#define MDIO_WR  BIT(26)
> +#define MDIO_PMD_SHIFT   21
> +#define MDIO_PMD_MASK0x1f
> +#define MDI

[PATCH 1/3] net: Add support for Broadcom GENETv5 Ethernet controller

2019-12-18 Thread Andre Przywara
From: Amit Singh Tomar 

The Broadcom GENET Ethernet MACs are used in several MIPS based SoCs
and in the Broadcom 2711/2838 SoC used on the Raspberry Pi 4.
There is no publicly available documentation, so this driver is based
on the Linux driver. Compared to that the queue management is
drastically simplified, also we only support version 5 of the IP and
RGMII connections between MAC and PHY, as used on the RPi4.

Signed-off-by: Amit Singh Tomar 
Reviewed-by: Andre Przywara 
[Andre: heavy cleanup and a few fixes]
Signed-off-by: Andre Przywara 
---
 drivers/net/Kconfig|   7 +
 drivers/net/Makefile   |   1 +
 drivers/net/bcmgenet.c | 702 +
 3 files changed, 710 insertions(+)
 create mode 100644 drivers/net/bcmgenet.c

diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index 142a2c6953..999714dd39 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -136,6 +136,13 @@ config BCM6368_ETH
help
  This driver supports the BCM6368 Ethernet MAC.
 
+config BCMGENET
+   bool "BCMGENET V5 support"
+   depends on DM_ETH
+   select PHYLIB
+   help
+ This driver supports the BCMGENET Ethernet MAC.
+
 config DWC_ETH_QOS
bool "Synopsys DWC Ethernet QOS device support"
depends on DM_ETH
diff --git a/drivers/net/Makefile b/drivers/net/Makefile
index 30991834ec..6e0a68834d 100644
--- a/drivers/net/Makefile
+++ b/drivers/net/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_AG7XXX) += ag7xxx.o
 obj-$(CONFIG_ARMADA100_FEC) += armada100_fec.o
 obj-$(CONFIG_BCM6348_ETH) += bcm6348-eth.o
 obj-$(CONFIG_BCM6368_ETH) += bcm6368-eth.o
+obj-$(CONFIG_BCMGENET) += bcmgenet.o
 obj-$(CONFIG_DRIVER_AT91EMAC) += at91_emac.o
 obj-$(CONFIG_DRIVER_AX88180) += ax88180.o
 obj-$(CONFIG_BCM_SF2_ETH) += bcm-sf2-eth.o
diff --git a/drivers/net/bcmgenet.c b/drivers/net/bcmgenet.c
new file mode 100644
index 00..24b025d804
--- /dev/null
+++ b/drivers/net/bcmgenet.c
@@ -0,0 +1,702 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2019 Amit Singh Tomar 
+ *
+ * Driver for Broadcom GENETv5 Ethernet controller (as found on the RPi4)
+ * This driver is based on the Linux driver:
+ *  drivers/net/ethernet/broadcom/genet/bcmgenet.c
+ *  which is: Copyright (c) 2014-2017 Broadcom
+ *
+ * The hardware supports multiple queues (16 priority queues and one
+ * default queue), both for RX and TX. There are 256 DMA descriptors (both
+ * for TX and RX), and they live in MMIO registers. The hardware allows
+ * assigning descriptor ranges to queues, but we choose the most simple setup:
+ * All 256 descriptors are assigned to the default queue (#16).
+ * Also the Linux driver supports multiple generations of the MAC, whereas
+ * we only support v5, as used in the Raspberry Pi 4.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* Register definitions derived from Linux source */
+#define SYS_REV_CTRL   0x00
+
+#define SYS_PORT_CTRL  0x04
+#define PORT_MODE_EXT_GPHY 3
+
+#define GENET_SYS_OFF  0x
+#define SYS_RBUF_FLUSH_CTRL(GENET_SYS_OFF  + 0x08)
+#define SYS_TBUF_FLUSH_CTRL(GENET_SYS_OFF  + 0x0c)
+
+#define GENET_EXT_OFF  0x0080
+#define EXT_RGMII_OOB_CTRL (GENET_EXT_OFF + 0x0c)
+#define RGMII_LINK BIT(4)
+#define OOB_DISABLEBIT(5)
+#define RGMII_MODE_EN  BIT(6)
+#define ID_MODE_DISBIT(16)
+
+#define GENET_RBUF_OFF 0x0300
+#define RBUF_TBUF_SIZE_CTRL(GENET_RBUF_OFF + 0xb4)
+#define RBUF_CTRL  (GENET_RBUF_OFF + 0x00)
+#define RBUF_ALIGN_2B  BIT(1)
+
+#define GENET_UMAC_OFF 0x0800
+#define UMAC_MIB_CTRL  (GENET_UMAC_OFF + 0x580)
+#define UMAC_MAX_FRAME_LEN (GENET_UMAC_OFF + 0x014)
+#define UMAC_MAC0  (GENET_UMAC_OFF + 0x00c)
+#define UMAC_MAC1  (GENET_UMAC_OFF + 0x010)
+#define UMAC_CMD   (GENET_UMAC_OFF + 0x008)
+#define MDIO_CMD   (GENET_UMAC_OFF + 0x614)
+#define UMAC_TX_FLUSH  (GENET_UMAC_OFF + 0x334)
+#define MDIO_START_BUSYBIT(29)
+#define MDIO_READ_FAIL BIT(28)
+#define MDIO_RD(2 << 26)
+#define MDIO_WRBIT(26)
+#define MDIO_PMD_SHIFT 21
+#define MDIO_PMD_MASK  0x1f
+#define MDIO_REG_SHIFT 16
+#define MDIO_REG_MASK  0x1f
+
+#define CMD_TX_EN  BIT(0)
+#define CMD_RX_EN  BIT(1)
+#define UMAC_SPEED_10  0
+#define UMAC_SPEED_100 1
+#define UMAC_SPEED_10002
+#define UMAC_SPE