Rev 3346 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2886 | hidnplayr | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
3 | ;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;; |
||
4 | ;; Distributed under terms of the GNU General Public License ;; |
||
5 | ;; ;; |
||
6 | ;; GNU GENERAL PUBLIC LICENSE ;; |
||
7 | ;; Version 2, June 1991 ;; |
||
8 | ;; ;; |
||
9 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
1472 | hidnplayr | 10 | |
2886 | hidnplayr | 11 | include 'bus/pci.inc' |
3350 | hidnplayr | 12 | include 'bus/mii.inc' |
1472 | hidnplayr | 13 | |
1556 | hidnplayr | 14 | ; Kernel variables |
1472 | hidnplayr | 15 | |
2887 | hidnplayr | 16 | PAGESIZE = 4096 |
17 | PG_SW = 0x003 |
||
2935 | hidnplayr | 18 | PG_NOCACHE = 0x018 |
1472 | hidnplayr | 19 | |
1556 | hidnplayr | 20 | |
1514 | hidnplayr | 21 | ; network driver types |
1472 | hidnplayr | 22 | |
2887 | hidnplayr | 23 | NET_TYPE_ETH = 1 |
24 | NET_TYPE_SLIP = 2 |
||
1514 | hidnplayr | 25 | |
3346 | hidnplayr | 26 | ; link state |
1514 | hidnplayr | 27 | |
3346 | hidnplayr | 28 | ETH_LINK_DOWN = 0 ; Link is down |
29 | ETH_LINK_UNKOWN = 1b ; There could be an active link |
||
30 | ETH_LINK_FD = 10b ; full duplex flag |
||
31 | ETH_LINK_10M = 100b ; 10 mbit |
||
32 | ETH_LINK_100M = 1000b ; 100 mbit |
||
33 | ETH_LINK_1G = 10000b ; gigabit |
||
34 | |||
35 | |||
2886 | hidnplayr | 36 | LAST_IO = 0 |
2887 | hidnplayr | 37 | macro set_io addr { |
1514 | hidnplayr | 38 | |
2886 | hidnplayr | 39 | if addr = 0 |
40 | mov edx, [device.io_addr] |
||
41 | else if addr = LAST_IO |
||
42 | else |
||
43 | add edx, addr - LAST_IO |
||
44 | end if |
||
1472 | hidnplayr | 45 | |
2886 | hidnplayr | 46 | LAST_IO = addr |
1472 | hidnplayr | 47 | } |
48 | |||
2887 | hidnplayr | 49 | macro allocate_and_clear dest, size, err { |
1472 | hidnplayr | 50 | |
51 | ; We need to allocate at least 8 pages, if we want a continuous memory in ram |
||
2886 | hidnplayr | 52 | push edx |
1472 | hidnplayr | 53 | if (size < 8*4096) & (size > 4096) |
2886 | hidnplayr | 54 | stdcall KernelAlloc, 8*4096 |
1472 | hidnplayr | 55 | else |
2886 | hidnplayr | 56 | stdcall KernelAlloc, size |
1472 | hidnplayr | 57 | end if |
2886 | hidnplayr | 58 | pop edx |
1521 | hidnplayr | 59 | |
2886 | hidnplayr | 60 | test eax, eax |
61 | jz err |
||
62 | mov dest, eax ; Save the address to it into the device struct |
||
63 | mov edi, eax ; look at last part of code! |
||
1472 | hidnplayr | 64 | |
65 | ; Release the unused pages (if any) |
||
66 | if (size < 8*4096) & (size > 4096) |
||
2886 | hidnplayr | 67 | add eax, (size/4096+1)*4096 |
68 | mov ecx, 8-(size/4096+1) |
||
69 | push edx |
||
70 | call ReleasePages |
||
71 | pop edx |
||
1472 | hidnplayr | 72 | end if |
73 | |||
74 | ; Clear the allocated buffer |
||
2886 | hidnplayr | 75 | mov ecx, size/4 ; divide by 4 because of DWORD |
76 | xor eax, eax |
||
77 | rep stosd |
||
1472 | hidnplayr | 78 | |
79 | } |
||
80 | |||
2887 | hidnplayr | 81 | struc IOCTL { |
82 | .handle dd ? |
||
83 | .io_code dd ? |
||
84 | .input dd ? |
||
85 | .inp_size dd ? |
||
86 | .output dd ? |
||
87 | .out_size dd ? |
||
1472 | hidnplayr | 88 | } |
89 | |||
90 | virtual at edx |
||
91 | IOCTL IOCTL |
||
92 | end virtual |
||
93 | |||
94 | |||
95 | if used null_op |
||
96 | align 4 |
||
97 | null_op: |
||
2886 | hidnplayr | 98 | or eax, -1 |
99 | ret |
||
1472 | hidnplayr | 100 | |
101 | end if |
||
102 | |||
103 | |||
2887 | hidnplayr | 104 | macro GetRealAddr { ; input and output is eax |
1472 | hidnplayr | 105 | |
2886 | hidnplayr | 106 | push ax |
107 | call GetPgAddr |
||
108 | and word[esp], PAGESIZE - 1 |
||
109 | or ax, word[esp] |
||
110 | inc esp |
||
111 | inc esp |
||
1472 | hidnplayr | 112 | |
1492 | hidnplayr | 113 | } |
114 | |||
2887 | hidnplayr | 115 | macro NET_DEVICE { |
1519 | hidnplayr | 116 | |
2886 | hidnplayr | 117 | .type dd ? ; Type field |
118 | .mtu dd ? ; Maximal Transmission Unit |
||
119 | .name dd ? ; Ptr to 0 terminated string |
||
1519 | hidnplayr | 120 | |
2886 | hidnplayr | 121 | .unload dd ? ; Ptrs to driver functions |
122 | .reset dd ? ; |
||
123 | .transmit dd ? ; |
||
1519 | hidnplayr | 124 | |
2886 | hidnplayr | 125 | .bytes_tx dq ? ; Statistics, updated by the driver |
126 | .bytes_rx dq ? ; |
||
127 | .packets_tx dd ? ; |
||
128 | .packets_rx dd ? ; |
||
1519 | hidnplayr | 129 | |
3346 | hidnplayr | 130 | .state dd ? ; link state (0 = no link) |
131 | .hwacc dd ? ; bitmask stating enabled HW accelerations |
||
132 | |||
2886 | hidnplayr | 133 | .end: |
1514 | hidnplayr | 134 | } |
1492 | hidnplayr | 135 | |
1529 | hidnplayr | 136 | |
2887 | hidnplayr | 137 | macro ETH_DEVICE { |
138 | NET_DEVICE |
||
1519 | hidnplayr | 139 | |
2886 | hidnplayr | 140 | .mac dp ? |
3346 | hidnplayr | 141 | dw ? ; qword alignment |
1519 | hidnplayr | 142 | |
1492 | hidnplayr | 143 | } |
144 | |||
1502 | hidnplayr | 145 | |
146 | |||
2887 | hidnplayr | 147 | macro SLIP_DEVICE { |
2886 | hidnplayr | 148 | NET_DEVICE |
1519 | hidnplayr | 149 | |
1529 | hidnplayr | 150 | }>> |