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