Rev 8896 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4522 | hidnplayr | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
9146 | hidnplayr | 3 | ;; Copyright (C) KolibriOS team 2004-2021. All rights reserved. ;; |
4522 | hidnplayr | 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 | |||
5074 | hidnplayr | 22 | include 'pci.inc' |
4522 | hidnplayr | 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 | |||
9146 | hidnplayr | 36 | ETH_LINK_DOWN = 0 ; Link is down |
37 | ETH_LINK_UNKNOWN = 1b ; There could be an active link |
||
38 | ETH_LINK_FULL_DUPLEX = 10b ; full duplex flag |
||
39 | |||
40 | ETH_LINK_SPEED_10M = 100b ; 10 Mbit |
||
41 | ETH_LINK_SPEED_100M = 1000b ; 100 Mbit |
||
42 | ETH_LINK_SPEED_1G = 1100b ; Gigabit |
||
43 | |||
44 | ETH_LINK_SPEED_MASK = 1100b |
||
45 | |||
46 | ; Deprecated naming - dont use |
||
4522 | hidnplayr | 47 | ETH_LINK_FD = 10b ; full duplex flag |
48 | ETH_LINK_10M = 100b ; 10 mbit |
||
49 | ETH_LINK_100M = 1000b ; 100 mbit |
||
4580 | hidnplayr | 50 | ETH_LINK_1G = 1100b ; gigabit |
4522 | hidnplayr | 51 | |
52 | ; Macro to easily set i/o addresses to access device. |
||
53 | ; In the beginning of a procedure (or ofter edx may have been destroyed), |
||
54 | ; always use set_io with offset 0 to reset the variables. |
||
55 | |||
56 | LAST_IO = 0 |
||
57 | |||
58 | macro set_io baseaddr, offset { |
||
59 | |||
60 | if offset = 0 |
||
61 | mov edx, baseaddr |
||
62 | else if offset = LAST_IO |
||
63 | else |
||
64 | add edx, offset - LAST_IO |
||
65 | end if |
||
66 | |||
67 | LAST_IO = offset |
||
68 | } |
||
69 | |||
70 | ; Macro to allocate a contiguous buffer in memory |
||
71 | ; And initialise it to all zeros |
||
72 | |||
73 | ; This macro will destroy eax, ecx and edi ! |
||
74 | |||
75 | macro allocate_and_clear dest, size, err { |
||
76 | |||
77 | ; We need to allocate at least 8 pages, if we want a contiguous area in ram |
||
78 | push edx |
||
79 | if (size < 8*4096) & (size > 4096) |
||
80 | invoke KernelAlloc, 8*4096 |
||
81 | else |
||
82 | invoke KernelAlloc, size |
||
83 | end if |
||
84 | pop edx |
||
85 | |||
86 | test eax, eax |
||
87 | jz err |
||
88 | mov dest, eax |
||
89 | mov edi, eax ; look at last part of code! |
||
90 | |||
91 | ; Release the unused pages (if any) |
||
92 | if (size < 8*4096) & (size > 4096) |
||
93 | add eax, (size/4096+1)*4096 |
||
94 | mov ecx, 8-(size/4096+1) |
||
95 | push edx |
||
96 | invoke ReleasePages |
||
97 | pop edx |
||
98 | end if |
||
99 | |||
100 | ; Clear the allocated buffer |
||
101 | mov ecx, size/4 ; divide by 4 because of DWORD |
||
102 | xor eax, eax |
||
103 | rep stosd |
||
104 | |||
105 | if (size - size/4*4) |
||
106 | mov ecx, size - size/4*4 |
||
107 | rep stosb |
||
108 | end if |
||
109 | |||
110 | } |
||
111 | |||
112 | |||
113 | struct NET_DEVICE |
||
114 | |||
115 | type dd ? ; Type field |
||
116 | mtu dd ? ; Maximal Transmission Unit |
||
117 | name dd ? ; Ptr to 0 terminated string |
||
118 | |||
119 | unload dd ? ; Ptrs to driver functions |
||
120 | reset dd ? ; |
||
121 | transmit dd ? ; |
||
122 | |||
8896 | hidnplayr | 123 | state dd ? ; link state (0 = no link) |
124 | hwacc dd ? ; bitmask stating enabled HW accelerations (offload engines) |
||
125 | |||
4522 | hidnplayr | 126 | bytes_tx dq ? ; Statistics, updated by the driver |
127 | bytes_rx dq ? ; |
||
8896 | hidnplayr | 128 | |
4522 | hidnplayr | 129 | packets_tx dd ? ; |
8896 | hidnplayr | 130 | packets_tx_err dd ? ; CRC errors, too long or too short frames |
131 | packets_tx_drop dd ? ; |
||
132 | packets_tx_ovr dd ? ; FIFO overrun |
||
133 | |||
4522 | hidnplayr | 134 | packets_rx dd ? ; |
8896 | hidnplayr | 135 | packets_rx_err dd ? ; CRC errors, too long or too short frames |
136 | packets_rx_drop dd ? ; |
||
137 | packets_rx_ovr dd ? ; FIFO overrun |
||
4522 | hidnplayr | 138 | |
139 | ends |
||
140 | |||
141 | |||
5522 | hidnplayr | 142 | struct NET_BUFF |
143 | |||
144 | NextPtr dd ? ; pointer to next frame in list |
||
145 | PrevPtr dd ? ; pointer to previous frame in list |
||
146 | device dd ? ; ptr to NET_DEVICE structure |
||
147 | type dd ? ; data type (e.g. Ethernet) |
||
148 | length dd ? ; data length |
||
149 | offset dd ? ; offset to actual data (24 bytes for default frame) |
||
150 | data rb 0 |
||
151 | |||
152 | ends |
||
153 | |||
154 | |||
4522 | hidnplayr | 155 | struct ETH_DEVICE NET_DEVICE |
156 | |||
157 | mac dp ? |
||
158 | dw ? ; qword alignment |
||
159 | |||
160 | ends>> |