Subversion Repositories Kolibri OS

Rev

Rev 4580 | Rev 5522 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4580 Rev 5074
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_pe.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
 
28
 
29
; Network driver types
29
; Network driver types
30
 
30
 
31
        NET_TYPE_ETH    = 1
31
        NET_TYPE_ETH    = 1
32
        NET_TYPE_SLIP   = 2
32
        NET_TYPE_SLIP   = 2
33
 
33
 
34
; Link state
34
; Link state
35
 
35
 
36
        ETH_LINK_DOWN   = 0             ; Link is down
36
        ETH_LINK_DOWN   = 0             ; Link is down
37
        ETH_LINK_UNKNOWN= 1b            ; There could be an active link
37
        ETH_LINK_UNKNOWN= 1b            ; There could be an active link
38
        ETH_LINK_FD     = 10b           ; full duplex flag
38
        ETH_LINK_FD     = 10b           ; full duplex flag
39
        ETH_LINK_10M    = 100b          ; 10 mbit
39
        ETH_LINK_10M    = 100b          ; 10 mbit
40
        ETH_LINK_100M   = 1000b         ; 100 mbit
40
        ETH_LINK_100M   = 1000b         ; 100 mbit
41
        ETH_LINK_1G     = 1100b         ; gigabit
41
        ETH_LINK_1G     = 1100b         ; gigabit
42
 
42
 
43
; Macro to easily set i/o addresses to access device.
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),
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.
45
; always use set_io with offset 0 to reset the variables.
46
 
46
 
47
        LAST_IO = 0
47
        LAST_IO = 0
48
 
48
 
49
macro   set_io  baseaddr, offset {
49
macro   set_io  baseaddr, offset {
50
 
50
 
51
        if      offset = 0
51
        if      offset = 0
52
        mov     edx, baseaddr
52
        mov     edx, baseaddr
53
        else if offset = LAST_IO
53
        else if offset = LAST_IO
54
        else
54
        else
55
        add     edx, offset - LAST_IO
55
        add     edx, offset - LAST_IO
56
        end if
56
        end if
57
 
57
 
58
        LAST_IO = offset
58
        LAST_IO = offset
59
}
59
}
60
 
60
 
61
; Macro to allocate a contiguous buffer in memory
61
; Macro to allocate a contiguous buffer in memory
62
; And initialise it to all zeros
62
; And initialise it to all zeros
63
 
63
 
64
; This macro will destroy eax, ecx and edi !
64
; This macro will destroy eax, ecx and edi !
65
 
65
 
66
macro   allocate_and_clear dest, size, err {
66
macro   allocate_and_clear dest, size, err {
67
 
67
 
68
; We need to allocate at least 8 pages, if we want a contiguous area in ram
68
; We need to allocate at least 8 pages, if we want a contiguous area in ram
69
        push    edx
69
        push    edx
70
    if (size < 8*4096) & (size > 4096)
70
    if (size < 8*4096) & (size > 4096)
71
        invoke  KernelAlloc, 8*4096
71
        invoke  KernelAlloc, 8*4096
72
    else
72
    else
73
        invoke  KernelAlloc, size
73
        invoke  KernelAlloc, size
74
    end if
74
    end if
75
        pop     edx
75
        pop     edx
76
 
76
 
77
        test    eax, eax
77
        test    eax, eax
78
        jz      err
78
        jz      err
79
        mov     dest, eax
79
        mov     dest, eax
80
        mov     edi, eax                ; look at last part of code!
80
        mov     edi, eax                ; look at last part of code!
81
 
81
 
82
; Release the unused pages (if any)
82
; Release the unused pages (if any)
83
    if (size < 8*4096) & (size > 4096)
83
    if (size < 8*4096) & (size > 4096)
84
        add     eax, (size/4096+1)*4096
84
        add     eax, (size/4096+1)*4096
85
        mov     ecx, 8-(size/4096+1)
85
        mov     ecx, 8-(size/4096+1)
86
        push    edx
86
        push    edx
87
        invoke  ReleasePages
87
        invoke  ReleasePages
88
        pop     edx
88
        pop     edx
89
    end if
89
    end if
90
 
90
 
91
; Clear the allocated buffer
91
; Clear the allocated buffer
92
        mov     ecx, size/4             ; divide by 4 because of DWORD
92
        mov     ecx, size/4             ; divide by 4 because of DWORD
93
        xor     eax, eax
93
        xor     eax, eax
94
        rep     stosd
94
        rep     stosd
95
 
95
 
96
     if (size - size/4*4)
96
     if (size - size/4*4)
97
        mov     ecx, size - size/4*4
97
        mov     ecx, size - size/4*4
98
        rep     stosb
98
        rep     stosb
99
     end if
99
     end if
100
 
100
 
101
}
101
}
102
 
102
 
103
 
103
 
104
struct  NET_DEVICE
104
struct  NET_DEVICE
105
 
105
 
106
        type            dd ?    ; Type field
106
        type            dd ?    ; Type field
107
        mtu             dd ?    ; Maximal Transmission Unit
107
        mtu             dd ?    ; Maximal Transmission Unit
108
        name            dd ?    ; Ptr to 0 terminated string
108
        name            dd ?    ; Ptr to 0 terminated string
109
 
109
 
110
        unload          dd ?    ; Ptrs to driver functions
110
        unload          dd ?    ; Ptrs to driver functions
111
        reset           dd ?    ;
111
        reset           dd ?    ;
112
        transmit        dd ?    ;
112
        transmit        dd ?    ;
113
 
113
 
114
        bytes_tx        dq ?    ; Statistics, updated by the driver
114
        bytes_tx        dq ?    ; Statistics, updated by the driver
115
        bytes_rx        dq ?    ;
115
        bytes_rx        dq ?    ;
116
        packets_tx      dd ?    ;
116
        packets_tx      dd ?    ;
117
        packets_rx      dd ?    ;
117
        packets_rx      dd ?    ;
118
 
118
 
119
        state           dd ?    ; link state (0 = no link)
119
        state           dd ?    ; link state (0 = no link)
120
        hwacc           dd ?    ; bitmask stating enabled HW accelerations
120
        hwacc           dd ?    ; bitmask stating enabled HW accelerations
121
 
121
 
122
ends
122
ends
123
 
123
 
124
 
124
 
125
struct  ETH_DEVICE      NET_DEVICE
125
struct  ETH_DEVICE      NET_DEVICE
126
 
126
 
127
        mac             dp ?
127
        mac             dp ?
128
                        dw ?    ; qword alignment
128
                        dw ?    ; qword alignment
129
 
129
 
130
ends
130
ends