Subversion Repositories Kolibri OS

Rev

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

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