bcmgenet: fix DMA buffer management 61/245361/1 accepted/tizen/6.0/unified/20201030.105045 accepted/tizen/6.0/unified/hotfix/20201102.235414 accepted/tizen/unified/20201008.043022 submit/tizen/20201008.021146 submit/tizen_6.0/20201029.205501 submit/tizen_6.0_hotfix/20201102.192901 submit/tizen_6.0_hotfix/20201103.115101 tizen_6.0.m2_release
authorJason Wessel <jason.wessel@windriver.com>
Fri, 17 Jul 2020 13:31:59 +0000 (06:31 -0700)
committerMarek Szyprowski <m.szyprowski@samsung.com>
Fri, 2 Oct 2020 11:30:59 +0000 (13:30 +0200)
commitf34dfbd774c2182a7818cd464f96269c463442cd
treeaee4cfbba53db815e341ebca31ef733be6b344c3
parent426ab963e5e582504b428e2c9b936ed924a90716
bcmgenet: fix DMA buffer management

This commit fixes a serious issue occurring when several network
commands are run on a raspberry pi 4 board: for instance a "dhcp"
command and then one or several "tftp" commands. In this case,
packet recv callbacks were called several times on the same packets,
and send function was failing most of the time.

note: if the boot procedure is made of a single network
command, the issue is not visible.

The issue is related to management of the packet ring buffers
(producer / consumer) and DMA.
Each time a packet is received, the ethernet device stores it
in the buffer and increments an index called RDMA_PROD_INDEX.
Each time the driver outputs a received packet, it increments
another index called RDMA_CONS_INDEX.

Between each pair of network commands, as part of the driver
'start' function, previous code tried to reset both RDMA_CONS_INDEX
and RDMA_PROD_INDEX to 0. But RDMA_PROD_INDEX cannot be written from
driver side, thus its value was actually not updated, and only
RDMA_CONS_INDEX was reset to 0. This was resulting in a major
synchronization issue between the driver and the device. Most
visible behavior was that the driver seemed to receive again the
packets from the previous commands (e.g. DHCP response packets
"received" again when performing the first TFTP command).

This fix consists in setting RDMA_CONS_INDEX to the same
value as RDMA_PROD_INDEX, when resetting the driver.

The same kind of fix was needed on the TX side, and a few variables
had to be reset accordingly (c_index, tx_index, rx_index).

The rx_index and tx_index have only 256 entries so the bottom 8 bits
must be masked off.

Originated-by: Etienne Dublé <etienne.duble@imag.fr>
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Tested-by: Petr Tesarik <ptesarik@suse.com>
Signed-off-by: Matthias Brugger <mbrugger@suse.com>
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Change-Id: Ia7c66c3957f1c6b5f104bf621ddef87402921da6
[backport of mainline commit ac458dc823de95e05e433d7645b960f8c6088f55]
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
drivers/net/bcmgenet.c