Rev 5363 | 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 | ;; MTD80x driver for KolibriOS ;; |
6 | ;; MTD80x driver for KolibriOS ;; |
7 | ;; ;; |
7 | ;; ;; |
8 | ;; Based on mtd80x.c from the etherboot project ;; |
8 | ;; Based on mtd80x.c from the etherboot project ;; |
9 | ;; ;; |
9 | ;; ;; |
10 | ;; Written by hidnplayr@kolibrios.org ;; |
10 | ;; Written by hidnplayr@kolibrios.org ;; |
11 | ;; ;; |
11 | ;; ;; |
12 | ;; GNU GENERAL PUBLIC LICENSE ;; |
12 | ;; GNU GENERAL PUBLIC LICENSE ;; |
13 | ;; Version 2, June 1991 ;; |
13 | ;; Version 2, June 1991 ;; |
14 | ;; ;; |
14 | ;; ;; |
15 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
15 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
16 | 16 | ||
17 | format PE DLL native |
17 | format PE DLL native |
18 | entry START |
18 | entry START |
19 | 19 | ||
20 | CURRENT_API = 0x0200 |
20 | CURRENT_API = 0x0200 |
21 | COMPATIBLE_API = 0x0100 |
21 | COMPATIBLE_API = 0x0100 |
22 | API_VERSION = (COMPATIBLE_API shl 16) + CURRENT_API |
22 | API_VERSION = (COMPATIBLE_API shl 16) + CURRENT_API |
23 | 23 | ||
24 | MAX_DEVICES = 16 |
24 | MAX_DEVICES = 16 |
25 | 25 | ||
26 | __DEBUG__ = 1 |
26 | __DEBUG__ = 1 |
27 | __DEBUG_LEVEL__ = 2 |
27 | __DEBUG_LEVEL__ = 2 |
28 | 28 | ||
29 | NUM_TX_DESC = 6 |
29 | NUM_TX_DESC = 6 |
30 | NUM_RX_DESC = 12 |
30 | NUM_RX_DESC = 12 |
31 | 31 | ||
32 | section '.flat' readable writable executable |
32 | section '.flat' readable writable executable |
33 | 33 | ||
34 | include '../proc32.inc' |
34 | include '../proc32.inc' |
35 | include '../struct.inc' |
35 | include '../struct.inc' |
36 | include '../macros.inc' |
36 | include '../macros.inc' |
37 | include '../fdo.inc' |
37 | include '../fdo.inc' |
38 | include '../netdrv.inc' |
38 | include '../netdrv.inc' |
39 | 39 | ||
40 | ; for different PHY |
40 | ; for different PHY |
41 | 41 | ||
42 | MysonPHY = 1 |
42 | MysonPHY = 1 |
43 | AhdocPHY = 2 |
43 | AhdocPHY = 2 |
44 | SeeqPHY = 3 |
44 | SeeqPHY = 3 |
45 | MarvellPHY = 4 |
45 | MarvellPHY = 4 |
46 | Myson981 = 5 |
46 | Myson981 = 5 |
47 | LevelOnePHY = 6 |
47 | LevelOnePHY = 6 |
48 | OtherPHY = 10 |
48 | OtherPHY = 10 |
49 | 49 | ||
50 | ; Offsets to the Command and Status Registers. |
50 | ; Offsets to the Command and Status Registers. |
51 | 51 | ||
52 | PAR0 = 0x0 ; physical address 0-3 |
52 | PAR0 = 0x0 ; physical address 0-3 |
53 | PAR1 = 0x04 ; physical address 4-5 |
53 | PAR1 = 0x04 ; physical address 4-5 |
54 | MAR0 = 0x08 ; multicast address 0-3 |
54 | MAR0 = 0x08 ; multicast address 0-3 |
55 | MAR1 = 0x0C ; multicast address 4-7 |
55 | MAR1 = 0x0C ; multicast address 4-7 |
56 | FAR0 = 0x10 ; flow-control address 0-3 |
56 | FAR0 = 0x10 ; flow-control address 0-3 |
57 | FAR1 = 0x14 ; flow-control address 4-5 |
57 | FAR1 = 0x14 ; flow-control address 4-5 |
58 | TCRRCR = 0x18 ; receive & transmit configuration |
58 | TCRRCR = 0x18 ; receive & transmit configuration |
59 | BCR = 0x1C ; bus command |
59 | BCR = 0x1C ; bus command |
60 | TXPDR = 0x20 ; transmit polling demand |
60 | TXPDR = 0x20 ; transmit polling demand |
61 | RXPDR = 0x24 ; receive polling demand |
61 | RXPDR = 0x24 ; receive polling demand |
62 | RXCWP = 0x28 ; receive current word pointer |
62 | RXCWP = 0x28 ; receive current word pointer |
63 | TXLBA = 0x2C ; transmit list base address |
63 | TXLBA = 0x2C ; transmit list base address |
64 | RXLBA = 0x30 ; receive list base address |
64 | RXLBA = 0x30 ; receive list base address |
65 | ISR = 0x34 ; interrupt status |
65 | ISR = 0x34 ; interrupt status |
66 | IMR = 0x38 ; interrupt mask |
66 | IMR = 0x38 ; interrupt mask |
67 | FTH = 0x3C ; flow control high/low threshold |
67 | FTH = 0x3C ; flow control high/low threshold |
68 | MANAGEMENT = 0x40 ; bootrom/eeprom and mii management |
68 | MANAGEMENT = 0x40 ; bootrom/eeprom and mii management |
69 | TALLY = 0x44 ; tally counters for crc and mpa |
69 | TALLY = 0x44 ; tally counters for crc and mpa |
70 | TSR = 0x48 ; tally counter for transmit status |
70 | TSR = 0x48 ; tally counter for transmit status |
71 | BMCRSR = 0x4c ; basic mode control and status |
71 | BMCRSR = 0x4c ; basic mode control and status |
72 | PHYIDENTIFIER = 0x50 ; phy identifier |
72 | PHYIDENTIFIER = 0x50 ; phy identifier |
73 | ANARANLPAR = 0x54 ; auto-negotiation advertisement and link partner ability |
73 | ANARANLPAR = 0x54 ; auto-negotiation advertisement and link partner ability |
74 | ANEROCR = 0x58 ; auto-negotiation expansion and pci conf. |
74 | ANEROCR = 0x58 ; auto-negotiation expansion and pci conf. |
75 | BPREMRPSR = 0x5c ; bypass & receive error mask and phy status |
75 | BPREMRPSR = 0x5c ; bypass & receive error mask and phy status |
76 | 76 | ||
77 | ; Bits in the interrupt status/enable registers. |
77 | ; Bits in the interrupt status/enable registers. |
78 | 78 | ||
79 | RFCON = 0x00020000 ; receive flow control xon packet |
79 | RFCON = 0x00020000 ; receive flow control xon packet |
80 | RFCOFF = 0x00010000 ; receive flow control xoff packet |
80 | RFCOFF = 0x00010000 ; receive flow control xoff packet |
81 | LSCStatus = 0x00008000 ; link status change |
81 | LSCStatus = 0x00008000 ; link status change |
82 | ANCStatus = 0x00004000 ; autonegotiation completed |
82 | ANCStatus = 0x00004000 ; autonegotiation completed |
83 | FBE = 0x00002000 ; fatal bus error |
83 | FBE = 0x00002000 ; fatal bus error |
84 | FBEMask = 0x00001800 ; mask bit12-11 |
84 | FBEMask = 0x00001800 ; mask bit12-11 |
85 | ParityErr = 0x00000000 ; parity error |
85 | ParityErr = 0x00000000 ; parity error |
86 | TargetErr = 0x00001000 ; target abort |
86 | TargetErr = 0x00001000 ; target abort |
87 | MasterErr = 0x00000800 ; master error |
87 | MasterErr = 0x00000800 ; master error |
88 | TUNF = 0x00000400 ; transmit underflow |
88 | TUNF = 0x00000400 ; transmit underflow |
89 | ROVF = 0x00000200 ; receive overflow |
89 | ROVF = 0x00000200 ; receive overflow |
90 | ETI = 0x00000100 ; transmit early int |
90 | ETI = 0x00000100 ; transmit early int |
91 | ERI = 0x00000080 ; receive early int |
91 | ERI = 0x00000080 ; receive early int |
92 | CNTOVF = 0x00000040 ; counter overflow |
92 | CNTOVF = 0x00000040 ; counter overflow |
93 | RBU = 0x00000020 ; receive buffer unavailable |
93 | RBU = 0x00000020 ; receive buffer unavailable |
94 | TBU = 0x00000010 ; transmit buffer unavilable |
94 | TBU = 0x00000010 ; transmit buffer unavilable |
95 | TI = 0x00000008 ; transmit interrupt |
95 | TI = 0x00000008 ; transmit interrupt |
96 | RI = 0x00000004 ; receive interrupt |
96 | RI = 0x00000004 ; receive interrupt |
97 | RxErr = 0x00000002 ; receive error |
97 | RxErr = 0x00000002 ; receive error |
98 | 98 | ||
99 | ; Bits in the NetworkConfig register. |
99 | ; Bits in the NetworkConfig register. |
100 | 100 | ||
101 | RxModeMask = 0xe0 |
101 | RxModeMask = 0xe0 |
102 | AcceptAllPhys = 0x80 ; promiscuous mode |
102 | AcceptAllPhys = 0x80 ; promiscuous mode |
103 | AcceptBroadcast = 0x40 ; accept broadcast |
103 | AcceptBroadcast = 0x40 ; accept broadcast |
104 | AcceptMulticast = 0x20 ; accept mutlicast |
104 | AcceptMulticast = 0x20 ; accept mutlicast |
105 | AcceptRunt = 0x08 ; receive runt pkt |
105 | AcceptRunt = 0x08 ; receive runt pkt |
106 | ALP = 0x04 ; receive long pkt |
106 | ALP = 0x04 ; receive long pkt |
107 | AcceptErr = 0x02 ; receive error pkt |
107 | AcceptErr = 0x02 ; receive error pkt |
108 | 108 | ||
109 | AcceptMyPhys = 0x00000000 |
109 | AcceptMyPhys = 0x00000000 |
110 | RxEnable = 0x00000001 |
110 | RxEnable = 0x00000001 |
111 | RxFlowCtrl = 0x00002000 |
111 | RxFlowCtrl = 0x00002000 |
112 | TxEnable = 0x00040000 |
112 | TxEnable = 0x00040000 |
113 | TxModeFDX = 0x00100000 |
113 | TxModeFDX = 0x00100000 |
114 | TxThreshold = 0x00e00000 |
114 | TxThreshold = 0x00e00000 |
115 | 115 | ||
116 | PS1000 = 0x00010000 |
116 | PS1000 = 0x00010000 |
117 | PS10 = 0x00080000 |
117 | PS10 = 0x00080000 |
118 | FD = 0x00100000 |
118 | FD = 0x00100000 |
119 | 119 | ||
120 | 120 | ||
121 | ; Bits in network_desc.status |
121 | ; Bits in network_desc.status |
122 | 122 | ||
123 | RXOWN = 0x80000000 ; own bit |
123 | RXOWN = 0x80000000 ; own bit |
124 | FLNGMASK = 0x0fff0000 ; frame length |
124 | FLNGMASK = 0x0fff0000 ; frame length |
125 | FLNGShift = 16 |
125 | FLNGShift = 16 |
126 | MARSTATUS = 0x00004000 ; multicast address received |
126 | MARSTATUS = 0x00004000 ; multicast address received |
127 | BARSTATUS = 0x00002000 ; broadcast address received |
127 | BARSTATUS = 0x00002000 ; broadcast address received |
128 | PHYSTATUS = 0x00001000 ; physical address received |
128 | PHYSTATUS = 0x00001000 ; physical address received |
129 | RXFSD = 0x00000800 ; first descriptor |
129 | RXFSD = 0x00000800 ; first descriptor |
130 | RXLSD = 0x00000400 ; last descriptor |
130 | RXLSD = 0x00000400 ; last descriptor |
131 | ErrorSummary = 0x80 ; error summary |
131 | ErrorSummary = 0x80 ; error summary |
132 | RUNT = 0x40 ; runt packet received |
132 | RUNT = 0x40 ; runt packet received |
133 | LONG = 0x20 ; long packet received |
133 | LONG = 0x20 ; long packet received |
134 | FAE = 0x10 ; frame align error |
134 | FAE = 0x10 ; frame align error |
135 | CRC = 0x08 ; crc error |
135 | CRC = 0x08 ; crc error |
136 | RXER = 0x04 ; receive error |
136 | RXER = 0x04 ; receive error |
137 | 137 | ||
138 | ; rx_desc_control_bits |
138 | ; rx_desc_control_bits |
139 | 139 | ||
140 | RXIC = 0x00800000 ; interrupt control |
140 | RXIC = 0x00800000 ; interrupt control |
141 | RBSShift = 0 |
141 | RBSShift = 0 |
142 | 142 | ||
143 | ; tx_desc_status_bits |
143 | ; tx_desc_status_bits |
144 | 144 | ||
145 | TXOWN = 0x80000000 ; own bit |
145 | TXOWN = 0x80000000 ; own bit |
146 | JABTO = 0x00004000 ; jabber timeout |
146 | JABTO = 0x00004000 ; jabber timeout |
147 | CSL = 0x00002000 ; carrier sense lost |
147 | CSL = 0x00002000 ; carrier sense lost |
148 | LC = 0x00001000 ; late collision |
148 | LC = 0x00001000 ; late collision |
149 | EC = 0x00000800 ; excessive collision |
149 | EC = 0x00000800 ; excessive collision |
150 | UDF = 0x00000400 ; fifo underflow |
150 | UDF = 0x00000400 ; fifo underflow |
151 | DFR = 0x00000200 ; deferred |
151 | DFR = 0x00000200 ; deferred |
152 | HF = 0x00000100 ; heartbeat fail |
152 | HF = 0x00000100 ; heartbeat fail |
153 | NCRMask = 0x000000ff ; collision retry count |
153 | NCRMask = 0x000000ff ; collision retry count |
154 | NCRShift = 0 |
154 | NCRShift = 0 |
155 | 155 | ||
156 | ; tx_desc_control_bits |
156 | ; tx_desc_control_bits |
157 | 157 | ||
158 | TXIC = 0x80000000 ; interrupt control |
158 | TXIC = 0x80000000 ; interrupt control |
159 | ETIControl = 0x40000000 ; early transmit interrupt |
159 | ETIControl = 0x40000000 ; early transmit interrupt |
160 | TXLD = 0x20000000 ; last descriptor |
160 | TXLD = 0x20000000 ; last descriptor |
161 | TXFD = 0x10000000 ; first descriptor |
161 | TXFD = 0x10000000 ; first descriptor |
162 | CRCEnable = 0x08000000 ; crc control |
162 | CRCEnable = 0x08000000 ; crc control |
163 | PADEnable = 0x04000000 ; padding control |
163 | PADEnable = 0x04000000 ; padding control |
164 | RetryTxLC = 0x02000000 ; retry late collision |
164 | RetryTxLC = 0x02000000 ; retry late collision |
165 | PKTSMask = 0x3ff800 ; packet size bit21-11 |
165 | PKTSMask = 0x3ff800 ; packet size bit21-11 |
166 | PKTSShift = 11 |
166 | PKTSShift = 11 |
167 | TBSMask = 0x000007ff ; transmit buffer bit 10-0 |
167 | TBSMask = 0x000007ff ; transmit buffer bit 10-0 |
168 | TBSShift = 0 |
168 | TBSShift = 0 |
169 | 169 | ||
170 | ; BootROM/EEPROM/MII Management Register |
170 | ; BootROM/EEPROM/MII Management Register |
171 | 171 | ||
172 | MASK_MIIR_MII_READ = 0x00000000 |
172 | MASK_MIIR_MII_READ = 0x00000000 |
173 | MASK_MIIR_MII_WRITE = 0x00000008 |
173 | MASK_MIIR_MII_WRITE = 0x00000008 |
174 | MASK_MIIR_MII_MDO = 0x00000004 |
174 | MASK_MIIR_MII_MDO = 0x00000004 |
175 | MASK_MIIR_MII_MDI = 0x00000002 |
175 | MASK_MIIR_MII_MDI = 0x00000002 |
176 | MASK_MIIR_MII_MDC = 0x00000001 |
176 | MASK_MIIR_MII_MDC = 0x00000001 |
177 | 177 | ||
178 | ; ST+OP+PHYAD+REGAD+TA |
178 | ; ST+OP+PHYAD+REGAD+TA |
179 | 179 | ||
180 | OP_READ = 0x6000 ; ST:01+OP:10+PHYAD+REGAD+TA:Z0 |
180 | OP_READ = 0x6000 ; ST:01+OP:10+PHYAD+REGAD+TA:Z0 |
181 | OP_WRITE = 0x5002 ; ST:01+OP:01+PHYAD+REGAD+TA:10 |
181 | OP_WRITE = 0x5002 ; ST:01+OP:01+PHYAD+REGAD+TA:10 |
182 | 182 | ||
183 | ; ------------------------------------------------------------------------- |
183 | ; ------------------------------------------------------------------------- |
184 | ; Constants for Myson PHY |
184 | ; Constants for Myson PHY |
185 | ; ------------------------------------------------------------------------- |
185 | ; ------------------------------------------------------------------------- |
186 | 186 | ||
187 | MysonPHYID = 0xd0000302 |
187 | MysonPHYID = 0xd0000302 |
188 | MysonPHYID0 = 0x0302 |
188 | MysonPHYID0 = 0x0302 |
189 | StatusRegister = 18 |
189 | StatusRegister = 18 |
190 | SPEED100 = 0x0400 ; bit10 |
190 | SPEED100 = 0x0400 ; bit10 |
191 | FULLMODE = 0x0800 ; bit11 |
191 | FULLMODE = 0x0800 ; bit11 |
192 | 192 | ||
193 | ; ------------------------------------------------------------------------- |
193 | ; ------------------------------------------------------------------------- |
194 | ; Constants for Seeq 80225 PHY |
194 | ; Constants for Seeq 80225 PHY |
195 | ; ------------------------------------------------------------------------- |
195 | ; ------------------------------------------------------------------------- |
196 | 196 | ||
197 | SeeqPHYID0 = 0x0016 |
197 | SeeqPHYID0 = 0x0016 |
198 | MIIRegister18 = 18 |
198 | MIIRegister18 = 18 |
199 | SPD_DET_100 = 0x80 |
199 | SPD_DET_100 = 0x80 |
200 | DPLX_DET_FULL = 0x40 |
200 | DPLX_DET_FULL = 0x40 |
201 | 201 | ||
202 | ; ------------------------------------------------------------------------- |
202 | ; ------------------------------------------------------------------------- |
203 | ; Constants for Ahdoc 101 PHY |
203 | ; Constants for Ahdoc 101 PHY |
204 | ; ------------------------------------------------------------------------- |
204 | ; ------------------------------------------------------------------------- |
205 | 205 | ||
206 | AhdocPHYID0 = 0x0022 |
206 | AhdocPHYID0 = 0x0022 |
207 | DiagnosticReg = 18 |
207 | DiagnosticReg = 18 |
208 | DPLX_FULL = 0x0800 |
208 | DPLX_FULL = 0x0800 |
209 | Speed_100 = 0x0400 |
209 | Speed_100 = 0x0400 |
210 | 210 | ||
211 | ; -------------------------------------------------------------------------- |
211 | ; -------------------------------------------------------------------------- |
212 | ; Constants |
212 | ; Constants |
213 | ; -------------------------------------------------------------------------- |
213 | ; -------------------------------------------------------------------------- |
214 | 214 | ||
215 | MarvellPHYID0 = 0x0141 |
215 | MarvellPHYID0 = 0x0141 |
216 | LevelOnePHYID0 = 0x0013 |
216 | LevelOnePHYID0 = 0x0013 |
217 | 217 | ||
218 | MII1000BaseTControlReg = 9 |
218 | MII1000BaseTControlReg = 9 |
219 | MII1000BaseTStatusReg = 10 |
219 | MII1000BaseTStatusReg = 10 |
220 | SpecificReg = 17 |
220 | SpecificReg = 17 |
221 | 221 | ||
222 | ; for 1000BaseT Control Register |
222 | ; for 1000BaseT Control Register |
223 | 223 | ||
224 | PHYAbletoPerform1000FullDuplex = 0x0200 |
224 | PHYAbletoPerform1000FullDuplex = 0x0200 |
225 | PHYAbletoPerform1000HalfDuplex = 0x0100 |
225 | PHYAbletoPerform1000HalfDuplex = 0x0100 |
226 | PHY1000AbilityMask = 0x300 |
226 | PHY1000AbilityMask = 0x300 |
227 | 227 | ||
228 | ; for phy specific status register, marvell phy. |
228 | ; for phy specific status register, marvell phy. |
229 | 229 | ||
230 | SpeedMask = 0x0c000 |
230 | SpeedMask = 0x0c000 |
231 | Speed_1000M = 0x08000 |
231 | Speed_1000M = 0x08000 |
232 | Speed_100M = 0x4000 |
232 | Speed_100M = 0x4000 |
233 | Speed_10M = 0 |
233 | Speed_10M = 0 |
234 | Full_Duplex = 0x2000 |
234 | Full_Duplex = 0x2000 |
235 | 235 | ||
236 | ; for phy specific status register, levelone phy |
236 | ; for phy specific status register, levelone phy |
237 | 237 | ||
238 | LXT1000_100M = 0x08000 |
238 | LXT1000_100M = 0x08000 |
239 | LXT1000_1000M = 0x0c000 |
239 | LXT1000_1000M = 0x0c000 |
240 | LXT1000_Full = 0x200 |
240 | LXT1000_Full = 0x200 |
241 | 241 | ||
242 | ; for PHY |
242 | ; for PHY |
243 | 243 | ||
244 | LinkIsUp = 0x0004 |
244 | LinkIsUp = 0x0004 |
245 | LinkIsUp2 = 0x00040000 |
245 | LinkIsUp2 = 0x00040000 |
246 | 246 | ||
247 | 247 | ||
248 | 248 | ||
249 | struct descriptor |
249 | struct descriptor |
250 | status dd ? |
250 | status dd ? |
251 | control dd ? |
251 | control dd ? |
252 | buffer dd ? |
252 | buffer dd ? |
253 | next_desc dd ? |
253 | next_desc dd ? |
254 | 254 | ||
255 | next_desc_logical dd ? |
255 | next_desc_logical dd ? |
256 | skbuff dd ? |
256 | skbuff dd ? |
257 | reserved1 dd ? |
257 | reserved1 dd ? |
258 | reserved2 dd ? |
258 | reserved2 dd ? |
259 | ends |
259 | ends |
260 | 260 | ||
261 | 261 | ||
262 | struct device ETH_DEVICE |
262 | struct device ETH_DEVICE |
263 | 263 | ||
264 | io_addr dd ? |
264 | io_addr dd ? |
265 | pci_bus dd ? |
265 | pci_bus dd ? |
266 | pci_dev dd ? |
266 | pci_dev dd ? |
267 | irq_line db ? |
267 | irq_line db ? |
268 | dev_id dw ? |
268 | dev_id dw ? |
269 | flags dd ? |
269 | flags dd ? |
270 | crvalue dd ? |
270 | crvalue dd ? |
271 | bcrvalue dd ? |
271 | bcrvalue dd ? |
272 | cur_rx dd ? |
272 | cur_rx dd ? |
273 | cur_tx dd ? |
273 | cur_tx dd ? |
274 | default_port dd ? |
274 | default_port dd ? |
275 | PHYType dd ? |
275 | PHYType dd ? |
276 | 276 | ||
277 | ; MII transceiver section. |
277 | ; MII transceiver section. |
278 | mii_cnt dd ? ; MII device addresses. |
278 | mii_cnt dd ? ; MII device addresses. |
279 | phys db ? ; MII device addresses. |
279 | phys db ? ; MII device addresses. |
280 | 280 | ||
281 | ; descriptors |
281 | ; descriptors |
282 | rb 0x100 - ($ and 0xff) ; align 256 |
282 | rb 0x100 - ($ and 0xff) ; align 256 |
283 | tx_desc rb NUM_TX_DESC*sizeof.descriptor |
283 | tx_desc rb NUM_TX_DESC*sizeof.descriptor |
284 | rx_desc rb NUM_RX_DESC*sizeof.descriptor |
284 | rx_desc rb NUM_RX_DESC*sizeof.descriptor |
285 | 285 | ||
286 | ends |
286 | ends |
287 | 287 | ||
288 | 288 | ||
289 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
289 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
290 | ;; ;; |
290 | ;; ;; |
291 | ;; proc START ;; |
291 | ;; proc START ;; |
292 | ;; ;; |
292 | ;; ;; |
293 | ;; (standard driver proc) ;; |
293 | ;; (standard driver proc) ;; |
294 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
294 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
295 | 295 | ||
296 | proc START c, reason:dword, cmdline:dword |
296 | proc START c, reason:dword, cmdline:dword |
297 | 297 | ||
298 | cmp [reason], DRV_ENTRY |
298 | cmp [reason], DRV_ENTRY |
299 | jne .fail |
299 | jne .fail |
300 | 300 | ||
301 | DEBUGF 1,"Loading driver\n" |
301 | DEBUGF 1,"Loading driver\n" |
302 | invoke RegService, my_service, service_proc |
302 | invoke RegService, my_service, service_proc |
303 | ret |
303 | ret |
304 | 304 | ||
305 | .fail: |
305 | .fail: |
306 | xor eax, eax |
306 | xor eax, eax |
307 | ret |
307 | ret |
308 | 308 | ||
309 | endp |
309 | endp |
310 | 310 | ||
311 | 311 | ||
312 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
312 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
313 | ;; ;; |
313 | ;; ;; |
314 | ;; proc SERVICE_PROC ;; |
314 | ;; proc SERVICE_PROC ;; |
315 | ;; ;; |
315 | ;; ;; |
316 | ;; (standard driver proc) ;; |
316 | ;; (standard driver proc) ;; |
317 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
317 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
318 | 318 | ||
319 | proc service_proc stdcall, ioctl:dword |
319 | proc service_proc stdcall, ioctl:dword |
320 | 320 | ||
321 | mov edx, [ioctl] |
321 | mov edx, [ioctl] |
322 | mov eax, [edx + IOCTL.io_code] |
322 | mov eax, [edx + IOCTL.io_code] |
323 | 323 | ||
324 | ;------------------------------------------------------ |
324 | ;------------------------------------------------------ |
325 | 325 | ||
326 | cmp eax, 0 ;SRV_GETVERSION |
326 | cmp eax, 0 ;SRV_GETVERSION |
327 | jne @F |
327 | jne @F |
328 | 328 | ||
329 | cmp [edx + IOCTL.out_size], 4 |
329 | cmp [edx + IOCTL.out_size], 4 |
330 | jb .fail |
330 | jb .fail |
331 | mov eax, [edx + IOCTL.output] |
331 | mov eax, [edx + IOCTL.output] |
332 | mov [eax], dword API_VERSION |
332 | mov [eax], dword API_VERSION |
333 | 333 | ||
334 | xor eax, eax |
334 | xor eax, eax |
335 | ret |
335 | ret |
336 | 336 | ||
337 | ;------------------------------------------------------ |
337 | ;------------------------------------------------------ |
338 | @@: |
338 | @@: |
339 | cmp eax, 1 ;SRV_HOOK |
339 | cmp eax, 1 ;SRV_HOOK |
340 | jne .fail |
340 | jne .fail |
341 | 341 | ||
342 | cmp [edx + IOCTL.inp_size], 3 ; Data input must be at least 3 bytes |
342 | cmp [edx + IOCTL.inp_size], 3 ; Data input must be at least 3 bytes |
343 | jb .fail |
343 | jb .fail |
344 | 344 | ||
345 | mov eax, [edx + IOCTL.input] |
345 | mov eax, [edx + IOCTL.input] |
346 | cmp byte [eax], 1 ; 1 means device number and bus number (pci) are given |
346 | cmp byte [eax], 1 ; 1 means device number and bus number (pci) are given |
347 | jne .fail ; other types arent supported for this card yet |
347 | jne .fail ; other types arent supported for this card yet |
348 | 348 | ||
349 | ; check if the device is already listed |
349 | ; check if the device is already listed |
350 | 350 | ||
351 | mov esi, device_list |
351 | mov esi, device_list |
352 | mov ecx, [devices] |
352 | mov ecx, [devices] |
353 | test ecx, ecx |
353 | test ecx, ecx |
354 | jz .firstdevice |
354 | jz .firstdevice |
355 | 355 | ||
356 | ; mov eax, [edx + IOCTL.input] ; get the pci bus and device numbers |
356 | ; mov eax, [edx + IOCTL.input] ; get the pci bus and device numbers |
357 | mov ax, [eax+1] ; |
357 | mov ax, [eax+1] ; |
358 | .nextdevice: |
358 | .nextdevice: |
359 | mov ebx, [esi] |
359 | mov ebx, [esi] |
360 | cmp al, byte[ebx + device.pci_bus] |
360 | cmp al, byte[ebx + device.pci_bus] |
361 | jne @f |
361 | jne @f |
362 | cmp ah, byte[ebx + device.pci_dev] |
362 | cmp ah, byte[ebx + device.pci_dev] |
363 | je .find_devicenum ; Device is already loaded, let's find it's device number |
363 | je .find_devicenum ; Device is already loaded, let's find it's device number |
364 | @@: |
364 | @@: |
365 | add esi, 4 |
365 | add esi, 4 |
366 | loop .nextdevice |
366 | loop .nextdevice |
367 | 367 | ||
368 | 368 | ||
369 | ; This device doesnt have its own eth_device structure yet, lets create one |
369 | ; This device doesnt have its own eth_device structure yet, lets create one |
370 | .firstdevice: |
370 | .firstdevice: |
371 | cmp [devices], MAX_DEVICES ; First check if the driver can handle one more card |
371 | cmp [devices], MAX_DEVICES ; First check if the driver can handle one more card |
372 | jae .fail |
372 | jae .fail |
373 | 373 | ||
374 | allocate_and_clear ebx, sizeof.device, .fail |
374 | allocate_and_clear ebx, sizeof.device, .fail |
375 | 375 | ||
376 | ; Fill in the direct call addresses into the struct |
376 | ; Fill in the direct call addresses into the struct |
377 | 377 | ||
378 | mov [ebx + device.reset], reset |
378 | mov [ebx + device.reset], reset |
379 | mov [ebx + device.transmit], transmit |
379 | mov [ebx + device.transmit], transmit |
380 | mov [ebx + device.unload], unload |
380 | mov [ebx + device.unload], unload |
381 | mov [ebx + device.name], my_service |
381 | mov [ebx + device.name], my_service |
382 | 382 | ||
383 | ; save the pci bus and device numbers |
383 | ; save the pci bus and device numbers |
384 | 384 | ||
385 | mov eax, [edx + IOCTL.input] |
385 | mov eax, [edx + IOCTL.input] |
386 | movzx ecx, byte[eax+1] |
386 | movzx ecx, byte[eax+1] |
387 | mov [ebx + device.pci_bus], ecx |
387 | mov [ebx + device.pci_bus], ecx |
388 | movzx ecx, byte[eax+2] |
388 | movzx ecx, byte[eax+2] |
389 | mov [ebx + device.pci_dev], ecx |
389 | mov [ebx + device.pci_dev], ecx |
390 | 390 | ||
391 | ; Now, it's time to find the base io addres of the PCI device |
391 | ; Now, it's time to find the base io addres of the PCI device |
392 | 392 | ||
393 | stdcall PCI_find_io, [ebx + device.pci_bus], [ebx + device.pci_dev] |
393 | stdcall PCI_find_io, [ebx + device.pci_bus], [ebx + device.pci_dev] |
394 | mov [ebx + device.io_addr], eax |
394 | mov [ebx + device.io_addr], eax |
395 | 395 | ||
396 | ; We've found the io address, find IRQ now |
396 | ; We've found the io address, find IRQ now |
397 | 397 | ||
398 | invoke PciRead8, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.interrupt_line |
398 | invoke PciRead8, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.interrupt_line |
399 | mov [ebx + device.irq_line], al |
399 | mov [ebx + device.irq_line], al |
400 | 400 | ||
401 | DEBUGF 1,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\ |
401 | DEBUGF 1,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\ |
402 | [ebx + device.pci_dev]:1,[ebx + device.pci_bus]:1,[ebx + device.irq_line]:1,[ebx + device.io_addr]:8 |
402 | [ebx + device.pci_dev]:1,[ebx + device.pci_bus]:1,[ebx + device.irq_line]:1,[ebx + device.io_addr]:8 |
403 | 403 | ||
404 | ; Ok, the eth_device structure is ready, let's probe the device |
404 | ; Ok, the eth_device structure is ready, let's probe the device |
405 | ; Because initialization fires IRQ, IRQ handler must be aware of this device |
405 | ; Because initialization fires IRQ, IRQ handler must be aware of this device |
406 | mov eax, [devices] ; Add the device structure to our device list |
406 | mov eax, [devices] ; Add the device structure to our device list |
407 | mov [device_list+4*eax], ebx ; (IRQ handler uses this list to find device) |
407 | mov [device_list+4*eax], ebx ; (IRQ handler uses this list to find device) |
408 | inc [devices] ; |
408 | inc [devices] ; |
409 | 409 | ||
410 | call probe ; this function will output in eax |
410 | call probe ; this function will output in eax |
411 | test eax, eax |
411 | test eax, eax |
412 | jnz .err2 ; If an error occured, exit |
412 | jnz .err2 ; If an error occured, exit |
413 | 413 | ||
414 | mov [ebx + device.type], NET_TYPE_ETH |
414 | mov [ebx + device.type], NET_TYPE_ETH |
415 | invoke NetRegDev |
415 | invoke NetRegDev |
416 | 416 | ||
417 | cmp eax, -1 |
417 | cmp eax, -1 |
418 | je .destroy |
418 | je .destroy |
419 | 419 | ||
420 | ret |
420 | ret |
421 | 421 | ||
422 | ; If the device was already loaded, find the device number and return it in eax |
422 | ; If the device was already loaded, find the device number and return it in eax |
423 | 423 | ||
424 | .find_devicenum: |
424 | .find_devicenum: |
425 | DEBUGF 2,"Trying to find device number of already registered device\n" |
425 | DEBUGF 2,"Trying to find device number of already registered device\n" |
426 | invoke NetPtrToNum ; This kernel procedure converts a pointer to device struct in ebx |
426 | invoke NetPtrToNum ; This kernel procedure converts a pointer to device struct in ebx |
427 | ; into a device number in edi |
427 | ; into a device number in edi |
428 | mov eax, edi ; Application wants it in eax instead |
428 | mov eax, edi ; Application wants it in eax instead |
429 | DEBUGF 2,"Kernel says: %u\n", eax |
429 | DEBUGF 2,"Kernel says: %u\n", eax |
430 | ret |
430 | ret |
431 | 431 | ||
432 | ; If an error occured, remove all allocated data and exit (returning -1 in eax) |
432 | ; If an error occured, remove all allocated data and exit (returning -1 in eax) |
433 | 433 | ||
434 | .destroy: |
434 | .destroy: |
435 | ; todo: reset device into virgin state |
435 | ; todo: reset device into virgin state |
436 | 436 | ||
437 | .err2: |
437 | .err2: |
438 | dec [devices] |
438 | dec [devices] |
439 | .err: |
439 | .err: |
440 | DEBUGF 2,"removing device structure\n" |
440 | DEBUGF 2,"removing device structure\n" |
441 | invoke KernelFree, ebx |
441 | invoke KernelFree, ebx |
442 | .fail: |
442 | .fail: |
443 | or eax, -1 |
443 | or eax, -1 |
444 | ret |
444 | ret |
445 | 445 | ||
446 | ;------------------------------------------------------ |
446 | ;------------------------------------------------------ |
447 | endp |
447 | endp |
448 | 448 | ||
449 | 449 | ||
450 | ;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;; |
450 | ;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;; |
451 | ;; ;; |
451 | ;; ;; |
452 | ;; Actual Hardware dependent code starts here ;; |
452 | ;; Actual Hardware dependent code starts here ;; |
453 | ;; ;; |
453 | ;; ;; |
454 | ;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;; |
454 | ;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;; |
455 | 455 | ||
456 | 456 | ||
457 | 457 | ||
458 | align 4 |
458 | align 4 |
459 | unload: |
459 | unload: |
460 | ; TODO: (in this particular order) |
460 | ; TODO: (in this particular order) |
461 | ; |
461 | ; |
462 | ; - Stop the device |
462 | ; - Stop the device |
463 | 463 | ||
464 | ; /* Disable Tx Rx*/ |
464 | ; /* Disable Tx Rx*/ |
465 | ; outl( mtdx.crvalue & (~TxEnable) & (~RxEnable), mtdx.ioaddr + TCRRCR ); |
465 | ; outl( mtdx.crvalue & (~TxEnable) & (~RxEnable), mtdx.ioaddr + TCRRCR ); |
466 | ; |
466 | ; |
467 | ; /* Reset the chip to erase previous misconfiguration. */ |
467 | ; /* Reset the chip to erase previous misconfiguration. */ |
468 | ; mtd_reset(nic); |
468 | ; mtd_reset(nic); |
469 | 469 | ||
470 | ; - Detach int handler |
470 | ; - Detach int handler |
471 | ; - Remove device from local list (device_list) |
471 | ; - Remove device from local list (device_list) |
472 | ; - call unregister function in kernel |
472 | ; - call unregister function in kernel |
473 | ; - Remove all allocated structures and buffers the card used |
473 | ; - Remove all allocated structures and buffers the card used |
474 | 474 | ||
475 | or eax, -1 |
475 | or eax, -1 |
476 | - | ||
477 | ret |
476 | ret |
478 | 477 | ||
479 | 478 | ||
480 | ;------- |
479 | ;------- |
481 | ; |
480 | ; |
482 | ; PROBE |
481 | ; PROBE |
483 | ; |
482 | ; |
484 | ;------- |
483 | ;------- |
485 | align 4 |
484 | align 4 |
486 | probe: |
485 | probe: |
487 | 486 | ||
488 | DEBUGF 1,"Probing\n" |
487 | DEBUGF 1,"Probing\n" |
489 | 488 | ||
490 | ; Make the device a bus master |
489 | ; Make the device a bus master |
491 | invoke PciRead32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command |
490 | invoke PciRead32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command |
492 | or al, PCI_CMD_MASTER |
491 | or al, PCI_CMD_MASTER |
493 | invoke PciWrite32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command, eax |
492 | invoke PciWrite32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command, eax |
494 | 493 | ||
495 | ; Check vendor/device id's |
494 | ; Check vendor/device id's |
496 | invoke PciRead32, [ebx + device.pci_bus], [ebx + device.pci_dev], 0 |
495 | invoke PciRead32, [ebx + device.pci_bus], [ebx + device.pci_dev], 0 |
497 | cmp ax, 0x1516 |
496 | cmp ax, 0x1516 |
498 | jne .notfound |
497 | jne .notfound |
499 | shr eax, 16 |
498 | shr eax, 16 |
500 | mov [ebx + device.dev_id], ax |
499 | mov [ebx + device.dev_id], ax |
501 | cmp ax, 0x0800 |
500 | cmp ax, 0x0800 |
502 | je .mtd800 |
501 | je .mtd800 |
503 | cmp ax, 0x0803 |
502 | cmp ax, 0x0803 |
504 | je .mtd803 |
503 | je .mtd803 |
505 | cmp ax, 0x0891 |
504 | cmp ax, 0x0891 |
506 | je .mtd891 |
505 | je .mtd891 |
507 | 506 | ||
508 | .notfound: |
507 | .notfound: |
509 | DEBUGF 2,"Device not supported!\n" |
508 | DEBUGF 2,"Device not supported!\n" |
510 | xor eax, eax |
509 | xor eax, eax |
511 | dec eax |
510 | dec eax |
512 | ret |
511 | ret |
513 | 512 | ||
514 | .mtd803: |
513 | .mtd803: |
515 | mov [ebx + device.name], sz_mtd803 |
514 | mov [ebx + device.name], sz_mtd803 |
516 | DEBUGF 1,"Device has chip xcvr\n" |
515 | DEBUGF 1,"Device has chip xcvr\n" |
517 | jmp .xcvr_set |
516 | jmp .xcvr_set |
518 | 517 | ||
519 | .mtd800: |
518 | .mtd800: |
520 | DEBUGF 1,"Device has mii xcvr\n" |
519 | DEBUGF 1,"Device has mii xcvr\n" |
521 | mov [ebx + device.name], sz_mtd800 |
520 | mov [ebx + device.name], sz_mtd800 |
522 | jmp .xcvr_set |
521 | jmp .xcvr_set |
523 | 522 | ||
524 | .mtd891: |
523 | .mtd891: |
525 | DEBUGF 1,"Device has mii xcvr\n" |
524 | DEBUGF 1,"Device has mii xcvr\n" |
526 | mov [ebx + device.name], sz_mtd800 |
525 | mov [ebx + device.name], sz_mtd800 |
527 | 526 | ||
528 | .xcvr_set: |
527 | .xcvr_set: |
529 | call read_mac |
528 | call read_mac |
530 | 529 | ||
531 | ; Reset the chip to erase previous misconfiguration. |
530 | ; Reset the chip to erase previous misconfiguration. |
532 | set_io [ebx + device.io_addr], 0 |
531 | set_io [ebx + device.io_addr], 0 |
533 | set_io [ebx + device.io_addr], BCR |
532 | set_io [ebx + device.io_addr], BCR |
534 | xor eax, eax |
533 | xor eax, eax |
535 | inc eax |
534 | inc eax |
536 | out dx, eax |
535 | out dx, eax |
537 | 536 | ||
538 | ; find the connected MII xcvrs |
537 | ; find the connected MII xcvrs |
539 | cmp [ebx + device.dev_id], 0x0803 |
538 | cmp [ebx + device.dev_id], 0x0803 |
540 | je .is_803 |
539 | je .is_803 |
541 | 540 | ||
542 | ; int phy, phy_idx = 0; |
541 | ; int phy, phy_idx = 0; |
543 | ; |
542 | ; |
544 | ; for (phy = 1; phy < 32 && phy_idx < 1; phy++) { |
543 | ; for (phy = 1; phy < 32 && phy_idx < 1; phy++) { |
545 | ; int mii_status = mdio_read(nic, phy, 1); |
544 | ; int mii_status = mdio_read(nic, phy, 1); |
546 | ; |
545 | ; |
547 | ; if (mii_status != 0xffff && mii_status != 0x0000) { |
546 | ; if (mii_status != 0xffff && mii_status != 0x0000) { |
548 | ; mtdx.phys[phy_idx] = phy; |
547 | ; mtdx.phys[phy_idx] = phy; |
549 | ; |
548 | ; |
550 | ; DBG ( "%s: MII PHY found at address %d, status " |
549 | ; DBG ( "%s: MII PHY found at address %d, status " |
551 | ; "0x%4.4x.\n", mtdx.nic_name, phy, mii_status ); |
550 | ; "0x%4.4x.\n", mtdx.nic_name, phy, mii_status ); |
552 | ; /* get phy type */ |
551 | ; /* get phy type */ |
553 | ; { |
552 | ; { |
554 | ; unsigned int data; |
553 | ; unsigned int data; |
555 | ; |
554 | ; |
556 | ; data = mdio_read(nic, mtdx.phys[phy_idx], 2); |
555 | ; data = mdio_read(nic, mtdx.phys[phy_idx], 2); |
557 | ; if (data equ= SeeqPHYID0) |
556 | ; if (data equ= SeeqPHYID0) |
558 | ; mtdx.PHYType = SeeqPHY; |
557 | ; mtdx.PHYType = SeeqPHY; |
559 | ; else if (data equ= AhdocPHYID0) |
558 | ; else if (data equ= AhdocPHYID0) |
560 | ; mtdx.PHYType = AhdocPHY; |
559 | ; mtdx.PHYType = AhdocPHY; |
561 | ; else if (data equ= MarvellPHYID0) |
560 | ; else if (data equ= MarvellPHYID0) |
562 | ; mtdx.PHYType = MarvellPHY; |
561 | ; mtdx.PHYType = MarvellPHY; |
563 | ; else if (data equ= MysonPHYID0) |
562 | ; else if (data equ= MysonPHYID0) |
564 | ; mtdx.PHYType = Myson981; |
563 | ; mtdx.PHYType = Myson981; |
565 | ; else if (data equ= LevelOnePHYID0) |
564 | ; else if (data equ= LevelOnePHYID0) |
566 | ; mtdx.PHYType = LevelOnePHY; |
565 | ; mtdx.PHYType = LevelOnePHY; |
567 | ; else |
566 | ; else |
568 | ; mtdx.PHYType = OtherPHY; |
567 | ; mtdx.PHYType = OtherPHY; |
569 | ; } |
568 | ; } |
570 | ; phy_idx++; |
569 | ; phy_idx++; |
571 | ; } |
570 | ; } |
572 | ; } |
571 | ; } |
573 | ; |
572 | ; |
574 | ; mtdx.mii_cnt = phy_idx; |
573 | ; mtdx.mii_cnt = phy_idx; |
575 | ; if (phy_idx equ= 0) { |
574 | ; if (phy_idx equ= 0) { |
576 | ; printf("%s: MII PHY not found -- this device may " |
575 | ; printf("%s: MII PHY not found -- this device may " |
577 | ; "not operate correctly.\n", mtdx.nic_name); |
576 | ; "not operate correctly.\n", mtdx.nic_name); |
578 | ; } |
577 | ; } |
579 | 578 | ||
580 | jmp .no_803 |
579 | jmp .no_803 |
581 | 580 | ||
582 | .is_803: |
581 | .is_803: |
583 | mov [ebx + device.phys], 32 |
582 | mov [ebx + device.phys], 32 |
584 | 583 | ||
585 | ; get phy type |
584 | ; get phy type |
586 | set_io [ebx + device.io_addr], 0 |
585 | set_io [ebx + device.io_addr], 0 |
587 | set_io [ebx + device.io_addr], PHYIDENTIFIER |
586 | set_io [ebx + device.io_addr], PHYIDENTIFIER |
588 | in eax, dx |
587 | in eax, dx |
589 | 588 | ||
590 | cmp eax, MysonPHYID |
589 | cmp eax, MysonPHYID |
591 | jne @f |
590 | jne @f |
592 | mov [ebx + device.PHYType], MysonPHY |
591 | mov [ebx + device.PHYType], MysonPHY |
593 | DEBUGF 1,"Myson PHY\n" |
592 | DEBUGF 1,"Myson PHY\n" |
594 | jmp .no_803 |
593 | jmp .no_803 |
595 | @@: |
594 | @@: |
596 | 595 | ||
597 | mov [ebx + device.PHYType], OtherPHY |
596 | mov [ebx + device.PHYType], OtherPHY |
598 | DEBUGF 1,"Other PHY\n" |
597 | DEBUGF 1,"Other PHY\n" |
599 | .no_803: |
598 | .no_803: |
600 | 599 | ||
601 | ;------- |
600 | ;------- |
602 | ; |
601 | ; |
603 | ; RESET |
602 | ; RESET |
604 | ; |
603 | ; |
605 | ;------- |
604 | ;------- |
606 | align 4 |
605 | align 4 |
607 | reset: |
606 | reset: |
608 | 607 | ||
609 | DEBUGF 1,"Resetting\n" |
608 | DEBUGF 1,"Resetting\n" |
610 | 609 | ||
611 | ; attach irq handler |
610 | ; attach irq handler |
612 | movzx eax, [ebx + device.irq_line] |
611 | movzx eax, [ebx + device.irq_line] |
613 | DEBUGF 1,"Attaching int handler to irq %x\n", eax:1 |
612 | DEBUGF 1,"Attaching int handler to irq %x\n", eax:1 |
614 | invoke AttachIntHandler, eax, int_handler, ebx |
613 | invoke AttachIntHandler, eax, int_handler, ebx |
615 | test eax, eax |
614 | test eax, eax |
616 | jnz @f |
615 | jnz @f |
617 | DEBUGF 2,"Could not attach int handler!\n" |
616 | DEBUGF 2,"Could not attach int handler!\n" |
618 | or eax, -1 |
617 | or eax, -1 |
619 | ret |
618 | ret |
620 | @@: |
619 | @@: |
621 | 620 | ||
622 | ; Reset the chip to erase previous misconfiguration. |
621 | ; Reset the chip to erase previous misconfiguration. |
623 | set_io [ebx + device.io_addr], 0 |
622 | set_io [ebx + device.io_addr], 0 |
624 | set_io [ebx + device.io_addr], BCR |
623 | set_io [ebx + device.io_addr], BCR |
625 | xor eax, eax |
624 | xor eax, eax |
626 | inc eax |
625 | inc eax |
627 | out dx, eax |
626 | out dx, eax |
628 | 627 | ||
629 | call init_ring |
628 | call init_ring |
- | 629 | test eax, eax |
|
- | 630 | jnz .err |
|
630 | 631 | ||
631 | ; Initialize other registers. |
632 | ; Initialize other registers. |
632 | ; Configure the PCI bus bursts and FIFO thresholds. |
633 | ; Configure the PCI bus bursts and FIFO thresholds. |
633 | mov [ebx + device.bcrvalue], 0x10 ; little-endian, 8 burst length |
634 | mov [ebx + device.bcrvalue], 0x10 ; little-endian, 8 burst length |
634 | mov [ebx + device.crvalue], 0xa00 ; 128 burst length |
635 | mov [ebx + device.crvalue], 0xa00 ; 128 burst length |
635 | 636 | ||
636 | cmp [ebx + device.dev_id], 0x891 |
637 | cmp [ebx + device.dev_id], 0x891 |
637 | jne @f |
638 | jne @f |
638 | or [ebx + device.bcrvalue], 0x200 ; set PROG bit |
639 | or [ebx + device.bcrvalue], 0x200 ; set PROG bit |
639 | or [ebx + device.crvalue], 0x02000000 ; set enhanced bit |
640 | or [ebx + device.crvalue], 0x02000000 ; set enhanced bit |
640 | @@: |
641 | @@: |
641 | or [ebx + device.crvalue], RxEnable + TxThreshold + TxEnable |
642 | or [ebx + device.crvalue], RxEnable + TxThreshold + TxEnable |
642 | 643 | ||
643 | call set_rx_mode |
644 | call set_rx_mode |
644 | 645 | ||
645 | set_io [ebx + device.io_addr], 0 |
646 | set_io [ebx + device.io_addr], 0 |
646 | set_io [ebx + device.io_addr], BCR |
647 | set_io [ebx + device.io_addr], BCR |
647 | mov eax, [ebx + device.bcrvalue] |
648 | mov eax, [ebx + device.bcrvalue] |
648 | out dx, eax |
649 | out dx, eax |
649 | 650 | ||
650 | set_io [ebx + device.io_addr], TCRRCR |
651 | set_io [ebx + device.io_addr], TCRRCR |
651 | mov eax, [ebx + device.crvalue] |
652 | mov eax, [ebx + device.crvalue] |
652 | out dx, eax |
653 | out dx, eax |
653 | 654 | ||
654 | call getlinkstatus |
655 | call getlinkstatus |
655 | 656 | ||
656 | ; Restart Rx engine if stopped. |
657 | ; Restart Rx engine if stopped. |
657 | set_io [ebx + device.io_addr], 0 |
658 | set_io [ebx + device.io_addr], 0 |
658 | set_io [ebx + device.io_addr], RXPDR |
659 | set_io [ebx + device.io_addr], RXPDR |
659 | xor eax, eax |
660 | xor eax, eax |
660 | out dx, eax |
661 | out dx, eax |
661 | 662 | ||
662 | ; Enable interrupts |
663 | ; Enable interrupts |
663 | set_io [ebx + device.io_addr], ISR |
664 | set_io [ebx + device.io_addr], ISR |
664 | mov eax, FBE or TUNF or CNTOVF or RBU or TI or RI |
665 | mov eax, FBE or TUNF or CNTOVF or RBU or TI or RI |
665 | out dx, eax |
666 | out dx, eax |
666 | set_io [ebx + device.io_addr], IMR |
667 | set_io [ebx + device.io_addr], IMR |
667 | out dx, eax |
668 | out dx, eax |
668 | 669 | ||
669 | ; clear packet/byte counters |
670 | ; clear packet/byte counters |
670 | xor eax, eax |
671 | xor eax, eax |
671 | lea edi, [ebx + device.bytes_tx] |
672 | lea edi, [ebx + device.bytes_tx] |
672 | mov ecx, 6 |
673 | mov ecx, 6 |
673 | rep stosd |
674 | rep stosd |
674 | 675 | ||
675 | mov [ebx + device.mtu], 1514 |
676 | mov [ebx + device.mtu], 1514 |
676 | xor eax, eax |
677 | xor eax, eax |
677 | ret |
678 | ret |
- | 679 | ||
- | 680 | .err: |
|
- | 681 | DEBUGF 2, "Error!\n" |
|
- | 682 | or eax, -1 |
|
- | 683 | ret |
|
678 | 684 | ||
679 | 685 | ||
680 | 686 | ||
681 | 687 | ||
682 | align 4 |
688 | align 4 |
683 | init_ring: |
689 | init_ring: |
684 | 690 | ||
685 | DEBUGF 1,"initializing rx and tx ring\n" |
691 | DEBUGF 1, "initializing rx and tx ring\n" |
686 | 692 | ||
687 | ; Initialize all Rx descriptors |
693 | ; Initialize all Rx descriptors |
688 | lea esi, [ebx + device.rx_desc] |
694 | lea esi, [ebx + device.rx_desc] |
689 | mov [ebx + device.cur_rx], esi |
695 | mov [ebx + device.cur_rx], esi |
690 | mov ecx, NUM_RX_DESC |
696 | mov ecx, NUM_RX_DESC |
691 | .rx_desc_loop: |
697 | .rx_desc_loop: |
692 | mov [esi + descriptor.status], RXOWN |
698 | mov [esi + descriptor.status], RXOWN |
693 | mov [esi + descriptor.control], 1536 shl RBSShift |
699 | mov [esi + descriptor.control], 1514 shl RBSShift |
694 | 700 | ||
695 | lea eax, [esi + sizeof.descriptor] |
701 | lea eax, [esi + sizeof.descriptor] |
696 | mov [esi + descriptor.next_desc_logical], eax |
702 | mov [esi + descriptor.next_desc_logical], eax |
697 | push ecx esi |
703 | push ecx esi |
698 | invoke GetPhysAddr |
704 | invoke GetPhysAddr |
699 | mov [esi + descriptor.next_desc], eax |
705 | mov [esi + descriptor.next_desc], eax |
700 | 706 | ||
701 | invoke KernelAlloc, 1536 |
707 | invoke NetAlloc, 1514+NET_BUFF.data |
- | 708 | pop esi ecx |
|
- | 709 | test eax, eax |
|
702 | pop esi |
710 | jz .out_of_mem |
703 | push esi |
711 | push ecx esi |
704 | mov [esi + descriptor.skbuff], eax |
712 | mov [esi + descriptor.skbuff], eax |
- | 713 | invoke GetPgAddr |
|
705 | invoke GetPgAddr |
714 | add eax, NET_BUFF.data |
706 | pop esi ecx |
715 | pop esi ecx |
707 | mov [esi + descriptor.buffer], eax |
716 | mov [esi + descriptor.buffer], eax |
708 | 717 | ||
709 | add esi, sizeof.descriptor |
718 | add esi, sizeof.descriptor |
710 | loop .rx_desc_loop |
719 | loop .rx_desc_loop |
711 | 720 | ||
712 | ; Mark the last entry as wrapping the ring. |
721 | ; Mark the last entry as wrapping the ring. |
713 | lea eax, [ebx + device.rx_desc] |
722 | lea eax, [ebx + device.rx_desc] |
714 | mov [esi - sizeof.descriptor + descriptor.next_desc_logical], eax |
723 | mov [esi - sizeof.descriptor + descriptor.next_desc_logical], eax |
715 | push esi |
724 | push esi |
716 | invoke GetPhysAddr |
725 | invoke GetPhysAddr |
717 | pop esi |
726 | pop esi |
718 | mov [esi - sizeof.descriptor + descriptor.next_desc], eax |
727 | mov [esi - sizeof.descriptor + descriptor.next_desc], eax |
719 | 728 | ||
720 | set_io [ebx + device.io_addr], 0 |
729 | set_io [ebx + device.io_addr], 0 |
721 | set_io [ebx + device.io_addr], RXLBA |
730 | set_io [ebx + device.io_addr], RXLBA |
722 | out dx, eax |
731 | out dx, eax |
723 | 732 | ||
724 | ; Initialize all Tx descriptors |
733 | ; Initialize all Tx descriptors |
725 | lea esi, [ebx + device.tx_desc] |
734 | lea esi, [ebx + device.tx_desc] |
726 | mov [ebx + device.cur_tx], esi |
735 | mov [ebx + device.cur_tx], esi |
727 | mov ecx, NUM_TX_DESC |
736 | mov ecx, NUM_TX_DESC |
728 | .tx_desc_loop: |
737 | .tx_desc_loop: |
729 | mov [esi + descriptor.status], 0 |
738 | mov [esi + descriptor.status], 0 |
730 | 739 | ||
731 | lea eax, [esi + sizeof.descriptor] |
740 | lea eax, [esi + sizeof.descriptor] |
732 | mov [esi + descriptor.next_desc_logical], eax |
741 | mov [esi + descriptor.next_desc_logical], eax |
733 | push ecx esi |
742 | push ecx esi |
734 | invoke GetPhysAddr |
743 | invoke GetPhysAddr |
735 | pop esi ecx |
744 | pop esi ecx |
736 | mov [esi + descriptor.next_desc], eax |
745 | mov [esi + descriptor.next_desc], eax |
737 | mov [esi + descriptor.skbuff], 0 |
746 | mov [esi + descriptor.skbuff], 0 |
738 | add esi, sizeof.descriptor |
747 | add esi, sizeof.descriptor |
739 | loop .tx_desc_loop |
748 | loop .tx_desc_loop |
740 | 749 | ||
741 | ; Mark the last entry as wrapping the ring. |
750 | ; Mark the last entry as wrapping the ring. |
742 | lea eax, [ebx + device.tx_desc] |
751 | lea eax, [ebx + device.tx_desc] |
743 | mov [esi - sizeof.descriptor + descriptor.next_desc_logical], eax |
752 | mov [esi - sizeof.descriptor + descriptor.next_desc_logical], eax |
744 | push esi |
753 | push esi |
745 | invoke GetPhysAddr |
754 | invoke GetPhysAddr |
746 | pop esi |
755 | pop esi |
747 | mov [esi - sizeof.descriptor + descriptor.next_desc], eax |
756 | mov [esi - sizeof.descriptor + descriptor.next_desc], eax |
748 | 757 | ||
749 | set_io [ebx + device.io_addr], 0 |
758 | set_io [ebx + device.io_addr], 0 |
750 | set_io [ebx + device.io_addr], TXLBA |
759 | set_io [ebx + device.io_addr], TXLBA |
751 | out dx, eax |
760 | out dx, eax |
- | 761 | ||
- | 762 | xor eax, eax |
|
- | 763 | ret |
|
- | 764 | ||
- | 765 | .out_of_mem: |
|
752 | 766 | or eax, -1 |
|
753 | ret |
767 | ret |
754 | 768 | ||
755 | 769 | ||
756 | align 4 |
770 | align 4 |
757 | set_rx_mode: |
771 | set_rx_mode: |
758 | 772 | ||
759 | DEBUGF 1,"Setting RX mode\n" |
773 | DEBUGF 1,"Setting RX mode\n" |
760 | 774 | ||
761 | ; Too many to match, or accept all multicasts. |
775 | ; Too many to match, or accept all multicasts. |
762 | set_io [ebx + device.io_addr], 0 |
776 | set_io [ebx + device.io_addr], 0 |
763 | set_io [ebx + device.io_addr], MAR0 |
777 | set_io [ebx + device.io_addr], MAR0 |
764 | xor eax, eax |
778 | xor eax, eax |
765 | not eax |
779 | not eax |
766 | out dx, eax |
780 | out dx, eax |
767 | set_io [ebx + device.io_addr], MAR1 |
781 | set_io [ebx + device.io_addr], MAR1 |
768 | out dx, eax |
782 | out dx, eax |
769 | 783 | ||
770 | and [ebx + device.crvalue], not (RxModeMask) |
784 | and [ebx + device.crvalue], not (RxModeMask) |
771 | or [ebx + device.crvalue], AcceptBroadcast + AcceptMulticast + AcceptMyPhys |
785 | or [ebx + device.crvalue], AcceptBroadcast + AcceptMulticast + AcceptMyPhys |
772 | 786 | ||
773 | ret |
787 | ret |
774 | 788 | ||
775 | 789 | ||
776 | align 4 |
790 | align 4 |
777 | getlinkstatus: |
791 | getlinkstatus: |
778 | 792 | ||
779 | DEBUGF 1,"Getting link status\n" |
793 | DEBUGF 1,"Getting link status\n" |
780 | 794 | ||
781 | mov [ebx + device.state], ETH_LINK_DOWN ; assume link is dead |
795 | mov [ebx + device.state], ETH_LINK_DOWN ; assume link is dead |
782 | 796 | ||
783 | cmp [ebx + device.PHYType], MysonPHY |
797 | cmp [ebx + device.PHYType], MysonPHY |
784 | jne .no_myson_phy |
798 | jne .no_myson_phy |
785 | set_io [ebx + device.io_addr], 0 |
799 | set_io [ebx + device.io_addr], 0 |
786 | set_io [ebx + device.io_addr], BMCRSR |
800 | set_io [ebx + device.io_addr], BMCRSR |
787 | in eax, dx |
801 | in eax, dx |
788 | test eax, LinkIsUp2 |
802 | test eax, LinkIsUp2 |
789 | jnz getlinktype |
803 | jnz getlinktype |
790 | ret |
804 | ret |
791 | 805 | ||
792 | .no_myson_phy: |
806 | .no_myson_phy: |
793 | set_io [ebx + device.io_addr], 0 |
807 | set_io [ebx + device.io_addr], 0 |
794 | set_io [ebx + device.io_addr], BMCRSR |
808 | set_io [ebx + device.io_addr], BMCRSR |
795 | in eax, dx |
809 | in eax, dx |
796 | test eax, LinkIsUp |
810 | test eax, LinkIsUp |
797 | jnz getlinktype |
811 | jnz getlinktype |
798 | ret |
812 | ret |
799 | 813 | ||
800 | getlinktype: |
814 | getlinktype: |
801 | 815 | ||
802 | DEBUGF 1,"Getting link type\n" |
816 | DEBUGF 1,"Getting link type\n" |
803 | cmp [ebx + device.PHYType], MysonPHY |
817 | cmp [ebx + device.PHYType], MysonPHY |
804 | jne .no_myson_phy |
818 | jne .no_myson_phy |
805 | 819 | ||
806 | DEBUGF 1,"myson PHY\n" |
820 | DEBUGF 1,"myson PHY\n" |
807 | set_io [ebx + device.io_addr], 0 |
821 | set_io [ebx + device.io_addr], 0 |
808 | set_io [ebx + device.io_addr], TCRRCR |
822 | set_io [ebx + device.io_addr], TCRRCR |
809 | in eax, dx |
823 | in eax, dx |
810 | test eax, FD |
824 | test eax, FD |
811 | jz @f |
825 | jz @f |
812 | DEBUGF 1,"full duplex\n" |
826 | DEBUGF 1,"full duplex\n" |
813 | or [ebx + device.state], ETH_LINK_FD |
827 | or [ebx + device.state], ETH_LINK_FD |
814 | @@: |
828 | @@: |
815 | test eax, PS10 |
829 | test eax, PS10 |
816 | jnz @f |
830 | jnz @f |
817 | DEBUGF 1,"100mbit\n" |
831 | DEBUGF 1,"100mbit\n" |
818 | or [ebx + device.state], ETH_LINK_100M |
832 | or [ebx + device.state], ETH_LINK_100M |
819 | ret |
833 | ret |
820 | @@: |
834 | @@: |
821 | DEBUGF 1,"10mbit\n" |
835 | DEBUGF 1,"10mbit\n" |
822 | or [ebx + device.state], ETH_LINK_10M |
836 | or [ebx + device.state], ETH_LINK_10M |
823 | ret |
837 | ret |
824 | 838 | ||
825 | .no_myson_phy: |
839 | .no_myson_phy: |
826 | DEBUGF 1,"not a myson PHY\n" |
840 | DEBUGF 1,"not a myson PHY\n" |
827 | mov [ebx + device.state], ETH_LINK_UNKNOWN |
841 | mov [ebx + device.state], ETH_LINK_UNKNOWN |
828 | 842 | ||
829 | ; if (mtdx.PHYType equ= SeeqPHY) { /* this PHY is SEEQ 80225 */ |
843 | ; if (mtdx.PHYType equ= SeeqPHY) { /* this PHY is SEEQ 80225 */ |
830 | ; unsigned int data; |
844 | ; unsigned int data; |
831 | ; |
845 | ; |
832 | ; data = mdio_read(dev, mtdx.phys[0], MIIRegister18); |
846 | ; data = mdio_read(dev, mtdx.phys[0], MIIRegister18); |
833 | ; if (data & SPD_DET_100) |
847 | ; if (data & SPD_DET_100) |
834 | ; mtdx.line_speed = 2; /* 100M */ |
848 | ; mtdx.line_speed = 2; /* 100M */ |
835 | ; else |
849 | ; else |
836 | ; mtdx.line_speed = 1; /* 10M */ |
850 | ; mtdx.line_speed = 1; /* 10M */ |
837 | ; if (data & DPLX_DET_FULL) |
851 | ; if (data & DPLX_DET_FULL) |
838 | ; mtdx.duplexmode = 2; /* full duplex mode */ |
852 | ; mtdx.duplexmode = 2; /* full duplex mode */ |
839 | ; else |
853 | ; else |
840 | ; mtdx.duplexmode = 1; /* half duplex mode */ |
854 | ; mtdx.duplexmode = 1; /* half duplex mode */ |
841 | ; } else if (mtdx.PHYType equ= AhdocPHY) { |
855 | ; } else if (mtdx.PHYType equ= AhdocPHY) { |
842 | ; unsigned int data; |
856 | ; unsigned int data; |
843 | ; |
857 | ; |
844 | ; data = mdio_read(dev, mtdx.phys[0], DiagnosticReg); |
858 | ; data = mdio_read(dev, mtdx.phys[0], DiagnosticReg); |
845 | ; if (data & Speed_100) |
859 | ; if (data & Speed_100) |
846 | ; mtdx.line_speed = 2; /* 100M */ |
860 | ; mtdx.line_speed = 2; /* 100M */ |
847 | ; else |
861 | ; else |
848 | ; mtdx.line_speed = 1; /* 10M */ |
862 | ; mtdx.line_speed = 1; /* 10M */ |
849 | ; if (data & DPLX_FULL) |
863 | ; if (data & DPLX_FULL) |
850 | ; mtdx.duplexmode = 2; /* full duplex mode */ |
864 | ; mtdx.duplexmode = 2; /* full duplex mode */ |
851 | ; else |
865 | ; else |
852 | ; mtdx.duplexmode = 1; /* half duplex mode */ |
866 | ; mtdx.duplexmode = 1; /* half duplex mode */ |
853 | ; } |
867 | ; } |
854 | ; else if (mtdx.PHYType equ= MarvellPHY) { |
868 | ; else if (mtdx.PHYType equ= MarvellPHY) { |
855 | ; unsigned int data; |
869 | ; unsigned int data; |
856 | ; |
870 | ; |
857 | ; data = mdio_read(dev, mtdx.phys[0], SpecificReg); |
871 | ; data = mdio_read(dev, mtdx.phys[0], SpecificReg); |
858 | ; if (data & Full_Duplex) |
872 | ; if (data & Full_Duplex) |
859 | ; mtdx.duplexmode = 2; /* full duplex mode */ |
873 | ; mtdx.duplexmode = 2; /* full duplex mode */ |
860 | ; else |
874 | ; else |
861 | ; mtdx.duplexmode = 1; /* half duplex mode */ |
875 | ; mtdx.duplexmode = 1; /* half duplex mode */ |
862 | ; data &= SpeedMask; |
876 | ; data &= SpeedMask; |
863 | ; if (data equ= Speed_1000M) |
877 | ; if (data equ= Speed_1000M) |
864 | ; mtdx.line_speed = 3; /* 1000M */ |
878 | ; mtdx.line_speed = 3; /* 1000M */ |
865 | ; else if (data equ= Speed_100M) |
879 | ; else if (data equ= Speed_100M) |
866 | ; mtdx.line_speed = 2; /* 100M */ |
880 | ; mtdx.line_speed = 2; /* 100M */ |
867 | ; else |
881 | ; else |
868 | ; mtdx.line_speed = 1; /* 10M */ |
882 | ; mtdx.line_speed = 1; /* 10M */ |
869 | ; } |
883 | ; } |
870 | ; else if (mtdx.PHYType equ= Myson981) { |
884 | ; else if (mtdx.PHYType equ= Myson981) { |
871 | ; unsigned int data; |
885 | ; unsigned int data; |
872 | ; |
886 | ; |
873 | ; data = mdio_read(dev, mtdx.phys[0], StatusRegister); |
887 | ; data = mdio_read(dev, mtdx.phys[0], StatusRegister); |
874 | ; |
888 | ; |
875 | ; if (data & SPEED100) |
889 | ; if (data & SPEED100) |
876 | ; mtdx.line_speed = 2; |
890 | ; mtdx.line_speed = 2; |
877 | ; else |
891 | ; else |
878 | ; mtdx.line_speed = 1; |
892 | ; mtdx.line_speed = 1; |
879 | ; |
893 | ; |
880 | ; if (data & FULLMODE) |
894 | ; if (data & FULLMODE) |
881 | ; mtdx.duplexmode = 2; |
895 | ; mtdx.duplexmode = 2; |
882 | ; else |
896 | ; else |
883 | ; mtdx.duplexmode = 1; |
897 | ; mtdx.duplexmode = 1; |
884 | ; } |
898 | ; } |
885 | ; else if (mtdx.PHYType equ= LevelOnePHY) { |
899 | ; else if (mtdx.PHYType equ= LevelOnePHY) { |
886 | ; unsigned int data; |
900 | ; unsigned int data; |
887 | ; |
901 | ; |
888 | ; data = mdio_read(dev, mtdx.phys[0], SpecificReg); |
902 | ; data = mdio_read(dev, mtdx.phys[0], SpecificReg); |
889 | ; if (data & LXT1000_Full) |
903 | ; if (data & LXT1000_Full) |
890 | ; mtdx.duplexmode = 2; /* full duplex mode */ |
904 | ; mtdx.duplexmode = 2; /* full duplex mode */ |
891 | ; else |
905 | ; else |
892 | ; mtdx.duplexmode = 1; /* half duplex mode */ |
906 | ; mtdx.duplexmode = 1; /* half duplex mode */ |
893 | ; data &= SpeedMask; |
907 | ; data &= SpeedMask; |
894 | ; if (data equ= LXT1000_1000M) |
908 | ; if (data equ= LXT1000_1000M) |
895 | ; mtdx.line_speed = 3; /* 1000M */ |
909 | ; mtdx.line_speed = 3; /* 1000M */ |
896 | ; else if (data equ= LXT1000_100M) |
910 | ; else if (data equ= LXT1000_100M) |
897 | ; mtdx.line_speed = 2; /* 100M */ |
911 | ; mtdx.line_speed = 2; /* 100M */ |
898 | ; else |
912 | ; else |
899 | ; mtdx.line_speed = 1; /* 10M */ |
913 | ; mtdx.line_speed = 1; /* 10M */ |
900 | ; } |
914 | ; } |
901 | 915 | ||
902 | ; // chage crvalue |
916 | ; // chage crvalue |
903 | ; // mtdx.crvalue&equ(~PS10)&(~FD); |
917 | ; // mtdx.crvalue&equ(~PS10)&(~FD); |
904 | ; mtdx.crvalue &= (~PS10) & (~FD) & (~PS1000); |
918 | ; mtdx.crvalue &= (~PS10) & (~FD) & (~PS1000); |
905 | ; if (mtdx.line_speed equ= 1) |
919 | ; if (mtdx.line_speed equ= 1) |
906 | ; mtdx.crvalue |= PS10; |
920 | ; mtdx.crvalue |= PS10; |
907 | ; else if (mtdx.line_speed equ= 3) |
921 | ; else if (mtdx.line_speed equ= 3) |
908 | ; mtdx.crvalue |= PS1000; |
922 | ; mtdx.crvalue |= PS1000; |
909 | ; if (mtdx.duplexmode equ= 2) |
923 | ; if (mtdx.duplexmode equ= 2) |
910 | ; mtdx.crvalue |= FD; |
924 | ; mtdx.crvalue |= FD; |
911 | 925 | ||
912 | ret |
926 | ret |
913 | 927 | ||
914 | 928 | ||
915 | 929 | ||
916 | 930 | ||
917 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
931 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
918 | ;; ;; |
932 | ;; ;; |
919 | ;; Transmit ;; |
933 | ;; Transmit ;; |
920 | ;; ;; |
934 | ;; ;; |
921 | ;; In: buffer pointer in [esp+4] ;; |
935 | ;; In: buffer pointer in [esp+4] ;; |
922 | ;; size of buffer in [esp+8] ;; |
936 | ;; size of buffer in [esp+8] ;; |
923 | ;; pointer to device structure in ebx ;; |
937 | ;; pointer to device structure in ebx ;; |
924 | ;; ;; |
938 | ;; ;; |
925 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
939 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
926 | 940 | ||
927 | proc transmit stdcall bufferptr, buffersize |
941 | proc transmit stdcall bufferptr |
928 | 942 | ||
929 | pushf |
943 | pushf |
930 | cli |
944 | cli |
- | 945 | ||
931 | 946 | mov esi, [bufferptr] |
|
932 | DEBUGF 1,"Transmitting packet, buffer:%x, size:%u\n", [bufferptr], [buffersize] |
947 | DEBUGF 1,"Transmitting packet, buffer:%x, size:%u\n", [bufferptr], [esi + NET_BUFF.length] |
933 | mov eax, [bufferptr] |
948 | lea eax, [esi + NET_BUFF.data] |
934 | DEBUGF 1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\ |
949 | DEBUGF 1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\ |
935 | [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\ |
950 | [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\ |
936 | [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\ |
951 | [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\ |
937 | [eax+13]:2,[eax+12]:2 |
952 | [eax+13]:2,[eax+12]:2 |
938 | 953 | ||
939 | cmp [buffersize], 1514 |
954 | cmp [esi + NET_BUFF.length], 1514 |
940 | ja .fail |
955 | ja .fail |
941 | cmp [buffersize], 60 |
956 | cmp [esi + NET_BUFF.length], 60 |
942 | jb .fail |
957 | jb .fail |
943 | 958 | ||
944 | mov esi, [ebx + device.cur_tx] |
959 | mov esi, [ebx + device.cur_tx] |
945 | - | ||
946 | test [esi + descriptor.status], TXOWN |
960 | test [esi + descriptor.status], TXOWN |
947 | jnz .fail |
961 | jnz .fail |
948 | 962 | ||
949 | push [esi + descriptor.next_desc_logical] |
963 | push [esi + descriptor.next_desc_logical] |
950 | pop [ebx + device.cur_tx] |
964 | pop [ebx + device.cur_tx] |
951 | 965 | ||
952 | mov eax, [bufferptr] |
966 | mov eax, [bufferptr] |
953 | mov [esi + descriptor.skbuff], eax |
967 | mov [esi + descriptor.skbuff], eax |
- | 968 | add eax, [eax + NET_BUFF.offset] |
|
954 | invoke GetPhysAddr |
969 | invoke GetPhysAddr |
955 | mov [esi + descriptor.buffer], eax |
970 | mov [esi + descriptor.buffer], eax |
956 | 971 | ||
- | 972 | mov eax, [bufferptr] |
|
957 | mov eax, [buffersize] |
973 | mov eax, [eax + NET_BUFF.length] |
958 | mov ecx, eax |
974 | mov ecx, eax |
959 | shl eax, PKTSShift ; packet size |
975 | shl eax, PKTSShift ; packet size |
960 | shl ecx, TBSShift |
976 | shl ecx, TBSShift |
961 | or eax, ecx |
977 | or eax, ecx |
962 | or eax, TXIC + TXLD + TXFD + CRCEnable + PADEnable |
978 | or eax, TXIC + TXLD + TXFD + CRCEnable + PADEnable |
963 | mov [esi + descriptor.control], eax |
979 | mov [esi + descriptor.control], eax |
964 | mov [esi + descriptor.status], TXOWN |
980 | mov [esi + descriptor.status], TXOWN |
965 | 981 | ||
966 | ; Update stats |
982 | ; Update stats |
967 | inc [ebx + device.packets_tx] |
983 | inc [ebx + device.packets_tx] |
968 | mov eax, [buffersize] |
984 | mov eax, [bufferptr] |
- | 985 | mov ecx, [eax + NET_BUFF.length] |
|
969 | add dword[ebx + device.bytes_tx], eax |
986 | add dword[ebx + device.bytes_tx], ecx |
970 | adc dword[ebx + device.bytes_tx + 4], 0 |
987 | adc dword[ebx + device.bytes_tx + 4], 0 |
971 | 988 | ||
972 | ; TX Poll |
989 | ; TX Poll |
973 | set_io [ebx + device.io_addr], 0 |
990 | set_io [ebx + device.io_addr], 0 |
974 | set_io [ebx + device.io_addr], TXPDR |
991 | set_io [ebx + device.io_addr], TXPDR |
975 | xor eax, eax |
992 | xor eax, eax |
976 | out dx, eax |
993 | out dx, eax |
977 | 994 | ||
978 | DEBUGF 1,"Transmit OK\n" |
995 | DEBUGF 1,"Transmit OK\n" |
979 | popf |
996 | popf |
980 | xor eax, eax |
997 | xor eax, eax |
981 | ret |
998 | ret |
982 | 999 | ||
983 | .fail: |
1000 | .fail: |
984 | DEBUGF 2,"Transmit failed\n" |
1001 | DEBUGF 2,"Transmit failed\n" |
985 | invoke KernelFree, [bufferptr] |
1002 | invoke NetFree, [bufferptr] |
986 | popf |
1003 | popf |
987 | or eax, -1 |
1004 | or eax, -1 |
988 | ret |
1005 | ret |
989 | 1006 | ||
990 | endp |
1007 | endp |
991 | 1008 | ||
992 | 1009 | ||
993 | 1010 | ||
994 | align 4 |
1011 | align 4 |
995 | read_mac: |
1012 | read_mac: |
996 | 1013 | ||
997 | set_io [ebx + device.io_addr], 0 |
1014 | set_io [ebx + device.io_addr], 0 |
998 | set_io [ebx + device.io_addr], PAR0 |
1015 | set_io [ebx + device.io_addr], PAR0 |
999 | lea edi, [ebx + device.mac] |
1016 | lea edi, [ebx + device.mac] |
1000 | insd |
1017 | insd |
1001 | set_io [ebx + device.io_addr], PAR1 |
1018 | set_io [ebx + device.io_addr], PAR1 |
1002 | insw |
1019 | insw |
1003 | DEBUGF 1,"MAC = %x-%x-%x-%x-%x-%x\n",\ |
1020 | DEBUGF 1,"MAC = %x-%x-%x-%x-%x-%x\n",\ |
1004 | [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 |
1021 | [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 |
1005 | 1022 | ||
1006 | ret |
1023 | ret |
1007 | 1024 | ||
1008 | align 4 |
1025 | align 4 |
1009 | write_mac: |
1026 | write_mac: |
1010 | 1027 | ||
1011 | ret |
1028 | ret |
1012 | 1029 | ||
1013 | 1030 | ||
1014 | 1031 | ||
1015 | ;;;;;;;;;;;;;;;;;;;;;;; |
1032 | ;;;;;;;;;;;;;;;;;;;;;;; |
1016 | ;; ;; |
1033 | ;; ;; |
1017 | ;; Interrupt handler ;; |
1034 | ;; Interrupt handler ;; |
1018 | ;; ;; |
1035 | ;; ;; |
1019 | ;;;;;;;;;;;;;;;;;;;;;;; |
1036 | ;;;;;;;;;;;;;;;;;;;;;;; |
1020 | 1037 | ||
1021 | align 4 |
1038 | align 4 |
1022 | int_handler: |
1039 | int_handler: |
1023 | 1040 | ||
1024 | push ebx esi edi |
1041 | push ebx esi edi |
1025 | 1042 | ||
1026 | DEBUGF 1,"INT\n" |
1043 | DEBUGF 1,"INT\n" |
1027 | 1044 | ||
1028 | ; find pointer of device wich made IRQ occur |
1045 | ; find pointer of device wich made IRQ occur |
1029 | 1046 | ||
1030 | mov ecx, [devices] |
1047 | mov ecx, [devices] |
1031 | test ecx, ecx |
1048 | test ecx, ecx |
1032 | jz .nothing |
1049 | jz .nothing |
1033 | mov esi, device_list |
1050 | mov esi, device_list |
1034 | .nextdevice: |
1051 | .nextdevice: |
1035 | mov ebx, [esi] |
1052 | mov ebx, [esi] |
1036 | 1053 | ||
1037 | set_io [ebx + device.io_addr], 0 |
1054 | set_io [ebx + device.io_addr], 0 |
1038 | set_io [ebx + device.io_addr], ISR |
1055 | set_io [ebx + device.io_addr], ISR |
1039 | in eax, dx |
1056 | in eax, dx |
1040 | out dx, eax ; send it back to ACK |
1057 | out dx, eax ; send it back to ACK |
1041 | test eax, eax |
1058 | test eax, eax |
1042 | jnz .got_it |
1059 | jnz .got_it |
1043 | .continue: |
1060 | .continue: |
1044 | add esi, 4 |
1061 | add esi, 4 |
1045 | dec ecx |
1062 | dec ecx |
1046 | jnz .nextdevice |
1063 | jnz .nextdevice |
1047 | .nothing: |
1064 | .nothing: |
1048 | pop edi esi ebx |
1065 | pop edi esi ebx |
1049 | xor eax, eax |
1066 | xor eax, eax |
1050 | 1067 | ||
1051 | ret ; If no device was found, abort (The irq was probably for a device, not registered to this driver) |
1068 | ret ; If no device was found, abort (The irq was probably for a device, not registered to this driver) |
1052 | 1069 | ||
1053 | .got_it: |
1070 | .got_it: |
1054 | 1071 | ||
1055 | DEBUGF 1,"Device: %x Status: %x\n", ebx, ax |
1072 | DEBUGF 1,"Device: %x Status: %x\n", ebx, ax |
1056 | 1073 | ||
1057 | test ax, RI ; receive interrupt |
1074 | test ax, RI ; receive interrupt |
1058 | jz .no_rx |
1075 | jz .no_rx |
1059 | push ax |
1076 | push ax |
1060 | .rx_loop: |
1077 | .rx_loop: |
1061 | mov esi, [ebx + device.cur_rx] |
1078 | mov esi, [ebx + device.cur_rx] |
1062 | test [esi + descriptor.status], RXOWN |
1079 | test [esi + descriptor.status], RXOWN |
1063 | jnz .rx_done |
1080 | jnz .rx_done |
1064 | 1081 | ||
1065 | push ebx |
1082 | push ebx |
1066 | push .rx_complete |
1083 | push .rx_complete |
1067 | 1084 | ||
1068 | mov ecx, [esi + descriptor.status] |
1085 | mov ecx, [esi + descriptor.status] |
1069 | shr ecx, FLNGShift |
1086 | shr ecx, FLNGShift |
1070 | sub ecx, 4 ; we dont need CRC |
1087 | sub ecx, 4 ; we dont need CRC |
1071 | push ecx |
- | |
1072 | DEBUGF 1,"Received %u bytes\n", ecx |
1088 | DEBUGF 1,"Received %u bytes\n", ecx |
- | 1089 | mov eax, [esi + descriptor.skbuff] |
|
- | 1090 | push eax |
|
- | 1091 | mov [eax + NET_BUFF.length], ecx |
|
- | 1092 | mov [eax + NET_BUFF.device], ebx |
|
- | 1093 | mov [eax + NET_BUFF.offset], NET_BUFF.data |
|
1073 | 1094 | ||
1074 | ; Update stats |
1095 | ; Update stats |
1075 | add dword[ebx + device.bytes_rx], ecx |
1096 | add dword[ebx + device.bytes_rx], ecx |
1076 | adc dword[ebx + device.bytes_rx + 4], 0 |
1097 | adc dword[ebx + device.bytes_rx + 4], 0 |
1077 | inc [ebx + device.packets_rx] |
1098 | inc [ebx + device.packets_rx] |
1078 | - | ||
1079 | push [esi + descriptor.skbuff] |
1099 | |
1080 | jmp [Eth_input] |
1100 | jmp [EthInput] |
1081 | 1101 | ||
1082 | .rx_complete: |
1102 | .rx_complete: |
1083 | pop ebx |
1103 | pop ebx |
1084 | mov esi, [ebx + device.cur_rx] |
1104 | mov esi, [ebx + device.cur_rx] |
1085 | mov [esi + descriptor.control], 1536 shl RBSShift |
1105 | mov [esi + descriptor.control], 1514 shl RBSShift |
1086 | push esi |
1106 | push esi |
1087 | invoke KernelAlloc, 1536 |
1107 | invoke NetAlloc, 1514+NET_BUFF.data |
1088 | pop esi |
1108 | pop esi |
- | 1109 | ; test eax, eax |
|
- | 1110 | ; jz .rx_loop |
|
1089 | mov [esi + descriptor.skbuff], eax |
1111 | mov [esi + descriptor.skbuff], eax |
1090 | invoke GetPgAddr |
1112 | invoke GetPhysAddr |
- | 1113 | add eax, NET_BUFF.data |
|
1091 | mov [esi + descriptor.buffer], eax |
1114 | mov [esi + descriptor.buffer], eax |
1092 | mov [esi + descriptor.status], RXOWN |
1115 | mov [esi + descriptor.status], RXOWN |
1093 | 1116 | ||
1094 | push [esi + descriptor.next_desc_logical] |
1117 | push [esi + descriptor.next_desc_logical] |
1095 | pop [ebx + device.cur_rx] |
1118 | pop [ebx + device.cur_rx] |
1096 | 1119 | ||
1097 | jmp .rx_loop |
1120 | jmp .rx_loop |
1098 | 1121 | ||
1099 | .rx_done: |
1122 | .rx_done: |
1100 | DEBUGF 1,"RX done\n" |
1123 | DEBUGF 1,"RX done\n" |
1101 | 1124 | ||
1102 | ; Restart Rx engine if stopped. |
1125 | ; Restart Rx engine if stopped. |
1103 | set_io [ebx + device.io_addr], 0 |
1126 | set_io [ebx + device.io_addr], 0 |
1104 | set_io [ebx + device.io_addr], RXPDR |
1127 | set_io [ebx + device.io_addr], RXPDR |
1105 | xor eax, eax |
1128 | xor eax, eax |
1106 | out dx, eax |
1129 | out dx, eax |
1107 | 1130 | ||
1108 | pop ax |
1131 | pop ax |
1109 | .no_rx: |
1132 | .no_rx: |
1110 | 1133 | ||
1111 | test ax, TI ; transmit interrupt |
1134 | test ax, TI ; transmit interrupt |
1112 | jz .no_tx |
1135 | jz .no_tx |
1113 | DEBUGF 1,"TX\n" |
1136 | DEBUGF 1,"TX\n" |
1114 | push ax |
1137 | push ax |
1115 | lea esi, [ebx + device.tx_desc] |
1138 | lea esi, [ebx + device.tx_desc] |
1116 | mov ecx, NUM_TX_DESC |
1139 | mov ecx, NUM_TX_DESC |
1117 | .tx_loop: |
1140 | .tx_loop: |
1118 | test [esi + descriptor.status], TXOWN |
1141 | test [esi + descriptor.status], TXOWN |
1119 | jnz .skip_this_one |
1142 | jnz .skip_this_one |
1120 | mov eax, [esi + descriptor.skbuff] |
1143 | mov eax, [esi + descriptor.skbuff] |
1121 | test eax, eax |
1144 | test eax, eax |
1122 | je .skip_this_one |
1145 | je .skip_this_one |
1123 | mov [esi + descriptor.skbuff], 0 |
1146 | mov [esi + descriptor.skbuff], 0 |
1124 | DEBUGF 1,"freeing buffer: 0x%x\n", eax |
1147 | DEBUGF 1,"freeing buffer: 0x%x\n", eax |
1125 | invoke KernelFree, eax |
1148 | invoke NetFree, eax |
1126 | .skip_this_one: |
1149 | .skip_this_one: |
1127 | mov esi, [esi + descriptor.next_desc_logical] |
1150 | mov esi, [esi + descriptor.next_desc_logical] |
1128 | loop .tx_loop |
1151 | loop .tx_loop |
1129 | pop ax |
1152 | pop ax |
1130 | .no_tx: |
1153 | .no_tx: |
1131 | 1154 | ||
1132 | test ax, LSCStatus |
1155 | test ax, LSCStatus |
1133 | jz .no_link_change |
1156 | jz .no_link_change |
1134 | push ax |
1157 | push ax |
1135 | call getlinkstatus |
1158 | call getlinkstatus |
1136 | pop ax |
1159 | pop ax |
1137 | .no_link_change: |
1160 | .no_link_change: |
1138 | 1161 | ||
1139 | ; test ax, TBU |
1162 | ; test ax, TBU |
1140 | ; jz .no_tbu |
1163 | ; jz .no_tbu |
1141 | ; DEBUGF 2,"Transmit buffer unavailable!\n" |
1164 | ; DEBUGF 2,"Transmit buffer unavailable!\n" |
1142 | ; .no_tbu: |
1165 | ; .no_tbu: |
1143 | 1166 | ||
1144 | .fail: |
1167 | .fail: |
1145 | pop edi esi ebx |
1168 | pop edi esi ebx |
1146 | xor eax, eax |
1169 | xor eax, eax |
1147 | inc eax |
1170 | inc eax |
1148 | 1171 | ||
1149 | ret |
1172 | ret |
1150 | 1173 | ||
1151 | 1174 | ||
1152 | ; End of code |
1175 | ; End of code |
1153 | 1176 | ||
1154 | 1177 | ||
1155 | data fixups |
1178 | data fixups |
1156 | end data |
1179 | end data |
1157 | 1180 | ||
1158 | include '../peimport.inc' |
1181 | include '../peimport.inc' |
1159 | 1182 | ||
1160 | my_service db 'MTD80X',0 ; max 16 chars include zero |
1183 | my_service db 'MTD80X',0 ; max 16 chars include zero |
1161 | 1184 | ||
1162 | sz_mtd800 db "Myson MTD800", 0 |
1185 | sz_mtd800 db "Myson MTD800", 0 |
1163 | sz_mtd803 db "Surecom EP-320X", 0 |
1186 | sz_mtd803 db "Surecom EP-320X", 0 |
1164 | sz_mtd891 db "Myson MTD891", 0 |
1187 | sz_mtd891 db "Myson MTD891", 0 |
1165 | 1188 | ||
1166 | 1189 | ||
1167 | include_debug_strings ; All data wich FDO uses will be included here |
1190 | include_debug_strings ; All data wich FDO uses will be included here |
1168 | 1191 | ||
1169 | align 4 |
1192 | align 4 |
1170 | devices dd 0 |
1193 | devices dd 0 |
1171 | device_list rd MAX_DEVICES ; This list contains all pointers to device structures the driver is handling>> |
1194 | device_list rd MAX_DEVICES ; This list contains all pointers to device structures the driver is handling>> |