home *** CD-ROM | disk | FTP | other *** search
/ The Best of Mecomp Multimedia 1 / Mecomp-CD.iso / amiga / tools / misc / cnetdevice / src / include / cnet.i < prev    next >
Encoding:
Text File  |  1997-03-04  |  11.1 KB  |  266 lines

  1. ;----------------------------------------------------------------------------
  2. ;             Includes for CNET CN40-BC PCMCIA network card
  3. ;----------------------------------------------------------------------------
  4. ;           Original code by Bruce Abbott (bhabbott@inhb.co.nz)
  5. ;
  6. ;    "Some PC oriented eight (8) bit cards may require you read
  7. ;     odd-byte I/O address registers at the corresponding even-byte
  8. ;     address plus 64K.  There is sufficient I/O address space
  9. ;     provided that exceeding I/O address space should not be a problem."
  10. ;
  11. ;            (extract from Autodoc 'cardresource.doc')
  12. ;
  13. ; The following information applies to the CNet CN40BC. Other cards could
  14. ; be quite different.
  15. ;
  16. ; Even byte addresses start at $a20000, and are mirrored every 1K.
  17. ; Odd byte addresses start at $a30000. By positioning the base I/O address
  18. ; 1K below the start of odd addressing, we can access both even and odd
  19. ; I/O space using a single CPU Address Register (with 16 bit offsets).
  20. ;
  21.  
  22. IObase      = $10000-$0400+$0300      ; offset to even nic registers
  23. odd         = $10000-IOBase+$0300-1   ; offset to odd nic registers
  24.  
  25. ;---------------------------------------------------------------------------
  26. ; The card will be initialised to present its I/O registers at the
  27. ; standard peecee I/O offset of $0300. This is acheived by writing a
  28. ; value of $20 to the card configuration register. Until this is done
  29. ; the I/O registers are invisible!
  30.  
  31. ; NOTE: this information was obtained by disassembling the peecee driver...
  32.  
  33. Config_Register = $03f8 ; offset to card config register (in attribute memory)
  34.  
  35. IOat300      = $20      ; configure ISA bus I/O base to $0300
  36.  
  37. ;IOat320    = $21
  38. ;IOat340    = $22     ; alternative I/O bases can be set...
  39. ;IOat360    = $23
  40.  
  41. ;-----------------------------------------------------------------------
  42. ; The CNET CN40-BC uses a controller chip that is compatible with
  43. ; National Semiconducter's DS8390. This is the same chip that is
  44. ; used in NE1000 and NE2000 ISA bus ethernet cards.
  45.  
  46. ; --------------------- DS8390 registers ------------------------
  47. ; registers in bank 0
  48. nic_cr       =  0         ; command register        (r/w) in all banks
  49. nic_pstart   =  1+odd     ; page start               (w)
  50. nic_pstop    =  2         ; page stop                (w)
  51. nic_clda0    =  nic_pstop ; current local dma addr   (r)
  52. nic_bnry     =  3+odd     ; boundary pointer        (r/w)
  53. nic_clda1    =  nic_bnry  ; current local dma addr   (r)
  54. nic_tpsr     =  4         ; transmit page start      (w)
  55. nic_tsr      =  nic_tpsr  ; transmit status register (r)
  56. nic_tbcr0    =  5+odd     ; transmit byte count      (w)
  57. nic_ncr      =  nic_tbcr0 ; number of collisions     (r)
  58. nic_tbcr1    =  6         ; transmit byte count      (w)
  59. nic_fifo     =  nic_tbcr1 ; fifo contents            (r)
  60. nic_isr      =  7+odd     ; interrupt status        (r/w)
  61. nic_rsar0    =  8         ; remote start address     (w)
  62. nic_crda0    =  nic_rsar0 ; current remote DMA addr  (r)
  63. nic_rsar1    =  9+odd     ; remote start address     (w)
  64. nic_crda1    =  nic_rsar1 ; current remote DMA addr  (r)
  65. nic_rbcr0    = 10         ; remote byte count        (w)
  66. nic_rbcr1    = 11+odd     ; remote byte count        (w)
  67. nic_rcr      = 12         ; receive configuration    (w)
  68. nic_rsr      = nic_rcr    ; receive status           (r)
  69. nic_tcr      = 13+odd     ; transmit configuration   (w)
  70. nic_cntr0    = nic_tcr    ; tally counter            (r) frame align errors
  71. nic_dcr      = 14         ; data configuration       (w)
  72. nic_cntr1    = nic_dcr    ; tally counter            (r) crc errors
  73. nic_imr      = 15+odd     ; interrupt mask           (w)
  74. nic_cntr2    = nic_imr    ; tally counter            (r) missed packets
  75.  
  76. ; bank 1 and 2 registers
  77. nic_par0     =  1+odd  ; physical etheraddress   (r/w)
  78. nic_par1     =  2      ; physical etheraddress   (r/w)
  79. nic_par2     =  3+odd  ; physical etheraddress   (r/w)
  80. nic_par3     =  4      ; physical etheraddress   (r/w)
  81. nic_par4     =  5+odd  ; physical etheraddress   (r/w)
  82. nic_par5     =  6      ; physical etheraddress   (r/w)
  83. nic_curr     =  7+odd  ; current page            (r/w)
  84. nic_mar0     =  8      ; multicast etheraddress  (r/w)
  85. nic_mar1     =  9+odd  ; multicast etheraddress  (r/w)
  86. nic_mar2     = 10      ; multicast etheraddress  (r/w)
  87. nic_mar3     = 11+odd  ; multicast etheraddress  (r/w)
  88. nic_mar4     = 12      ; multicast etheraddress  (r/w)
  89. nic_mar5     = 13+odd  ; multicast etheraddress  (r/w)
  90. nic_mar6     = 14      ; multicast etheraddress  (r/w)
  91. nic_mar7     = 15+odd  ; multicast etheraddress  (r/w)
  92.  
  93. ; ASIC registers in the NE2000 card
  94. nic_data     = 16      ;  DMA port  (r/w)  16 bit
  95. nic_rst      = 31+odd  ;  card reset (r=reset, w=not)
  96.  
  97. ; DS8390 command bits
  98. DSCM_STOP    = $01 ; Stop controller
  99. DSCM_START   = $02 ; Start controller
  100. DSCM_TRANS   = $04 ; Transmit packet
  101. DSCM_RREAD   = $08 ; Remote read (read from nic memory to Amiga memory)
  102. DSCM_RWRITE  = $10 ; Remote write (write from Amiga memory to nic memory)
  103. DSCM_NODMA   = $20 ; No Remote DMA present
  104. DSCM_PG0     = $00 ; Select register bank 0
  105. DSCM_PG1     = $40 ; Select register bank 1
  106. DSCM_PG2     = $80 ; Select register bank 2
  107.  
  108. ; tansmit status register values
  109. DSTS_PTX     = $01 ; Successful packet transmit
  110. DSTS_COLL    = $02 ; Packet transmit w/ collision
  111. DSTS_COLL16  = $04 ; Packet had >16 collisions & fail
  112. DSTS_UND     = $20 ; FIFO Underrun on transmission
  113.  
  114. ; interrupt status register values
  115. DSIS_RX      = $01 ; Successful packet reception
  116. DSIS_TX      = $02 ; Successful packet transmission
  117. DSIS_RXE     = $04 ; Packet reception  w/error
  118. DSIS_TXE     = $08 ; Packet transmission  w/error
  119. DSIS_ROVRN   = $10 ; Receiver overrun in the ring
  120. DSIS_CTRS    = $20 ; Diagnostic counters need attn
  121. DSIS_RDC     = $40 ; Remote DMA Complete
  122. DSIS_RESET   = $80 ; Reset Complete
  123.  
  124. ; interrupt mask register values
  125. DSIM_PRXE    = $01 ; Packet received enable
  126. DSIM_PTXE    = $02 ; Packet transmitted enable
  127. DSIM_RXEE    = $04 ; Receive error enable
  128. DSIM_TXEE    = $08 ; Transmit error enable
  129. DSIM_OVWE    = $10 ; Overwrite warning enable
  130. DSIM_CNTE    = $20 ; Counter overflow enable
  131. DSIM_RDCE    = $40 ; Remote DMA complete enable
  132. DSIM_RESET   = $80 ; Reset Complete enable
  133.  
  134. ; Bit numbers for interrupts (same for int status and mask)
  135. DSIB_RX      = 0
  136. DSIB_TX      = 1
  137. DSIB_RXE     = 2
  138. DSIB_TXE     = 3
  139. DSIB_ROVRN   = 4
  140. DSIB_CTRS    = 5
  141. DSIB_RDC     = 6
  142. DSIB_RESET   = 7
  143.  
  144. INTMASK = $ff&~(DSIM_RESET|DSIM_RDCE) ; all ints except DMA, Reset complete
  145.  
  146.  
  147. ; data configuration register values
  148. DSDC_WTS     = $01 ; Word Transfer Select
  149. DSDC_BOS     = $02 ; Byte Order Select
  150. DSDC_LAS     = $04 ; Long Address Select
  151. DSDC_BMS     = $08 ; Burst Mode Select
  152. DSDC_AR      = $10 ; Autoinitialize Remote
  153. DSDC_FT0     = $20 ; Fifo Threshold Select
  154. DSDC_FT1     = $40 ; Fifo Threshold Select
  155.  
  156. ; receive status register values
  157. DSRS_RPC     = $01 ; Received Packet Complete
  158.  
  159. ; transmit configuration register values
  160. DSTC_CRC     = $01 ; Inhibit CRC
  161. DSTC_LB0     = $02 ; Encoded Loopback Control
  162. DSTC_LB1     = $04 ; Encoded Loopback Control
  163. DSTC_ATD     = $08 ; Auto Transmit Disable
  164. DSTC_OFST    = $10 ; Collision Offset Enable
  165.  
  166. ; receive configuration register values
  167. DSRC_SEP     = $01 ; Save error packets
  168. DSRC_AR      = $02 ; Accept Runt packets
  169. DSRC_AB      = $04 ; Accept Broadcast packets
  170. DSRC_AM      = $08 ; Accept Multicast packets
  171. DSRC_PRO     = $10 ; Promiscuous physical
  172. DSRC_MON     = $20 ; Monitor mode
  173.  
  174.  
  175. ;-------------------------------------------------------------------------
  176. ; Packet receive header, 1 per each buffer page used in receive packet.
  177. ; The nic inserts this in front of the received packet.
  178. ;
  179.  STRUCTURE prhdr,0
  180.    BYTE  prhdr_status  ; is this a good packet, same as ds0_rsr
  181.    BYTE  prhdr_nxtpg   ; next page of packet or next packet
  182.    BYTE  prhdr_sz0     ; length (lower byte)
  183.    BYTE  prhdr_sz1     ; length (upper byte)
  184.   LABEL  prhdr_sizeof
  185.  
  186. ;-------------------------------------------------------------------------
  187. ; nic has 16K of on-board RAM, from $4000 to $7fff (16 bit address)
  188. ;
  189. ; Internal DMA operations (ie. tx/rx) require the upper 8 bits of the
  190. ; address, as RAM is addressed in 256 byte pages.
  191. ;
  192. ; DMA to/from the host Amiga ("Remote DMA") requires a 16 bit word-aligned
  193. ; address
  194. ;
  195.  
  196. PKTSZ    =  $0600             ; space for biggest ethernet packet (6 pages)
  197.  
  198. TBUF     =  $4000             ; Starting location of Transmit Buffer
  199. TBUF1    =  $4000+PKTSZ       ; Another Tx Buffer (for double-buffered tx)
  200. RBUF     =  $4000+(PKTSZ*2)   ; Starting location of Receive Ring Buffer
  201. RBUFEND  =  $8000             ; Ending location of Receive Ring Buffer
  202.  
  203. ETHER_MIN_LEN = 64            ; smallest acceptable packet size
  204. ETHER_MAX_LEN = 1536          ; largest raw packet size
  205.  
  206. ; ethernet packet data sizes (maximum)
  207.  
  208. ETHERPKT_SIZE = 1500
  209. RAWPKT_SIZE   = 1514
  210.  
  211. ; size of our packet buffer
  212.  
  213. PKTBUF_SIZE   = 1600   ; actually only need 1536 ?
  214.  
  215. ; ethernet address bytesize
  216.  
  217. ETHER_ADDR_SIZE = 6
  218.  
  219. ; structure of an ethernet packet
  220.  
  221.   STRUCTURE etherpacket,0
  222.    STRUCT ether_dest,ETHER_ADDR_SIZE     ;  0 destination address
  223.    STRUCT ether_src,ETHER_ADDR_SIZE      ;  6 originator  address
  224.     WORD  ether_type                     ; 12 packet type
  225.    LABEL  ether_data                     ; 14 user data (up to 1500 bytes)
  226.  
  227.  
  228. ; our extension to device data
  229.  
  230.   STRUCTURE device_data,lib_size
  231.     BYTE  dd_flags                             ; various flags
  232.     BYTE  dd_dcr                               ; copy of nic data config reg
  233.     BYTE  dd_rcr                               ; copy of nic rx config reg
  234.     BYTE  dd_imr                               ; copy of nic intmask register
  235.     LONG  dd_overflows                         ; nic rx buffer overflow count
  236.     LONG  dd_errors                            ; bad packets received
  237.     LONG  dd_collisions                        ; tx collision count
  238.     LONG  dd_seglist                           ; device seglist
  239.     APTR  dd_copytobuf                         ; caller's read routine
  240.     APTR  dd_copyfrombuf                       ; caller's write routine
  241.     APTR  dd_cardres                           ; card.resource base
  242.     APTR  dd_cmm                               ; card memory map
  243.    STRUCT dd_romstationaddress,ETHER_ADDR_SIZE ; hardware address from ROM
  244.    STRUCT dd_stationaddress,ETHER_ADDR_SIZE    ; hardware station addr used
  245.    STRUCT dd_readlist,mlh_size                 ; read requests
  246.    STRUCT dd_writelist,mlh_size                ; write requests
  247.    STRUCT dd_eventlist,mlh_size                ; events
  248.    STRUCT dd_cardhandle,cah_sizeof             ; credit card handle
  249.    STRUCT dd_cardstatus,is_size                ; card status interrupt
  250.    STRUCT dd_cardremoved,is_size               ; card removed interrupt
  251.    STRUCT dd_cardinserted,is_size              ; card inserted interrupt
  252.    STRUCT dd_txint,is_size                     ; transmit software interrupt
  253.    STRUCT dd_rxint,is_size                     ; receive software interrupt
  254.     LABEL dd_extsize
  255.  
  256.  
  257. ; bit definitions for dd_flags
  258.  
  259.  BITDEF DD,CARDIN,1         ; card is inserted
  260.  BITDEF DD,NICUP,2          ; controller hardware is initialised
  261.  BITDEF DD,OWNED,3          ; owncard was successful
  262.  BITDEF DD,CONFIGURED,4     ; hardware address is configured
  263.  BITDEF DD,ONLINE,5         ; device is online
  264.  BITDEF DD,TX,6             ; transmit buffer is full
  265.  BITDEF DD,DEVINIT,7        ; device is initialised
  266.