Subversion Repositories Kolibri OS

Rev

Rev 4449 | Blame | Last modification | View Log | RSS feed

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