Rev 5522 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5522 | Rev 9157 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2010-2015. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2010-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 | ;; rhine.asm ;; |
6 | ;; rhine.asm ;; |
7 | ;; ;; |
7 | ;; ;; |
8 | ;; Ethernet driver for Kolibri OS ;; |
8 | ;; Ethernet driver for Kolibri OS ;; |
Line 19... | Line 19... | ||
19 | ;; See file COPYING for details ;; |
19 | ;; See file COPYING for details ;; |
20 | ;; ;; |
20 | ;; ;; |
21 | ;; ;; |
21 | ;; ;; |
22 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
22 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line -... | Line 23... | ||
- | 23 | ||
- | 24 | ; TODO: test for RX-overrun |
|
23 | 25 | ||
24 | format PE DLL native |
26 | format PE DLL native |
Line 25... | Line 27... | ||
25 | entry START |
27 | entry START |
26 | 28 | ||
Line 31... | Line 33... | ||
31 | MAX_DEVICES = 16 |
33 | MAX_DEVICES = 16 |
Line 32... | Line 34... | ||
32 | 34 | ||
33 | __DEBUG__ = 1 |
35 | __DEBUG__ = 1 |
Line 34... | Line 36... | ||
34 | __DEBUG_LEVEL__ = 2 ; 1 = all, 2 = errors only |
36 | __DEBUG_LEVEL__ = 2 ; 1 = all, 2 = errors only |
35 | 37 | ||
Line 36... | Line 38... | ||
36 | TX_RING_SIZE = 4 |
38 | TX_RING_SIZE = 32 |
37 | RX_RING_SIZE = 4 |
39 | RX_RING_SIZE = 32 |
Line 38... | Line 40... | ||
38 | 40 | ||
Line 1403... | Line 1405... | ||
1403 | ;; ;; |
1405 | ;; ;; |
1404 | ;; Transmit ;; |
1406 | ;; Transmit ;; |
1405 | ;; ;; |
1407 | ;; ;; |
1406 | ;; In: buffer pointer in [esp+4] ;; |
1408 | ;; In: buffer pointer in [esp+4] ;; |
1407 | ;; pointer to device structure in ebx ;; |
1409 | ;; pointer to device structure in ebx ;; |
- | 1410 | ;; Out: eax = 0 on success ;; |
|
1408 | ;; ;; |
1411 | ;; ;; |
1409 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1412 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1410 | align 4 |
1413 | align 16 |
1411 | proc transmit stdcall bufferptr |
1414 | proc transmit stdcall bufferptr |
Line 1412... | Line 1415... | ||
1412 | 1415 | ||
1413 | pushf |
- | |
Line 1414... | Line 1416... | ||
1414 | cli |
1416 | spin_lock_irqsave |
1415 | 1417 | ||
1416 | mov esi, [bufferptr] |
1418 | mov esi, [bufferptr] |
1417 | DEBUGF 1,"Transmitting packet, buffer:%x, size:%u\n", [bufferptr], [esi + NET_BUFF.length] |
1419 | DEBUGF 1,"Transmitting packet, buffer:%x, size:%u\n", [bufferptr], [esi + NET_BUFF.length] |
1418 | lea eax, [esi + NET_BUFF.data] |
1420 | lea eax, [esi + NET_BUFF.data] |
1419 | DEBUGF 1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\ |
1421 | DEBUGF 1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\ |
1420 | [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\ |
1422 | [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\ |
Line 1421... | Line 1423... | ||
1421 | [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\ |
1423 | [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\ |
1422 | [eax+13]:2,[eax+12]:2 |
1424 | [eax+13]:2,[eax+12]:2 |
1423 | 1425 | ||
1424 | cmp [esi + NET_BUFF.length], 1514 |
1426 | cmp [esi + NET_BUFF.length], 1514 |
Line -... | Line 1427... | ||
- | 1427 | ja .error |
|
1425 | ja .fail |
1428 | cmp [esi + NET_BUFF.length], 60 |
1426 | cmp [esi + NET_BUFF.length], 60 |
1429 | jb .error |
1427 | jb .fail |
1430 | |
1428 | 1431 | ; Program the descriptor |
|
1429 | movzx eax, [ebx + device.cur_tx] |
1432 | movzx eax, [ebx + device.cur_tx] |
Line 1430... | Line 1433... | ||
1430 | mov ecx, sizeof.tx_head |
1433 | mov ecx, sizeof.tx_head |
1431 | mul ecx |
1434 | mul ecx |
Line 1432... | Line 1435... | ||
1432 | lea edi, [ebx + device.tx_ring] |
1435 | lea edi, [ebx + device.tx_ring] |
1433 | add edi, eax |
1436 | add edi, eax |
1434 | 1437 | ||
1435 | cmp [edi + tx_head.buff_addr_virt], 0 |
1438 | cmp [edi + tx_head.buff_addr_virt], 0 |
Line 1461... | Line 1464... | ||
1461 | inc [ebx + device.packets_tx] |
1464 | inc [ebx + device.packets_tx] |
1462 | mov ecx, [esi + NET_BUFF.length] |
1465 | mov ecx, [esi + NET_BUFF.length] |
1463 | add dword [ebx + device.bytes_tx], ecx |
1466 | add dword [ebx + device.bytes_tx], ecx |
1464 | adc dword [ebx + device.bytes_tx + 4], 0 |
1467 | adc dword [ebx + device.bytes_tx + 4], 0 |
Line 1465... | Line 1468... | ||
1465 | 1468 | ||
1466 | DEBUGF 1,"Transmit OK\n" |
- | |
1467 | popf |
1469 | spin_unlock_irqrestore |
1468 | xor eax, eax |
1470 | xor eax, eax |
Line 1469... | Line 1471... | ||
1469 | ret |
1471 | ret |
1470 | 1472 | ||
- | 1473 | .error: |
|
- | 1474 | DEBUGF 2, "TX packet error\n" |
|
- | 1475 | inc [ebx + device.packets_tx_err] |
|
- | 1476 | invoke NetFree, [bufferptr] |
|
- | 1477 | ||
- | 1478 | spin_unlock_irqrestore |
|
- | 1479 | or eax, -1 |
|
- | 1480 | ret |
|
- | 1481 | ||
- | 1482 | .overrun: |
|
1471 | .fail: |
1483 | DEBUGF 2, "TX overrun\n" |
- | 1484 | inc [ebx + device.packets_tx_ovr] |
|
1472 | DEBUGF 2,"Transmit failed\n" |
1485 | invoke NetFree, [bufferptr] |
1473 | invoke NetFree, [bufferptr] |
1486 | |
1474 | popf |
1487 | spin_unlock_irqrestore |
Line -... | Line 1488... | ||
- | 1488 | or eax, -1 |
|
1475 | or eax, -1 |
1489 | ret |
Line 1476... | Line 1490... | ||
1476 | ret |
1490 | |
1477 | 1491 | ||
1478 | endp |
1492 | endp |
1479 | 1493 | ||
1480 | 1494 | ||
1481 | - | ||
1482 | ;;;;;;;;;;;;;;;;;;;;;;; |
1495 | |
1483 | ;; ;; |
1496 | ;;;;;;;;;;;;;;;;;;;;;;; |
Line 1484... | Line 1497... | ||
1484 | ;; Interrupt handler ;; |
1497 | ;; ;; |
Line 1485... | Line -... | ||
1485 | ;; ;; |
- | |
1486 | ;;;;;;;;;;;;;;;;;;;;;;; |
- | |
1487 | - | ||
1488 | align 4 |
1498 | ;; Interrupt handler ;; |
1489 | int_handler: |
1499 | ;; ;; |
1490 | - | ||
1491 | push ebx esi edi |
- | |
1492 | - | ||
1493 | DEBUGF 1,"INT\n" |
- | |
Line 1494... | Line 1500... | ||
1494 | 1500 | ;;;;;;;;;;;;;;;;;;;;;;; |
|
1495 | ; Find pointer of device which made IRQ occur |
1501 | align 16 |
1496 | mov ecx, [devices] |
1502 | int_handler: |
1497 | test ecx, ecx |
- | |
1498 | jz .nothing |
1503 | |
1499 | mov esi, device_list |
1504 | push ebx esi edi |
1500 | .nextdevice: |
- | |
1501 | mov ebx, [esi] |
- | |
1502 | - | ||
1503 | set_io [ebx + device.io_addr], 0 |
- | |
1504 | set_io [ebx + device.io_addr], IntrStatus |
- | |
1505 | in ax, dx |
- | |
1506 | out dx, ax ; send it back to ACK |
- | |
1507 | test ax, ax |
- | |
1508 | jnz .got_it |
- | |
1509 | .continue: |
- | |
Line 1510... | Line 1505... | ||
1510 | add esi, 4 |
1505 | |
1511 | dec ecx |
1506 | mov ebx, [esp+4*4] |
Line 1512... | Line 1507... | ||
1512 | jnz .nextdevice |
1507 | DEBUGF 1,"INT for 0x%x\n", ebx |
Line 1513... | Line 1508... | ||
1513 | .nothing: |
1508 | |
1514 | pop edi esi ebx |
1509 | set_io [ebx + device.io_addr], 0 |
Line 1650... | Line 1645... | ||
1650 | xor eax, eax |
1645 | xor eax, eax |
1651 | inc eax |
1646 | inc eax |
Line 1652... | Line 1647... | ||
1652 | 1647 | ||
Line -... | Line 1648... | ||
- | 1648 | ret |
|
- | 1649 | ||
- | 1650 | .nothing: |
|
- | 1651 | pop edi esi ebx |
|
- | 1652 | xor eax, eax |
|
Line 1653... | Line 1653... | ||
1653 | ret |
1653 |