Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4522 | hidnplayr | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
3 | ;; Copyright (C) KolibriOS team 2004-2014. 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 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
10 | |||
11 | ; This macro will prepend driver name to all debug output through DEBUGF macro |
||
12 | ; The driver name is taken from my_service label |
||
13 | |||
14 | if defined my_service |
||
15 | |||
16 | macro DEBUGF _level,_format, [args] { |
||
17 | common DEBUGF _level, "%s: " # _format, my_service, args |
||
18 | } |
||
19 | |||
20 | end if |
||
21 | |||
22 | include 'pci_pe.inc' |
||
23 | include 'mii.inc' |
||
24 | |||
25 | ; Kernel variables |
||
26 | |||
27 | PAGESIZE = 4096 |
||
28 | |||
29 | ; Network driver types |
||
30 | |||
31 | NET_TYPE_ETH = 1 |
||
32 | NET_TYPE_SLIP = 2 |
||
33 | |||
34 | ; Link state |
||
35 | |||
36 | ETH_LINK_DOWN = 0 ; Link is down |
||
37 | ETH_LINK_UNKOWN = 1b ; There could be an active link |
||
38 | ETH_LINK_FD = 10b ; full duplex flag |
||
39 | ETH_LINK_10M = 100b ; 10 mbit |
||
40 | ETH_LINK_100M = 1000b ; 100 mbit |
||
41 | ETH_LINK_1G = 10000b ; gigabit |
||
42 | |||
43 | ; Macro to easily set i/o addresses to access device. |
||
44 | ; In the beginning of a procedure (or ofter edx may have been destroyed), |
||
45 | ; always use set_io with offset 0 to reset the variables. |
||
46 | |||
47 | LAST_IO = 0 |
||
48 | |||
49 | macro set_io baseaddr, offset { |
||
50 | |||
51 | if offset = 0 |
||
52 | mov edx, baseaddr |
||
53 | else if offset = LAST_IO |
||
54 | else |
||
55 | add edx, offset - LAST_IO |
||
56 | end if |
||
57 | |||
58 | LAST_IO = offset |
||
59 | } |
||
60 | |||
61 | ; Macro to allocate a contiguous buffer in memory |
||
62 | ; And initialise it to all zeros |
||
63 | |||
64 | ; This macro will destroy eax, ecx and edi ! |
||
65 | |||
66 | macro allocate_and_clear dest, size, err { |
||
67 | |||
68 | ; We need to allocate at least 8 pages, if we want a contiguous area in ram |
||
69 | push edx |
||
70 | if (size < 8*4096) & (size > 4096) |
||
71 | invoke KernelAlloc, 8*4096 |
||
72 | else |
||
73 | invoke KernelAlloc, size |
||
74 | end if |
||
75 | pop edx |
||
76 | |||
77 | test eax, eax |
||
78 | jz err |
||
79 | mov dest, eax |
||
80 | mov edi, eax ; look at last part of code! |
||
81 | |||
82 | ; Release the unused pages (if any) |
||
83 | if (size < 8*4096) & (size > 4096) |
||
84 | add eax, (size/4096+1)*4096 |
||
85 | mov ecx, 8-(size/4096+1) |
||
86 | push edx |
||
87 | invoke ReleasePages |
||
88 | pop edx |
||
89 | end if |
||
90 | |||
91 | ; Clear the allocated buffer |
||
92 | mov ecx, size/4 ; divide by 4 because of DWORD |
||
93 | xor eax, eax |
||
94 | rep stosd |
||
95 | |||
96 | if (size - size/4*4) |
||
97 | mov ecx, size - size/4*4 |
||
98 | rep stosb |
||
99 | end if |
||
100 | |||
101 | } |
||
102 | |||
103 | |||
104 | struct NET_DEVICE |
||
105 | |||
106 | type dd ? ; Type field |
||
107 | mtu dd ? ; Maximal Transmission Unit |
||
108 | name dd ? ; Ptr to 0 terminated string |
||
109 | |||
110 | unload dd ? ; Ptrs to driver functions |
||
111 | reset dd ? ; |
||
112 | transmit dd ? ; |
||
113 | |||
114 | bytes_tx dq ? ; Statistics, updated by the driver |
||
115 | bytes_rx dq ? ; |
||
116 | packets_tx dd ? ; |
||
117 | packets_rx dd ? ; |
||
118 | |||
119 | state dd ? ; link state (0 = no link) |
||
120 | hwacc dd ? ; bitmask stating enabled HW accelerations |
||
121 | |||
122 | ends |
||
123 | |||
124 | |||
125 | struct ETH_DEVICE NET_DEVICE |
||
126 | |||
127 | mac dp ? |
||
128 | dw ? ; qword alignment |
||
129 | |||
130 | ends>> |