Subversion Repositories Kolibri OS

Rev

Rev 3545 | Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                                 ;;
  3. ;; Copyright (C) KolibriOS team 2004-2012. All rights reserved.    ;;
  4. ;; Distributed under terms of the GNU General Public License       ;;
  5. ;;                                                                 ;;
  6. ;;          GNU GENERAL PUBLIC LICENSE                             ;;
  7. ;;             Version 2, June 1991                                ;;
  8. ;;                                                                 ;;
  9. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  10.  
  11. include 'pci.inc'
  12. include 'mii.inc'
  13.  
  14. ; Kernel variables
  15.  
  16.         PAGESIZE        = 4096
  17.         PG_SW           = 0x003
  18.         PG_NOCACHE      = 0x018
  19.  
  20.  
  21. ; network driver types
  22.  
  23.         NET_TYPE_ETH    = 1
  24.         NET_TYPE_SLIP   = 2
  25.  
  26. ; link state
  27.  
  28.         ETH_LINK_DOWN   = 0             ; Link is down
  29.         ETH_LINK_UNKOWN = 1b            ; There could be an active link
  30.         ETH_LINK_FD     = 10b           ; full duplex flag
  31.         ETH_LINK_10M    = 100b          ; 10 mbit
  32.         ETH_LINK_100M   = 1000b         ; 100 mbit
  33.         ETH_LINK_1G     = 10000b        ; gigabit
  34.  
  35.  
  36.         LAST_IO = 0
  37. macro   set_io addr {
  38.  
  39.         if      addr = 0
  40.         mov     edx, [device.io_addr]
  41.         else if addr = LAST_IO
  42.         else
  43.         add     edx, addr - LAST_IO
  44.         end if
  45.  
  46.         LAST_IO = addr
  47. }
  48.  
  49. macro   allocate_and_clear dest, size, err {
  50.  
  51. ; We need to allocate at least 8 pages, if we want a continuous memory in ram
  52.         push    edx
  53.     if (size < 8*4096) & (size > 4096)
  54.         stdcall KernelAlloc, 8*4096
  55.     else
  56.         stdcall KernelAlloc, size
  57.     end if
  58.         pop     edx
  59.  
  60.         test    eax, eax
  61.         jz      err
  62.         mov     dest, eax               ; Save the address to it into the device struct
  63.         mov     edi, eax                ; look at last part of code!
  64.  
  65. ; Release the unused pages (if any)
  66.     if (size < 8*4096) & (size > 4096)
  67.         add     eax, (size/4096+1)*4096
  68.         mov     ecx, 8-(size/4096+1)
  69.         push    edx
  70.         call    ReleasePages
  71.         pop     edx
  72.     end if
  73.  
  74. ; Clear the allocated buffer
  75.         mov     ecx, size/4             ; divide by 4 because of DWORD
  76.         xor     eax, eax
  77.         rep     stosd
  78.  
  79.      if (size - size/4*4)
  80.         mov     ecx, size - size/4*4
  81.         rep     stosb
  82.      end if
  83.  
  84. }
  85.  
  86. struc   IOCTL {
  87.         .handle         dd ?
  88.         .io_code        dd ?
  89.         .input          dd ?
  90.         .inp_size       dd ?
  91.         .output         dd ?
  92.         .out_size       dd ?
  93. }
  94.  
  95. virtual at edx
  96.   IOCTL IOCTL
  97. end virtual
  98.  
  99.  
  100. if used null_op
  101. align 4
  102. null_op:
  103.         or      eax, -1
  104.         ret
  105.  
  106. end if
  107.  
  108.  
  109. macro   GetRealAddr {             ; input and output is eax
  110.  
  111.         push    ax
  112.         call    GetPgAddr
  113.         and     word[esp], PAGESIZE - 1
  114.         or      ax, word[esp]
  115.         inc     esp
  116.         inc     esp
  117.  
  118. }
  119.  
  120. macro   NET_DEVICE {
  121.  
  122.         .type           dd ?    ; Type field
  123.         .mtu            dd ?    ; Maximal Transmission Unit
  124.         .name           dd ?    ; Ptr to 0 terminated string
  125.  
  126.         .unload         dd ?    ; Ptrs to driver functions
  127.         .reset          dd ?    ;
  128.         .transmit       dd ?    ;
  129.  
  130.         .bytes_tx       dq ?    ; Statistics, updated by the driver
  131.         .bytes_rx       dq ?    ;
  132.         .packets_tx     dd ?    ;
  133.         .packets_rx     dd ?    ;
  134.  
  135.         .state          dd ?    ; link state (0 = no link)
  136.         .hwacc          dd ?    ; bitmask stating enabled HW accelerations
  137.  
  138.         .end:
  139. }
  140.  
  141.  
  142. macro   ETH_DEVICE {
  143.         NET_DEVICE
  144.  
  145.         .mac            dp ?
  146.                         dw ?    ; qword alignment
  147.  
  148. }
  149.  
  150.  
  151.  
  152. macro   SLIP_DEVICE {
  153.         NET_DEVICE
  154.  
  155. }