Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[draft] Add CompositeEMAC and use it to rewrite STM32 Ethernet MAC driver #438

Open
wants to merge 22 commits into
base: master
Choose a base branch
from

Conversation

multiplemonomials
Copy link
Collaborator

Summary of changes

This PR introduces a new framework for writing Ethernet MAC drivers. The existing EMAC interface requires MAC drivers to implement quite a lot of the specifics of memory management, MAC address tracking, and DMA themselves, even though quite a bit of this logic is common to all MAC drivers. This has led to duplicated code, and quite often to half-assed code as well as chip vendors have struggled to conform to the (admittedly not very well defined) EMAC API.

CompositeEMAC should make this a thing of the past. It's a class which implements the EMAC API and delegates its duties to four subclasses:

  • A MAC peripheral driver
  • A Tx DMA ring driver
  • An Rx DMA ring driver
  • A PHY driver

The first three of those classes are provided by the chip-specific EMAC driver, while the fourth comes from a library of PHY drivers and is not MCU specific. But this way most of the tough logic can be done in the non-MCU-specific layer, and all that needs to be done on a per-MCU basis is writing the low level MAC driver and low level code to interact with Ethernet descriptors.

Impact of changes

  • Ethernet support added for STM32H5
  • Significant Ethernet speed improvement for STM32H7: MAC no longer blocks while packets are being sent
  • Also, data cache no longer gets disabled when you use Ethernet on STM32H7. Apparently someone just made the driver globally disable the cache to fix a bug...
  • Zero-copy Ethernet support for STM32 devices, so small packets can be received with less wasted memory and large packets can be received with no copying
  • Generic PHY driver system allows any PHY supported by Mbed to be used with any MCU. Previously the PHY was hardcoded into the EMAC driver, so you had to use that exact model of PHY.

Migration actions required

Documentation


Pull request type

[] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

[] No Tests required for this change (E.g docs only update)
[] Covered by existing mbed-os tests (Greentea or Unittest)
[] Tests / results supplied as part of this PR

@multiplemonomials multiplemonomials force-pushed the dev/emac-test-improvements branch from d17f6ab to 404fdd4 Compare February 20, 2025 03:42
Base automatically changed from dev/emac-test-improvements to master February 20, 2025 04:00
Make progress on driver

More progress, but I realized that I can't free packets from an ISR...

Driver building, now I can start testing...

Add CompositeEthMac

MAC boots and can send!  Rx not working yet though

Sending and receiving sort of working!

Clean up CTP code to use structs

Fix dumb cache and off by one issues with Rx

Fix a couple memory issues, making progress...

Fix double free when transmission uses more than 1 descriptor

Start adding multicast support

Making progress on multicast support

Multicast filter working!

Tests passing!

Improve mcast filter test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant