Subversion Repositories Kolibri OS

Rev

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

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