Subversion Repositories Kolibri OS

Rev

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

Rev 5363 Rev 5522
Line 344... Line 344...
344
 
344
 
345
NIC_LB_NONE             = 0x00
345
NIC_LB_NONE             = 0x00
346
NIC_LB_INTERNAL         = 0x01
346
NIC_LB_INTERNAL         = 0x01
Line 347... Line 347...
347
NIC_LB_PHY              = 0x02    ; MII or Internal-10BaseT loopback
347
NIC_LB_PHY              = 0x02    ; MII or Internal-10BaseT loopback
Line 348... Line 348...
348
 
348
 
349
PKT_BUF_SZ              = 1536    ; Size of each temporary Rx buffer.
349
PKT_BUF_SZ              = 1514
Line 350... Line 350...
350
 
350
 
Line 927... Line 927...
927
; attach int handler
927
; attach int handler
928
        movzx   eax, [ebx + device.irq_line]
928
        movzx   eax, [ebx + device.irq_line]
929
        DEBUGF  1,"Attaching int handler to irq %x\n", eax:1
929
        DEBUGF  1,"Attaching int handler to irq %x\n", eax:1
930
        invoke  AttachIntHandler, eax, int_handler, ebx
930
        invoke  AttachIntHandler, eax, int_handler, ebx
931
        test    eax, eax
931
        test    eax, eax
932
        jnz     @f
932
        jz      .err
933
        DEBUGF  2,"Could not attach int handler!\n"
-
 
934
        or      eax, -1
-
 
935
        ret
-
 
936
       @@:
-
 
Line 937... Line 933...
937
 
933
 
938
; Soft reset the chip.
934
; Soft reset the chip.
939
        set_io  [ebx + device.io_addr], 0
935
        set_io  [ebx + device.io_addr], 0
940
        set_io  [ebx + device.io_addr], byCR0
936
        set_io  [ebx + device.io_addr], byCR0
Line 943... Line 939...
943
 
939
 
Line 944... Line 940...
944
        call    MIIDelay
940
        call    MIIDelay
945
 
941
 
-
 
942
; Initialize rings
-
 
943
        call    init_ring
Line 946... Line 944...
946
; Initialize rings
944
        test    eax, eax
947
        call    init_ring
945
        jnz     .err
Line 948... Line 946...
948
 
946
 
Line 966... Line 964...
966
        set_io  [ebx + device.io_addr], byTCR
964
        set_io  [ebx + device.io_addr], byTCR
967
        mov     al, 0x60
965
        mov     al, 0x60
968
        out     dx, al
966
        out     dx, al
Line 969... Line 967...
969
 
967
 
970
; Set Fulldupex
-
 
971
 
968
; Set Fulldupex
972
        call    QueryAuto
969
        call    QueryAuto
973
        test    eax, eax        ; full duplex?
970
        test    eax, eax        ; full duplex?
Line 974... Line 971...
974
        jz      @f
971
        jz      @f
Line 1005... Line 1002...
1005
 
1002
 
1006
; say reset was successful
1003
; say reset was successful
1007
        xor     eax, eax
1004
        xor     eax, eax
Line -... Line 1005...
-
 
1005
        ret
-
 
1006
 
-
 
1007
  .err:
-
 
1008
        DEBUGF  2,"Error!\n"
-
 
1009
        or      eax, -1
Line 1008... Line 1010...
1008
        ret
1010
        ret
1009
 
1011
 
Line 1071... Line 1073...
1071
   .rx_init:
1073
   .rx_init:
1072
        add     esi, sizeof.rx_head
1074
        add     esi, sizeof.rx_head
1073
        mov     [edi + rx_head.status], RX_SBITS_OWN_BIT
1075
        mov     [edi + rx_head.status], RX_SBITS_OWN_BIT
1074
        mov     [edi + rx_head.control], PKT_BUF_SZ
1076
        mov     [edi + rx_head.control], PKT_BUF_SZ
1075
        push    ecx
1077
        push    ecx
1076
        invoke  KernelAlloc, PKT_BUF_SZ
1078
        invoke  NetAlloc, PKT_BUF_SZ+NET_BUFF.data
1077
        pop     ecx
1079
        pop     ecx
-
 
1080
        test    eax, eax
-
 
1081
        jz      .out_of_mem
1078
        mov     [edi + rx_head.buff_addr_virt], eax
1082
        mov     [edi + rx_head.buff_addr_virt], eax
1079
        invoke  GetPhysAddr
1083
        invoke  GetPhysAddr
-
 
1084
        add     eax, NET_BUFF.data
1080
        mov     [edi + rx_head.buff_addr], eax                        ; buffer ptr
1085
        mov     [edi + rx_head.buff_addr], eax                        ; buffer ptr
1081
        mov     [edi + rx_head.next_desc], esi                        ; next head
1086
        mov     [edi + rx_head.next_desc], esi                        ; next head
1082
        add     edi, sizeof.rx_head
1087
        add     edi, sizeof.rx_head
1083
        dec     ecx
1088
        dec     ecx
1084
        jnz     .rx_init
1089
        jnz     .rx_init
Line 1118... Line 1123...
1118
        xor     eax, eax
1123
        xor     eax, eax
1119
        mov     [ebx + device.cur_rx], ax
1124
        mov     [ebx + device.cur_rx], ax
1120
        mov     [ebx + device.cur_tx], ax
1125
        mov     [ebx + device.cur_tx], ax
1121
        mov     [ebx + device.last_tx], ax
1126
        mov     [ebx + device.last_tx], ax
Line -... Line 1127...
-
 
1127
 
-
 
1128
        xor     eax, eax
-
 
1129
        ret
-
 
1130
 
-
 
1131
  .out_of_mem:
-
 
1132
        add     esp, 4
1122
 
1133
        or      eax, -1
Line 1123... Line 1134...
1123
        ret
1134
        ret
1124
 
1135
 
Line 1347... Line 1358...
1347
 
1358
 
1348
        set_io  [ebx + device.io_addr], byMAR4
1359
        set_io  [ebx + device.io_addr], byMAR4
Line 1349... Line 1360...
1349
        out     dx, eax
1360
        out     dx, eax
1350
 
1361
 
1351
        set_io  [ebx + device.io_addr], byRCR
1362
        set_io  [ebx + device.io_addr], byRCR
Line 1352... Line 1363...
1352
        mov     al, 0x6C                ;rx_mode = 0x0C;
1363
        mov     al, 0x6C                ; thresh or rx_mode
Line 1391... Line 1402...
1391
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1402
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1392
;;                                         ;;
1403
;;                                         ;;
1393
;; Transmit                                ;;
1404
;; Transmit                                ;;
1394
;;                                         ;;
1405
;;                                         ;;
1395
;; In: buffer pointer in [esp+4]           ;;
1406
;; In: buffer pointer in [esp+4]           ;;
1396
;;     size of buffer in [esp+8]           ;;
-
 
1397
;;     pointer to device structure in ebx  ;;
1407
;;     pointer to device structure in ebx  ;;
1398
;;                                         ;;
1408
;;                                         ;;
1399
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1409
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1400
align 4
1410
align 4
1401
proc transmit stdcall bufferptr, buffersize
1411
proc transmit stdcall bufferptr
Line 1402... Line 1412...
1402
 
1412
 
1403
        pushf
1413
        pushf
Line -... Line 1414...
-
 
1414
        cli
1404
        cli
1415
 
1405
 
1416
        mov     esi, [bufferptr]
1406
        DEBUGF  1,"Transmitting packet, buffer:%x, size:%u\n", [bufferptr], [buffersize]
1417
        DEBUGF  1,"Transmitting packet, buffer:%x, size:%u\n", [bufferptr], [esi + NET_BUFF.length]
1407
        mov     eax, [bufferptr]
1418
        lea     eax, [esi + NET_BUFF.data]
1408
        DEBUGF  1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\
1419
        DEBUGF  1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\
1409
        [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\
1420
        [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\
Line 1410... Line 1421...
1410
        [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\
1421
        [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\
1411
        [eax+13]:2,[eax+12]:2
1422
        [eax+13]:2,[eax+12]:2
1412
 
1423
 
1413
        cmp     [buffersize], 1514
1424
        cmp     [esi + NET_BUFF.length], 1514
Line 1414... Line 1425...
1414
        ja      .fail
1425
        ja      .fail
1415
        cmp     [buffersize], 60
1426
        cmp     [esi + NET_BUFF.length], 60
1416
        jb      .fail
1427
        jb      .fail
Line 1422... Line 1433...
1422
        add     edi, eax
1433
        add     edi, eax
Line 1423... Line 1434...
1423
 
1434
 
1424
        cmp     [edi + tx_head.buff_addr_virt], 0
1435
        cmp     [edi + tx_head.buff_addr_virt], 0
Line 1425... Line 1436...
1425
        jne     .fail
1436
        jne     .fail
1426
 
1437
 
-
 
1438
        mov     eax, esi
1427
        mov     eax, [bufferptr]
1439
        mov     [edi + tx_head.buff_addr_virt], eax
1428
        mov     [edi + tx_head.buff_addr_virt], eax
1440
        add     eax, [eax + NET_BUFF.offset]
1429
        invoke  GetPhysAddr
1441
        invoke  GetPhysAddr
1430
        mov     [edi + tx_head.buff_addr], eax
1442
        mov     [edi + tx_head.buff_addr], eax
1431
        mov     ecx, [buffersize]
1443
        mov     ecx, [esi + NET_BUFF.length]
1432
        and     ecx, TX_CBITS_TX_BUF_SIZE
1444
        and     ecx, TX_CBITS_TX_BUF_SIZE
1433
        or      ecx,  0x00E08000
1445
        or      ecx,  0x00E08000
Line 1445... Line 1457...
1445
 
1457
 
Line 1446... Line 1458...
1446
        ;outw(IMRShadow,byIMR0); ;
1458
        ;outw(IMRShadow,byIMR0); ;
1447
 
1459
 
1448
; Update stats
1460
; Update stats
1449
        inc     [ebx + device.packets_tx]
1461
        inc     [ebx + device.packets_tx]
1450
        mov     ecx, [buffersize]
1462
        mov     ecx, [esi + NET_BUFF.length]
Line 1451... Line 1463...
1451
        add     dword [ebx + device.bytes_tx], ecx
1463
        add     dword [ebx + device.bytes_tx], ecx
1452
        adc     dword [ebx + device.bytes_tx + 4], 0
1464
        adc     dword [ebx + device.bytes_tx + 4], 0
1453
 
1465
 
1454
        DEBUGF  1,"Transmit OK\n"
1466
        DEBUGF  1,"Transmit OK\n"
Line 1455... Line 1467...
1455
        popf
1467
        popf
1456
        xor     eax, eax
1468
        xor     eax, eax
1457
        ret
1469
        ret
1458
 
1470
 
1459
  .fail:
1471
  .fail:
1460
        DEBUGF  2,"Transmit failed\n"
1472
        DEBUGF  2,"Transmit failed\n"
Line 1461... Line 1473...
1461
        invoke  KernelFree, [bufferptr]
1473
        invoke  NetFree, [bufferptr]
Line 1479... Line 1491...
1479
        push    ebx esi edi
1491
        push    ebx esi edi
Line 1480... Line 1492...
1480
 
1492
 
Line 1481... Line 1493...
1481
        DEBUGF  1,"INT\n"
1493
        DEBUGF  1,"INT\n"
1482
 
-
 
1483
; Find pointer of device which made IRQ occur
1494
 
1484
 
1495
; Find pointer of device which made IRQ occur
1485
        mov     ecx, [devices]
1496
        mov     ecx, [devices]
1486
        test    ecx, ecx
1497
        test    ecx, ecx
1487
        jz      .nothing
1498
        jz      .nothing
Line 1504... Line 1515...
1504
        xor     eax, eax
1515
        xor     eax, eax
Line 1505... Line 1516...
1505
 
1516
 
Line 1506... Line -...
1506
        ret                             ; If no device was found, abort (The irq was probably for a device, not registered to this driver)
-
 
1507
 
1517
        ret                             ; If no device was found, abort (The irq was probably for a device, not registered to this driver)
1508
 
-
 
1509
 
1518
 
Line 1510... Line 1519...
1510
  .got_it:
1519
 
Line 1511... Line 1520...
1511
 
1520
  .got_it:
Line 1519... Line 1528...
1519
        push    ebx
1528
        push    ebx
1520
  .more_RX:
1529
  .more_RX:
1521
        pop     ebx
1530
        pop     ebx
Line 1522... Line 1531...
1522
 
1531
 
1523
; Get the current descriptor pointer
-
 
1524
 
1532
; Get the current descriptor pointer
1525
        movzx   eax, [ebx + device.cur_rx]
1533
        movzx   eax, [ebx + device.cur_rx]
1526
        mov     ecx, sizeof.rx_head
1534
        mov     ecx, sizeof.rx_head
1527
        mul     ecx
1535
        mul     ecx
1528
        lea     edi, [ebx + device.rx_ring]
1536
        lea     edi, [ebx + device.rx_ring]
Line 1529... Line 1537...
1529
        add     edi, eax
1537
        add     edi, eax
1530
 
-
 
1531
; Check it's status
1538
 
1532
 
1539
; Check it's status
Line 1533... Line 1540...
1533
        test    [edi + rx_head.status], RX_SBITS_OWN_BIT
1540
        test    [edi + rx_head.status], RX_SBITS_OWN_BIT
Line 1534... Line 1541...
1534
        jnz     .not_bit_own
1541
        jnz     .not_RX
Line 1535... Line 1542...
1535
 
1542
 
1536
        DEBUGF  1, "Packet status = 0x%x\n", [edi + rx_head.status]
-
 
1537
 
1543
        DEBUGF  1, "Packet status = 0x%x\n", [edi + rx_head.status]
1538
; TODO: check error bits
1544
 
1539
 
1545
; TODO: check error bits
1540
; get length
1546
 
Line 1541... Line 1547...
1541
 
1547
; get length
1542
        mov     ecx, [edi + rx_head.status]
-
 
1543
        and     ecx, RX_SBITS_FRAME_LENGTH
1548
        mov     ecx, [edi + rx_head.status]
1544
        shr     ecx, 16
1549
        and     ecx, RX_SBITS_FRAME_LENGTH
1545
        sub     ecx, 4  ; We dont want CRC
1550
        shr     ecx, 16
Line 1546... Line 1551...
1546
 
1551
        sub     ecx, 4                          ; We dont want CRC
1547
; Update stats
-
 
1548
 
1552
 
1549
        add     dword [ebx + device.bytes_rx], ecx
1553
; Update stats
1550
        adc     dword [ebx + device.bytes_rx + 4], 0
-
 
1551
        inc     [ebx + device.packets_rx]
1554
        add     dword [ebx + device.bytes_rx], ecx
-
 
1555
        adc     dword [ebx + device.bytes_rx + 4], 0
1552
 
1556
        inc     [ebx + device.packets_rx]
-
 
1557
 
-
 
1558
; Push packet pointer, kernel will need it..
Line 1553... Line 1559...
1553
; Push packet size and pointer, kernel will need it..
1559
        push    ebx
1554
 
-
 
1555
        push    ebx
1560
        push    .more_RX                        ; return ptr
1556
        push    .more_RX        ; return ptr
1561
        mov     eax, [edi + rx_head.buff_addr_virt]
1557
 
1562
        push    eax
1558
        push    ecx             ; full packet size
1563
        mov     [eax + NET_BUFF.length], ecx
1559
        push    [edi + rx_head.buff_addr_virt]
1564
        mov     [eax + NET_BUFF.device], ebx
-
 
1565
        mov     [eax + NET_BUFF.offset], NET_BUFF.data
1560
 
1566
 
1561
; reset the RX descriptor
1567
; reset the RX descriptor
Line 1562... Line 1568...
1562
 
1568
        push    edi
1563
        push    edi
-
 
1564
        invoke  KernelAlloc, PKT_BUF_SZ
1569
        invoke  NetAlloc, PKT_BUF_SZ+NET_BUFF.data
1565
        pop     edi
1570
        pop     edi
Line 1566... Line 1571...
1566
        mov     [edi + rx_head.buff_addr_virt], eax
1571
        mov     [edi + rx_head.buff_addr_virt], eax
-
 
1572
        invoke  GetPhysAddr
Line 1567... Line -...
1567
        invoke  GetPhysAddr
-
 
1568
        mov     [edi + rx_head.buff_addr], eax
-
 
1569
        mov     [edi + rx_head.status], RX_SBITS_OWN_BIT
-
 
1570
 
1573
        add     eax, NET_BUFF.data
1571
; Use next descriptor next time
-
 
1572
 
1574
        mov     [edi + rx_head.buff_addr], eax
Line 1573... Line 1575...
1573
        inc     [ebx + device.cur_rx]
1575
        mov     [edi + rx_head.status], RX_SBITS_OWN_BIT
1574
        and     [ebx + device.cur_rx], RX_RING_SIZE - 1
1576
 
Line 1600... Line 1602...
1600
 
1602
 
Line 1601... Line 1603...
1601
        DEBUGF  1,"Freeing buffer 0x%x\n", [edi + tx_head.buff_addr_virt]
1603
        DEBUGF  1,"Freeing buffer 0x%x\n", [edi + tx_head.buff_addr_virt]
1602
 
1604
 
1603
        push    [edi + tx_head.buff_addr_virt]
1605
        push    [edi + tx_head.buff_addr_virt]
Line 1604... Line 1606...
1604
        mov     [edi + tx_head.buff_addr_virt], 0
1606
        mov     [edi + tx_head.buff_addr_virt], 0
1605
        invoke  KernelFree
1607
        invoke  NetFree
Line 1606... Line 1608...
1606
 
1608
 
Line 1607... Line 1609...
1607
        inc     [ebx + device.last_tx]
1609
        inc     [ebx + device.last_tx]
Line 1608... Line 1610...
1608
        and     [ebx + device.last_tx], TX_RING_SIZE - 1
1610
        and     [ebx + device.last_tx], TX_RING_SIZE - 1
1609
 
1611
 
1610
        jmp     .loop_tx
1612
        jmp     .loop_tx
1611
 
1613
 
1612
  .not_TX:
1614
  .not_TX:
1613
 
1615
 
1614
        ; On Rhine-II, Bit 3 indicates Tx descriptor write-back race.
1616
        ; On Rhine-II, Bit 3 indicates Tx descriptor write-back race.
1615
if 0
1617
if 0
1616
        cmp     [ebx + device.chip_id], 0x3065 ;if (tp->chip_id == 0x3065)
1618
        cmp     [ebx + device.chip_id], 0x3065
1617
        jne     @f
1619
        jne     @f
1618
        push    ax
1620
        push    ax
1619
        xor     eax, eax
1621
        xor     eax, eax