Rev 7679 | Rev 9394 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 7679 | Rev 9017 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2019. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2021. All rights reserved. ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
5 | ;; ;; |
6 | ;; ETHERNET.INC ;; |
6 | ;; ETHERNET.INC ;; |
7 | ;; ;; |
7 | ;; ;; |
8 | ;; Ethernet network layer for KolibriOS ;; |
8 | ;; Ethernet network layer for KolibriOS ;; |
Line 12... | Line 12... | ||
12 | ;; GNU GENERAL PUBLIC LICENSE ;; |
12 | ;; GNU GENERAL PUBLIC LICENSE ;; |
13 | ;; Version 2, June 1991 ;; |
13 | ;; Version 2, June 1991 ;; |
14 | ;; ;; |
14 | ;; ;; |
15 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
15 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line 16... | Line 16... | ||
16 | 16 | ||
Line 17... | Line 17... | ||
17 | $Revision: 7679 $ |
17 | $Revision: 9017 $ |
18 | 18 | ||
Line 19... | Line 19... | ||
19 | ETH_FRAME_MINIMUM = 60 |
19 | ETH_FRAME_MINIMUM = 60 |
Line 74... | Line 74... | ||
74 | ;-----------------------------------------------------------------; |
74 | ;-----------------------------------------------------------------; |
75 | align 4 |
75 | align 4 |
76 | eth_input: |
76 | eth_input: |
Line 77... | Line 77... | ||
77 | 77 | ||
- | 78 | pop eax |
|
- | 79 | ||
- | 80 | if defined NETWORK_SANITY_CHECKS |
|
- | 81 | cmp eax, [net_buffs_low] |
|
- | 82 | jb .assert_mbuff |
|
- | 83 | cmp eax, [net_buffs_high] |
|
78 | pop eax |
84 | ja .assert_mbuff |
- | 85 | test eax, 0x7ff |
|
- | 86 | jnz .assert_mbuff |
|
- | 87 | end if |
|
79 | pushf |
88 | |
Line 80... | Line 89... | ||
80 | cli |
89 | spin_lock_irqsave |
81 | 90 | ||
82 | cmp [ETH_frame_queued], ETH_QUEUE_SIZE |
91 | cmp [ETH_frame_queued], ETH_QUEUE_SIZE |
Line 90... | Line 99... | ||
90 | mov [eax + NET_BUFF.PrevPtr], ebx |
99 | mov [eax + NET_BUFF.PrevPtr], ebx |
Line 91... | Line 100... | ||
91 | 100 | ||
92 | mov [ETH_frame_tail], eax |
101 | mov [ETH_frame_tail], eax |
Line 93... | Line 102... | ||
93 | mov [ebx + NET_BUFF.NextPtr], eax |
102 | mov [ebx + NET_BUFF.NextPtr], eax |
Line 94... | Line 103... | ||
94 | 103 | ||
95 | popf |
104 | spin_unlock_irqrestore |
Line 96... | Line 105... | ||
96 | 105 | ||
Line 105... | Line 114... | ||
105 | call raise_event |
114 | call raise_event |
Line 106... | Line 115... | ||
106 | 115 | ||
Line 107... | Line 116... | ||
107 | ret |
116 | ret |
- | 117 | ||
- | 118 | .full: |
|
108 | 119 | mov ebx, [eax + NET_BUFF.device] |
|
- | 120 | inc [ebx + NET_DEVICE.packets_rx_ovr] |
|
- | 121 | DEBUGF DEBUG_NETWORK_VERBOSE, "ETH incoming queue is full, discarding packet!\n" |
|
109 | .full: |
122 | spin_unlock_irqrestore |
- | 123 | stdcall net_buff_free, eax |
|
- | 124 | ret |
|
110 | DEBUGF DEBUG_NETWORK_ERROR, "ETH incoming queue is full, discarding packet!\n" |
125 | |
- | 126 | if defined NETWORK_SANITY_CHECKS |
|
- | 127 | .assert_mbuff: |
|
111 | popf |
128 | DEBUGF DEBUG_NETWORK_ERROR, "eth_input: invalid buffer 0x%x\n", eax |
112 | push eax |
129 | DEBUGF DEBUG_NETWORK_ERROR, "eth_input: caller=0x%x\n", [esp+4] |
- | 130 | xor eax, eax |
|
Line 113... | Line 131... | ||
113 | call net_buff_free |
131 | ret |
114 | ret |
132 | end if |
Line 162... | Line 180... | ||
162 | pushd .loop ; return address for protocol handler |
180 | pushd .loop ; return address for protocol handler |
163 | push esi ; keep pointer to NET_BUFF on stack |
181 | push esi ; keep pointer to NET_BUFF on stack |
Line 164... | Line 182... | ||
164 | 182 | ||
165 | DEBUGF DEBUG_NETWORK_VERBOSE, "ETH_input: size=%u\n", ecx |
183 | DEBUGF DEBUG_NETWORK_VERBOSE, "ETH_input: size=%u\n", ecx |
166 | sub ecx, sizeof.ETH_header |
184 | sub ecx, sizeof.ETH_header |
Line 167... | Line 185... | ||
167 | jb .dump |
185 | jb .err |
168 | 186 | ||
169 | ; Set registers for protocol handlers |
187 | ; Set registers for protocol handlers |
Line 186... | Line 204... | ||
186 | ; cmp ax, ETHER_PROTO_PPP_SESSION |
204 | ; cmp ax, ETHER_PROTO_PPP_SESSION |
187 | ; je pppoe_session_input |
205 | ; je pppoe_session_input |
Line 188... | Line 206... | ||
188 | 206 | ||
Line 189... | Line 207... | ||
189 | DEBUGF DEBUG_NETWORK_VERBOSE, "ETH_input: Unknown packet type=%x\n", ax |
207 | DEBUGF DEBUG_NETWORK_VERBOSE, "ETH_input: Unknown packet type=%x\n", ax |
- | 208 | ||
- | 209 | .drop: |
|
- | 210 | mov eax, [esp] |
|
190 | 211 | mov eax, [eax + NET_BUFF.device] |
|
- | 212 | inc [eax + NET_DEVICE.packets_rx_drop] |
|
- | 213 | DEBUGF DEBUG_NETWORK_VERBOSE, "ETH_input: dropping\n" |
|
- | 214 | call net_buff_free |
|
- | 215 | ret |
|
- | 216 | ||
- | 217 | .err: |
|
- | 218 | mov eax, [esp] |
|
- | 219 | mov eax, [eax + NET_BUFF.device] |
|
191 | .dump: |
220 | inc [eax + NET_DEVICE.packets_rx_err] |
192 | DEBUGF DEBUG_NETWORK_VERBOSE, "ETH_input: dumping\n" |
221 | DEBUGF DEBUG_NETWORK_VERBOSE, "ETH_input: invalid frame received\n" |
Line -... | Line 222... | ||
- | 222 | call net_buff_free |
|
193 | call net_buff_free |
223 | ret |
194 | ret |
224 | |
195 | 225 | ||
196 | 226 | ||
197 | 227 | ||
Line 214... | Line 244... | ||
214 | eth_output: |
244 | eth_output: |
Line 215... | Line 245... | ||
215 | 245 | ||
Line 216... | Line 246... | ||
216 | DEBUGF DEBUG_NETWORK_VERBOSE, "ETH_output: size=%u device=%x\n", ecx, ebx |
246 | DEBUGF DEBUG_NETWORK_VERBOSE, "ETH_output: size=%u device=%x\n", ecx, ebx |
217 | 247 | ||
Line 218... | Line 248... | ||
218 | cmp ecx, [ebx + ETH_DEVICE.mtu] |
248 | cmp ecx, [ebx + ETH_DEVICE.mtu] |
219 | ja .exit |
249 | ja .too_large |
Line 220... | Line 250... | ||
220 | 250 | ||
221 | push ecx |
251 | push ecx |
222 | push ax edx |
252 | push ax edx |
223 | 253 | ||
- | 254 | add ecx, sizeof.ETH_header + NET_BUFF.data |
|
224 | add ecx, sizeof.ETH_header + NET_BUFF.data |
255 | stdcall net_buff_alloc, ecx |
225 | stdcall net_buff_alloc, ecx |
256 | test eax, eax |
226 | test eax, eax |
257 | jz .out_of_ram |
227 | jz .out_of_ram |
258 | |
Line 254... | Line 285... | ||
254 | mov edx, ETH_FRAME_MINIMUM |
285 | mov edx, ETH_FRAME_MINIMUM |
255 | test edx, edx ; clear zero flag |
286 | test edx, edx ; clear zero flag |
256 | jmp .done |
287 | jmp .done |
Line 257... | Line 288... | ||
257 | 288 | ||
- | 289 | .out_of_ram: |
|
258 | .out_of_ram: |
290 | inc [ebx + NET_DEVICE.packets_tx_drop] |
259 | DEBUGF DEBUG_NETWORK_ERROR, "ETH_output: Out of ram!\n" |
291 | DEBUGF DEBUG_NETWORK_VERBOSE, "ETH_output: Out of ram!\n" |
- | 292 | add esp, 4+2 |
|
260 | add esp, 4+2+4 |
293 | pop ecx |
261 | xor eax, eax |
294 | xor eax, eax |
Line 262... | Line 295... | ||
262 | ret |
295 | ret |
- | 296 | ||
263 | 297 | .too_large: |
|
264 | .exit: |
298 | inc [eax + NET_DEVICE.packets_tx_err] |
265 | DEBUGF DEBUG_NETWORK_ERROR, "ETH_output: Packet too large!\n" |
299 | DEBUGF DEBUG_NETWORK_VERBOSE, "ETH_output: Packet too large!\n" |