@@ -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
191203net_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
498513net_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
0 commit comments