Skip to content

Conversation

@IanSeyler
Copy link
Member

This pull request significantly refactors the VirtIO network driver to support multiple network interfaces and improve descriptor management. The changes replace the use of global/static variables with per-interface data structures, update how descriptor tables and rings are managed, and streamline packet transmit/receive logic for better correctness and maintainability.

Key improvements and refactoring:

Per-Interface Data Management:

  • Replaced global variables (such as os_net_mem, netrxdescindex, nettxdescindex, etc.) with per-interface fields accessed via offsets from an interface structure (using r8/rdx and offsets like nt_rx_desc, nt_tx_desc, etc.), enabling support for multiple network interfaces and eliminating shared state. [1] [2] [3] [4] [5] [6] [7] [8]

Descriptor Table and Ring Handling:

  • Updated initialization routines to use per-interface descriptor table addresses, and improved how RX/TX descriptor rings are populated and managed. This includes new logic for resetting, populating, and wrapping descriptor indices and handling the available and used rings per interface. [1] [2] [3] [4] [5] [6] [7]

Transmit and Receive Logic:

  • Refactored net_virtio_transmit and net_virtio_poll to use per-interface descriptor tables and indices, improved ring index management, and ensured correct address calculations for packet data. Also, improved handling of the used/available rings for packet transmission and reception, including proper wrap-around of indices. [1] [2] [3]

Cleanup and Removal of Global State:

  • Removed global/static variables related to descriptor and ring indices (netrxdescindex, netrxavailindex, nettxdescindex, nettxavailindex), as these are now managed per interface.

General Code Organization and Comments:

  • Improved comments and code organization, clarified TODOs, and commented out obsolete or now-redundant code sections related to old assumptions (e.g., fixed 256 entries).

These changes make the VirtIO network driver more robust, modular, and ready for environments with multiple network devices.

Ian Seyler added 7 commits September 23, 2025 15:55
- make use of the addresses set aside by `net_virtio_init`
Redo `net_virtio_poll` to gather packet location from descriptor entry, with no `movsb` - Only accepts single packet at the moment.
@IanSeyler IanSeyler self-assigned this Sep 26, 2025
@IanSeyler IanSeyler merged commit fab4363 into master Sep 26, 2025
6 checks passed
@IanSeyler IanSeyler deleted the virtio-net-rewrite branch September 26, 2025 19:01
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.

2 participants