Rev 5498 | Rev 5567 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5498 | 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 | ;; RTL8169 driver for KolibriOS ;; |
6 | ;; RTL8169 driver for KolibriOS ;; |
7 | ;; ;; |
7 | ;; ;; |
8 | ;; Copyright 2007 mike.dld, ;; |
8 | ;; Copyright 2007 mike.dld, ;; |
9 | ;; mike.dld@gmail.com ;; |
9 | ;; mike.dld@gmail.com ;; |
10 | ;; ;; |
10 | ;; ;; |
11 | ;; port to net branch by hidnplayr ;; |
11 | ;; port to net branch by hidnplayr ;; |
12 | ;; ;; |
12 | ;; ;; |
13 | ;; References: ;; |
13 | ;; References: ;; |
14 | ;; r8169.c - linux driver (etherboot project) ;; |
14 | ;; r8169.c - linux driver (etherboot project) ;; |
15 | ;; ;; |
15 | ;; ;; |
16 | ;; GNU GENERAL PUBLIC LICENSE ;; |
16 | ;; GNU GENERAL PUBLIC LICENSE ;; |
17 | ;; Version 2, June 1991 ;; |
17 | ;; Version 2, June 1991 ;; |
18 | ;; ;; |
18 | ;; ;; |
19 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
19 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
20 | 20 | ||
21 | format PE DLL native |
21 | format PE DLL native |
22 | entry START |
22 | entry START |
23 | 23 | ||
24 | CURRENT_API = 0x0200 |
24 | CURRENT_API = 0x0200 |
25 | COMPATIBLE_API = 0x0100 |
25 | COMPATIBLE_API = 0x0100 |
26 | API_VERSION = (COMPATIBLE_API shl 16) + CURRENT_API |
26 | API_VERSION = (COMPATIBLE_API shl 16) + CURRENT_API |
27 | 27 | ||
28 | MAX_DEVICES = 16 |
28 | MAX_DEVICES = 16 |
29 | 29 | ||
30 | __DEBUG__ = 1 |
30 | __DEBUG__ = 1 |
31 | __DEBUG_LEVEL__ = 2 ; 1 = verbose, 2 = errors only |
31 | __DEBUG_LEVEL__ = 2 ; 1 = verbose, 2 = errors only |
32 | 32 | ||
33 | NUM_TX_DESC = 4 |
33 | NUM_TX_DESC = 4 |
34 | NUM_RX_DESC = 4 |
34 | NUM_RX_DESC = 4 |
35 | 35 | ||
36 | section '.flat' readable writable executable |
36 | section '.flat' readable writable executable |
37 | 37 | ||
38 | include '../proc32.inc' |
38 | include '../proc32.inc' |
39 | include '../struct.inc' |
39 | include '../struct.inc' |
40 | include '../macros.inc' |
40 | include '../macros.inc' |
41 | include '../fdo.inc' |
41 | include '../fdo.inc' |
42 | include '../netdrv.inc' |
42 | include '../netdrv.inc' |
43 | 43 | ||
44 | REG_MAC0 = 0x0 ; Ethernet hardware address |
44 | REG_MAC0 = 0x0 ; Ethernet hardware address |
45 | REG_MAR0 = 0x8 ; Multicast filter |
45 | REG_MAR0 = 0x8 ; Multicast filter |
46 | REG_TxDescStartAddr = 0x20 |
46 | REG_TxDescStartAddr = 0x20 |
47 | REG_TxHDescStartAddr = 0x28 |
47 | REG_TxHDescStartAddr = 0x28 |
48 | REG_FLASH = 0x30 |
48 | REG_FLASH = 0x30 |
49 | REG_ERSR = 0x36 |
49 | REG_ERSR = 0x36 |
50 | REG_ChipCmd = 0x37 |
50 | REG_ChipCmd = 0x37 |
51 | REG_TxPoll = 0x38 |
51 | REG_TxPoll = 0x38 |
52 | REG_IntrMask = 0x3C |
52 | REG_IntrMask = 0x3C |
53 | REG_IntrStatus = 0x3E |
53 | REG_IntrStatus = 0x3E |
54 | REG_TxConfig = 0x40 |
54 | REG_TxConfig = 0x40 |
55 | REG_RxConfig = 0x44 |
55 | REG_RxConfig = 0x44 |
56 | REG_RxMissed = 0x4C |
56 | REG_RxMissed = 0x4C |
57 | REG_Cfg9346 = 0x50 |
57 | REG_Cfg9346 = 0x50 |
58 | REG_Config0 = 0x51 |
58 | REG_Config0 = 0x51 |
59 | REG_Config1 = 0x52 |
59 | REG_Config1 = 0x52 |
60 | REG_Config2 = 0x53 |
60 | REG_Config2 = 0x53 |
61 | REG_Config3 = 0x54 |
61 | REG_Config3 = 0x54 |
62 | REG_Config4 = 0x55 |
62 | REG_Config4 = 0x55 |
63 | REG_Config5 = 0x56 |
63 | REG_Config5 = 0x56 |
64 | REG_MultiIntr = 0x5C |
64 | REG_MultiIntr = 0x5C |
65 | REG_PHYAR = 0x60 |
65 | REG_PHYAR = 0x60 |
66 | REG_TBICSR = 0x64 |
66 | REG_TBICSR = 0x64 |
67 | REG_TBI_ANAR = 0x68 |
67 | REG_TBI_ANAR = 0x68 |
68 | REG_TBI_LPAR = 0x6A |
68 | REG_TBI_LPAR = 0x6A |
69 | REG_PHYstatus = 0x6C |
69 | REG_PHYstatus = 0x6C |
70 | REG_RxMaxSize = 0xDA |
70 | REG_RxMaxSize = 0xDA |
71 | REG_CPlusCmd = 0xE0 |
71 | REG_CPlusCmd = 0xE0 |
72 | REG_RxDescStartAddr = 0xE4 |
72 | REG_RxDescStartAddr = 0xE4 |
73 | REG_ETThReg = 0xEC |
73 | REG_ETThReg = 0xEC |
74 | REG_FuncEvent = 0xF0 |
74 | REG_FuncEvent = 0xF0 |
75 | REG_FuncEventMask = 0xF4 |
75 | REG_FuncEventMask = 0xF4 |
76 | REG_FuncPresetState = 0xF8 |
76 | REG_FuncPresetState = 0xF8 |
77 | REG_FuncForceEvent = 0xFC |
77 | REG_FuncForceEvent = 0xFC |
78 | 78 | ||
79 | ; InterruptStatusBits |
79 | ; InterruptStatusBits |
80 | ISB_SYSErr = 0x8000 |
80 | ISB_SYSErr = 0x8000 |
81 | ISB_PCSTimeout = 0x4000 |
81 | ISB_PCSTimeout = 0x4000 |
82 | ISB_SWInt = 0x0100 |
82 | ISB_SWInt = 0x0100 |
83 | ISB_TxDescUnavail = 0x80 |
83 | ISB_TxDescUnavail = 0x80 |
84 | ISB_RxFIFOOver = 0x40 |
84 | ISB_RxFIFOOver = 0x40 |
85 | ISB_LinkChg = 0x20 |
85 | ISB_LinkChg = 0x20 |
86 | ISB_RxOverflow = 0x10 |
86 | ISB_RxOverflow = 0x10 |
87 | ISB_TxErr = 0x08 |
87 | ISB_TxErr = 0x08 |
88 | ISB_TxOK = 0x04 |
88 | ISB_TxOK = 0x04 |
89 | ISB_RxErr = 0x02 |
89 | ISB_RxErr = 0x02 |
90 | ISB_RxOK = 0x01 |
90 | ISB_RxOK = 0x01 |
91 | 91 | ||
92 | ; RxStatusDesc |
92 | ; RxStatusDesc |
93 | SD_RxRES = 0x00200000 |
93 | SD_RxRES = 0x00200000 |
94 | SD_RxCRC = 0x00080000 |
94 | SD_RxCRC = 0x00080000 |
95 | SD_RxRUNT = 0x00100000 |
95 | SD_RxRUNT = 0x00100000 |
96 | SD_RxRWT = 0x00400000 |
96 | SD_RxRWT = 0x00400000 |
97 | 97 | ||
98 | ; ChipCmdBits |
98 | ; ChipCmdBits |
99 | CMD_Reset = 0x10 |
99 | CMD_Reset = 0x10 |
100 | CMD_RxEnb = 0x08 |
100 | CMD_RxEnb = 0x08 |
101 | CMD_TxEnb = 0x04 |
101 | CMD_TxEnb = 0x04 |
102 | CMD_RxBufEmpty = 0x01 |
102 | CMD_RxBufEmpty = 0x01 |
103 | 103 | ||
104 | ; Cfg9346Bits |
104 | ; Cfg9346Bits |
105 | CFG_9346_Lock = 0x00 |
105 | CFG_9346_Lock = 0x00 |
106 | CFG_9346_Unlock = 0xC0 |
106 | CFG_9346_Unlock = 0xC0 |
107 | 107 | ||
108 | ; rx_mode_bits |
108 | ; rx_mode_bits |
109 | RXM_AcceptErr = 0x20 |
109 | RXM_AcceptErr = 0x20 |
110 | RXM_AcceptRunt = 0x10 |
110 | RXM_AcceptRunt = 0x10 |
111 | RXM_AcceptBroadcast = 0x08 |
111 | RXM_AcceptBroadcast = 0x08 |
112 | RXM_AcceptMulticast = 0x04 |
112 | RXM_AcceptMulticast = 0x04 |
113 | RXM_AcceptMyPhys = 0x02 |
113 | RXM_AcceptMyPhys = 0x02 |
114 | RXM_AcceptAllPhys = 0x01 |
114 | RXM_AcceptAllPhys = 0x01 |
115 | 115 | ||
116 | ; RxConfigBits |
116 | ; RxConfigBits |
117 | RXC_FIFOShift = 13 |
117 | RXC_FIFOShift = 13 |
118 | RXC_DMAShift = 8 |
118 | RXC_DMAShift = 8 |
119 | 119 | ||
120 | ; TxConfigBits |
120 | ; TxConfigBits |
121 | TXC_InterFrameGapShift = 24 |
121 | TXC_InterFrameGapShift = 24 |
122 | TXC_DMAShift = 8 ; DMA burst value (0-7) is shift this many bits |
122 | TXC_DMAShift = 8 ; DMA burst value (0-7) is shift this many bits |
123 | 123 | ||
124 | ; PHYstatus |
124 | ; PHYstatus |
125 | PHYS_TBI_Enable = 0x80 |
125 | PHYS_TBI_Enable = 0x80 |
126 | PHYS_TxFlowCtrl = 0x40 |
126 | PHYS_TxFlowCtrl = 0x40 |
127 | PHYS_RxFlowCtrl = 0x20 |
127 | PHYS_RxFlowCtrl = 0x20 |
128 | PHYS_1000bpsF = 0x10 |
128 | PHYS_1000bpsF = 0x10 |
129 | PHYS_100bps = 0x08 |
129 | PHYS_100bps = 0x08 |
130 | PHYS_10bps = 0x04 |
130 | PHYS_10bps = 0x04 |
131 | PHYS_LinkStatus = 0x02 |
131 | PHYS_LinkStatus = 0x02 |
132 | PHYS_FullDup = 0x01 |
132 | PHYS_FullDup = 0x01 |
133 | 133 | ||
134 | ; GIGABIT_PHY_registers |
134 | ; GIGABIT_PHY_registers |
135 | PHY_CTRL_REG = 0 |
135 | PHY_CTRL_REG = 0 |
136 | PHY_STAT_REG = 1 |
136 | PHY_STAT_REG = 1 |
137 | PHY_AUTO_NEGO_REG = 4 |
137 | PHY_AUTO_NEGO_REG = 4 |
138 | PHY_1000_CTRL_REG = 9 |
138 | PHY_1000_CTRL_REG = 9 |
139 | 139 | ||
140 | ; GIGABIT_PHY_REG_BIT |
140 | ; GIGABIT_PHY_REG_BIT |
141 | PHY_Restart_Auto_Nego = 0x0200 |
141 | PHY_Restart_Auto_Nego = 0x0200 |
142 | PHY_Enable_Auto_Nego = 0x1000 |
142 | PHY_Enable_Auto_Nego = 0x1000 |
143 | 143 | ||
144 | ; PHY_STAT_REG = 1 |
144 | ; PHY_STAT_REG = 1 |
145 | PHY_Auto_Neco_Comp = 0x0020 |
145 | PHY_Auto_Neco_Comp = 0x0020 |
146 | 146 | ||
147 | ; PHY_AUTO_NEGO_REG = 4 |
147 | ; PHY_AUTO_NEGO_REG = 4 |
148 | PHY_Cap_10_Half = 0x0020 |
148 | PHY_Cap_10_Half = 0x0020 |
149 | PHY_Cap_10_Full = 0x0040 |
149 | PHY_Cap_10_Full = 0x0040 |
150 | PHY_Cap_100_Half = 0x0080 |
150 | PHY_Cap_100_Half = 0x0080 |
151 | PHY_Cap_100_Full = 0x0100 |
151 | PHY_Cap_100_Full = 0x0100 |
152 | 152 | ||
153 | ; PHY_1000_CTRL_REG = 9 |
153 | ; PHY_1000_CTRL_REG = 9 |
154 | PHY_Cap_1000_Full = 0x0200 |
154 | PHY_Cap_1000_Full = 0x0200 |
155 | PHY_Cap_1000_Half = 0x0100 |
155 | PHY_Cap_1000_Half = 0x0100 |
156 | 156 | ||
157 | PHY_Cap_PAUSE = 0x0400 |
157 | PHY_Cap_PAUSE = 0x0400 |
158 | PHY_Cap_ASYM_PAUSE = 0x0800 |
158 | PHY_Cap_ASYM_PAUSE = 0x0800 |
159 | 159 | ||
160 | PHY_Cap_Null = 0x0 |
160 | PHY_Cap_Null = 0x0 |
161 | 161 | ||
162 | ; _MediaType |
162 | ; _MediaType |
163 | MT_10_Half = 0x01 |
163 | MT_10_Half = 0x01 |
164 | MT_10_Full = 0x02 |
164 | MT_10_Full = 0x02 |
165 | MT_100_Half = 0x04 |
165 | MT_100_Half = 0x04 |
166 | MT_100_Full = 0x08 |
166 | MT_100_Full = 0x08 |
167 | MT_1000_Full = 0x10 |
167 | MT_1000_Full = 0x10 |
168 | 168 | ||
169 | ; _TBICSRBit |
169 | ; _TBICSRBit |
170 | TBI_LinkOK = 0x02000000 |
170 | TBI_LinkOK = 0x02000000 |
171 | 171 | ||
172 | ; _DescStatusBit |
172 | ; _DescStatusBit |
173 | DSB_OWNbit = 0x80000000 |
173 | DSB_OWNbit = 0x80000000 |
174 | DSB_EORbit = 0x40000000 |
174 | DSB_EORbit = 0x40000000 |
175 | DSB_FSbit = 0x20000000 |
175 | DSB_FSbit = 0x20000000 |
176 | DSB_LSbit = 0x10000000 |
176 | DSB_LSbit = 0x10000000 |
177 | 177 | ||
178 | RX_BUF_SIZE = 1536 ; Rx Buffer size |
178 | RX_BUF_SIZE = 1514 ; Rx Buffer size |
179 | 179 | ||
180 | ; max supported gigabit ethernet frame size -- must be at least (dev->mtu+14+4) |
180 | ; max supported gigabit ethernet frame size -- must be at least (dev->mtu+14+4) |
181 | MAX_ETH_FRAME_SIZE = 1536 |
181 | MAX_ETH_FRAME_SIZE = 1514 |
182 | 182 | ||
183 | TX_FIFO_THRESH = 256 ; In bytes |
183 | TX_FIFO_THRESH = 256 ; In bytes |
184 | 184 | ||
185 | RX_FIFO_THRESH = 7 ; 7 means NO threshold, Rx buffer level before first PCI xfer |
185 | RX_FIFO_THRESH = 7 ; 7 means NO threshold, Rx buffer level before first PCI xfer |
186 | RX_DMA_BURST = 7 ; Maximum PCI burst, '6' is 1024 |
186 | RX_DMA_BURST = 7 ; Maximum PCI burst, '6' is 1024 |
187 | TX_DMA_BURST = 7 ; Maximum PCI burst, '6' is 1024 |
187 | TX_DMA_BURST = 7 ; Maximum PCI burst, '6' is 1024 |
188 | ETTh = 0x3F ; 0x3F means NO threshold |
188 | ETTh = 0x3F ; 0x3F means NO threshold |
189 | 189 | ||
190 | EarlyTxThld = 0x3F ; 0x3F means NO early transmit |
190 | EarlyTxThld = 0x3F ; 0x3F means NO early transmit |
191 | RxPacketMaxSize = 0x0800 ; Maximum size supported is 16K-1 |
191 | RxPacketMaxSize = 0x0800 ; Maximum size supported is 16K-1 |
192 | InterFrameGap = 0x03 ; 3 means InterFrameGap = the shortest one |
192 | InterFrameGap = 0x03 ; 3 means InterFrameGap = the shortest one |
193 | 193 | ||
194 | HZ = 1000 |
194 | HZ = 1000 |
195 | 195 | ||
196 | RTL_MIN_IO_SIZE = 0x80 |
196 | RTL_MIN_IO_SIZE = 0x80 |
197 | TX_TIMEOUT = (6*HZ) |
197 | TX_TIMEOUT = (6*HZ) |
198 | 198 | ||
199 | TIMER_EXPIRE_TIME = 100 |
199 | TIMER_EXPIRE_TIME = 100 |
200 | 200 | ||
201 | ETH_HDR_LEN = 14 |
201 | ETH_HDR_LEN = 14 |
202 | DEFAULT_MTU = 1500 |
202 | DEFAULT_MTU = 1500 |
203 | DEFAULT_RX_BUF_LEN = 1536 |
203 | DEFAULT_RX_BUF_LEN = 1514 |
204 | 204 | ||
205 | 205 | ||
206 | ;ifdef JUMBO_FRAME_SUPPORT |
206 | ;ifdef JUMBO_FRAME_SUPPORT |
207 | ; MAX_JUMBO_FRAME_MTU = 10000 |
207 | ; MAX_JUMBO_FRAME_MTU = 10000 |
208 | ; MAX_RX_SKBDATA_SIZE = (MAX_JUMBO_FRAME_MTU + ETH_HDR_LEN ) |
208 | ; MAX_RX_SKBDATA_SIZE = (MAX_JUMBO_FRAME_MTU + ETH_HDR_LEN ) |
209 | ;else |
209 | ;else |
210 | MAX_RX_SKBDATA_SIZE = 1600 |
210 | MAX_RX_SKBDATA_SIZE = 1600 |
211 | ;end if |
211 | ;end if |
212 | 212 | ||
213 | MCFG_METHOD_01 = 0x01 |
213 | MCFG_METHOD_01 = 0x01 |
214 | MCFG_METHOD_02 = 0x02 |
214 | MCFG_METHOD_02 = 0x02 |
215 | MCFG_METHOD_03 = 0x03 |
215 | MCFG_METHOD_03 = 0x03 |
216 | MCFG_METHOD_04 = 0x04 |
216 | MCFG_METHOD_04 = 0x04 |
217 | MCFG_METHOD_05 = 0x05 |
217 | MCFG_METHOD_05 = 0x05 |
218 | MCFG_METHOD_11 = 0x0b |
218 | MCFG_METHOD_11 = 0x0b |
219 | MCFG_METHOD_12 = 0x0c |
219 | MCFG_METHOD_12 = 0x0c |
220 | MCFG_METHOD_13 = 0x0d |
220 | MCFG_METHOD_13 = 0x0d |
221 | MCFG_METHOD_14 = 0x0e |
221 | MCFG_METHOD_14 = 0x0e |
222 | MCFG_METHOD_15 = 0x0f |
222 | MCFG_METHOD_15 = 0x0f |
223 | 223 | ||
224 | PCFG_METHOD_1 = 0x01 ; PHY Reg 0x03 bit0-3 == 0x0000 |
224 | PCFG_METHOD_1 = 0x01 ; PHY Reg 0x03 bit0-3 == 0x0000 |
225 | PCFG_METHOD_2 = 0x02 ; PHY Reg 0x03 bit0-3 == 0x0001 |
225 | PCFG_METHOD_2 = 0x02 ; PHY Reg 0x03 bit0-3 == 0x0001 |
226 | PCFG_METHOD_3 = 0x03 ; PHY Reg 0x03 bit0-3 == 0x0002 |
226 | PCFG_METHOD_3 = 0x03 ; PHY Reg 0x03 bit0-3 == 0x0002 |
227 | 227 | ||
228 | struct tx_desc |
228 | struct tx_desc |
229 | status dd ? |
229 | status dd ? |
230 | vlan_tag dd ? |
230 | vlan_tag dd ? |
231 | buf_addr dq ? |
231 | buf_addr dq ? |
232 | ends |
232 | ends |
233 | tx_desc.buf_soft_addr = NUM_TX_DESC*sizeof.tx_desc |
233 | tx_desc.buf_soft_addr = NUM_TX_DESC*sizeof.tx_desc |
234 | 234 | ||
235 | struct rx_desc |
235 | struct rx_desc |
236 | status dd ? |
236 | status dd ? |
237 | vlan_tag dd ? |
237 | vlan_tag dd ? |
238 | buf_addr dq ? |
238 | buf_addr dq ? |
239 | ends |
239 | ends |
240 | rx_desc.buf_soft_addr = NUM_RX_DESC*sizeof.rx_desc |
240 | rx_desc.buf_soft_addr = NUM_RX_DESC*sizeof.rx_desc |
241 | 241 | ||
242 | struct device ETH_DEVICE |
242 | struct device ETH_DEVICE |
243 | 243 | ||
244 | io_addr dd ? |
244 | io_addr dd ? |
245 | pci_bus dd ? |
245 | pci_bus dd ? |
246 | pci_dev dd ? |
246 | pci_dev dd ? |
247 | irq_line db ? |
247 | irq_line db ? |
248 | rb 3 ; align 4 |
248 | rb 3 ; align 4 |
249 | mmio_addr dd ? ; memory map physical address |
249 | mmio_addr dd ? ; memory map physical address |
250 | pcfg dd ? |
250 | pcfg dd ? |
251 | mcfg dd ? |
251 | mcfg dd ? |
252 | 252 | ||
253 | cur_rx dd ? ; Index into the Rx descriptor buffer of next Rx pkt |
253 | cur_rx dd ? ; Index into the Rx descriptor buffer of next Rx pkt |
254 | cur_tx dd ? ; Index into the Tx descriptor buffer of next Rx pkt |
254 | cur_tx dd ? ; Index into the Tx descriptor buffer of next Rx pkt |
255 | last_tx dd ? |
255 | last_tx dd ? |
256 | mac_version dd ? |
256 | mac_version dd ? |
257 | 257 | ||
258 | rb 0x100-($ and 0xff) ; align 256 |
258 | rb 0x100-($ and 0xff) ; align 256 |
259 | tx_ring rb NUM_TX_DESC * sizeof.tx_desc * 2 |
259 | tx_ring rb NUM_TX_DESC * sizeof.tx_desc * 2 |
260 | 260 | ||
261 | rb 0x100-($ and 0xff) ; align 256 |
261 | rb 0x100-($ and 0xff) ; align 256 |
262 | rx_ring rb NUM_RX_DESC * sizeof.rx_desc * 2 |
262 | rx_ring rb NUM_RX_DESC * sizeof.rx_desc * 2 |
263 | 263 | ||
264 | ends |
264 | ends |
265 | 265 | ||
266 | intr_mask = ISB_LinkChg or ISB_RxOverflow or ISB_RxFIFOOver or ISB_TxErr or ISB_TxOK or ISB_RxErr or ISB_RxOK |
266 | intr_mask = ISB_LinkChg or ISB_RxOverflow or ISB_RxFIFOOver or ISB_TxErr or ISB_TxOK or ISB_RxErr or ISB_RxOK |
267 | rx_config = (RX_FIFO_THRESH shl RXC_FIFOShift) or (RX_DMA_BURST shl RXC_DMAShift) or 0x0000000E |
267 | rx_config = (RX_FIFO_THRESH shl RXC_FIFOShift) or (RX_DMA_BURST shl RXC_DMAShift) or 0x0000000E |
268 | 268 | ||
269 | 269 | ||
270 | macro udelay msec { |
270 | macro udelay msec { |
271 | 271 | ||
272 | push esi ecx |
272 | push esi ecx |
273 | mov esi, msec |
273 | mov esi, msec |
274 | invoke Sleep |
274 | invoke Sleep |
275 | pop ecx esi |
275 | pop ecx esi |
276 | 276 | ||
277 | } |
277 | } |
278 | 278 | ||
279 | macro WRITE_GMII_REG RegAddr, value { |
279 | macro WRITE_GMII_REG RegAddr, value { |
280 | 280 | ||
281 | set_io [ebx + device.io_addr], REG_PHYAR |
281 | set_io [ebx + device.io_addr], REG_PHYAR |
282 | if value eq ax |
282 | if value eq ax |
283 | and eax, 0x0000ffff |
283 | and eax, 0x0000ffff |
284 | or eax, 0x80000000 + (RegAddr shl 16) |
284 | or eax, 0x80000000 + (RegAddr shl 16) |
285 | else |
285 | else |
286 | mov eax, 0x80000000 + (RegAddr shl 16) + value |
286 | mov eax, 0x80000000 + (RegAddr shl 16) + value |
287 | end if |
287 | end if |
288 | out dx, eax |
288 | out dx, eax |
289 | 289 | ||
290 | call PHY_WAIT_WRITE |
290 | call PHY_WAIT_WRITE |
291 | } |
291 | } |
292 | 292 | ||
293 | macro READ_GMII_REG RegAddr { |
293 | macro READ_GMII_REG RegAddr { |
294 | 294 | ||
295 | local .error, .done |
295 | local .error, .done |
296 | 296 | ||
297 | set_io [ebx + device.io_addr], REG_PHYAR |
297 | set_io [ebx + device.io_addr], REG_PHYAR |
298 | mov eax, RegAddr shl 16 |
298 | mov eax, RegAddr shl 16 |
299 | out dx, eax |
299 | out dx, eax |
300 | 300 | ||
301 | call PHY_WAIT_READ |
301 | call PHY_WAIT_READ |
302 | jz .error |
302 | jz .error |
303 | 303 | ||
304 | in eax, dx |
304 | in eax, dx |
305 | and eax, 0xFFFF |
305 | and eax, 0xFFFF |
306 | jmp .done |
306 | jmp .done |
307 | 307 | ||
308 | .error: |
308 | .error: |
309 | or eax, -1 |
309 | or eax, -1 |
310 | .done: |
310 | .done: |
311 | } |
311 | } |
312 | 312 | ||
313 | align 4 |
313 | align 4 |
314 | PHY_WAIT_READ: ; io addr must already be set to REG_PHYAR |
314 | PHY_WAIT_READ: ; io addr must already be set to REG_PHYAR |
315 | 315 | ||
316 | udelay 1 ;;;1000 |
316 | udelay 1 ;;;1000 |
317 | 317 | ||
318 | push ecx |
318 | push ecx |
319 | mov ecx, 2000 |
319 | mov ecx, 2000 |
320 | ; Check if the RTL8169 has completed writing/reading to the specified MII register |
320 | ; Check if the RTL8169 has completed writing/reading to the specified MII register |
321 | @@: |
321 | @@: |
322 | in eax, dx |
322 | in eax, dx |
323 | test eax, 0x80000000 |
323 | test eax, 0x80000000 |
324 | jnz .exit |
324 | jnz .exit |
325 | udelay 1 ;;;100 |
325 | udelay 1 ;;;100 |
326 | loop @b |
326 | loop @b |
327 | .exit: |
327 | .exit: |
328 | pop ecx |
328 | pop ecx |
329 | ret |
329 | ret |
330 | 330 | ||
331 | align 4 |
331 | align 4 |
332 | PHY_WAIT_WRITE: ; io addr must already be set to REG_PHYAR |
332 | PHY_WAIT_WRITE: ; io addr must already be set to REG_PHYAR |
333 | 333 | ||
334 | udelay 1 ;;;1000 |
334 | udelay 1 ;;;1000 |
335 | 335 | ||
336 | push ecx |
336 | push ecx |
337 | mov ecx, 2000 |
337 | mov ecx, 2000 |
338 | ; Check if the RTL8169 has completed writing/reading to the specified MII register |
338 | ; Check if the RTL8169 has completed writing/reading to the specified MII register |
339 | @@: |
339 | @@: |
340 | in eax, dx |
340 | in eax, dx |
341 | test eax, 0x80000000 |
341 | test eax, 0x80000000 |
342 | jz .exit |
342 | jz .exit |
343 | udelay 1 ;;;100 |
343 | udelay 1 ;;;100 |
344 | loop @b |
344 | loop @b |
345 | .exit: |
345 | .exit: |
346 | pop ecx |
346 | pop ecx |
347 | ret |
347 | ret |
348 | 348 | ||
349 | 349 | ||
350 | 350 | ||
351 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
351 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
352 | ;; ;; |
352 | ;; ;; |
353 | ;; proc START ;; |
353 | ;; proc START ;; |
354 | ;; ;; |
354 | ;; ;; |
355 | ;; (standard driver proc) ;; |
355 | ;; (standard driver proc) ;; |
356 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
356 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
357 | 357 | ||
358 | proc START c, reason:dword, cmdline:dword |
358 | proc START c, reason:dword, cmdline:dword |
359 | 359 | ||
360 | cmp [reason], DRV_ENTRY |
360 | cmp [reason], DRV_ENTRY |
361 | jne .fail |
361 | jne .fail |
362 | 362 | ||
363 | DEBUGF 2,"Loading driver\n" |
363 | DEBUGF 2,"Loading driver\n" |
364 | invoke RegService, my_service, service_proc |
364 | invoke RegService, my_service, service_proc |
365 | ret |
365 | ret |
366 | 366 | ||
367 | .fail: |
367 | .fail: |
368 | xor eax, eax |
368 | xor eax, eax |
369 | ret |
369 | ret |
370 | 370 | ||
371 | endp |
371 | endp |
372 | 372 | ||
373 | 373 | ||
374 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
374 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
375 | ;; ;; |
375 | ;; ;; |
376 | ;; proc SERVICE_PROC ;; |
376 | ;; proc SERVICE_PROC ;; |
377 | ;; ;; |
377 | ;; ;; |
378 | ;; (standard driver proc) ;; |
378 | ;; (standard driver proc) ;; |
379 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
379 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
380 | 380 | ||
381 | proc service_proc stdcall, ioctl:dword |
381 | proc service_proc stdcall, ioctl:dword |
382 | 382 | ||
383 | mov edx, [ioctl] |
383 | mov edx, [ioctl] |
384 | mov eax, [edx + IOCTL.io_code] |
384 | mov eax, [edx + IOCTL.io_code] |
385 | 385 | ||
386 | ;------------------------------------------------------ |
386 | ;------------------------------------------------------ |
387 | 387 | ||
388 | cmp eax, 0 ;SRV_GETVERSION |
388 | cmp eax, 0 ;SRV_GETVERSION |
389 | jne @F |
389 | jne @F |
390 | 390 | ||
391 | cmp [edx + IOCTL.out_size], 4 |
391 | cmp [edx + IOCTL.out_size], 4 |
392 | jb .fail |
392 | jb .fail |
393 | mov eax, [edx + IOCTL.output] |
393 | mov eax, [edx + IOCTL.output] |
394 | mov [eax], dword API_VERSION |
394 | mov [eax], dword API_VERSION |
395 | 395 | ||
396 | xor eax, eax |
396 | xor eax, eax |
397 | ret |
397 | ret |
398 | 398 | ||
399 | ;------------------------------------------------------ |
399 | ;------------------------------------------------------ |
400 | @@: |
400 | @@: |
401 | cmp eax, 1 ;SRV_HOOK |
401 | cmp eax, 1 ;SRV_HOOK |
402 | jne .fail |
402 | jne .fail |
403 | 403 | ||
404 | cmp [edx + IOCTL.inp_size], 3 ; Data input must be at least 3 bytes |
404 | cmp [edx + IOCTL.inp_size], 3 ; Data input must be at least 3 bytes |
405 | jb .fail |
405 | jb .fail |
406 | 406 | ||
407 | mov eax, [edx + IOCTL.input] |
407 | mov eax, [edx + IOCTL.input] |
408 | cmp byte [eax], 1 ; 1 means device number and bus number (pci) are given |
408 | cmp byte [eax], 1 ; 1 means device number and bus number (pci) are given |
409 | jne .fail ; other types arent supported for this card yet |
409 | jne .fail ; other types arent supported for this card yet |
410 | 410 | ||
411 | ; check if the device is already listed |
411 | ; check if the device is already listed |
412 | 412 | ||
413 | mov esi, device_list |
413 | mov esi, device_list |
414 | mov ecx, [devices] |
414 | mov ecx, [devices] |
415 | test ecx, ecx |
415 | test ecx, ecx |
416 | jz .firstdevice |
416 | jz .firstdevice |
417 | 417 | ||
418 | ; mov eax, [edx + IOCTL.input] ; get the pci bus and device numbers |
418 | ; mov eax, [edx + IOCTL.input] ; get the pci bus and device numbers |
419 | mov ax, [eax+1] ; |
419 | mov ax, [eax+1] ; |
420 | .nextdevice: |
420 | .nextdevice: |
421 | mov ebx, [esi] |
421 | mov ebx, [esi] |
422 | cmp al, byte[ebx + device.pci_bus] |
422 | cmp al, byte[ebx + device.pci_bus] |
423 | jne @f |
423 | jne @f |
424 | cmp ah, byte[ebx + device.pci_dev] |
424 | cmp ah, byte[ebx + device.pci_dev] |
425 | je .find_devicenum ; Device is already loaded, let's find it's device number |
425 | je .find_devicenum ; Device is already loaded, let's find it's device number |
426 | @@: |
426 | @@: |
427 | add esi, 4 |
427 | add esi, 4 |
428 | loop .nextdevice |
428 | loop .nextdevice |
429 | 429 | ||
430 | 430 | ||
431 | ; This device doesnt have its own eth_device structure yet, lets create one |
431 | ; This device doesnt have its own eth_device structure yet, lets create one |
432 | .firstdevice: |
432 | .firstdevice: |
433 | cmp [devices], MAX_DEVICES ; First check if the driver can handle one more card |
433 | cmp [devices], MAX_DEVICES ; First check if the driver can handle one more card |
434 | jae .fail |
434 | jae .fail |
435 | 435 | ||
436 | allocate_and_clear ebx, sizeof.device, .fail ; Allocate memory to put the device structure in |
436 | allocate_and_clear ebx, sizeof.device, .fail ; Allocate memory to put the device structure in |
437 | 437 | ||
438 | ; Fill in the direct call addresses into the struct |
438 | ; Fill in the direct call addresses into the struct |
439 | 439 | ||
440 | mov [ebx + device.reset], reset |
440 | mov [ebx + device.reset], reset |
441 | mov [ebx + device.transmit], transmit |
441 | mov [ebx + device.transmit], transmit |
442 | mov [ebx + device.unload], unload |
442 | mov [ebx + device.unload], unload |
443 | mov [ebx + device.name], my_service |
443 | mov [ebx + device.name], my_service |
444 | 444 | ||
445 | ; save the pci bus and device numbers |
445 | ; save the pci bus and device numbers |
446 | 446 | ||
447 | mov eax, [edx + IOCTL.input] |
447 | mov eax, [edx + IOCTL.input] |
448 | movzx ecx, byte[eax+1] |
448 | movzx ecx, byte[eax+1] |
449 | mov [ebx + device.pci_bus], ecx |
449 | mov [ebx + device.pci_bus], ecx |
450 | movzx ecx, byte[eax+2] |
450 | movzx ecx, byte[eax+2] |
451 | mov [ebx + device.pci_dev], ecx |
451 | mov [ebx + device.pci_dev], ecx |
452 | 452 | ||
453 | ; Now, it's time to find the base io addres of the PCI device |
453 | ; Now, it's time to find the base io addres of the PCI device |
454 | 454 | ||
455 | stdcall PCI_find_io, [ebx + device.pci_bus], [ebx + device.pci_dev] |
455 | stdcall PCI_find_io, [ebx + device.pci_bus], [ebx + device.pci_dev] |
456 | mov [ebx + device.io_addr], eax |
456 | mov [ebx + device.io_addr], eax |
457 | 457 | ||
458 | ; We've found the io address, find IRQ now |
458 | ; We've found the io address, find IRQ now |
459 | 459 | ||
460 | invoke PciRead8, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.interrupt_line |
460 | invoke PciRead8, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.interrupt_line |
461 | mov [ebx + device.irq_line], al |
461 | mov [ebx + device.irq_line], al |
462 | 462 | ||
463 | DEBUGF 2,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\ |
463 | DEBUGF 2,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\ |
464 | [ebx + device.pci_dev]:1,[ebx + device.pci_bus]:1,[ebx + device.irq_line]:1,[ebx + device.io_addr]:8 |
464 | [ebx + device.pci_dev]:1,[ebx + device.pci_bus]:1,[ebx + device.irq_line]:1,[ebx + device.io_addr]:8 |
465 | 465 | ||
466 | ; Ok, the eth_device structure is ready, let's probe the device |
466 | ; Ok, the eth_device structure is ready, let's probe the device |
467 | ; Because initialization fires IRQ, IRQ handler must be aware of this device |
467 | ; Because initialization fires IRQ, IRQ handler must be aware of this device |
468 | mov eax, [devices] ; Add the device structure to our device list |
468 | mov eax, [devices] ; Add the device structure to our device list |
469 | mov [device_list + 4*eax], ebx ; (IRQ handler uses this list to find device) |
469 | mov [device_list + 4*eax], ebx ; (IRQ handler uses this list to find device) |
470 | inc [devices] ; |
470 | inc [devices] ; |
471 | 471 | ||
472 | call probe ; this function will output in eax |
472 | call probe ; this function will output in eax |
473 | test eax, eax |
473 | test eax, eax |
474 | jnz .err2 ; If an error occured, exit |
474 | jnz .err2 ; If an error occured, exit |
475 | 475 | ||
476 | mov [ebx + device.type], NET_TYPE_ETH |
476 | mov [ebx + device.type], NET_TYPE_ETH |
477 | invoke NetRegDev |
477 | invoke NetRegDev |
478 | 478 | ||
479 | cmp eax, -1 |
479 | cmp eax, -1 |
480 | je .destroy |
480 | je .destroy |
481 | 481 | ||
482 | ret |
482 | ret |
483 | 483 | ||
484 | ; If the device was already loaded, find the device number and return it in eax |
484 | ; If the device was already loaded, find the device number and return it in eax |
485 | 485 | ||
486 | .find_devicenum: |
486 | .find_devicenum: |
487 | DEBUGF 2,"Trying to find device number of already registered device\n" |
487 | DEBUGF 2,"Trying to find device number of already registered device\n" |
488 | invoke NetPtrToNum ; This kernel procedure converts a pointer to device struct in ebx |
488 | invoke NetPtrToNum ; This kernel procedure converts a pointer to device struct in ebx |
489 | ; into a device number in edi |
489 | ; into a device number in edi |
490 | mov eax, edi ; Application wants it in eax instead |
490 | mov eax, edi ; Application wants it in eax instead |
491 | DEBUGF 2,"Kernel says: %u\n", eax |
491 | DEBUGF 2,"Kernel says: %u\n", eax |
492 | ret |
492 | ret |
493 | 493 | ||
494 | ; If an error occured, remove all allocated data and exit (returning -1 in eax) |
494 | ; If an error occured, remove all allocated data and exit (returning -1 in eax) |
495 | 495 | ||
496 | .destroy: |
496 | .destroy: |
497 | ; todo: reset device into virgin state |
497 | ; todo: reset device into virgin state |
498 | 498 | ||
499 | .err2: |
499 | .err2: |
500 | dec [devices] |
500 | dec [devices] |
501 | .err: |
501 | .err: |
502 | DEBUGF 2,"removing device structure\n" |
502 | DEBUGF 2,"removing device structure\n" |
503 | invoke KernelFree, ebx |
503 | invoke KernelFree, ebx |
504 | .fail: |
504 | .fail: |
505 | or eax, -1 |
505 | or eax, -1 |
506 | ret |
506 | ret |
507 | 507 | ||
508 | ;------------------------------------------------------ |
508 | ;------------------------------------------------------ |
509 | endp |
509 | endp |
510 | 510 | ||
511 | 511 | ||
512 | align 4 |
512 | align 4 |
513 | unload: |
513 | unload: |
514 | 514 | ||
515 | ret |
515 | ret |
516 | 516 | ||
517 | 517 | ||
518 | align 4 |
518 | align 4 |
519 | init_board: |
519 | init_board: |
520 | 520 | ||
521 | DEBUGF 1,"init_board\n" |
521 | DEBUGF 1,"init_board\n" |
522 | 522 | ||
523 | ; Make the device a bus master |
523 | ; Make the device a bus master |
524 | invoke PciRead32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command |
524 | invoke PciRead32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command |
525 | or al, PCI_CMD_MASTER |
525 | or al, PCI_CMD_MASTER |
526 | invoke PciWrite32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command, eax |
526 | invoke PciWrite32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command, eax |
527 | 527 | ||
528 | ; Soft reset the chip |
528 | ; Soft reset the chip |
529 | set_io [ebx + device.io_addr], 0 |
529 | set_io [ebx + device.io_addr], 0 |
530 | set_io [ebx + device.io_addr], REG_ChipCmd |
530 | set_io [ebx + device.io_addr], REG_ChipCmd |
531 | mov al, CMD_Reset |
531 | mov al, CMD_Reset |
532 | out dx, al |
532 | out dx, al |
533 | 533 | ||
534 | ; Check that the chip has finished the reset |
534 | ; Check that the chip has finished the reset |
535 | mov ecx, 1000 |
535 | mov ecx, 1000 |
536 | set_io [ebx + device.io_addr], REG_ChipCmd |
536 | set_io [ebx + device.io_addr], REG_ChipCmd |
537 | @@: |
537 | @@: |
538 | in al, dx |
538 | in al, dx |
539 | test al, CMD_Reset |
539 | test al, CMD_Reset |
540 | jz @f |
540 | jz @f |
541 | udelay 10 |
541 | udelay 10 |
542 | loop @b |
542 | loop @b |
543 | @@: |
543 | @@: |
544 | 544 | ||
545 | 545 | ||
546 | set_io [ebx + device.io_addr], REG_TxConfig |
546 | set_io [ebx + device.io_addr], REG_TxConfig |
547 | in eax, dx |
547 | in eax, dx |
548 | mov esi, MAC_VERSION_LIST |
548 | mov esi, MAC_VERSION_LIST |
549 | @@: |
549 | @@: |
550 | mov ecx, eax |
550 | mov ecx, eax |
551 | and ecx, dword[esi] |
551 | and ecx, dword[esi] |
552 | cmp ecx, dword[esi+4] |
552 | cmp ecx, dword[esi+4] |
553 | je @f |
553 | je @f |
554 | add esi, 4*4 |
554 | add esi, 4*4 |
555 | jmp @r |
555 | jmp @r |
556 | @@: |
556 | @@: |
557 | 557 | ||
558 | mov eax, [esi+8] |
558 | mov eax, [esi+8] |
559 | mov [ebx + device.mac_version], eax |
559 | mov [ebx + device.mac_version], eax |
560 | mov eax, [esi+12] |
560 | mov eax, [esi+12] |
561 | mov [ebx + device.name], eax |
561 | mov [ebx + device.name], eax |
562 | 562 | ||
563 | xor eax, eax |
563 | xor eax, eax |
564 | ret |
564 | ret |
565 | 565 | ||
566 | 566 | ||
567 | 567 | ||
568 | ;*************************************************************************** |
568 | ;*************************************************************************** |
569 | ; Function |
569 | ; Function |
570 | ; probe |
570 | ; probe |
571 | ; Description |
571 | ; Description |
572 | ; Searches for an ethernet card, enables it and clears the rx buffer |
572 | ; Searches for an ethernet card, enables it and clears the rx buffer |
573 | ; If a card was found, it enables the ethernet -> TCPIP link |
573 | ; If a card was found, it enables the ethernet -> TCPIP link |
574 | ; Destroyed registers |
574 | ; Destroyed registers |
575 | ; eax, ebx, ecx, edx |
575 | ; eax, ebx, ecx, edx |
576 | ; |
576 | ; |
577 | ;*************************************************************************** |
577 | ;*************************************************************************** |
578 | align 4 |
578 | align 4 |
579 | probe: |
579 | probe: |
580 | 580 | ||
581 | DEBUGF 1,"probe\n" |
581 | DEBUGF 1,"probe\n" |
582 | 582 | ||
583 | call init_board |
583 | call init_board |
584 | call read_mac |
584 | call read_mac |
585 | call PHY_config |
585 | call PHY_config |
586 | 586 | ||
587 | DEBUGF 1,"Set MAC Reg C+CR Offset 0x82h = 0x01h\n" |
587 | DEBUGF 1,"Set MAC Reg C+CR Offset 0x82h = 0x01h\n" |
588 | set_io [ebx + device.io_addr], 0 |
588 | set_io [ebx + device.io_addr], 0 |
589 | set_io [ebx + device.io_addr], 0x82 |
589 | set_io [ebx + device.io_addr], 0x82 |
590 | mov al, 0x01 |
590 | mov al, 0x01 |
591 | out dx, al |
591 | out dx, al |
592 | cmp [ebx + device.mcfg], MCFG_METHOD_03 |
592 | cmp [ebx + device.mcfg], MCFG_METHOD_03 |
593 | jae @f |
593 | jae @f |
594 | DEBUGF 1,"Set PCI Latency=0x40\n" |
594 | DEBUGF 1,"Set PCI Latency=0x40\n" |
595 | ; Adjust PCI latency to be at least 64 |
595 | ; Adjust PCI latency to be at least 64 |
596 | invoke PciRead8, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.max_latency |
596 | invoke PciRead8, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.max_latency |
597 | cmp al, 64 |
597 | cmp al, 64 |
598 | jae @f |
598 | jae @f |
599 | mov al, 64 |
599 | mov al, 64 |
600 | invoke PciWrite8, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.max_latency, eax |
600 | invoke PciWrite8, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.max_latency, eax |
601 | @@: |
601 | @@: |
602 | cmp [ebx + device.mcfg], MCFG_METHOD_02 |
602 | cmp [ebx + device.mcfg], MCFG_METHOD_02 |
603 | jne @f |
603 | jne @f |
604 | DEBUGF 1,"Set MAC Reg C+CR Offset 0x82h = 0x01h\n" |
604 | DEBUGF 1,"Set MAC Reg C+CR Offset 0x82h = 0x01h\n" |
605 | set_io [ebx + device.io_addr], 0 |
605 | set_io [ebx + device.io_addr], 0 |
606 | set_io [ebx + device.io_addr], 0x82 |
606 | set_io [ebx + device.io_addr], 0x82 |
607 | mov al, 0x01 |
607 | mov al, 0x01 |
608 | out dx, al |
608 | out dx, al |
609 | DEBUGF 1,"Set PHY Reg 0x0bh = 0x00h\n" |
609 | DEBUGF 1,"Set PHY Reg 0x0bh = 0x00h\n" |
610 | WRITE_GMII_REG 0x0b, 0x0000 ; w 0x0b 15 0 0 |
610 | WRITE_GMII_REG 0x0b, 0x0000 ; w 0x0b 15 0 0 |
611 | @@: |
611 | @@: |
612 | ; if TBI is not enabled |
612 | ; if TBI is not enabled |
613 | set_io [ebx + device.io_addr], 0 |
613 | set_io [ebx + device.io_addr], 0 |
614 | set_io [ebx + device.io_addr], REG_PHYstatus |
614 | set_io [ebx + device.io_addr], REG_PHYstatus |
615 | in al, dx |
615 | in al, dx |
616 | test al, PHYS_TBI_Enable |
616 | test al, PHYS_TBI_Enable |
617 | jz .tbi_dis |
617 | jz .tbi_dis |
618 | READ_GMII_REG PHY_AUTO_NEGO_REG |
618 | READ_GMII_REG PHY_AUTO_NEGO_REG |
619 | 619 | ||
620 | ; enable 10/100 Full/Half Mode, leave PHY_AUTO_NEGO_REG bit4:0 unchanged |
620 | ; enable 10/100 Full/Half Mode, leave PHY_AUTO_NEGO_REG bit4:0 unchanged |
621 | and eax, 0x0C1F |
621 | and eax, 0x0C1F |
622 | or eax, PHY_Cap_10_Half or PHY_Cap_10_Full or PHY_Cap_100_Half or PHY_Cap_100_Full |
622 | or eax, PHY_Cap_10_Half or PHY_Cap_10_Full or PHY_Cap_100_Half or PHY_Cap_100_Full |
623 | WRITE_GMII_REG PHY_AUTO_NEGO_REG, ax |
623 | WRITE_GMII_REG PHY_AUTO_NEGO_REG, ax |
624 | 624 | ||
625 | ; enable 1000 Full Mode |
625 | ; enable 1000 Full Mode |
626 | WRITE_GMII_REG PHY_1000_CTRL_REG, PHY_Cap_1000_Full or PHY_Cap_1000_Half ; rtl8168 |
626 | WRITE_GMII_REG PHY_1000_CTRL_REG, PHY_Cap_1000_Full or PHY_Cap_1000_Half ; rtl8168 |
627 | 627 | ||
628 | ; Enable auto-negotiation and restart auto-nigotiation |
628 | ; Enable auto-negotiation and restart auto-nigotiation |
629 | WRITE_GMII_REG PHY_CTRL_REG, PHY_Enable_Auto_Nego or PHY_Restart_Auto_Nego |
629 | WRITE_GMII_REG PHY_CTRL_REG, PHY_Enable_Auto_Nego or PHY_Restart_Auto_Nego |
630 | 630 | ||
631 | udelay 1 ; 100 |
631 | udelay 1 ; 100 |
632 | mov ecx, 200 ; 10000 |
632 | mov ecx, 200 ; 10000 |
633 | DEBUGF 1, "Waiting for auto-negotiation to complete\n" |
633 | DEBUGF 1, "Waiting for auto-negotiation to complete\n" |
634 | ; wait for auto-negotiation process |
634 | ; wait for auto-negotiation process |
635 | @@: dec ecx |
635 | @@: dec ecx |
636 | jz @f |
636 | jz @f |
637 | set_io [ebx + device.io_addr], 0 |
637 | set_io [ebx + device.io_addr], 0 |
638 | READ_GMII_REG PHY_STAT_REG |
638 | READ_GMII_REG PHY_STAT_REG |
639 | udelay 1 ; 100 |
639 | udelay 1 ; 100 |
640 | test eax, PHY_Auto_Neco_Comp |
640 | test eax, PHY_Auto_Neco_Comp |
641 | jz @b |
641 | jz @b |
642 | set_io [ebx + device.io_addr], REG_PHYstatus |
642 | set_io [ebx + device.io_addr], REG_PHYstatus |
643 | in al, dx |
643 | in al, dx |
644 | jmp @f |
644 | jmp @f |
645 | .tbi_dis: |
645 | .tbi_dis: |
646 | udelay 1 ; 100 |
646 | udelay 1 ; 100 |
647 | @@: |
647 | @@: |
648 | DEBUGF 1, "auto-negotiation complete\n" |
648 | DEBUGF 1, "auto-negotiation complete\n" |
649 | 649 | ||
650 | ;*************************************************************************** |
650 | ;*************************************************************************** |
651 | ; Function |
651 | ; Function |
652 | ; rt8169_reset |
652 | ; rt8169_reset |
653 | ; Description |
653 | ; Description |
654 | ; Place the chip (ie, the ethernet card) into a virgin state |
654 | ; Place the chip (ie, the ethernet card) into a virgin state |
655 | ; Destroyed registers |
655 | ; Destroyed registers |
656 | ; eax, ebx, ecx, edx |
656 | ; eax, ebx, ecx, edx |
657 | ; |
657 | ; |
658 | ;*************************************************************************** |
658 | ;*************************************************************************** |
659 | align 4 |
659 | align 4 |
660 | reset: |
660 | reset: |
661 | 661 | ||
662 | DEBUGF 1,"resetting\n" |
662 | DEBUGF 1,"resetting\n" |
663 | 663 | ||
664 | call init_ring |
664 | call init_ring |
- | 665 | test eax, eax |
|
- | 666 | jnz .err |
|
- | 667 | ||
665 | call hw_start |
668 | call hw_start |
666 | 669 | ||
667 | ; clear packet/byte counters |
670 | ; clear packet/byte counters |
668 | 671 | ||
669 | xor eax, eax |
672 | xor eax, eax |
670 | lea edi, [ebx + device.bytes_tx] |
673 | lea edi, [ebx + device.bytes_tx] |
671 | mov ecx, 6 |
674 | mov ecx, 6 |
672 | rep stosd |
675 | rep stosd |
673 | 676 | ||
674 | mov [ebx + device.mtu], 1500 |
677 | mov [ebx + device.mtu], 1500 |
675 | call detect_link |
678 | call detect_link |
676 | 679 | ||
677 | DEBUGF 2,"init OK!\n" |
680 | DEBUGF 2,"init OK!\n" |
678 | xor eax, eax |
681 | xor eax, eax |
679 | ret |
682 | ret |
680 | 683 | ||
- | 684 | .err: |
|
- | 685 | DEBUGF 2,"failed!\n" |
|
- | 686 | or eax, -1 |
|
681 | 687 | ret |
|
682 | 688 | ||
683 | 689 | ||
684 | 690 | ||
685 | align 4 |
691 | align 4 |
686 | PHY_config: |
692 | PHY_config: |
687 | 693 | ||
688 | DEBUGF 1,"hw_PHY_config: priv.mcfg=%d, priv.pcfg=%d\n", [ebx + device.mcfg], [ebx + device.pcfg] |
694 | DEBUGF 1,"hw_PHY_config: priv.mcfg=%d, priv.pcfg=%d\n", [ebx + device.mcfg], [ebx + device.pcfg] |
689 | 695 | ||
690 | cmp [ebx + device.mcfg], MCFG_METHOD_04 |
696 | cmp [ebx + device.mcfg], MCFG_METHOD_04 |
691 | jne .not_4 |
697 | jne .not_4 |
692 | set_io [ebx + device.io_addr], 0 |
698 | set_io [ebx + device.io_addr], 0 |
693 | ; WRITE_GMII_REG 0x1F, 0x0001 |
699 | ; WRITE_GMII_REG 0x1F, 0x0001 |
694 | ; WRITE_GMII_REG 0x1b, 0x841e |
700 | ; WRITE_GMII_REG 0x1b, 0x841e |
695 | ; WRITE_GMII_REG 0x0e, 0x7bfb |
701 | ; WRITE_GMII_REG 0x0e, 0x7bfb |
696 | ; WRITE_GMII_REG 0x09, 0x273a |
702 | ; WRITE_GMII_REG 0x09, 0x273a |
697 | WRITE_GMII_REG 0x1F, 0x0002 |
703 | WRITE_GMII_REG 0x1F, 0x0002 |
698 | WRITE_GMII_REG 0x01, 0x90D0 |
704 | WRITE_GMII_REG 0x01, 0x90D0 |
699 | WRITE_GMII_REG 0x1F, 0x0000 |
705 | WRITE_GMII_REG 0x1F, 0x0000 |
700 | jmp .exit |
706 | jmp .exit |
701 | .not_4: |
707 | .not_4: |
702 | cmp [ebx + device.mcfg], MCFG_METHOD_02 |
708 | cmp [ebx + device.mcfg], MCFG_METHOD_02 |
703 | je @f |
709 | je @f |
704 | cmp [ebx + device.mcfg], MCFG_METHOD_03 |
710 | cmp [ebx + device.mcfg], MCFG_METHOD_03 |
705 | jne .not_2_or_3 |
711 | jne .not_2_or_3 |
706 | @@: |
712 | @@: |
707 | set_io [ebx + device.io_addr], 0 |
713 | set_io [ebx + device.io_addr], 0 |
708 | WRITE_GMII_REG 0x1F, 0x0001 |
714 | WRITE_GMII_REG 0x1F, 0x0001 |
709 | WRITE_GMII_REG 0x15, 0x1000 |
715 | WRITE_GMII_REG 0x15, 0x1000 |
710 | WRITE_GMII_REG 0x18, 0x65C7 |
716 | WRITE_GMII_REG 0x18, 0x65C7 |
711 | WRITE_GMII_REG 0x04, 0x0000 |
717 | WRITE_GMII_REG 0x04, 0x0000 |
712 | WRITE_GMII_REG 0x03, 0x00A1 |
718 | WRITE_GMII_REG 0x03, 0x00A1 |
713 | WRITE_GMII_REG 0x02, 0x0008 |
719 | WRITE_GMII_REG 0x02, 0x0008 |
714 | WRITE_GMII_REG 0x01, 0x1020 |
720 | WRITE_GMII_REG 0x01, 0x1020 |
715 | WRITE_GMII_REG 0x00, 0x1000 |
721 | WRITE_GMII_REG 0x00, 0x1000 |
716 | WRITE_GMII_REG 0x04, 0x0800 |
722 | WRITE_GMII_REG 0x04, 0x0800 |
717 | WRITE_GMII_REG 0x04, 0x0000 |
723 | WRITE_GMII_REG 0x04, 0x0000 |
718 | WRITE_GMII_REG 0x04, 0x7000 |
724 | WRITE_GMII_REG 0x04, 0x7000 |
719 | WRITE_GMII_REG 0x03, 0xFF41 |
725 | WRITE_GMII_REG 0x03, 0xFF41 |
720 | WRITE_GMII_REG 0x02, 0xDE60 |
726 | WRITE_GMII_REG 0x02, 0xDE60 |
721 | WRITE_GMII_REG 0x01, 0x0140 |
727 | WRITE_GMII_REG 0x01, 0x0140 |
722 | WRITE_GMII_REG 0x00, 0x0077 |
728 | WRITE_GMII_REG 0x00, 0x0077 |
723 | WRITE_GMII_REG 0x04, 0x7800 |
729 | WRITE_GMII_REG 0x04, 0x7800 |
724 | WRITE_GMII_REG 0x04, 0x7000 |
730 | WRITE_GMII_REG 0x04, 0x7000 |
725 | WRITE_GMII_REG 0x04, 0xA000 |
731 | WRITE_GMII_REG 0x04, 0xA000 |
726 | WRITE_GMII_REG 0x03, 0xDF01 |
732 | WRITE_GMII_REG 0x03, 0xDF01 |
727 | WRITE_GMII_REG 0x02, 0xDF20 |
733 | WRITE_GMII_REG 0x02, 0xDF20 |
728 | WRITE_GMII_REG 0x01, 0xFF95 |
734 | WRITE_GMII_REG 0x01, 0xFF95 |
729 | WRITE_GMII_REG 0x00, 0xFA00 |
735 | WRITE_GMII_REG 0x00, 0xFA00 |
730 | WRITE_GMII_REG 0x04, 0xA800 |
736 | WRITE_GMII_REG 0x04, 0xA800 |
731 | WRITE_GMII_REG 0x04, 0xA000 |
737 | WRITE_GMII_REG 0x04, 0xA000 |
732 | WRITE_GMII_REG 0x04, 0xB000 |
738 | WRITE_GMII_REG 0x04, 0xB000 |
733 | WRITE_GMII_REG 0x03, 0xFF41 |
739 | WRITE_GMII_REG 0x03, 0xFF41 |
734 | WRITE_GMII_REG 0x02, 0xDE20 |
740 | WRITE_GMII_REG 0x02, 0xDE20 |
735 | WRITE_GMII_REG 0x01, 0x0140 |
741 | WRITE_GMII_REG 0x01, 0x0140 |
736 | WRITE_GMII_REG 0x00, 0x00BB |
742 | WRITE_GMII_REG 0x00, 0x00BB |
737 | WRITE_GMII_REG 0x04, 0xB800 |
743 | WRITE_GMII_REG 0x04, 0xB800 |
738 | WRITE_GMII_REG 0x04, 0xB000 |
744 | WRITE_GMII_REG 0x04, 0xB000 |
739 | WRITE_GMII_REG 0x04, 0xF000 |
745 | WRITE_GMII_REG 0x04, 0xF000 |
740 | WRITE_GMII_REG 0x03, 0xDF01 |
746 | WRITE_GMII_REG 0x03, 0xDF01 |
741 | WRITE_GMII_REG 0x02, 0xDF20 |
747 | WRITE_GMII_REG 0x02, 0xDF20 |
742 | WRITE_GMII_REG 0x01, 0xFF95 |
748 | WRITE_GMII_REG 0x01, 0xFF95 |
743 | WRITE_GMII_REG 0x00, 0xBF00 |
749 | WRITE_GMII_REG 0x00, 0xBF00 |
744 | WRITE_GMII_REG 0x04, 0xF800 |
750 | WRITE_GMII_REG 0x04, 0xF800 |
745 | WRITE_GMII_REG 0x04, 0xF000 |
751 | WRITE_GMII_REG 0x04, 0xF000 |
746 | WRITE_GMII_REG 0x04, 0x0000 |
752 | WRITE_GMII_REG 0x04, 0x0000 |
747 | WRITE_GMII_REG 0x1F, 0x0000 |
753 | WRITE_GMII_REG 0x1F, 0x0000 |
748 | WRITE_GMII_REG 0x0B, 0x0000 |
754 | WRITE_GMII_REG 0x0B, 0x0000 |
749 | jmp .exit |
755 | jmp .exit |
750 | .not_2_or_3: |
756 | .not_2_or_3: |
751 | DEBUGF 1,"mcfg=%d, discard hw PHY config\n", [ebx + device.mcfg] |
757 | DEBUGF 1,"mcfg=%d, discard hw PHY config\n", [ebx + device.mcfg] |
752 | .exit: |
758 | .exit: |
753 | ret |
759 | ret |
754 | 760 | ||
755 | 761 | ||
756 | 762 | ||
757 | align 4 |
763 | align 4 |
758 | set_rx_mode: |
764 | set_rx_mode: |
759 | 765 | ||
760 | DEBUGF 1,"set_rx_mode\n" |
766 | DEBUGF 1,"set_rx_mode\n" |
761 | 767 | ||
762 | ; IFF_ALLMULTI |
768 | ; IFF_ALLMULTI |
763 | ; Too many to filter perfectly -- accept all multicasts |
769 | ; Too many to filter perfectly -- accept all multicasts |
764 | set_io [ebx + device.io_addr], 0 |
770 | set_io [ebx + device.io_addr], 0 |
765 | set_io [ebx + device.io_addr], REG_RxConfig |
771 | set_io [ebx + device.io_addr], REG_RxConfig |
766 | in eax, dx |
772 | in eax, dx |
767 | and eax, 0xff7e1880 |
773 | and eax, 0xff7e1880 |
768 | or eax, rx_config or (RXM_AcceptBroadcast or RXM_AcceptMulticast or RXM_AcceptMyPhys) |
774 | or eax, rx_config or (RXM_AcceptBroadcast or RXM_AcceptMulticast or RXM_AcceptMyPhys) |
769 | out dx, eax |
775 | out dx, eax |
770 | 776 | ||
771 | ; Multicast hash filter |
777 | ; Multicast hash filter |
772 | set_io [ebx + device.io_addr], REG_MAR0 + 0 |
778 | set_io [ebx + device.io_addr], REG_MAR0 + 0 |
773 | or eax, -1 |
779 | or eax, -1 |
774 | out dx, eax |
780 | out dx, eax |
775 | set_io [ebx + device.io_addr], REG_MAR0 + 4 |
781 | set_io [ebx + device.io_addr], REG_MAR0 + 4 |
776 | out dx, eax |
782 | out dx, eax |
777 | 783 | ||
778 | ret |
784 | ret |
779 | 785 | ||
780 | 786 | ||
781 | align 4 |
787 | align 4 |
782 | init_ring: |
788 | init_ring: |
783 | 789 | ||
784 | DEBUGF 1,"init_ring\n" |
790 | DEBUGF 1,"init_ring\n" |
785 | 791 | ||
786 | xor eax, eax |
792 | xor eax, eax |
787 | mov [ebx + device.cur_rx], eax |
793 | mov [ebx + device.cur_rx], eax |
788 | mov [ebx + device.cur_tx], eax |
794 | mov [ebx + device.cur_tx], eax |
789 | mov [ebx + device.last_tx], eax |
795 | mov [ebx + device.last_tx], eax |
790 | 796 | ||
791 | lea edi, [ebx + device.tx_ring] |
797 | lea edi, [ebx + device.tx_ring] |
792 | mov ecx, (NUM_TX_DESC * sizeof.tx_desc) / 4 * 2 |
798 | mov ecx, (NUM_TX_DESC * sizeof.tx_desc) / 4 * 2 |
793 | rep stosd |
799 | rep stosd |
794 | 800 | ||
795 | lea edi, [ebx + device.rx_ring] |
801 | lea edi, [ebx + device.rx_ring] |
796 | mov ecx, (NUM_RX_DESC * sizeof.rx_desc) / 4 |
802 | mov ecx, (NUM_RX_DESC * sizeof.rx_desc) / 4 |
797 | rep stosd |
803 | rep stosd |
798 | 804 | ||
799 | lea edi, [ebx + device.rx_ring] |
805 | lea edi, [ebx + device.rx_ring] |
800 | mov ecx, NUM_RX_DESC |
806 | mov ecx, NUM_RX_DESC |
801 | .loop: |
807 | .loop: |
802 | push ecx |
808 | push ecx |
803 | invoke KernelAlloc, RX_BUF_SIZE |
809 | invoke NetAlloc, RX_BUF_SIZE+NET_BUFF.data |
- | 810 | test eax, eax |
|
- | 811 | jz .err |
|
804 | mov dword [edi + rx_desc.buf_soft_addr], eax |
812 | mov dword [edi + rx_desc.buf_soft_addr], eax |
805 | invoke GetPhysAddr |
813 | invoke GetPhysAddr |
- | 814 | add eax, NET_BUFF.data |
|
806 | mov dword [edi + rx_desc.buf_addr], eax |
815 | mov dword [edi + rx_desc.buf_addr], eax |
807 | mov [edi + rx_desc.status], DSB_OWNbit or RX_BUF_SIZE |
816 | mov [edi + rx_desc.status], DSB_OWNbit or RX_BUF_SIZE |
808 | add edi, sizeof.rx_desc |
817 | add edi, sizeof.rx_desc |
809 | pop ecx |
818 | pop ecx |
810 | dec ecx |
819 | dec ecx |
811 | jnz .loop |
820 | jnz .loop |
812 | or [edi - sizeof.rx_desc + rx_desc.status], DSB_EORbit |
821 | or [edi - sizeof.rx_desc + rx_desc.status], DSB_EORbit |
- | 822 | ||
813 | 823 | xor eax, eax |
|
- | 824 | ret |
|
- | 825 | ||
- | 826 | .err: |
|
- | 827 | pop eax |
|
814 | ret |
828 | or eax, -1 |
815 | 829 | ret |
|
816 | 830 | ||
817 | align 4 |
831 | align 4 |
818 | hw_start: |
832 | hw_start: |
819 | 833 | ||
820 | DEBUGF 1,"hw_start\n" |
834 | DEBUGF 1,"hw_start\n" |
821 | 835 | ||
822 | ; attach int handler |
836 | ; attach int handler |
823 | movzx eax, [ebx + device.irq_line] |
837 | movzx eax, [ebx + device.irq_line] |
824 | DEBUGF 1,"Attaching int handler to irq %x\n", eax:1 |
838 | DEBUGF 1,"Attaching int handler to irq %x\n", eax:1 |
825 | invoke AttachIntHandler, eax, int_handler, ebx |
839 | invoke AttachIntHandler, eax, int_handler, ebx |
826 | test eax, eax |
840 | test eax, eax |
827 | jnz @f |
841 | jnz @f |
828 | DEBUGF 2,"Could not attach int handler!\n" |
842 | DEBUGF 2,"Could not attach int handler!\n" |
829 | or eax, -1 |
843 | or eax, -1 |
830 | ret |
844 | ret |
831 | @@: |
845 | @@: |
832 | 846 | ||
833 | ; Soft reset the chip |
847 | ; Soft reset the chip |
834 | set_io [ebx + device.io_addr], 0 |
848 | set_io [ebx + device.io_addr], 0 |
835 | set_io [ebx + device.io_addr], REG_ChipCmd |
849 | set_io [ebx + device.io_addr], REG_ChipCmd |
836 | mov al, CMD_Reset |
850 | mov al, CMD_Reset |
837 | out dx, al |
851 | out dx, al |
838 | 852 | ||
839 | DEBUGF 1,"Waiting for chip to reset... " |
853 | DEBUGF 1,"Waiting for chip to reset... " |
840 | ; Check that the chip has finished the reset |
854 | ; Check that the chip has finished the reset |
841 | mov ecx, 1000 |
855 | mov ecx, 1000 |
842 | set_io [ebx + device.io_addr], REG_ChipCmd |
856 | set_io [ebx + device.io_addr], REG_ChipCmd |
843 | @@: in al, dx |
857 | @@: in al, dx |
844 | test al, CMD_Reset |
858 | test al, CMD_Reset |
845 | jz @f |
859 | jz @f |
846 | udelay 10 |
860 | udelay 10 |
847 | loop @b |
861 | loop @b |
848 | @@: |
862 | @@: |
849 | DEBUGF 1,"done!\n" |
863 | DEBUGF 1,"done!\n" |
850 | 864 | ||
851 | set_io [ebx + device.io_addr], REG_Cfg9346 |
865 | set_io [ebx + device.io_addr], REG_Cfg9346 |
852 | mov al, CFG_9346_Unlock |
866 | mov al, CFG_9346_Unlock |
853 | out dx, al |
867 | out dx, al |
854 | 868 | ||
855 | set_io [ebx + device.io_addr], REG_ChipCmd |
869 | set_io [ebx + device.io_addr], REG_ChipCmd |
856 | mov al, CMD_TxEnb or CMD_RxEnb |
870 | mov al, CMD_TxEnb or CMD_RxEnb |
857 | out dx, al |
871 | out dx, al |
858 | 872 | ||
859 | set_io [ebx + device.io_addr], REG_ETThReg |
873 | set_io [ebx + device.io_addr], REG_ETThReg |
860 | mov al, ETTh |
874 | mov al, ETTh |
861 | out dx, al |
875 | out dx, al |
862 | 876 | ||
863 | ; For gigabit rtl8169 |
877 | ; For gigabit rtl8169 |
864 | set_io [ebx + device.io_addr], REG_RxMaxSize |
878 | set_io [ebx + device.io_addr], REG_RxMaxSize |
865 | mov ax, RxPacketMaxSize |
879 | mov ax, RxPacketMaxSize |
866 | out dx, ax |
880 | out dx, ax |
867 | 881 | ||
868 | ; Set Rx Config register |
882 | ; Set Rx Config register |
869 | set_io [ebx + device.io_addr], REG_RxConfig |
883 | set_io [ebx + device.io_addr], REG_RxConfig |
870 | in ax, dx |
884 | in ax, dx |
871 | and eax, 0xff7e1880 |
885 | and eax, 0xff7e1880 |
872 | or eax, rx_config |
886 | or eax, rx_config |
873 | out dx, eax |
887 | out dx, eax |
874 | 888 | ||
875 | ; Set DMA burst size and Interframe Gap Time |
889 | ; Set DMA burst size and Interframe Gap Time |
876 | set_io [ebx + device.io_addr], REG_TxConfig |
890 | set_io [ebx + device.io_addr], REG_TxConfig |
877 | mov eax, (TX_DMA_BURST shl TXC_DMAShift) or (InterFrameGap shl TXC_InterFrameGapShift) |
891 | mov eax, (TX_DMA_BURST shl TXC_DMAShift) or (InterFrameGap shl TXC_InterFrameGapShift) |
878 | out dx, eax |
892 | out dx, eax |
879 | 893 | ||
880 | set_io [ebx + device.io_addr], REG_CPlusCmd |
894 | set_io [ebx + device.io_addr], REG_CPlusCmd |
881 | in ax, dx |
895 | in ax, dx |
882 | out dx, ax |
896 | out dx, ax |
883 | 897 | ||
884 | in ax, dx |
898 | in ax, dx |
885 | or ax, 1 shl 3 |
899 | or ax, 1 shl 3 |
886 | cmp [ebx + device.mcfg], MCFG_METHOD_02 |
900 | cmp [ebx + device.mcfg], MCFG_METHOD_02 |
887 | jne @f |
901 | jne @f |
888 | cmp [ebx + device.mcfg], MCFG_METHOD_03 |
902 | cmp [ebx + device.mcfg], MCFG_METHOD_03 |
889 | jne @f |
903 | jne @f |
890 | or ax,1 shl 14 |
904 | or ax,1 shl 14 |
891 | DEBUGF 1,"Set MAC Reg C+CR Offset 0xE0: bit-3 and bit-14\n" |
905 | DEBUGF 1,"Set MAC Reg C+CR Offset 0xE0: bit-3 and bit-14\n" |
892 | jmp .set |
906 | jmp .set |
893 | @@: |
907 | @@: |
894 | DEBUGF 1,"Set MAC Reg C+CR Offset 0xE0: bit-3\n" |
908 | DEBUGF 1,"Set MAC Reg C+CR Offset 0xE0: bit-3\n" |
895 | .set: |
909 | .set: |
896 | set_io [ebx + device.io_addr], REG_CPlusCmd |
910 | set_io [ebx + device.io_addr], REG_CPlusCmd |
897 | out dx, ax |
911 | out dx, ax |
898 | 912 | ||
899 | set_io [ebx + device.io_addr], 0xE2 |
913 | set_io [ebx + device.io_addr], 0xE2 |
900 | ; mov ax, 0x1517 |
914 | ; mov ax, 0x1517 |
901 | ; out dx, ax |
915 | ; out dx, ax |
902 | ; mov ax, 0x152a |
916 | ; mov ax, 0x152a |
903 | ; out dx, ax |
917 | ; out dx, ax |
904 | ; mov ax, 0x282a |
918 | ; mov ax, 0x282a |
905 | ; out dx, ax |
919 | ; out dx, ax |
906 | xor ax, ax |
920 | xor ax, ax |
907 | out dx, ax |
921 | out dx, ax |
908 | 922 | ||
909 | xor eax, eax |
923 | xor eax, eax |
910 | mov [ebx + device.cur_rx], eax |
924 | mov [ebx + device.cur_rx], eax |
911 | lea eax, [ebx + device.tx_ring] |
925 | lea eax, [ebx + device.tx_ring] |
912 | invoke GetPhysAddr |
926 | invoke GetPhysAddr |
913 | set_io [ebx + device.io_addr], REG_TxDescStartAddr |
927 | set_io [ebx + device.io_addr], REG_TxDescStartAddr |
914 | out dx, eax |
928 | out dx, eax |
915 | set_io [ebx + device.io_addr], REG_TxDescStartAddr + 4 |
929 | set_io [ebx + device.io_addr], REG_TxDescStartAddr + 4 |
916 | xor eax, eax |
930 | xor eax, eax |
917 | out dx, eax |
931 | out dx, eax |
918 | 932 | ||
919 | lea eax, [ebx + device.rx_ring] |
933 | lea eax, [ebx + device.rx_ring] |
920 | invoke GetPhysAddr |
934 | invoke GetPhysAddr |
921 | set_io [ebx + device.io_addr], REG_RxDescStartAddr |
935 | set_io [ebx + device.io_addr], REG_RxDescStartAddr |
922 | out dx, eax |
936 | out dx, eax |
923 | xor eax, eax |
937 | xor eax, eax |
924 | set_io [ebx + device.io_addr], REG_RxDescStartAddr + 4 |
938 | set_io [ebx + device.io_addr], REG_RxDescStartAddr + 4 |
925 | out dx, eax |
939 | out dx, eax |
926 | 940 | ||
927 | set_io [ebx + device.io_addr], REG_Cfg9346 |
941 | set_io [ebx + device.io_addr], REG_Cfg9346 |
928 | mov al, CFG_9346_Lock |
942 | mov al, CFG_9346_Lock |
929 | out dx, al |
943 | out dx, al |
930 | 944 | ||
931 | udelay 10 |
945 | udelay 10 |
932 | 946 | ||
933 | xor eax, eax |
947 | xor eax, eax |
934 | set_io [ebx + device.io_addr], REG_RxMissed |
948 | set_io [ebx + device.io_addr], REG_RxMissed |
935 | out dx, eax |
949 | out dx, eax |
936 | 950 | ||
937 | call set_rx_mode |
951 | call set_rx_mode |
938 | 952 | ||
939 | set_io [ebx + device.io_addr], 0 |
953 | set_io [ebx + device.io_addr], 0 |
940 | ; no early-rx interrupts |
954 | ; no early-rx interrupts |
941 | set_io [ebx + device.io_addr], REG_MultiIntr |
955 | set_io [ebx + device.io_addr], REG_MultiIntr |
942 | in ax, dx |
956 | in ax, dx |
943 | and ax, 0xF000 |
957 | and ax, 0xF000 |
944 | out dx, ax |
958 | out dx, ax |
945 | 959 | ||
946 | ; set interrupt mask |
960 | ; set interrupt mask |
947 | set_io [ebx + device.io_addr], REG_IntrMask |
961 | set_io [ebx + device.io_addr], REG_IntrMask |
948 | mov ax, intr_mask |
962 | mov ax, intr_mask |
949 | out dx, ax |
963 | out dx, ax |
950 | 964 | ||
951 | xor eax, eax |
965 | xor eax, eax |
952 | ret |
966 | ret |
953 | 967 | ||
954 | 968 | ||
955 | align 4 |
969 | align 4 |
956 | read_mac: |
970 | read_mac: |
957 | 971 | ||
958 | set_io [ebx + device.io_addr], 0 |
972 | set_io [ebx + device.io_addr], 0 |
959 | set_io [ebx + device.io_addr], REG_MAC0 |
973 | set_io [ebx + device.io_addr], REG_MAC0 |
960 | xor ecx, ecx |
974 | xor ecx, ecx |
961 | lea edi, [ebx + device.mac] |
975 | lea edi, [ebx + device.mac] |
962 | mov ecx, 6 |
976 | mov ecx, 6 |
963 | 977 | ||
964 | ; Get MAC address. FIXME: read EEPROM |
978 | ; Get MAC address. FIXME: read EEPROM |
965 | @@: |
979 | @@: |
966 | in al, dx |
980 | in al, dx |
967 | stosb |
981 | stosb |
968 | inc edx |
982 | inc edx |
969 | loop @r |
983 | loop @r |
970 | 984 | ||
971 | DEBUGF 1,"MAC = %x-%x-%x-%x-%x-%x\n",\ |
985 | DEBUGF 1,"MAC = %x-%x-%x-%x-%x-%x\n",\ |
972 | [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 |
986 | [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 |
973 | 987 | ||
974 | ret |
988 | ret |
975 | 989 | ||
976 | align 4 |
990 | align 4 |
977 | write_mac: |
991 | write_mac: |
978 | 992 | ||
979 | ret 6 |
993 | ret 6 |
980 | 994 | ||
981 | 995 | ||
982 | ;*************************************************************************** |
996 | ;*************************************************************************** |
983 | ; Function |
997 | ; Function |
984 | ; transmit |
998 | ; transmit |
985 | ; Description |
999 | ; Description |
986 | ; Transmits a packet of data via the ethernet card |
1000 | ; Transmits a packet of data via the ethernet card |
987 | ; |
1001 | ; |
988 | ; Destroyed registers |
1002 | ; Destroyed registers |
989 | ; eax, edx, esi, edi |
1003 | ; eax, edx, esi, edi |
990 | ; |
1004 | ; |
991 | ;*************************************************************************** |
1005 | ;*************************************************************************** |
992 | 1006 | ||
993 | proc transmit stdcall bufferptr, buffersize |
1007 | proc transmit stdcall bufferptr |
994 | 1008 | ||
995 | pushf |
1009 | pushf |
996 | cli |
1010 | cli |
- | 1011 | ||
997 | 1012 | mov esi, [bufferptr] |
|
998 | DEBUGF 1,"Transmitting packet, buffer:%x, size:%u\n", [bufferptr], [buffersize] |
1013 | DEBUGF 1,"Transmitting packet, buffer:%x, size:%u\n", [bufferptr], [esi + NET_BUFF.length] |
999 | mov eax, [bufferptr] |
1014 | lea eax, [esi + NET_BUFF.data] |
1000 | DEBUGF 1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\ |
1015 | DEBUGF 1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\ |
1001 | [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\ |
1016 | [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\ |
1002 | [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\ |
1017 | [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\ |
1003 | [eax+13]:2,[eax+12]:2 |
1018 | [eax+13]:2,[eax+12]:2 |
1004 | 1019 | ||
1005 | cmp [buffersize], 1514 |
1020 | cmp [esi + NET_BUFF.length], 1514 |
1006 | ja .fail |
1021 | ja .fail |
1007 | cmp [buffersize], 60 |
1022 | cmp [esi + NET_BUFF.length], 60 |
1008 | jb .fail |
1023 | jb .fail |
1009 | 1024 | ||
1010 | ;---------------------------------- |
1025 | ;---------------------------------- |
1011 | ; Find currentTX descriptor address |
1026 | ; Find currentTX descriptor address |
1012 | 1027 | ||
1013 | mov eax, sizeof.tx_desc |
1028 | mov eax, sizeof.tx_desc |
1014 | mul [ebx + device.cur_tx] |
1029 | mul [ebx + device.cur_tx] |
1015 | lea esi, [ebx + device.tx_ring + eax] |
1030 | lea esi, [ebx + device.tx_ring + eax] |
1016 | 1031 | ||
1017 | DEBUGF 1,"Using TX desc: %x\n", esi |
1032 | DEBUGF 1,"Using TX desc: %x\n", esi |
1018 | 1033 | ||
1019 | ;---------------------------------- |
1034 | ;---------------------------------- |
1020 | ; Check if the descriptor is in use |
1035 | ; Check if the descriptor is in use |
1021 | 1036 | ||
1022 | test [esi + tx_desc.status], DSB_OWNbit |
1037 | test [esi + tx_desc.status], DSB_OWNbit |
1023 | jnz .desc |
1038 | jnz .desc |
1024 | 1039 | ||
1025 | ;--------------------------- |
1040 | ;--------------------------- |
1026 | ; Program the packet pointer |
1041 | ; Program the packet pointer |
1027 | 1042 | ||
1028 | mov eax, [bufferptr] |
1043 | mov eax, [bufferptr] |
- | 1044 | mov ecx, [eax + NET_BUFF.length] |
|
1029 | mov [esi + tx_desc.buf_soft_addr], eax |
1045 | mov [esi + tx_desc.buf_soft_addr], eax |
- | 1046 | add eax, [eax + NET_BUFF.offset] |
|
1030 | invoke GetPhysAddr |
1047 | invoke GetPhysAddr |
1031 | mov dword [esi + tx_desc.buf_addr], eax |
1048 | mov dword [esi + tx_desc.buf_addr], eax |
1032 | 1049 | ||
1033 | ;------------------------ |
1050 | ;------------------------ |
1034 | ; Program the packet size |
1051 | ; Program the packet size |
1035 | 1052 | ||
1036 | mov eax, [buffersize] |
- | |
1037 | @@: |
1053 | mov eax, ecx |
1038 | or eax, DSB_OWNbit or DSB_FSbit or DSB_LSbit |
1054 | or eax, DSB_OWNbit or DSB_FSbit or DSB_LSbit |
1039 | cmp [ebx + device.cur_tx], NUM_TX_DESC - 1 |
1055 | cmp [ebx + device.cur_tx], NUM_TX_DESC - 1 |
1040 | jne @f |
1056 | jne @f |
1041 | or eax, DSB_EORbit |
1057 | or eax, DSB_EORbit |
1042 | @@: |
1058 | @@: |
1043 | mov [esi + tx_desc.status], eax |
1059 | mov [esi + tx_desc.status], eax |
1044 | 1060 | ||
1045 | ;----------------------------------------- |
1061 | ;----------------------------------------- |
1046 | ; Set the polling bit (start transmission) |
1062 | ; Set the polling bit (start transmission) |
1047 | 1063 | ||
1048 | set_io [ebx + device.io_addr], 0 |
1064 | set_io [ebx + device.io_addr], 0 |
1049 | set_io [ebx + device.io_addr], REG_TxPoll |
1065 | set_io [ebx + device.io_addr], REG_TxPoll |
1050 | mov al, 0x40 ; set polling bit |
1066 | mov al, 0x40 ; set polling bit |
1051 | out dx, al |
1067 | out dx, al |
1052 | 1068 | ||
1053 | ;----------------------- |
1069 | ;----------------------- |
1054 | ; Update TX descriptor |
1070 | ; Update TX descriptor |
1055 | 1071 | ||
1056 | inc [ebx + device.cur_tx] |
1072 | inc [ebx + device.cur_tx] |
1057 | and [ebx + device.cur_tx], NUM_TX_DESC - 1 |
1073 | and [ebx + device.cur_tx], NUM_TX_DESC - 1 |
1058 | 1074 | ||
1059 | ;------------- |
1075 | ;------------- |
1060 | ; Update stats |
1076 | ; Update stats |
1061 | 1077 | ||
1062 | inc [ebx + device.packets_tx] |
1078 | inc [ebx + device.packets_tx] |
1063 | mov eax, [buffersize] |
- | |
1064 | add dword [ebx + device.bytes_tx], eax |
1079 | add dword [ebx + device.bytes_tx], ecx |
1065 | adc dword [ebx + device.bytes_tx + 4], 0 |
1080 | adc dword [ebx + device.bytes_tx + 4], 0 |
1066 | 1081 | ||
1067 | popf |
1082 | popf |
1068 | xor eax, eax |
1083 | xor eax, eax |
1069 | ret |
1084 | ret |
1070 | 1085 | ||
1071 | .desc: |
1086 | .desc: |
1072 | DEBUGF 2,"Descriptor is still in use!\n" |
1087 | DEBUGF 2,"Descriptor is still in use!\n" |
1073 | .fail: |
1088 | .fail: |
1074 | DEBUGF 2,"Transmit failed\n" |
1089 | DEBUGF 2,"Transmit failed\n" |
1075 | invoke KernelFree, [bufferptr] |
1090 | invoke NetFree, [bufferptr] |
1076 | popf |
1091 | popf |
1077 | or eax, -1 |
1092 | or eax, -1 |
1078 | ret |
1093 | ret |
1079 | 1094 | ||
1080 | endp |
1095 | endp |
1081 | 1096 | ||
1082 | 1097 | ||
1083 | 1098 | ||
1084 | ;;;;;;;;;;;;;;;;;;;;;;; |
1099 | ;;;;;;;;;;;;;;;;;;;;;;; |
1085 | ;; ;; |
1100 | ;; ;; |
1086 | ;; Interrupt handler ;; |
1101 | ;; Interrupt handler ;; |
1087 | ;; ;; |
1102 | ;; ;; |
1088 | ;;;;;;;;;;;;;;;;;;;;;;; |
1103 | ;;;;;;;;;;;;;;;;;;;;;;; |
1089 | 1104 | ||
1090 | align 4 |
1105 | align 4 |
1091 | int_handler: |
1106 | int_handler: |
1092 | 1107 | ||
1093 | push ebx esi edi |
1108 | push ebx esi edi |
1094 | 1109 | ||
1095 | DEBUGF 1,"INT\n" |
1110 | DEBUGF 1,"INT\n" |
1096 | 1111 | ||
1097 | ; find pointer of device wich made IRQ occur |
1112 | ; find pointer of device wich made IRQ occur |
1098 | 1113 | ||
1099 | mov ecx, [devices] |
1114 | mov ecx, [devices] |
1100 | test ecx, ecx |
1115 | test ecx, ecx |
1101 | jz .nothing |
1116 | jz .nothing |
1102 | mov esi, device_list |
1117 | mov esi, device_list |
1103 | .nextdevice: |
1118 | .nextdevice: |
1104 | mov ebx, [esi] |
1119 | mov ebx, [esi] |
1105 | 1120 | ||
1106 | set_io [ebx + device.io_addr], 0 |
1121 | set_io [ebx + device.io_addr], 0 |
1107 | set_io [ebx + device.io_addr], REG_IntrStatus |
1122 | set_io [ebx + device.io_addr], REG_IntrStatus |
1108 | in ax, dx |
1123 | in ax, dx |
1109 | out dx, ax ; ACK all interrupts |
1124 | out dx, ax ; ACK all interrupts |
1110 | cmp ax, 0xffff ; if so, hardware is no longer present |
1125 | cmp ax, 0xffff ; if so, hardware is no longer present |
1111 | je .nothing |
1126 | je .nothing |
1112 | test ax, ax |
1127 | test ax, ax |
1113 | jnz .got_it |
1128 | jnz .got_it |
1114 | .continue: |
1129 | .continue: |
1115 | add esi, 4 |
1130 | add esi, 4 |
1116 | dec ecx |
1131 | dec ecx |
1117 | jnz .nextdevice |
1132 | jnz .nextdevice |
1118 | .nothing: |
1133 | .nothing: |
1119 | pop edi esi ebx |
1134 | pop edi esi ebx |
1120 | xor eax, eax |
1135 | xor eax, eax |
1121 | 1136 | ||
1122 | ret ; If no device was found, abort (The irq was probably for a device, not registered to this driver) |
1137 | ret ; If no device was found, abort (The irq was probably for a device, not registered to this driver) |
1123 | 1138 | ||
1124 | .got_it: |
1139 | .got_it: |
1125 | DEBUGF 1,"Device: %x Status: %x\n", ebx, ax |
1140 | DEBUGF 1,"Device: %x Status: %x\n", ebx, ax |
1126 | 1141 | ||
1127 | ;-------- |
1142 | ;-------- |
1128 | ; Receive |
1143 | ; Receive |
1129 | test ax, ISB_RxOK |
1144 | test ax, ISB_RxOK |
1130 | jz .no_rx |
1145 | jz .no_rx |
1131 | 1146 | ||
1132 | push ax |
1147 | push ax |
1133 | push ebx |
1148 | push ebx |
1134 | 1149 | ||
1135 | .check_more: |
1150 | .check_more: |
1136 | pop ebx |
1151 | pop ebx |
1137 | mov eax, sizeof.rx_desc |
1152 | mov eax, sizeof.rx_desc |
1138 | mul [ebx + device.cur_rx] |
1153 | mul [ebx + device.cur_rx] |
1139 | lea esi, [ebx + device.rx_ring + eax] |
1154 | lea esi, [ebx + device.rx_ring + eax] |
1140 | 1155 | ||
1141 | DEBUGF 1,"RxDesc.status = 0x%x\n", [esi + rx_desc.status] |
1156 | DEBUGF 1,"RxDesc.status = 0x%x\n", [esi + rx_desc.status] |
1142 | mov eax, [esi + rx_desc.status] |
1157 | mov ecx, [esi + rx_desc.status] |
1143 | test eax, DSB_OWNbit ;;; |
1158 | test ecx, DSB_OWNbit ;;; |
1144 | jnz .no_own |
1159 | jnz .rx_return |
1145 | 1160 | ||
1146 | DEBUGF 1,"cur_rx = %u\n", [ebx + device.cur_rx] |
1161 | DEBUGF 1,"cur_rx = %u\n", [ebx + device.cur_rx] |
1147 | 1162 | ||
1148 | test eax, SD_RxRES |
1163 | test ecx, SD_RxRES |
1149 | jnz .rx_return ;;;;; RX error! |
1164 | jnz .rx_return ;;;;; RX error! |
1150 | 1165 | ||
1151 | push ebx |
1166 | push ebx |
1152 | push .check_more |
1167 | push .check_more |
1153 | and eax, 0x00001FFF |
1168 | and ecx, 0x00001FFF |
1154 | add eax, -4 ; we dont need CRC |
1169 | add ecx, -4 ; we dont need CRC |
- | 1170 | DEBUGF 1,"data length = %u\n", ecx |
|
- | 1171 | mov eax, [esi + rx_desc.buf_soft_addr] |
|
1155 | push eax |
1172 | push eax |
- | 1173 | mov [eax + NET_BUFF.length], ecx |
|
1156 | DEBUGF 1,"data length = %u\n", ax |
1174 | mov [eax + NET_BUFF.device], ebx |
- | 1175 | mov [eax + NET_BUFF.offset], NET_BUFF.data |
|
- | 1176 | ||
1157 | 1177 | ;------------- |
|
1158 | ; Update stats |
1178 | ; Update stats |
1159 | 1179 | ||
1160 | add dword [ebx + device.bytes_rx], eax |
1180 | add dword [ebx + device.bytes_rx], eax |
1161 | adc dword [ebx + device.bytes_rx + 4], 0 |
1181 | adc dword [ebx + device.bytes_rx + 4], 0 |
1162 | inc [ebx + device.packets_rx] |
1182 | inc [ebx + device.packets_rx] |
1163 | 1183 | ||
1164 | pushd [esi + rx_desc.buf_soft_addr] |
- | |
1165 | 1184 | ;---------------------- |
|
1166 | ; Allocate a new buffer |
1185 | ; Allocate a new buffer |
1167 | 1186 | ||
1168 | invoke KernelAlloc, RX_BUF_SIZE |
1187 | invoke NetAlloc, RX_BUF_SIZE+NET_BUFF.data |
- | 1188 | mov [esi + rx_desc.buf_soft_addr], eax |
|
1169 | mov [esi + rx_desc.buf_soft_addr], eax |
1189 | invoke GetPhysAddr |
- | 1190 | add eax, NET_BUFF.data |
|
1170 | invoke GetPhysAddr |
1191 | mov dword [esi + rx_desc.buf_addr], eax |
1171 | mov dword [esi + rx_desc.buf_addr], eax |
1192 | |
1172 | 1193 | ;--------------- |
|
1173 | ; reset OWN bit |
1194 | ; re set OWN bit |
1174 | 1195 | ||
1175 | mov eax, DSB_OWNbit or RX_BUF_SIZE |
1196 | mov eax, DSB_OWNbit or RX_BUF_SIZE |
1176 | cmp [ebx + device.cur_rx], NUM_RX_DESC - 1 |
1197 | cmp [ebx + device.cur_rx], NUM_RX_DESC - 1 |
1177 | jne @f |
1198 | jne @f |
1178 | or eax, DSB_EORbit |
1199 | or eax, DSB_EORbit |
1179 | @@: |
1200 | @@: |
1180 | mov [esi + rx_desc.status], eax |
1201 | mov [esi + rx_desc.status], eax |
- | 1202 | ||
1181 | 1203 | ;-------------- |
|
1182 | ; Update rx ptr |
1204 | ; Update rx ptr |
1183 | 1205 | ||
1184 | inc [ebx + device.cur_rx] |
1206 | inc [ebx + device.cur_rx] |
1185 | and [ebx + device.cur_rx], NUM_RX_DESC - 1 |
1207 | and [ebx + device.cur_rx], NUM_RX_DESC - 1 |
1186 | 1208 | ||
1187 | jmp [Eth_input] |
1209 | jmp [EthInput] |
1188 | .rx_return: |
- | |
1189 | DEBUGF 1,"RX error!\n" |
1210 | .rx_return: |
1190 | .no_own: |
1211 | |
1191 | pop ax |
1212 | pop ax |
1192 | .no_rx: |
1213 | .no_rx: |
1193 | 1214 | ||
1194 | ;----------------- |
1215 | ;----------------- |
1195 | ; Transmit cleanup |
1216 | ; Transmit cleanup |
1196 | 1217 | ||
1197 | test ax, ISB_TxOK or ISB_TxErr or ISB_TxDescUnavail |
1218 | test ax, ISB_TxOK or ISB_TxErr or ISB_TxDescUnavail |
1198 | jz .no_tx |
1219 | jz .no_tx |
- | 1220 | push ax |
|
1199 | 1221 | ||
1200 | DEBUGF 1,"TX done!\n" |
- | |
1201 | .txloop: |
- | |
1202 | mov esi, [ebx + device.last_tx] |
- | |
1203 | imul esi, sizeof.tx_desc |
- | |
- | 1222 | DEBUGF 1,"TX done!\n" |
|
- | 1223 | ||
- | 1224 | mov ecx, NUM_TX_DESC |
|
1204 | lea esi, [ebx + device.tx_ring + esi] |
1225 | lea esi, [ebx + device.tx_ring] |
1205 | 1226 | .txloop: |
|
1206 | cmp dword [esi + tx_desc.buf_soft_addr], 0 |
1227 | cmp dword [esi + tx_desc.buf_soft_addr], 0 |
1207 | je .no_tx |
1228 | jz .maybenext |
- | 1229 | ||
1208 | 1230 | test [esi + tx_desc.status], DSB_OWNbit |
|
1209 | test [esi + tx_desc.status], DSB_OWNbit |
1231 | jnz .maybenext |
1210 | jnz .no_tx |
1232 | |
1211 | - | ||
1212 | DEBUGF 1,"Freeing up TX desc: 0x%x\n", esi |
1233 | push ecx |
1213 | DEBUGF 1,"buff: 0x%x\n", [esi + tx_desc.buf_soft_addr] |
- | |
1214 | push eax |
- | |
- | 1234 | DEBUGF 1,"Freeing up TX desc: %x\n", esi |
|
1215 | push dword [esi + tx_desc.buf_soft_addr] |
1235 | invoke NetFree, [esi + tx_desc.buf_soft_addr] |
1216 | and dword [esi + tx_desc.buf_soft_addr], 0 |
1236 | pop ecx |
1217 | invoke KernelFree |
1237 | and dword [esi + tx_desc.buf_soft_addr], 0 |
- | 1238 | ||
- | 1239 | .maybenext: |
|
1218 | pop eax |
1240 | add esi, sizeof.tx_desc |
1219 | 1241 | dec ecx |
|
1220 | inc [ebx + device.last_tx] |
1242 | jnz .txloop |
1221 | and [ebx + device.last_tx], NUM_TX_DESC-1 |
1243 | |
1222 | jmp .txloop |
1244 | pop ax |
1223 | .no_tx: |
1245 | .no_tx: |
1224 | 1246 | ||
1225 | test ax, ISB_LinkChg |
1247 | test ax, ISB_LinkChg |
1226 | jz .no_linkchange |
1248 | jz .no_linkchange |
1227 | DEBUGF 2, "Link change detected\n" |
1249 | DEBUGF 2, "Link change detected\n" |
1228 | call detect_link |
1250 | call detect_link |
1229 | .no_linkchange: |
1251 | .no_linkchange: |
1230 | 1252 | ||
1231 | pop edi esi ebx |
1253 | pop edi esi ebx |
1232 | xor eax, eax |
1254 | xor eax, eax |
1233 | inc eax |
1255 | inc eax |
1234 | 1256 | ||
1235 | ret |
1257 | ret |
1236 | 1258 | ||
1237 | 1259 | ||
1238 | 1260 | ||
1239 | align 4 |
1261 | align 4 |
1240 | detect_link: |
1262 | detect_link: |
1241 | 1263 | ||
1242 | set_io [ebx + device.io_addr], 0 |
1264 | set_io [ebx + device.io_addr], 0 |
1243 | 1265 | ||
1244 | ; set_io [ebx + device.io_addr], REG_TBICSR |
1266 | ; set_io [ebx + device.io_addr], REG_TBICSR |
1245 | ; in eax, dx |
1267 | ; in eax, dx |
1246 | ; test eax, TBI_LinkOK |
1268 | ; test eax, TBI_LinkOK |
1247 | ; jz .down |
1269 | ; jz .down |
1248 | 1270 | ||
1249 | ; mov [ebx + device.state], ETH_LINK_UNKNOWN |
1271 | ; mov [ebx + device.state], ETH_LINK_UNKNOWN |
1250 | ; invoke NetLinkChanged |
1272 | ; invoke NetLinkChanged |
1251 | ; ret |
1273 | ; ret |
1252 | 1274 | ||
1253 | set_io [ebx + device.io_addr], REG_PHYstatus |
1275 | set_io [ebx + device.io_addr], REG_PHYstatus |
1254 | in al, dx |
1276 | in al, dx |
1255 | test al, PHYS_LinkStatus |
1277 | test al, PHYS_LinkStatus |
1256 | jz .down |
1278 | jz .down |
1257 | DEBUGF 2, "Link is up, phystatus=0x%x\n", al |
1279 | DEBUGF 2, "Link is up, phystatus=0x%x\n", al |
1258 | xor ecx, ecx |
1280 | xor ecx, ecx |
1259 | test al, PHYS_10bps |
1281 | test al, PHYS_10bps |
1260 | jz @f |
1282 | jz @f |
1261 | or cl, ETH_LINK_10M |
1283 | or cl, ETH_LINK_10M |
1262 | @@: |
1284 | @@: |
1263 | test al, PHYS_100bps |
1285 | test al, PHYS_100bps |
1264 | jz @f |
1286 | jz @f |
1265 | or cl, ETH_LINK_100M |
1287 | or cl, ETH_LINK_100M |
1266 | @@: |
1288 | @@: |
1267 | test al, PHYS_1000bpsF |
1289 | test al, PHYS_1000bpsF |
1268 | jz @f |
1290 | jz @f |
1269 | or cl, ETH_LINK_1G ;or ETH_LINK_FD |
1291 | or cl, ETH_LINK_1G ;or ETH_LINK_FD |
1270 | @@: |
1292 | @@: |
1271 | test al, PHYS_FullDup |
1293 | test al, PHYS_FullDup |
1272 | jz @f |
1294 | jz @f |
1273 | or cl, ETH_LINK_FD |
1295 | or cl, ETH_LINK_FD |
1274 | @@: |
1296 | @@: |
1275 | mov [ebx + device.state], ecx |
1297 | mov [ebx + device.state], ecx |
1276 | invoke NetLinkChanged |
1298 | invoke NetLinkChanged |
1277 | ret |
1299 | ret |
1278 | 1300 | ||
1279 | .down: |
1301 | .down: |
1280 | DEBUGF 2, "Link is down\n" |
1302 | DEBUGF 2, "Link is down\n" |
1281 | mov [ebx + device.state], ETH_LINK_DOWN |
1303 | mov [ebx + device.state], ETH_LINK_DOWN |
1282 | invoke NetLinkChanged |
1304 | invoke NetLinkChanged |
1283 | ret |
1305 | ret |
1284 | 1306 | ||
1285 | 1307 | ||
1286 | 1308 | ||
1287 | ; End of code |
1309 | ; End of code |
1288 | 1310 | ||
1289 | data fixups |
1311 | data fixups |
1290 | end data |
1312 | end data |
1291 | 1313 | ||
1292 | include '../peimport.inc' |
1314 | include '../peimport.inc' |
1293 | 1315 | ||
1294 | my_service db 'RTL8169',0 ; max 16 chars include zero |
1316 | my_service db 'RTL8169',0 ; max 16 chars include zero |
1295 | 1317 | ||
1296 | include_debug_strings ; All data wich FDO uses will be included here |
1318 | include_debug_strings ; All data wich FDO uses will be included here |
1297 | 1319 | ||
1298 | MAC_VERSION_LIST: |
1320 | MAC_VERSION_LIST: |
1299 | 1321 | ||
1300 | ; 8168EP family. |
1322 | ; 8168EP family. |
1301 | dd 0x7cf00000, 0x50200000, 51, name_49 |
1323 | dd 0x7cf00000, 0x50200000, 51, name_49 |
1302 | dd 0x7cf00000, 0x50100000, 50, name_49 |
1324 | dd 0x7cf00000, 0x50100000, 50, name_49 |
1303 | dd 0x7cf00000, 0x50000000, 49, name_49 |
1325 | dd 0x7cf00000, 0x50000000, 49, name_49 |
1304 | 1326 | ||
1305 | ; 8168H family. |
1327 | ; 8168H family. |
1306 | dd 0x7cf00000, 0x54100000, 46, name_45 |
1328 | dd 0x7cf00000, 0x54100000, 46, name_45 |
1307 | dd 0x7cf00000, 0x54000000, 45, name_45 |
1329 | dd 0x7cf00000, 0x54000000, 45, name_45 |
1308 | 1330 | ||
1309 | ; 8168G family. |
1331 | ; 8168G family. |
1310 | dd 0x7cf00000, 0x5c800000, 44, name_44 |
1332 | dd 0x7cf00000, 0x5c800000, 44, name_44 |
1311 | dd 0x7cf00000, 0x50900000, 42, name_40 |
1333 | dd 0x7cf00000, 0x50900000, 42, name_40 |
1312 | dd 0x7cf00000, 0x4c100000, 41, name_40 |
1334 | dd 0x7cf00000, 0x4c100000, 41, name_40 |
1313 | dd 0x7cf00000, 0x4c000000, 40, name_40 |
1335 | dd 0x7cf00000, 0x4c000000, 40, name_40 |
1314 | 1336 | ||
1315 | ; 8168F family. |
1337 | ; 8168F family. |
1316 | dd 0x7c800000, 0x48800000, 38, name_38 |
1338 | dd 0x7c800000, 0x48800000, 38, name_38 |
1317 | dd 0x7cf00000, 0x48100000, 36, name_35 |
1339 | dd 0x7cf00000, 0x48100000, 36, name_35 |
1318 | dd 0x7cf00000, 0x48000000, 35, name_35 |
1340 | dd 0x7cf00000, 0x48000000, 35, name_35 |
1319 | 1341 | ||
1320 | ; 8168E family. |
1342 | ; 8168E family. |
1321 | dd 0x7c800000, 0x2c800000, 34, name_34 |
1343 | dd 0x7c800000, 0x2c800000, 34, name_34 |
1322 | dd 0x7cf00000, 0x2c200000, 33, name_32 |
1344 | dd 0x7cf00000, 0x2c200000, 33, name_32 |
1323 | dd 0x7cf00000, 0x2c100000, 32, name_32 |
1345 | dd 0x7cf00000, 0x2c100000, 32, name_32 |
1324 | dd 0x7c800000, 0x2c000000, 33, name_32 |
1346 | dd 0x7c800000, 0x2c000000, 33, name_32 |
1325 | 1347 | ||
1326 | ; 8168D family. |
1348 | ; 8168D family. |
1327 | dd 0x7cf00000, 0x28300000, 26, name_25 |
1349 | dd 0x7cf00000, 0x28300000, 26, name_25 |
1328 | dd 0x7cf00000, 0x28100000, 25, name_25 |
1350 | dd 0x7cf00000, 0x28100000, 25, name_25 |
1329 | dd 0x7c800000, 0x28000000, 26, name_25 |
1351 | dd 0x7c800000, 0x28000000, 26, name_25 |
1330 | 1352 | ||
1331 | ; 8168DP family. |
1353 | ; 8168DP family. |
1332 | dd 0x7cf00000, 0x28800000, 27, name_27 |
1354 | dd 0x7cf00000, 0x28800000, 27, name_27 |
1333 | dd 0x7cf00000, 0x28a00000, 28, name_27 |
1355 | dd 0x7cf00000, 0x28a00000, 28, name_27 |
1334 | 1356 | ||
1335 | ; 8168C family. |
1357 | ; 8168C family. |
1336 | dd 0x7cf00000, 0x3cb00000, 24, name_23 |
1358 | dd 0x7cf00000, 0x3cb00000, 24, name_18 |
1337 | dd 0x7cf00000, 0x3c900000, 23, name_23 |
1359 | dd 0x7cf00000, 0x3c900000, 23, name_18 |
1338 | dd 0x7cf00000, 0x3c800000, 18, name_18 |
1360 | dd 0x7cf00000, 0x3c800000, 18, name_18 |
1339 | dd 0x7c800000, 0x3c800000, 24, name_23 |
1361 | dd 0x7c800000, 0x3c800000, 24, name_18 |
1340 | dd 0x7cf00000, 0x3c000000, 19, name_19 |
1362 | dd 0x7cf00000, 0x3c000000, 19, name_19 |
1341 | dd 0x7cf00000, 0x3c200000, 20, name_19 |
1363 | dd 0x7cf00000, 0x3c200000, 20, name_19 |
1342 | dd 0x7cf00000, 0x3c300000, 21, name_19 |
1364 | dd 0x7cf00000, 0x3c300000, 21, name_19 |
1343 | dd 0x7cf00000, 0x3c400000, 22, name_19 |
1365 | dd 0x7cf00000, 0x3c400000, 22, name_19 |
1344 | dd 0x7c800000, 0x3c000000, 22, name_19 |
1366 | dd 0x7c800000, 0x3c000000, 22, name_19 |
1345 | 1367 | ||
1346 | ; 8168B family. |
1368 | ; 8168B family. |
1347 | dd 0x7cf00000, 0x38000000, 12, name_11 |
1369 | dd 0x7cf00000, 0x38000000, 12, name_11 |
1348 | dd 0x7cf00000, 0x38500000, 17, name_10 |
1370 | dd 0x7cf00000, 0x38500000, 17, name_10 |
1349 | dd 0x7c800000, 0x38000000, 17, name_10 |
1371 | dd 0x7c800000, 0x38000000, 17, name_10 |
1350 | dd 0x7c800000, 0x30000000, 11, name_11 |
1372 | dd 0x7c800000, 0x30000000, 11, name_11 |
1351 | 1373 | ||
1352 | ; 8101 family. |
1374 | ; 8101 family. |
1353 | dd 0x7cf00000, 0x34a00000, 09, name_07 |
1375 | dd 0x7cf00000, 0x34a00000, 09, name_07 |
1354 | dd 0x7cf00000, 0x24a00000, 09, name_07 |
1376 | dd 0x7cf00000, 0x24a00000, 09, name_07 |
1355 | dd 0x7cf00000, 0x34900000, 08, name_07 |
1377 | dd 0x7cf00000, 0x34900000, 08, name_07 |
1356 | dd 0x7cf00000, 0x24900000, 08, name_07 |
1378 | dd 0x7cf00000, 0x24900000, 08, name_07 |
1357 | dd 0x7cf00000, 0x34800000, 07, name_07 |
1379 | dd 0x7cf00000, 0x34800000, 07, name_07 |
1358 | dd 0x7cf00000, 0x24800000, 07, name_07 |
1380 | dd 0x7cf00000, 0x24800000, 07, name_07 |
1359 | dd 0x7cf00000, 0x34000000, 13, name_10 |
1381 | dd 0x7cf00000, 0x34000000, 13, name_10 |
1360 | dd 0x7cf00000, 0x34300000, 10, name_10 |
1382 | dd 0x7cf00000, 0x34300000, 10, name_10 |
1361 | dd 0x7cf00000, 0x34200000, 16, name_11 |
1383 | dd 0x7cf00000, 0x34200000, 16, name_11 |
1362 | dd 0x7c800000, 0x34800000, 09, name_07 |
1384 | dd 0x7c800000, 0x34800000, 09, name_07 |
1363 | dd 0x7c800000, 0x24800000, 09, name_07 |
1385 | dd 0x7c800000, 0x24800000, 09, name_07 |
1364 | dd 0x7c800000, 0x34000000, 16, name_11 |
1386 | dd 0x7c800000, 0x34000000, 16, name_11 |
1365 | dd 0xfc800000, 0x38800000, 15, name_14 |
1387 | dd 0xfc800000, 0x38800000, 15, name_14 |
1366 | dd 0xfc800000, 0x30800000, 14, name_14 |
1388 | dd 0xfc800000, 0x30800000, 14, name_14 |
1367 | 1389 | ||
1368 | ; 8110 family. |
1390 | ; 8110 family. |
1369 | dd 0xfc800000, 0x98000000, 06, name_05 |
1391 | dd 0xfc800000, 0x98000000, 06, name_05 |
1370 | dd 0xfc800000, 0x18000000, 05, name_05 |
1392 | dd 0xfc800000, 0x18000000, 05, name_05 |
1371 | dd 0xfc800000, 0x10000000, 04, name_04 |
1393 | dd 0xfc800000, 0x10000000, 04, name_04 |
1372 | dd 0xfc800000, 0x04000000, 03, name_03 |
1394 | dd 0xfc800000, 0x04000000, 03, name_03 |
1373 | dd 0xfc800000, 0x00800000, 02, name_02 |
1395 | dd 0xfc800000, 0x00800000, 02, name_02 |
1374 | dd 0xfc800000, 0x00000000, 01, name_01 |
1396 | dd 0xfc800000, 0x00000000, 01, name_01 |
1375 | 1397 | ||
1376 | ; Catch-all |
1398 | ; Catch-all |
1377 | dd 0x00000000, 0x00000000, 0, name_unknown |
1399 | dd 0x00000000, 0x00000000, 0, name_unknown |
1378 | 1400 | ||
1379 | ; PCI-devices |
1401 | ; PCI-devices |
1380 | name_01 db "RTL8169",0 |
1402 | name_01 db "RTL8169",0 |
1381 | name_02 db "RTL8169s",0 |
1403 | name_02 db "RTL8169s",0 |
1382 | name_03 db "RTL8110s",0 |
1404 | name_03 db "RTL8110s",0 |
1383 | name_04 db "RTL8169sb/8110sb",0 |
1405 | name_04 db "RTL8169sb/8110sb",0 |
1384 | name_05 db "RTL8169sc/8110sc",0 |
1406 | name_05 db "RTL8169sc/8110sc",0 |
1385 | ;name_06 db "RTL8169sc/8110sc",0 |
1407 | ;name_06 db "RTL8169sc/8110sc",0 |
1386 | 1408 | ||
1387 | ; PCI-E devices |
1409 | ; PCI-E devices |
1388 | name_07 db "RTL8102e",0 |
1410 | name_07 db "RTL8102e",0 |
1389 | ;name_08 db "RTL8102e",0 |
1411 | ;name_08 db "RTL8102e",0 |
1390 | ;name_09 db "RTL8102e",0 |
1412 | ;name_09 db "RTL8102e",0 |
1391 | name_10 db "RTL8101e",0 |
1413 | name_10 db "RTL8101e",0 |
1392 | name_11 db "RTL8168b/8111b",0 |
1414 | name_11 db "RTL8168b/8111b",0 |
1393 | ;name_12 db "RTL8168b/8111b",0 |
1415 | ;name_12 db "RTL8168b/8111b",0 |
1394 | ;name_13 db "RTL8101e",0 |
1416 | ;name_13 db "RTL8101e",0 |
1395 | name_14 db "RTL8100e",0 |
1417 | name_14 db "RTL8100e",0 |
1396 | ;name_15 db "RTL8100e",0 |
1418 | ;name_15 db "RTL8100e",0 |
1397 | ;name_16 db "RTL8168b/8111b",0 |
1419 | ;name_16 db "RTL8168b/8111b",0 |
1398 | ;name_17 db "RTL8101e",0 |
1420 | ;name_17 db "RTL8101e",0 |
1399 | name_18 db "RTL8168cp/8111cp",0 |
1421 | name_18 db "RTL8168cp/8111cp",0 |
1400 | name_19 db "RTL8168c/8111c",0 |
1422 | name_19 db "RTL8168c/8111c",0 |
1401 | ;name_20 db "RTL8168c/8111c",0 |
1423 | ;name_20 db "RTL8168c/8111c",0 |
1402 | ;name_21 db "RTL8168c/8111c",0 |
1424 | ;name_21 db "RTL8168c/8111c",0 |
1403 | ;name_22 db "RTL8168c/8111c",0 |
1425 | ;name_22 db "RTL8168c/8111c",0 |
1404 | name_23 db "RTL8168cp/8111cp",0 |
1426 | ;name_23 db "RTL8168cp/8111cp",0 |
1405 | ;name_24 db "RTL8168cp/8111cp",0 |
1427 | ;name_24 db "RTL8168cp/8111cp",0 |
1406 | name_25 db "RTL8168d/8111d",0 |
1428 | name_25 db "RTL8168d/8111d",0 |
1407 | ;name_26 db "RTL8168d/8111d",0 |
1429 | ;name_26 db "RTL8168d/8111d",0 |
1408 | name_27 db "RTL8168dp/8111dp",0 |
1430 | name_27 db "RTL8168dp/8111dp",0 |
1409 | ;name_28 db "RTL8168dp/8111dp",0 |
1431 | ;name_28 db "RTL8168dp/8111dp",0 |
1410 | name_29 db "RTL8105e",0 |
1432 | name_29 db "RTL8105e",0 |
1411 | ;name_30 db "RTL8105e",0 |
1433 | ;name_30 db "RTL8105e",0 |
1412 | ;name_31 db "RTL8168dp/8111dp",0 |
1434 | ;name_31 db "RTL8168dp/8111dp",0 |
1413 | name_32 db "RTL8168e/8111e",0 |
1435 | name_32 db "RTL8168e/8111e",0 |
1414 | ;name_33 db "RTL8168e/8111e",0 |
1436 | ;name_33 db "RTL8168e/8111e",0 |
1415 | name_34 db "RTL8168evl/8111evl",0 |
1437 | name_34 db "RTL8168evl/8111evl",0 |
1416 | name_35 db "RTL8168f/8111f",0 |
1438 | name_35 db "RTL8168f/8111f",0 |
1417 | ;name_36 db "RTL8168f/8111f",0 |
1439 | ;name_36 db "RTL8168f/8111f",0 |
1418 | name_37 db "RTL8402",0 |
1440 | name_37 db "RTL8402",0 |
1419 | name_38 db "RTL8411",0 |
1441 | name_38 db "RTL8411",0 |
1420 | name_39 db "RTL8106e",0 |
1442 | name_39 db "RTL8106e",0 |
1421 | name_40 db "RTL8168g/8111g",0 |
1443 | name_40 db "RTL8168g/8111g",0 |
1422 | ;name_41 db "RTL8168g/8111g",0 |
1444 | ;name_41 db "RTL8168g/8111g",0 |
1423 | ;name_42 db "RTL8168g/8111g",0 |
1445 | ;name_42 db "RTL8168g/8111g",0 |
1424 | ;name_43 db "RTL8106e",0 |
1446 | ;name_43 db "RTL8106e",0 |
1425 | name_44 db "RTL8411",0 |
1447 | name_44 db "RTL8411",0 |
1426 | name_45 db "RTL8168h/8111h",0 |
1448 | name_45 db "RTL8168h/8111h",0 |
1427 | ;name_46 db "RTL8168h/8111h",0 |
1449 | ;name_46 db "RTL8168h/8111h",0 |
1428 | name_47 db "RTL8107e",0 |
1450 | name_47 db "RTL8107e",0 |
1429 | ;name_48 db "RTL8107e",0 |
1451 | ;name_48 db "RTL8107e",0 |
1430 | name_49 db "RTL8168ep/8111ep",0 |
1452 | name_49 db "RTL8168ep/8111ep",0 |
1431 | ;name_50 db "RTL8168ep/8111ep",0 |
1453 | ;name_50 db "RTL8168ep/8111ep",0 |
1432 | ;name_51 db "RTL8168ep/8111ep",0 |
1454 | ;name_51 db "RTL8168ep/8111ep",0 |
1433 | 1455 | ||
1434 | name_unknown db "unknown RTL8169 clone",0 |
1456 | name_unknown db "unknown RTL8169 clone",0 |
1435 | 1457 | ||
1436 | align 4 |
1458 | align 4 |
1437 | devices dd 0 |
1459 | devices dd 0 |
1438 | device_list rd MAX_DEVICES ; This list contains all pointers to device structures the driver is handling |
1460 | device_list rd MAX_DEVICES ; This list contains all pointers to device structures the driver is handling |