Skip to content

Commit 1a255f6

Browse files
author
Ian Seyler
committed
Set TX and RX descriptors per interface
1 parent e0f4473 commit 1a255f6

File tree

2 files changed

+36
-13
lines changed

2 files changed

+36
-13
lines changed

src/drivers/net/i8254x.asm

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,19 @@ net_i8254x_init:
5858
shr eax, 8
5959
stosb
6060

61+
; Set base addresses for TX and RX descriptors
62+
xor ecx, ecx
63+
mov cl, byte [os_net_icount]
64+
shl ecx, 15
65+
66+
add rdi, 0x22
67+
mov rax, os_tx_desc
68+
add rax, rcx
69+
stosq
70+
mov rax, os_rx_desc
71+
add rax, rcx
72+
stosq
73+
6174
; Reset the device
6275
xor edx, edx
6376
mov dl, [os_net_icount]
@@ -141,8 +154,11 @@ net_i8254x_reset:
141154
; Create RX descriptors
142155
push rdi
143156
mov ecx, i8254x_MAX_DESC
144-
; TODO - Adjust value based on iid
157+
xor eax, eax
158+
mov al, byte [os_net_icount]
159+
shl eax, 15
145160
mov rdi, os_rx_desc
161+
add rdi, rax
146162
net_i8254x_reset_nextdesc:
147163
mov rax, os_PacketBuffers ; Default packet will go here
148164
stosq
@@ -153,8 +169,10 @@ net_i8254x_reset_nextdesc:
153169
pop rdi
154170

155171
; Initialize receive
156-
; TODO - Adjust value based on iid
157-
mov rax, os_rx_desc
172+
xor eax, eax
173+
mov al, byte [os_net_icount]
174+
shl eax, 15
175+
add rax, os_rx_desc
158176
mov [rsi+i8254x_RDBAL], eax ; Receive Descriptor Base Address Low
159177
shr rax, 32
160178
mov [rsi+i8254x_RDBAH], eax ; Receive Descriptor Base Address High
@@ -168,8 +186,10 @@ net_i8254x_reset_nextdesc:
168186
mov [rsi+i8254x_RCTL], eax ; Receive Control Register
169187

170188
; Initialize transmit
171-
; TODO - Adjust value based on iid
172-
mov rax, os_tx_desc
189+
xor eax, eax
190+
mov al, byte [os_net_icount]
191+
shl eax, 15
192+
add rax, os_tx_desc
173193
mov [rsi+i8254x_TDBAL], eax ; Transmit Descriptor Base Address Low
174194
shr rax, 32
175195
mov [rsi+i8254x_TDBAH], eax ; Transmit Descriptor Base Address High
@@ -217,7 +237,7 @@ net_i8254x_transmit:
217237
push rdi
218238
push rax
219239

220-
mov rdi, os_tx_desc ; Transmit Descriptor Base Address
240+
mov rdi, [rdx+nt_tx_desc] ; Transmit Descriptor Base Address
221241

222242
; Calculate the descriptor to write to
223243
mov eax, [rdx+nt_tx_head] ; Get tx_lasttail
@@ -267,7 +287,7 @@ net_i8254x_poll:
267287
push rsi ; Used for the base MMIO of the NIC
268288
push rax
269289

270-
mov rdi, os_rx_desc
290+
mov rdi, [rdx+nt_rx_desc]
271291
mov rsi, [rdx+nt_base] ; Load the base MMIO of the NIC
272292

273293
; Calculate the descriptor to read from

src/sysvar.asm

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,15 @@ nt_base: equ 0x10 ; 64-bit
175175
nt_len: equ 0x18 ; 64-bit
176176
nt_transmit: equ 0x20 ; 64-bit
177177
nt_poll: equ 0x28 ; 64-bit
178-
nt_tx_head: equ 0x30 ; 64-bit
179-
nt_rx_head: equ 0x34 ; 64-bit
180-
nt_tx_packets: equ 0x40 ; 64-bit
181-
nt_tx_bytes: equ 0x48 ; 64-bit
182-
nt_rx_packets: equ 0x50 ; 64-bit
183-
nt_rx_bytes: equ 0x58 ; 64-bit
178+
nt_tx_desc: equ 0x30 ; 64-bit
179+
nt_rx_desc: equ 0x38 ; 64-bit
180+
nt_tx_head: equ 0x40 ; 64-bit
181+
nt_rx_head: equ 0x44 ; 64-bit
182+
nt_tx_packets: equ 0x50 ; 64-bit
183+
nt_tx_bytes: equ 0x58 ; 64-bit
184+
nt_rx_packets: equ 0x60 ; 64-bit
185+
nt_rx_bytes: equ 0x68 ; 64-bit
186+
; bytes 70-7F for future use
184187

185188

186189
; Misc

0 commit comments

Comments
 (0)