Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
425 victor 1
$Revision: 523 $
1 ha 2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3
;;                                                                 ;;
431 serge 4
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved.    ;;
5
;; Distributed under terms of the GNU General Public License       ;;
6
;;                                                                 ;;
1 ha 7
;;  ETHERNET.INC                                                   ;;
8
;;                                                                 ;;
9
;;  Ethernet network layer for Menuet OS                           ;;
10
;;                                                                 ;;
11
;;  Version 0.4  22 September 2003                                 ;;
12
;;                                                                 ;;
13
;;  This file contains the following:                              ;;
14
;;      PCI bus scanning for valid devices                         ;;
15
;;      Table of supported ethernet drivers                        ;;
16
;;      Code to identify and activate a supported driver           ;;
17
;;      ARP handler                                                ;;
18
;;      Driver interface to the IP layer                           ;;
19
;;      Gateway support                                            ;;
20
;;                                                                 ;;
21
;;  Individual driver files are included here                      ;;
22
;;                                                                 ;;
23
;;  The PCI bus scanning code was ported from the etherboot        ;;
24
;;  5.0.6 project. The copyright statement for that code is        ;;
25
;;                                                                 ;;
26
;;          GNU GENERAL PUBLIC LICENSE                             ;;
27
;;             Version 2, June 1991                                ;;
28
;;                                                                 ;;
29
;;  remaining parts Copyright 2002 Mike Hibbett                    ;;
30
;;   mikeh@oceanfree.net                                           ;;
31
;;                                                                 ;;
32
;;  See file COPYING for details                                   ;;
33
;;                                                                 ;;
34
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
35
 
36
;********************************************************************
37
;   Interface
38
;      ethernet_driver   called by stack_handler in stack.inc
39
;      eth_probe         called by app_stack_handler in stack.inc
40
;
41
;********************************************************************
42
 
302 hidnplayr 43
ETHER_IP		    equ     0x0008	; Reversed from 0800 for intel
44
ETHER_ARP		    equ     0x0608	; Reversed from 0806 for intel
45
ETHER_RARP		    equ     0x3580
261 hidnplayr 46
 
47
struc ETH_FRAME
302 hidnplayr 48
{  .DstMAC	 dp   ?  ;destination MAC-address [6 bytes]
49
   .SrcMAC	 dp   ?  ;source MAC-address [6 bytes]
50
   .Type	 dw   ?  ;type of the upper-layer protocol [2 bytes]
51
   .Data	 db   ?  ;data [46-1500 bytes]
261 hidnplayr 52
}
53
 
54
virtual at Ether_buffer
55
  ETH_FRAME ETH_FRAME
56
end virtual
57
 
58
 
1 ha 59
; Some useful information on data structures
60
 
61
;     Ethernet Packet - ARP Request example
62
;
63
;   0                   1                   2                   3
64
;   0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
65
;
66
;   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
67
;   |       Dest   H/W Address                                      |
68
;   |                    ( 14 byte header )                         |
69
;   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
70
;   |                               |     Source     H/W Address    |
71
;   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
72
;   |                                                               |
73
;   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
74
;   |    Protocol - ARP 08  06      |
75
;   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
76
 
77
;   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
78
;   |  H/W Type  00           01    |  Protocol Type   08 00        |
79
;   |                   ( ARP Request packet )                      |
80
;   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
81
;   | HLen    0x06  | PLen    0x04  |    OpCode        00   01      |
82
;   |               ( 0001 for request, 0002 for reply )            |
83
;   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
84
;   | Source Hardware Address ( MAC Address )                       |
85
;   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
86
;   |                               |  Source IP Address            |
87
;   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
88
;   |                               | Destination Hardware Address  |
89
;   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
90
;   |                                                               |
91
;   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
92
;   | Destination IP Address                                        |
93
;   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
94
 
95
; Include individual drivers source files at this point.
96
; If you create a new driver, include it below.
97
 
261 hidnplayr 98
include "drivers/rtl8029.inc"
99
include "drivers/i8255x.inc"
100
include "drivers/rtl8139.inc"
101
include "drivers/3c59x.inc"
102
include "drivers/sis900.inc"
103
include "drivers/pcnet32.inc"
373 mikedld 104
include "drivers/rtl8169.inc"
1 ha 105
 
106
; PCICards
107
; ========
108
; PCI vendor and hardware types for hardware supported by the above drivers
109
; If you add a driver, ensure you update this datastructure, otherwise the
110
; card will not be probed.
111
; Each driver is defined by 4 double words. These are
112
;   PCIVendorDevice  probeFunction ResetFunction PollFunction transmitFunction
113
; The last entry must be kept at all zeros, to indicate the end of the list
114
; As a PCI driver may support more than one hardware implementation, there may
115
; be several lines which refer to the same functions.
116
; The first driver found on the PCI bus will be the one used.
117
 
302 hidnplayr 118
PCICARDS_ENTRY_SIZE	    equ     24	  ; Size of each PCICARDS entry
1 ha 119
 
120
iglobal
121
PCICards:
302 hidnplayr 122
dd  0x12098086, I8255x_probe, I8255x_reset, I8255x_poll, I8255x_transmit, 0
123
dd  0x10298086, I8255x_probe, I8255x_reset, I8255x_poll, I8255x_transmit, 0
124
dd  0x12298086, I8255x_probe, I8255x_reset, I8255x_poll, I8255x_transmit, 0
125
dd  0x10308086, I8255x_probe, I8255x_reset, I8255x_poll, I8255x_transmit, 0
126
dd  0x24498086, I8255x_probe, I8255x_reset, I8255x_poll, I8255x_transmit, 0
505 hidnplayr 127
 
302 hidnplayr 128
dd  0x802910ec, rtl8029_probe, rtl8029_reset, rtl8029_poll, rtl8029_transmit, 0
129
 
505 hidnplayr 130
dd  0x813910ec, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable  ; tested by hidnplayr: works ok
302 hidnplayr 131
dd  0x813810ec, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable
505 hidnplayr 132
dd  0x12111113, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable  ; tested by hidnplayr: works ok
302 hidnplayr 133
dd  0x13601500, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable
134
dd  0x13604033, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable
135
dd  0x13001186, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable
136
dd  0x13401186, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable
137
dd  0xab0613d1, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable
138
dd  0xa1171259, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable
139
dd  0xa11e1259, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable
140
dd  0xab0614ea, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable
141
dd  0xab0714ea, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable
142
dd  0x123411db, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable
143
dd  0x91301432, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable
144
dd  0x101202ac, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable
145
dd  0x0106018a, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable
146
dd  0x1211126c, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable
147
dd  0x81391743, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable
148
dd  0x8139021b, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable
149
 
373 mikedld 150
dd  0x816810ec, rtl8169_probe, rtl8169_reset, rtl8169_poll, rtl8169_transmit, 0
151
dd  0x816910ec, rtl8169_probe, rtl8169_reset, rtl8169_poll, rtl8169_transmit, 0
152
dd  0x011616ec, rtl8169_probe, rtl8169_reset, rtl8169_poll, rtl8169_transmit, 0
153
dd  0x43001186, rtl8169_probe, rtl8169_reset, rtl8169_poll, rtl8169_transmit, 0
154
 
302 hidnplayr 155
dd  0x590010b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
156
dd  0x592010b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
157
dd  0x597010b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
158
dd  0x595010b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
159
dd  0x595110b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
160
dd  0x595210b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
161
dd  0x900010b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
162
dd  0x900110b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
523 diamond 163
dd  0x900410b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
302 hidnplayr 164
dd  0x900510b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
165
dd  0x900610b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
166
dd  0x900A10b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
167
dd  0x905010b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
168
dd  0x905110b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
169
dd  0x905510b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
170
dd  0x905810b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
171
dd  0x905A10b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
172
dd  0x920010b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
173
dd  0x980010b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
174
dd  0x980510b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
175
dd  0x764610b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
176
dd  0x505510b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
177
dd  0x605510b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
178
dd  0x605610b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
179
dd  0x5b5710b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
180
dd  0x505710b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
181
dd  0x515710b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
182
dd  0x525710b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
183
dd  0x656010b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
184
dd  0x656210b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
185
dd  0x656410b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
186
dd  0x450010b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
187
 
188
dd  0x09001039, SIS900_probe, SIS900_reset, SIS900_poll, SIS900_transmit, 0
189
 
190
dd  0x20001022, pcnet32_probe, pcnet32_reset, pcnet32_poll, pcnet32_xmit, 0
191
dd  0x26251022, pcnet32_probe, pcnet32_reset, pcnet32_poll, pcnet32_xmit, 0
192
dd  0x20011022, pcnet32_probe, pcnet32_reset, pcnet32_poll, pcnet32_xmit, 0
323 hidnplayr 193
 
194
;dd  0x08031516, mtd80x_probe, mtd80x_reset, mtd80x_poll, mtd80x_transmit, mtd80x_cable
195
 
196
; following cards are untested
302 hidnplayr 197
dd  0x70161039, SIS900_probe, SIS900_reset, SIS900_poll, SIS900_transmit, 0
323 hidnplayr 198
;dd  0x08001516, mtd80x_probe, mtd80x_reset, mtd80x_poll, mtd80x_transmit, mtd80x_cable
199
;dd  0x08911516, mtd80x_probe, mtd80x_reset, mtd80x_poll, mtd80x_transmit, mtd80x_cable
200
 
302 hidnplayr 201
rb PCICARDS_ENTRY_SIZE	; end of list marker, do not remove
1 ha 202
endg
203
 
204
uglobal
261 hidnplayr 205
;Net-stack's interface's settings
302 hidnplayr 206
  node_addr:	      db  0,0,0,0,0,0
207
  gateway_ip:	      dd  0
208
  dns_ip:	      dd  0
261 hidnplayr 209
 
1 ha 210
  eth_rx_data_len:    dw  0
302 hidnplayr 211
  eth_status:	      dd  0
212
  io_addr:	      dd  0
213
  hdrtype:	      db  0
1 ha 214
  vendor_device:      dd  0
302 hidnplayr 215
  pci_data:	      dd  0
216
  pci_dev:	      dd  0
217
  pci_bus:	      dd  0
1 ha 218
 
219
  ; These will hold pointers to the selected driver functions
302 hidnplayr 220
  drvr_probe:	      dd  0
221
  drvr_reset:	      dd  0
222
  drvr_poll:	      dd  0
1 ha 223
  drvr_transmit:      dd  0
302 hidnplayr 224
  drvr_cable:	      dd  0
1 ha 225
 
226
endg
227
 
228
iglobal
229
  broadcast_add:      db  0xff,0xff,0xff,0xff,0xff,0xff
302 hidnplayr 230
  subnet_mask:	      dd  0x00ffffff   ; 255.255.255.0
1 ha 231
endg
232
 
261 hidnplayr 233
include "arp.inc"    ;arp-protocol functions
234
include "pci.inc"    ;PCI bus access functions
1 ha 235
 
236
 
237
;***************************************************************************
238
;   Function
239
;      eth_tx
240
;
241
;   Description
242
;      Looks at the NET1OUT_QUEUE for data to send.
243
;      Stores that destination IP in a location used by the tx routine
244
;      Looks up the MAC address in the ARP table; stores that where
245
;      the tx routine can get it
246
;      Get the length of the data. Store that where the tx routine wants it
247
;      Call tx
248
;      Places buffer on empty queue when the tx routine finished
249
;
250
;***************************************************************************
261 hidnplayr 251
proc eth_tx stdcall uses ebx esi edi
252
local MACAddress  dp  ?  ;allocate 6 bytes in the stack
253
 
1 ha 254
    ; Look for a buffer to tx
255
    mov     eax, NET1OUT_QUEUE
256
    call    dequeue
257
    cmp     ax, NO_BUFFER
302 hidnplayr 258
    je	    .exit	     ; Exit if no buffer available
1 ha 259
 
261 hidnplayr 260
    push    eax  ;save buffer number
1 ha 261
 
262
    ; convert buffer pointer eax to the absolute address
261 hidnplayr 263
    imul    eax, IPBUFFSIZE
1 ha 264
    add     eax, IPbuffs
265
 
266
    ; Extract the destination IP
267
    ; find the destination IP in the ARP table, get MAC
268
    ; store this MAC in 'MACAddress'
302 hidnplayr 269
    mov     ebx, eax		   ; Save buffer address
270
    mov     edx, [ebx + 16]	   ; get destination address
1 ha 271
 
272
    ; If the destination address is 255.255.255.255,
273
    ; set the MACAddress to all ones ( broadcast )
261 hidnplayr 274
    cld
275
    mov     esi, broadcast_add
276
    lea     edi, [MACAddress]
277
    movsd
278
    movsw
1 ha 279
    cmp     edx, 0xffffffff
302 hidnplayr 280
    je	    .send		 ; If it is broadcast, just send
1 ha 281
 
511 heavyiron 282
    ; first, check destination IP to see if it is on 'this' network.
283
    ; The test is:
284
    ; if ( destIP & subnet_mask == stack_ip & subnet_mask )
285
    ;   destination is local
286
    ; else
287
    ;  destination is remote, so pass to gateway
288
 
289
    mov     eax, edx
290
    and     eax, [subnet_mask]
291
    mov     ecx, [stack_ip]
292
    and     ecx, [subnet_mask]
293
    cmp     eax, ecx
294
    je      .local
295
 
296
    mov     edx, [gateway_ip]
297
  .local:
298
 
302 hidnplayr 299
    lea     eax, [MACAddress]	 ;cause this is local variable
261 hidnplayr 300
    stdcall arp_table_manager, ARP_TABLE_IP_TO_MAC, edx, eax ;opcode,IP,MAC_ptr - Get the MAC address.
1 ha 301
 
302
    cmp     eax, ARP_VALID_MAPPING
302 hidnplayr 303
    je	    .send
1 ha 304
 
261 hidnplayr 305
    ; No valid entry. Has the request been sent, but timed out?
1 ha 306
    cmp     eax, ARP_RESPONSE_TIMEOUT
302 hidnplayr 307
    je	    .freebuf
1 ha 308
 
302 hidnplayr 309
  .wait_response:		    ;we wait arp-response
310
				    ; Re-queue the packet, and exit
1 ha 311
    pop     ebx
312
    mov     eax, NET1OUT_QUEUE
302 hidnplayr 313
    call    queue			 ; Get the buffer back
261 hidnplayr 314
    jmp     .exit
1 ha 315
 
261 hidnplayr 316
  .send:    ;if ARP_VALID_MAPPING then send the packet
302 hidnplayr 317
    lea     edi, [MACAddress]	  ; Pointer to 48 bit destination address
318
    movzx   ecx, word[ebx+2]	  ; Size of IP packet to send
319
    xchg    ch, cl		  ; because mirror byte-order
320
    mov     esi, ebx		  ; Pointer to packet data
321
    mov     bx, ETHER_IP	  ; Type of packet
523 diamond 322
    push    ebp
261 hidnplayr 323
    call    dword [drvr_transmit] ; Call the drivers transmit function
523 diamond 324
    pop     ebp
1 ha 325
 
326
    ; OK, we have sent a packet, so increment the count
327
    inc     dword [ip_tx_count]
328
 
329
    ; And finally, return the buffer to the free queue
261 hidnplayr 330
  .freebuf:
1 ha 331
    pop     eax
332
    call    freeBuff
333
 
261 hidnplayr 334
  .exit:
1 ha 335
    ret
261 hidnplayr 336
endp
1 ha 337
 
338
;***************************************************************************
339
;   Function
340
;      ether_IP_handler
341
;
342
;   Description
343
;      Called when an IP ethernet packet is received on the ethernet
344
;      Header + Data is in Ether_buffer[]
345
;      We just need to get a buffer from the 'free' queue, and
346
;      store the packet in it, then insert the packet number into the
347
;      IPRX queue.
348
;      If no queue entry is available, the packet is silently discarded
349
;      All registers may be destroyed
350
;
351
;***************************************************************************
352
ether_IP_handler:
353
    mov     eax, EMPTY_QUEUE
354
    call    dequeue
355
    cmp     ax, NO_BUFFER
302 hidnplayr 356
    je	    eiph00x
1 ha 357
 
358
    ; convert buffer pointer eax to the absolute address
359
    push    eax
360
    mov     ecx, IPBUFFSIZE
361
    mul     ecx
362
    add     eax, IPbuffs
363
 
364
    mov     edi, eax
365
 
366
    ; get a pointer to the start of the DATA
261 hidnplayr 367
    mov     esi, ETH_FRAME.Data
1 ha 368
 
369
    ; Now store it all away
370
    mov     ecx, IPBUFFSIZE / 4     ; Copy all of the available
302 hidnplayr 371
			      ; data across - worse case
1 ha 372
    cld
373
    rep     movsd
374
 
375
    ; And finally, place the buffer in the IPRX queue
376
    pop     ebx
377
    mov     eax, IPIN_QUEUE
378
    call    queue
379
 
380
eiph00x:
381
    ret
382
 
383
;***************************************************************************
384
;   Function
261 hidnplayr 385
;      eth_probe
1 ha 386
;   Description
261 hidnplayr 387
;      Searches for an ethernet card. If found, the card is enabled and
388
;      the ethernet -> IP link established
1 ha 389
;
261 hidnplayr 390
;      This function scans the PCI bus looking for a supported device.
391
;      ISA bus is currently not supported.
1 ha 392
;
261 hidnplayr 393
;        eax is 0 if no hardware found
1 ha 394
;***************************************************************************
261 hidnplayr 395
eth_probe:
396
    ; Find a card on the PCI bus, and get it's address
302 hidnplayr 397
    call    scan_bus			; Find the ethernet cards PIC address
1 ha 398
    xor     eax, eax
261 hidnplayr 399
    cmp     [io_addr], eax
302 hidnplayr 400
    je	    ep_00x			; Return 0 in eax if no cards found
1 ha 401
 
302 hidnplayr 402
    call    dword [drvr_probe]		; Call the drivers probe function
1 ha 403
 
302 hidnplayr 404
    mov     eax, [io_addr]		; return a non zero value
1 ha 405
 
261 hidnplayr 406
ep_00x:
1 ha 407
    ret
408
 
409
;***************************************************************************
410
;   Function
261 hidnplayr 411
;      ethernet_driver
1 ha 412
;
413
;   Description
261 hidnplayr 414
;       The ethernet RX and TX handler
415
;       This is a kernel function, called by stack_handler
1 ha 416
;
417
;***************************************************************************
261 hidnplayr 418
ethernet_driver:
419
    ; Do nothing if the driver is inactive
420
    cmp     [ethernet_active], byte 0
302 hidnplayr 421
    je	    eth_exit
1 ha 422
 
261 hidnplayr 423
    call    eth_rx
424
    call    eth_tx
1 ha 425
 
261 hidnplayr 426
eth_exit:
1 ha 427
    ret
428
 
429
;***************************************************************************
430
;   Function
261 hidnplayr 431
;      eth_rx
1 ha 432
;
433
;   Description
261 hidnplayr 434
;      Polls the ethernet card for received data. Extracts if present
435
;       Depending on the Protocol within the packet:
436
;         ARP : Pass to ARP_handler. This may result in an ARP reply
437
;               being tx'ed
438
;         IP  : Store in an IP buffer
1 ha 439
;
440
;***************************************************************************
261 hidnplayr 441
eth_rx:
442
    xor     ax, ax
443
    mov     [eth_rx_data_len], ax
302 hidnplayr 444
    call    dword [drvr_poll]	    ; Call the drivers poll function
1 ha 445
 
261 hidnplayr 446
    mov     ax, [eth_rx_data_len]
447
    cmp     ax, 0
302 hidnplayr 448
    je	    .exit
1 ha 449
 
450
 
261 hidnplayr 451
    ; Check the protocol. Call appropriate handler
1 ha 452
 
261 hidnplayr 453
    mov     ax, [ETH_FRAME.Type]    ; The address of the protocol word
1 ha 454
 
261 hidnplayr 455
    cmp     ax, ETHER_IP
302 hidnplayr 456
    je	    .is_ip		     ; It's IP
1 ha 457
 
261 hidnplayr 458
    cmp     ax, ETHER_ARP
302 hidnplayr 459
    je	    .is_arp		     ; It is ARP
1 ha 460
 
302 hidnplayr 461
    jmp     .exit		; If not IP or ARP, ignore
1 ha 462
 
261 hidnplayr 463
  .is_ip:
373 mikedld 464
    DEBUGF  1,"K : eth_rx - IP packet\n"
261 hidnplayr 465
    inc     dword [ip_rx_count]
466
    call    ether_IP_handler
467
    jmp     .exit
1 ha 468
 
261 hidnplayr 469
  .is_arp:
373 mikedld 470
    DEBUGF  1,"K : eth_rx - ARP packet\n"
261 hidnplayr 471
    ; At this point, the packet is still in the Ether_buffer
472
    call    arp_handler
1 ha 473
 
261 hidnplayr 474
  .exit:
302 hidnplayr 475
    ret