Subversion Repositories Kolibri OS

Rev

Rev 2544 | Blame | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                                 ;;
  3. ;; Copyright (C) KolibriOS team 2004-2010. All rights reserved.    ;;
  4. ;; Distributed under terms of the GNU General Public License       ;;
  5. ;;                                                                 ;;
  6. ;;  RTL8169 driver for KolibriOS                                   ;;
  7. ;;                                                                 ;;
  8. ;;  Copyright 2007 mike.dld,                                       ;;
  9. ;;   mike.dld@gmail.com                                            ;;
  10. ;;                                                                 ;;
  11. ;;  Version 0.1  11 February 2007                                  ;;
  12. ;;  Version 0.2  3 August 2010 - port to net branch by hidnplayr   ;;
  13. ;;  Version 0.3  31 Januari 2011 - bugfixes by hidnplayr           ;;
  14. ;;                                                                 ;;
  15. ;;  References:                                                    ;;
  16. ;;    r8169.c - linux driver (etherboot project)                   ;;
  17. ;;                                                                 ;;
  18. ;;          GNU GENERAL PUBLIC LICENSE                             ;;
  19. ;;             Version 2, June 1991                                ;;
  20. ;;                                                                 ;;
  21. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  22.  
  23. format MS COFF
  24.  
  25.         API_VERSION             =   0x01000100
  26.         DRIVER_VERSION          =   5
  27.  
  28.         MAX_DEVICES             =   16
  29.  
  30.         DEBUG                   =   1
  31.         __DEBUG__               =   1
  32.         __DEBUG_LEVEL__         =   1
  33.  
  34.         NUM_TX_DESC             =   4
  35.         NUM_RX_DESC             =   4
  36.  
  37. include 'proc32.inc'
  38. include 'imports.inc'
  39. include 'fdo.inc'
  40. include 'netdrv.inc'
  41.  
  42. public START
  43. public service_proc
  44. public version
  45.  
  46.  
  47.         REG_MAC0               =   0x0 ; Ethernet hardware address
  48.         REG_MAR0               =   0x8 ; Multicast filter
  49.         REG_TxDescStartAddr    =   0x20
  50.         REG_TxHDescStartAddr   =   0x28
  51.         REG_FLASH              =   0x30
  52.         REG_ERSR               =   0x36
  53.         REG_ChipCmd            =   0x37
  54.         REG_TxPoll             =   0x38
  55.         REG_IntrMask           =   0x3C
  56.         REG_IntrStatus         =   0x3E
  57.         REG_TxConfig           =   0x40
  58.         REG_RxConfig           =   0x44
  59.         REG_RxMissed           =   0x4C
  60.         REG_Cfg9346            =   0x50
  61.         REG_Config0            =   0x51
  62.         REG_Config1            =   0x52
  63.         REG_Config2            =   0x53
  64.         REG_Config3            =   0x54
  65.         REG_Config4            =   0x55
  66.         REG_Config5            =   0x56
  67.         REG_MultiIntr          =   0x5C
  68.         REG_PHYAR              =   0x60
  69.         REG_TBICSR             =   0x64
  70.         REG_TBI_ANAR           =   0x68
  71.         REG_TBI_LPAR           =   0x6A
  72.         REG_PHYstatus          =   0x6C
  73.         REG_RxMaxSize          =   0xDA
  74.         REG_CPlusCmd           =   0xE0
  75.         REG_RxDescStartAddr    =   0xE4
  76.         REG_ETThReg            =   0xEC
  77.         REG_FuncEvent          =   0xF0
  78.         REG_FuncEventMask      =   0xF4
  79.         REG_FuncPresetState    =   0xF8
  80.         REG_FuncForceEvent     =   0xFC
  81.  
  82.         ; InterruptStatusBits
  83.         ISB_SYSErr             =   0x8000
  84.         ISB_PCSTimeout         =   0x4000
  85.         ISB_SWInt              =   0x0100
  86.         ISB_TxDescUnavail      =   0x80
  87.         ISB_RxFIFOOver         =   0x40
  88.         ISB_LinkChg            =   0x20
  89.         ISB_RxOverflow         =   0x10
  90.         ISB_TxErr              =   0x08
  91.         ISB_TxOK               =   0x04
  92.         ISB_RxErr              =   0x02
  93.         ISB_RxOK               =   0x01
  94.  
  95.         ; RxStatusDesc
  96.         SD_RxRES               =   0x00200000
  97.         SD_RxCRC               =   0x00080000
  98.         SD_RxRUNT              =   0x00100000
  99.         SD_RxRWT               =   0x00400000
  100.  
  101.         ; ChipCmdBits
  102.         CMD_Reset              =   0x10
  103.         CMD_RxEnb              =   0x08
  104.         CMD_TxEnb              =   0x04
  105.         CMD_RxBufEmpty         =   0x01
  106.  
  107.         ; Cfg9346Bits
  108.         CFG_9346_Lock          =   0x00
  109.         CFG_9346_Unlock        =   0xC0
  110.  
  111.         ; rx_mode_bits
  112.         RXM_AcceptErr          =   0x20
  113.         RXM_AcceptRunt         =   0x10
  114.         RXM_AcceptBroadcast    =   0x08
  115.         RXM_AcceptMulticast    =   0x04
  116.         RXM_AcceptMyPhys       =   0x02
  117.         RXM_AcceptAllPhys      =   0x01
  118.  
  119.         ; RxConfigBits
  120.         RXC_FIFOShift          =   13
  121.         RXC_DMAShift           =   8
  122.  
  123.         ; TxConfigBits
  124.         TXC_InterFrameGapShift =   24
  125.         TXC_DMAShift           =   8    ; DMA burst value (0-7) is shift this many bits
  126.  
  127.         ; PHYstatus
  128.         PHYS_TBI_Enable        =   0x80
  129.         PHYS_TxFlowCtrl        =   0x40
  130.         PHYS_RxFlowCtrl        =   0x20
  131.         PHYS_1000bpsF          =   0x10
  132.         PHYS_100bps            =   0x08
  133.         PHYS_10bps             =   0x04
  134.         PHYS_LinkStatus        =   0x02
  135.         PHYS_FullDup           =   0x01
  136.  
  137.         ; GIGABIT_PHY_registers
  138.         PHY_CTRL_REG           =   0
  139.         PHY_STAT_REG           =   1
  140.         PHY_AUTO_NEGO_REG      =   4
  141.         PHY_1000_CTRL_REG      =   9
  142.  
  143.         ; GIGABIT_PHY_REG_BIT
  144.         PHY_Restart_Auto_Nego  =   0x0200
  145.         PHY_Enable_Auto_Nego   =   0x1000
  146.  
  147.         ; PHY_STAT_REG = 1;
  148.         PHY_Auto_Neco_Comp     =   0x0020
  149.  
  150.         ; PHY_AUTO_NEGO_REG = 4;
  151.         PHY_Cap_10_Half        =   0x0020
  152.         PHY_Cap_10_Full        =   0x0040
  153.         PHY_Cap_100_Half       =   0x0080
  154.         PHY_Cap_100_Full       =   0x0100
  155.  
  156.         ; PHY_1000_CTRL_REG = 9;
  157.         PHY_Cap_1000_Full      =   0x0200
  158.         PHY_Cap_1000_Half      =   0x0100
  159.  
  160.         PHY_Cap_PAUSE          =   0x0400
  161.         PHY_Cap_ASYM_PAUSE     =   0x0800
  162.  
  163.         PHY_Cap_Null           =   0x0
  164.  
  165.         ; _MediaType
  166.         MT_10_Half             =   0x01
  167.         MT_10_Full             =   0x02
  168.         MT_100_Half            =   0x04
  169.         MT_100_Full            =   0x08
  170.         MT_1000_Full           =   0x10
  171.  
  172.         ; _TBICSRBit
  173.         TBI_LinkOK             =   0x02000000
  174.  
  175.         ; _DescStatusBit
  176.         DSB_OWNbit             =   0x80000000
  177.         DSB_EORbit             =   0x40000000
  178.         DSB_FSbit              =   0x20000000
  179.         DSB_LSbit              =   0x10000000
  180.  
  181.         RX_BUF_SIZE             =   1536    ; Rx Buffer size
  182.  
  183.  
  184. ETH_ALEN               =   6
  185. ETH_HLEN               =   (2 * ETH_ALEN + 2)
  186. ETH_ZLEN               =   60 ; 60 + 4bytes auto payload for
  187.                                       ; mininmum 64bytes frame length
  188.  
  189. ; MAC address length
  190. MAC_ADDR_LEN        =   6
  191.  
  192. ; max supported gigabit ethernet frame size -- must be at least (dev->mtu+14+4)
  193. MAX_ETH_FRAME_SIZE  =   1536
  194.  
  195. TX_FIFO_THRESH      =   256     ; In bytes
  196.  
  197. RX_FIFO_THRESH      =   7       ; 7 means NO threshold, Rx buffer level before first PCI xfer
  198. RX_DMA_BURST        =   7       ; Maximum PCI burst, '6' is 1024
  199. TX_DMA_BURST        =   7       ; Maximum PCI burst, '6' is 1024
  200. ETTh                =   0x3F    ; 0x3F means NO threshold
  201.  
  202. EarlyTxThld         =   0x3F    ; 0x3F means NO early transmit
  203. RxPacketMaxSize     =   0x0800  ; Maximum size supported is 16K-1
  204. InterFrameGap       =   0x03    ; 3 means InterFrameGap = the shortest one
  205.  
  206. HZ                  =   1000
  207.  
  208. RTL_MIN_IO_SIZE     =   0x80
  209. TX_TIMEOUT          =   (6*HZ)
  210.  
  211. TIMER_EXPIRE_TIME =   100
  212.  
  213. ETH_HDR_LEN         =   14
  214. DEFAULT_MTU         =   1500
  215. DEFAULT_RX_BUF_LEN  =   1536
  216.  
  217.  
  218. ;#ifdef JUMBO_FRAME_SUPPORT
  219. ;#define MAX_JUMBO_FRAME_MTU    ( 10000 )
  220. ;#define MAX_RX_SKBDATA_SIZE    ( MAX_JUMBO_FRAME_MTU + ETH_HDR_LEN )
  221. ;#else
  222. MAX_RX_SKBDATA_SIZE =   1600
  223. ;#endif                         //end #ifdef JUMBO_FRAME_SUPPORT
  224.  
  225. MCFG_METHOD_01       =   0x01
  226. MCFG_METHOD_02       =   0x02
  227. MCFG_METHOD_03       =   0x03
  228. MCFG_METHOD_04       =   0x04
  229. MCFG_METHOD_05       =   0x05
  230. MCFG_METHOD_11       =   0x0b
  231. MCFG_METHOD_12       =   0x0c
  232. MCFG_METHOD_13       =   0x0d
  233. MCFG_METHOD_14       =   0x0e
  234. MCFG_METHOD_15       =   0x0f
  235.  
  236. PCFG_METHOD_1       =   0x01    ; PHY Reg 0x03 bit0-3 == 0x0000
  237. PCFG_METHOD_2       =   0x02    ; PHY Reg 0x03 bit0-3 == 0x0001
  238. PCFG_METHOD_3       =   0x03    ; PHY Reg 0x03 bit0-3 == 0x0002
  239.  
  240. virtual at 0
  241.   tx_desc:
  242.   .status    dd ?
  243.   .vlan_tag  dd ?
  244.   .buf_addr  dq ?
  245.   .size = $
  246.   rb    (NUM_TX_DESC-1)*tx_desc.size
  247.   .buf_soft_addr        dd ?
  248. end virtual
  249.  
  250. virtual at 0
  251.   rx_desc:
  252.   .status    dd ?
  253.   .vlan_tag  dd ?
  254.   .buf_addr  dq ?
  255.   .size = $
  256.   rb    (NUM_RX_DESC-1)*rx_desc.size
  257.   .buf_soft_addr        dd ?
  258. end virtual
  259.  
  260. virtual at ebx
  261.  
  262.         device:
  263.  
  264.         ETH_DEVICE
  265.  
  266.         .io_addr        dd ?
  267.         .pci_bus        db ?
  268.         .pci_dev        db ?
  269.         .irq_line       db ?
  270.  
  271.         tpc:
  272.         .mmio_addr      dd ? ; memory map physical address
  273.         .chipset        dd ?
  274.         .pcfg           dd ?
  275.         .mcfg           dd ?
  276.         .cur_rx         dd ? ; Index into the Rx descriptor buffer of next Rx pkt
  277.         .cur_tx         dd ? ; Index into the Tx descriptor buffer of next Rx pkt
  278.         .TxDescArrays   dd ? ; Index of Tx Descriptor buffer
  279.         .RxDescArrays   dd ? ; Index of Rx Descriptor buffer
  280.         .TxDescArray    dd ? ; Index of 256-alignment Tx Descriptor buffer
  281.         .RxDescArray    dd ? ; Index of 256-alignment Rx Descriptor buffer
  282.  
  283.         rb 256-(($ - device) and 255)              ;        align 256
  284.         tx_ring rb NUM_TX_DESC * tx_desc.size * 2
  285.  
  286.         rb 256-(($ - device) and 255)              ;        align 256
  287.         rx_ring rb NUM_RX_DESC * rx_desc.size * 2
  288.  
  289.         device_size = $ - device
  290.  
  291. end virtual
  292.  
  293. intr_mask = ISB_LinkChg or ISB_RxOverflow or ISB_RxFIFOOver or ISB_TxErr or ISB_TxOK or ISB_RxErr or ISB_RxOK
  294. rx_config = (RX_FIFO_THRESH shl RXC_FIFOShift) or (RX_DMA_BURST shl RXC_DMAShift) or 0x0000000E
  295.  
  296.  
  297. macro   udelay msec {
  298.  
  299.         push    esi
  300.         mov     esi, msec
  301.         call    Sleep
  302.         pop     esi
  303.  
  304. }
  305.  
  306. macro   WRITE_GMII_REG  RegAddr, value {
  307.  
  308.         set_io  REG_PHYAR
  309.         if      value eq ax
  310.         and     eax, 0x0000ffff
  311.         or      eax, 0x80000000 + (RegAddr shl 16)
  312.         else
  313.         mov     eax, 0x80000000 + (RegAddr shl 16) + value
  314.         end if
  315.         out     dx, eax
  316.  
  317.         call    PHY_WAIT
  318. }
  319.  
  320. macro   READ_GMII_REG  RegAddr {
  321.  
  322. local   .error, .done
  323.  
  324.         set_io  REG_PHYAR
  325.         mov     eax, RegAddr shl 16
  326.         out     dx, eax
  327.  
  328.         call    PHY_WAIT
  329.         jz      .error
  330.  
  331.         in      eax, dx
  332.         and     eax, 0xFFFF
  333.         jmp     .done
  334.  
  335.   .error:
  336.         or      eax, -1
  337.   .done:
  338. }
  339.  
  340. align 4
  341. PHY_WAIT:       ; io addr must already be set to REG_PHYAR
  342.  
  343.         udelay  1        ;;;1000
  344.  
  345.         push    ecx
  346.         mov     ecx, 2000
  347.         ; Check if the RTL8169 has completed writing/reading to the specified MII register
  348.     @@:
  349.         in      eax, dx
  350.         test    eax, 0x80000000
  351.         jz      .exit
  352.         udelay  1        ;;;100
  353.         loop    @b
  354.   .exit:
  355.         pop     ecx
  356.         ret
  357.  
  358.  
  359.  
  360. section '.flat' code readable align 16
  361.  
  362. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  363. ;;                        ;;
  364. ;; proc START             ;;
  365. ;;                        ;;
  366. ;; (standard driver proc) ;;
  367. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  368.  
  369. align 4
  370. proc START stdcall, state:dword
  371.  
  372.         cmp [state], 1
  373.         jne .exit
  374.  
  375.   .entry:
  376.  
  377.         DEBUGF  2,"Loading rtl8169 driver\n"
  378.         stdcall RegService, my_service, service_proc
  379.         ret
  380.  
  381.   .fail:
  382.   .exit:
  383.         xor eax, eax
  384.         ret
  385.  
  386. endp
  387.  
  388.  
  389. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  390. ;;                        ;;
  391. ;; proc SERVICE_PROC      ;;
  392. ;;                        ;;
  393. ;; (standard driver proc) ;;
  394. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  395.  
  396. align 4
  397. proc service_proc stdcall, ioctl:dword
  398.  
  399.         mov     edx, [ioctl]
  400.         mov     eax, [IOCTL.io_code]
  401.  
  402. ;------------------------------------------------------
  403.  
  404.         cmp     eax, 0 ;SRV_GETVERSION
  405.         jne     @F
  406.  
  407.         cmp     [IOCTL.out_size], 4
  408.         jl      .fail
  409.         mov     eax, [IOCTL.output]
  410.         mov     [eax], dword API_VERSION
  411.  
  412.         xor     eax, eax
  413.         ret
  414.  
  415. ;------------------------------------------------------
  416.   @@:
  417.         cmp     eax, 1 ;SRV_HOOK
  418.         jne     .fail
  419.  
  420.         cmp     [IOCTL.inp_size], 3                     ; Data input must be at least 3 bytes
  421.         jl      .fail
  422.  
  423.         mov     eax, [IOCTL.input]
  424.         cmp     byte [eax], 1                           ; 1 means device number and bus number (pci) are given
  425.         jne     .fail                                   ; other types arent supported for this card yet
  426.  
  427. ; check if the device is already listed
  428.  
  429.         mov     esi, device_list
  430.         mov     ecx, [devices]
  431.         test    ecx, ecx
  432.         jz      .firstdevice
  433.  
  434. ;        mov     eax, [IOCTL.input]                     ; get the pci bus and device numbers
  435.         mov     ax , [eax+1]                            ;
  436.   .nextdevice:
  437.         mov     ebx, [esi]
  438.         cmp     ax , word [device.pci_bus]              ; compare with pci and device num in device list (notice the usage of word instead of byte)
  439.         je      .find_devicenum                         ; Device is already loaded, let's find it's device number
  440.         add     esi, 4
  441.         loop    .nextdevice
  442.  
  443.  
  444. ; This device doesnt have its own eth_device structure yet, lets create one
  445.   .firstdevice:
  446.         cmp     [devices], MAX_DEVICES                  ; First check if the driver can handle one more card
  447.         jge     .fail
  448.  
  449.         allocate_and_clear ebx, device_size, .fail      ; Allocate memory to put the device structure in
  450.  
  451. ; Fill in the direct call addresses into the struct
  452.  
  453.         mov     [device.reset], reset
  454.         mov     [device.transmit], transmit
  455.         mov     [device.get_MAC], read_mac
  456.         mov     [device.set_MAC], write_mac
  457.         mov     [device.unload], unload
  458.         mov     [device.name], my_service
  459.  
  460. ; save the pci bus and device numbers
  461.  
  462.         mov     eax, [IOCTL.input]
  463.         mov     cl , [eax+1]
  464.         mov     [device.pci_bus], cl
  465.         mov     cl , [eax+2]
  466.         mov     [device.pci_dev], cl
  467.  
  468. ; Now, it's time to find the base io addres of the PCI device
  469.  
  470.         find_io [device.pci_bus], [device.pci_dev], [device.io_addr]
  471.         mov     eax, [device.io_addr]
  472.         mov     [tpc.mmio_addr], eax
  473.  
  474. ; We've found the io address, find IRQ now
  475.  
  476.         find_irq [device.pci_bus], [device.pci_dev], [device.irq_line]
  477.  
  478.         DEBUGF  2,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\
  479.         [device.pci_dev]:1,[device.pci_bus]:1,[device.irq_line]:1,[device.io_addr]:8
  480.  
  481. ; Ok, the eth_device structure is ready, let's probe the device
  482. ; Because initialization fires IRQ, IRQ handler must be aware of this device
  483.         mov     eax, [devices]                                          ; Add the device structure to our device list
  484.         mov     [device_list+4*eax], ebx                                ; (IRQ handler uses this list to find device)
  485.         inc     [devices]                                               ;
  486.  
  487.         call    probe                                                   ; this function will output in eax
  488.         test    eax, eax
  489.         jnz     .err2                                                   ; If an error occured, exit
  490.  
  491.  
  492.         mov     [device.type], NET_TYPE_ETH
  493.         call    NetRegDev
  494.  
  495.         cmp     eax, -1
  496.         je      .destroy
  497.  
  498.         ret
  499.  
  500. ; If the device was already loaded, find the device number and return it in eax
  501.  
  502.   .find_devicenum:
  503.         DEBUGF  2,"Trying to find device number of already registered device\n"
  504.         call    NetPtrToNum                                             ; This kernel procedure converts a pointer to device struct in ebx
  505.                                                                         ; into a device number in edi
  506.         mov     eax, edi                                                ; Application wants it in eax instead
  507.         DEBUGF  2,"Kernel says: %u\n", eax
  508.         ret
  509.  
  510. ; If an error occured, remove all allocated data and exit (returning -1 in eax)
  511.  
  512.   .destroy:
  513.         ; todo: reset device into virgin state
  514.  
  515.   .err2:
  516.         dec     [devices]
  517.   .err:
  518.         DEBUGF  2,"removing device structure\n"
  519.         stdcall KernelFree, ebx
  520.  
  521.  
  522.   .fail:
  523.         or      eax, -1
  524.         ret
  525.  
  526. ;------------------------------------------------------
  527. endp
  528.  
  529.  
  530. align 4
  531. unload:
  532.  
  533.         ret
  534.  
  535.  
  536. align 4
  537. init_board:
  538.  
  539.         DEBUGF  1,"init_board\n"
  540.  
  541.         make_bus_master [device.pci_bus], [device.pci_dev]
  542.  
  543.         ; Soft reset the chip
  544.         set_io  0
  545.         set_io  REG_ChipCmd
  546.         mov     al, CMD_Reset
  547.         out     dx, al
  548.  
  549.         ; Check that the chip has finished the reset
  550.         mov     ecx, 1000
  551.         set_io  REG_ChipCmd
  552.     @@: in      al, dx
  553.         test    al, CMD_Reset
  554.         jz      @f
  555.         udelay  10
  556.         loop    @b
  557.     @@:
  558.         ; identify config method
  559.         set_io  REG_TxConfig
  560.         in      eax, dx
  561.         and     eax, 0x7c800000
  562.         DEBUGF  1,"init_board: TxConfig & 0x7c800000 = 0x%x\n", eax
  563.         mov     esi, mac_info-8
  564.     @@: add     esi, 8
  565.         mov     ecx, eax
  566.         and     ecx, [esi]
  567.         cmp     ecx, [esi]
  568.         jne     @b
  569.         mov     eax, [esi+4]
  570.         mov     [tpc.mcfg], eax
  571.  
  572.         mov     [tpc.pcfg], PCFG_METHOD_3
  573.         READ_GMII_REG 3
  574.         and     al, 0x0f
  575.         or      al, al
  576.         jnz     @f
  577.         mov     [tpc.pcfg], PCFG_METHOD_1
  578.         jmp     .pconf
  579.     @@: dec     al
  580.         jnz     .pconf
  581.         mov     [tpc.pcfg], PCFG_METHOD_2
  582.   .pconf:
  583.  
  584.         ; identify chip attached to board
  585.         mov     ecx, 10
  586.         mov     eax, [tpc.mcfg]
  587.     @@: dec     ecx
  588.         js      @f
  589.         cmp     eax, [rtl_chip_info+ecx*8]
  590.         jne     @b
  591.         mov     [tpc.chipset], ecx
  592.         jmp     .match
  593.     @@:
  594.         ; if unknown chip, assume array element #0, original RTL-8169 in this case
  595.         DEBUGF  1,"init_board: PCI device: unknown chip version, assuming RTL-8169\n"
  596.         set_io  REG_TxConfig
  597.         in      eax, dx
  598.         DEBUGF  1,"init_board: PCI device: TxConfig = 0x%x\n", eax
  599.  
  600.         mov     [tpc.chipset],  0
  601.  
  602.         xor     eax, eax
  603.         inc     eax
  604.         ret
  605.  
  606.   .match:
  607.         DEBUGF  1,"init_board: chipset=%u\n", ecx
  608.         xor     eax,eax
  609.         ret
  610.  
  611.  
  612.  
  613. ;***************************************************************************
  614. ;   Function
  615. ;      probe
  616. ;   Description
  617. ;      Searches for an ethernet card, enables it and clears the rx buffer
  618. ;      If a card was found, it enables the ethernet -> TCPIP link
  619. ;   Destroyed registers
  620. ;      eax, ebx, ecx, edx
  621. ;
  622. ;***************************************************************************
  623. align 4
  624. probe:
  625.  
  626.         DEBUGF  1,"probe\n"
  627.  
  628.         call    init_board
  629.  
  630.         call    read_mac
  631.  
  632.         call    PHY_config
  633.  
  634. ;       DEBUGF  1,"K :   Set MAC Reg C+CR Offset 0x82h = 0x01h\n"
  635.         set_io  0
  636.         set_io  0x82
  637.         mov     al, 0x01
  638.         out     dx, al
  639.         cmp     [tpc.mcfg], MCFG_METHOD_03
  640.         jae     @f
  641. ;       DEBUGF  1,"K :   Set PCI Latency=0x40\n"
  642. ;       stdcall pci_write_config_byte,PCI_LATENCY_TIMER,0x40
  643.    @@:
  644.         cmp     [tpc.mcfg], MCFG_METHOD_02
  645.         jne     @f
  646. ;       DEBUGF  1,"K :   Set MAC Reg C+CR Offset 0x82h = 0x01h\n"
  647.         set_io  0x82
  648.         mov     al, 0x01
  649.         out     dx, al
  650. ;       DEBUGF  1,"K :   Set PHY Reg 0x0bh = 0x00h\n"
  651.         WRITE_GMII_REG 0x0b, 0x0000      ; w 0x0b 15 0 0
  652.     @@:
  653.         ; if TBI is not enabled
  654.         set_io  0
  655.         set_io  REG_PHYstatus
  656.         in      al, dx
  657.         test    al, PHYS_TBI_Enable
  658.         jz      .tbi_dis
  659.         READ_GMII_REG PHY_AUTO_NEGO_REG
  660.  
  661.         ; enable 10/100 Full/Half Mode, leave PHY_AUTO_NEGO_REG bit4:0 unchanged
  662.         and     eax, 0x0C1F
  663.         or      eax, PHY_Cap_10_Half or PHY_Cap_10_Full or PHY_Cap_100_Half or PHY_Cap_100_Full
  664.         WRITE_GMII_REG PHY_AUTO_NEGO_REG, ax
  665.  
  666.         ; enable 1000 Full Mode
  667.         WRITE_GMII_REG PHY_1000_CTRL_REG, PHY_Cap_1000_Full or PHY_Cap_1000_Half ; rtl8168
  668.  
  669.         ; Enable auto-negotiation and restart auto-nigotiation
  670.         WRITE_GMII_REG PHY_CTRL_REG, PHY_Enable_Auto_Nego or PHY_Restart_Auto_Nego
  671.  
  672.         udelay  100
  673.         mov     ecx, 10000
  674.         ; wait for auto-negotiation process
  675.     @@: dec     ecx
  676.         jz      @f
  677.         set_io  0
  678.         READ_GMII_REG PHY_STAT_REG
  679.         udelay  100
  680.         test    eax, PHY_Auto_Neco_Comp
  681.         jz      @b
  682.         set_io  REG_PHYstatus
  683.         in      al, dx
  684.         jmp     @f
  685.   .tbi_dis:
  686.         udelay  100
  687.     @@:
  688.  
  689.  
  690. ;***************************************************************************
  691. ;   Function
  692. ;      rt8169_reset
  693. ;   Description
  694. ;      Place the chip (ie, the ethernet card) into a virgin state
  695. ;   Destroyed registers
  696. ;      eax, ebx, ecx, edx
  697. ;
  698. ;***************************************************************************
  699. align 4
  700. reset:
  701.  
  702.         DEBUGF  1,"reset\n"
  703.  
  704.         lea     eax, [tx_ring]
  705.         mov     [tpc.TxDescArrays], eax
  706.         mov     [tpc.TxDescArray], eax
  707.  
  708.         lea     eax, [rx_ring]
  709.         mov     [tpc.RxDescArrays], eax
  710.         mov     [tpc.RxDescArray], eax
  711.  
  712.         call    init_ring
  713.         call    hw_start
  714.  
  715. ; clear packet/byte counters
  716.  
  717.         xor     eax, eax
  718.         lea     edi, [device.bytes_tx]
  719.         mov     ecx, 6
  720.         rep     stosd
  721.  
  722.         mov     [device.mtu], 1500
  723.  
  724.         xor     eax, eax
  725.         ret
  726.  
  727.  
  728.  
  729.  
  730.  
  731. align 4
  732. PHY_config:
  733.  
  734.         DEBUGF  1,"hw_PHY_config: priv.mcfg=%d, priv.pcfg=%d\n",[tpc.mcfg],[tpc.pcfg]
  735.  
  736.         cmp     [tpc.mcfg], MCFG_METHOD_04
  737.         jne     .not_4
  738.         set_io  0
  739. ;       WRITE_GMII_REG 0x1F, 0x0001
  740. ;       WRITE_GMII_REG 0x1b, 0x841e
  741. ;       WRITE_GMII_REG 0x0e, 0x7bfb
  742. ;       WRITE_GMII_REG 0x09, 0x273a
  743.         WRITE_GMII_REG 0x1F, 0x0002
  744.         WRITE_GMII_REG 0x01, 0x90D0
  745.         WRITE_GMII_REG 0x1F, 0x0000
  746.         jmp     .exit
  747.   .not_4:
  748.         cmp     [tpc.mcfg], MCFG_METHOD_02
  749.         je      @f
  750.         cmp     [tpc.mcfg], MCFG_METHOD_03
  751.         jne     .not_2_or_3
  752.     @@:
  753.         set_io  0
  754.         WRITE_GMII_REG 0x1F, 0x0001
  755.         WRITE_GMII_REG 0x15, 0x1000
  756.         WRITE_GMII_REG 0x18, 0x65C7
  757.         WRITE_GMII_REG 0x04, 0x0000
  758.         WRITE_GMII_REG 0x03, 0x00A1
  759.         WRITE_GMII_REG 0x02, 0x0008
  760.         WRITE_GMII_REG 0x01, 0x1020
  761.         WRITE_GMII_REG 0x00, 0x1000
  762.         WRITE_GMII_REG 0x04, 0x0800
  763.         WRITE_GMII_REG 0x04, 0x0000
  764.         WRITE_GMII_REG 0x04, 0x7000
  765.         WRITE_GMII_REG 0x03, 0xFF41
  766.         WRITE_GMII_REG 0x02, 0xDE60
  767.         WRITE_GMII_REG 0x01, 0x0140
  768.         WRITE_GMII_REG 0x00, 0x0077
  769.         WRITE_GMII_REG 0x04, 0x7800
  770.         WRITE_GMII_REG 0x04, 0x7000
  771.         WRITE_GMII_REG 0x04, 0xA000
  772.         WRITE_GMII_REG 0x03, 0xDF01
  773.         WRITE_GMII_REG 0x02, 0xDF20
  774.         WRITE_GMII_REG 0x01, 0xFF95
  775.         WRITE_GMII_REG 0x00, 0xFA00
  776.         WRITE_GMII_REG 0x04, 0xA800
  777.         WRITE_GMII_REG 0x04, 0xA000
  778.         WRITE_GMII_REG 0x04, 0xB000
  779.         WRITE_GMII_REG 0x03, 0xFF41
  780.         WRITE_GMII_REG 0x02, 0xDE20
  781.         WRITE_GMII_REG 0x01, 0x0140
  782.         WRITE_GMII_REG 0x00, 0x00BB
  783.         WRITE_GMII_REG 0x04, 0xB800
  784.         WRITE_GMII_REG 0x04, 0xB000
  785.         WRITE_GMII_REG 0x04, 0xF000
  786.         WRITE_GMII_REG 0x03, 0xDF01
  787.         WRITE_GMII_REG 0x02, 0xDF20
  788.         WRITE_GMII_REG 0x01, 0xFF95
  789.         WRITE_GMII_REG 0x00, 0xBF00
  790.         WRITE_GMII_REG 0x04, 0xF800
  791.         WRITE_GMII_REG 0x04, 0xF000
  792.         WRITE_GMII_REG 0x04, 0x0000
  793.         WRITE_GMII_REG 0x1F, 0x0000
  794.         WRITE_GMII_REG 0x0B, 0x0000
  795.         jmp     .exit
  796.   .not_2_or_3:
  797.         DEBUGF  1,"tpc.mcfg=%d, discard hw PHY config\n", [tpc.mcfg]
  798.   .exit:
  799.         ret
  800.  
  801.  
  802.  
  803. align 4
  804. set_rx_mode:
  805.  
  806.         DEBUGF  1,"set_rx_mode\n"
  807.  
  808.         ; IFF_ALLMULTI
  809.         ; Too many to filter perfectly -- accept all multicasts
  810.         set_io  0
  811.         set_io  REG_RxConfig
  812.         in      eax, dx
  813.         mov     ecx, [tpc.chipset]
  814.         and     eax, [rtl_chip_info + ecx * 8 + 4] ; RxConfigMask
  815.         or      eax, rx_config or (RXM_AcceptBroadcast or RXM_AcceptMulticast or RXM_AcceptMyPhys)
  816.         out     dx, eax
  817.  
  818.         ; Multicast hash filter
  819.         set_io  REG_MAR0 + 0
  820.         or      eax, -1
  821.         out     dx, eax
  822.         set_io  REG_MAR0 + 4
  823.         out     dx, eax
  824.  
  825.         ret
  826.  
  827.  
  828. align 4
  829. init_ring:
  830.  
  831.         DEBUGF  1,"init_ring\n"
  832.  
  833.         xor     eax, eax
  834.         mov     [tpc.cur_rx], eax
  835.         mov     [tpc.cur_tx], eax
  836.  
  837.         lea     edi, [tx_ring]
  838.         mov     ecx, (NUM_TX_DESC * tx_desc.size) / 4
  839.         rep     stosd
  840.  
  841.         lea     edi, [rx_ring]
  842.         mov     ecx, (NUM_RX_DESC * rx_desc.size) / 4
  843.         rep     stosd
  844.  
  845.         mov     edi, [tpc.RxDescArray]
  846.         mov     ecx, NUM_RX_DESC
  847.   .loop:
  848.         push    ecx
  849.         stdcall KernelAlloc, RX_BUF_SIZE
  850.         mov     [edi + rx_desc.buf_soft_addr], eax
  851.         call    GetPgAddr
  852.         mov     dword [edi + rx_desc.buf_addr], eax
  853.         mov     [edi + rx_desc.status], DSB_OWNbit or RX_BUF_SIZE
  854.         add     edi, rx_desc.size
  855.         pop     ecx
  856.         loop    .loop
  857.         or      [edi - rx_desc.size + rx_desc.status], DSB_EORbit
  858.  
  859.         ret
  860.  
  861.  
  862. align 4
  863. hw_start:
  864.  
  865.         DEBUGF  1,"hw_start\n"
  866.  
  867. ; attach int handler
  868.         movzx   eax, [device.irq_line]
  869.         DEBUGF  1,"Attaching int handler to irq %x\n", eax:1
  870.         stdcall AttachIntHandler, eax, int_handler, dword 0
  871.  
  872.         ; Soft reset the chip
  873.         set_io  0
  874.         set_io  REG_ChipCmd
  875.         mov     al, CMD_Reset
  876.         out     dx, al
  877.  
  878.         ; Check that the chip has finished the reset
  879.         mov     ecx, 1000
  880.         set_io  REG_ChipCmd
  881.     @@: in      al, dx
  882.         test    al, CMD_Reset
  883.         jz      @f
  884.         udelay  10
  885.         loop    @b
  886.     @@:
  887.  
  888.         set_io  REG_Cfg9346
  889.         mov     al, CFG_9346_Unlock
  890.         out     dx, al
  891.  
  892.         set_io  REG_ChipCmd
  893.         mov     al, CMD_TxEnb or CMD_RxEnb
  894.         out     dx, al
  895.  
  896.         set_io  REG_ETThReg
  897.         mov     al, ETTh
  898.         out     dx, al
  899.  
  900.         ; For gigabit rtl8169
  901.         set_io  REG_RxMaxSize
  902.         mov     ax, RxPacketMaxSize
  903.         out     dx, ax
  904.  
  905.         ; Set Rx Config register
  906.         set_io  REG_RxConfig
  907.         in      ax, dx
  908.         mov     ecx, [tpc.chipset]
  909.         and     eax, [rtl_chip_info + ecx * 8 + 4] ; RxConfigMask
  910.         or      eax, rx_config
  911.         out     dx, eax
  912.  
  913.         ; Set DMA burst size and Interframe Gap Time
  914.         set_io  REG_TxConfig
  915.         mov     eax, (TX_DMA_BURST shl TXC_DMAShift) or (InterFrameGap shl TXC_InterFrameGapShift)
  916.         out     dx, eax
  917.  
  918.         set_io  REG_CPlusCmd
  919.         in      ax, dx
  920.         out     dx, ax
  921.  
  922.         in      ax, dx
  923.         or      ax, 1 shl 3
  924.         cmp     [tpc.mcfg], MCFG_METHOD_02
  925.         jne     @f
  926.         cmp     [tpc.mcfg], MCFG_METHOD_03
  927.         jne     @f
  928.         or      ax,1 shl 14
  929.         DEBUGF  1,"Set MAC Reg C+CR Offset 0xE0: bit-3 and bit-14\n"
  930.         jmp     .set
  931.     @@:
  932.         DEBUGF  1,"Set MAC Reg C+CR Offset 0xE0: bit-3\n"
  933.   .set:
  934.         set_io  REG_CPlusCmd
  935.         out     dx, ax
  936.  
  937.         set_io  0xE2
  938. ;        mov     ax, 0x1517
  939. ;        out     dx, ax
  940. ;        mov     ax, 0x152a
  941. ;        out     dx, ax
  942. ;        mov     ax, 0x282a
  943. ;        out     dx, ax
  944.         xor     ax, ax
  945.         out     dx, ax
  946.  
  947.         xor     eax, eax
  948.         mov     [tpc.cur_rx], eax
  949.         lea     eax, [tx_ring]
  950.         GetRealAddr
  951.         set_io  REG_TxDescStartAddr
  952.         out     dx, eax
  953.  
  954.         lea     eax, [rx_ring]
  955.         GetRealAddr
  956.         set_io  REG_RxDescStartAddr
  957.         out     dx, eax
  958.  
  959.         set_io  REG_Cfg9346
  960.         mov     al, CFG_9346_Lock
  961.         out     dx, al
  962.  
  963.         udelay  10
  964.  
  965.         xor     eax, eax
  966.         set_io  REG_RxMissed
  967.         out     dx, eax
  968.  
  969.         call    set_rx_mode
  970.  
  971.         set_io  0
  972.         ; no early-rx interrupts
  973.         set_io  REG_MultiIntr
  974.         in      ax, dx
  975.         and     ax, 0xF000
  976.         out     dx, ax
  977.  
  978.         ; set interrupt mask
  979.         set_io  REG_IntrMask
  980.         mov     ax, intr_mask
  981.         out     dx, ax
  982.  
  983.         xor     eax, eax
  984.         ret
  985.  
  986.  
  987. align 4
  988. read_mac:
  989.  
  990.         set_io  0
  991.         set_io  REG_MAC0
  992.         xor     ecx, ecx
  993.         lea     edi, [device.mac]
  994.         mov     ecx, MAC_ADDR_LEN
  995.  
  996.         ; Get MAC address. FIXME: read EEPROM
  997.     @@: in      al, dx
  998.         stosb
  999.         inc     edx
  1000.         loop    @r
  1001.  
  1002.         DEBUGF  1,"MAC = %x-%x-%x-%x-%x-%x\n",[device.mac+0]:2,[device.mac+1]:2,[device.mac+2]:2,[device.mac+3]:2,[device.mac+4]:2,[device.mac+5]:2
  1003.  
  1004.         ret
  1005.  
  1006. align 4
  1007. write_mac:
  1008.  
  1009.         ret     6
  1010.  
  1011.  
  1012.  
  1013.  
  1014.  
  1015. ;***************************************************************************
  1016. ;   Function
  1017. ;      transmit
  1018. ;   Description
  1019. ;      Transmits a packet of data via the ethernet card
  1020. ;
  1021. ;   Destroyed registers
  1022. ;      eax, edx, esi, edi
  1023. ;
  1024. ;***************************************************************************
  1025. align 4
  1026. transmit:
  1027.  
  1028.         DEBUGF  1,"Transmitting packet, buffer:%x, size:%u\n", [esp+4], [esp+8]
  1029.         mov     eax, [esp+4]
  1030.         DEBUGF  1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\
  1031.         [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\
  1032.         [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\
  1033.         [eax+13]:2,[eax+12]:2
  1034.  
  1035.         cmp     dword [esp+8], MAX_ETH_FRAME_SIZE
  1036.         ja      .fail
  1037.  
  1038. ;----------------------------------
  1039. ; Find currentTX descriptor address
  1040.  
  1041.         mov     eax, tx_desc.size
  1042.         mul     [tpc.cur_tx]
  1043.         lea     esi, [eax + tx_ring]
  1044.  
  1045.         DEBUGF  1,"Using TX desc: %x\n", esi
  1046.  
  1047. ;---------------------------
  1048. ; Program the packet pointer
  1049.  
  1050.         mov     eax, [esp + 4]
  1051.         mov     [esi + tx_desc.buf_soft_addr], eax
  1052.         GetRealAddr
  1053.         mov     dword [esi + tx_desc.buf_addr], eax
  1054.  
  1055. ;------------------------
  1056. ; Program the packet size
  1057.  
  1058.         mov     eax, [esp + 8]
  1059.     @@: or      eax, DSB_OWNbit or DSB_FSbit or DSB_LSbit
  1060.         cmp     [tpc.cur_tx], NUM_TX_DESC - 1
  1061.         jne     @f
  1062.         or      eax, DSB_EORbit
  1063.     @@: mov     [esi + tx_desc.status], eax
  1064.  
  1065. ;-----------------------------------------
  1066. ; Set the polling bit (start transmission)
  1067.  
  1068.         set_io  0
  1069.         set_io  REG_TxPoll
  1070.         mov     al, 0x40     ; set polling bit
  1071.         out     dx, al
  1072.  
  1073. ;-----------------------
  1074. ; Update TX descriptor
  1075.  
  1076.         inc     [tpc.cur_tx]
  1077.         and     [tpc.cur_tx], NUM_TX_DESC - 1
  1078.  
  1079. ;-------------
  1080. ; Update stats
  1081.  
  1082.         inc     [device.packets_tx]
  1083.         mov     eax, [esp+8]
  1084.         add     dword [device.bytes_tx], eax
  1085.         adc     dword [device.bytes_tx + 4], 0
  1086.  
  1087.         xor     eax, eax
  1088.         ret     8
  1089.  
  1090.   .fail:
  1091.         DEBUGF  1,"transmit failed\n"
  1092.         or      eax, -1
  1093.         stdcall KernelFree, [esp+4]
  1094.         ret     8
  1095.  
  1096.  
  1097. ;;;DSB_OWNbit
  1098.  
  1099.  
  1100. ;;;;;;;;;;;;;;;;;;;;;;;
  1101. ;;                   ;;
  1102. ;; Interrupt handler ;;
  1103. ;;                   ;;
  1104. ;;;;;;;;;;;;;;;;;;;;;;;
  1105.  
  1106. align 4
  1107. int_handler:
  1108.  
  1109.         DEBUGF  1,"IRQ %x ",eax:2
  1110.  
  1111. ; find pointer of device wich made IRQ occur
  1112.  
  1113.         mov     ecx, [devices]
  1114.         test    ecx, ecx
  1115.         jz      .fail
  1116.         mov     esi, device_list
  1117.   .nextdevice:
  1118.         mov     ebx, dword [esi]
  1119.  
  1120.         set_io  0
  1121.         set_io  REG_IntrStatus
  1122.         in      ax, dx
  1123.  
  1124.         test    ax, ax
  1125.         jnz     .got_it
  1126.  
  1127.   .continue:
  1128.         add     esi, 4
  1129.         dec     ecx
  1130.         jnz     .nextdevice
  1131.  
  1132.         ret                                             ; If no device was found, abort (The irq was probably for a device, not registered to this driver)
  1133.  
  1134.   .got_it:
  1135.         DEBUGF  1,"IntrStatus = 0x%x\n",ax
  1136.  
  1137.         cmp     ax, 0xFFFF      ; if so, hardware is no longer present
  1138.         je      .fail
  1139.  
  1140. ;--------
  1141. ; Receive
  1142.  
  1143.         test    ax, ISB_RxOK
  1144.         jz      .no_rx
  1145.  
  1146.         push    ax
  1147.         push    ebx
  1148.  
  1149.   .check_more:
  1150.         pop     ebx
  1151.         DEBUGF  1,"ebx = 0x%x\n", ebx
  1152.         mov     eax, rx_desc.size
  1153.         mul     [tpc.cur_rx]
  1154.         lea     esi, [eax + rx_ring]
  1155.  
  1156.         DEBUGF  1,"RxDesc.status = 0x%x\n", [esi + rx_desc.status]
  1157.  
  1158.         mov     eax, [esi + rx_desc.status]
  1159.         test    eax, DSB_OWNbit ;;;
  1160.         jnz     .rx_return
  1161.  
  1162.         DEBUGF  1,"tpc.cur_rx = %u\n", [tpc.cur_rx]
  1163.  
  1164.         test    eax, SD_RxRES
  1165.         jnz     .rx_return      ;;;;; RX error!
  1166.  
  1167.         push    ebx
  1168.         push    .check_more
  1169.         and     eax, 0x00001FFF
  1170.         add     eax, -4                         ; we dont need CRC
  1171.         push    eax
  1172.         DEBUGF  1,"data length = %u\n", ax
  1173.  
  1174. ;-------------
  1175. ; Update stats
  1176.  
  1177.         add     dword [device.bytes_rx], eax
  1178.         adc     dword [device.bytes_rx + 4], 0
  1179.         inc     dword [device.packets_rx]
  1180.  
  1181.         push    [esi + rx_desc.buf_soft_addr]
  1182.  
  1183. ;----------------------
  1184. ; Allocate a new buffer
  1185.  
  1186.         stdcall KernelAlloc, RX_BUF_SIZE
  1187.         mov     [esi + rx_desc.buf_soft_addr], eax
  1188.         GetRealAddr
  1189.         mov     dword [esi + rx_desc.buf_addr], eax
  1190.  
  1191. ;---------------
  1192. ; re set OWN bit
  1193.  
  1194.         mov     eax, DSB_OWNbit or RX_BUF_SIZE
  1195.         cmp     [tpc.cur_rx], NUM_RX_DESC - 1
  1196.         jne     @f
  1197.         or      eax, DSB_EORbit
  1198.     @@: mov     [esi + rx_desc.status], eax
  1199.  
  1200. ;--------------
  1201. ; Update rx ptr
  1202.  
  1203.         inc     [tpc.cur_rx]
  1204.         and     [tpc.cur_rx], NUM_RX_DESC - 1
  1205.  
  1206.         jmp     EthReceiver
  1207.   .rx_return:
  1208.  
  1209.         pop     ax
  1210.   .no_rx:
  1211.  
  1212. ;---------
  1213. ; Transmit
  1214.  
  1215.         test    ax, ISB_TxOK
  1216.         jz      .no_tx
  1217.         push    ax
  1218.  
  1219.         DEBUGF  1,"TX ok!\n"
  1220.  
  1221.         mov     ecx, NUM_TX_DESC
  1222.         lea     esi, [tx_ring]
  1223.   .txloop:
  1224.         cmp     [esi+tx_desc.buf_soft_addr], 0
  1225.         jz      .maybenext
  1226.  
  1227.         test    [esi+tx_desc.status], DSB_OWNbit
  1228.         jnz     .maybenext
  1229.  
  1230.         push    ecx
  1231.         DEBUGF  1,"Freeing up TX desc: %x\n", esi
  1232.         stdcall KernelFree, [esi+tx_desc.buf_soft_addr]
  1233.         pop     ecx
  1234.         and     [esi+tx_desc.buf_soft_addr], 0
  1235.  
  1236.   .maybenext:
  1237.         add     esi, tx_desc.size
  1238.         dec     ecx
  1239.         jnz     .txloop
  1240.  
  1241.         pop     ax
  1242.   .no_tx:
  1243.  
  1244. ;-------
  1245. ; Finish
  1246.  
  1247.         set_io  0
  1248.         set_io  REG_IntrStatus
  1249.         out     dx, ax                  ; ACK all interrupts
  1250.  
  1251.   .fail:
  1252.         ret
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.  
  1259.  
  1260.  
  1261.  
  1262. ; End of code
  1263. align 4                                         ; Place all initialised data here
  1264.  
  1265. devices       dd 0
  1266. version       dd (DRIVER_VERSION shl 16) or (API_VERSION and 0xFFFF)
  1267. my_service    db 'RTL8169',0                    ; max 16 chars include zero
  1268.  
  1269. include_debug_strings                           ; All data wich FDO uses will be included here
  1270.  
  1271. rtl_chip_info dd \
  1272.   MCFG_METHOD_01, 0xff7e1880, \ ; RTL8169
  1273.   MCFG_METHOD_02, 0xff7e1880, \ ; RTL8169s/8110s
  1274.   MCFG_METHOD_03, 0xff7e1880, \ ; RTL8169s/8110s
  1275.   MCFG_METHOD_04, 0xff7e1880, \ ; RTL8169sb/8110sb
  1276.   MCFG_METHOD_05, 0xff7e1880, \ ; RTL8169sc/8110sc
  1277.   MCFG_METHOD_11, 0xff7e1880, \ ; RTL8168b/8111b   // PCI-E
  1278.   MCFG_METHOD_12, 0xff7e1880, \ ; RTL8168b/8111b   // PCI-E
  1279.   MCFG_METHOD_13, 0xff7e1880, \ ; RTL8101e         // PCI-E 8139
  1280.   MCFG_METHOD_14, 0xff7e1880, \ ; RTL8100e         // PCI-E 8139
  1281.   MCFG_METHOD_15, 0xff7e1880    ; RTL8100e         // PCI-E 8139
  1282.  
  1283. mac_info dd \
  1284.   0x38800000, MCFG_METHOD_15, \
  1285.   0x38000000, MCFG_METHOD_12, \
  1286.   0x34000000, MCFG_METHOD_13, \
  1287.   0x30800000, MCFG_METHOD_14, \
  1288.   0x30000000, MCFG_METHOD_11, \
  1289.   0x18000000, MCFG_METHOD_05, \
  1290.   0x10000000, MCFG_METHOD_04, \
  1291.   0x04000000, MCFG_METHOD_03, \
  1292.   0x00800000, MCFG_METHOD_02, \
  1293.   0x00000000, MCFG_METHOD_01    ; catch-all
  1294.  
  1295. name_01         db "RTL8169", 0
  1296. name_02_03      db "RTL8169s/8110s", 0
  1297. name_04         db "RTL8169sb/8110sb", 0
  1298. name_05         db "RTL8169sc/8110sc", 0
  1299. name_11_12      db "RTL8168b/8111b", 0  ; PCI-E
  1300. name_13         db "RTL8101e", 0        ; PCI-E 8139
  1301. name_14_15      db "RTL8100e", 0        ; PCI-E 8139
  1302.  
  1303.  
  1304. section '.data' data readable writable align 16 ; place all uninitialized data place here
  1305.  
  1306. device_list rd MAX_DEVICES                     ; This list contains all pointers to device structures the driver is handling
  1307.  
  1308.  
  1309.