Subversion Repositories Kolibri OS

Rev

Rev 3635 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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