Rev 4521 | Rev 4524 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4521 | Rev 4522 | ||
---|---|---|---|
Line 12... | Line 12... | ||
12 | ;; GNU GENERAL PUBLIC LICENSE ;; |
12 | ;; GNU GENERAL PUBLIC LICENSE ;; |
13 | ;; Version 2, June 1991 ;; |
13 | ;; Version 2, June 1991 ;; |
14 | ;; ;; |
14 | ;; ;; |
15 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
15 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line 16... | Line 16... | ||
16 | 16 | ||
- | 17 | format PE DLL native |
|
Line 17... | Line 18... | ||
17 | format MS COFF |
18 | entry START |
18 | 19 | ||
- | 20 | CURRENT_API = 0x0200 |
|
Line 19... | Line 21... | ||
19 | API_VERSION = 0x01000100 |
21 | COMPATIBLE_API = 0x0100 |
Line 20... | Line -... | ||
20 | DRIVER_VERSION = 5 |
- | |
21 | 22 | API_VERSION = (COMPATIBLE_API shl 16) + CURRENT_API |
|
22 | MAX_DEVICES = 16 |
23 | |
Line 23... | Line 24... | ||
23 | 24 | MAX_DEVICES = 16 |
|
Line 24... | Line 25... | ||
24 | DEBUG = 1 |
25 | |
25 | __DEBUG__ = 1 |
26 | __DEBUG__ = 1 |
Line -... | Line 27... | ||
- | 27 | __DEBUG_LEVEL__ = 2 ; 1 = verbose, 2 = errors only |
|
- | 28 | ||
- | 29 | MAX_PKT_SIZE = 4096 ; Maximum packet size |
|
26 | __DEBUG_LEVEL__ = 2 ; 1 = verbose, 2 = errors only |
30 | |
27 | 31 | RX_RING_SIZE = 8 ; Must be a power of 2, and minimum 8 |
|
28 | MAX_PKT_SIZE = 4096 ; Maximum packet size |
- | |
29 | - | ||
30 | RX_RING_SIZE = 8 ; Must be a power of 2, and minimum 8 |
32 | TX_RING_SIZE = 8 ; Must be a power of 2, and minimum 8 |
31 | TX_RING_SIZE = 8 ; Must be a power of 2, and minimum 8 |
33 | |
32 | - | ||
33 | include '../struct.inc' |
- | |
34 | include '../macros.inc' |
- | |
35 | include '../proc32.inc' |
- | |
36 | include '../imports.inc' |
- | |
37 | include '../fdo.inc' |
- | |
Line 38... | Line 34... | ||
38 | include '../netdrv.inc' |
34 | section '.flat' readable writable executable |
39 | 35 | ||
40 | public START |
36 | include '../proc32.inc' |
41 | public service_proc |
37 | include '../struct.inc' |
Line 268... | Line 264... | ||
268 | RXDESC_VP = 0x00000008 ; Packet is 802.1Q |
264 | RXDESC_VP = 0x00000008 ; Packet is 802.1Q |
269 | RXDESC_IXSM = 0x00000004 ; Ignore cksum indication |
265 | RXDESC_IXSM = 0x00000004 ; Ignore cksum indication |
270 | RXDESC_EOP = 0x00000002 ; End Of Packet |
266 | RXDESC_EOP = 0x00000002 ; End Of Packet |
271 | RXDESC_DD = 0x00000001 ; Descriptor Done |
267 | RXDESC_DD = 0x00000001 ; Descriptor Done |
Line 272... | Line -... | ||
272 | - | ||
273 | virtual at ebx |
- | |
274 | device: |
268 | |
Line 275... | Line 269... | ||
275 | ETH_DEVICE |
269 | struct device ETH_DEVICE |
276 | 270 | ||
277 | .mmio_addr dd ? |
271 | mmio_addr dd ? |
278 | .pci_bus dd ? |
272 | pci_bus dd ? |
Line 279... | Line 273... | ||
279 | .pci_dev dd ? |
273 | pci_dev dd ? |
280 | .irq_line db ? |
274 | irq_line db ? |
281 | 275 | ||
Line 282... | Line 276... | ||
282 | .cur_rx dd ? |
276 | cur_rx dd ? |
283 | .cur_tx dd ? |
- | |
Line 284... | Line -... | ||
284 | .last_tx dd ? |
- | |
285 | 277 | cur_tx dd ? |
|
Line 286... | Line 278... | ||
286 | rb 0x100 - (($ - device) and 0xff) ; align 256 |
278 | last_tx dd ? |
Line 287... | Line -... | ||
287 | .rx_desc rb RX_RING_SIZE*sizeof.RDESC*2 |
- | |
288 | - | ||
289 | rb 0x100 - (($ - device) and 0xff) ; align 256 |
- | |
290 | .tx_desc rb TX_RING_SIZE*sizeof.TDESC*2 |
279 | |
Line -... | Line 280... | ||
- | 280 | rb 0x100 - ($ and 0xff) ; align 256 |
|
Line 291... | Line 281... | ||
291 | 281 | ||
292 | sizeof.device_struct = $ - device |
282 | rx_desc rb RX_RING_SIZE*sizeof.RDESC*2 |
293 | 283 | ||
294 | end virtual |
284 | rb 0x100 - ($ and 0xff) ; align 256 |
295 | 285 | ||
296 | 286 | tx_desc rb TX_RING_SIZE*sizeof.TDESC*2 |
|
Line 297... | Line -... | ||
297 | section '.flat' code readable align 16 |
- | |
298 | 287 | ||
299 | - | ||
300 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
- | |
301 | ;; ;; |
- | |
Line -... | Line 288... | ||
- | 288 | ends |
|
302 | ;; proc START ;; |
289 | |
Line 303... | Line 290... | ||
303 | ;; ;; |
290 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
304 | ;; (standard driver proc) ;; |
291 | ;; ;; |
305 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
292 | ;; proc START ;; |
Line 306... | Line 293... | ||
306 | 293 | ;; ;; |
|
307 | align 4 |
- | |
308 | proc START stdcall, state:dword |
294 | ;; (standard driver proc) ;; |
309 | 295 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|
Line 310... | Line 296... | ||
310 | cmp [state], 1 |
296 | |
Line 311... | Line -... | ||
311 | jne .exit |
- | |
312 | - | ||
313 | .entry: |
297 | proc START stdcall, reason:dword, cmdline:dword |
314 | 298 | ||
315 | DEBUGF 1,"Loading driver\n" |
299 | cmp [reason], DRV_ENTRY |
316 | stdcall RegService, my_service, service_proc |
300 | jne .fail |
317 | ret |
301 | |
Line 345... | Line 329... | ||
345 | jne @F |
329 | jne @F |
Line 346... | Line 330... | ||
346 | 330 | ||
347 | cmp [edx + IOCTL.out_size], 4 |
331 | cmp [edx + IOCTL.out_size], 4 |
348 | jb .fail |
332 | jb .fail |
349 | mov eax, [edx + IOCTL.output] |
333 | mov eax, [edx + IOCTL.output] |
Line 350... | Line 334... | ||
350 | mov [eax], dword API_VERSION |
334 | mov dword[eax], API_VERSION |
351 | 335 | ||
Line 352... | Line 336... | ||
352 | xor eax, eax |
336 | xor eax, eax |
Line 373... | Line 357... | ||
373 | 357 | ||
374 | ; mov eax, [edx + IOCTL.input] ; get the pci bus and device numbers |
358 | ; mov eax, [edx + IOCTL.input] ; get the pci bus and device numbers |
375 | mov ax, [eax+1] ; |
359 | mov ax, [eax+1] ; |
376 | .nextdevice: |
360 | .nextdevice: |
377 | mov ebx, [esi] |
361 | mov ebx, [esi] |
378 | cmp al, byte [device.pci_bus] |
362 | cmp al, byte[ebx + device.pci_bus] |
379 | jne .next |
363 | jne .next |
380 | cmp ah, byte [device.pci_dev] |
364 | cmp ah, byte[ebx + device.pci_dev] |
381 | je .find_devicenum ; Device is already loaded, let's find it's device number |
365 | je .find_devicenum ; Device is already loaded, let's find it's device number |
382 | .next: |
366 | .next: |
383 | add esi, 4 |
367 | add esi, 4 |
Line 387... | Line 371... | ||
387 | ; This device doesnt have its own eth_device structure yet, lets create one |
371 | ; This device doesnt have its own eth_device structure yet, lets create one |
388 | .firstdevice: |
372 | .firstdevice: |
389 | cmp [devices], MAX_DEVICES ; First check if the driver can handle one more card |
373 | cmp [devices], MAX_DEVICES ; First check if the driver can handle one more card |
390 | jae .fail |
374 | jae .fail |
Line 391... | Line 375... | ||
391 | 375 | ||
Line 392... | Line 376... | ||
392 | allocate_and_clear ebx, sizeof.device_struct, .fail ; Allocate the buffer for device structure |
376 | allocate_and_clear ebx, sizeof.device, .fail ; Allocate the buffer for device structure |
Line 393... | Line 377... | ||
393 | 377 | ||
394 | ; Fill in the direct call addresses into the struct |
378 | ; Fill in the direct call addresses into the struct |
395 | 379 | ||
396 | mov [device.reset], reset |
380 | mov [ebx + device.reset], reset |
Line 397... | Line 381... | ||
397 | mov [device.transmit], transmit |
381 | mov [ebx + device.transmit], transmit |
Line 398... | Line 382... | ||
398 | mov [device.unload], unload |
382 | mov [ebx + device.unload], unload |
399 | mov [device.name], my_service |
383 | mov [ebx + device.name], my_service |
400 | 384 | ||
401 | ; save the pci bus and device numbers |
385 | ; save the pci bus and device numbers |
402 | 386 | ||
Line 403... | Line 387... | ||
403 | mov eax, [edx + IOCTL.input] |
387 | mov eax, [edx + IOCTL.input] |
Line 404... | Line 388... | ||
404 | movzx ecx, byte [eax+1] |
388 | movzx ecx, byte [eax+1] |
Line 405... | Line 389... | ||
405 | mov [device.pci_bus], ecx |
389 | mov [ebx + device.pci_bus], ecx |
Line 406... | Line 390... | ||
406 | movzx ecx, byte [eax+2] |
390 | movzx ecx, byte [eax+2] |
407 | mov [device.pci_dev], ecx |
- | |
408 | - | ||
409 | ; Now, it's time to find the base mmio addres of the PCI device |
- | |
410 | 391 | mov [ebx + device.pci_dev], ecx |
|
Line 411... | Line 392... | ||
411 | PCI_find_mmio32 |
392 | |
Line -... | Line 393... | ||
- | 393 | ; Now, it's time to find the base mmio addres of the PCI device |
|
412 | 394 | ||
Line 413... | Line 395... | ||
413 | ; Create virtual mapping of the physical memory |
395 | stdcall PCI_find_mmio32, [ebx + device.pci_bus], [ebx + device.pci_dev] ; returns in eax |
414 | 396 | ||
Line 415... | Line 397... | ||
415 | push 1Bh ; PG_SW+PG_NOCACHE |
397 | ; Create virtual mapping of the physical memory |
416 | push 10000h ; size of the map |
398 | |
417 | push eax |
399 | invoke MapIoMem, eax, 10000h, PG_SW+PG_NOCACHE |
418 | call MapIoMem |
400 | mov [ebx + device.mmio_addr], eax |
Line 434... | Line 416... | ||
434 | mov [device_list+4*eax], ebx ; (IRQ handler uses this list to find device) |
416 | mov [device_list+4*eax], ebx ; (IRQ handler uses this list to find device) |
435 | inc [devices] ; |
417 | inc [devices] ; |
Line 436... | Line 418... | ||
436 | 418 | ||
Line 437... | Line 419... | ||
437 | call start_i8254x |
419 | call start_i8254x |
438 | 420 | ||
439 | mov [device.type], NET_TYPE_ETH |
- | |
440 | call NetRegDev |
421 | mov [ebx + device.type], NET_TYPE_ETH |
441 | 422 | invoke NetRegDev |
|
Line 442... | Line 423... | ||
442 | cmp eax, -1 |
423 | cmp eax, -1 |
Line 443... | Line 424... | ||
443 | je .destroy |
424 | je .destroy |
Line 444... | Line 425... | ||
444 | 425 | ||
445 | ret |
426 | ret |
446 | 427 | ||
447 | ; If the device was already loaded, find the device number and return it in eax |
428 | ; If the device was already loaded, find the device number and return it in eax |
448 | 429 | ||
449 | .find_devicenum: |
430 | .find_devicenum: |
450 | DEBUGF 1,"Trying to find device number of already registered device\n" |
431 | DEBUGF 1,"Trying to find device number of already registered device\n" |
Line 458... | Line 439... | ||
458 | 439 | ||
459 | .destroy: |
440 | .destroy: |
Line 460... | Line 441... | ||
460 | ; todo: reset device into virgin state |
441 | ; todo: reset device into virgin state |
461 | 442 | ||
Line 462... | Line 443... | ||
462 | .err: |
443 | .err: |
463 | stdcall KernelFree, ebx |
444 | invoke KernelFree, ebx |
464 | 445 | ||
Line 501... | Line 482... | ||
501 | align 4 |
482 | align 4 |
502 | probe: |
483 | probe: |
Line 503... | Line 484... | ||
503 | 484 | ||
Line 504... | Line 485... | ||
504 | DEBUGF 1,"Probe\n" |
485 | DEBUGF 1,"Probe\n" |
- | 486 | ||
- | 487 | ; Make the device a bus master |
|
- | 488 | invoke PciRead32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command |
|
Line 505... | Line 489... | ||
505 | 489 | or al, PCI_CMD_MASTER |
|
Line 506... | Line 490... | ||
506 | PCI_make_bus_master |
490 | invoke PciWrite32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command, eax |
Line 507... | Line 491... | ||
507 | 491 | ||
508 | ; TODO: validate the device |
492 | ; TODO: validate the device |
509 | 493 | ||
510 | call read_mac |
494 | call read_mac |
511 | 495 | ||
512 | movzx eax, [device.irq_line] |
496 | movzx eax, [ebx + device.irq_line] |
513 | DEBUGF 1,"Attaching int handler to irq %x\n", eax:1 |
497 | DEBUGF 1,"Attaching int handler to irq %x\n", eax:1 |
514 | stdcall AttachIntHandler, eax, int_handler, dword 0 |
498 | invoke AttachIntHandler, eax, int_handler, ebx |
Line 521... | Line 505... | ||
521 | 505 | ||
522 | 506 | ||
Line 523... | Line 507... | ||
523 | reset_dontstart: |
507 | reset_dontstart: |
Line 524... | Line 508... | ||
524 | DEBUGF 1,"Reset\n" |
508 | DEBUGF 1,"Reset\n" |
525 | 509 | ||
526 | mov esi, [device.mmio_addr] |
510 | mov esi, [ebx + device.mmio_addr] |
527 | 511 | ||
528 | or dword[esi + REG_CTRL], CTRL_RST ; reset device |
512 | or dword[esi + REG_CTRL], CTRL_RST ; reset device |
529 | .loop: |
513 | .loop: |
530 | push esi |
514 | push esi |
531 | xor esi, esi |
515 | xor esi, esi |
532 | inc esi |
516 | inc esi |
Line 533... | Line 517... | ||
533 | call Sleep |
517 | invoke Sleep |
Line 565... | Line 549... | ||
565 | 549 | ||
566 | 550 | ||
Line 567... | Line 551... | ||
567 | align 4 |
551 | align 4 |
568 | init_rx: |
552 | init_rx: |
569 | 553 | ||
570 | lea edi, [device.rx_desc] |
554 | lea edi, [ebx + device.rx_desc] |
571 | mov ecx, RX_RING_SIZE |
555 | mov ecx, RX_RING_SIZE |
572 | .loop: |
556 | .loop: |
573 | push ecx |
557 | push ecx |
574 | push edi |
558 | push edi |
575 | stdcall KernelAlloc, MAX_PKT_SIZE |
559 | invoke KernelAlloc, MAX_PKT_SIZE |
576 | DEBUGF 1,"RX buffer: 0x%x\n", eax |
560 | DEBUGF 1,"RX buffer: 0x%x\n", eax |
577 | pop edi |
561 | pop edi |
578 | mov dword[edi + RX_RING_SIZE*sizeof.RDESC], eax |
562 | mov dword[edi + RX_RING_SIZE*sizeof.RDESC], eax |
579 | push edi |
563 | push edi |
580 | GetRealAddr |
564 | invoke GetPhysAddr |
581 | pop edi |
565 | pop edi |
582 | mov [edi + RDESC.addr_l], eax |
566 | mov [edi + RDESC.addr_l], eax |
583 | mov [edi + RDESC.addr_h], 0 |
567 | mov [edi + RDESC.addr_h], 0 |
584 | mov [edi + RDESC.status_l], 0 |
568 | mov [edi + RDESC.status_l], 0 |
585 | mov [edi + RDESC.status_h], 0 |
569 | mov [edi + RDESC.status_h], 0 |
586 | add edi, sizeof.RDESC |
570 | add edi, sizeof.RDESC |
Line 587... | Line 571... | ||
587 | pop ecx |
571 | pop ecx |
Line 588... | Line 572... | ||
588 | dec ecx |
572 | dec ecx |
589 | jnz .loop |
573 | jnz .loop |
590 | 574 | ||
591 | mov [device.cur_rx], 0 |
575 | mov [ebx + device.cur_rx], 0 |
592 | 576 | ||
593 | lea eax, [device.rx_desc] |
577 | lea eax, [ebx + device.rx_desc] |
594 | GetRealAddr |
578 | invoke GetPhysAddr |
Line 605... | Line 589... | ||
605 | 589 | ||
606 | 590 | ||
Line 607... | Line 591... | ||
607 | align 4 |
591 | align 4 |
608 | init_tx: |
592 | init_tx: |
609 | 593 | ||
610 | lea edi, [device.tx_desc] |
594 | lea edi, [ebx + device.tx_desc] |
611 | mov ecx, TX_RING_SIZE |
595 | mov ecx, TX_RING_SIZE |
612 | .loop: |
596 | .loop: |
613 | mov [edi + TDESC.addr_l], eax |
597 | mov [edi + TDESC.addr_l], eax |
614 | mov [edi + TDESC.addr_h], 0 |
598 | mov [edi + TDESC.addr_h], 0 |
615 | mov [edi + TDESC.length_cso_cmd], 0 |
599 | mov [edi + TDESC.length_cso_cmd], 0 |
616 | mov [edi + TDESC.status], 0 |
600 | mov [edi + TDESC.status], 0 |
Line 617... | Line 601... | ||
617 | add edi, sizeof.TDESC |
601 | add edi, sizeof.TDESC |
618 | dec ecx |
602 | dec ecx |
Line 619... | Line 603... | ||
619 | jnz .loop |
603 | jnz .loop |
620 | 604 | ||
621 | mov [device.cur_tx], 0 |
605 | mov [ebx + device.cur_tx], 0 |
622 | mov [device.last_tx], 0 |
606 | mov [ebx + device.last_tx], 0 |
623 | 607 | ||
624 | lea eax, [device.tx_desc] |
608 | lea eax, [ebx + device.tx_desc] |
625 | GetRealAddr |
609 | invoke GetPhysAddr |
Line 638... | Line 622... | ||
638 | reset: |
622 | reset: |
639 | call reset_dontstart |
623 | call reset_dontstart |
Line 640... | Line 624... | ||
640 | 624 | ||
Line 641... | Line 625... | ||
641 | start_i8254x: |
625 | start_i8254x: |
642 | 626 | ||
Line 643... | Line 627... | ||
643 | mov esi, [device.mmio_addr] |
627 | mov esi, [ebx + device.mmio_addr] |
644 | or dword[esi + REG_RCTL], RCTL_EN ; Enable the receiver |
628 | or dword[esi + REG_RCTL], RCTL_EN ; Enable the receiver |
645 | 629 | ||
646 | xor eax, eax |
630 | xor eax, eax |
Line 647... | Line 631... | ||
647 | mov [esi + REG_RDTR], eax ; Clear the Receive Delay Timer Register |
631 | mov [esi + REG_RDTR], eax ; Clear the Receive Delay Timer Register |
648 | mov [esi + REG_RADV], eax ; Clear the Receive Interrupt Absolute Delay Timer |
632 | mov [esi + REG_RADV], eax ; Clear the Receive Interrupt Absolute Delay Timer |
Line 649... | Line 633... | ||
649 | mov [esi + REG_RSRPD], eax ; Clear the Receive Small Packet Detect Interrupt |
633 | mov [esi + REG_RSRPD], eax ; Clear the Receive Small Packet Detect Interrupt |
650 | 634 | ||
Line 651... | Line 635... | ||
651 | mov dword[esi + REG_IMS], 0x1F6DC ; Enable interrupt types |
635 | mov dword[esi + REG_IMS], 0x1F6DC ; Enable interrupt types |
652 | mov eax, [esi + REG_ICR] ; Clear pending interrupts |
636 | mov eax, [esi + REG_ICR] ; Clear pending interrupts |
Line 663... | Line 647... | ||
663 | align 4 |
647 | align 4 |
664 | read_mac: |
648 | read_mac: |
Line 665... | Line 649... | ||
665 | 649 | ||
Line 666... | Line 650... | ||
666 | DEBUGF 1,"Read MAC\n" |
650 | DEBUGF 1,"Read MAC\n" |
Line 667... | Line 651... | ||
667 | 651 | ||
668 | mov esi, [device.mmio_addr] |
652 | mov esi, [ebx + device.mmio_addr] |
669 | 653 | ||
Line 670... | Line 654... | ||
670 | mov eax, [esi+0x5400] ; RAL |
654 | mov eax, [esi+0x5400] ; RAL |
671 | test eax, eax |
655 | test eax, eax |
672 | jz .try_eeprom |
656 | jz .try_eeprom |
Line 673... | Line 657... | ||
673 | 657 | ||
Line 674... | Line 658... | ||
674 | mov dword[device.mac], eax |
658 | mov dword[ebx + device.mac], eax |
675 | mov eax, [esi+0x5404] ; RAH |
659 | mov eax, [esi+0x5404] ; RAH |
676 | mov word[device.mac+4], ax |
660 | mov word[ebx + device.mac+4], ax |
677 | 661 | ||
678 | jmp .mac_ok |
662 | jmp .mac_ok |
Line 679... | Line 663... | ||
679 | 663 | ||
680 | .try_eeprom: |
664 | .try_eeprom: |
681 | mov dword[esi+0x14], 0x00000001 |
665 | mov dword[esi+0x14], 0x00000001 |
682 | mov eax, [esi+0x14] |
666 | mov eax, [esi+0x14] |
Line 683... | Line 667... | ||
683 | shr eax, 16 |
667 | shr eax, 16 |
684 | mov word[device.mac], ax |
668 | mov word[ebx + device.mac], ax |
685 | 669 | ||
686 | mov dword[esi+0x14], 0x00000101 |
670 | mov dword[esi+0x14], 0x00000101 |
Line 687... | Line 671... | ||
687 | mov eax, [esi+0x14] |
671 | mov eax, [esi+0x14] |
688 | shr eax, 16 |
672 | shr eax, 16 |
- | 673 | mov word[ebx + device.mac+2], ax |
|
689 | mov word[device.mac+2], ax |
674 | |
Line 690... | Line 675... | ||
690 | 675 | mov dword[esi+0x14], 0x00000201 |
|
Line 691... | Line 676... | ||
691 | mov dword[esi+0x14], 0x00000201 |
676 | mov eax, [esi+0x14] |
Line 724... | Line 709... | ||
724 | ja .fail |
709 | ja .fail |
725 | cmp [buffersize], 60 |
710 | cmp [buffersize], 60 |
726 | jb .fail |
711 | jb .fail |
Line 727... | Line 712... | ||
727 | 712 | ||
728 | ; Program the descriptor (use legacy mode) |
713 | ; Program the descriptor (use legacy mode) |
729 | mov edi, [device.cur_tx] |
714 | mov edi, [ebx + device.cur_tx] |
730 | DEBUGF 1, "Using TX desc: %u\n", edi |
715 | DEBUGF 1, "Using TX desc: %u\n", edi |
731 | shl edi, 4 ; edi = edi * sizeof.TDESC |
716 | shl edi, 4 ; edi = edi * sizeof.TDESC |
732 | lea edi, [device.tx_desc + edi] |
717 | lea edi, [ebx + device.tx_desc + edi] |
733 | mov dword[edi + TX_RING_SIZE*sizeof.TDESC], eax ; Store the data location (for driver) |
718 | mov dword[edi + TX_RING_SIZE*sizeof.TDESC], eax ; Store the data location (for driver) |
734 | GetRealAddr |
719 | invoke GetPhysAddr |
735 | mov [edi + TDESC.addr_l], eax ; Data location (for hardware) |
720 | mov [edi + TDESC.addr_l], eax ; Data location (for hardware) |
Line 736... | Line 721... | ||
736 | mov [edi + TDESC.addr_h], 0 |
721 | mov [edi + TDESC.addr_h], 0 |
737 | 722 | ||
738 | mov ecx, [buffersize] |
723 | mov ecx, [buffersize] |
739 | or ecx, TXDESC_EOP + TXDESC_IFCS + TXDESC_RS |
724 | or ecx, TXDESC_EOP + TXDESC_IFCS + TXDESC_RS |
Line 740... | Line 725... | ||
740 | mov [edi + TDESC.length_cso_cmd], ecx |
725 | mov [edi + TDESC.length_cso_cmd], ecx |
741 | mov [edi + TDESC.status], 0 |
726 | mov [edi + TDESC.status], 0 |
742 | 727 | ||
743 | ; Tell i8254x wich descriptor(s) we programmed |
728 | ; Tell i8254x wich descriptor(s) we programmed, by moving the tail |
744 | mov edi, [device.mmio_addr] |
729 | mov edi, [ebx + device.mmio_addr] |
745 | mov eax, [device.cur_tx] |
730 | mov eax, [ebx + device.cur_tx] |
746 | inc eax |
731 | inc eax |
Line 747... | Line 732... | ||
747 | and eax, TX_RING_SIZE-1 |
732 | and eax, TX_RING_SIZE-1 |
748 | mov [device.cur_tx], eax |
733 | mov [ebx + device.cur_tx], eax |
749 | mov dword[edi + REG_TDT], eax ; TDT - Transmit Descriptor Tail |
734 | mov dword[edi + REG_TDT], eax ; TDT - Transmit Descriptor Tail |
750 | 735 | ||
751 | ; Update stats |
736 | ; Update stats |
Line 752... | Line 737... | ||
752 | inc [device.packets_tx] |
737 | inc [ebx + device.packets_tx] |
753 | mov eax, [buffersize] |
738 | mov eax, [buffersize] |
754 | add dword[device.bytes_tx], eax |
739 | add dword[ebx + device.bytes_tx], eax |
Line 755... | Line 740... | ||
755 | adc dword[device.bytes_tx + 4], 0 |
740 | adc dword[ebx + device.bytes_tx + 4], 0 |
756 | 741 | ||
757 | popf |
742 | popf |
758 | xor eax, eax |
743 | xor eax, eax |
759 | ret |
744 | ret |
760 | 745 | ||
Line 761... | Line 746... | ||
761 | .fail: |
746 | .fail: |
Line 787... | Line 772... | ||
787 | test ecx, ecx |
772 | test ecx, ecx |
788 | jz .nothing |
773 | jz .nothing |
789 | mov esi, device_list |
774 | mov esi, device_list |
790 | .nextdevice: |
775 | .nextdevice: |
791 | mov ebx, [esi] |
776 | mov ebx, [esi] |
792 | - | ||
793 | mov edi, [device.mmio_addr] |
777 | mov edi, [ebx + device.mmio_addr] |
794 | mov eax, [edi + REG_ICR] |
778 | mov eax, [edi + REG_ICR] |
795 | test eax, eax |
779 | test eax, eax |
796 | jnz .got_it |
780 | jnz .got_it |
797 | .continue: |
781 | .continue: |
798 | add esi, 4 |
782 | add esi, 4 |
Line 803... | Line 787... | ||
803 | xor eax, eax |
787 | xor eax, eax |
Line 804... | Line 788... | ||
804 | 788 | ||
Line 805... | Line 789... | ||
805 | ret |
789 | ret |
806 | - | ||
807 | .got_it: |
790 | |
Line 808... | Line 791... | ||
808 | 791 | .got_it: |
|
809 | DEBUGF 1,"Device: %x Status: %x\n", ebx, eax |
792 | DEBUGF 1,"Device: %x Status: %x\n", ebx, eax |
Line 816... | Line 799... | ||
816 | 799 | ||
817 | push eax ebx |
800 | push eax ebx |
818 | .retaddr: |
801 | .retaddr: |
819 | pop ebx eax |
802 | pop ebx eax |
820 | ; Get last descriptor addr |
803 | ; Get last descriptor addr |
821 | mov esi, [device.cur_rx] |
804 | mov esi, [ebx + device.cur_rx] |
822 | shl esi, 4 ; esi = esi * sizeof.RDESC |
805 | shl esi, 4 ; esi = esi * sizeof.RDESC |
823 | lea esi, [device.rx_desc + esi] |
806 | lea esi, [ebx + device.rx_desc + esi] |
824 | cmp byte[esi + RDESC.status_h], 0 ; Check status field |
807 | cmp byte[esi + RDESC.status_h], 0 ; Check status field |
Line 825... | Line 808... | ||
825 | je .no_rx |
808 | je .no_rx |
826 | 809 | ||
Line 830... | Line 813... | ||
830 | DEBUGF 1,"got %u bytes\n", ecx |
813 | DEBUGF 1,"got %u bytes\n", ecx |
831 | push ecx |
814 | push ecx |
832 | push dword[esi + RX_RING_SIZE*sizeof.RDESC] ; Get packet pointer |
815 | push dword[esi + RX_RING_SIZE*sizeof.RDESC] ; Get packet pointer |
Line 833... | Line 816... | ||
833 | 816 | ||
834 | ; Update stats |
817 | ; Update stats |
835 | add dword[device.bytes_rx], ecx |
818 | add dword[ebx + device.bytes_rx], ecx |
836 | adc dword[device.bytes_rx + 4], 0 |
819 | adc dword[ebx + device.bytes_rx + 4], 0 |
Line 837... | Line 820... | ||
837 | inc [device.packets_rx] |
820 | inc [ebx + device.packets_rx] |
838 | 821 | ||
839 | ; Allocate new descriptor |
822 | ; Allocate new descriptor |
840 | push esi |
823 | push esi |
841 | stdcall KernelAlloc, MAX_PKT_SIZE |
824 | invoke KernelAlloc, MAX_PKT_SIZE |
842 | pop esi |
825 | pop esi |
843 | mov dword[esi + RX_RING_SIZE*sizeof.RDESC], eax |
826 | mov dword[esi + RX_RING_SIZE*sizeof.RDESC], eax |
844 | GetRealAddr |
827 | invoke GetPhysAddr |
845 | mov [esi + RDESC.addr_l], eax |
828 | mov [esi + RDESC.addr_l], eax |
Line 846... | Line 829... | ||
846 | mov [esi + RDESC.status_l], 0 |
829 | mov [esi + RDESC.status_l], 0 |
847 | mov [esi + RDESC.status_h], 0 |
830 | mov [esi + RDESC.status_h], 0 |
848 | 831 | ||
849 | ; Move the receive descriptor tail |
832 | ; Move the receive descriptor tail |
Line 850... | Line 833... | ||
850 | mov esi, [device.mmio_addr] |
833 | mov esi, [ebx + device.mmio_addr] |
851 | mov eax, [device.cur_rx] |
834 | mov eax, [ebx + device.cur_rx] |
852 | mov [esi + REG_RDT], eax |
835 | mov [esi + REG_RDT], eax |
Line 853... | Line 836... | ||
853 | 836 | ||
854 | ; Move to next rx desc |
837 | ; Move to next rx desc |
Line 855... | Line 838... | ||
855 | inc [device.cur_rx] |
838 | inc [ebx + device.cur_rx] |
856 | and [device.cur_rx], RX_RING_SIZE-1 |
839 | and [ebx + device.cur_rx], RX_RING_SIZE-1 |
Line 875... | Line 858... | ||
875 | jz .no_tx |
858 | jz .no_tx |
Line 876... | Line 859... | ||
876 | 859 | ||
Line 877... | Line 860... | ||
877 | DEBUGF 1,"Transmit done\n" |
860 | DEBUGF 1,"Transmit done\n" |
878 | 861 | ||
879 | .txdesc_loop: |
862 | .txdesc_loop: |
880 | mov edi, [device.last_tx] |
863 | mov edi, [ebx + device.last_tx] |
881 | shl edi, 4 ; edi = edi * sizeof.TDESC |
864 | shl edi, 4 ; edi = edi * sizeof.TDESC |
882 | lea edi, [device.tx_desc + edi] |
865 | lea edi, [ebx + device.tx_desc + edi] |
883 | test [edi + TDESC.status], TXDESC_DD ; Descriptor done? |
866 | test [edi + TDESC.status], TXDESC_DD ; Descriptor done? |
884 | jz .no_tx |
867 | jz .no_tx |
Line 885... | Line 868... | ||
885 | cmp dword[edi + TX_RING_SIZE*sizeof.TDESC], 0 |
868 | cmp dword[edi + TX_RING_SIZE*sizeof.TDESC], 0 |
Line 886... | Line 869... | ||
886 | je .no_tx |
869 | je .no_tx |
887 | 870 | ||
888 | DEBUGF 1,"Cleaning up TX desc: 0x%x\n", edi |
871 | DEBUGF 1,"Cleaning up TX desc: 0x%x\n", edi |
889 | 872 | ||
890 | push ebx |
873 | push ebx |
Line 891... | Line 874... | ||
891 | push dword[edi + TX_RING_SIZE*sizeof.TDESC] |
874 | push dword[edi + TX_RING_SIZE*sizeof.TDESC] |
892 | mov dword[edi + TX_RING_SIZE*sizeof.TDESC], 0 |
875 | mov dword[edi + TX_RING_SIZE*sizeof.TDESC], 0 |
893 | call KernelFree |
876 | invoke KernelFree |
Line 894... | Line 877... | ||
894 | pop ebx |
877 | pop ebx |
895 | 878 | ||
896 | inc [device.last_tx] |
879 | inc [ebx + device.last_tx] |
897 | and [device.last_tx], TX_RING_SIZE-1 |
880 | and [ebx + device.last_tx], TX_RING_SIZE-1 |
898 | jmp .txdesc_loop |
- | |
899 | 881 | jmp .txdesc_loop |
|
Line 900... | Line 882... | ||
900 | .no_tx: |
882 | |
Line 901... | Line 883... | ||
901 | pop edi esi ebx |
883 | .no_tx: |
902 | xor eax, eax |
884 | pop edi esi ebx |
Line 903... | Line 885... | ||
903 | inc eax |
885 | xor eax, eax |
904 | - | ||
905 | ret |
886 | inc eax |
Line 906... | Line -... | ||
906 | - | ||
907 | 887 | ret |
|
- | 888 | ||
908 | 889 |