Subversion Repositories Kolibri OS

Rev

Rev 4449 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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