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

Add e1000 driver #337

Merged
merged 61 commits into from
Apr 8, 2024
Merged

Add e1000 driver #337

merged 61 commits into from
Apr 8, 2024

Conversation

vinc
Copy link
Owner

@vinc vinc commented May 7, 2022

Driver for the Intel PRO/1000 network card family. Tested on the following hardware:

  • Intel PRO/1000 (QEMU, VirtualBox, PC)
  • Intel 82567LM (ThinkPad X200, Dell Latitude E6400)
  • Intel I217-LM (ThinkPad T440p)
  • Intel I219-LM (ThinkPad T480)

References:

@vinc vinc closed this Aug 7, 2022
@vinc vinc deleted the feature/e1000-network-card branch August 7, 2022 07:55
@vinc vinc restored the feature/e1000-network-card branch August 7, 2022 08:02
@vinc vinc reopened this Aug 7, 2022
@vinc vinc changed the title Add e1000 network card support Add e1000 driver Mar 25, 2024
@vinc
Copy link
Owner Author

vinc commented Mar 26, 2024

Some progress on the last commit but nothing is working yet:

  • When the card receive a packet sent from the host we can see it because the ICR register become 0x80 instead of 0x00 or 0x02 usually. But nothing is written to the descriptors or the buffers.
  • When we try to send a packet we can see that the card zero the descriptor before the next tentative but nothing is actually sent.

The OS is run with make qemu output=serial nic=e1000 kvm=true pcap=true and the host can do curl http://localhost:8080 to send a packet or tcpdump -r /tmp/qemu.pcap to read what happened on the network.

I'm using PCI/PCI-X Family of Gigabit Ethernet Controllers Software Developer’s Manual and code sample from osdev.org to try to grok it.

@vinc
Copy link
Owner Author

vinc commented Mar 27, 2024

I found the issue last night, the addresses of the descriptors were changing when the device was cloned so the solution is to wrap them around an Arc and a Mutex and now I can see incoming packets. I was thinking that the device was zeroing TxDesc but that was not the case, it was just a new array of descriptors every time, pointing to the same physical buffers. I figured that out when I added a loop at the end of the transmission to watch the descriptor being changed and it would never happen.

@vinc
Copy link
Owner Author

vinc commented Mar 27, 2024

~
> net config debug true

~
> dhcp
DEBUG: NET Packet Transmitted
00000000: FFFF FFFF FFFF 5254 0012 3456 0800 4500 ......RT..4V..E.
00000010: 0122 0000 4000 4011 39CC 0000 0000 FFFF ."..@.@.9.......
00000020: FFFF 0044 0043 010E 808B 0101 0600 FDEC ...D.C..........
00000030: F8A2 0000 0000 0000 0000 0000 0000 0000 ................
00000040: 0000 0000 0000 5254 0012 3456 0000 0000 ......RT..4V....
00000050: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000060: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000070: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000080: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000090: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000A0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000B0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000C0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000D0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000E0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000F0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000100: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000110: 0000 0000 0000 6382 5363 3501 013D 0701 ......c.Sc5..=..
00000120: 5254 0012 3456 3902 058A 3703 0103 06FF RT..4V9...7.....
DEBUG: NET Packet Received
00000000: FFFF FFFF FFFF 5255 0A00 0202 0800 4510 ......RU......E.
00000010: 0240 0003 0000 4011 6C99 0A00 0202 FFFF .@....@.l.......
00000020: FFFF 0043 0044 022C C4E1 0201 0600 FDEC ...C.D.,........
00000030: F8A2 0000 0000 0000 0000 0A00 020F 0A00 ................
00000040: 0202 0000 0000 5254 0012 3456 0000 0000 ......RT..4V....
00000050: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000060: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000070: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000080: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000090: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000A0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000B0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000C0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000D0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000E0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000F0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000100: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000110: 0000 0000 0000 6382 5363 3501 0236 040A ......c.Sc5..6..
00000120: 0002 0201 04FF FFFF 0003 040A 0002 0206 ................
00000130: 040A 0002 0333 0400 0151 80FF 0000 0000 .....3...Q......
00000140: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000150: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000160: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000170: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000180: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000190: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000001A0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000001B0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000001C0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000001D0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000001E0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000001F0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000200: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000210: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000220: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000230: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000240: 0000 0000 0000 0000 0000 0000 0000      ..............
DEBUG: NET Packet Transmitted
00000000: FFFF FFFF FFFF 5254 0012 3456 0800 4500 ......RT..4V..E.
00000010: 012E 0000 4000 4011 39C0 0000 0000 FFFF ....@.@.9.......
00000020: FFFF 0044 0043 011A D4F5 0101 0600 6130 ...D.C........a0
00000030: BEC3 0000 0000 0000 0000 0000 0000 0000 ................
00000040: 0000 0000 0000 5254 0012 3456 0000 0000 ......RT..4V....
00000050: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000060: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000070: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000080: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000090: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000A0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000B0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000C0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000D0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000E0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000F0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000100: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000110: 0000 0000 0000 6382 5363 3501 033D 0701 ......c.Sc5..=..
00000120: 5254 0012 3456 3604 0A00 0202 3204 0A00 RT..4V6.....2...
00000130: 020F 3902 058A 3703 0103 06FF           ..9...7.....
DEBUG: NET Packet Received
00000000: FFFF FFFF FFFF 5255 0A00 0202 0800 4510 ......RU......E.
00000010: 0240 0004 0000 4011 6C98 0A00 0202 FFFF .@....@.l.......
00000020: FFFF 0043 0044 022C 987D 0201 0600 6130 ...C.D.,.}....a0
00000030: BEC3 0000 0000 0000 0000 0A00 020F 0A00 ................
00000040: 0202 0000 0000 5254 0012 3456 0000 0000 ......RT..4V....
00000050: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000060: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000070: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000080: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000090: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000A0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000B0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000C0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000D0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000E0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000F0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000100: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000110: 0000 0000 0000 6382 5363 3501 0536 040A ......c.Sc5..6..
00000120: 0002 0201 04FF FFFF 0003 040A 0002 0206 ................
00000130: 040A 0002 0333 0400 0151 80FF 0000 0000 .....3...Q......
00000140: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000150: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000160: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000170: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000180: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000190: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000001A0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000001B0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000001C0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000001D0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000001E0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000001F0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000200: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000210: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000220: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000230: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000240: 0000 0000 0000 0000 0000 0000 0000      ..............
ip:  10.0.2.15/24
gw:  10.0.2.2
dns: 10.0.2.3

@vinc
Copy link
Owner Author

vinc commented Apr 2, 2024

I got some pretty good performance on my old ThinkPad X200 running httpd -d /var/www:

$ siege --no-parser http://x200.moros.lan -c 8 -t 30s -b
** SIEGE 4.1.6
** Preparing 8 concurrent users for battle.
The server is now under siege...
HTTP/1.1 200     0.00 secs:     273 bytes ==> GET  /
HTTP/1.1 200     0.00 secs:     273 bytes ==> GET  /
HTTP/1.1 200     0.01 secs:     273 bytes ==> GET  /
HTTP/1.1 200     0.01 secs:     273 bytes ==> GET  /
HTTP/1.1 200     0.01 secs:     273 bytes ==> GET  /
HTTP/1.1 200     0.01 secs:     273 bytes ==> GET  /
HTTP/1.1 200     0.01 secs:     273 bytes ==> GET  /
HTTP/1.1 200     0.01 secs:     273 bytes ==> GET  /
HTTP/1.1 200     0.01 secs:     273 bytes ==> GET  /
HTTP/1.1 200     0.01 secs:     273 bytes ==> GET  /
HTTP/1.1 200     0.01 secs:     273 bytes ==> GET  /
HTTP/1.1 200     0.01 secs:     273 bytes ==> GET  /
HTTP/1.1 200     0.01 secs:     273 bytes ==> GET  /
HTTP/1.1 200     0.01 secs:     273 bytes ==> GET  /
HTTP/1.1 200     0.01 secs:     273 bytes ==> GET  /
HTTP/1.1 200     0.01 secs:     273 bytes ==> GET  /
[...]

Lifting the server siege...
Transactions:		       29609 hits
Availability:		       99.97 %
Elapsed time:		       30.40 secs
Data transferred:	       17.42 MB
Response time:		        0.01 secs
Transaction rate:	      973.98 trans/sec
Throughput:		        0.57 MB/sec
Concurrency:		        7.36
Successful transactions:       29609
Failed transactions:	           9
Longest transaction:	        7.22
Shortest transaction:	        0.00

@vinc vinc mentioned this pull request Apr 2, 2024
@vinc
Copy link
Owner Author

vinc commented Apr 4, 2024

Hardware tests so far:

  • Intel PRO/1000 GT
  • Intel 82567LM (ThinkPad X200, Dell Latitude E6400)
  • Intel I217-LM (ThinkPad T440p)

The net monitor command works on the ThinkPad T440p but dhcp doesn't.

@vinc
Copy link
Owner Author

vinc commented Apr 5, 2024

The driver now work for the Intel I217-LM of a ThinkPad T440p but I also tested it without success on the Intel I219-LM of a ThinkPad T480. The TCTL_MULR bit need to be set during transmit initialization for the I217-LM to work.

@vinc
Copy link
Owner Author

vinc commented Apr 6, 2024

The driver works well on VirtualBox with the various Intel PRO/1000 cards!

@vinc vinc marked this pull request as ready for review April 6, 2024 13:59
@vinc
Copy link
Owner Author

vinc commented Apr 6, 2024

I tested the driver on one of my old Lenovo ThinkCentre M83 SFF which makes it a great inexpensive desktop target for MOROS.

@vinc
Copy link
Owner Author

vinc commented Apr 7, 2024

Doing self.write(REG_IMS, ICR_LSC | ICR_RXDMT0 | ICR_RXT0) makes my ThinkPad T440p hang during boot after network init but not my ThinkPad X200. We don't need interrupts right now so we can just do self.write(REG_IMS, 0) and keep the code for when they will be needed.

@vinc vinc merged commit 2b91c9c into trunk Apr 8, 2024
1 check passed
@vinc vinc deleted the feature/e1000-network-card branch April 8, 2024 13:23
@vinc vinc mentioned this pull request Jun 18, 2024
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