Rev 9146 | 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 | |||
4522 | hidnplayr | 46 | ; Macro to easily set i/o addresses to access device. |
47 | ; In the beginning of a procedure (or ofter edx may have been destroyed), |
||
48 | ; always use set_io with offset 0 to reset the variables. |
||
49 | |||
50 | LAST_IO = 0 |
||
51 | |||
52 | macro set_io baseaddr, offset { |
||
53 | |||
54 | if offset = 0 |
||
55 | mov edx, baseaddr |
||
56 | else if offset = LAST_IO |
||
57 | else |
||
58 | add edx, offset - LAST_IO |
||
59 | end if |
||
60 | |||
61 | LAST_IO = offset |
||
62 | } |
||
63 | |||
64 | ; Macro to allocate a contiguous buffer in memory |
||
65 | ; And initialise it to all zeros |
||
66 | |||
67 | ; This macro will destroy eax, ecx and edi ! |
||
68 | |||
69 | macro allocate_and_clear dest, size, err { |
||
70 | |||
71 | ; We need to allocate at least 8 pages, if we want a contiguous area in ram |
||
72 | push edx |
||
73 | if (size < 8*4096) & (size > 4096) |
||
74 | invoke KernelAlloc, 8*4096 |
||
75 | else |
||
76 | invoke KernelAlloc, size |
||
77 | end if |
||
78 | pop edx |
||
79 | |||
80 | test eax, eax |
||
81 | jz err |
||
82 | mov dest, eax |
||
83 | mov edi, eax ; look at last part of code! |
||
84 | |||
85 | ; Release the unused pages (if any) |
||
86 | if (size < 8*4096) & (size > 4096) |
||
87 | add eax, (size/4096+1)*4096 |
||
88 | mov ecx, 8-(size/4096+1) |
||
89 | push edx |
||
90 | invoke ReleasePages |
||
91 | pop edx |
||
92 | end if |
||
93 | |||
94 | ; Clear the allocated buffer |
||
95 | mov ecx, size/4 ; divide by 4 because of DWORD |
||
96 | xor eax, eax |
||
97 | rep stosd |
||
98 | |||
99 | if (size - size/4*4) |
||
100 | mov ecx, size - size/4*4 |
||
101 | rep stosb |
||
102 | end if |
||
103 | |||
104 | } |
||
105 | |||
106 | |||
107 | struct NET_DEVICE |
||
108 | |||
109 | type dd ? ; Type field |
||
110 | mtu dd ? ; Maximal Transmission Unit |
||
111 | name dd ? ; Ptr to 0 terminated string |
||
112 | |||
113 | unload dd ? ; Ptrs to driver functions |
||
114 | reset dd ? ; |
||
115 | transmit dd ? ; |
||
116 | |||
8896 | hidnplayr | 117 | state dd ? ; link state (0 = no link) |
118 | hwacc dd ? ; bitmask stating enabled HW accelerations (offload engines) |
||
119 | |||
4522 | hidnplayr | 120 | bytes_tx dq ? ; Statistics, updated by the driver |
121 | bytes_rx dq ? ; |
||
8896 | hidnplayr | 122 | |
4522 | hidnplayr | 123 | packets_tx dd ? ; |
8896 | hidnplayr | 124 | packets_tx_err dd ? ; CRC errors, too long or too short frames |
125 | packets_tx_drop dd ? ; |
||
126 | packets_tx_ovr dd ? ; FIFO overrun |
||
127 | |||
4522 | hidnplayr | 128 | packets_rx dd ? ; |
8896 | hidnplayr | 129 | packets_rx_err dd ? ; CRC errors, too long or too short frames |
130 | packets_rx_drop dd ? ; |
||
131 | packets_rx_ovr dd ? ; FIFO overrun |
||
4522 | hidnplayr | 132 | |
133 | ends |
||
134 | |||
135 | |||
5522 | hidnplayr | 136 | struct NET_BUFF |
137 | |||
138 | NextPtr dd ? ; pointer to next frame in list |
||
139 | PrevPtr dd ? ; pointer to previous frame in list |
||
140 | device dd ? ; ptr to NET_DEVICE structure |
||
141 | type dd ? ; data type (e.g. Ethernet) |
||
142 | length dd ? ; data length |
||
143 | offset dd ? ; offset to actual data (24 bytes for default frame) |
||
144 | data rb 0 |
||
145 | |||
146 | ends |
||
147 | |||
148 | |||
4522 | hidnplayr | 149 | struct ETH_DEVICE NET_DEVICE |
150 | |||
151 | mac dp ? |
||
152 | dw ? ; qword alignment |
||
153 | |||
154 | ends>> |