Skip to content

Commit 9a4619e

Browse files
author
Ian Seyler
committed
Re-org of net_i8259x_poll
1 parent 10c3540 commit 9a4619e

File tree

3 files changed

+49
-33
lines changed

3 files changed

+49
-33
lines changed

src/drivers/net/i8257x.asm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,9 @@ net_i8257x_transmit:
299299

300300
; -----------------------------------------------------------------------------
301301
; net_i8257x_poll - Polls the Intel 8257x NIC for a received packet
302-
; IN: RDI = Location to store packet
303-
; RDX = Interface ID
304-
; OUT: RCX = Length of packet
302+
; IN: RDX = Interface ID
303+
; OUT: RDI = Location of stored packet
304+
; RCX = Length of packet
305305
; Note: RDESC Descriptor Format:
306306
; First Qword:
307307
; Bits 63:0 - Buffer Address

src/drivers/net/i8259x.asm

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ net_i8259x_init:
6060
; Set base addresses for TX and RX descriptors
6161
xor ecx, ecx
6262
mov cl, byte [os_net_icount]
63-
shl ecx, 15
63+
shl ecx, 15 ; Quick multiply by 32768
6464

6565
mov rax, os_tx_desc
6666
add rax, rcx
@@ -126,7 +126,7 @@ net_i8259x_reset_wait:
126126
mov eax, [rsi+i8259x_CTRL] ; Read CTRL
127127
jnz net_i8259x_reset_wait ; Wait for it to read back as 0x0
128128

129-
; Wait 10ns
129+
; Wait 10ms (4.6.3.2)
130130
mov rax, 10000
131131
call b_delay
132132

@@ -137,6 +137,18 @@ net_i8259x_reset_wait:
137137
mov [rsi+i8259x_EIMC], eax
138138
mov eax, [rsi+i8259x_EICR]
139139

140+
; Preform general configuration (4.6.3.2)
141+
;FCTTV
142+
;FCRTL - Flow Control Low Threshold
143+
;FCRTH - Flow Control High Threshold
144+
;FCRTV
145+
;FCCFG
146+
; Section 3.7.7.3.2 through Section 3.7.7.3.5
147+
;FDIRCTRL - Clear PBALLOC
148+
;SRRCTL[n].BSIZEPACKET field defines the data buffer size. Section 7.1.2
149+
;Aggregation - Section 7.1.7
150+
;Receive Coalescing (RSC) - Section 7.11.5.1
151+
140152
; Wait for EEPROM auto read completion (4.6.3)
141153
mov eax, [rsi+i8259x_EEC] ; Read current value
142154
bts eax, 9 ; i8259x_EEC_ARD
@@ -185,7 +197,7 @@ net_i8259x_reset_dma_wait:
185197
mov ecx, i8259x_MAX_DESC
186198
xor eax, eax
187199
mov al, byte [os_net_icount]
188-
shl eax, 15
200+
shl eax, 15 ; Quick multiply by 32768
189201
mov rdi, os_rx_desc
190202
add rdi, rax
191203
net_i8259x_reset_nextdesc:
@@ -205,13 +217,13 @@ net_i8259x_reset_nextdesc:
205217
; mov eax, 32768
206218
; mov [rsi+i8259x_RXPBSIZE], eax
207219
; Set Max packet size
208-
mov eax, 9000 ; 9000 bytes
209-
shl eax, 16 ; Shift to bits 31:16
210-
mov [rsi+i8259x_MAXFRS], eax
220+
; mov eax, 9000 ; 9000 bytes
221+
; shl eax, 16 ; Shift to bits 31:16
222+
; mov [rsi+i8259x_MAXFRS], eax
211223
; Enable Jumbo Frames
212-
mov eax, [rsi+i8259x_HLREG0]
213-
or eax, 1 << i8259x_HLREG0_JUMBOEN
214-
mov [rsi+i8259x_HLREG0], eax
224+
; mov eax, [rsi+i8259x_HLREG0]
225+
; or eax, 1 << i8259x_HLREG0_JUMBOEN
226+
; mov [rsi+i8259x_HLREG0], eax
215227
; Enable CRC offloading
216228
mov eax, [rsi+i8259x_HLREG0]
217229
or eax, 1 << i8259x_HLREG0_RXCRCSTRP
@@ -223,7 +235,7 @@ net_i8259x_reset_nextdesc:
223235
mov eax, [rsi+i8259x_FCTRL]
224236
or eax, i8259x_FCTRL_BAM
225237
mov [rsi+i8259x_FCTRL], eax
226-
; Enable Advanced RX descriptors
238+
; Disable Advanced RX descriptors
227239
mov eax, [rsi+i8259x_SRRCTL]
228240
and eax, 0xF1FFFFFF ; Clear bits 27:25 for DESCTYPE
229241
; or eax, 0x02000000 ; Bits 27:25 = 001 for Advanced desc one buffer
@@ -232,7 +244,7 @@ net_i8259x_reset_nextdesc:
232244
; Set up RX descriptor ring 0
233245
xor eax, eax
234246
mov al, byte [os_net_icount]
235-
shl eax, 15
247+
shl eax, 15 ; Quick multiply by 32768
236248
add rax, os_rx_desc
237249
mov [rsi+i8259x_RDBAL], eax
238250
shr rax, 32
@@ -308,7 +320,7 @@ net_i8259x_init_rx_enable_wait:
308320
; Set up TX descriptor ring 0
309321
xor eax, eax
310322
mov al, byte [os_net_icount]
311-
shl eax, 15
323+
shl eax, 15 ; Quick multiply by 32768
312324
add rax, os_tx_desc
313325
mov [rsi+i8259x_TDBAL], eax ; Bits 6:0 are ignored, memory alignment at 128bytes
314326
shr rax, 32
@@ -453,9 +465,9 @@ net_i8259x_transmit:
453465

454466
; -----------------------------------------------------------------------------
455467
; net_i8259x_poll - Polls the Intel 8259x NIC for a received packet
456-
; IN: RDI = Location to store packet
457-
; RDX = Interface ID
458-
; OUT: RCX = Length of packet
468+
; IN: RDX = Interface ID
469+
; OUT: RDI = Location of stored packet
470+
; RCX = Length of packet
459471
; Note: Receive Descriptor (RDESC) Layout - Legacy Mode (7.1.5):
460472
; Bits 63:0 - Buffer Address
461473
; Bits 95:64 - Fragment Checksum (Bits 31:16) / Length (Bits 15:0)
@@ -465,34 +477,37 @@ net_i8259x_poll:
465477
push rbx
466478
push rax
467479

468-
mov rdi, [rdx+nt_rx_desc]
480+
mov rdi, [rdx+nt_rx_desc] ; Load the base address of the RX descriptors
469481
mov rsi, [rdx+nt_base] ; Load the base MMIO of the NIC
470482

471483
; Calculate the descriptor to read from
472-
mov eax, [rdx+nt_rx_head] ; Get rx_lasthead
484+
mov eax, [rdx+nt_rx_head] ; Get rx_head
473485
shl eax, 4 ; Quick multiply by 16
474-
add rdi, rax ; Add offset to RDI
475-
mov rbx, [rdi]
486+
add rdi, rax ; Add offset to RX descriptor base
487+
mov rbx, [rdi] ; Load the buffer address (where the packet is)
476488
add rdi, 8 ; Offset to bytes received
477-
; Todo: read all 64 bits. check status bit for DD
489+
; Todo: read all 64 bits. check status bit DD(0)
490+
; Errors (Bits 47:40) should be clear
478491
xor ecx, ecx ; Clear RCX
479492
mov cx, [rdi] ; Get the packet length
480493
cmp cx, 0
481494
je net_i8259x_poll_end ; No data? Bail out
482495

483496
xor eax, eax
484497
stosq ; Clear the descriptor length and status
485-
mov rdi, rbx
498+
mov rdi, rbx ; Copy the buffer address to RDI
486499

487-
; Increment i8259x_rx_lasthead and the Receive Descriptor Tail
488-
mov eax, [rdx+nt_rx_head] ; Get rx_lasthead
500+
; Increment rx_head
501+
mov eax, [rdx+nt_rx_head] ; Get rx_head
489502
add eax, 1
490503
and eax, i8259x_MAX_DESC - 1
491-
mov [rdx+nt_rx_head], eax ; Set rx_lasthead
504+
mov [rdx+nt_rx_head], eax ; Set rx_head
492505

493-
mov eax, [rsi+i8259x_RDT] ; Read the current Receive Descriptor Tail
506+
; Increment rx_tail and the device Receive Descriptor Tail
507+
mov eax, [rdx+nt_rx_tail] ; Load the last tail value
494508
add eax, 1 ; Add 1 to the Receive Descriptor Tail
495-
and eax, i8259x_MAX_DESC - 1
509+
and eax, i8259x_MAX_DESC - 1 ; Wrap around if needed
510+
mov [rdx+nt_rx_tail], eax ; Update driver info
496511
mov [rsi+i8259x_RDT], eax ; Write the updated Receive Descriptor Tail
497512

498513
net_i8259x_poll_end:
@@ -504,7 +519,7 @@ net_i8259x_poll_end:
504519

505520

506521
; Constants
507-
i8259x_MAX_DESC equ 2048 ; Must be 16, 32, 64, 128, etc. Each descriptor is 16 bytes
522+
i8259x_MAX_DESC equ 2048 ; Must be a multiple of 128. Each descriptor is 16 bytes
508523

509524
; Register list (All registers should be accessed as 32-bit values)
510525

src/sysvar.asm

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,12 @@ nt_base: equ 0x10 ; 64-bit Base MMIO
150150
nt_config: equ 0x18 ; 64-bit Config function address
151151
nt_transmit: equ 0x20 ; 64-bit Transmit function address
152152
nt_poll: equ 0x28 ; 64-bit Poll function address
153-
; nt_desc: equ 0xXX ; 64-bit Address of TX/RX descriptors
154153
nt_tx_desc: equ 0x30 ; 64-bit Address of TX descriptors
155154
nt_rx_desc: equ 0x38 ; 64-bit Address of RX descriptors
156-
nt_tx_tail: equ 0x40 ; 64-bit TX Tail
157-
nt_rx_head: equ 0x44 ; 64-bit RX Head
155+
nt_tx_head: equ 0x40 ; 32-bit TX Head
156+
nt_tx_tail: equ 0x44 ; 32-bit TX Tail
157+
nt_rx_head: equ 0x48 ; 32-bit RX Head
158+
nt_rx_tail: equ 0x4A ; 32-bit RX Tail
158159
nt_tx_packets: equ 0x50 ; 64-bit Number of packets transmitted
159160
nt_tx_bytes: equ 0x58 ; 64-bit Number of bytes transmitted
160161
nt_rx_packets: equ 0x60 ; 64-bit Number of packets received

0 commit comments

Comments
 (0)