wanxlfw.S 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897
  1. .psize 0
  2. /*
  3. wanXL serial card driver for Linux
  4. card firmware part
  5. Copyright (C) 2003 Krzysztof Halasa <khc@pm.waw.pl>
  6. This program is free software; you can redistribute it and/or modify it
  7. under the terms of version 2 of the GNU General Public License
  8. as published by the Free Software Foundation.
  9. DPRAM BDs:
  10. 0x000 - 0x050 TX#0 0x050 - 0x140 RX#0
  11. 0x140 - 0x190 TX#1 0x190 - 0x280 RX#1
  12. 0x280 - 0x2D0 TX#2 0x2D0 - 0x3C0 RX#2
  13. 0x3C0 - 0x410 TX#3 0x410 - 0x500 RX#3
  14. 000 5FF 1536 Bytes Dual-Port RAM User Data / BDs
  15. 600 6FF 256 Bytes Dual-Port RAM User Data / BDs
  16. 700 7FF 256 Bytes Dual-Port RAM User Data / BDs
  17. C00 CBF 192 Bytes Dual-Port RAM Parameter RAM Page 1
  18. D00 DBF 192 Bytes Dual-Port RAM Parameter RAM Page 2
  19. E00 EBF 192 Bytes Dual-Port RAM Parameter RAM Page 3
  20. F00 FBF 192 Bytes Dual-Port RAM Parameter RAM Page 4
  21. local interrupts level
  22. NMI 7
  23. PIT timer, CPM (RX/TX complete) 4
  24. PCI9060 DMA and PCI doorbells 3
  25. Cable - not used 1
  26. */
  27. #include <linux/hdlc.h>
  28. #include <linux/hdlc/ioctl.h>
  29. #include "wanxl.h"
  30. /* memory addresses and offsets */
  31. MAX_RAM_SIZE = 16 * 1024 * 1024 // max RAM supported by hardware
  32. PCI9060_VECTOR = 0x0000006C
  33. CPM_IRQ_BASE = 0x40
  34. ERROR_VECTOR = CPM_IRQ_BASE * 4
  35. SCC1_VECTOR = (CPM_IRQ_BASE + 0x1E) * 4
  36. SCC2_VECTOR = (CPM_IRQ_BASE + 0x1D) * 4
  37. SCC3_VECTOR = (CPM_IRQ_BASE + 0x1C) * 4
  38. SCC4_VECTOR = (CPM_IRQ_BASE + 0x1B) * 4
  39. CPM_IRQ_LEVEL = 4
  40. TIMER_IRQ = 128
  41. TIMER_IRQ_LEVEL = 4
  42. PITR_CONST = 0x100 + 16 // 1 Hz timer
  43. MBAR = 0x0003FF00
  44. VALUE_WINDOW = 0x40000000
  45. ORDER_WINDOW = 0xC0000000
  46. PLX = 0xFFF90000
  47. CSRA = 0xFFFB0000
  48. CSRB = 0xFFFB0002
  49. CSRC = 0xFFFB0004
  50. CSRD = 0xFFFB0006
  51. STATUS_CABLE_LL = 0x2000
  52. STATUS_CABLE_DTR = 0x1000
  53. DPRBASE = 0xFFFC0000
  54. SCC1_BASE = DPRBASE + 0xC00
  55. MISC_BASE = DPRBASE + 0xCB0
  56. SCC2_BASE = DPRBASE + 0xD00
  57. SCC3_BASE = DPRBASE + 0xE00
  58. SCC4_BASE = DPRBASE + 0xF00
  59. // offset from SCCx_BASE
  60. // SCC_xBASE contain offsets from DPRBASE and must be divisible by 8
  61. SCC_RBASE = 0 // 16-bit RxBD base address
  62. SCC_TBASE = 2 // 16-bit TxBD base address
  63. SCC_RFCR = 4 // 8-bit Rx function code
  64. SCC_TFCR = 5 // 8-bit Tx function code
  65. SCC_MRBLR = 6 // 16-bit maximum Rx buffer length
  66. SCC_C_MASK = 0x34 // 32-bit CRC constant
  67. SCC_C_PRES = 0x38 // 32-bit CRC preset
  68. SCC_MFLR = 0x46 // 16-bit max Rx frame length (without flags)
  69. REGBASE = DPRBASE + 0x1000
  70. PICR = REGBASE + 0x026 // 16-bit periodic irq control
  71. PITR = REGBASE + 0x02A // 16-bit periodic irq timing
  72. OR1 = REGBASE + 0x064 // 32-bit RAM bank #1 options
  73. CICR = REGBASE + 0x540 // 32(24)-bit CP interrupt config
  74. CIMR = REGBASE + 0x548 // 32-bit CP interrupt mask
  75. CISR = REGBASE + 0x54C // 32-bit CP interrupts in-service
  76. PADIR = REGBASE + 0x550 // 16-bit PortA data direction bitmap
  77. PAPAR = REGBASE + 0x552 // 16-bit PortA pin assignment bitmap
  78. PAODR = REGBASE + 0x554 // 16-bit PortA open drain bitmap
  79. PADAT = REGBASE + 0x556 // 16-bit PortA data register
  80. PCDIR = REGBASE + 0x560 // 16-bit PortC data direction bitmap
  81. PCPAR = REGBASE + 0x562 // 16-bit PortC pin assignment bitmap
  82. PCSO = REGBASE + 0x564 // 16-bit PortC special options
  83. PCDAT = REGBASE + 0x566 // 16-bit PortC data register
  84. PCINT = REGBASE + 0x568 // 16-bit PortC interrupt control
  85. CR = REGBASE + 0x5C0 // 16-bit Command register
  86. SCC1_REGS = REGBASE + 0x600
  87. SCC2_REGS = REGBASE + 0x620
  88. SCC3_REGS = REGBASE + 0x640
  89. SCC4_REGS = REGBASE + 0x660
  90. SICR = REGBASE + 0x6EC // 32-bit SI clock route
  91. // offset from SCCx_REGS
  92. SCC_GSMR_L = 0x00 // 32 bits
  93. SCC_GSMR_H = 0x04 // 32 bits
  94. SCC_PSMR = 0x08 // 16 bits
  95. SCC_TODR = 0x0C // 16 bits
  96. SCC_DSR = 0x0E // 16 bits
  97. SCC_SCCE = 0x10 // 16 bits
  98. SCC_SCCM = 0x14 // 16 bits
  99. SCC_SCCS = 0x17 // 8 bits
  100. #if QUICC_MEMCPY_USES_PLX
  101. .macro memcpy_from_pci src, dest, len // len must be < 8 MB
  102. addl #3, \len
  103. andl #0xFFFFFFFC, \len // always copy n * 4 bytes
  104. movel \src, PLX_DMA_0_PCI
  105. movel \dest, PLX_DMA_0_LOCAL
  106. movel \len, PLX_DMA_0_LENGTH
  107. movel #0x0103, PLX_DMA_CMD_STS // start channel 0 transfer
  108. bsr memcpy_from_pci_run
  109. .endm
  110. .macro memcpy_to_pci src, dest, len
  111. addl #3, \len
  112. andl #0xFFFFFFFC, \len // always copy n * 4 bytes
  113. movel \src, PLX_DMA_1_LOCAL
  114. movel \dest, PLX_DMA_1_PCI
  115. movel \len, PLX_DMA_1_LENGTH
  116. movel #0x0301, PLX_DMA_CMD_STS // start channel 1 transfer
  117. bsr memcpy_to_pci_run
  118. .endm
  119. #else
  120. .macro memcpy src, dest, len // len must be < 65536 bytes
  121. movel %d7, -(%sp) // src and dest must be < 256 MB
  122. movel \len, %d7 // bits 0 and 1
  123. lsrl #2, \len
  124. andl \len, \len
  125. beq 99f // only 0 - 3 bytes
  126. subl #1, \len // for dbf
  127. 98: movel (\src)+, (\dest)+
  128. dbfw \len, 98b
  129. 99: movel %d7, \len
  130. btstl #1, \len
  131. beq 99f
  132. movew (\src)+, (\dest)+
  133. 99: btstl #0, \len
  134. beq 99f
  135. moveb (\src)+, (\dest)+
  136. 99:
  137. movel (%sp)+, %d7
  138. .endm
  139. .macro memcpy_from_pci src, dest, len
  140. addl #VALUE_WINDOW, \src
  141. memcpy \src, \dest, \len
  142. .endm
  143. .macro memcpy_to_pci src, dest, len
  144. addl #VALUE_WINDOW, \dest
  145. memcpy \src, \dest, \len
  146. .endm
  147. #endif
  148. .macro wait_for_command
  149. 99: btstl #0, CR
  150. bne 99b
  151. .endm
  152. /****************************** card initialization *******************/
  153. .text
  154. .global _start
  155. _start: bra init
  156. .org _start + 4
  157. ch_status_addr: .long 0, 0, 0, 0
  158. rx_descs_addr: .long 0
  159. init:
  160. #if DETECT_RAM
  161. movel OR1, %d0
  162. andl #0xF00007FF, %d0 // mask AMxx bits
  163. orl #0xFFFF800 & ~(MAX_RAM_SIZE - 1), %d0 // update RAM bank size
  164. movel %d0, OR1
  165. #endif
  166. addl #VALUE_WINDOW, rx_descs_addr // PCI addresses of shared data
  167. clrl %d0 // D0 = 4 * port
  168. init_1: tstl ch_status_addr(%d0)
  169. beq init_2
  170. addl #VALUE_WINDOW, ch_status_addr(%d0)
  171. init_2: addl #4, %d0
  172. cmpl #4 * 4, %d0
  173. bne init_1
  174. movel #pci9060_interrupt, PCI9060_VECTOR
  175. movel #error_interrupt, ERROR_VECTOR
  176. movel #port_interrupt_1, SCC1_VECTOR
  177. movel #port_interrupt_2, SCC2_VECTOR
  178. movel #port_interrupt_3, SCC3_VECTOR
  179. movel #port_interrupt_4, SCC4_VECTOR
  180. movel #timer_interrupt, TIMER_IRQ * 4
  181. movel #0x78000000, CIMR // only SCCx IRQs from CPM
  182. movew #(TIMER_IRQ_LEVEL << 8) + TIMER_IRQ, PICR // interrupt from PIT
  183. movew #PITR_CONST, PITR
  184. // SCC1=SCCa SCC2=SCCb SCC3=SCCc SCC4=SCCd prio=4 HP=-1 IRQ=64-79
  185. movel #0xD41F40 + (CPM_IRQ_LEVEL << 13), CICR
  186. movel #0x543, PLX_DMA_0_MODE // 32-bit, Ready, Burst, IRQ
  187. movel #0x543, PLX_DMA_1_MODE
  188. movel #0x0, PLX_DMA_0_DESC // from PCI to local
  189. movel #0x8, PLX_DMA_1_DESC // from local to PCI
  190. movel #0x101, PLX_DMA_CMD_STS // enable both DMA channels
  191. // enable local IRQ, DMA, doorbells and PCI IRQ
  192. orl #0x000F0300, PLX_INTERRUPT_CS
  193. #if DETECT_RAM
  194. bsr ram_test
  195. #else
  196. movel #1, PLX_MAILBOX_5 // non-zero value = init complete
  197. #endif
  198. bsr check_csr
  199. movew #0xFFFF, PAPAR // all pins are clocks/data
  200. clrw PADIR // first function
  201. clrw PCSO // CD and CTS always active
  202. /****************************** main loop *****************************/
  203. main: movel channel_stats, %d7 // D7 = doorbell + irq status
  204. clrl channel_stats
  205. tstl %d7
  206. bne main_1
  207. // nothing to do - wait for next event
  208. stop #0x2200 // supervisor + IRQ level 2
  209. movew #0x2700, %sr // disable IRQs again
  210. bra main
  211. main_1: clrl %d0 // D0 = 4 * port
  212. clrl %d6 // D6 = doorbell to host value
  213. main_l: btstl #DOORBELL_TO_CARD_CLOSE_0, %d7
  214. beq main_op
  215. bclrl #DOORBELL_TO_CARD_OPEN_0, %d7 // in case both bits are set
  216. bsr close_port
  217. main_op:
  218. btstl #DOORBELL_TO_CARD_OPEN_0, %d7
  219. beq main_cl
  220. bsr open_port
  221. main_cl:
  222. btstl #DOORBELL_TO_CARD_TX_0, %d7
  223. beq main_txend
  224. bsr tx
  225. main_txend:
  226. btstl #TASK_SCC_0, %d7
  227. beq main_next
  228. bsr tx_end
  229. bsr rx
  230. main_next:
  231. lsrl #1, %d7 // port status for next port
  232. addl #4, %d0 // D0 = 4 * next port
  233. cmpl #4 * 4, %d0
  234. bne main_l
  235. movel %d6, PLX_DOORBELL_FROM_CARD // signal the host
  236. bra main
  237. /****************************** open port *****************************/
  238. open_port: // D0 = 4 * port, D6 = doorbell to host
  239. movel ch_status_addr(%d0), %a0 // A0 = port status address
  240. tstl STATUS_OPEN(%a0)
  241. bne open_port_ret // port already open
  242. movel #1, STATUS_OPEN(%a0) // confirm the port is open
  243. // setup BDs
  244. clrl tx_in(%d0)
  245. clrl tx_out(%d0)
  246. clrl tx_count(%d0)
  247. clrl rx_in(%d0)
  248. movel SICR, %d1 // D1 = clock settings in SICR
  249. andl clocking_mask(%d0), %d1
  250. cmpl #CLOCK_TXFROMRX, STATUS_CLOCKING(%a0)
  251. bne open_port_clock_ext
  252. orl clocking_txfromrx(%d0), %d1
  253. bra open_port_set_clock
  254. open_port_clock_ext:
  255. orl clocking_ext(%d0), %d1
  256. open_port_set_clock:
  257. movel %d1, SICR // update clock settings in SICR
  258. orw #STATUS_CABLE_DTR, csr_output(%d0) // DTR on
  259. bsr check_csr // call with disabled timer interrupt
  260. // Setup TX descriptors
  261. movel first_buffer(%d0), %d1 // D1 = starting buffer address
  262. movel tx_first_bd(%d0), %a1 // A1 = starting TX BD address
  263. movel #TX_BUFFERS - 2, %d2 // D2 = TX_BUFFERS - 1 counter
  264. movel #0x18000000, %d3 // D3 = initial TX BD flags: Int + Last
  265. cmpl #PARITY_NONE, STATUS_PARITY(%a0)
  266. beq open_port_tx_loop
  267. bsetl #26, %d3 // TX BD flag: Transmit CRC
  268. open_port_tx_loop:
  269. movel %d3, (%a1)+ // TX flags + length
  270. movel %d1, (%a1)+ // buffer address
  271. addl #BUFFER_LENGTH, %d1
  272. dbfw %d2, open_port_tx_loop
  273. bsetl #29, %d3 // TX BD flag: Wrap (last BD)
  274. movel %d3, (%a1)+ // Final TX flags + length
  275. movel %d1, (%a1)+ // buffer address
  276. // Setup RX descriptors // A1 = starting RX BD address
  277. movel #RX_BUFFERS - 2, %d2 // D2 = RX_BUFFERS - 1 counter
  278. open_port_rx_loop:
  279. movel #0x90000000, (%a1)+ // RX flags + length
  280. movel %d1, (%a1)+ // buffer address
  281. addl #BUFFER_LENGTH, %d1
  282. dbfw %d2, open_port_rx_loop
  283. movel #0xB0000000, (%a1)+ // Final RX flags + length
  284. movel %d1, (%a1)+ // buffer address
  285. // Setup port parameters
  286. movel scc_base_addr(%d0), %a1 // A1 = SCC_BASE address
  287. movel scc_reg_addr(%d0), %a2 // A2 = SCC_REGS address
  288. movel #0xFFFF, SCC_SCCE(%a2) // clear status bits
  289. movel #0x0000, SCC_SCCM(%a2) // interrupt mask
  290. movel tx_first_bd(%d0), %d1
  291. movew %d1, SCC_TBASE(%a1) // D1 = offset of first TxBD
  292. addl #TX_BUFFERS * 8, %d1
  293. movew %d1, SCC_RBASE(%a1) // D1 = offset of first RxBD
  294. moveb #0x8, SCC_RFCR(%a1) // Intel mode, 1000
  295. moveb #0x8, SCC_TFCR(%a1)
  296. // Parity settings
  297. cmpl #PARITY_CRC16_PR1_CCITT, STATUS_PARITY(%a0)
  298. bne open_port_parity_1
  299. clrw SCC_PSMR(%a2) // CRC16-CCITT
  300. movel #0xF0B8, SCC_C_MASK(%a1)
  301. movel #0xFFFF, SCC_C_PRES(%a1)
  302. movew #HDLC_MAX_MRU + 2, SCC_MFLR(%a1) // 2 bytes for CRC
  303. movew #2, parity_bytes(%d0)
  304. bra open_port_2
  305. open_port_parity_1:
  306. cmpl #PARITY_CRC32_PR1_CCITT, STATUS_PARITY(%a0)
  307. bne open_port_parity_2
  308. movew #0x0800, SCC_PSMR(%a2) // CRC32-CCITT
  309. movel #0xDEBB20E3, SCC_C_MASK(%a1)
  310. movel #0xFFFFFFFF, SCC_C_PRES(%a1)
  311. movew #HDLC_MAX_MRU + 4, SCC_MFLR(%a1) // 4 bytes for CRC
  312. movew #4, parity_bytes(%d0)
  313. bra open_port_2
  314. open_port_parity_2:
  315. cmpl #PARITY_CRC16_PR0_CCITT, STATUS_PARITY(%a0)
  316. bne open_port_parity_3
  317. clrw SCC_PSMR(%a2) // CRC16-CCITT preset 0
  318. movel #0xF0B8, SCC_C_MASK(%a1)
  319. clrl SCC_C_PRES(%a1)
  320. movew #HDLC_MAX_MRU + 2, SCC_MFLR(%a1) // 2 bytes for CRC
  321. movew #2, parity_bytes(%d0)
  322. bra open_port_2
  323. open_port_parity_3:
  324. cmpl #PARITY_CRC32_PR0_CCITT, STATUS_PARITY(%a0)
  325. bne open_port_parity_4
  326. movew #0x0800, SCC_PSMR(%a2) // CRC32-CCITT preset 0
  327. movel #0xDEBB20E3, SCC_C_MASK(%a1)
  328. clrl SCC_C_PRES(%a1)
  329. movew #HDLC_MAX_MRU + 4, SCC_MFLR(%a1) // 4 bytes for CRC
  330. movew #4, parity_bytes(%d0)
  331. bra open_port_2
  332. open_port_parity_4:
  333. clrw SCC_PSMR(%a2) // no parity
  334. movel #0xF0B8, SCC_C_MASK(%a1)
  335. movel #0xFFFF, SCC_C_PRES(%a1)
  336. movew #HDLC_MAX_MRU, SCC_MFLR(%a1) // 0 bytes for CRC
  337. clrw parity_bytes(%d0)
  338. open_port_2:
  339. movel #0x00000003, SCC_GSMR_H(%a2) // RTSM
  340. cmpl #ENCODING_NRZI, STATUS_ENCODING(%a0)
  341. bne open_port_nrz
  342. movel #0x10040900, SCC_GSMR_L(%a2) // NRZI: TCI Tend RECN+TENC=1
  343. bra open_port_3
  344. open_port_nrz:
  345. movel #0x10040000, SCC_GSMR_L(%a2) // NRZ: TCI Tend RECN+TENC=0
  346. open_port_3:
  347. movew #BUFFER_LENGTH, SCC_MRBLR(%a1)
  348. movel %d0, %d1
  349. lsll #4, %d1 // D1 bits 7 and 6 = port
  350. orl #1, %d1
  351. movew %d1, CR // Init SCC RX and TX params
  352. wait_for_command
  353. // TCI Tend ENR ENT
  354. movew #0x001F, SCC_SCCM(%a2) // TXE RXF BSY TXB RXB interrupts
  355. orl #0x00000030, SCC_GSMR_L(%a2) // enable SCC
  356. open_port_ret:
  357. rts
  358. /****************************** close port ****************************/
  359. close_port: // D0 = 4 * port, D6 = doorbell to host
  360. movel scc_reg_addr(%d0), %a0 // A0 = SCC_REGS address
  361. clrw SCC_SCCM(%a0) // no SCC interrupts
  362. andl #0xFFFFFFCF, SCC_GSMR_L(%a0) // Disable ENT and ENR
  363. andw #~STATUS_CABLE_DTR, csr_output(%d0) // DTR off
  364. bsr check_csr // call with disabled timer interrupt
  365. movel ch_status_addr(%d0), %d1
  366. clrl STATUS_OPEN(%d1) // confirm the port is closed
  367. rts
  368. /****************************** transmit packet ***********************/
  369. // queue packets for transmission
  370. tx: // D0 = 4 * port, D6 = doorbell to host
  371. cmpl #TX_BUFFERS, tx_count(%d0)
  372. beq tx_ret // all DB's = descs in use
  373. movel tx_out(%d0), %d1
  374. movel %d1, %d2 // D1 = D2 = tx_out BD# = desc#
  375. mulul #DESC_LENGTH, %d2 // D2 = TX desc offset
  376. addl ch_status_addr(%d0), %d2
  377. addl #STATUS_TX_DESCS, %d2 // D2 = TX desc address
  378. cmpl #PACKET_FULL, (%d2) // desc status
  379. bne tx_ret
  380. // queue it
  381. movel 4(%d2), %a0 // PCI address
  382. lsll #3, %d1 // BD is 8-bytes long
  383. addl tx_first_bd(%d0), %d1 // D1 = current tx_out BD addr
  384. movel 4(%d1), %a1 // A1 = dest address
  385. movel 8(%d2), %d2 // D2 = length
  386. movew %d2, 2(%d1) // length into BD
  387. memcpy_from_pci %a0, %a1, %d2
  388. bsetl #31, (%d1) // CP go ahead
  389. // update tx_out and tx_count
  390. movel tx_out(%d0), %d1
  391. addl #1, %d1
  392. cmpl #TX_BUFFERS, %d1
  393. bne tx_1
  394. clrl %d1
  395. tx_1: movel %d1, tx_out(%d0)
  396. addl #1, tx_count(%d0)
  397. bra tx
  398. tx_ret: rts
  399. /****************************** packet received ***********************/
  400. // Service receive buffers // D0 = 4 * port, D6 = doorbell to host
  401. rx: movel rx_in(%d0), %d1 // D1 = rx_in BD#
  402. lsll #3, %d1 // BD is 8-bytes long
  403. addl rx_first_bd(%d0), %d1 // D1 = current rx_in BD address
  404. movew (%d1), %d2 // D2 = RX BD flags
  405. btstl #15, %d2
  406. bne rx_ret // BD still empty
  407. btstl #1, %d2
  408. bne rx_overrun
  409. tstw parity_bytes(%d0)
  410. bne rx_parity
  411. bclrl #2, %d2 // do not test for CRC errors
  412. rx_parity:
  413. andw #0x0CBC, %d2 // mask status bits
  414. cmpw #0x0C00, %d2 // correct frame
  415. bne rx_bad_frame
  416. clrl %d3
  417. movew 2(%d1), %d3
  418. subw parity_bytes(%d0), %d3 // D3 = packet length
  419. cmpw #HDLC_MAX_MRU, %d3
  420. bgt rx_bad_frame
  421. rx_good_frame:
  422. movel rx_out, %d2
  423. mulul #DESC_LENGTH, %d2
  424. addl rx_descs_addr, %d2 // D2 = RX desc address
  425. cmpl #PACKET_EMPTY, (%d2) // desc stat
  426. bne rx_overrun
  427. movel %d3, 8(%d2)
  428. movel 4(%d1), %a0 // A0 = source address
  429. movel 4(%d2), %a1
  430. tstl %a1
  431. beq rx_ignore_data
  432. memcpy_to_pci %a0, %a1, %d3
  433. rx_ignore_data:
  434. movel packet_full(%d0), (%d2) // update desc stat
  435. // update D6 and rx_out
  436. bsetl #DOORBELL_FROM_CARD_RX, %d6 // signal host that RX completed
  437. movel rx_out, %d2
  438. addl #1, %d2
  439. cmpl #RX_QUEUE_LENGTH, %d2
  440. bne rx_1
  441. clrl %d2
  442. rx_1: movel %d2, rx_out
  443. rx_free_bd:
  444. andw #0xF000, (%d1) // clear CM and error bits
  445. bsetl #31, (%d1) // free BD
  446. // update rx_in
  447. movel rx_in(%d0), %d1
  448. addl #1, %d1
  449. cmpl #RX_BUFFERS, %d1
  450. bne rx_2
  451. clrl %d1
  452. rx_2: movel %d1, rx_in(%d0)
  453. bra rx
  454. rx_overrun:
  455. movel ch_status_addr(%d0), %d2
  456. addl #1, STATUS_RX_OVERRUNS(%d2)
  457. bra rx_free_bd
  458. rx_bad_frame:
  459. movel ch_status_addr(%d0), %d2
  460. addl #1, STATUS_RX_FRAME_ERRORS(%d2)
  461. bra rx_free_bd
  462. rx_ret: rts
  463. /****************************** packet transmitted ********************/
  464. // Service transmit buffers // D0 = 4 * port, D6 = doorbell to host
  465. tx_end: tstl tx_count(%d0)
  466. beq tx_end_ret // TX buffers already empty
  467. movel tx_in(%d0), %d1
  468. movel %d1, %d2 // D1 = D2 = tx_in BD# = desc#
  469. lsll #3, %d1 // BD is 8-bytes long
  470. addl tx_first_bd(%d0), %d1 // D1 = current tx_in BD address
  471. movew (%d1), %d3 // D3 = TX BD flags
  472. btstl #15, %d3
  473. bne tx_end_ret // BD still being transmitted
  474. // update D6, tx_in and tx_count
  475. orl bell_tx(%d0), %d6 // signal host that TX desc freed
  476. subl #1, tx_count(%d0)
  477. movel tx_in(%d0), %d1
  478. addl #1, %d1
  479. cmpl #TX_BUFFERS, %d1
  480. bne tx_end_1
  481. clrl %d1
  482. tx_end_1:
  483. movel %d1, tx_in(%d0)
  484. // free host's descriptor
  485. mulul #DESC_LENGTH, %d2 // D2 = TX desc offset
  486. addl ch_status_addr(%d0), %d2
  487. addl #STATUS_TX_DESCS, %d2 // D2 = TX desc address
  488. btstl #1, %d3
  489. bne tx_end_underrun
  490. movel #PACKET_SENT, (%d2)
  491. bra tx_end
  492. tx_end_underrun:
  493. movel #PACKET_UNDERRUN, (%d2)
  494. bra tx_end
  495. tx_end_ret: rts
  496. /****************************** PLX PCI9060 DMA memcpy ****************/
  497. #if QUICC_MEMCPY_USES_PLX
  498. // called with interrupts disabled
  499. memcpy_from_pci_run:
  500. movel %d0, -(%sp)
  501. movew %sr, -(%sp)
  502. memcpy_1:
  503. movel PLX_DMA_CMD_STS, %d0 // do not btst PLX register directly
  504. btstl #4, %d0 // transfer done?
  505. bne memcpy_end
  506. stop #0x2200 // enable PCI9060 interrupts
  507. movew #0x2700, %sr // disable interrupts again
  508. bra memcpy_1
  509. memcpy_to_pci_run:
  510. movel %d0, -(%sp)
  511. movew %sr, -(%sp)
  512. memcpy_2:
  513. movel PLX_DMA_CMD_STS, %d0 // do not btst PLX register directly
  514. btstl #12, %d0 // transfer done?
  515. bne memcpy_end
  516. stop #0x2200 // enable PCI9060 interrupts
  517. movew #0x2700, %sr // disable interrupts again
  518. bra memcpy_2
  519. memcpy_end:
  520. movew (%sp)+, %sr
  521. movel (%sp)+, %d0
  522. rts
  523. #endif
  524. /****************************** PLX PCI9060 interrupt *****************/
  525. pci9060_interrupt:
  526. movel %d0, -(%sp)
  527. movel PLX_DOORBELL_TO_CARD, %d0
  528. movel %d0, PLX_DOORBELL_TO_CARD // confirm all requests
  529. orl %d0, channel_stats
  530. movel #0x0909, PLX_DMA_CMD_STS // clear DMA ch #0 and #1 interrupts
  531. movel (%sp)+, %d0
  532. rte
  533. /****************************** SCC interrupts ************************/
  534. port_interrupt_1:
  535. orl #0, SCC1_REGS + SCC_SCCE; // confirm SCC events
  536. orl #1 << TASK_SCC_0, channel_stats
  537. movel #0x40000000, CISR
  538. rte
  539. port_interrupt_2:
  540. orl #0, SCC2_REGS + SCC_SCCE; // confirm SCC events
  541. orl #1 << TASK_SCC_1, channel_stats
  542. movel #0x20000000, CISR
  543. rte
  544. port_interrupt_3:
  545. orl #0, SCC3_REGS + SCC_SCCE; // confirm SCC events
  546. orl #1 << TASK_SCC_2, channel_stats
  547. movel #0x10000000, CISR
  548. rte
  549. port_interrupt_4:
  550. orl #0, SCC4_REGS + SCC_SCCE; // confirm SCC events
  551. orl #1 << TASK_SCC_3, channel_stats
  552. movel #0x08000000, CISR
  553. rte
  554. error_interrupt:
  555. rte
  556. /****************************** cable and PM routine ******************/
  557. // modified registers: none
  558. check_csr:
  559. movel %d0, -(%sp)
  560. movel %d1, -(%sp)
  561. movel %d2, -(%sp)
  562. movel %a0, -(%sp)
  563. movel %a1, -(%sp)
  564. clrl %d0 // D0 = 4 * port
  565. movel #CSRA, %a0 // A0 = CSR address
  566. check_csr_loop:
  567. movew (%a0), %d1 // D1 = CSR input bits
  568. andl #0xE7, %d1 // PM and cable sense bits (no DCE bit)
  569. cmpw #STATUS_CABLE_V35 * (1 + 1 << STATUS_CABLE_PM_SHIFT), %d1
  570. bne check_csr_1
  571. movew #0x0E08, %d1
  572. bra check_csr_valid
  573. check_csr_1:
  574. cmpw #STATUS_CABLE_X21 * (1 + 1 << STATUS_CABLE_PM_SHIFT), %d1
  575. bne check_csr_2
  576. movew #0x0408, %d1
  577. bra check_csr_valid
  578. check_csr_2:
  579. cmpw #STATUS_CABLE_V24 * (1 + 1 << STATUS_CABLE_PM_SHIFT), %d1
  580. bne check_csr_3
  581. movew #0x0208, %d1
  582. bra check_csr_valid
  583. check_csr_3:
  584. cmpw #STATUS_CABLE_EIA530 * (1 + 1 << STATUS_CABLE_PM_SHIFT), %d1
  585. bne check_csr_disable
  586. movew #0x0D08, %d1
  587. bra check_csr_valid
  588. check_csr_disable:
  589. movew #0x0008, %d1 // D1 = disable everything
  590. movew #0x80E7, %d2 // D2 = input mask: ignore DSR
  591. bra check_csr_write
  592. check_csr_valid: // D1 = mode and IRQ bits
  593. movew csr_output(%d0), %d2
  594. andw #0x3000, %d2 // D2 = requested LL and DTR bits
  595. orw %d2, %d1 // D1 = all requested output bits
  596. movew #0x80FF, %d2 // D2 = input mask: include DSR
  597. check_csr_write:
  598. cmpw old_csr_output(%d0), %d1
  599. beq check_csr_input
  600. movew %d1, old_csr_output(%d0)
  601. movew %d1, (%a0) // Write CSR output bits
  602. check_csr_input:
  603. movew (PCDAT), %d1
  604. andw dcd_mask(%d0), %d1
  605. beq check_csr_dcd_on // DCD and CTS signals are negated
  606. movew (%a0), %d1 // D1 = CSR input bits
  607. andw #~STATUS_CABLE_DCD, %d1 // DCD off
  608. bra check_csr_previous
  609. check_csr_dcd_on:
  610. movew (%a0), %d1 // D1 = CSR input bits
  611. orw #STATUS_CABLE_DCD, %d1 // DCD on
  612. check_csr_previous:
  613. andw %d2, %d1 // input mask
  614. movel ch_status_addr(%d0), %a1
  615. cmpl STATUS_CABLE(%a1), %d1 // check for change
  616. beq check_csr_next
  617. movel %d1, STATUS_CABLE(%a1) // update status
  618. movel bell_cable(%d0), PLX_DOORBELL_FROM_CARD // signal the host
  619. check_csr_next:
  620. addl #2, %a0 // next CSR register
  621. addl #4, %d0 // D0 = 4 * next port
  622. cmpl #4 * 4, %d0
  623. bne check_csr_loop
  624. movel (%sp)+, %a1
  625. movel (%sp)+, %a0
  626. movel (%sp)+, %d2
  627. movel (%sp)+, %d1
  628. movel (%sp)+, %d0
  629. rts
  630. /****************************** timer interrupt ***********************/
  631. timer_interrupt:
  632. bsr check_csr
  633. rte
  634. /****************************** RAM sizing and test *******************/
  635. #if DETECT_RAM
  636. ram_test:
  637. movel #0x12345678, %d1 // D1 = test value
  638. movel %d1, (128 * 1024 - 4)
  639. movel #128 * 1024, %d0 // D0 = RAM size tested
  640. ram_test_size:
  641. cmpl #MAX_RAM_SIZE, %d0
  642. beq ram_test_size_found
  643. movel %d0, %a0
  644. addl #128 * 1024 - 4, %a0
  645. cmpl (%a0), %d1
  646. beq ram_test_size_check
  647. ram_test_next_size:
  648. lsll #1, %d0
  649. bra ram_test_size
  650. ram_test_size_check:
  651. eorl #0xFFFFFFFF, %d1
  652. movel %d1, (128 * 1024 - 4)
  653. cmpl (%a0), %d1
  654. bne ram_test_next_size
  655. ram_test_size_found: // D0 = RAM size
  656. movel %d0, %a0 // A0 = fill ptr
  657. subl #firmware_end + 4, %d0
  658. lsrl #2, %d0
  659. movel %d0, %d1 // D1 = DBf counter
  660. ram_test_fill:
  661. movel %a0, -(%a0)
  662. dbfw %d1, ram_test_fill
  663. subl #0x10000, %d1
  664. cmpl #0xFFFFFFFF, %d1
  665. bne ram_test_fill
  666. ram_test_loop: // D0 = DBf counter
  667. cmpl (%a0)+, %a0
  668. dbnew %d0, ram_test_loop
  669. bne ram_test_found_bad
  670. subl #0x10000, %d0
  671. cmpl #0xFFFFFFFF, %d0
  672. bne ram_test_loop
  673. bra ram_test_all_ok
  674. ram_test_found_bad:
  675. subl #4, %a0
  676. ram_test_all_ok:
  677. movel %a0, PLX_MAILBOX_5
  678. rts
  679. #endif
  680. /****************************** constants *****************************/
  681. scc_reg_addr:
  682. .long SCC1_REGS, SCC2_REGS, SCC3_REGS, SCC4_REGS
  683. scc_base_addr:
  684. .long SCC1_BASE, SCC2_BASE, SCC3_BASE, SCC4_BASE
  685. tx_first_bd:
  686. .long DPRBASE
  687. .long DPRBASE + (TX_BUFFERS + RX_BUFFERS) * 8
  688. .long DPRBASE + (TX_BUFFERS + RX_BUFFERS) * 8 * 2
  689. .long DPRBASE + (TX_BUFFERS + RX_BUFFERS) * 8 * 3
  690. rx_first_bd:
  691. .long DPRBASE + TX_BUFFERS * 8
  692. .long DPRBASE + TX_BUFFERS * 8 + (TX_BUFFERS + RX_BUFFERS) * 8
  693. .long DPRBASE + TX_BUFFERS * 8 + (TX_BUFFERS + RX_BUFFERS) * 8 * 2
  694. .long DPRBASE + TX_BUFFERS * 8 + (TX_BUFFERS + RX_BUFFERS) * 8 * 3
  695. first_buffer:
  696. .long BUFFERS_ADDR
  697. .long BUFFERS_ADDR + (TX_BUFFERS + RX_BUFFERS) * BUFFER_LENGTH
  698. .long BUFFERS_ADDR + (TX_BUFFERS + RX_BUFFERS) * BUFFER_LENGTH * 2
  699. .long BUFFERS_ADDR + (TX_BUFFERS + RX_BUFFERS) * BUFFER_LENGTH * 3
  700. bell_tx:
  701. .long 1 << DOORBELL_FROM_CARD_TX_0, 1 << DOORBELL_FROM_CARD_TX_1
  702. .long 1 << DOORBELL_FROM_CARD_TX_2, 1 << DOORBELL_FROM_CARD_TX_3
  703. bell_cable:
  704. .long 1 << DOORBELL_FROM_CARD_CABLE_0, 1 << DOORBELL_FROM_CARD_CABLE_1
  705. .long 1 << DOORBELL_FROM_CARD_CABLE_2, 1 << DOORBELL_FROM_CARD_CABLE_3
  706. packet_full:
  707. .long PACKET_FULL, PACKET_FULL + 1, PACKET_FULL + 2, PACKET_FULL + 3
  708. clocking_ext:
  709. .long 0x0000002C, 0x00003E00, 0x002C0000, 0x3E000000
  710. clocking_txfromrx:
  711. .long 0x0000002D, 0x00003F00, 0x002D0000, 0x3F000000
  712. clocking_mask:
  713. .long 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000
  714. dcd_mask:
  715. .word 0x020, 0, 0x080, 0, 0x200, 0, 0x800
  716. .ascii "wanXL firmware\n"
  717. .asciz "Copyright (C) 2003 Krzysztof Halasa <khc@pm.waw.pl>\n"
  718. /****************************** variables *****************************/
  719. .align 4
  720. channel_stats: .long 0
  721. tx_in: .long 0, 0, 0, 0 // transmitted
  722. tx_out: .long 0, 0, 0, 0 // received from host for transmission
  723. tx_count: .long 0, 0, 0, 0 // currently in transmit queue
  724. rx_in: .long 0, 0, 0, 0 // received from port
  725. rx_out: .long 0 // transmitted to host
  726. parity_bytes: .word 0, 0, 0, 0, 0, 0, 0 // only 4 words are used
  727. csr_output: .word 0
  728. old_csr_output: .word 0, 0, 0, 0, 0, 0, 0
  729. .align 4
  730. firmware_end: // must be dword-aligned