Subversion Repositories Kolibri OS

Rev

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

Rev 5363 Rev 5522
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
2
;;                                                                 ;;
3
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved.    ;;
3
;; Copyright (C) KolibriOS team 2004-2015. 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
;;  FORCEDETH.INC                                                  ;;
6
;;  FORCEDETH.INC                                                  ;;
7
;;                                                                 ;;
7
;;                                                                 ;;
8
;;  Ethernet driver for Kolibri OS                                 ;;
8
;;  Ethernet driver for Kolibri OS                                 ;;
9
;;                                                                 ;;
9
;;                                                                 ;;
10
;;  Driver for chips of NVIDIA nForce2                             ;;
10
;;  Driver for chips of NVIDIA nForce2                             ;;
11
;;  References:                                                    ;;
11
;;  References:                                                    ;;
12
;;    forcedeth.c - linux driver (etherboot project)               ;;
12
;;    forcedeth.c - linux driver (etherboot project)               ;;
13
;;    ethernet driver template by Mike Hibbett                     ;;
13
;;    ethernet driver template by Mike Hibbett                     ;;
14
;;                                                                 ;;
14
;;                                                                 ;;
15
;;  The copyright statement is                                     ;;
15
;;  The copyright statement is                                     ;;
16
;;                                                                 ;;
16
;;                                                                 ;;
17
;;          GNU GENERAL PUBLIC LICENSE                             ;;
17
;;          GNU GENERAL PUBLIC LICENSE                             ;;
18
;;             Version 2, June 1991                                ;;
18
;;             Version 2, June 1991                                ;;
19
;;                                                                 ;;
19
;;                                                                 ;;
20
;;  Copyright 2008 shurf,                                          ;;
20
;;  Copyright 2008 shurf,                                          ;;
21
;;   cit.utc@gmail.com                                             ;;
21
;;   cit.utc@gmail.com                                             ;;
22
;;                                                                 ;;
22
;;                                                                 ;;
23
;;  See file COPYING for details                                   ;;
23
;;  See file COPYING for details                                   ;;
24
;;                                                                 ;;
24
;;                                                                 ;;
25
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
25
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
26
 
26
 
27
 
27
 
28
format PE DLL native
28
format PE DLL native
29
entry START
29
entry START
30
 
30
 
31
        CURRENT_API             = 0x0200
31
        CURRENT_API             = 0x0200
32
        COMPATIBLE_API          = 0x0100
32
        COMPATIBLE_API          = 0x0100
33
        API_VERSION             = (COMPATIBLE_API shl 16) + CURRENT_API
33
        API_VERSION             = (COMPATIBLE_API shl 16) + CURRENT_API
34
 
34
 
35
        MAX_DEVICES             = 16
35
        MAX_DEVICES             = 16
36
 
36
 
37
        RBLEN                   = 0     ; Receive buffer size: 0=4K 1=8k 2=16k 3=32k 4=64k
37
        RBLEN                   = 0     ; Receive buffer size: 0=4K 1=8k 2=16k 3=32k 4=64k
38
                                        ; FIXME: option 1 and 2 will not allocate buffer correctly causing data loss!
38
                                        ; FIXME: option 1 and 2 may allocate a non contiguous buffer causing data loss!
39
 
39
 
40
        DEBUG                   = 1
40
        DEBUG                   = 1
41
        __DEBUG__               = 1
41
        __DEBUG__               = 1
42
        __DEBUG_LEVEL__         = 2
42
        __DEBUG_LEVEL__         = 2
43
 
43
 
44
        RX_RING                 = 4
44
        RX_RING                 = 4
45
        TX_RING                 = 4
45
        TX_RING                 = 4
46
 
46
 
47
section '.flat' readable writable executable
47
section '.flat' readable writable executable
48
 
48
 
49
include '../proc32.inc'
49
include '../proc32.inc'
50
include '../struct.inc'
50
include '../struct.inc'
51
include '../macros.inc'
51
include '../macros.inc'
52
include '../fdo.inc'
52
include '../fdo.inc'
53
include '../netdrv.inc'
53
include '../netdrv.inc'
54
include '../mii.inc'
54
include '../mii.inc'
55
 
55
 
56
;**************************************************************************
56
;**************************************************************************
57
; forcedeth Register Definitions
57
; forcedeth Register Definitions
58
;**************************************************************************
58
;**************************************************************************
59
 
59
 
60
PCI_DEVICE_ID_NVIDIA_NVENET_1   = 0x01c3
60
PCI_DEVICE_ID_NVIDIA_NVENET_1   = 0x01c3
61
PCI_DEVICE_ID_NVIDIA_NVENET_2   = 0x0066
61
PCI_DEVICE_ID_NVIDIA_NVENET_2   = 0x0066
62
PCI_DEVICE_ID_NVIDIA_NVENET_4   = 0x0086
62
PCI_DEVICE_ID_NVIDIA_NVENET_4   = 0x0086
63
PCI_DEVICE_ID_NVIDIA_NVENET_5   = 0x008c
63
PCI_DEVICE_ID_NVIDIA_NVENET_5   = 0x008c
64
PCI_DEVICE_ID_NVIDIA_NVENET_3   = 0x00d6
64
PCI_DEVICE_ID_NVIDIA_NVENET_3   = 0x00d6
65
PCI_DEVICE_ID_NVIDIA_NVENET_7   = 0x00df
65
PCI_DEVICE_ID_NVIDIA_NVENET_7   = 0x00df
66
PCI_DEVICE_ID_NVIDIA_NVENET_6   = 0x00e6
66
PCI_DEVICE_ID_NVIDIA_NVENET_6   = 0x00e6
67
PCI_DEVICE_ID_NVIDIA_NVENET_8   = 0x0056
67
PCI_DEVICE_ID_NVIDIA_NVENET_8   = 0x0056
68
PCI_DEVICE_ID_NVIDIA_NVENET_9   = 0x0057
68
PCI_DEVICE_ID_NVIDIA_NVENET_9   = 0x0057
69
PCI_DEVICE_ID_NVIDIA_NVENET_10  = 0x0037
69
PCI_DEVICE_ID_NVIDIA_NVENET_10  = 0x0037
70
PCI_DEVICE_ID_NVIDIA_NVENET_11  = 0x0038
70
PCI_DEVICE_ID_NVIDIA_NVENET_11  = 0x0038
71
PCI_DEVICE_ID_NVIDIA_NVENET_12  = 0x0268
71
PCI_DEVICE_ID_NVIDIA_NVENET_12  = 0x0268
72
PCI_DEVICE_ID_NVIDIA_NVENET_13  = 0x0269
72
PCI_DEVICE_ID_NVIDIA_NVENET_13  = 0x0269
73
PCI_DEVICE_ID_NVIDIA_NVENET_14  = 0x0372
73
PCI_DEVICE_ID_NVIDIA_NVENET_14  = 0x0372
74
PCI_DEVICE_ID_NVIDIA_NVENET_15  = 0x0373
74
PCI_DEVICE_ID_NVIDIA_NVENET_15  = 0x0373
75
 
75
 
76
UNKSETUP1_VAL             = 0x16070f
76
UNKSETUP1_VAL             = 0x16070f
77
UNKSETUP2_VAL             = 0x16
77
UNKSETUP2_VAL             = 0x16
78
UNKSETUP3_VAL1            = 0x200010
78
UNKSETUP3_VAL1            = 0x200010
79
UNKSETUP4_VAL             = 8
79
UNKSETUP4_VAL             = 8
80
UNKSETUP5_BIT31           = (1 shl 31)
80
UNKSETUP5_BIT31           = (1 shl 31)
81
UNKSETUP6_VAL             = 3
81
UNKSETUP6_VAL             = 3
82
 
82
 
83
TXRXCTL_RXCHECK           = 0x0400
83
TXRXCTL_RXCHECK           = 0x0400
84
MIISTAT_ERROR             = 0x0001
84
MIISTAT_ERROR             = 0x0001
85
MIISTAT_MASK              = 0x000f
85
MIISTAT_MASK              = 0x000f
86
MIISTAT_MASK2             = 0x000f
86
MIISTAT_MASK2             = 0x000f
87
MIICTL_INUSE              = 0x08000
87
MIICTL_INUSE              = 0x08000
88
MIICTL_WRITE              = 0x00400
88
MIICTL_WRITE              = 0x00400
89
MIICTL_ADDRSHIFT          = 5
89
MIICTL_ADDRSHIFT          = 5
90
 
90
 
91
MIISPEED_BIT8             = (1 shl 8)
91
MIISPEED_BIT8             = (1 shl 8)
92
MIIDELAY                  = 5
92
MIIDELAY                  = 5
93
 
93
 
94
IRQ_RX_ERROR              = 0x0001
94
IRQ_RX_ERROR              = 0x0001
95
IRQ_RX                    = 0x0002
95
IRQ_RX                    = 0x0002
96
IRQ_RX_NOBUF              = 0x0004
96
IRQ_RX_NOBUF              = 0x0004
97
IRQ_TX_ERROR              = 0x0008
97
IRQ_TX_ERROR              = 0x0008
98
IRQ_TX_OK                 = 0x0010
98
IRQ_TX_OK                 = 0x0010
99
IRQ_TIMER                 = 0x0020
99
IRQ_TIMER                 = 0x0020
100
IRQ_LINK                  = 0x0040
100
IRQ_LINK                  = 0x0040
101
IRQ_RX_FORCED             = 0x0080
101
IRQ_RX_FORCED             = 0x0080
102
IRQ_TX_FORCED             = 0x0100
102
IRQ_TX_FORCED             = 0x0100
103
IRQ_RECOVER_ERROR         = 0x8200                                           ;
103
IRQ_RECOVER_ERROR         = 0x8200                                           ;
104
IRQMASK_WANTED_2          = IRQ_TX_FORCED + IRQ_LINK + IRQ_RX_ERROR + IRQ_RX + IRQ_TX_OK + IRQ_TX_ERROR
104
IRQMASK_WANTED_2          = IRQ_TX_FORCED + IRQ_LINK + IRQ_RX_ERROR + IRQ_RX + IRQ_TX_OK + IRQ_TX_ERROR
105
 
105
 
106
IRQ_RX_ALL                = IRQ_RX_ERROR or IRQ_RX or IRQ_RX_NOBUF or IRQ_RX_FORCED
106
IRQ_RX_ALL                = IRQ_RX_ERROR or IRQ_RX or IRQ_RX_NOBUF or IRQ_RX_FORCED
107
IRQ_TX_ALL                = IRQ_TX_ERROR or IRQ_TX_OK or IRQ_TX_FORCED
107
IRQ_TX_ALL                = IRQ_TX_ERROR or IRQ_TX_OK or IRQ_TX_FORCED
108
IRQ_OTHER                 = IRQ_LINK or IRQ_TIMER or IRQ_RECOVER_ERROR
108
IRQ_OTHER                 = IRQ_LINK or IRQ_TIMER or IRQ_RECOVER_ERROR
109
 
109
 
110
IRQSTAT_MASK              = 0x1ff
110
IRQSTAT_MASK              = 0x1ff
111
 
111
 
112
TXRXCTL_KICK              = 0x0001
112
TXRXCTL_KICK              = 0x0001
113
TXRXCTL_BIT1              = 0x0002
113
TXRXCTL_BIT1              = 0x0002
114
TXRXCTL_BIT2              = 0x0004
114
TXRXCTL_BIT2              = 0x0004
115
TXRXCTL_IDLE              = 0x0008
115
TXRXCTL_IDLE              = 0x0008
116
TXRXCTL_RESET             = 0x0010
116
TXRXCTL_RESET             = 0x0010
117
TXRXCTL_RXCHECK           = 0x0400
117
TXRXCTL_RXCHECK           = 0x0400
118
 
118
 
119
MCASTADDRA_FORCE          = 0x01
119
MCASTADDRA_FORCE          = 0x01
120
 
120
 
121
MAC_RESET_ASSERT          = 0x0F3
121
MAC_RESET_ASSERT          = 0x0F3
122
 
122
 
123
MISC1_HD                  = 0x02
123
MISC1_HD                  = 0x02
124
MISC1_FORCE               = 0x3b0f3c
124
MISC1_FORCE               = 0x3b0f3c
125
 
125
 
126
PFF_ALWAYS                = 0x7F0008
126
PFF_ALWAYS                = 0x7F0008
127
PFF_PROMISC               = 0x80
127
PFF_PROMISC               = 0x80
128
PFF_MYADDR                = 0x20
128
PFF_MYADDR                = 0x20
129
 
129
 
130
OFFLOAD_HOMEPHY           = 0x601
130
OFFLOAD_HOMEPHY           = 0x601
131
OFFLOAD_NORMAL            = 4096 shl RBLEN
131
OFFLOAD_NORMAL            = 4096 shl RBLEN
132
 
132
 
133
RNDSEED_MASK              = 0x00ff
133
RNDSEED_MASK              = 0x00ff
134
RNDSEED_FORCE             = 0x7f00
134
RNDSEED_FORCE             = 0x7f00
135
RNDSEED_FORCE2            = 0x2d00
135
RNDSEED_FORCE2            = 0x2d00
136
RNDSEED_FORCE3            = 0x7400
136
RNDSEED_FORCE3            = 0x7400
137
 
137
 
138
; POLL_DEFAULT is the interval length of the timer source on the nic
138
; POLL_DEFAULT is the interval length of the timer source on the nic
139
; POLL_DEFAULT=97 would result in an interval length of 1 ms
139
; POLL_DEFAULT=97 would result in an interval length of 1 ms
140
POLL_DEFAULT              = 970
140
POLL_DEFAULT              = 970
141
 
141
 
142
ADAPTCTL_START            = 0x02
142
ADAPTCTL_START            = 0x02
143
ADAPTCTL_LINKUP           = 0x04
143
ADAPTCTL_LINKUP           = 0x04
144
ADAPTCTL_PHYVALID         = 0x40000
144
ADAPTCTL_PHYVALID         = 0x40000
145
ADAPTCTL_RUNNING          = 0x100000
145
ADAPTCTL_RUNNING          = 0x100000
146
ADAPTCTL_PHYSHIFT         = 24
146
ADAPTCTL_PHYSHIFT         = 24
147
 
147
 
148
WAKEUPFLAGS_VAL           = 0x7770
148
WAKEUPFLAGS_VAL           = 0x7770
149
 
149
 
150
POWERSTATE_POWEREDUP      = 0x8000
150
POWERSTATE_POWEREDUP      = 0x8000
151
POWERSTATE_VALID          = 0x0100
151
POWERSTATE_VALID          = 0x0100
152
POWERSTATE_MASK           = 0x0003
152
POWERSTATE_MASK           = 0x0003
153
POWERSTATE_D0             = 0x0000
153
POWERSTATE_D0             = 0x0000
154
POWERSTATE_D1             = 0x0001
154
POWERSTATE_D1             = 0x0001
155
POWERSTATE_D2             = 0x0002
155
POWERSTATE_D2             = 0x0002
156
POWERSTATE_D3             = 0x0003
156
POWERSTATE_D3             = 0x0003
157
 
157
 
158
POWERSTATE2_POWERUP_MASK  = 0x0F11
158
POWERSTATE2_POWERUP_MASK  = 0x0F11
159
POWERSTATE2_POWERUP_REV_A3= 0x0001
159
POWERSTATE2_POWERUP_REV_A3= 0x0001
160
 
160
 
161
RCVCTL_START              = 0x01
161
RCVCTL_START              = 0x01
162
RCVSTAT_BUSY              = 0x01
162
RCVSTAT_BUSY              = 0x01
163
 
163
 
164
XMITCTL_START             = 0x01
164
XMITCTL_START             = 0x01
165
 
165
 
166
LINKSPEED_FORCE           = 0x10000
166
LINKSPEED_FORCE           = 0x10000
167
LINKSPEED_10              = 1000
167
LINKSPEED_10              = 1000
168
LINKSPEED_100             = 100
168
LINKSPEED_100             = 100
169
LINKSPEED_1000            = 50
169
LINKSPEED_1000            = 50
170
 
170
 
171
RINGSZ_TXSHIFT            = 0
171
RINGSZ_TXSHIFT            = 0
172
RINGSZ_RXSHIFT            = 16
172
RINGSZ_RXSHIFT            = 16
173
 
173
 
174
LPA_1000FULL                    = 0x0800
174
LPA_1000FULL                    = 0x0800
175
 
175
 
176
; Link partner ability register.
176
; Link partner ability register.
177
LPA_SLCT                        = 0x001f  ; Same as advertise selector
177
LPA_SLCT                        = 0x001f  ; Same as advertise selector
178
LPA_10HALF                      = 0x0020  ; Can do 10mbps half-duplex
178
LPA_10HALF                      = 0x0020  ; Can do 10mbps half-duplex
179
LPA_10FULL                      = 0x0040  ; Can do 10mbps full-duplex
179
LPA_10FULL                      = 0x0040  ; Can do 10mbps full-duplex
180
LPA_100HALF                     = 0x0080  ; Can do 100mbps half-duplex
180
LPA_100HALF                     = 0x0080  ; Can do 100mbps half-duplex
181
LPA_100FULL                     = 0x0100  ; Can do 100mbps full-duplex
181
LPA_100FULL                     = 0x0100  ; Can do 100mbps full-duplex
182
LPA_100BASE4                    = 0x0200  ; Can do 100mbps 4k packets
182
LPA_100BASE4                    = 0x0200  ; Can do 100mbps 4k packets
183
LPA_RESV                        = 0x1c00  ; Unused...
183
LPA_RESV                        = 0x1c00  ; Unused...
184
LPA_RFAULT                      = 0x2000  ; Link partner faulted
184
LPA_RFAULT                      = 0x2000  ; Link partner faulted
185
LPA_LPACK                       = 0x4000  ; Link partner acked us
185
LPA_LPACK                       = 0x4000  ; Link partner acked us
186
LPA_NPAGE                       = 0x8000  ; Next page bit
186
LPA_NPAGE                       = 0x8000  ; Next page bit
187
 
187
 
188
MII_READ                        = (-1)
188
MII_READ                        = (-1)
189
MII_PHYSID1                     = 0x02    ; PHYS ID 1
189
MII_PHYSID1                     = 0x02    ; PHYS ID 1
190
MII_PHYSID2                     = 0x03    ; PHYS ID 2
190
MII_PHYSID2                     = 0x03    ; PHYS ID 2
191
MII_BMCR                        = 0x00    ; Basic mode control register
191
MII_BMCR                        = 0x00    ; Basic mode control register
192
MII_BMSR                        = 0x01    ; Basic mode status register
192
MII_BMSR                        = 0x01    ; Basic mode status register
193
MII_ADVERTISE                   = 0x04    ; Advertisement control reg
193
MII_ADVERTISE                   = 0x04    ; Advertisement control reg
194
MII_LPA                         = 0x05    ; Link partner ability reg
194
MII_LPA                         = 0x05    ; Link partner ability reg
195
MII_SREVISION                   = 0x16    ; Silicon revision
195
MII_SREVISION                   = 0x16    ; Silicon revision
196
MII_RESV1                       = 0x17    ; Reserved...
196
MII_RESV1                       = 0x17    ; Reserved...
197
MII_NCONFIG                     = 0x1c    ; Network interface config
197
MII_NCONFIG                     = 0x1c    ; Network interface config
198
 
198
 
199
; PHY defines
199
; PHY defines
200
PHY_OUI_MARVELL                 = 0x5043
200
PHY_OUI_MARVELL                 = 0x5043
201
PHY_OUI_CICADA                  = 0x03f1
201
PHY_OUI_CICADA                  = 0x03f1
202
PHYID1_OUI_MASK                 = 0x03ff
202
PHYID1_OUI_MASK                 = 0x03ff
203
PHYID1_OUI_SHFT                 = 6
203
PHYID1_OUI_SHFT                 = 6
204
PHYID2_OUI_MASK                 = 0xfc00
204
PHYID2_OUI_MASK                 = 0xfc00
205
PHYID2_OUI_SHFT                 = 10
205
PHYID2_OUI_SHFT                 = 10
206
PHY_INIT1                       = 0x0f000
206
PHY_INIT1                       = 0x0f000
207
PHY_INIT2                       = 0x0e00
207
PHY_INIT2                       = 0x0e00
208
PHY_INIT3                       = 0x01000
208
PHY_INIT3                       = 0x01000
209
PHY_INIT4                       = 0x0200
209
PHY_INIT4                       = 0x0200
210
PHY_INIT5                       = 0x0004
210
PHY_INIT5                       = 0x0004
211
PHY_INIT6                       = 0x02000
211
PHY_INIT6                       = 0x02000
212
PHY_GIGABIT                     = 0x0100
212
PHY_GIGABIT                     = 0x0100
213
 
213
 
214
PHY_TIMEOUT                     = 0x1
214
PHY_TIMEOUT                     = 0x1
215
PHY_ERROR                       = 0x2
215
PHY_ERROR                       = 0x2
216
 
216
 
217
PHY_100                         = 0x1
217
PHY_100                         = 0x1
218
PHY_1000                        = 0x2
218
PHY_1000                        = 0x2
219
PHY_HALF                        = 0x100
219
PHY_HALF                        = 0x100
220
 
220
 
221
PHY_RGMII                       = 0x10000000
221
PHY_RGMII                       = 0x10000000
222
 
222
 
223
; desc_ver values:
223
; desc_ver values:
224
; This field has two purposes:
224
; This field has two purposes:
225
; - Newer nics uses a different ring layout. The layout is selected by
225
; - Newer nics uses a different ring layout. The layout is selected by
226
;   comparing np->desc_ver with DESC_VER_xy.
226
;   comparing np->desc_ver with DESC_VER_xy.
227
; - It contains bits that are forced on when writing to TxRxControl.
227
; - It contains bits that are forced on when writing to TxRxControl.
228
DESC_VER_1                      = 0x0
228
DESC_VER_1                      = 0x0
229
DESC_VER_2                      = (0x02100 or TXRXCTL_RXCHECK)
229
DESC_VER_2                      = (0x02100 or TXRXCTL_RXCHECK)
230
 
230
 
231
NV_TX_LASTPACKET                = (1 shl 16)
231
NV_TX_LASTPACKET                = (1 shl 16)
232
NV_TX_RETRYERROR                = (1 shl 19)
232
NV_TX_RETRYERROR                = (1 shl 19)
233
NV_TX_LASTPACKET1               = (1 shl 24)
233
NV_TX_LASTPACKET1               = (1 shl 24)
234
NV_TX_DEFERRED                  = (1 shl 26)
234
NV_TX_DEFERRED                  = (1 shl 26)
235
NV_TX_CARRIERLOST               = (1 shl 27)
235
NV_TX_CARRIERLOST               = (1 shl 27)
236
NV_TX_LATECOLLISION             = (1 shl 28)
236
NV_TX_LATECOLLISION             = (1 shl 28)
237
NV_TX_UNDERFLOW                 = (1 shl 29)
237
NV_TX_UNDERFLOW                 = (1 shl 29)
238
NV_TX_ERROR                     = (1 shl 30)
238
NV_TX_ERROR                     = (1 shl 30)
239
NV_TX_VALID                     = (1 shl 31)
239
NV_TX_VALID                     = (1 shl 31)
240
 
240
 
241
NV_TX2_LASTPACKET               = (1 shl 29)
241
NV_TX2_LASTPACKET               = (1 shl 29)
242
NV_TX2_RETRYERROR               = (1 shl 18)
242
NV_TX2_RETRYERROR               = (1 shl 18)
243
NV_TX2_LASTPACKET1              = (1 shl 23)
243
NV_TX2_LASTPACKET1              = (1 shl 23)
244
NV_TX2_DEFERRED                 = (1 shl 25)
244
NV_TX2_DEFERRED                 = (1 shl 25)
245
NV_TX2_CARRIERLOST              = (1 shl 26)
245
NV_TX2_CARRIERLOST              = (1 shl 26)
246
NV_TX2_LATECOLLISION            = (1 shl 27)
246
NV_TX2_LATECOLLISION            = (1 shl 27)
247
NV_TX2_UNDERFLOW                = (1 shl 28)
247
NV_TX2_UNDERFLOW                = (1 shl 28)
248
; error and valid are the same for both
248
; error and valid are the same for both
249
NV_TX2_ERROR                    = (1 shl 30)
249
NV_TX2_ERROR                    = (1 shl 30)
250
NV_TX2_VALID                    = (1 shl 31)
250
NV_TX2_VALID                    = (1 shl 31)
251
 
251
 
252
NV_RX_DESCRIPTORVALID           = (1 shl 16)
252
NV_RX_DESCRIPTORVALID           = (1 shl 16)
253
NV_RX_AVAIL                     = (1 shl 31)
253
NV_RX_AVAIL                     = (1 shl 31)
254
 
254
 
255
NV_RX2_DESCRIPTORVALID          = (1 shl 29)
255
NV_RX2_DESCRIPTORVALID          = (1 shl 29)
256
 
256
 
257
FLAG_MASK_V1                    = 0xffff0000
257
FLAG_MASK_V1                    = 0xffff0000
258
FLAG_MASK_V2                    = 0xffffc000
258
FLAG_MASK_V2                    = 0xffffc000
259
LEN_MASK_V1                     = (0xffffffff xor FLAG_MASK_V1)
259
LEN_MASK_V1                     = (0xffffffff xor FLAG_MASK_V1)
260
LEN_MASK_V2                     = (0xffffffff xor FLAG_MASK_V2)
260
LEN_MASK_V2                     = (0xffffffff xor FLAG_MASK_V2)
261
 
261
 
262
; Miscelaneous hardware related defines:
262
; Miscelaneous hardware related defines:
263
NV_PCI_REGSZ_VER1               = 0x270
263
NV_PCI_REGSZ_VER1               = 0x270
264
NV_PCI_REGSZ_VER2               = 0x604
264
NV_PCI_REGSZ_VER2               = 0x604
265
; various timeout delays: all in usec
265
; various timeout delays: all in usec
266
NV_TXRX_RESET_DELAY             = 4
266
NV_TXRX_RESET_DELAY             = 4
267
NV_TXSTOP_DELAY1                = 10
267
NV_TXSTOP_DELAY1                = 10
268
NV_TXSTOP_DELAY1MAX             = 500000
268
NV_TXSTOP_DELAY1MAX             = 500000
269
NV_TXSTOP_DELAY2                = 100
269
NV_TXSTOP_DELAY2                = 100
270
NV_RXSTOP_DELAY1                = 10
270
NV_RXSTOP_DELAY1                = 10
271
NV_RXSTOP_DELAY1MAX             = 500000
271
NV_RXSTOP_DELAY1MAX             = 500000
272
NV_RXSTOP_DELAY2                = 100
272
NV_RXSTOP_DELAY2                = 100
273
NV_SETUP5_DELAY                 = 5
273
NV_SETUP5_DELAY                 = 5
274
NV_SETUP5_DELAYMAX              = 50000
274
NV_SETUP5_DELAYMAX              = 50000
275
NV_POWERUP_DELAY                = 5
275
NV_POWERUP_DELAY                = 5
276
NV_POWERUP_DELAYMAX             = 5000
276
NV_POWERUP_DELAYMAX             = 5000
277
NV_MIIBUSY_DELAY                = 50
277
NV_MIIBUSY_DELAY                = 50
278
NV_MIIPHY_DELAY                 = 10
278
NV_MIIPHY_DELAY                 = 10
279
NV_MIIPHY_DELAYMAX              = 10000
279
NV_MIIPHY_DELAYMAX              = 10000
280
NV_MAC_RESET_DELAY              = 64
280
NV_MAC_RESET_DELAY              = 64
281
NV_WAKEUPPATTERNS               = 5
281
NV_WAKEUPPATTERNS               = 5
282
NV_WAKEUPMASKENTRIES            = 4
282
NV_WAKEUPMASKENTRIES            = 4
283
 
283
 
284
struct  TxDesc
284
struct  TxDesc
285
        PacketBuffer            dd ?
285
        PacketBuffer            dd ?
286
        FlagLen                 dd ?
286
        FlagLen                 dd ?
287
ends
287
ends
288
 
288
 
289
struct  RxDesc
289
struct  RxDesc
290
        PacketBuffer            dd ?
290
        PacketBuffer            dd ?
291
        FlagLen                 dd ?
291
        FlagLen                 dd ?
292
ends
292
ends
293
 
293
 
294
struct  device                  ETH_DEVICE
294
struct  device                  ETH_DEVICE
295
 
295
 
296
        pci_bus                 dd ?
296
        pci_bus                 dd ?
297
        pci_dev                 dd ?
297
        pci_dev                 dd ?
298
 
298
 
299
        mmio_addr               dd ?
299
        mmio_addr               dd ?
300
        vendor_id               dw ?
300
        vendor_id               dw ?
301
        device_id               dw ?
301
        device_id               dw ?
302
        txflags                 dd ?
302
        txflags                 dd ?
303
        desc_ver                dd ?
303
        desc_ver                dd ?
304
        irqmask                 dd ?
304
        irqmask                 dd ?
305
        wolenabled              dd ?
305
        wolenabled              dd ?
306
        in_shutdown             dd ?
306
        in_shutdown             dd ?
307
        cur_rx                  dd ?
307
        cur_rx                  dd ?
308
        cur_tx                  dd ?
308
        cur_tx                  dd ?
309
        last_tx                 dd ?
309
        last_tx                 dd ?
310
        phyaddr                 dd ?
310
        phyaddr                 dd ?
311
        phy_oui                 dd ?
311
        phy_oui                 dd ?
312
        gigabit                 dd ?
312
        gigabit                 dd ?
313
        needs_mac_reset         dd ?
313
        needs_mac_reset         dd ?
314
        linkspeed               dd ?
314
        linkspeed               dd ?
315
        duplex                  dd ?
315
        duplex                  dd ?
316
        nocable                 dd ?
316
        nocable                 dd ?
317
 
317
 
318
                                rb 0x100 - ($ and 0xff)
318
                                rb 0x100 - ($ and 0xff)
319
        tx_ring                 rd (TX_RING * sizeof.TxDesc) /4*2
319
        tx_ring                 rd (TX_RING * sizeof.TxDesc) /4*2
320
 
320
 
321
                                rb 0x100 - ($ and 0xff)
321
                                rb 0x100 - ($ and 0xff)
322
        rx_ring                 rd (RX_RING * sizeof.RxDesc) /4*2
322
        rx_ring                 rd (RX_RING * sizeof.RxDesc) /4*2
323
 
323
 
324
ends
324
ends
325
 
325
 
326
 
326
 
327
 
327
 
328
virtual at edi
328
virtual at edi
329
        IrqStatus               dd ?
329
        IrqStatus               dd ?
330
        IrqMask                 dd ?
330
        IrqMask                 dd ?
331
        UnknownSetupReg6        dd ?
331
        UnknownSetupReg6        dd ?
332
        PollingInterval         dd ?
332
        PollingInterval         dd ?
333
end virtual
333
end virtual
334
 
334
 
335
virtual at edi + 0x3c
335
virtual at edi + 0x3c
336
        MacReset                dd ?
336
        MacReset                dd ?
337
end virtual
337
end virtual
338
 
338
 
339
virtual at edi + 0x80
339
virtual at edi + 0x80
340
        Misc1                   dd ?
340
        Misc1                   dd ?
341
        TransmitterControl      dd ?
341
        TransmitterControl      dd ?
342
        TransmitterStatus       dd ?
342
        TransmitterStatus       dd ?
343
        PacketFilterFlags       dd ?
343
        PacketFilterFlags       dd ?
344
        OffloadConfig           dd ?
344
        OffloadConfig           dd ?
345
        ReceiverControl         dd ?
345
        ReceiverControl         dd ?
346
        ReceiverStatus          dd ?
346
        ReceiverStatus          dd ?
347
        RandomSeed              dd ?
347
        RandomSeed              dd ?
348
        UnknownSetupReg1        dd ?
348
        UnknownSetupReg1        dd ?
349
        UnknownSetupReg2        dd ?
349
        UnknownSetupReg2        dd ?
350
        MacAddrA                dd ?
350
        MacAddrA                dd ?
351
        MacAddrB                dd ?
351
        MacAddrB                dd ?
352
        MulticastAddrA          dd ?
352
        MulticastAddrA          dd ?
353
        MulticastAddrB          dd ?
353
        MulticastAddrB          dd ?
354
        MulticastMaskA          dd ?
354
        MulticastMaskA          dd ?
355
        MulticastMaskB          dd ?
355
        MulticastMaskB          dd ?
356
        PhyInterface            dd ?
356
        PhyInterface            dd ?
357
end virtual
357
end virtual
358
 
358
 
359
virtual at edi + 0x100
359
virtual at edi + 0x100
360
        TxRingPhysAddr          dd ?
360
        TxRingPhysAddr          dd ?
361
        RxRingPhysAddr          dd ?
361
        RxRingPhysAddr          dd ?
362
        RingSizes               dd ?
362
        RingSizes               dd ?
363
        UnknownTransmitterReg   dd ?
363
        UnknownTransmitterReg   dd ?
364
        LinkSpeed               dd ?
364
        LinkSpeed               dd ?
365
end virtual
365
end virtual
366
 
366
 
367
virtual at edi + 0x130
367
virtual at edi + 0x130
368
        UnknownSetupReg5        dd ?
368
        UnknownSetupReg5        dd ?
369
end virtual
369
end virtual
370
 
370
 
371
virtual at edi + 0x13c
371
virtual at edi + 0x13c
372
        UnknownSetupReg3        dd ?
372
        UnknownSetupReg3        dd ?
373
end virtual
373
end virtual
374
 
374
 
375
virtual at edi + 0x144
375
virtual at edi + 0x144
376
        TxRxControl             dd ?
376
        TxRxControl             dd ?
377
end virtual
377
end virtual
378
 
378
 
379
virtual at edi + 0x180
379
virtual at edi + 0x180
380
        MIIStatus               dd ?
380
        MIIStatus               dd ?
381
        UnknownSetupReg4        dd ?
381
        UnknownSetupReg4        dd ?
382
        AdapterControl          dd ?
382
        AdapterControl          dd ?
383
        MIISpeed                dd ?
383
        MIISpeed                dd ?
384
        MIIControl              dd ?
384
        MIIControl              dd ?
385
        MIIData                 dd ?
385
        MIIData                 dd ?
386
end virtual
386
end virtual
387
 
387
 
388
virtual at edi + 0x200
388
virtual at edi + 0x200
389
        WakeUpFlags             dd ?
389
        WakeUpFlags             dd ?
390
end virtual
390
end virtual
391
 
391
 
392
virtual at edi + 0x26c
392
virtual at edi + 0x26c
393
        PowerState              dd ?
393
        PowerState              dd ?
394
end virtual
394
end virtual
395
 
395
 
396
virtual at edi + 0x600
396
virtual at edi + 0x600
397
        PowerState2             dd ?
397
        PowerState2             dd ?
398
end virtual
398
end virtual
399
 
399
 
400
 
400
 
401
 
401
 
402
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
402
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
403
;;                        ;;
403
;;                        ;;
404
;; proc START             ;;
404
;; proc START             ;;
405
;;                        ;;
405
;;                        ;;
406
;; (standard driver proc) ;;
406
;; (standard driver proc) ;;
407
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
407
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
408
 
408
 
409
proc START c, reason:dword, cmdline:dword
409
proc START c, reason:dword, cmdline:dword
410
 
410
 
411
        cmp     [reason], DRV_ENTRY
411
        cmp     [reason], DRV_ENTRY
412
        jne     .fail
412
        jne     .fail
413
 
413
 
414
        DEBUGF  2,"Loading driver\n"
414
        DEBUGF  2,"Loading driver\n"
415
        invoke  RegService, my_service, service_proc
415
        invoke  RegService, my_service, service_proc
416
        ret
416
        ret
417
 
417
 
418
  .fail:
418
  .fail:
419
        xor     eax, eax
419
        xor     eax, eax
420
        ret
420
        ret
421
 
421
 
422
endp
422
endp
423
 
423
 
424
 
424
 
425
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
425
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
426
;;                        ;;
426
;;                        ;;
427
;; proc SERVICE_PROC      ;;
427
;; proc SERVICE_PROC      ;;
428
;;                        ;;
428
;;                        ;;
429
;; (standard driver proc) ;;
429
;; (standard driver proc) ;;
430
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
430
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
431
 
431
 
432
proc service_proc stdcall, ioctl:dword
432
proc service_proc stdcall, ioctl:dword
433
 
433
 
434
        mov     edx, [ioctl]
434
        mov     edx, [ioctl]
435
        mov     eax, [edx + IOCTL.io_code]
435
        mov     eax, [edx + IOCTL.io_code]
436
 
436
 
437
;------------------------------------------------------
437
;------------------------------------------------------
438
 
438
 
439
        cmp     eax, 0 ;SRV_GETVERSION
439
        cmp     eax, 0 ;SRV_GETVERSION
440
        jne     @F
440
        jne     @F
441
 
441
 
442
        cmp     [edx + IOCTL.out_size], 4
442
        cmp     [edx + IOCTL.out_size], 4
443
        jb      .fail
443
        jb      .fail
444
        mov     eax, [edx + IOCTL.output]
444
        mov     eax, [edx + IOCTL.output]
445
        mov     [eax], dword API_VERSION
445
        mov     [eax], dword API_VERSION
446
 
446
 
447
        xor     eax, eax
447
        xor     eax, eax
448
        ret
448
        ret
449
 
449
 
450
;------------------------------------------------------
450
;------------------------------------------------------
451
  @@:
451
  @@:
452
        cmp     eax, 1 ;SRV_HOOK
452
        cmp     eax, 1 ;SRV_HOOK
453
        jne     .fail
453
        jne     .fail
454
 
454
 
455
        cmp     [edx + IOCTL.inp_size], 3               ; Data input must be at least 3 bytes
455
        cmp     [edx + IOCTL.inp_size], 3               ; Data input must be at least 3 bytes
456
        jb      .fail
456
        jb      .fail
457
 
457
 
458
        mov     eax, [edx + IOCTL.input]
458
        mov     eax, [edx + IOCTL.input]
459
        cmp     byte [eax], 1                           ; 1 means device number and bus number (pci) are given
459
        cmp     byte [eax], 1                           ; 1 means device number and bus number (pci) are given
460
        jne     .fail                                   ; other types arent supported for this card yet
460
        jne     .fail                                   ; other types arent supported for this card yet
461
 
461
 
462
; check if the device is already listed
462
; check if the device is already listed
463
 
463
 
464
        mov     esi, device_list
464
        mov     esi, device_list
465
        mov     ecx, [devices]
465
        mov     ecx, [devices]
466
        test    ecx, ecx
466
        test    ecx, ecx
467
        jz      .firstdevice
467
        jz      .firstdevice
468
 
468
 
469
;        mov     eax, [edx + IOCTL.input]                ; get the pci bus and device numbers
469
;        mov     eax, [edx + IOCTL.input]                ; get the pci bus and device numbers
470
        mov     ax, [eax+1]
470
        mov     ax, [eax+1]
471
  .nextdevice:
471
  .nextdevice:
472
        mov     ebx, [esi]
472
        mov     ebx, [esi]
473
        cmp     al, byte [ebx + device.pci_bus]               ; compare with pci and device num in device list (notice the usage of word instead of byte)
473
        cmp     al, byte [ebx + device.pci_bus]               ; compare with pci and device num in device list (notice the usage of word instead of byte)
474
        jne     @f
474
        jne     @f
475
        cmp     ah, byte [ebx + device.pci_dev]
475
        cmp     ah, byte [ebx + device.pci_dev]
476
        je      .find_devicenum                         ; Device is already loaded, let's find it's device number
476
        je      .find_devicenum                         ; Device is already loaded, let's find it's device number
477
  @@:
477
  @@:
478
        add     esi, 4
478
        add     esi, 4
479
        loop    .nextdevice
479
        loop    .nextdevice
480
 
480
 
481
 
481
 
482
; This device doesnt have its own eth_device structure yet, lets create one
482
; This device doesnt have its own eth_device structure yet, lets create one
483
  .firstdevice:
483
  .firstdevice:
484
        cmp     [devices], MAX_DEVICES                  ; First check if the driver can handle one more card
484
        cmp     [devices], MAX_DEVICES                  ; First check if the driver can handle one more card
485
        jae     .fail
485
        jae     .fail
486
 
486
 
487
        allocate_and_clear ebx, sizeof.device, .fail      ; Allocate the buffer for device structure
487
        allocate_and_clear ebx, sizeof.device, .fail      ; Allocate the buffer for device structure
488
 
488
 
489
; Fill in the direct call addresses into the struct
489
; Fill in the direct call addresses into the struct
490
 
490
 
491
        mov     [ebx + device.reset], reset
491
        mov     [ebx + device.reset], reset
492
        mov     [ebx + device.transmit], transmit
492
        mov     [ebx + device.transmit], transmit
493
        mov     [ebx + device.unload], .fail
493
        mov     [ebx + device.unload], .fail
494
        mov     [ebx + device.name], my_service
494
        mov     [ebx + device.name], my_service
495
 
495
 
496
; save the pci bus and device numbers
496
; save the pci bus and device numbers
497
 
497
 
498
        mov     eax, [edx + IOCTL.input]
498
        mov     eax, [edx + IOCTL.input]
499
        movzx   ecx, byte [eax+1]
499
        movzx   ecx, byte [eax+1]
500
        mov     [ebx + device.pci_bus], ecx
500
        mov     [ebx + device.pci_bus], ecx
501
        movzx   ecx, byte [eax+2]
501
        movzx   ecx, byte [eax+2]
502
        mov     [ebx + device.pci_dev], ecx
502
        mov     [ebx + device.pci_dev], ecx
503
 
503
 
504
        DEBUGF  1,"Hooking into device, dev:%x, bus:%x\n", [ebx + device.pci_dev], [ebx + device.pci_bus]
504
        DEBUGF  1,"Hooking into device, dev:%x, bus:%x\n", [ebx + device.pci_dev], [ebx + device.pci_bus]
505
 
505
 
506
; Ok, the eth_device structure is ready, let's probe the device
506
; Ok, the eth_device structure is ready, let's probe the device
507
        call    probe                                                   ; this function will output in eax
507
        call    probe                                                   ; this function will output in eax
508
        test    eax, eax
508
        test    eax, eax
509
        jnz     .err                                                    ; If an error occured, exit
509
        jnz     .err                                                    ; If an error occured, exit
510
 
510
 
511
        mov     eax, [devices]                                          ; Add the device structure to our device list
511
        mov     eax, [devices]                                          ; Add the device structure to our device list
512
        mov     [device_list+4*eax], ebx                                ; (IRQ handler uses this list to find device)
512
        mov     [device_list+4*eax], ebx                                ; (IRQ handler uses this list to find device)
513
        inc     [devices]                                               ;
513
        inc     [devices]                                               ;
514
 
514
 
515
        mov     [ebx + device.type], NET_TYPE_ETH
515
        mov     [ebx + device.type], NET_TYPE_ETH
516
        invoke  NetRegDev
516
        invoke  NetRegDev
517
 
517
 
518
        cmp     eax, -1
518
        cmp     eax, -1
519
        je      .destroy
519
        je      .destroy
520
 
520
 
521
        ret
521
        ret
522
 
522
 
523
; If the device was already loaded, find the device number and return it in eax
523
; If the device was already loaded, find the device number and return it in eax
524
 
524
 
525
  .find_devicenum:
525
  .find_devicenum:
526
        DEBUGF  1,"Trying to find device number of already registered device\n"
526
        DEBUGF  1,"Trying to find device number of already registered device\n"
527
        invoke  NetPtrToNum                                             ; This kernel procedure converts a pointer to device struct in ebx
527
        invoke  NetPtrToNum                                             ; This kernel procedure converts a pointer to device struct in ebx
528
                                                                        ; into a device number in edi
528
                                                                        ; into a device number in edi
529
        mov     eax, edi                                                ; Application wants it in eax instead
529
        mov     eax, edi                                                ; Application wants it in eax instead
530
        DEBUGF  1,"Kernel says: %u\n", eax
530
        DEBUGF  1,"Kernel says: %u\n", eax
531
        ret
531
        ret
532
 
532
 
533
; If an error occured, remove all allocated data and exit (returning -1 in eax)
533
; If an error occured, remove all allocated data and exit (returning -1 in eax)
534
 
534
 
535
  .destroy:
535
  .destroy:
536
        ; todo: reset device into virgin state
536
        ; todo: reset device into virgin state
537
 
537
 
538
  .err:
538
  .err:
539
        invoke  KernelFree, ebx
539
        invoke  KernelFree, ebx
540
  .fail:
540
  .fail:
541
 
541
 
542
        ret
542
        ret
543
 
543
 
544
;------------------------------------------------------
544
;------------------------------------------------------
545
endp
545
endp
546
 
546
 
547
 
547
 
548
;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;;
548
;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;;
549
;;                                                                        ;;
549
;;                                                                        ;;
550
;;        Actual Hardware dependent code starts here                      ;;
550
;;        Actual Hardware dependent code starts here                      ;;
551
;;                                                                        ;;
551
;;                                                                        ;;
552
;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;;
552
;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;;
553
 
553
 
554
 
554
 
555
 
555
 
556
 
556
 
557
;***************************************************************************
557
;***************************************************************************
558
;   Function
558
;   Function
559
;      probe
559
;      probe
560
;   Description
560
;   Description
561
;      Searches for an ethernet card, enables it and clears the rx buffer
561
;      Searches for an ethernet card, enables it and clears the rx buffer
562
;
562
;
563
;***************************************************************************
563
;***************************************************************************
564
align 4
564
align 4
565
probe:
565
probe:
566
 
566
 
567
        DEBUGF  1,"probe\n"
567
        DEBUGF  1,"probe\n"
568
 
568
 
569
        mov     [ebx + device.needs_mac_reset], 0
569
        mov     [ebx + device.needs_mac_reset], 0
570
 
570
 
571
; Make the device a bus master and enable response in I/O space
571
; Make the device a bus master and enable response in I/O space
572
        invoke  PciRead32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command
572
        invoke  PciRead32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command
573
        or      al, PCI_CMD_MASTER + PCI_CMD_PIO ; + PCI_CMD_MMIO
573
        or      al, PCI_CMD_MASTER + PCI_CMD_PIO ; + PCI_CMD_MMIO
574
        invoke  PciWrite32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command, eax
574
        invoke  PciWrite32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command, eax
575
 
575
 
576
; Adjust PCI latency to be at least 32
576
; Adjust PCI latency to be at least 32
577
        invoke  PciRead8, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.max_latency
577
        invoke  PciRead8, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.max_latency
578
        cmp     al, 32
578
        cmp     al, 32
579
        jae     @f
579
        jae     @f
580
        mov     al, 32
580
        mov     al, 32
581
        invoke  PciWrite8, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.max_latency, eax
581
        invoke  PciWrite8, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.max_latency, eax
582
  @@:
582
  @@:
583
 
583
 
584
; Now, it's time to find the base mmio addres of the PCI device
584
; Now, it's time to find the base mmio addres of the PCI device
585
        stdcall PCI_find_mmio32, [ebx + device.pci_bus], [ebx + device.pci_dev] ; returns in eax
585
        stdcall PCI_find_mmio32, [ebx + device.pci_bus], [ebx + device.pci_dev] ; returns in eax
586
        DEBUGF 1,"mmio_addr= 0x%x\n", eax
586
        DEBUGF 1,"mmio_addr= 0x%x\n", eax
587
 
587
 
588
; Create virtual mapping of the physical memory
588
; Create virtual mapping of the physical memory
589
        invoke  MapIoMem, eax, 10000h, PG_SW + PG_NOCACHE
589
        invoke  MapIoMem, eax, 10000h, PG_SW + PG_NOCACHE
590
        test    eax, eax
590
        test    eax, eax
591
        jz      fail
591
        jz      fail
592
        mov     [ebx + device.mmio_addr], eax
592
        mov     [ebx + device.mmio_addr], eax
593
        DEBUGF 1,"mapped mmio_addr= 0x%x\n", eax
593
        DEBUGF 1,"mapped mmio_addr= 0x%x\n", eax
594
 
594
 
595
; Read PCI vendor/device ID
595
; Read PCI vendor/device ID
596
        invoke  PciRead32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.vendor_id
596
        invoke  PciRead32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.vendor_id
597
        mov     dword[ebx + device.vendor_id], eax
597
        mov     dword[ebx + device.vendor_id], eax
598
        DEBUGF 1,"vendor = 0x%x\n", [ebx + device.vendor_id]:4
598
        DEBUGF 1,"vendor = 0x%x\n", [ebx + device.vendor_id]:4
599
        DEBUGF 1,"device = 0x%x\n", [ebx + device.device_id]:4
599
        DEBUGF 1,"device = 0x%x\n", [ebx + device.device_id]:4
600
 
600
 
601
;-------------------------------------
601
;-------------------------------------
602
; handle different descriptor versions
602
; handle different descriptor versions
603
        mov     [ebx + device.desc_ver], DESC_VER_1
603
        mov     [ebx + device.desc_ver], DESC_VER_1
604
        mov     ax, [ebx + device.device_id]
604
        mov     ax, [ebx + device.device_id]
605
        cmp     ax, PCI_DEVICE_ID_NVIDIA_NVENET_1
605
        cmp     ax, PCI_DEVICE_ID_NVIDIA_NVENET_1
606
        je      .ver1
606
        je      .ver1
607
        cmp     ax, PCI_DEVICE_ID_NVIDIA_NVENET_2
607
        cmp     ax, PCI_DEVICE_ID_NVIDIA_NVENET_2
608
        je      .ver1
608
        je      .ver1
609
        cmp     ax, PCI_DEVICE_ID_NVIDIA_NVENET_3
609
        cmp     ax, PCI_DEVICE_ID_NVIDIA_NVENET_3
610
        je      .ver1
610
        je      .ver1
611
        mov     [ebx + device.desc_ver], DESC_VER_2
611
        mov     [ebx + device.desc_ver], DESC_VER_2
612
  .ver1:
612
  .ver1:
613
 
613
 
614
        call    read_mac
614
        call    read_mac
615
 
615
 
616
        ; disable WOL
616
        ; disable WOL
617
        mov     [WakeUpFlags], 0
617
        mov     [WakeUpFlags], 0
618
        mov     [ebx + device.wolenabled], 0
618
        mov     [ebx + device.wolenabled], 0
619
        
619
        
620
        mov     [ebx + device.txflags], (NV_TX2_LASTPACKET or NV_TX2_VALID)
620
        mov     [ebx + device.txflags], (NV_TX2_LASTPACKET or NV_TX2_VALID)
621
        cmp     [ebx + device.desc_ver], DESC_VER_1
621
        cmp     [ebx + device.desc_ver], DESC_VER_1
622
        jne     @f
622
        jne     @f
623
        mov     [ebx + device.txflags], (NV_TX_LASTPACKET or NV_TX_VALID)
623
        mov     [ebx + device.txflags], (NV_TX_LASTPACKET or NV_TX_VALID)
624
      @@:
624
      @@:
625
 
625
 
626
; BEGIN of switch (pci->dev_id)
626
; BEGIN of switch (pci->dev_id)
627
 
627
 
628
        cmp     [ebx + device.device_id], 0x01C3
628
        cmp     [ebx + device.device_id], 0x01C3
629
        jne     .not_0x01c3
629
        jne     .not_0x01c3
630
        ; nforce
630
        ; nforce
631
        mov     [ebx + device.irqmask], (IRQMASK_WANTED_2 or IRQ_TIMER)         ;;; Was 0
631
        mov     [ebx + device.irqmask], (IRQMASK_WANTED_2 or IRQ_TIMER)         ;;; Was 0
632
        jmp     .find_phy
632
        jmp     .find_phy
633
  .not_0x01c3:
633
  .not_0x01c3:
634
 
634
 
635
        cmp     [ebx + device.device_id], 0x0066
635
        cmp     [ebx + device.device_id], 0x0066
636
        je      @f
636
        je      @f
637
        cmp     [ebx + device.device_id], 0x00D6
637
        cmp     [ebx + device.device_id], 0x00D6
638
        jne     .not_0x0066
638
        jne     .not_0x0066
639
  @@:
639
  @@:
640
        mov     [ebx + device.irqmask], (IRQMASK_WANTED_2 or IRQ_TIMER)         ;;;; was 0
640
        mov     [ebx + device.irqmask], (IRQMASK_WANTED_2 or IRQ_TIMER)         ;;;; was 0
641
        cmp     [ebx + device.desc_ver], DESC_VER_1
641
        cmp     [ebx + device.desc_ver], DESC_VER_1
642
        jne     @f
642
        jne     @f
643
        or      [ebx + device.txflags], NV_TX_LASTPACKET1
643
        or      [ebx + device.txflags], NV_TX_LASTPACKET1
644
        jmp     .find_phy
644
        jmp     .find_phy
645
  @@:
645
  @@:
646
        or      [ebx + device.txflags], NV_TX2_LASTPACKET1
646
        or      [ebx + device.txflags], NV_TX2_LASTPACKET1
647
        jmp     .find_phy
647
        jmp     .find_phy
648
  .not_0x0066:
648
  .not_0x0066:
649
 
649
 
650
        cmp     [ebx + device.device_id], 0x0086
650
        cmp     [ebx + device.device_id], 0x0086
651
        je      @f
651
        je      @f
652
        cmp     [ebx + device.device_id], 0x008c
652
        cmp     [ebx + device.device_id], 0x008c
653
        je      @f
653
        je      @f
654
        cmp     [ebx + device.device_id], 0x00e6
654
        cmp     [ebx + device.device_id], 0x00e6
655
        je      @f
655
        je      @f
656
        cmp     [ebx + device.device_id], 0x00df
656
        cmp     [ebx + device.device_id], 0x00df
657
        je      @f
657
        je      @f
658
        cmp     [ebx + device.device_id], 0x0056
658
        cmp     [ebx + device.device_id], 0x0056
659
        je      @f
659
        je      @f
660
        cmp     [ebx + device.device_id], 0x0057
660
        cmp     [ebx + device.device_id], 0x0057
661
        je      @f
661
        je      @f
662
        cmp     [ebx + device.device_id], 0x0037
662
        cmp     [ebx + device.device_id], 0x0037
663
        je      @f
663
        je      @f
664
        cmp     [ebx + device.device_id], 0x0038
664
        cmp     [ebx + device.device_id], 0x0038
665
        jne     .not_0x0086
665
        jne     .not_0x0086
666
 
666
 
667
      @@:
667
      @@:
668
        mov     [ebx + device.irqmask], (IRQMASK_WANTED_2 or IRQ_TIMER) ;;; was 0
668
        mov     [ebx + device.irqmask], (IRQMASK_WANTED_2 or IRQ_TIMER) ;;; was 0
669
 
669
 
670
        cmp     [ebx + device.desc_ver], DESC_VER_1
670
        cmp     [ebx + device.desc_ver], DESC_VER_1
671
        jne     @f
671
        jne     @f
672
        or      [ebx + device.txflags], NV_TX_LASTPACKET1
672
        or      [ebx + device.txflags], NV_TX_LASTPACKET1
673
        jmp     .find_phy
673
        jmp     .find_phy
674
       @@:
674
       @@:
675
        or      [ebx + device.txflags], NV_TX2_LASTPACKET1
675
        or      [ebx + device.txflags], NV_TX2_LASTPACKET1
676
        jmp     .find_phy
676
        jmp     .find_phy
677
  .not_0x0086:
677
  .not_0x0086:
678
 
678
 
679
;       cmp     word [device_id], 0x0268
679
;       cmp     word [device_id], 0x0268
680
;       je      @f
680
;       je      @f
681
;       cmp     word [device_id], 0x0269
681
;       cmp     word [device_id], 0x0269
682
;       je      @f
682
;       je      @f
683
;       cmp     word [device_id], 0x0372
683
;       cmp     word [device_id], 0x0372
684
;       je      @f
684
;       je      @f
685
;       cmp     word [device_id], 0x0373
685
;       cmp     word [device_id], 0x0373
686
;       je      @f
686
;       je      @f
687
;       jmp     .default_switch
687
;       jmp     .default_switch
688
;@@:
688
;@@:
689
        cmp     [ebx + device.device_id], 0x0268
689
        cmp     [ebx + device.device_id], 0x0268
690
        jb      .undefined
690
        jb      .undefined
691
 
691
 
692
; Get device revision
692
; Get device revision
693
        invoke  PciRead8, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header.revision_id
693
        invoke  PciRead8, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header.revision_id
694
        mov     edi, [ebx + device.mmio_addr]   ;;;;;
694
        mov     edi, [ebx + device.mmio_addr]   ;;;;;
695
 
695
 
696
; take phy and nic out of low power mode
696
; take phy and nic out of low power mode
697
        mov     ecx, [PowerState2]
697
        mov     ecx, [PowerState2]
698
        and     ecx, not POWERSTATE2_POWERUP_MASK
698
        and     ecx, not POWERSTATE2_POWERUP_MASK
699
        cmp     [ebx + device.device_id], PCI_DEVICE_ID_NVIDIA_NVENET_12
699
        cmp     [ebx + device.device_id], PCI_DEVICE_ID_NVIDIA_NVENET_12
700
        je      @f
700
        je      @f
701
        cmp     [ebx + device.device_id], PCI_DEVICE_ID_NVIDIA_NVENET_13
701
        cmp     [ebx + device.device_id], PCI_DEVICE_ID_NVIDIA_NVENET_13
702
        jne     .set_powerstate
702
        jne     .set_powerstate
703
  @@:
703
  @@:
704
        cmp     al, 0xA3
704
        cmp     al, 0xA3
705
        jb      .set_powerstate
705
        jb      .set_powerstate
706
        or      ecx, POWERSTATE2_POWERUP_REV_A3
706
        or      ecx, POWERSTATE2_POWERUP_REV_A3
707
  .set_powerstate:
707
  .set_powerstate:
708
        mov     [PowerState2], ecx
708
        mov     [PowerState2], ecx
709
 
709
 
710
        ; DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ
710
        ; DEV_NEED_LASTPACKET1|DEV_IRQMASK_2|DEV_NEED_TIMERIRQ
711
        mov     [ebx + device.irqmask], (IRQMASK_WANTED_2 or IRQ_TIMER)         ; was 0
711
        mov     [ebx + device.irqmask], (IRQMASK_WANTED_2 or IRQ_TIMER)         ; was 0
712
        
712
        
713
        mov     [ebx + device.needs_mac_reset], 1
713
        mov     [ebx + device.needs_mac_reset], 1
714
        cmp     [ebx + device.desc_ver], DESC_VER_1
714
        cmp     [ebx + device.desc_ver], DESC_VER_1
715
        jne     @f
715
        jne     @f
716
        or      [ebx + device.txflags], NV_TX_LASTPACKET1
716
        or      [ebx + device.txflags], NV_TX_LASTPACKET1
717
        jmp     .find_phy
717
        jmp     .find_phy
718
 
718
 
719
       @@:
719
       @@:
720
        cmp     [ebx + device.desc_ver], DESC_VER_2
720
        cmp     [ebx + device.desc_ver], DESC_VER_2
721
        jne     .undefined
721
        jne     .undefined
722
        or      [ebx + device.txflags], NV_TX2_LASTPACKET1
722
        or      [ebx + device.txflags], NV_TX2_LASTPACKET1
723
        jmp     .find_phy
723
        jmp     .find_phy
724
 
724
 
725
  .undefined:
725
  .undefined:
726
        DEBUGF  2,"Your card was undefined in this driver.\n"
726
        DEBUGF  2,"Your card was undefined in this driver.\n"
727
        or      eax, -1
727
        or      eax, -1
728
        ret
728
        ret
729
 
729
 
730
; Find a suitable phy
730
; Find a suitable phy
731
; Start with address 1 to 31, then do 0, then fail
731
; Start with address 1 to 31, then do 0, then fail
732
 
732
 
733
  .find_phy:
733
  .find_phy:
734
        xor     edx, edx
734
        xor     edx, edx
735
  .phy_loop:
735
  .phy_loop:
736
        inc     edx
736
        inc     edx
737
        and     edx, 0x1f       ; phyaddr = i & 0x1f
737
        and     edx, 0x1f       ; phyaddr = i & 0x1f
738
        mov     eax, MII_PHYSID1
738
        mov     eax, MII_PHYSID1
739
        mov     ecx, MII_READ
739
        mov     ecx, MII_READ
740
        call    mii_rw          ; EDX - addr, EAX - miireg, ECX - value
740
        call    mii_rw          ; EDX - addr, EAX - miireg, ECX - value
741
 
741
 
742
        cmp     eax, 0x0000ffff
742
        cmp     eax, 0x0000ffff
743
        je      .try_next
743
        je      .try_next
744
        test    eax, 0x80000000
744
        test    eax, 0x80000000
745
        jnz     .try_next
745
        jnz     .try_next
746
        mov     esi, eax
746
        mov     esi, eax
747
 
747
 
748
        mov     eax, MII_PHYSID2
748
        mov     eax, MII_PHYSID2
749
        mov     ecx, MII_READ
749
        mov     ecx, MII_READ
750
        call    mii_rw
750
        call    mii_rw
751
 
751
 
752
        cmp     eax, 0x0000ffff
752
        cmp     eax, 0x0000ffff
753
        je      .try_next
753
        je      .try_next
754
        test    eax, 0x80000000
754
        test    eax, 0x80000000
755
        jnz     .try_next
755
        jnz     .try_next
756
        jmp     .got_it
756
        jmp     .got_it
757
 
757
 
758
  .try_next:
758
  .try_next:
759
        test    edx, edx
759
        test    edx, edx
760
        jnz     .phy_loop
760
        jnz     .phy_loop
761
 
761
 
762
        ; PHY in isolate mode? No phy attached and user wants to test loopback?
762
        ; PHY in isolate mode? No phy attached and user wants to test loopback?
763
        ; Very odd, but can be correct.
763
        ; Very odd, but can be correct.
764
        
764
        
765
        DEBUGF  2,"Could not find a valid PHY.\n"
765
        DEBUGF  2,"Could not find a valid PHY.\n"
766
        jmp     .no_phy
766
        jmp     .no_phy
767
 
767
 
768
  .got_it:
768
  .got_it:
769
        and     esi, PHYID1_OUI_MASK
769
        and     esi, PHYID1_OUI_MASK
770
        shl     esi, PHYID1_OUI_SHFT
770
        shl     esi, PHYID1_OUI_SHFT
771
        and     eax, PHYID2_OUI_MASK
771
        and     eax, PHYID2_OUI_MASK
772
        shr     eax, PHYID2_OUI_SHFT
772
        shr     eax, PHYID2_OUI_SHFT
773
        or      eax, esi
773
        or      eax, esi
774
 
774
 
775
        mov     [ebx + device.phyaddr], edx
775
        mov     [ebx + device.phyaddr], edx
776
        mov     [ebx + device.phy_oui], eax
776
        mov     [ebx + device.phy_oui], eax
777
 
777
 
778
        DEBUGF 1,"Found PHY with OUI:0x%x at address:0x%x\n", eax, edx
778
        DEBUGF 1,"Found PHY with OUI:0x%x at address:0x%x\n", eax, edx
779
 
779
 
780
        call    phy_init
780
        call    phy_init
781
 
781
 
782
  .no_phy:
782
  .no_phy:
783
 
783
 
784
        cmp     [ebx + device.needs_mac_reset], 0
784
        cmp     [ebx + device.needs_mac_reset], 0
785
        je      @f
785
        je      @f
786
        call    mac_reset
786
        call    mac_reset
787
  @@:
787
  @@:
788
        
788
        
789
;***************************************************************************
789
;***************************************************************************
790
;   Function
790
;   Function
791
;      reset
791
;      reset
792
;   Description
792
;   Description
793
;      Place the chip (ie, the ethernet card) into a virgin state
793
;      Place the chip (ie, the ethernet card) into a virgin state
794
;      No inputs
794
;      No inputs
795
;      All registers destroyed
795
;      All registers destroyed
796
;
796
;
797
;***************************************************************************
797
;***************************************************************************
798
reset:
798
reset:
799
 
799
 
800
        DEBUGF  1,"Resetting\n"
800
        DEBUGF  1,"Resetting\n"
801
 
801
 
802
        invoke  PciRead8, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.interrupt_line
802
        invoke  PciRead8, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.interrupt_line
803
        movzx   eax, al
803
        movzx   eax, al
804
        invoke  AttachIntHandler, eax, int_handler, ebx
804
        invoke  AttachIntHandler, eax, int_handler, ebx
805
        test    eax, eax
805
        test    eax, eax
806
        jnz     @f
806
        jnz     @f
807
        DEBUGF  2,"Could not attach int handler!\n"
807
        DEBUGF  2,"Could not attach int handler!\n"
808
        or      eax, -1
808
        or      eax, -1
809
        ret
809
        ret
810
       @@:
810
       @@:
811
 
811
 
812
; erase previous misconfiguration
812
; erase previous misconfiguration
813
 
813
 
814
        mov     edi, [ebx + device.mmio_addr]
814
        mov     edi, [ebx + device.mmio_addr]
815
        mov     [MulticastAddrA], MCASTADDRA_FORCE
815
        mov     [MulticastAddrA], MCASTADDRA_FORCE
816
        mov     [MulticastAddrB], 0
816
        mov     [MulticastAddrB], 0
817
        mov     [MulticastMaskA], 0
817
        mov     [MulticastMaskA], 0
818
        mov     [MulticastMaskB], 0
818
        mov     [MulticastMaskB], 0
819
        mov     [PacketFilterFlags], 0
819
        mov     [PacketFilterFlags], 0
820
        mov     [TransmitterControl], 0
820
        mov     [TransmitterControl], 0
821
        mov     [ReceiverControl], 0
821
        mov     [ReceiverControl], 0
822
        mov     [AdapterControl], 0
822
        mov     [AdapterControl], 0
823
 
823
 
824
; initialize descriptor rings
824
; initialize descriptor rings
825
 
825
 
826
        call    init_ring
826
        call    init_ring
827
 
827
 
828
        mov     [LinkSpeed], 0
828
        mov     [LinkSpeed], 0
829
        mov     [UnknownTransmitterReg], 0
829
        mov     [UnknownTransmitterReg], 0
830
 
830
 
831
        call    txrx_reset
831
        call    txrx_reset
832
 
832
 
833
        mov     [UnknownSetupReg6], 0
833
        mov     [UnknownSetupReg6], 0
834
        mov     [ebx + device.in_shutdown], 0
834
        mov     [ebx + device.in_shutdown], 0
835
 
835
 
836
; give hw rings
836
; give hw rings
837
 
837
 
838
        lea     eax, [ebx + device.rx_ring]
838
        lea     eax, [ebx + device.rx_ring]
839
        invoke  GetPhysAddr
839
        invoke  GetPhysAddr
840
        mov     [RxRingPhysAddr], eax
840
        mov     [RxRingPhysAddr], eax
841
 
841
 
842
        lea     eax, [ebx + device.tx_ring]
842
        lea     eax, [ebx + device.tx_ring]
843
        invoke  GetPhysAddr
843
        invoke  GetPhysAddr
844
        mov     [TxRingPhysAddr], eax
844
        mov     [TxRingPhysAddr], eax
845
 
845
 
846
        mov     [RingSizes], (((RX_RING - 1) shl RINGSZ_RXSHIFT) + ((TX_RING - 1) shl RINGSZ_TXSHIFT))
846
        mov     [RingSizes], (((RX_RING - 1) shl RINGSZ_RXSHIFT) + ((TX_RING - 1) shl RINGSZ_TXSHIFT))
847
 
847
 
848
;
848
;
849
 
849
 
850
        mov     [ebx + device.linkspeed], (LINKSPEED_FORCE or LINKSPEED_10)
850
        mov     [ebx + device.linkspeed], (LINKSPEED_FORCE or LINKSPEED_10)
851
        mov     [ebx + device.duplex], 0
851
        mov     [ebx + device.duplex], 0
852
        mov     [LinkSpeed], (LINKSPEED_FORCE or LINKSPEED_10)
852
        mov     [LinkSpeed], (LINKSPEED_FORCE or LINKSPEED_10)
853
        mov     [UnknownSetupReg3], UNKSETUP3_VAL1
853
        mov     [UnknownSetupReg3], UNKSETUP3_VAL1
854
 
854
 
855
        mov     eax, [ebx + device.desc_ver]
855
        mov     eax, [ebx + device.desc_ver]
856
        mov     [TxRxControl], eax
856
        mov     [TxRxControl], eax
857
        call    pci_push
857
        call    pci_push
858
        or      eax, TXRXCTL_BIT1
858
        or      eax, TXRXCTL_BIT1
859
        mov     [TxRxControl], eax
859
        mov     [TxRxControl], eax
860
 
860
 
861
        stdcall reg_delay, UnknownSetupReg5-edi, UNKSETUP5_BIT31, UNKSETUP5_BIT31, NV_SETUP5_DELAY, NV_SETUP5_DELAYMAX, 0
861
        stdcall reg_delay, UnknownSetupReg5-edi, UNKSETUP5_BIT31, UNKSETUP5_BIT31, NV_SETUP5_DELAY, NV_SETUP5_DELAYMAX, 0
862
 
862
 
863
        mov     [UnknownSetupReg4], 0
863
        mov     [UnknownSetupReg4], 0
864
        mov     [MIIStatus], MIISTAT_MASK2
864
        mov     [MIIStatus], MIISTAT_MASK2
865
 
865
 
866
;
866
;
867
        
867
        
868
        mov     [Misc1], (MISC1_FORCE or MISC1_HD)
868
        mov     [Misc1], (MISC1_FORCE or MISC1_HD)
869
 
869
 
870
        mov     eax, [TransmitterStatus]
870
        mov     eax, [TransmitterStatus]
871
        mov     [TransmitterStatus], eax
871
        mov     [TransmitterStatus], eax
872
 
872
 
873
        mov     [PacketFilterFlags], PFF_ALWAYS
873
        mov     [PacketFilterFlags], PFF_ALWAYS
874
 
874
 
875
        mov     [OffloadConfig], OFFLOAD_NORMAL
875
        mov     [OffloadConfig], OFFLOAD_NORMAL
876
 
876
 
877
        mov     eax, [ReceiverStatus]
877
        mov     eax, [ReceiverStatus]
878
        mov     [ReceiverStatus], eax
878
        mov     [ReceiverStatus], eax
879
 
879
 
880
; set random seed
880
; set random seed
881
        push    ebx
881
        push    ebx
882
        invoke  GetTimerTicks   ; bad idea, driver is started at system startup in 90% of cases..
882
        invoke  GetTimerTicks   ; bad idea, driver is started at system startup in 90% of cases..
883
        pop     ebx
883
        pop     ebx
884
 
884
 
885
        mov     edi, [ebx + device.mmio_addr]
885
        mov     edi, [ebx + device.mmio_addr]
886
 
886
 
887
        and     eax, RNDSEED_MASK
887
        and     eax, RNDSEED_MASK
888
        or      eax, RNDSEED_FORCE
888
        or      eax, RNDSEED_FORCE
889
        mov     [RandomSeed], eax
889
        mov     [RandomSeed], eax
890
 
890
 
891
        mov     [UnknownSetupReg1], UNKSETUP1_VAL
891
        mov     [UnknownSetupReg1], UNKSETUP1_VAL
892
        mov     [UnknownSetupReg2], UNKSETUP2_VAL
892
        mov     [UnknownSetupReg2], UNKSETUP2_VAL
893
        mov     [PollingInterval], POLL_DEFAULT
893
        mov     [PollingInterval], POLL_DEFAULT
894
        mov     [UnknownSetupReg6], UNKSETUP6_VAL
894
        mov     [UnknownSetupReg6], UNKSETUP6_VAL
895
 
895
 
896
        mov     eax, [ebx + device.phyaddr]
896
        mov     eax, [ebx + device.phyaddr]
897
        shl     eax, ADAPTCTL_PHYSHIFT
897
        shl     eax, ADAPTCTL_PHYSHIFT
898
        or      eax, (ADAPTCTL_PHYVALID or ADAPTCTL_RUNNING)
898
        or      eax, (ADAPTCTL_PHYVALID or ADAPTCTL_RUNNING)
899
        mov     [AdapterControl], eax
899
        mov     [AdapterControl], eax
900
 
900
 
901
        mov     [MIISpeed], (MIISPEED_BIT8 or MIIDELAY)
901
        mov     [MIISpeed], (MIISPEED_BIT8 or MIIDELAY)
902
        mov     [UnknownSetupReg4], UNKSETUP4_VAL
902
        mov     [UnknownSetupReg4], UNKSETUP4_VAL
903
        mov     [WakeUpFlags], WAKEUPFLAGS_VAL
903
        mov     [WakeUpFlags], WAKEUPFLAGS_VAL
904
        
904
        
905
        or      [PowerState], POWERSTATE_POWEREDUP
905
        or      [PowerState], POWERSTATE_POWEREDUP
906
        call    pci_push
906
        call    pci_push
907
 
907
 
908
        mov     esi, 10
908
        mov     esi, 10
909
        invoke  Sleep
909
        invoke  Sleep
910
 
910
 
911
        or      [PowerState], POWERSTATE_VALID
911
        or      [PowerState], POWERSTATE_VALID
912
        mov     [IrqMask], 0
912
        mov     [IrqMask], 0
913
 
913
 
914
;;;     ; ??? Mask RX interrupts
914
;;;     ; ??? Mask RX interrupts
915
        mov      [IrqMask], IRQ_RX_ALL + IRQ_TX_ALL
915
        mov      [IrqMask], IRQ_RX_ALL + IRQ_TX_ALL
916
;;;     ; ??? Mask TX interrupts
916
;;;     ; ??? Mask TX interrupts
917
;;;     mov      [IrqMask], IRQ_TX_ALL
917
;;;     mov      [IrqMask], IRQ_TX_ALL
918
;;;     ; ??? Mask OTHER interrupts
918
;;;     ; ??? Mask OTHER interrupts
919
;;;     mov      [IrqMask], IRQ_OTHER_ALL
919
;;;     mov      [IrqMask], IRQ_OTHER_ALL
920
        call    pci_push
920
        call    pci_push
921
 
921
 
922
        mov     [MIIStatus], MIISTAT_MASK2
922
        mov     [MIIStatus], MIISTAT_MASK2
923
        mov     [IrqStatus], IRQSTAT_MASK
923
        mov     [IrqStatus], IRQSTAT_MASK
924
        call    pci_push
924
        call    pci_push
925
 
925
 
926
        mov     [MulticastAddrA], MCASTADDRA_FORCE
926
        mov     [MulticastAddrA], MCASTADDRA_FORCE
927
        mov     [MulticastAddrB], 0
927
        mov     [MulticastAddrB], 0
928
        mov     [MulticastMaskA], 0
928
        mov     [MulticastMaskA], 0
929
        mov     [MulticastMaskB], 0
929
        mov     [MulticastMaskB], 0
930
 
930
 
931
        mov     [PacketFilterFlags], (PFF_ALWAYS or PFF_MYADDR)
931
        mov     [PacketFilterFlags], (PFF_ALWAYS or PFF_MYADDR)
932
 
932
 
933
        call    set_multicast
933
        call    set_multicast
934
        
934
        
935
        ; One manual link speed update: Interrupts are enabled, future link
935
        ; One manual link speed update: Interrupts are enabled, future link
936
        ; speed changes cause interrupts and are handled by nv_link_irq().
936
        ; speed changes cause interrupts and are handled by nv_link_irq().
937
 
937
 
938
        mov     eax, [MIIStatus]
938
        mov     eax, [MIIStatus]
939
        mov     [MIIStatus], MIISTAT_MASK
939
        mov     [MIIStatus], MIISTAT_MASK
940
        DEBUGF  1,"startup: got 0x%x\n", eax
940
        DEBUGF  1,"startup: got 0x%x\n", eax
941
 
941
 
942
        call    update_linkspeed
942
        call    update_linkspeed
943
 
943
 
944
        mov     [TransmitterControl], XMITCTL_START       ; start TX
944
        mov     [TransmitterControl], XMITCTL_START       ; start TX
945
        call    pci_push
945
        call    pci_push
946
 
946
 
947
        mov     [ebx + device.nocable], 0
947
        mov     [ebx + device.nocable], 0
948
        test    eax, eax
948
        test    eax, eax
949
        jnz     .return
949
        jnz     .return
950
        DEBUGF  1,"no link during initialization.\n"
950
        DEBUGF  1,"no link during initialization.\n"
951
        mov     [ebx + device.nocable], 1
951
        mov     [ebx + device.nocable], 1
952
 
952
 
953
  .return:
953
  .return:
954
        xor     eax, eax        ; Indicate that we have successfully reset the card
954
        xor     eax, eax        ; Indicate that we have successfully reset the card
955
        mov     [ebx + device.mtu], 1514 ;;; FIXME
955
        mov     [ebx + device.mtu], 1514 ;;; FIXME
956
        ret
956
        ret
957
 
957
 
958
 
958
 
959
fail:
959
fail:
960
        or      eax, -1
960
        or      eax, -1
961
        ret
961
        ret
962
 
962
 
963
;--------------------------------------------------------
963
;--------------------------------------------------------
964
;
964
;
965
; MII_RW
965
; MII_RW
966
;
966
;
967
; read/write a register on the PHY.
967
; read/write a register on the PHY.
968
; Caller must guarantee serialization
968
; Caller must guarantee serialization
969
; Input:  EAX - miireg, EDX - phy addr, ECX - value to write (or -1 to read)
969
; Input:  EAX - miireg, EDX - phy addr, ECX - value to write (or -1 to read)
970
; Output: EAX - retval (lower 16 bits)
970
; Output: EAX - retval (lower 16 bits)
971
;
971
;
972
;--------------------------------------------------------
972
;--------------------------------------------------------
973
 
973
 
974
mii_rw:
974
mii_rw:
975
 
975
 
976
        DEBUGF  1,"mii_rw: 0x%x to reg %d at PHY %d\n", ecx, eax, edx
976
        DEBUGF  1,"mii_rw: 0x%x to reg %d at PHY %d\n", ecx, eax, edx
977
 
977
 
978
        push    edx
978
        push    edx
979
 
979
 
980
        mov     edi, [ebx + device.mmio_addr]
980
        mov     edi, [ebx + device.mmio_addr]
981
 
981
 
982
; Check if MII interface is busy
982
; Check if MII interface is busy
983
        mov     [MIIStatus], MIISTAT_MASK
983
        mov     [MIIStatus], MIISTAT_MASK
984
       @@:
984
       @@:
985
        test    [MIIControl], MIICTL_INUSE
985
        test    [MIIControl], MIICTL_INUSE
986
        jz      @f
986
        jz      @f
987
        mov     [MIIControl], MIICTL_INUSE
987
        mov     [MIIControl], MIICTL_INUSE
988
 
988
 
989
        DEBUGF  1,"mii_rw: in use!\n"
989
        DEBUGF  1,"mii_rw: in use!\n"
990
        pusha
990
        pusha
991
        mov     esi, NV_MIIBUSY_DELAY
991
        mov     esi, NV_MIIBUSY_DELAY
992
        invoke  Sleep
992
        invoke  Sleep
993
        popa
993
        popa
994
        jmp     @r
994
        jmp     @r
995
       @@:
995
       @@:
996
 
996
 
997
; Set the address we want to access
997
; Set the address we want to access
998
        shl     edx, MIICTL_ADDRSHIFT
998
        shl     edx, MIICTL_ADDRSHIFT
999
        or      edx, eax
999
        or      edx, eax
1000
 
1000
 
1001
        ; When writing, write the data first.
1001
        ; When writing, write the data first.
1002
        cmp     ecx, MII_READ
1002
        cmp     ecx, MII_READ
1003
        je      @f
1003
        je      @f
1004
        mov     [MIIData], ecx
1004
        mov     [MIIData], ecx
1005
        or      edx, MIICTL_WRITE
1005
        or      edx, MIICTL_WRITE
1006
       @@:
1006
       @@:
1007
 
1007
 
1008
        mov     [MIIControl], edx
1008
        mov     [MIIControl], edx
1009
 
1009
 
1010
; Wait for read/write to complete
1010
; Wait for read/write to complete
1011
        stdcall reg_delay, MIIControl-edi, MIICTL_INUSE, 0, NV_MIIPHY_DELAY, NV_MIIPHY_DELAYMAX, 0
1011
        stdcall reg_delay, MIIControl-edi, MIICTL_INUSE, 0, NV_MIIPHY_DELAY, NV_MIIPHY_DELAYMAX, 0
1012
 
1012
 
1013
        test    eax, eax
1013
        test    eax, eax
1014
        jz      @f
1014
        jz      @f
1015
        DEBUGF  1,"mii_rw timed out.\n"
1015
        DEBUGF  1,"mii_rw timed out.\n"
1016
        or      eax, -1
1016
        or      eax, -1
1017
        jmp     .return
1017
        jmp     .return
1018
 
1018
 
1019
       @@:
1019
       @@:
1020
        cmp     ecx, MII_READ
1020
        cmp     ecx, MII_READ
1021
        je      .read
1021
        je      .read
1022
; it was a write operation - fewer failures are detectable
1022
; it was a write operation - fewer failures are detectable
1023
        DEBUGF  1,"mii_rw write: ok\n"
1023
        DEBUGF  1,"mii_rw write: ok\n"
1024
        xor     eax, eax
1024
        xor     eax, eax
1025
        jmp     .return
1025
        jmp     .return
1026
 
1026
 
1027
  .read:
1027
  .read:
1028
        mov     eax, [MIIStatus]
1028
        mov     eax, [MIIStatus]
1029
        test    eax, MIISTAT_ERROR
1029
        test    eax, MIISTAT_ERROR
1030
        jz      @f
1030
        jz      @f
1031
        DEBUGF  1,"mii read: failed.\n"
1031
        DEBUGF  1,"mii read: failed.\n"
1032
        or      eax, -1
1032
        or      eax, -1
1033
        jmp     .return
1033
        jmp     .return
1034
 
1034
 
1035
       @@:
1035
       @@:
1036
        mov     eax, [MIIData]
1036
        mov     eax, [MIIData]
1037
        DEBUGF  1,"mii read: 0x%x.\n", eax
1037
        DEBUGF  1,"mii read: 0x%x.\n", eax
1038
 
1038
 
1039
  .return:
1039
  .return:
1040
        pop     edx
1040
        pop     edx
1041
        ret
1041
        ret
1042
 
1042
 
1043
 
1043
 
1044
 
1044
 
1045
 
1045
 
1046
 
1046
 
1047
; Input:  offset:word, mask:dword, target:dword, delay:word, delaymax:word, msg:dword
1047
; Input:  offset:word, mask:dword, target:dword, delay:word, delaymax:word, msg:dword
1048
; Output: EAX - 0|1
1048
; Output: EAX - 0|1
1049
 
1049
 
1050
proc    reg_delay, offset:dword, mask:dword, target:dword, delay:dword, delaymax:dword, msg:dword
1050
proc    reg_delay, offset:dword, mask:dword, target:dword, delay:dword, delaymax:dword, msg:dword
1051
 
1051
 
1052
;        DEBUGF  1,"reg_delay\n"
1052
;        DEBUGF  1,"reg_delay\n"
1053
 
1053
 
1054
        push    esi
1054
        push    esi
1055
        call    pci_push
1055
        call    pci_push
1056
 
1056
 
1057
  .loop:
1057
  .loop:
1058
        mov     esi, [delay]
1058
        mov     esi, [delay]
1059
        invoke  Sleep
1059
        invoke  Sleep
1060
        mov     eax, [delaymax]
1060
        mov     eax, [delaymax]
1061
        sub     eax, [delay]
1061
        sub     eax, [delay]
1062
        mov     [delaymax], eax
1062
        mov     [delaymax], eax
1063
 
1063
 
1064
        cmp     eax, 0
1064
        cmp     eax, 0
1065
        jl      .fail
1065
        jl      .fail
1066
 
1066
 
1067
        mov     eax, [offset]
1067
        mov     eax, [offset]
1068
        mov     eax, [edi + eax]
1068
        mov     eax, [edi + eax]
1069
        and     eax, [mask]
1069
        and     eax, [mask]
1070
        cmp     eax, [target]
1070
        cmp     eax, [target]
1071
        jne     .loop
1071
        jne     .loop
1072
 
1072
 
1073
        pop     esi
1073
        pop     esi
1074
        xor     eax, eax
1074
        xor     eax, eax
1075
        ret
1075
        ret
1076
 
1076
 
1077
  .fail:
1077
  .fail:
1078
        pop     esi
1078
        pop     esi
1079
        xor     eax, eax
1079
        xor     eax, eax
1080
        inc     eax
1080
        inc     eax
1081
        ret
1081
        ret
1082
 
1082
 
1083
endp
1083
endp
1084
 
1084
 
1085
 
1085
 
1086
 
1086
 
1087
 
1087
 
1088
 
1088
 
1089
; Input:  none
1089
; Input:  none
1090
; Output: EAX - result (0 = OK, other = error)
1090
; Output: EAX - result (0 = OK, other = error)
1091
phy_init:
1091
phy_init:
1092
 
1092
 
1093
        push    ebx ecx
1093
        push    ebx ecx
1094
        
1094
        
1095
        ; set advertise register
1095
        ; set advertise register
1096
        mov     edx, [ebx + device.phyaddr]
1096
        mov     edx, [ebx + device.phyaddr]
1097
        mov     eax, MII_ADVERTISE
1097
        mov     eax, MII_ADVERTISE
1098
        mov     ecx, MII_READ
1098
        mov     ecx, MII_READ
1099
        call    mii_rw
1099
        call    mii_rw
1100
 
1100
 
1101
        or      eax, (ADVERTISE_10HALF or ADVERTISE_10FULL or ADVERTISE_100HALF or ADVERTISE_100FULL or 0x800 or 0x400)
1101
        or      eax, (ADVERTISE_10HALF or ADVERTISE_10FULL or ADVERTISE_100HALF or ADVERTISE_100FULL or 0x800 or 0x400)
1102
 
1102
 
1103
        mov     ecx, eax
1103
        mov     ecx, eax
1104
        mov     eax, MII_ADVERTISE
1104
        mov     eax, MII_ADVERTISE
1105
        call    mii_rw
1105
        call    mii_rw
1106
 
1106
 
1107
        test    eax, eax
1107
        test    eax, eax
1108
        jz      @f
1108
        jz      @f
1109
 
1109
 
1110
        DEBUGF  2,"phy write to advertise failed.\n"
1110
        DEBUGF  2,"phy write to advertise failed.\n"
1111
 
1111
 
1112
        mov     eax, PHY_ERROR
1112
        mov     eax, PHY_ERROR
1113
        jmp     .return
1113
        jmp     .return
1114
       @@:
1114
       @@:
1115
 
1115
 
1116
        ; get phy interface type
1116
        ; get phy interface type
1117
        mov     edi, [ebx + device.mmio_addr]
1117
        mov     edi, [ebx + device.mmio_addr]
1118
        mov     eax, [PhyInterface]
1118
        mov     eax, [PhyInterface]
1119
        DEBUGF  1,"phy interface type = 0x%x\n", eax:8
1119
        DEBUGF  1,"phy interface type = 0x%x\n", eax:8
1120
 
1120
 
1121
        ; see if gigabit phy
1121
        ; see if gigabit phy
1122
        mov     eax, MII_BMSR
1122
        mov     eax, MII_BMSR
1123
        mov     ecx, MII_READ
1123
        mov     ecx, MII_READ
1124
        call    mii_rw
1124
        call    mii_rw
1125
        
1125
        
1126
        test    eax, PHY_GIGABIT
1126
        test    eax, PHY_GIGABIT
1127
        jnz     .gigabit
1127
        jnz     .gigabit
1128
        mov     [ebx + device.gigabit], 0
1128
        mov     [ebx + device.gigabit], 0
1129
        jmp     .next_if
1129
        jmp     .next_if
1130
 
1130
 
1131
  .gigabit:
1131
  .gigabit:
1132
        mov     [ebx + device.gigabit], PHY_GIGABIT
1132
        mov     [ebx + device.gigabit], PHY_GIGABIT
1133
 
1133
 
1134
        mov     eax, MII_CTRL1000
1134
        mov     eax, MII_CTRL1000
1135
        mov     ecx, MII_READ
1135
        mov     ecx, MII_READ
1136
        call    mii_rw
1136
        call    mii_rw
1137
        
1137
        
1138
        and     eax, (not ADVERTISE_1000HALF)
1138
        and     eax, (not ADVERTISE_1000HALF)
1139
 
1139
 
1140
        test    [PhyInterface], PHY_RGMII
1140
        test    [PhyInterface], PHY_RGMII
1141
        jz      @f
1141
        jz      @f
1142
        or      eax, ADVERTISE_1000FULL
1142
        or      eax, ADVERTISE_1000FULL
1143
        jmp     .next
1143
        jmp     .next
1144
       @@:
1144
       @@:
1145
 
1145
 
1146
        and     eax, (not ADVERTISE_1000FULL)
1146
        and     eax, (not ADVERTISE_1000FULL)
1147
 
1147
 
1148
  .next:
1148
  .next:
1149
        mov     ecx, eax
1149
        mov     ecx, eax
1150
        mov     eax, MII_CTRL1000
1150
        mov     eax, MII_CTRL1000
1151
        call    mii_rw
1151
        call    mii_rw
1152
 
1152
 
1153
        test    eax, eax
1153
        test    eax, eax
1154
        jz      .next_if
1154
        jz      .next_if
1155
 
1155
 
1156
        DEBUGF  2,"phy init failed.\n"
1156
        DEBUGF  2,"phy init failed.\n"
1157
 
1157
 
1158
        mov     eax, PHY_ERROR
1158
        mov     eax, PHY_ERROR
1159
        jmp     .return
1159
        jmp     .return
1160
 
1160
 
1161
  .next_if:
1161
  .next_if:
1162
 
1162
 
1163
        call    phy_reset
1163
        call    phy_reset
1164
        test    eax, eax
1164
        test    eax, eax
1165
        jz      @f
1165
        jz      @f
1166
 
1166
 
1167
        DEBUGF  2,"phy reset failed.\n"
1167
        DEBUGF  2,"phy reset failed.\n"
1168
 
1168
 
1169
        mov     eax, PHY_ERROR
1169
        mov     eax, PHY_ERROR
1170
        jmp     .return
1170
        jmp     .return
1171
       @@:
1171
       @@:
1172
 
1172
 
1173
        ; phy vendor specific configuration
1173
        ; phy vendor specific configuration
1174
        cmp     [ebx + device.phy_oui], PHY_OUI_CICADA
1174
        cmp     [ebx + device.phy_oui], PHY_OUI_CICADA
1175
        jne     .next_if2
1175
        jne     .next_if2
1176
        test    [PhyInterface], PHY_RGMII
1176
        test    [PhyInterface], PHY_RGMII
1177
        jz      .next_if2
1177
        jz      .next_if2
1178
 
1178
 
1179
        mov     eax, MII_RESV1
1179
        mov     eax, MII_RESV1
1180
        mov     ecx, MII_READ
1180
        mov     ecx, MII_READ
1181
        call    mii_rw
1181
        call    mii_rw
1182
 
1182
 
1183
        and     eax, (not (PHY_INIT1 or PHY_INIT2))
1183
        and     eax, (not (PHY_INIT1 or PHY_INIT2))
1184
        or      eax, (PHY_INIT3 or PHY_INIT4)
1184
        or      eax, (PHY_INIT3 or PHY_INIT4)
1185
        mov     ecx, eax
1185
        mov     ecx, eax
1186
        mov     eax, MII_RESV1
1186
        mov     eax, MII_RESV1
1187
        call    mii_rw
1187
        call    mii_rw
1188
 
1188
 
1189
        test    eax, eax
1189
        test    eax, eax
1190
        jz      @f
1190
        jz      @f
1191
 
1191
 
1192
        DEBUGF  2,"phy init failed.\n"
1192
        DEBUGF  2,"phy init failed.\n"
1193
 
1193
 
1194
        mov     eax, PHY_ERROR
1194
        mov     eax, PHY_ERROR
1195
        jmp     .return
1195
        jmp     .return
1196
       @@:
1196
       @@:
1197
 
1197
 
1198
        mov     eax, MII_NCONFIG
1198
        mov     eax, MII_NCONFIG
1199
        mov     ecx, MII_READ
1199
        mov     ecx, MII_READ
1200
        call    mii_rw
1200
        call    mii_rw
1201
 
1201
 
1202
        or      eax, PHY_INIT5
1202
        or      eax, PHY_INIT5
1203
        mov     ecx, eax
1203
        mov     ecx, eax
1204
        mov     eax, MII_NCONFIG
1204
        mov     eax, MII_NCONFIG
1205
        call    mii_rw
1205
        call    mii_rw
1206
        test    eax, eax
1206
        test    eax, eax
1207
        jz      .next_if2
1207
        jz      .next_if2
1208
 
1208
 
1209
        DEBUGF  2,"phy init failed.\n"
1209
        DEBUGF  2,"phy init failed.\n"
1210
 
1210
 
1211
        mov     eax, PHY_ERROR
1211
        mov     eax, PHY_ERROR
1212
        jmp     .return
1212
        jmp     .return
1213
 
1213
 
1214
 
1214
 
1215
 
1215
 
1216
  .next_if2:
1216
  .next_if2:
1217
 
1217
 
1218
        cmp     [ebx + device.phy_oui], PHY_OUI_CICADA
1218
        cmp     [ebx + device.phy_oui], PHY_OUI_CICADA
1219
        jne     .restart
1219
        jne     .restart
1220
        
1220
        
1221
        mov     eax, MII_SREVISION
1221
        mov     eax, MII_SREVISION
1222
        mov     ecx, MII_READ
1222
        mov     ecx, MII_READ
1223
        call    mii_rw
1223
        call    mii_rw
1224
        
1224
        
1225
        or      eax, PHY_INIT6
1225
        or      eax, PHY_INIT6
1226
        mov     ecx, eax
1226
        mov     ecx, eax
1227
        mov     eax, MII_SREVISION
1227
        mov     eax, MII_SREVISION
1228
        call    mii_rw
1228
        call    mii_rw
1229
        test    eax, eax
1229
        test    eax, eax
1230
        jz      .restart
1230
        jz      .restart
1231
 
1231
 
1232
        DEBUGF  2,"phy init failed.\n"
1232
        DEBUGF  2,"phy init failed.\n"
1233
 
1233
 
1234
        jmp     .return
1234
        jmp     .return
1235
 
1235
 
1236
  .restart:
1236
  .restart:
1237
        ; restart auto negotiation
1237
        ; restart auto negotiation
1238
 
1238
 
1239
        mov     eax, MII_BMCR
1239
        mov     eax, MII_BMCR
1240
        mov     ecx, MII_READ
1240
        mov     ecx, MII_READ
1241
        call    mii_rw
1241
        call    mii_rw
1242
 
1242
 
1243
        or      eax, (BMCR_ANRESTART or BMCR_ANENABLE)
1243
        or      eax, (BMCR_ANRESTART or BMCR_ANENABLE)
1244
        mov     ecx, eax
1244
        mov     ecx, eax
1245
        mov     eax, MII_BMCR
1245
        mov     eax, MII_BMCR
1246
        call    mii_rw
1246
        call    mii_rw
1247
        test    eax, eax
1247
        test    eax, eax
1248
        jz      .ok
1248
        jz      .ok
1249
 
1249
 
1250
        mov     eax, PHY_ERROR
1250
        mov     eax, PHY_ERROR
1251
        jmp     .return
1251
        jmp     .return
1252
 
1252
 
1253
  .ok:
1253
  .ok:
1254
        xor     eax, eax
1254
        xor     eax, eax
1255
  .return:
1255
  .return:
1256
        pop     ecx ebx
1256
        pop     ecx ebx
1257
 
1257
 
1258
        ret
1258
        ret
1259
 
1259
 
1260
 
1260
 
1261
; Input:  none
1261
; Input:  none
1262
; Output: EAX - result (0 = OK, other = error)
1262
; Output: EAX - result (0 = OK, other = error)
1263
phy_reset:
1263
phy_reset:
1264
 
1264
 
1265
        DEBUGF  1,"phy_reset\n"
1265
        DEBUGF  1,"phy_reset\n"
1266
 
1266
 
1267
        push    ebx ecx edx
1267
        push    ebx ecx edx
1268
 
1268
 
1269
        mov     edx, [ebx + device.phyaddr]
1269
        mov     edx, [ebx + device.phyaddr]
1270
        mov     eax, MII_BMCR
1270
        mov     eax, MII_BMCR
1271
        mov     ecx, MII_READ
1271
        mov     ecx, MII_READ
1272
        call    mii_rw
1272
        call    mii_rw
1273
 
1273
 
1274
        or      eax, BMCR_RESET
1274
        or      eax, BMCR_RESET
1275
        push    eax
1275
        push    eax
1276
        mov     ecx, eax
1276
        mov     ecx, eax
1277
        mov     eax, MII_BMCR
1277
        mov     eax, MII_BMCR
1278
        call    mii_rw
1278
        call    mii_rw
1279
 
1279
 
1280
        test    eax, eax
1280
        test    eax, eax
1281
        jz      @f
1281
        jz      @f
1282
 
1282
 
1283
        pop     eax
1283
        pop     eax
1284
        mov     eax, 0xffffffff
1284
        mov     eax, 0xffffffff
1285
        jmp     .return
1285
        jmp     .return
1286
       @@:
1286
       @@:
1287
 
1287
 
1288
        pop     eax
1288
        pop     eax
1289
 
1289
 
1290
        mov     esi, 500
1290
        mov     esi, 500
1291
        invoke  Sleep
1291
        invoke  Sleep
1292
 
1292
 
1293
        ; must wait till reset is deasserted
1293
        ; must wait till reset is deasserted
1294
        mov     esi, 100        ; FIXME: 100 tries seem excessive
1294
        mov     esi, 100        ; FIXME: 100 tries seem excessive
1295
  .while_loop:
1295
  .while_loop:
1296
        test    eax, BMCR_RESET
1296
        test    eax, BMCR_RESET
1297
        jz      .while_loop_exit
1297
        jz      .while_loop_exit
1298
 
1298
 
1299
        push    esi
1299
        push    esi
1300
        mov     esi, 10
1300
        mov     esi, 10
1301
        invoke  Sleep
1301
        invoke  Sleep
1302
        pop     esi
1302
        pop     esi
1303
 
1303
 
1304
        mov     eax, MII_BMCR
1304
        mov     eax, MII_BMCR
1305
        mov     ecx, MII_READ
1305
        mov     ecx, MII_READ
1306
        call    mii_rw
1306
        call    mii_rw
1307
 
1307
 
1308
        dec     esi
1308
        dec     esi
1309
        jnz     .while_loop
1309
        jnz     .while_loop
1310
 
1310
 
1311
        mov     eax, 0xffffffff
1311
        mov     eax, 0xffffffff
1312
        jmp     .return
1312
        jmp     .return
1313
 
1313
 
1314
  .while_loop_exit:
1314
  .while_loop_exit:
1315
        xor     eax, eax
1315
        xor     eax, eax
1316
  .return:
1316
  .return:
1317
        pop     edx ecx ebx
1317
        pop     edx ecx ebx
1318
 
1318
 
1319
        ret
1319
        ret
1320
 
1320
 
1321
 
1321
 
1322
align 4
1322
align 4
1323
pci_push:
1323
pci_push:
1324
 
1324
 
1325
        push    eax
1325
        push    eax
1326
        mov     eax, [edi]
1326
        mov     eax, [edi]
1327
        pop     eax
1327
        pop     eax
1328
 
1328
 
1329
        ret
1329
        ret
1330
 
1330
 
1331
 
1331
 
1332
 
1332
 
1333
 
1333
 
1334
align 4
1334
align 4
1335
mac_reset:
1335
mac_reset:
1336
 
1336
 
1337
        push    esi edi
1337
        push    esi edi
1338
 
1338
 
1339
        DEBUGF  1,"mac_reset.\n"
1339
        DEBUGF  1,"mac_reset.\n"
1340
 
1340
 
1341
        mov     edi, [ebx + device.mmio_addr]
1341
        mov     edi, [ebx + device.mmio_addr]
1342
        mov     eax, [ebx + device.desc_ver]
1342
        mov     eax, [ebx + device.desc_ver]
1343
        or      eax, (TXRXCTL_BIT2 or TXRXCTL_RESET)
1343
        or      eax, (TXRXCTL_BIT2 or TXRXCTL_RESET)
1344
        mov     [TxRxControl], eax
1344
        mov     [TxRxControl], eax
1345
        call    pci_push
1345
        call    pci_push
1346
 
1346
 
1347
        mov     [MacReset], MAC_RESET_ASSERT
1347
        mov     [MacReset], MAC_RESET_ASSERT
1348
        call    pci_push
1348
        call    pci_push
1349
 
1349
 
1350
        mov     esi, NV_MAC_RESET_DELAY
1350
        mov     esi, NV_MAC_RESET_DELAY
1351
        invoke  Sleep
1351
        invoke  Sleep
1352
 
1352
 
1353
        mov     [MacReset], 0
1353
        mov     [MacReset], 0
1354
        call    pci_push
1354
        call    pci_push
1355
 
1355
 
1356
        mov     esi, NV_MAC_RESET_DELAY
1356
        mov     esi, NV_MAC_RESET_DELAY
1357
        invoke  Sleep
1357
        invoke  Sleep
1358
 
1358
 
1359
        mov     eax, [ebx + device.desc_ver]
1359
        mov     eax, [ebx + device.desc_ver]
1360
        or      eax, TXRXCTL_BIT2
1360
        or      eax, TXRXCTL_BIT2
1361
        mov     [TxRxControl], eax
1361
        mov     [TxRxControl], eax
1362
        call    pci_push
1362
        call    pci_push
1363
 
1363
 
1364
        pop     edi esi
1364
        pop     edi esi
1365
 
1365
 
1366
        ret
1366
        ret
1367
 
1367
 
1368
 
1368
 
1369
 
1369
 
1370
align 4
1370
align 4
1371
init_ring:
1371
init_ring:
1372
 
1372
 
1373
        DEBUGF  1,"init rings\n"
1373
        DEBUGF  1,"init rings\n"
1374
        push    eax esi ecx
1374
        push    esi ecx
1375
 
1375
 
1376
        mov     [ebx + device.cur_tx], 0
1376
        mov     [ebx + device.cur_tx], 0
1377
        mov     [ebx + device.last_tx], 0
1377
        mov     [ebx + device.last_tx], 0
1378
 
1378
 
1379
        mov     ecx, TX_RING
1379
        mov     ecx, TX_RING
1380
        lea     esi, [ebx + device.tx_ring]
1380
        lea     esi, [ebx + device.tx_ring]
1381
  .tx_loop:
1381
  .tx_loop:
1382
        mov     [esi + TxDesc.FlagLen], 0
1382
        mov     [esi + TxDesc.FlagLen], 0
1383
        mov     [esi + TxDesc.PacketBuffer], 0
1383
        mov     [esi + TxDesc.PacketBuffer], 0
1384
        add     esi, sizeof.TxDesc
1384
        add     esi, sizeof.TxDesc
1385
        dec     ecx
1385
        dec     ecx
1386
        jnz     .tx_loop
1386
        jnz     .tx_loop
1387
 
1387
 
1388
 
1388
 
1389
        mov     [ebx + device.cur_rx], 0
1389
        mov     [ebx + device.cur_rx], 0
1390
 
1390
 
1391
        mov     ecx, RX_RING
1391
        mov     ecx, RX_RING
1392
        lea     esi, [ebx + device.rx_ring]
1392
        lea     esi, [ebx + device.rx_ring]
1393
  .rx_loop:
1393
  .rx_loop:
1394
        push    ecx esi
1394
        push    ecx esi
1395
        invoke  KernelAlloc, 4096 shl RBLEN             ; push/pop esi not needed, but just in case...
1395
        invoke  NetAlloc, (4096 shl RBLEN) + NET_BUFF.data             ; push/pop esi not needed, but just in case...
1396
        pop     esi
1396
        pop     esi
-
 
1397
        test    eax, eax
-
 
1398
        jz      .out_of_mem
1397
        mov     [esi + RX_RING*sizeof.RxDesc], eax
1399
        mov     [esi + RX_RING*sizeof.RxDesc], eax
1398
        invoke  GetPhysAddr
1400
        invoke  GetPhysAddr
-
 
1401
        add     eax, NET_BUFF.data
1399
        mov     [esi + RxDesc.PacketBuffer], eax
1402
        mov     [esi + RxDesc.PacketBuffer], eax
1400
        mov     [esi + RxDesc.FlagLen], (4096 shl RBLEN or NV_RX_AVAIL)
1403
        mov     [esi + RxDesc.FlagLen], (4096 shl RBLEN or NV_RX_AVAIL)
1401
        add     esi, sizeof.RxDesc
1404
        add     esi, sizeof.RxDesc
1402
        pop     ecx
1405
        pop     ecx
1403
        dec     ecx
1406
        dec     ecx
1404
        jnz     .rx_loop
1407
        jnz     .rx_loop
1405
        
1408
        
-
 
1409
        pop     ecx esi
-
 
1410
 
-
 
1411
        xor     eax, eax
-
 
1412
        ret
-
 
1413
 
-
 
1414
  .out_of_mem:
1406
        pop     ecx esi eax
1415
        add     esp, 12
1407
 
1416
        or      eax, -1
1408
        ret
1417
        ret
1409
 
1418
 
1410
 
1419
 
1411
 
1420
 
1412
 
1421
 
1413
 
1422
 
1414
; Input:  none
1423
; Input:  none
1415
; Output: none
1424
; Output: none
1416
align 4
1425
align 4
1417
txrx_reset:
1426
txrx_reset:
1418
 
1427
 
1419
        push    eax esi
1428
        push    eax esi
1420
 
1429
 
1421
        DEBUGF  1,"txrx_reset\n"
1430
        DEBUGF  1,"txrx_reset\n"
1422
 
1431
 
1423
        mov     edi, [ebx + device.mmio_addr]
1432
        mov     edi, [ebx + device.mmio_addr]
1424
        mov     eax, [ebx + device.desc_ver]
1433
        mov     eax, [ebx + device.desc_ver]
1425
        or      eax, (TXRXCTL_BIT2 or TXRXCTL_RESET)
1434
        or      eax, (TXRXCTL_BIT2 or TXRXCTL_RESET)
1426
        mov     [TxRxControl], eax
1435
        mov     [TxRxControl], eax
1427
        call    pci_push
1436
        call    pci_push
1428
 
1437
 
1429
        mov     esi, NV_TXRX_RESET_DELAY
1438
        mov     esi, NV_TXRX_RESET_DELAY
1430
        invoke  Sleep
1439
        invoke  Sleep
1431
 
1440
 
1432
        mov     eax, [ebx + device.desc_ver]
1441
        mov     eax, [ebx + device.desc_ver]
1433
        or      eax, TXRXCTL_BIT2
1442
        or      eax, TXRXCTL_BIT2
1434
        mov     [TxRxControl], eax
1443
        mov     [TxRxControl], eax
1435
        call    pci_push
1444
        call    pci_push
1436
 
1445
 
1437
        pop     esi eax
1446
        pop     esi eax
1438
 
1447
 
1439
        ret
1448
        ret
1440
 
1449
 
1441
 
1450
 
1442
 
1451
 
1443
 
1452
 
1444
 
1453
 
1445
; Input:  none
1454
; Input:  none
1446
; Output: none
1455
; Output: none
1447
set_multicast:
1456
set_multicast:
1448
 
1457
 
1449
        ; u32 addr[2];
1458
        ; u32 addr[2];
1450
        ; u32 mask[2];
1459
        ; u32 mask[2];
1451
        ; u32 pff;
1460
        ; u32 pff;
1452
        ; u32 alwaysOff[2];
1461
        ; u32 alwaysOff[2];
1453
        ; u32 alwaysOn[2];
1462
        ; u32 alwaysOn[2];
1454
        ;
1463
        ;
1455
        ; memset(addr, 0, sizeof(addr));
1464
        ; memset(addr, 0, sizeof(addr));
1456
        ; memset(mask, 0, sizeof(mask));
1465
        ; memset(mask, 0, sizeof(mask));
1457
        ;
1466
        ;
1458
        ; pff = PFF_MYADDR;
1467
        ; pff = PFF_MYADDR;
1459
        ;
1468
        ;
1460
        ; alwaysOn[0] = alwaysOn[1] = alwaysOff[0] = alwaysOff[1] = 0;
1469
        ; alwaysOn[0] = alwaysOn[1] = alwaysOff[0] = alwaysOff[1] = 0;
1461
        ;
1470
        ;
1462
        ; addr[0] = alwaysOn[0];
1471
        ; addr[0] = alwaysOn[0];
1463
        ; addr[1] = alwaysOn[1];
1472
        ; addr[1] = alwaysOn[1];
1464
        ; mask[0] = alwaysOn[0] | alwaysOff[0];
1473
        ; mask[0] = alwaysOn[0] | alwaysOff[0];
1465
        ; mask[1] = alwaysOn[1] | alwaysOff[1];
1474
        ; mask[1] = alwaysOn[1] | alwaysOff[1];
1466
        ;
1475
        ;
1467
        ; addr[0] |= MCASTADDRA_FORCE;
1476
        ; addr[0] |= MCASTADDRA_FORCE;
1468
        ; pff |= PFF_ALWAYS;
1477
        ; pff |= PFF_ALWAYS;
1469
 
1478
 
1470
        call    stop_rx
1479
        call    stop_rx
1471
 
1480
 
1472
        mov     edi, [ebx + device.mmio_addr]
1481
        mov     edi, [ebx + device.mmio_addr]
1473
        mov     [MulticastAddrA], MCASTADDRA_FORCE
1482
        mov     [MulticastAddrA], MCASTADDRA_FORCE
1474
 
1483
 
1475
        mov     [MulticastAddrB], 0
1484
        mov     [MulticastAddrB], 0
1476
        mov     [MulticastMaskA], 0
1485
        mov     [MulticastMaskA], 0
1477
        mov     [MulticastMaskB], 0
1486
        mov     [MulticastMaskB], 0
1478
        mov     [PacketFilterFlags], (PFF_MYADDR or PFF_ALWAYS)
1487
        mov     [PacketFilterFlags], (PFF_MYADDR or PFF_ALWAYS)
1479
 
1488
 
1480
        call    start_rx
1489
        call    start_rx
1481
 
1490
 
1482
        ret
1491
        ret
1483
 
1492
 
1484
 
1493
 
1485
 
1494
 
1486
 
1495
 
1487
 
1496
 
1488
; Input:  none
1497
; Input:  none
1489
; Output: none
1498
; Output: none
1490
start_rx:
1499
start_rx:
1491
 
1500
 
1492
        push    edi
1501
        push    edi
1493
 
1502
 
1494
        DEBUGF  1,"start_rx\n"
1503
        DEBUGF  1,"start_rx\n"
1495
 
1504
 
1496
        ; Already running? Stop it.
1505
        ; Already running? Stop it.
1497
        mov     edi, [ebx + device.mmio_addr]
1506
        mov     edi, [ebx + device.mmio_addr]
1498
        mov     eax, [ReceiverControl]
1507
        mov     eax, [ReceiverControl]
1499
        test    eax, RCVCTL_START
1508
        test    eax, RCVCTL_START
1500
        jz      @f
1509
        jz      @f
1501
        mov     [ReceiverControl], 0
1510
        mov     [ReceiverControl], 0
1502
        call    pci_push
1511
        call    pci_push
1503
       @@:
1512
       @@:
1504
 
1513
 
1505
        mov     eax, [ebx + device.linkspeed]
1514
        mov     eax, [ebx + device.linkspeed]
1506
        mov     [LinkSpeed], eax
1515
        mov     [LinkSpeed], eax
1507
        call    pci_push
1516
        call    pci_push
1508
 
1517
 
1509
        mov     [ReceiverControl], RCVCTL_START
1518
        mov     [ReceiverControl], RCVCTL_START
1510
        call    pci_push
1519
        call    pci_push
1511
 
1520
 
1512
        pop     edi
1521
        pop     edi
1513
 
1522
 
1514
        ret
1523
        ret
1515
 
1524
 
1516
 
1525
 
1517
 
1526
 
1518
 
1527
 
1519
; Input:  none
1528
; Input:  none
1520
; Output: none
1529
; Output: none
1521
stop_rx:
1530
stop_rx:
1522
 
1531
 
1523
        push    esi edi
1532
        push    esi edi
1524
 
1533
 
1525
        DEBUGF  1,"stop_rx.\n"
1534
        DEBUGF  1,"stop_rx.\n"
1526
 
1535
 
1527
        mov     edi, [ebx + device.mmio_addr]
1536
        mov     edi, [ebx + device.mmio_addr]
1528
        mov     [ReceiverControl], 0
1537
        mov     [ReceiverControl], 0
1529
 
1538
 
1530
        push    ebx edx edi
1539
        push    ebx edx edi
1531
        stdcall reg_delay, ReceiverStatus-edi, RCVSTAT_BUSY, 0, NV_RXSTOP_DELAY1, NV_RXSTOP_DELAY1MAX, 0
1540
        stdcall reg_delay, ReceiverStatus-edi, RCVSTAT_BUSY, 0, NV_RXSTOP_DELAY1, NV_RXSTOP_DELAY1MAX, 0
1532
        pop     edi edx ebx
1541
        pop     edi edx ebx
1533
 
1542
 
1534
        mov     esi, NV_RXSTOP_DELAY2
1543
        mov     esi, NV_RXSTOP_DELAY2
1535
        invoke  Sleep
1544
        invoke  Sleep
1536
 
1545
 
1537
        mov     [LinkSpeed], 0
1546
        mov     [LinkSpeed], 0
1538
 
1547
 
1539
        pop     edi esi
1548
        pop     edi esi
1540
 
1549
 
1541
        ret
1550
        ret
1542
 
1551
 
1543
 
1552
 
1544
 
1553
 
1545
 
1554
 
1546
; Input:  none
1555
; Input:  none
1547
; Output: EAX
1556
; Output: EAX
1548
update_linkspeed:
1557
update_linkspeed:
1549
 
1558
 
1550
        DEBUGF  1,"update linkspeed\n"
1559
        DEBUGF  1,"update linkspeed\n"
1551
 
1560
 
1552
; BMSR_LSTATUS is latched, read it twice: we want the current value.
1561
; BMSR_LSTATUS is latched, read it twice: we want the current value.
1553
        
1562
        
1554
        mov     edx, [ebx + device.phyaddr]
1563
        mov     edx, [ebx + device.phyaddr]
1555
        mov     eax, MII_BMSR
1564
        mov     eax, MII_BMSR
1556
        mov     ecx, MII_READ
1565
        mov     ecx, MII_READ
1557
        call    mii_rw
1566
        call    mii_rw
1558
 
1567
 
1559
        mov     eax, MII_BMSR
1568
        mov     eax, MII_BMSR
1560
        mov     ecx, MII_READ
1569
        mov     ecx, MII_READ
1561
        call    mii_rw
1570
        call    mii_rw
1562
        
1571
        
1563
        test    ax, BMSR_LSTATUS               ; Link up?
1572
        test    ax, BMSR_LSTATUS               ; Link up?
1564
        jz      .no_link
1573
        jz      .no_link
1565
 
1574
 
1566
        DEBUGF  1,"link is up\n"
1575
        DEBUGF  1,"link is up\n"
1567
 
1576
 
1568
        test    ax, BMSR_ANEGCOMPLETE          ; still in autonegotiation?
1577
        test    ax, BMSR_ANEGCOMPLETE          ; still in autonegotiation?
1569
        jz      .10mbit_hd
1578
        jz      .10mbit_hd
1570
 
1579
 
1571
        DEBUGF  1,"autonegotiation is complete\n"
1580
        DEBUGF  1,"autonegotiation is complete\n"
1572
 
1581
 
1573
        cmp     [ebx + device.gigabit], PHY_GIGABIT
1582
        cmp     [ebx + device.gigabit], PHY_GIGABIT
1574
        jne     .no_gigabit
1583
        jne     .no_gigabit
1575
 
1584
 
1576
        ;mov     edx, [ebx + device.phyaddr]
1585
        ;mov     edx, [ebx + device.phyaddr]
1577
        mov     eax, MII_CTRL1000
1586
        mov     eax, MII_CTRL1000
1578
        mov     ecx, MII_READ
1587
        mov     ecx, MII_READ
1579
        call    mii_rw
1588
        call    mii_rw
1580
        push    eax
1589
        push    eax
1581
 
1590
 
1582
        ;mov     edx, [ebx + device.phyaddr]
1591
        ;mov     edx, [ebx + device.phyaddr]
1583
        mov     eax, MII_STAT1000
1592
        mov     eax, MII_STAT1000
1584
        mov     ecx, MII_READ
1593
        mov     ecx, MII_READ
1585
        call    mii_rw
1594
        call    mii_rw
1586
        pop     ecx
1595
        pop     ecx
1587
 
1596
 
1588
        test    eax, LPA_1000FULL
1597
        test    eax, LPA_1000FULL
1589
        jz      .no_gigabit
1598
        jz      .no_gigabit
1590
        test    ecx, ADVERTISE_1000FULL
1599
        test    ecx, ADVERTISE_1000FULL
1591
        jz      .no_gigabit
1600
        jz      .no_gigabit
1592
 
1601
 
1593
        DEBUGF  1,"update_linkspeed: GBit ethernet detected.\n"
1602
        DEBUGF  1,"update_linkspeed: GBit ethernet detected.\n"
1594
        mov     [ebx + device.state], ETH_LINK_1G
1603
        mov     [ebx + device.state], ETH_LINK_1G
1595
        mov     ecx, (LINKSPEED_FORCE or LINKSPEED_1000)
1604
        mov     ecx, (LINKSPEED_FORCE or LINKSPEED_1000)
1596
        xor     eax, eax
1605
        xor     eax, eax
1597
        inc     eax
1606
        inc     eax
1598
        jmp     set_speed
1607
        jmp     set_speed
1599
  .no_gigabit:
1608
  .no_gigabit:
1600
 
1609
 
1601
        ;mov     edx, [ebx + device.phyaddr]
1610
        ;mov     edx, [ebx + device.phyaddr]
1602
        mov     eax, MII_ADVERTISE
1611
        mov     eax, MII_ADVERTISE
1603
        mov     ecx, MII_READ
1612
        mov     ecx, MII_READ
1604
        call    mii_rw        ; adv = eax
1613
        call    mii_rw        ; adv = eax
1605
        push    eax
1614
        push    eax
1606
 
1615
 
1607
        ;mov     edx, [ebx + device.phyaddr]
1616
        ;mov     edx, [ebx + device.phyaddr]
1608
        mov     eax, MII_LPA
1617
        mov     eax, MII_LPA
1609
        mov     ecx, MII_READ
1618
        mov     ecx, MII_READ
1610
        call    mii_rw        ; lpa = eax
1619
        call    mii_rw        ; lpa = eax
1611
        pop     ecx
1620
        pop     ecx
1612
 
1621
 
1613
        DEBUGF  1,"PHY advertises 0x%x, lpa 0x%x\n", cx, ax
1622
        DEBUGF  1,"PHY advertises 0x%x, lpa 0x%x\n", cx, ax
1614
        and     eax, ecx                ; FIXME: handle parallel detection properly, handle gigabit ethernet
1623
        and     eax, ecx                ; FIXME: handle parallel detection properly, handle gigabit ethernet
1615
 
1624
 
1616
        test    eax, LPA_100FULL
1625
        test    eax, LPA_100FULL
1617
        jz      @f
1626
        jz      @f
1618
        DEBUGF  1,"update_linkspeed: 100 mbit full duplex\n"
1627
        DEBUGF  1,"update_linkspeed: 100 mbit full duplex\n"
1619
        mov     [ebx + device.state], ETH_LINK_100M + ETH_LINK_FD
1628
        mov     [ebx + device.state], ETH_LINK_100M + ETH_LINK_FD
1620
        mov     ecx, (LINKSPEED_FORCE or LINKSPEED_100)
1629
        mov     ecx, (LINKSPEED_FORCE or LINKSPEED_100)
1621
        xor     eax, eax
1630
        xor     eax, eax
1622
        inc     eax
1631
        inc     eax
1623
        jmp     set_speed
1632
        jmp     set_speed
1624
       @@:
1633
       @@:
1625
 
1634
 
1626
        test    eax, LPA_100HALF
1635
        test    eax, LPA_100HALF
1627
        jz      @f
1636
        jz      @f
1628
        DEBUGF  1,"update_linkspeed: 100 mbit half duplex\n"
1637
        DEBUGF  1,"update_linkspeed: 100 mbit half duplex\n"
1629
        mov     [ebx + device.state], ETH_LINK_100M
1638
        mov     [ebx + device.state], ETH_LINK_100M
1630
        mov     ecx, (LINKSPEED_FORCE or LINKSPEED_100)
1639
        mov     ecx, (LINKSPEED_FORCE or LINKSPEED_100)
1631
        xor     eax, eax
1640
        xor     eax, eax
1632
        jmp     set_speed
1641
        jmp     set_speed
1633
       @@:
1642
       @@:
1634
 
1643
 
1635
        test    eax, LPA_10FULL
1644
        test    eax, LPA_10FULL
1636
        jz      @f
1645
        jz      @f
1637
        DEBUGF  1,"update_linkspeed: 10 mbit full duplex\n"
1646
        DEBUGF  1,"update_linkspeed: 10 mbit full duplex\n"
1638
        mov     [ebx + device.state], ETH_LINK_10M + ETH_LINK_FD
1647
        mov     [ebx + device.state], ETH_LINK_10M + ETH_LINK_FD
1639
        mov     ecx, (LINKSPEED_FORCE or LINKSPEED_10)
1648
        mov     ecx, (LINKSPEED_FORCE or LINKSPEED_10)
1640
        xor     eax, eax
1649
        xor     eax, eax
1641
        inc     eax
1650
        inc     eax
1642
        jmp     set_speed
1651
        jmp     set_speed
1643
       @@:
1652
       @@:
1644
 
1653
 
1645
  .10mbit_hd:
1654
  .10mbit_hd:
1646
        DEBUGF  1,"update_linkspeed: 10 mbit half duplex\n"
1655
        DEBUGF  1,"update_linkspeed: 10 mbit half duplex\n"
1647
        mov     [ebx + device.state], ETH_LINK_10M
1656
        mov     [ebx + device.state], ETH_LINK_10M
1648
        mov     ecx, (LINKSPEED_FORCE or LINKSPEED_10)
1657
        mov     ecx, (LINKSPEED_FORCE or LINKSPEED_10)
1649
        xor     eax, eax
1658
        xor     eax, eax
1650
        jmp     set_speed
1659
        jmp     set_speed
1651
 
1660
 
1652
  .no_link:
1661
  .no_link:
1653
        DEBUGF  1,"update_linkspeed: link is down\n"
1662
        DEBUGF  1,"update_linkspeed: link is down\n"
1654
        mov     [ebx + device.state], ETH_LINK_DOWN
1663
        mov     [ebx + device.state], ETH_LINK_DOWN
1655
        mov     ecx, (LINKSPEED_FORCE or LINKSPEED_10)
1664
        mov     ecx, (LINKSPEED_FORCE or LINKSPEED_10)
1656
        xor     eax, eax
1665
        xor     eax, eax
1657
        jmp     set_speed
1666
        jmp     set_speed
1658
 
1667
 
1659
 
1668
 
1660
align 4
1669
align 4
1661
set_speed:
1670
set_speed:
1662
 
1671
 
1663
        cmp     eax, [ebx + device.duplex]
1672
        cmp     eax, [ebx + device.duplex]
1664
        jne     .update
1673
        jne     .update
1665
        cmp     ecx, [ebx + device.linkspeed]
1674
        cmp     ecx, [ebx + device.linkspeed]
1666
        jne     .update
1675
        jne     .update
1667
 
1676
 
1668
        ret
1677
        ret
1669
 
1678
 
1670
  .update:
1679
  .update:
1671
        DEBUGF  1,"update_linkspeed: changing link to 0x%x/XD.\n", ecx
1680
        DEBUGF  1,"update_linkspeed: changing link to 0x%x/XD.\n", ecx
1672
        
1681
        
1673
        mov     [ebx + device.duplex], eax
1682
        mov     [ebx + device.duplex], eax
1674
        mov     [ebx + device.linkspeed], ecx
1683
        mov     [ebx + device.linkspeed], ecx
1675
        
1684
        
1676
        cmp     [ebx + device.gigabit], PHY_GIGABIT
1685
        cmp     [ebx + device.gigabit], PHY_GIGABIT
1677
        jne     .no_gigabit
1686
        jne     .no_gigabit
1678
 
1687
 
1679
        mov     edi, [ebx + device.mmio_addr]
1688
        mov     edi, [ebx + device.mmio_addr]
1680
        mov     eax, [RandomSeed]
1689
        mov     eax, [RandomSeed]
1681
 
1690
 
1682
        and     eax, not (0x3FF00)
1691
        and     eax, not (0x3FF00)
1683
        mov     ecx, eax                ; phyreg = ecx
1692
        mov     ecx, eax                ; phyreg = ecx
1684
 
1693
 
1685
        mov     eax, [ebx + device.linkspeed]
1694
        mov     eax, [ebx + device.linkspeed]
1686
        and     eax, 0xFFF
1695
        and     eax, 0xFFF
1687
        cmp     eax, LINKSPEED_10
1696
        cmp     eax, LINKSPEED_10
1688
        jne     @f
1697
        jne     @f
1689
        or      ecx, RNDSEED_FORCE3
1698
        or      ecx, RNDSEED_FORCE3
1690
        jmp     .end_if4
1699
        jmp     .end_if4
1691
       @@:
1700
       @@:
1692
 
1701
 
1693
        cmp     eax, LINKSPEED_100
1702
        cmp     eax, LINKSPEED_100
1694
        jne     @f
1703
        jne     @f
1695
        or      ecx, RNDSEED_FORCE2
1704
        or      ecx, RNDSEED_FORCE2
1696
        jmp     .end_if4
1705
        jmp     .end_if4
1697
       @@:
1706
       @@:
1698
 
1707
 
1699
        cmp     eax, LINKSPEED_1000
1708
        cmp     eax, LINKSPEED_1000
1700
        jne     .end_if4
1709
        jne     .end_if4
1701
        or      ecx, RNDSEED_FORCE
1710
        or      ecx, RNDSEED_FORCE
1702
  .end_if4:
1711
  .end_if4:
1703
        mov     [RandomSeed], ecx
1712
        mov     [RandomSeed], ecx
1704
  .no_gigabit:
1713
  .no_gigabit:
1705
 
1714
 
1706
        mov     ecx, [PhyInterface]
1715
        mov     ecx, [PhyInterface]
1707
        and     ecx, not (PHY_HALF or PHY_100 or PHY_1000)
1716
        and     ecx, not (PHY_HALF or PHY_100 or PHY_1000)
1708
 
1717
 
1709
        cmp     [ebx + device.duplex], 0
1718
        cmp     [ebx + device.duplex], 0
1710
        jne     @f
1719
        jne     @f
1711
        or      ecx, PHY_HALF
1720
        or      ecx, PHY_HALF
1712
       @@:
1721
       @@:
1713
 
1722
 
1714
        mov     eax, [ebx + device.linkspeed]
1723
        mov     eax, [ebx + device.linkspeed]
1715
        and     eax, 0xFFF
1724
        and     eax, 0xFFF
1716
        cmp     eax, LINKSPEED_100
1725
        cmp     eax, LINKSPEED_100
1717
        jne     @f
1726
        jne     @f
1718
        or      ecx, PHY_100
1727
        or      ecx, PHY_100
1719
        jmp     .end_if5
1728
        jmp     .end_if5
1720
       @@:
1729
       @@:
1721
 
1730
 
1722
        cmp     eax, LINKSPEED_1000
1731
        cmp     eax, LINKSPEED_1000
1723
        jne     .end_if5
1732
        jne     .end_if5
1724
        or      ecx, PHY_1000
1733
        or      ecx, PHY_1000
1725
 
1734
 
1726
  .end_if5:
1735
  .end_if5:
1727
        mov     [PhyInterface], ecx
1736
        mov     [PhyInterface], ecx
1728
                
1737
                
1729
        cmp     [ebx + device.duplex], 0
1738
        cmp     [ebx + device.duplex], 0
1730
        je      @f
1739
        je      @f
1731
        xor     ecx, ecx
1740
        xor     ecx, ecx
1732
        jmp     .next
1741
        jmp     .next
1733
       @@:
1742
       @@:
1734
 
1743
 
1735
        mov     ecx, MISC1_HD
1744
        mov     ecx, MISC1_HD
1736
  .next:
1745
  .next:
1737
        or      ecx, MISC1_FORCE
1746
        or      ecx, MISC1_FORCE
1738
        mov     [Misc1], ecx
1747
        mov     [Misc1], ecx
1739
 
1748
 
1740
        call    pci_push
1749
        call    pci_push
1741
 
1750
 
1742
        mov     eax, [ebx + device.linkspeed]
1751
        mov     eax, [ebx + device.linkspeed]
1743
        mov     [LinkSpeed], eax
1752
        mov     [LinkSpeed], eax
1744
 
1753
 
1745
        call    pci_push
1754
        call    pci_push
1746
 
1755
 
1747
        ret
1756
        ret
1748
 
1757
 
1749
 
1758
 
1750
 
1759
 
1751
 
1760
 
1752
 
1761
 
1753
 
1762
 
1754
align 4
1763
align 4
1755
read_mac:
1764
read_mac:
1756
 
1765
 
1757
        mov     edi, [ebx + device.mmio_addr]
1766
        mov     edi, [ebx + device.mmio_addr]
1758
        mov     eax, [MacAddrA]
1767
        mov     eax, [MacAddrA]
1759
        mov     ecx, [MacAddrB]
1768
        mov     ecx, [MacAddrB]
1760
 
1769
 
1761
        mov     dword [ebx + device.mac], eax
1770
        mov     dword [ebx + device.mac], eax
1762
        mov     word [ebx + device.mac + 4], cx
1771
        mov     word [ebx + device.mac + 4], cx
1763
 
1772
 
1764
        cmp     [ebx + device.device_id], 0x03E5
1773
        cmp     [ebx + device.device_id], 0x03E5
1765
        jae     @f
1774
        jae     @f
1766
        bswap   eax
1775
        bswap   eax
1767
        xchg    cl, ch
1776
        xchg    cl, ch
1768
        mov     dword [ebx + device.mac + 2], eax
1777
        mov     dword [ebx + device.mac + 2], eax
1769
        mov     word [ebx + device.mac], cx
1778
        mov     word [ebx + device.mac], cx
1770
       @@:
1779
       @@:
1771
 
1780
 
1772
        DEBUGF  1,"MAC = %x-%x-%x-%x-%x-%x\n", \
1781
        DEBUGF  1,"MAC = %x-%x-%x-%x-%x-%x\n", \
1773
        [ebx + device.mac+0]:2,[ebx + device.mac+1]:2,[ebx + device.mac+2]:2,[ebx + device.mac+3]:2,[ebx + device.mac+4]:2,[ebx + device.mac+5]:2
1782
        [ebx + device.mac+0]:2,[ebx + device.mac+1]:2,[ebx + device.mac+2]:2,[ebx + device.mac+3]:2,[ebx + device.mac+4]:2,[ebx + device.mac+5]:2
1774
 
1783
 
1775
        ret
1784
        ret
1776
 
1785
 
1777
 
1786
 
1778
 
1787
 
1779
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1788
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1780
;;                                         ;;
1789
;;                                         ;;
1781
;; Transmit                                ;;
1790
;; Transmit                                ;;
1782
;;                                         ;;
1791
;;                                         ;;
1783
;; In: buffer pointer in [esp+4]           ;;
1792
;; In: buffer pointer in [esp+4]           ;;
1784
;;     size of buffer in [esp+8]           ;;
-
 
1785
;;     pointer to device structure in ebx  ;;
1793
;;     pointer to device structure in ebx  ;;
1786
;;                                         ;;
1794
;;                                         ;;
1787
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1795
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1788
 
1796
 
1789
proc transmit stdcall bufferptr, buffersize
1797
proc transmit stdcall bufferptr
1790
 
1798
 
1791
        pushf
1799
        pushf
1792
        cli
1800
        cli
-
 
1801
 
1793
 
1802
        mov     esi, [bufferptr]
1794
        DEBUGF  1,"Transmitting packet, buffer:%x, size:%u\n", [bufferptr], [buffersize]
1803
        DEBUGF  1,"Transmitting packet, buffer:%x, size:%u\n", [bufferptr], [esi + NET_BUFF.length]
1795
        mov     eax, [bufferptr]
1804
        lea     eax, [esi + NET_BUFF.data]
1796
        DEBUGF  1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\
1805
        DEBUGF  1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\
1797
        [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\
1806
        [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\
1798
        [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\
1807
        [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\
1799
        [eax+13]:2,[eax+12]:2
1808
        [eax+13]:2,[eax+12]:2
1800
 
1809
 
1801
        cmp     [buffersize], 1514
1810
        cmp     [esi + NET_BUFF.length], 1514
1802
        ja      .fail
1811
        ja      .fail
1803
        cmp     [buffersize], 60
1812
        cmp     [esi + NET_BUFF.length], 60
1804
        jb      .fail
1813
        jb      .fail
1805
 
1814
 
1806
; get the descriptor address
1815
; get the descriptor address
1807
        mov     eax, [ebx + device.cur_tx]
1816
        mov     eax, [ebx + device.cur_tx]
1808
        shl     eax, 3                                  ; TX descriptor is 8 bytes.
1817
        shl     eax, 3                                  ; TX descriptor is 8 bytes.
1809
        lea     esi, [ebx + device.tx_ring + eax]
1818
        lea     edi, [ebx + device.tx_ring + eax]
1810
 
1819
 
1811
        mov     eax, [bufferptr]
1820
        mov     eax, [bufferptr]
-
 
1821
        mov     [edi + TX_RING*sizeof.TxDesc], eax
1812
        mov     [esi + TX_RING*sizeof.TxDesc], eax
1822
        add     eax, [eax + NET_BUFF.offset]
1813
        invoke  GetPhysAddr                             ; Does not change esi/ebx :)
1823
        invoke  GetPhysAddr                             ; Does not change esi/ebx :)
1814
        mov     [esi + TxDesc.PacketBuffer], eax
1824
        mov     [edi + TxDesc.PacketBuffer], eax
1815
 
1825
 
1816
        mov     eax, [buffersize]
1826
        mov     ecx, [esi + NET_BUFF.length]
1817
        or      eax, [ebx + device.txflags]
1827
        or      ecx, [ebx + device.txflags]
1818
        mov     [esi + TxDesc.FlagLen], eax
1828
        mov     [edi + TxDesc.FlagLen], ecx
1819
 
1829
 
1820
        mov     edi, [ebx + device.mmio_addr]
1830
        mov     edi, [ebx + device.mmio_addr]
1821
        mov     eax, [ebx + device.desc_ver]
1831
        mov     eax, [ebx + device.desc_ver]
1822
        or      eax, TXRXCTL_KICK
1832
        or      eax, TXRXCTL_KICK
1823
        mov     [TxRxControl], eax
1833
        mov     [TxRxControl], eax
1824
 
1834
 
1825
        call    pci_push
1835
        call    pci_push
1826
 
1836
 
1827
        inc     [ebx + device.cur_tx]
1837
        inc     [ebx + device.cur_tx]
1828
        and     [ebx + device.cur_tx], (TX_RING-1)
1838
        and     [ebx + device.cur_tx], (TX_RING-1)
1829
 
1839
 
1830
; Update stats
1840
; Update stats
1831
        inc     [ebx + device.packets_tx]
1841
        inc     [ebx + device.packets_tx]
1832
        mov     eax, [buffersize]
-
 
1833
        add     dword[ebx + device.bytes_tx], eax
1842
        add     dword[ebx + device.bytes_tx], ecx
1834
        adc     dword[ebx + device.bytes_tx + 4], 0
1843
        adc     dword[ebx + device.bytes_tx + 4], 0
1835
 
1844
 
1836
        popf
1845
        popf
1837
        xor     eax, eax
1846
        xor     eax, eax
1838
        ret
1847
        ret
1839
 
1848
 
1840
  .fail:
1849
  .fail:
1841
        DEBUGF  2,"Send failed\n"
1850
        DEBUGF  2,"Send failed\n"
1842
        invoke  KernelFree, [bufferptr]
1851
        invoke  NetFree, [bufferptr]
1843
        popf
1852
        popf
1844
        or      eax, -1
1853
        or      eax, -1
1845
        ret
1854
        ret
1846
 
1855
 
1847
endp
1856
endp
1848
 
1857
 
1849
 
1858
 
1850
 
1859
 
1851
 
1860
 
1852
 
1861
 
1853
 
1862
 
1854
; Interrupt handler
1863
; Interrupt handler
1855
align 4
1864
align 4
1856
int_handler:
1865
int_handler:
1857
 
1866
 
1858
        push    ebx esi edi
1867
        push    ebx esi edi
1859
 
1868
 
1860
        DEBUGF  1,"INT\n"
1869
        DEBUGF  1,"INT\n"
1861
 
1870
 
1862
;-------------------------------------------
1871
;-------------------------------------------
1863
; Find pointer of device wich made IRQ occur
1872
; Find pointer of device wich made IRQ occur
1864
 
1873
 
1865
        mov     esi, device_list
1874
        mov     esi, device_list
1866
        mov     ecx, [devices]
1875
        mov     ecx, [devices]
1867
        test    ecx, ecx
1876
        test    ecx, ecx
1868
        jz      .fail
1877
        jz      .fail
1869
  .nextdevice:
1878
  .nextdevice:
1870
        mov     ebx, dword [esi]
1879
        mov     ebx, dword [esi]
1871
        add     esi, 4
1880
        add     esi, 4
1872
 
1881
 
1873
        mov     edi, [ebx + device.mmio_addr]
1882
        mov     edi, [ebx + device.mmio_addr]
1874
        mov     eax, [IrqStatus]
1883
        mov     eax, [IrqStatus]
1875
        test    eax, eax
1884
        test    eax, eax
1876
        jnz     .got_it
1885
        jnz     .got_it
1877
        dec     ecx
1886
        dec     ecx
1878
        jnz     .nextdevice
1887
        jnz     .nextdevice
1879
  .nothing:
1888
  .nothing:
1880
        pop     edi esi ebx
1889
        pop     edi esi ebx
1881
        xor     eax, eax
1890
        xor     eax, eax
1882
 
1891
 
1883
        ret
1892
        ret
1884
 
1893
 
1885
  .got_it:
1894
  .got_it:
1886
        mov     [IrqStatus], eax
1895
        mov     [IrqStatus], eax
1887
        DEBUGF  1,"IrqStatus = %x\n", eax
1896
        DEBUGF  1,"IrqStatus = %x\n", eax
1888
 
1897
 
1889
        test    eax, IRQ_RX ;+ IRQ_TIMER ;;;;
1898
        test    eax, IRQ_RX ;+ IRQ_TIMER ;;;;
1890
        jz      .no_rx
1899
        jz      .no_rx
1891
 
1900
 
1892
        push    ebx
1901
        push    ebx
1893
  .more_rx:
1902
  .more_rx:
1894
        pop     ebx
1903
        pop     ebx
1895
        mov     eax, [ebx + device.cur_rx]
1904
        mov     eax, [ebx + device.cur_rx]
1896
        mov     cx, sizeof.RxDesc
1905
        mov     cx, sizeof.RxDesc
1897
        mul     cx
1906
        mul     cx
1898
        lea     esi, [ebx + device.rx_ring + eax]
1907
        lea     esi, [ebx + device.rx_ring + eax]
1899
        mov     eax, [esi + RxDesc.FlagLen]
1908
        mov     ecx, [esi + RxDesc.FlagLen]
1900
 
1909
 
1901
        test    eax, NV_RX_AVAIL        ; still owned by hardware
1910
        test    ecx, NV_RX_AVAIL        ; still owned by hardware
1902
        jnz     .no_rx
1911
        jnz     .no_rx
1903
 
1912
 
1904
        cmp     [ebx + device.desc_ver], DESC_VER_1
1913
        cmp     [ebx + device.desc_ver], DESC_VER_1
1905
        jne     @f
1914
        jne     @f
1906
        test    eax, NV_RX_DESCRIPTORVALID
1915
        test    ecx, NV_RX_DESCRIPTORVALID
1907
        jz      .no_rx
1916
        jz      .no_rx
1908
        jmp     .next
1917
        jmp     .next
1909
  @@:
1918
  @@:
1910
        test    eax, NV_RX2_DESCRIPTORVALID
1919
        test    ecx, NV_RX2_DESCRIPTORVALID
1911
        jz      .no_rx
1920
        jz      .no_rx
1912
 
1921
 
1913
  .next:
1922
  .next:
1914
        cmp     dword[ebx + device.desc_ver], DESC_VER_1
1923
        cmp     dword[ebx + device.desc_ver], DESC_VER_1
1915
        jne     @f
1924
        jne     @f
1916
        and     eax, LEN_MASK_V1
1925
        and     ecx, LEN_MASK_V1
1917
        jmp     .next2
1926
        jmp     .next2
1918
   @@:
1927
   @@:
1919
        and     eax, LEN_MASK_V2
1928
        and     ecx, LEN_MASK_V2
1920
 
1929
 
1921
  .next2:
1930
  .next2:
1922
        DEBUGF  1,"Received %u bytes\n", eax
1931
        DEBUGF  1,"Received %u bytes\n", ecx
1923
 
1932
 
1924
        ; Update stats
1933
        ; Update stats
1925
        add     dword[ebx + device.bytes_rx], eax
1934
        add     dword[ebx + device.bytes_rx], ecx
1926
        adc     dword[ebx + device.bytes_rx + 4], 0
1935
        adc     dword[ebx + device.bytes_rx + 4], 0
1927
        inc     dword[ebx + device.packets_rx]
1936
        inc     dword[ebx + device.packets_rx]
1928
 
1937
 
1929
        ; Prepare to give packet to kernel
1938
        ; Prepare to give packet to kernel
1930
        push    ebx
1939
        push    ebx
1931
        push    .more_rx
1940
        push    .more_rx
-
 
1941
 
1932
 
1942
        mov     eax, [esi + RX_RING*sizeof.RxDesc]
-
 
1943
        push    eax
1933
        push    eax
1944
        mov     [eax + NET_BUFF.device], ebx
-
 
1945
        mov     [eax + NET_BUFF.length], ecx
1934
        push    dword[esi + RX_RING*sizeof.RxDesc]
1946
        mov     [eax + NET_BUFF.offset], NET_BUFF.data
1935
        DEBUGF  1,"packet ptr=0x%x\n", [esi + RX_RING*sizeof.RxDesc]
1947
        DEBUGF  1,"packet ptr=0x%x\n", [esi + RX_RING*sizeof.RxDesc]
1936
 
1948
 
1937
        ; Allocate new buffer for this descriptor
1949
        ; Allocate new buffer for this descriptor
1938
        invoke  KernelAlloc, 4096 shl RBLEN
1950
        invoke  NetAlloc, (4096 shl RBLEN) + NET_BUFF.data
1939
        mov     [esi + RX_RING*sizeof.RxDesc], eax
1951
        mov     [esi + RX_RING*sizeof.RxDesc], eax
1940
        invoke  GetPhysAddr
1952
        invoke  GetPhysAddr
-
 
1953
        add     eax, NET_BUFF.data
1941
        mov     [esi + RxDesc.PacketBuffer], eax
1954
        mov     [esi + RxDesc.PacketBuffer], eax
1942
        mov     [esi + RxDesc.FlagLen], (4096 shl RBLEN or NV_RX_AVAIL)
1955
        mov     [esi + RxDesc.FlagLen], (4096 shl RBLEN or NV_RX_AVAIL)
1943
 
1956
 
1944
        ; update current RX descriptor
1957
        ; update current RX descriptor
1945
        inc     [ebx + device.cur_rx]
1958
        inc     [ebx + device.cur_rx]
1946
        and     [ebx + device.cur_rx], (RX_RING-1)
1959
        and     [ebx + device.cur_rx], (RX_RING-1)
1947
 
1960
 
1948
        jmp     [Eth_input]
1961
        jmp     [EthInput]
1949
 
1962
 
1950
  .no_rx:
1963
  .no_rx:
1951
        test    eax, IRQ_RX_ERROR
1964
        test    eax, IRQ_RX_ERROR
1952
        jz      .no_rx_err
1965
        jz      .no_rx_err
1953
 
1966
 
1954
        push    eax
1967
        push    eax
1955
        DEBUGF  2,"RX error!\n"
1968
        DEBUGF  2,"RX error!\n"
1956
 
1969
 
1957
        mov     eax, [ebx + device.cur_rx]
1970
        mov     eax, [ebx + device.cur_rx]
1958
        mov     cx, sizeof.RxDesc
1971
        mov     cx, sizeof.RxDesc
1959
        mul     cx
1972
        mul     cx
1960
        lea     esi, [ebx + device.rx_ring + eax]
1973
        lea     esi, [ebx + device.rx_ring + eax]
1961
        mov     eax, [esi + RxDesc.FlagLen]
1974
        mov     eax, [esi + RxDesc.FlagLen]
1962
 
1975
 
1963
        DEBUGF  1,"Flaglen=%x\n", eax
1976
        DEBUGF  1,"Flaglen=%x\n", eax
1964
 
1977
 
1965
        ; TODO: allocate new buff ?
1978
        ; TODO: allocate new buff ?
1966
        pop     eax
1979
        pop     eax
1967
 
1980
 
1968
  .no_rx_err:
1981
  .no_rx_err:
1969
        test    eax, IRQ_TX_ERROR
1982
        test    eax, IRQ_TX_ERROR
1970
        jz      .no_tx_err
1983
        jz      .no_tx_err
1971
 
1984
 
1972
        DEBUGF  2,"TX error!\n"
1985
        DEBUGF  2,"TX error!\n"
1973
        ; TODO
1986
        ; TODO
1974
 
1987
 
1975
  .no_tx_err:
1988
  .no_tx_err:
1976
        test    eax, IRQ_LINK
1989
        test    eax, IRQ_LINK
1977
        jz      .no_link
1990
        jz      .no_link
1978
 
1991
 
1979
        push    eax
1992
        push    eax
1980
        call    update_linkspeed
1993
        call    update_linkspeed
1981
        pop     eax
1994
        pop     eax
1982
 
1995
 
1983
  .no_link:
1996
  .no_link:
1984
        test    eax, IRQ_TX_OK
1997
        test    eax, IRQ_TX_OK
1985
        jz      .no_tx
1998
        jz      .no_tx
1986
 
1999
 
1987
        DEBUGF  1, "TX completed\n"
2000
        DEBUGF  1, "TX completed\n"
1988
      .loop_tx:
2001
      .loop_tx:
1989
        mov     esi, [ebx + device.last_tx]
2002
        mov     esi, [ebx + device.last_tx]
1990
        shl     esi, 3                                  ; TX descriptor is 8 bytes.
2003
        shl     esi, 3                                  ; TX descriptor is 8 bytes.
1991
        lea     esi, [ebx + device.tx_ring + esi]
2004
        lea     esi, [ebx + device.tx_ring + esi]
1992
 
2005
 
1993
        DEBUGF  1,"Flaglen = 0x%x\n", [esi + TxDesc.FlagLen]
2006
        DEBUGF  1,"Flaglen = 0x%x\n", [esi + TxDesc.FlagLen]
1994
        test    [esi + TxDesc.FlagLen], NV_TX_VALID
2007
        test    [esi + TxDesc.FlagLen], NV_TX_VALID
1995
        jnz     .no_tx
2008
        jnz     .no_tx
1996
        cmp     dword[esi + TX_RING*sizeof.TxDesc], 0
2009
        cmp     dword[esi + TX_RING*sizeof.TxDesc], 0
1997
        je      .no_tx
2010
        je      .no_tx
1998
 
2011
 
1999
        DEBUGF  1,"Freeing buffer 0x%x\n", [esi + TX_RING*sizeof.TxDesc]:8
2012
        DEBUGF  1,"Freeing buffer 0x%x\n", [esi + TX_RING*sizeof.TxDesc]:8
2000
        push    dword[esi + TX_RING*sizeof.TxDesc]
2013
        push    dword[esi + TX_RING*sizeof.TxDesc]
2001
        mov     dword[esi + TX_RING*sizeof.TxDesc], 0
2014
        mov     dword[esi + TX_RING*sizeof.TxDesc], 0
2002
        invoke  KernelFree
2015
        invoke  NetFree
2003
 
2016
 
2004
        inc     [ebx + device.last_tx]
2017
        inc     [ebx + device.last_tx]
2005
        and     [ebx + device.last_tx], TX_RING - 1
2018
        and     [ebx + device.last_tx], TX_RING - 1
2006
 
2019
 
2007
        jmp     .loop_tx
2020
        jmp     .loop_tx
2008
 
2021
 
2009
  .no_tx:
2022
  .no_tx:
2010
  .fail:
2023
  .fail:
2011
        pop     edi esi ebx
2024
        pop     edi esi ebx
2012
        xor     eax, eax
2025
        xor     eax, eax
2013
        inc     eax
2026
        inc     eax
2014
 
2027
 
2015
        ret
2028
        ret
2016
 
2029
 
2017
 
2030
 
2018
; End of code
2031
; End of code
2019
 
2032
 
2020
data fixups
2033
data fixups
2021
end data
2034
end data
2022
 
2035
 
2023
include '../peimport.inc'
2036
include '../peimport.inc'
2024
 
2037
 
2025
my_service      db 'FORCEDETH',0                ; max 16 chars include zero
2038
my_service      db 'FORCEDETH',0                ; max 16 chars include zero
2026
 
2039
 
2027
include_debug_strings
2040
include_debug_strings
2028
 
2041
 
2029
align 4
2042
align 4
2030
devices         dd 0
2043
devices         dd 0
2031
device_list     rd MAX_DEVICES                  ; This list contains all pointers to device structures the driver is handling
2044
device_list     rd MAX_DEVICES                  ; This list contains all pointers to device structures the driver is handling