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