1.psize 0
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37#include <linux/hdlc.h>
38#include <linux/hdlc/ioctl.h>
39#include "wanxl.h"
40
41
42
43MAX_RAM_SIZE = 16 * 1024 * 1024
44
45PCI9060_VECTOR = 0x0000006C
46CPM_IRQ_BASE = 0x40
47ERROR_VECTOR = CPM_IRQ_BASE * 4
48SCC1_VECTOR = (CPM_IRQ_BASE + 0x1E) * 4
49SCC2_VECTOR = (CPM_IRQ_BASE + 0x1D) * 4
50SCC3_VECTOR = (CPM_IRQ_BASE + 0x1C) * 4
51SCC4_VECTOR = (CPM_IRQ_BASE + 0x1B) * 4
52CPM_IRQ_LEVEL = 4
53TIMER_IRQ = 128
54TIMER_IRQ_LEVEL = 4
55PITR_CONST = 0x100 + 16
56
57MBAR = 0x0003FF00
58
59VALUE_WINDOW = 0x40000000
60ORDER_WINDOW = 0xC0000000
61
62PLX = 0xFFF90000
63
64CSRA = 0xFFFB0000
65CSRB = 0xFFFB0002
66CSRC = 0xFFFB0004
67CSRD = 0xFFFB0006
68STATUS_CABLE_LL = 0x2000
69STATUS_CABLE_DTR = 0x1000
70
71DPRBASE = 0xFFFC0000
72
73SCC1_BASE = DPRBASE + 0xC00
74MISC_BASE = DPRBASE + 0xCB0
75SCC2_BASE = DPRBASE + 0xD00
76SCC3_BASE = DPRBASE + 0xE00
77SCC4_BASE = DPRBASE + 0xF00
78
79
80
81SCC_RBASE = 0
82SCC_TBASE = 2
83SCC_RFCR = 4
84SCC_TFCR = 5
85SCC_MRBLR = 6
86SCC_C_MASK = 0x34
87SCC_C_PRES = 0x38
88SCC_MFLR = 0x46
89
90REGBASE = DPRBASE + 0x1000
91PICR = REGBASE + 0x026
92PITR = REGBASE + 0x02A
93OR1 = REGBASE + 0x064
94CICR = REGBASE + 0x540
95CIMR = REGBASE + 0x548
96CISR = REGBASE + 0x54C
97PADIR = REGBASE + 0x550
98PAPAR = REGBASE + 0x552
99PAODR = REGBASE + 0x554
100PADAT = REGBASE + 0x556
101
102PCDIR = REGBASE + 0x560
103PCPAR = REGBASE + 0x562
104PCSO = REGBASE + 0x564
105PCDAT = REGBASE + 0x566
106PCINT = REGBASE + 0x568
107CR = REGBASE + 0x5C0
108
109SCC1_REGS = REGBASE + 0x600
110SCC2_REGS = REGBASE + 0x620
111SCC3_REGS = REGBASE + 0x640
112SCC4_REGS = REGBASE + 0x660
113SICR = REGBASE + 0x6EC
114
115
116SCC_GSMR_L = 0x00
117SCC_GSMR_H = 0x04
118SCC_PSMR = 0x08
119SCC_TODR = 0x0C
120SCC_DSR = 0x0E
121SCC_SCCE = 0x10
122SCC_SCCM = 0x14
123SCC_SCCS = 0x17
124
125
126 .macro memcpy_from_pci src, dest, len
127 addl
128 andl
129 movel \src, PLX_DMA_0_PCI
130 movel \dest, PLX_DMA_0_LOCAL
131 movel \len, PLX_DMA_0_LENGTH
132 movel
133 bsr memcpy_from_pci_run
134 .endm
135
136 .macro memcpy_to_pci src, dest, len
137 addl
138 andl
139 movel \src, PLX_DMA_1_LOCAL
140 movel \dest, PLX_DMA_1_PCI
141 movel \len, PLX_DMA_1_LENGTH
142 movel
143 bsr memcpy_to_pci_run
144 .endm
145
146#else
147
148 .macro memcpy src, dest, len
149 movel %d7, -(%sp)
150 movel \len, %d7
151 lsrl
152 andl \len, \len
153 beq 99f
154 subl
15598: movel (\src)+, (\dest)+
156 dbfw \len, 98b
15799: movel %d7, \len
158 btstl
159 beq 99f
160 movew (\src)+, (\dest)+
16199: btstl
162 beq 99f
163 moveb (\src)+, (\dest)+
16499:
165 movel (%sp)+, %d7
166 .endm
167
168 .macro memcpy_from_pci src, dest, len
169 addl
170 memcpy \src, \dest, \len
171 .endm
172
173 .macro memcpy_to_pci src, dest, len
174 addl
175 memcpy \src, \dest, \len
176 .endm
177#endif
178
179
180 .macro wait_for_command
18199: btstl
182 bne 99b
183 .endm
184
185
186
187
188
189 .text
190 .global _start
191_start: bra init
192
193 .org _start + 4
194ch_status_addr: .long 0, 0, 0, 0
195rx_descs_addr: .long 0
196
197init:
198
199 movel OR1, %d0
200 andl
201 orl
202 movel %d0, OR1
203#endif
204
205 addl
206 clrl %d0
207init_1: tstl ch_status_addr(%d0)
208 beq init_2
209 addl
210init_2: addl
211 cmpl
212 bne init_1
213
214 movel
215 movel
216 movel
217 movel
218 movel
219 movel
220 movel
221
222 movel
223 movew
224 movew
225
226
227 movel
228 movel
229 movel
230 movel
231 movel
232 movel
233
234 orl
235
236
237 bsr ram_test
238#else
239 movel
240#endif
241 bsr check_csr
242
243 movew
244 clrw PADIR
245 clrw PCSO
246
247
248
249
250main: movel channel_stats, %d7
251 clrl channel_stats
252
253 tstl %d7
254 bne main_1
255
256 stop
257 movew
258 bra main
259
260main_1: clrl %d0
261 clrl %d6
262
263main_l: btstl
264 beq main_op
265 bclrl
266 bsr close_port
267main_op:
268 btstl
269 beq main_cl
270 bsr open_port
271main_cl:
272 btstl
273 beq main_txend
274 bsr tx
275main_txend:
276 btstl
277 beq main_next
278 bsr tx_end
279 bsr rx
280
281main_next:
282 lsrl
283 addl
284 cmpl
285 bne main_l
286 movel %d6, PLX_DOORBELL_FROM_CARD
287 bra main
288
289
290
291
292open_port:
293 movel ch_status_addr(%d0), %a0
294 tstl STATUS_OPEN(%a0)
295 bne open_port_ret
296 movel
297
298 clrl tx_in(%d0)
299 clrl tx_out(%d0)
300 clrl tx_count(%d0)
301 clrl rx_in(%d0)
302
303 movel SICR, %d1
304 andl clocking_mask(%d0), %d1
305 cmpl
306 bne open_port_clock_ext
307 orl clocking_txfromrx(%d0), %d1
308 bra open_port_set_clock
309
310open_port_clock_ext:
311 orl clocking_ext(%d0), %d1
312open_port_set_clock:
313 movel %d1, SICR
314
315 orw
316 bsr check_csr
317
318
319 movel first_buffer(%d0), %d1
320 movel tx_first_bd(%d0), %a1
321 movel
322 movel
323 cmpl
324 beq open_port_tx_loop
325 bsetl
326open_port_tx_loop:
327 movel %d3, (%a1)+
328 movel %d1, (%a1)+
329 addl
330 dbfw %d2, open_port_tx_loop
331
332 bsetl
333 movel %d3, (%a1)+
334 movel %d1, (%a1)+
335
336
337 movel
338open_port_rx_loop:
339 movel
340 movel %d1, (%a1)+
341 addl
342 dbfw %d2, open_port_rx_loop
343
344 movel
345 movel %d1, (%a1)+
346
347
348 movel scc_base_addr(%d0), %a1
349 movel scc_reg_addr(%d0), %a2
350
351 movel
352 movel
353
354 movel tx_first_bd(%d0), %d1
355 movew %d1, SCC_TBASE(%a1)
356 addl
357 movew %d1, SCC_RBASE(%a1)
358 moveb
359 moveb
360
361
362 cmpl
363 bne open_port_parity_1
364 clrw SCC_PSMR(%a2)
365 movel
366 movel
367 movew
368 movew
369 bra open_port_2
370
371open_port_parity_1:
372 cmpl
373 bne open_port_parity_2
374 movew
375 movel
376 movel
377 movew
378 movew
379 bra open_port_2
380
381open_port_parity_2:
382 cmpl
383 bne open_port_parity_3
384 clrw SCC_PSMR(%a2)
385 movel
386 clrl SCC_C_PRES(%a1)
387 movew
388 movew
389 bra open_port_2
390
391open_port_parity_3:
392 cmpl
393 bne open_port_parity_4
394 movew
395 movel
396 clrl SCC_C_PRES(%a1)
397 movew
398 movew
399 bra open_port_2
400
401open_port_parity_4:
402 clrw SCC_PSMR(%a2)
403 movel
404 movel
405 movew
406 clrw parity_bytes(%d0)
407
408open_port_2:
409 movel
410 cmpl
411 bne open_port_nrz
412 movel
413 bra open_port_3
414
415open_port_nrz:
416 movel
417open_port_3:
418 movew
419 movel %d0, %d1
420 lsll
421 orl
422 movew %d1, CR
423 wait_for_command
424
425
426 movew
427 orl
428open_port_ret:
429 rts
430
431
432
433
434close_port:
435 movel scc_reg_addr(%d0), %a0
436 clrw SCC_SCCM(%a0)
437 andl
438
439 andw
440 bsr check_csr
441
442 movel ch_status_addr(%d0), %d1
443 clrl STATUS_OPEN(%d1)
444 rts
445
446
447
448
449tx:
450 cmpl
451 beq tx_ret
452
453 movel tx_out(%d0), %d1
454 movel %d1, %d2
455 mulul
456 addl ch_status_addr(%d0), %d2
457 addl
458 cmpl
459 bne tx_ret
460
461
462 movel 4(%d2), %a0
463 lsll
464 addl tx_first_bd(%d0), %d1
465
466 movel 4(%d1), %a1
467 movel 8(%d2), %d2
468 movew %d2, 2(%d1)
469 memcpy_from_pci %a0, %a1, %d2
470 bsetl
471
472
473 movel tx_out(%d0), %d1
474 addl
475 cmpl
476 bne tx_1
477 clrl %d1
478tx_1: movel %d1, tx_out(%d0)
479
480 addl
481 bra tx
482
483tx_ret: rts
484
485
486
487
488
489rx: movel rx_in(%d0), %d1
490 lsll
491 addl rx_first_bd(%d0), %d1
492 movew (%d1), %d2
493 btstl
494 bne rx_ret
495
496 btstl
497 bne rx_overrun
498
499 tstw parity_bytes(%d0)
500 bne rx_parity
501 bclrl
502rx_parity:
503 andw
504 cmpw
505 bne rx_bad_frame
506 clrl %d3
507 movew 2(%d1), %d3
508 subw parity_bytes(%d0), %d3
509 cmpw
510 bgt rx_bad_frame
511
512rx_good_frame:
513 movel rx_out, %d2
514 mulul
515 addl rx_descs_addr, %d2
516 cmpl
517 bne rx_overrun
518
519 movel %d3, 8(%d2)
520 movel 4(%d1), %a0
521 movel 4(%d2), %a1
522 tstl %a1
523 beq rx_ignore_data
524 memcpy_to_pci %a0, %a1, %d3
525rx_ignore_data:
526 movel packet_full(%d0), (%d2)
527
528
529 bsetl
530 movel rx_out, %d2
531 addl
532 cmpl
533 bne rx_1
534 clrl %d2
535rx_1: movel %d2, rx_out
536
537rx_free_bd:
538 andw
539 bsetl
540
541 movel rx_in(%d0), %d1
542 addl
543 cmpl
544 bne rx_2
545 clrl %d1
546rx_2: movel %d1, rx_in(%d0)
547 bra rx
548
549rx_overrun:
550 movel ch_status_addr(%d0), %d2
551 addl
552 bra rx_free_bd
553
554rx_bad_frame:
555 movel ch_status_addr(%d0), %d2
556 addl
557 bra rx_free_bd
558
559rx_ret: rts
560
561
562
563
564
565tx_end: tstl tx_count(%d0)
566 beq tx_end_ret
567
568 movel tx_in(%d0), %d1
569 movel %d1, %d2
570 lsll
571 addl tx_first_bd(%d0), %d1
572 movew (%d1), %d3
573 btstl
574 bne tx_end_ret
575
576
577 orl bell_tx(%d0), %d6
578 subl
579 movel tx_in(%d0), %d1
580 addl
581 cmpl
582 bne tx_end_1
583 clrl %d1
584tx_end_1:
585 movel %d1, tx_in(%d0)
586
587
588 mulul
589 addl ch_status_addr(%d0), %d2
590 addl
591 btstl
592 bne tx_end_underrun
593 movel
594 bra tx_end
595
596tx_end_underrun:
597 movel
598 bra tx_end
599
600tx_end_ret: rts
601
602
603
604
605
606
607memcpy_from_pci_run:
608 movel %d0, -(%sp)
609 movew %sr, -(%sp)
610memcpy_1:
611 movel PLX_DMA_CMD_STS, %d0
612 btstl
613 bne memcpy_end
614 stop
615 movew
616 bra memcpy_1
617
618memcpy_to_pci_run:
619 movel %d0, -(%sp)
620 movew %sr, -(%sp)
621memcpy_2:
622 movel PLX_DMA_CMD_STS, %d0
623 btstl
624 bne memcpy_end
625 stop
626 movew
627 bra memcpy_2
628
629memcpy_end:
630 movew (%sp)+, %sr
631 movel (%sp)+, %d0
632 rts
633#endif
634
635
636
637
638
639
640
641
642pci9060_interrupt:
643 movel %d0, -(%sp)
644
645 movel PLX_DOORBELL_TO_CARD, %d0
646 movel %d0, PLX_DOORBELL_TO_CARD
647 orl %d0, channel_stats
648
649 movel
650
651 movel (%sp)+, %d0
652 rte
653
654
655
656port_interrupt_1:
657 orl
658 orl
659 movel
660 rte
661
662port_interrupt_2:
663 orl
664 orl
665 movel
666 rte
667
668port_interrupt_3:
669 orl
670 orl
671 movel
672 rte
673
674port_interrupt_4:
675 orl
676 orl
677 movel
678 rte
679
680error_interrupt:
681 rte
682
683
684
685
686check_csr:
687 movel %d0, -(%sp)
688 movel %d1, -(%sp)
689 movel %d2, -(%sp)
690 movel %a0, -(%sp)
691 movel %a1, -(%sp)
692
693 clrl %d0
694 movel
695
696check_csr_loop:
697 movew (%a0), %d1
698 andl
699 cmpw
700 bne check_csr_1
701 movew
702 bra check_csr_valid
703
704check_csr_1:
705 cmpw
706 bne check_csr_2
707 movew
708 bra check_csr_valid
709
710check_csr_2:
711 cmpw
712 bne check_csr_3
713 movew
714 bra check_csr_valid
715
716check_csr_3:
717 cmpw
718 bne check_csr_disable
719 movew
720 bra check_csr_valid
721
722check_csr_disable:
723 movew
724 movew
725 bra check_csr_write
726
727check_csr_valid:
728 movew csr_output(%d0), %d2
729 andw
730 orw %d2, %d1
731 movew
732
733check_csr_write:
734 cmpw old_csr_output(%d0), %d1
735 beq check_csr_input
736 movew %d1, old_csr_output(%d0)
737 movew %d1, (%a0)
738
739check_csr_input:
740 movew (PCDAT), %d1
741 andw dcd_mask(%d0), %d1
742 beq check_csr_dcd_on
743 movew (%a0), %d1
744 andw
745 bra check_csr_previous
746
747check_csr_dcd_on:
748 movew (%a0), %d1
749 orw
750check_csr_previous:
751 andw %d2, %d1
752 movel ch_status_addr(%d0), %a1
753 cmpl STATUS_CABLE(%a1), %d1
754 beq check_csr_next
755 movel %d1, STATUS_CABLE(%a1)
756 movel bell_cable(%d0), PLX_DOORBELL_FROM_CARD
757
758check_csr_next:
759 addl
760 addl
761 cmpl
762 bne check_csr_loop
763
764 movel (%sp)+, %a1
765 movel (%sp)+, %a0
766 movel (%sp)+, %d2
767 movel (%sp)+, %d1
768 movel (%sp)+, %d0
769 rts
770
771
772
773
774timer_interrupt:
775 bsr check_csr
776 rte
777
778
779
780
781ram_test:
782 movel
783 movel %d1, (128 * 1024 - 4)
784 movel
785ram_test_size:
786 cmpl
787 beq ram_test_size_found
788 movel %d0, %a0
789 addl
790 cmpl (%a0), %d1
791 beq ram_test_size_check
792ram_test_next_size:
793 lsll
794 bra ram_test_size
795
796ram_test_size_check:
797 eorl
798 movel %d1, (128 * 1024 - 4)
799 cmpl (%a0), %d1
800 bne ram_test_next_size
801
802ram_test_size_found:
803 movel %d0, %a0
804 subl
805 lsrl
806 movel %d0, %d1
807ram_test_fill:
808 movel %a0, -(%a0)
809 dbfw %d1, ram_test_fill
810 subl
811 cmpl
812 bne ram_test_fill
813
814ram_test_loop:
815 cmpl (%a0)+, %a0
816 dbnew %d0, ram_test_loop
817 bne ram_test_found_bad
818 subl
819 cmpl
820 bne ram_test_loop
821 bra ram_test_all_ok
822
823ram_test_found_bad:
824 subl
825ram_test_all_ok:
826 movel %a0, PLX_MAILBOX_5
827 rts
828#endif
829
830
831
832
833scc_reg_addr:
834 .long SCC1_REGS, SCC2_REGS, SCC3_REGS, SCC4_REGS
835scc_base_addr:
836 .long SCC1_BASE, SCC2_BASE, SCC3_BASE, SCC4_BASE
837
838tx_first_bd:
839 .long DPRBASE
840 .long DPRBASE + (TX_BUFFERS + RX_BUFFERS) * 8
841 .long DPRBASE + (TX_BUFFERS + RX_BUFFERS) * 8 * 2
842 .long DPRBASE + (TX_BUFFERS + RX_BUFFERS) * 8 * 3
843
844rx_first_bd:
845 .long DPRBASE + TX_BUFFERS * 8
846 .long DPRBASE + TX_BUFFERS * 8 + (TX_BUFFERS + RX_BUFFERS) * 8
847 .long DPRBASE + TX_BUFFERS * 8 + (TX_BUFFERS + RX_BUFFERS) * 8 * 2
848 .long DPRBASE + TX_BUFFERS * 8 + (TX_BUFFERS + RX_BUFFERS) * 8 * 3
849
850first_buffer:
851 .long BUFFERS_ADDR
852 .long BUFFERS_ADDR + (TX_BUFFERS + RX_BUFFERS) * BUFFER_LENGTH
853 .long BUFFERS_ADDR + (TX_BUFFERS + RX_BUFFERS) * BUFFER_LENGTH * 2
854 .long BUFFERS_ADDR + (TX_BUFFERS + RX_BUFFERS) * BUFFER_LENGTH * 3
855
856bell_tx:
857 .long 1 << DOORBELL_FROM_CARD_TX_0, 1 << DOORBELL_FROM_CARD_TX_1
858 .long 1 << DOORBELL_FROM_CARD_TX_2, 1 << DOORBELL_FROM_CARD_TX_3
859
860bell_cable:
861 .long 1 << DOORBELL_FROM_CARD_CABLE_0, 1 << DOORBELL_FROM_CARD_CABLE_1
862 .long 1 << DOORBELL_FROM_CARD_CABLE_2, 1 << DOORBELL_FROM_CARD_CABLE_3
863
864packet_full:
865 .long PACKET_FULL, PACKET_FULL + 1, PACKET_FULL + 2, PACKET_FULL + 3
866
867clocking_ext:
868 .long 0x0000002C, 0x00003E00, 0x002C0000, 0x3E000000
869clocking_txfromrx:
870 .long 0x0000002D, 0x00003F00, 0x002D0000, 0x3F000000
871clocking_mask:
872 .long 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000
873dcd_mask:
874 .word 0x020, 0, 0x080, 0, 0x200, 0, 0x800
875
876 .ascii "wanXL firmware\n"
877 .asciz "Copyright (C) 2003 Krzysztof Halasa <khc@pm.waw.pl>\n"
878
879
880
881
882 .align 4
883channel_stats: .long 0
884
885tx_in: .long 0, 0, 0, 0
886tx_out: .long 0, 0, 0, 0
887tx_count: .long 0, 0, 0, 0
888
889rx_in: .long 0, 0, 0, 0
890rx_out: .long 0
891parity_bytes: .word 0, 0, 0, 0, 0, 0, 0
892
893csr_output: .word 0
894old_csr_output: .word 0, 0, 0, 0, 0, 0, 0
895 .align 4
896firmware_end:
897