Subversion Repositories Kolibri OS

Rev

Rev 3685 | Rev 3857 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3685 Rev 3856
Line 25... Line 25...
25
        RBLEN                   = 3 ; Receive buffer size: 0==8K 1==16k 2==32k 3==64k
25
        RBLEN                   = 3 ; Receive buffer size: 0==8K 1==16k 2==32k 3==64k
26
        NUM_TX_DESC             = 4
26
        NUM_TX_DESC             = 4
Line 27... Line 27...
27
 
27
 
28
        DEBUG                   = 1
28
        DEBUG                   = 1
29
        __DEBUG__               = 1
29
        __DEBUG__               = 1
Line 30... Line 30...
30
        __DEBUG_LEVEL__         = 2
30
        __DEBUG_LEVEL__         = 2             ; 1 = verbose, 2 = errors only
31
 
31
 
32
include '../proc32.inc'
32
include '../proc32.inc'
33
include '../imports.inc'
33
include '../imports.inc'
Line 235... Line 235...
235
        cmp     [state], 1
235
        cmp     [state], 1
236
        jne     .exit
236
        jne     .exit
Line 237... Line 237...
237
 
237
 
Line 238... Line 238...
238
  .entry:
238
  .entry:
239
 
239
 
240
        DEBUGF  2, "Loading %s driver\n", my_service
240
        DEBUGF  1, "Loading driver\n"
Line 241... Line 241...
241
        stdcall RegService, my_service, service_proc
241
        stdcall RegService, my_service, service_proc
242
        ret
242
        ret
Line 334... Line 334...
334
 
334
 
Line 335... Line 335...
335
; We've found the io address, find IRQ now
335
; We've found the io address, find IRQ now
Line 336... Line 336...
336
 
336
 
337
        PCI_find_irq
337
        PCI_find_irq
Line 338... Line 338...
338
 
338
 
Line 339... Line 339...
339
        DEBUGF  2, "Hooking into device, dev:%x, bus:%x, irq:%x, I/O addr:%x\n",\
339
        DEBUGF  1, "Hooking into device, dev:%x, bus:%x, irq:%x, I/O addr:%x\n",\
Line 369... Line 369...
369
        ret
369
        ret
Line 370... Line 370...
370
 
370
 
Line 371... Line 371...
371
; If the device was already loaded, find the device number and return it in eax
371
; If the device was already loaded, find the device number and return it in eax
372
 
372
 
373
  .find_devicenum:
373
  .find_devicenum:
374
        DEBUGF  2, "Trying to find device number of already registered device\n"
374
        DEBUGF  1, "Trying to find device number of already registered device\n"
375
        call    NetPtrToNum                                             ; This kernel procedure converts a pointer to device struct in ebx
375
        call    NetPtrToNum                                             ; This kernel procedure converts a pointer to device struct in ebx
376
                                                                        ; into a device number in edi
376
                                                                        ; into a device number in edi
377
        mov     eax, edi                                                ; Application wants it in eax instead
377
        mov     eax, edi                                                ; Application wants it in eax instead
Line 378... Line 378...
378
        DEBUGF  2, "Kernel says: %u\n", eax
378
        DEBUGF  1, "Kernel says: %u\n", eax
Line 379... Line 379...
379
        ret
379
        ret
380
 
380
 
381
; If an error occured, remove all allocated data and exit (returning -1 in eax)
381
; If an error occured, remove all allocated data and exit (returning -1 in eax)
Line 382... Line 382...
382
 
382
 
-
 
383
  .destroy:
383
  .destroy:
384
        ; todo: unregister device from device_list
384
        ; todo: unregister device from device_list
385
        ; todo: reset device into virgin state
Line 385... Line 386...
385
        ; todo: reset device into virgin state
386
 
386
 
387
  .err:
Line 423... Line 424...
423
;;
424
;;
424
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
425
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 425... Line 426...
425
 
426
 
426
align 4
427
align 4
427
probe:
428
probe:
Line 428... Line 429...
428
        DEBUGF  2, "Probing %s device\n", my_service
429
        DEBUGF  1, "Probing\n"
Line 429... Line 430...
429
 
430
 
430
        PCI_make_bus_master
431
        PCI_make_bus_master
Line 453... Line 454...
453
        mov     [device.hw_ver_id], cl
454
        mov     [device.hw_ver_id], cl
Line 454... Line 455...
454
 
455
 
455
        mov     ecx, [crosslist+ecx*4]
456
        mov     ecx, [crosslist+ecx*4]
Line 456... Line 457...
456
        mov     [device.name], ecx
457
        mov     [device.name], ecx
Line 457... Line 458...
457
 
458
 
458
        DEBUGF  2, "Chip version: %s\n", ecx
459
        DEBUGF  1, "Chip version: %s\n", ecx
459
 
460
 
460
; wake up the chip
461
; wake up the chip
Line 496... Line 497...
496
  .finish_wake_up:
497
  .finish_wake_up:
497
        xor     al, al
498
        xor     al, al
498
        set_io  0
499
        set_io  0
499
        set_io  REG_9346CR
500
        set_io  REG_9346CR
500
        out     dx, al
501
        out     dx, al
501
        DEBUGF  2, "done!\n"
502
        DEBUGF  1, "probing done!\n"
Line 502... Line 503...
502
 
503
 
Line 503... Line 504...
503
        xor     eax, eax
504
        xor     eax, eax
Line 510... Line 511...
510
;;   reset: Set up all registers and descriptors, clear some values
511
;;   reset: Set up all registers and descriptors, clear some values
511
;;
512
;;
512
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
513
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 513... Line 514...
513
 
514
 
514
reset:
515
reset:
Line 515... Line 516...
515
        DEBUGF  2, "Reset\n"
516
        DEBUGF  1, "Reset\n"
516
 
517
 
517
; attach int handler
518
; attach int handler
518
        movzx   eax, [device.irq_line]
519
        movzx   eax, [device.irq_line]
519
        DEBUGF  1, "Attaching int handler to irq %x\n", eax:1
520
        DEBUGF  1, "Attaching int handler to irq %x\n", eax:1
520
        stdcall AttachIntHandler, eax, int_handler, dword 0
521
        stdcall AttachIntHandler, eax, int_handler, dword 0
521
        test    eax, eax
522
        test    eax, eax
522
        jnz     @f
523
        jnz     @f
523
        DEBUGF  1, "\nCould not attach int handler!\n"
524
        DEBUGF  2, "Could not attach int handler!\n"
524
;        or      eax, -1
525
;        or      eax, -1
Line 525... Line 526...
525
;        ret
526
;        ret
Line 536... Line 537...
536
        in      al, dx
537
        in      al, dx
537
        test    al, 1 shl BIT_RST
538
        test    al, 1 shl BIT_RST
538
        jz      .reset_completed        ; RST remains 1 during reset
539
        jz      .reset_completed        ; RST remains 1 during reset
539
        dec     cx
540
        dec     cx
540
        jns     .wait_for_reset
541
        jns     .wait_for_reset
541
        DEBUGF  1, "Reset timeout!\n"
542
        DEBUGF  2, "Reset timeout!\n"
542
  .reset_completed:
543
  .reset_completed:
Line 543... Line 544...
543
 
544
 
544
; unlock config and BMCR registers
545
; unlock config and BMCR registers
545
        set_io  REG_9346CR
546
        set_io  REG_9346CR
Line 639... Line 640...
639
;;     pointer to device structure in ebx  ;;
640
;;     pointer to device structure in ebx  ;;
640
;;                                         ;;
641
;;                                         ;;
641
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
642
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
642
align 4
643
align 4
643
transmit:
644
transmit:
644
        DEBUGF  1, "\nTransmitting packet, buffer:%x, size:%u\n", [esp+4], [esp+8]
645
        DEBUGF  1, "Transmitting packet, buffer:%x, size:%u\n", [esp+4], [esp+8]
645
        mov     eax, [esp+4]
646
        mov     eax, [esp+4]
646
        DEBUGF  1, "To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\
647
        DEBUGF  1, "To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\
647
        [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\
648
        [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\
648
        [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\
649
        [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\
649
        [eax+13]:2,[eax+12]:2
650
        [eax+13]:2,[eax+12]:2
Line 708... Line 709...
708
        popa
709
        popa
Line 709... Line 710...
709
 
710
 
Line 710... Line 711...
710
        jmp     .send_packet
711
        jmp     .send_packet
711
 
712
 
712
  .fail:
713
  .fail:
713
        DEBUGF  1, "failed!\n"
714
        DEBUGF  2, "transmit failed!\n"
714
        stdcall KernelFree, [esp+4]
715
        stdcall KernelFree, [esp+4]
Line 728... Line 729...
728
align 4
729
align 4
729
int_handler:
730
int_handler:
Line 730... Line 731...
730
 
731
 
Line 731... Line 732...
731
        push    ebx esi edi
732
        push    ebx esi edi
Line 732... Line 733...
732
 
733
 
733
        DEBUGF  1, "\n%s int\n", my_service
734
        DEBUGF  1, "INT\n"
734
 
735
 
735
; find pointer of device wich made IRQ occur
736
; find pointer of device wich made IRQ occur
Line 772... Line 773...
772
        set_io  REG_COMMAND
773
        set_io  REG_COMMAND
773
        in      al, dx
774
        in      al, dx
774
        test    al, BUFE                        ; test if RX buffer is empty
775
        test    al, BUFE                        ; test if RX buffer is empty
775
        jnz     .finish
776
        jnz     .finish
Line 776... Line 777...
776
 
777
 
Line 777... Line 778...
777
        DEBUGF  1, "RX: "
778
        DEBUGF  1, "RX:\n"
778
 
779
 
779
        mov     eax, [device.rx_buffer]
780
        mov     eax, [device.rx_buffer]
780
        add     eax, [device.rx_data_offset]
781
        add     eax, [device.rx_data_offset]
Line 829... Line 830...
829
        add     eax, 4+3                        ; packet header is 4 bytes long + dword alignment
830
        add     eax, 4+3                        ; packet header is 4 bytes long + dword alignment
830
        and     eax, not 3                      ; dword alignment
831
        and     eax, not 3                      ; dword alignment
Line 831... Line 832...
831
 
832
 
832
        cmp     eax, RX_BUFFER_SIZE
833
        cmp     eax, RX_BUFFER_SIZE
833
        jb      .no_wrap
834
        jb      .no_wrap
834
        DEBUGF  1, "Wrapping"
835
        DEBUGF  1, "Wrapping\n"
835
        sub     eax, RX_BUFFER_SIZE
836
        sub     eax, RX_BUFFER_SIZE
836
  .no_wrap:
837
  .no_wrap:
837
        mov     [device.rx_data_offset], eax
838
        mov     [device.rx_data_offset], eax
Line 845... Line 846...
845
        jmp     .receive                        ; check for multiple packets
846
        jmp     .receive                        ; check for multiple packets
Line 846... Line 847...
846
 
847
 
847
  .reset_rx:
848
  .reset_rx:
848
        test    byte [eax], (1 shl BIT_CRC)
849
        test    byte [eax], (1 shl BIT_CRC)
849
        jz      .no_crc_error
850
        jz      .no_crc_error
Line 850... Line 851...
850
        DEBUGF  2, "\nCRC error!\n"
851
        DEBUGF  2, "RX: CRC error!\n"
851
 
852
 
852
  .no_crc_error:
853
  .no_crc_error:
853
        test    byte [eax], (1 shl BIT_FAE)
854
        test    byte [eax], (1 shl BIT_FAE)
Line 854... Line 855...
854
        jz      .no_fae_error
855
        jz      .no_fae_error
855
        DEBUGF  1, "\nFrame alignment error!\n"
856
        DEBUGF  2, "RX: Frame alignment error!\n"
856
 
857
 
857
  .no_fae_error:
858
  .no_fae_error:
Line 928... Line 929...
928
  @@:
929
  @@:
929
        test    ax, ISR_RXOVW
930
        test    ax, ISR_RXOVW
930
        jz      @f
931
        jz      @f
Line 931... Line 932...
931
 
932
 
932
        push    ax
933
        push    ax
Line 933... Line 934...
933
        DEBUGF  2, "RX-buffer overflow!\n"
934
        DEBUGF  2, "RX:buffer overflow!\n"
934
 
935
 
935
        set_io  0
936
        set_io  0
936
        set_io  REG_ISR
937
        set_io  REG_ISR
Line 942... Line 943...
942
; Packet underrun?
943
; Packet underrun?
943
  @@:
944
  @@:
944
        test    ax, ISR_PUN
945
        test    ax, ISR_PUN
945
        jz      @f
946
        jz      @f
Line 946... Line 947...
946
 
947
 
Line 947... Line 948...
947
        DEBUGF  2, "Packet underrun!\n"
948
        DEBUGF  2, "RX:Packet underrun!\n"
948
 
949
 
949
;----------------------------------------------------
950
;----------------------------------------------------
950
; Receive FIFO overflow ?
951
; Receive FIFO overflow ?
951
  @@:
952
  @@:
Line 952... Line 953...
952
        test    ax, ISR_FIFOOVW
953
        test    ax, ISR_FIFOOVW
953
        jz      @f
954
        jz      @f
Line 954... Line 955...
954
 
955
 
955
        push    ax
956
        push    ax
956
        DEBUGF  2, "RX fifo overflow!\n"
957
        DEBUGF  2, "RX:fifo overflow!\n"
957
 
958
 
Line 968... Line 969...
968
        jz      .fail
969
        jz      .fail
Line 969... Line 970...
969
 
970
 
Line 970... Line 971...
970
        call    cable
971
        call    cable
971
 
-
 
972
  .fail:
972
 
973
        DEBUGF  1, "\n"
973
  .fail:
974
        pop     edi esi ebx
974
        pop     edi esi ebx
Line 975... Line 975...
975
        xor     eax, eax
975
        xor     eax, eax
Line 1027... Line 1027...
1027
;;;;;;;;;;;;;;;;;;;;;;;
1027
;;;;;;;;;;;;;;;;;;;;;;;
Line 1028... Line 1028...
1028
 
1028
 
1029
align 4
1029
align 4
Line 1030... Line 1030...
1030
write_mac:      ; in: mac pushed onto stack (as 3 words)
1030
write_mac:      ; in: mac pushed onto stack (as 3 words)
Line 1031... Line 1031...
1031
 
1031
 
1032
        DEBUGF  2, "Writing MAC: "
1032
        DEBUGF  1, "Writing MAC\n"
1033
 
1033
 
1034
; disable all in command registers
1034
; disable all in command registers
Line 1063... Line 1063...
1063
; disable writing
1063
; disable writing
1064
        set_io  REG_9346CR
1064
        set_io  REG_9346CR
1065
        xor     eax, eax
1065
        xor     eax, eax
1066
        out     dx, al
1066
        out     dx, al
Line 1067... Line 1067...
1067
 
1067
 
Line 1068... Line 1068...
1068
        DEBUGF  2, "ok!\n"
1068
        DEBUGF  1, "MAC write ok!\n"
Line 1069... Line 1069...
1069
 
1069
 
Line 1075... Line 1075...
1075
;; Read MAC address ;;
1075
;; Read MAC address ;;
1076
;;                  ;;
1076
;;                  ;;
1077
;;;;;;;;;;;;;;;;;;;;;;
1077
;;;;;;;;;;;;;;;;;;;;;;
Line 1078... Line 1078...
1078
 
1078
 
1079
read_mac:
1079
read_mac:
Line 1080... Line 1080...
1080
        DEBUGF  2, "Reading MAC: "
1080
        DEBUGF  2, "Reading MAC:\n"
1081
 
1081
 
1082
        set_io  0
1082
        set_io  0
1083
        lea     edi, [device.mac]
1083
        lea     edi, [device.mac]