1
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
38
39#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
40
41#include <linux/module.h>
42#include <linux/kernel.h>
43#include <linux/mm.h>
44#include <linux/net.h>
45#include <linux/skbuff.h>
46#include <linux/netdevice.h>
47#include <linux/if_arp.h>
48#include <linux/delay.h>
49#include <linux/hdlc.h>
50#include <linux/ioport.h>
51#include <linux/init.h>
52#include <linux/gfp.h>
53#include <asm/dma.h>
54#include <asm/io.h>
55#define RT_LOCK
56#define RT_UNLOCK
57#include <linux/spinlock.h>
58
59#include "z85230.h"
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78static inline int z8530_read_port(unsigned long p)
79{
80 u8 r=inb(Z8530_PORT_OF(p));
81 if(p&Z8530_PORT_SLEEP)
82 udelay(5);
83 return r;
84}
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102static inline void z8530_write_port(unsigned long p, u8 d)
103{
104 outb(d,Z8530_PORT_OF(p));
105 if(p&Z8530_PORT_SLEEP)
106 udelay(5);
107}
108
109
110
111static void z8530_rx_done(struct z8530_channel *c);
112static void z8530_tx_done(struct z8530_channel *c);
113
114
115
116
117
118
119
120
121
122
123
124
125
126static inline u8 read_zsreg(struct z8530_channel *c, u8 reg)
127{
128 if(reg)
129 z8530_write_port(c->ctrlio, reg);
130 return z8530_read_port(c->ctrlio);
131}
132
133
134
135
136
137
138
139
140
141static inline u8 read_zsdata(struct z8530_channel *c)
142{
143 u8 r;
144 r=z8530_read_port(c->dataio);
145 return r;
146}
147
148
149
150
151
152
153
154
155
156
157
158
159
160static inline void write_zsreg(struct z8530_channel *c, u8 reg, u8 val)
161{
162 if(reg)
163 z8530_write_port(c->ctrlio, reg);
164 z8530_write_port(c->ctrlio, val);
165
166}
167
168
169
170
171
172
173
174
175
176static inline void write_zsctrl(struct z8530_channel *c, u8 val)
177{
178 z8530_write_port(c->ctrlio, val);
179}
180
181
182
183
184
185
186
187
188
189
190static inline void write_zsdata(struct z8530_channel *c, u8 val)
191{
192 z8530_write_port(c->dataio, val);
193}
194
195
196
197
198
199u8 z8530_dead_port[]=
200{
201 255
202};
203
204EXPORT_SYMBOL(z8530_dead_port);
205
206
207
208
209
210
211
212
213
214
215
216u8 z8530_hdlc_kilostream[]=
217{
218 4, SYNC_ENAB|SDLC|X1CLK,
219 2, 0,
220 1, 0,
221 3, ENT_HM|RxCRC_ENAB|Rx8,
222 5, TxCRC_ENAB|RTS|TxENAB|Tx8|DTR,
223 9, 0,
224 6, 0xFF,
225 7, FLAG,
226 10, ABUNDER|NRZ|CRCPS,
227 11, TCTRxCP,
228 14, DISDPLL,
229 15, DCDIE|SYNCIE|CTSIE|TxUIE|BRKIE,
230 1, EXT_INT_ENAB|TxINT_ENAB|INT_ALL_Rx,
231 9, NV|MIE|NORESET,
232 255
233};
234
235EXPORT_SYMBOL(z8530_hdlc_kilostream);
236
237
238
239
240
241u8 z8530_hdlc_kilostream_85230[]=
242{
243 4, SYNC_ENAB|SDLC|X1CLK,
244 2, 0,
245 1, 0,
246 3, ENT_HM|RxCRC_ENAB|Rx8,
247 5, TxCRC_ENAB|RTS|TxENAB|Tx8|DTR,
248 9, 0,
249 6, 0xFF,
250 7, FLAG,
251 10, ABUNDER|NRZ|CRCPS,
252 11, TCTRxCP,
253 14, DISDPLL,
254 15, DCDIE|SYNCIE|CTSIE|TxUIE|BRKIE,
255 1, EXT_INT_ENAB|TxINT_ENAB|INT_ALL_Rx,
256 9, NV|MIE|NORESET,
257 23, 3,
258
259 255
260};
261
262EXPORT_SYMBOL(z8530_hdlc_kilostream_85230);
263
264
265
266
267
268
269
270
271
272
273
274
275
276static void z8530_flush_fifo(struct z8530_channel *c)
277{
278 read_zsreg(c, R1);
279 read_zsreg(c, R1);
280 read_zsreg(c, R1);
281 read_zsreg(c, R1);
282 if(c->dev->type==Z85230)
283 {
284 read_zsreg(c, R1);
285 read_zsreg(c, R1);
286 read_zsreg(c, R1);
287 read_zsreg(c, R1);
288 }
289}
290
291
292
293
294
295
296
297
298
299
300
301
302static void z8530_rtsdtr(struct z8530_channel *c, int set)
303{
304 if (set)
305 c->regs[5] |= (RTS | DTR);
306 else
307 c->regs[5] &= ~(RTS | DTR);
308 write_zsreg(c, R5, c->regs[5]);
309}
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335static void z8530_rx(struct z8530_channel *c)
336{
337 u8 ch,stat;
338
339 while(1)
340 {
341
342 if(!(read_zsreg(c, R0)&1))
343 break;
344 ch=read_zsdata(c);
345 stat=read_zsreg(c, R1);
346
347
348
349
350 if(c->count < c->max)
351 {
352 *c->dptr++=ch;
353 c->count++;
354 }
355
356 if(stat&END_FR)
357 {
358
359
360
361
362 if(stat&(Rx_OVR|CRC_ERR))
363 {
364
365 if(c->skb)
366 c->dptr=c->skb->data;
367 c->count=0;
368 if(stat&Rx_OVR)
369 {
370 pr_warn("%s: overrun\n", c->dev->name);
371 c->rx_overrun++;
372 }
373 if(stat&CRC_ERR)
374 {
375 c->rx_crc_err++;
376
377 }
378
379 }
380 else
381 {
382
383
384
385
386 z8530_rx_done(c);
387 write_zsctrl(c, RES_Rx_CRC);
388 }
389 }
390 }
391
392
393
394 write_zsctrl(c, ERR_RES);
395 write_zsctrl(c, RES_H_IUS);
396}
397
398
399
400
401
402
403
404
405
406
407
408
409static void z8530_tx(struct z8530_channel *c)
410{
411 while(c->txcount) {
412
413 if(!(read_zsreg(c, R0)&4))
414 return;
415 c->txcount--;
416
417
418
419 write_zsreg(c, R8, *c->tx_ptr++);
420 write_zsctrl(c, RES_H_IUS);
421
422 if(c->txcount==0)
423 {
424 write_zsctrl(c, RES_EOM_L);
425 write_zsreg(c, R10, c->regs[10]&~ABUNDER);
426 }
427 }
428
429
430
431
432
433
434 write_zsctrl(c, RES_Tx_P);
435
436 z8530_tx_done(c);
437 write_zsctrl(c, RES_H_IUS);
438}
439
440
441
442
443
444
445
446
447
448
449
450static void z8530_status(struct z8530_channel *chan)
451{
452 u8 status, altered;
453
454 status = read_zsreg(chan, R0);
455 altered = chan->status ^ status;
456
457 chan->status = status;
458
459 if (status & TxEOM) {
460
461 chan->netdevice->stats.tx_fifo_errors++;
462 write_zsctrl(chan, ERR_RES);
463 z8530_tx_done(chan);
464 }
465
466 if (altered & chan->dcdcheck)
467 {
468 if (status & chan->dcdcheck) {
469 pr_info("%s: DCD raised\n", chan->dev->name);
470 write_zsreg(chan, R3, chan->regs[3] | RxENABLE);
471 if (chan->netdevice)
472 netif_carrier_on(chan->netdevice);
473 } else {
474 pr_info("%s: DCD lost\n", chan->dev->name);
475 write_zsreg(chan, R3, chan->regs[3] & ~RxENABLE);
476 z8530_flush_fifo(chan);
477 if (chan->netdevice)
478 netif_carrier_off(chan->netdevice);
479 }
480
481 }
482 write_zsctrl(chan, RES_EXT_INT);
483 write_zsctrl(chan, RES_H_IUS);
484}
485
486struct z8530_irqhandler z8530_sync =
487{
488 z8530_rx,
489 z8530_tx,
490 z8530_status
491};
492
493EXPORT_SYMBOL(z8530_sync);
494
495
496
497
498
499
500
501
502
503
504
505static void z8530_dma_rx(struct z8530_channel *chan)
506{
507 if(chan->rxdma_on)
508 {
509
510 u8 status;
511
512 read_zsreg(chan, R7);
513 read_zsreg(chan, R6);
514
515 status=read_zsreg(chan, R1);
516
517 if(status&END_FR)
518 {
519 z8530_rx_done(chan);
520 }
521 write_zsctrl(chan, ERR_RES);
522 write_zsctrl(chan, RES_H_IUS);
523 }
524 else
525 {
526
527 z8530_rx(chan);
528 }
529}
530
531
532
533
534
535
536
537
538
539static void z8530_dma_tx(struct z8530_channel *chan)
540{
541 if(!chan->dma_tx)
542 {
543 pr_warn("Hey who turned the DMA off?\n");
544 z8530_tx(chan);
545 return;
546 }
547
548 pr_err("DMA tx - bogus event!\n");
549 z8530_tx(chan);
550}
551
552
553
554
555
556
557
558
559
560
561
562static void z8530_dma_status(struct z8530_channel *chan)
563{
564 u8 status, altered;
565
566 status=read_zsreg(chan, R0);
567 altered=chan->status^status;
568
569 chan->status=status;
570
571
572 if(chan->dma_tx)
573 {
574 if(status&TxEOM)
575 {
576 unsigned long flags;
577
578 flags=claim_dma_lock();
579 disable_dma(chan->txdma);
580 clear_dma_ff(chan->txdma);
581 chan->txdma_on=0;
582 release_dma_lock(flags);
583 z8530_tx_done(chan);
584 }
585 }
586
587 if (altered & chan->dcdcheck)
588 {
589 if (status & chan->dcdcheck) {
590 pr_info("%s: DCD raised\n", chan->dev->name);
591 write_zsreg(chan, R3, chan->regs[3] | RxENABLE);
592 if (chan->netdevice)
593 netif_carrier_on(chan->netdevice);
594 } else {
595 pr_info("%s: DCD lost\n", chan->dev->name);
596 write_zsreg(chan, R3, chan->regs[3] & ~RxENABLE);
597 z8530_flush_fifo(chan);
598 if (chan->netdevice)
599 netif_carrier_off(chan->netdevice);
600 }
601 }
602
603 write_zsctrl(chan, RES_EXT_INT);
604 write_zsctrl(chan, RES_H_IUS);
605}
606
607static struct z8530_irqhandler z8530_dma_sync = {
608 z8530_dma_rx,
609 z8530_dma_tx,
610 z8530_dma_status
611};
612
613static struct z8530_irqhandler z8530_txdma_sync = {
614 z8530_rx,
615 z8530_dma_tx,
616 z8530_dma_status
617};
618
619
620
621
622
623
624
625
626
627
628
629static void z8530_rx_clear(struct z8530_channel *c)
630{
631
632
633
634 u8 stat;
635
636 read_zsdata(c);
637 stat=read_zsreg(c, R1);
638
639 if(stat&END_FR)
640 write_zsctrl(c, RES_Rx_CRC);
641
642
643
644 write_zsctrl(c, ERR_RES);
645 write_zsctrl(c, RES_H_IUS);
646}
647
648
649
650
651
652
653
654
655
656
657static void z8530_tx_clear(struct z8530_channel *c)
658{
659 write_zsctrl(c, RES_Tx_P);
660 write_zsctrl(c, RES_H_IUS);
661}
662
663
664
665
666
667
668
669
670
671
672static void z8530_status_clear(struct z8530_channel *chan)
673{
674 u8 status=read_zsreg(chan, R0);
675 if(status&TxEOM)
676 write_zsctrl(chan, ERR_RES);
677 write_zsctrl(chan, RES_EXT_INT);
678 write_zsctrl(chan, RES_H_IUS);
679}
680
681struct z8530_irqhandler z8530_nop=
682{
683 z8530_rx_clear,
684 z8530_tx_clear,
685 z8530_status_clear
686};
687
688
689EXPORT_SYMBOL(z8530_nop);
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707irqreturn_t z8530_interrupt(int irq, void *dev_id)
708{
709 struct z8530_dev *dev=dev_id;
710 u8 uninitialized_var(intr);
711 static volatile int locker=0;
712 int work=0;
713 struct z8530_irqhandler *irqs;
714
715 if(locker)
716 {
717 pr_err("IRQ re-enter\n");
718 return IRQ_NONE;
719 }
720 locker=1;
721
722 spin_lock(&dev->lock);
723
724 while(++work<5000)
725 {
726
727 intr = read_zsreg(&dev->chanA, R3);
728 if(!(intr & (CHARxIP|CHATxIP|CHAEXT|CHBRxIP|CHBTxIP|CHBEXT)))
729 break;
730
731
732
733
734
735
736
737 irqs=dev->chanA.irqs;
738
739 if(intr & (CHARxIP|CHATxIP|CHAEXT))
740 {
741 if(intr&CHARxIP)
742 irqs->rx(&dev->chanA);
743 if(intr&CHATxIP)
744 irqs->tx(&dev->chanA);
745 if(intr&CHAEXT)
746 irqs->status(&dev->chanA);
747 }
748
749 irqs=dev->chanB.irqs;
750
751 if(intr & (CHBRxIP|CHBTxIP|CHBEXT))
752 {
753 if(intr&CHBRxIP)
754 irqs->rx(&dev->chanB);
755 if(intr&CHBTxIP)
756 irqs->tx(&dev->chanB);
757 if(intr&CHBEXT)
758 irqs->status(&dev->chanB);
759 }
760 }
761 spin_unlock(&dev->lock);
762 if(work==5000)
763 pr_err("%s: interrupt jammed - abort(0x%X)!\n",
764 dev->name, intr);
765
766 locker=0;
767 return IRQ_HANDLED;
768}
769
770EXPORT_SYMBOL(z8530_interrupt);
771
772static const u8 reg_init[16]=
773{
774 0,0,0,0,
775 0,0,0,0,
776 0,0,0,0,
777 0x55,0,0,0
778};
779
780
781
782
783
784
785
786
787
788
789
790int z8530_sync_open(struct net_device *dev, struct z8530_channel *c)
791{
792 unsigned long flags;
793
794 spin_lock_irqsave(c->lock, flags);
795
796 c->sync = 1;
797 c->mtu = dev->mtu+64;
798 c->count = 0;
799 c->skb = NULL;
800 c->skb2 = NULL;
801 c->irqs = &z8530_sync;
802
803
804 z8530_rx_done(c);
805 z8530_rx_done(c);
806 z8530_rtsdtr(c,1);
807 c->dma_tx = 0;
808 c->regs[R1]|=TxINT_ENAB;
809 write_zsreg(c, R1, c->regs[R1]);
810 write_zsreg(c, R3, c->regs[R3]|RxENABLE);
811
812 spin_unlock_irqrestore(c->lock, flags);
813 return 0;
814}
815
816
817EXPORT_SYMBOL(z8530_sync_open);
818
819
820
821
822
823
824
825
826
827
828int z8530_sync_close(struct net_device *dev, struct z8530_channel *c)
829{
830 u8 chk;
831 unsigned long flags;
832
833 spin_lock_irqsave(c->lock, flags);
834 c->irqs = &z8530_nop;
835 c->max = 0;
836 c->sync = 0;
837
838 chk=read_zsreg(c,R0);
839 write_zsreg(c, R3, c->regs[R3]);
840 z8530_rtsdtr(c,0);
841
842 spin_unlock_irqrestore(c->lock, flags);
843 return 0;
844}
845
846EXPORT_SYMBOL(z8530_sync_close);
847
848
849
850
851
852
853
854
855
856
857
858int z8530_sync_dma_open(struct net_device *dev, struct z8530_channel *c)
859{
860 unsigned long cflags, dflags;
861
862 c->sync = 1;
863 c->mtu = dev->mtu+64;
864 c->count = 0;
865 c->skb = NULL;
866 c->skb2 = NULL;
867
868
869
870 c->rxdma_on = 0;
871 c->txdma_on = 0;
872
873
874
875
876
877
878
879 if(c->mtu > PAGE_SIZE/2)
880 return -EMSGSIZE;
881
882 c->rx_buf[0]=(void *)get_zeroed_page(GFP_KERNEL|GFP_DMA);
883 if(c->rx_buf[0]==NULL)
884 return -ENOBUFS;
885 c->rx_buf[1]=c->rx_buf[0]+PAGE_SIZE/2;
886
887 c->tx_dma_buf[0]=(void *)get_zeroed_page(GFP_KERNEL|GFP_DMA);
888 if(c->tx_dma_buf[0]==NULL)
889 {
890 free_page((unsigned long)c->rx_buf[0]);
891 c->rx_buf[0]=NULL;
892 return -ENOBUFS;
893 }
894 c->tx_dma_buf[1]=c->tx_dma_buf[0]+PAGE_SIZE/2;
895
896 c->tx_dma_used=0;
897 c->dma_tx = 1;
898 c->dma_num=0;
899 c->dma_ready=1;
900
901
902
903
904
905 spin_lock_irqsave(c->lock, cflags);
906
907
908
909
910
911 c->regs[R14]|= DTRREQ;
912 write_zsreg(c, R14, c->regs[R14]);
913
914 c->regs[R1]&= ~TxINT_ENAB;
915 write_zsreg(c, R1, c->regs[R1]);
916
917
918
919
920
921 c->regs[R1]|= WT_FN_RDYFN;
922 c->regs[R1]|= WT_RDY_RT;
923 c->regs[R1]|= INT_ERR_Rx;
924 c->regs[R1]&= ~TxINT_ENAB;
925 write_zsreg(c, R1, c->regs[R1]);
926 c->regs[R1]|= WT_RDY_ENAB;
927 write_zsreg(c, R1, c->regs[R1]);
928
929
930
931
932
933
934
935
936
937 dflags=claim_dma_lock();
938
939 disable_dma(c->rxdma);
940 clear_dma_ff(c->rxdma);
941 set_dma_mode(c->rxdma, DMA_MODE_READ|0x10);
942 set_dma_addr(c->rxdma, virt_to_bus(c->rx_buf[0]));
943 set_dma_count(c->rxdma, c->mtu);
944 enable_dma(c->rxdma);
945
946 disable_dma(c->txdma);
947 clear_dma_ff(c->txdma);
948 set_dma_mode(c->txdma, DMA_MODE_WRITE);
949 disable_dma(c->txdma);
950
951 release_dma_lock(dflags);
952
953
954
955
956
957 c->rxdma_on = 1;
958 c->txdma_on = 1;
959 c->tx_dma_used = 1;
960
961 c->irqs = &z8530_dma_sync;
962 z8530_rtsdtr(c,1);
963 write_zsreg(c, R3, c->regs[R3]|RxENABLE);
964
965 spin_unlock_irqrestore(c->lock, cflags);
966
967 return 0;
968}
969
970EXPORT_SYMBOL(z8530_sync_dma_open);
971
972
973
974
975
976
977
978
979
980
981int z8530_sync_dma_close(struct net_device *dev, struct z8530_channel *c)
982{
983 u8 chk;
984 unsigned long flags;
985
986 c->irqs = &z8530_nop;
987 c->max = 0;
988 c->sync = 0;
989
990
991
992
993
994 flags=claim_dma_lock();
995 disable_dma(c->rxdma);
996 clear_dma_ff(c->rxdma);
997
998 c->rxdma_on = 0;
999
1000 disable_dma(c->txdma);
1001 clear_dma_ff(c->txdma);
1002 release_dma_lock(flags);
1003
1004 c->txdma_on = 0;
1005 c->tx_dma_used = 0;
1006
1007 spin_lock_irqsave(c->lock, flags);
1008
1009
1010
1011
1012
1013 c->regs[R1]&= ~WT_RDY_ENAB;
1014 write_zsreg(c, R1, c->regs[R1]);
1015 c->regs[R1]&= ~(WT_RDY_RT|WT_FN_RDYFN|INT_ERR_Rx);
1016 c->regs[R1]|= INT_ALL_Rx;
1017 write_zsreg(c, R1, c->regs[R1]);
1018 c->regs[R14]&= ~DTRREQ;
1019 write_zsreg(c, R14, c->regs[R14]);
1020
1021 if(c->rx_buf[0])
1022 {
1023 free_page((unsigned long)c->rx_buf[0]);
1024 c->rx_buf[0]=NULL;
1025 }
1026 if(c->tx_dma_buf[0])
1027 {
1028 free_page((unsigned long)c->tx_dma_buf[0]);
1029 c->tx_dma_buf[0]=NULL;
1030 }
1031 chk=read_zsreg(c,R0);
1032 write_zsreg(c, R3, c->regs[R3]);
1033 z8530_rtsdtr(c,0);
1034
1035 spin_unlock_irqrestore(c->lock, flags);
1036
1037 return 0;
1038}
1039
1040EXPORT_SYMBOL(z8530_sync_dma_close);
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052int z8530_sync_txdma_open(struct net_device *dev, struct z8530_channel *c)
1053{
1054 unsigned long cflags, dflags;
1055
1056 printk("Opening sync interface for TX-DMA\n");
1057 c->sync = 1;
1058 c->mtu = dev->mtu+64;
1059 c->count = 0;
1060 c->skb = NULL;
1061 c->skb2 = NULL;
1062
1063
1064
1065
1066
1067
1068
1069 if(c->mtu > PAGE_SIZE/2)
1070 return -EMSGSIZE;
1071
1072 c->tx_dma_buf[0]=(void *)get_zeroed_page(GFP_KERNEL|GFP_DMA);
1073 if(c->tx_dma_buf[0]==NULL)
1074 return -ENOBUFS;
1075
1076 c->tx_dma_buf[1] = c->tx_dma_buf[0] + PAGE_SIZE/2;
1077
1078
1079 spin_lock_irqsave(c->lock, cflags);
1080
1081
1082
1083
1084
1085 z8530_rx_done(c);
1086 z8530_rx_done(c);
1087
1088
1089
1090
1091
1092 c->rxdma_on = 0;
1093 c->txdma_on = 0;
1094
1095 c->tx_dma_used=0;
1096 c->dma_num=0;
1097 c->dma_ready=1;
1098 c->dma_tx = 1;
1099
1100
1101
1102
1103
1104
1105
1106
1107 c->regs[R14]|= DTRREQ;
1108 write_zsreg(c, R14, c->regs[R14]);
1109
1110 c->regs[R1]&= ~TxINT_ENAB;
1111 write_zsreg(c, R1, c->regs[R1]);
1112
1113
1114
1115
1116
1117 dflags = claim_dma_lock();
1118
1119 disable_dma(c->txdma);
1120 clear_dma_ff(c->txdma);
1121 set_dma_mode(c->txdma, DMA_MODE_WRITE);
1122 disable_dma(c->txdma);
1123
1124 release_dma_lock(dflags);
1125
1126
1127
1128
1129
1130 c->rxdma_on = 0;
1131 c->txdma_on = 1;
1132 c->tx_dma_used = 1;
1133
1134 c->irqs = &z8530_txdma_sync;
1135 z8530_rtsdtr(c,1);
1136 write_zsreg(c, R3, c->regs[R3]|RxENABLE);
1137 spin_unlock_irqrestore(c->lock, cflags);
1138
1139 return 0;
1140}
1141
1142EXPORT_SYMBOL(z8530_sync_txdma_open);
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153int z8530_sync_txdma_close(struct net_device *dev, struct z8530_channel *c)
1154{
1155 unsigned long dflags, cflags;
1156 u8 chk;
1157
1158
1159 spin_lock_irqsave(c->lock, cflags);
1160
1161 c->irqs = &z8530_nop;
1162 c->max = 0;
1163 c->sync = 0;
1164
1165
1166
1167
1168
1169 dflags = claim_dma_lock();
1170
1171 disable_dma(c->txdma);
1172 clear_dma_ff(c->txdma);
1173 c->txdma_on = 0;
1174 c->tx_dma_used = 0;
1175
1176 release_dma_lock(dflags);
1177
1178
1179
1180
1181
1182 c->regs[R1]&= ~WT_RDY_ENAB;
1183 write_zsreg(c, R1, c->regs[R1]);
1184 c->regs[R1]&= ~(WT_RDY_RT|WT_FN_RDYFN|INT_ERR_Rx);
1185 c->regs[R1]|= INT_ALL_Rx;
1186 write_zsreg(c, R1, c->regs[R1]);
1187 c->regs[R14]&= ~DTRREQ;
1188 write_zsreg(c, R14, c->regs[R14]);
1189
1190 if(c->tx_dma_buf[0])
1191 {
1192 free_page((unsigned long)c->tx_dma_buf[0]);
1193 c->tx_dma_buf[0]=NULL;
1194 }
1195 chk=read_zsreg(c,R0);
1196 write_zsreg(c, R3, c->regs[R3]);
1197 z8530_rtsdtr(c,0);
1198
1199 spin_unlock_irqrestore(c->lock, cflags);
1200 return 0;
1201}
1202
1203
1204EXPORT_SYMBOL(z8530_sync_txdma_close);
1205
1206
1207
1208
1209
1210
1211
1212static const char *z8530_type_name[]={
1213 "Z8530",
1214 "Z85C30",
1215 "Z85230"
1216};
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229void z8530_describe(struct z8530_dev *dev, char *mapping, unsigned long io)
1230{
1231 pr_info("%s: %s found at %s 0x%lX, IRQ %d\n",
1232 dev->name,
1233 z8530_type_name[dev->type],
1234 mapping,
1235 Z8530_PORT_OF(io),
1236 dev->irq);
1237}
1238
1239EXPORT_SYMBOL(z8530_describe);
1240
1241
1242
1243
1244
1245static inline int do_z8530_init(struct z8530_dev *dev)
1246{
1247
1248
1249 dev->chanA.irqs=&z8530_nop;
1250 dev->chanB.irqs=&z8530_nop;
1251 dev->chanA.dcdcheck=DCD;
1252 dev->chanB.dcdcheck=DCD;
1253
1254
1255 write_zsreg(&dev->chanA, R9, 0xC0);
1256 udelay(200);
1257
1258 write_zsreg(&dev->chanA, R12, 0xAA);
1259 if(read_zsreg(&dev->chanA, R12)!=0xAA)
1260 return -ENODEV;
1261 write_zsreg(&dev->chanA, R12, 0x55);
1262 if(read_zsreg(&dev->chanA, R12)!=0x55)
1263 return -ENODEV;
1264
1265 dev->type=Z8530;
1266
1267
1268
1269
1270
1271 write_zsreg(&dev->chanA, R15, 0x01);
1272
1273
1274
1275
1276
1277
1278 if(read_zsreg(&dev->chanA, R15)==0x01)
1279 {
1280
1281
1282 write_zsreg(&dev->chanA, R8, 0);
1283 if(read_zsreg(&dev->chanA, R0)&Tx_BUF_EMP)
1284 dev->type = Z85230;
1285 else
1286 dev->type = Z85C30;
1287 }
1288
1289
1290
1291
1292
1293
1294
1295 write_zsreg(&dev->chanA, R15, 0);
1296
1297
1298
1299
1300
1301 memcpy(dev->chanA.regs, reg_init, 16);
1302 memcpy(dev->chanB.regs, reg_init ,16);
1303
1304 return 0;
1305}
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324int z8530_init(struct z8530_dev *dev)
1325{
1326 unsigned long flags;
1327 int ret;
1328
1329
1330 spin_lock_init(&dev->lock);
1331 dev->chanA.lock = &dev->lock;
1332 dev->chanB.lock = &dev->lock;
1333
1334 spin_lock_irqsave(&dev->lock, flags);
1335 ret = do_z8530_init(dev);
1336 spin_unlock_irqrestore(&dev->lock, flags);
1337
1338 return ret;
1339}
1340
1341
1342EXPORT_SYMBOL(z8530_init);
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355int z8530_shutdown(struct z8530_dev *dev)
1356{
1357 unsigned long flags;
1358
1359
1360 spin_lock_irqsave(&dev->lock, flags);
1361 dev->chanA.irqs=&z8530_nop;
1362 dev->chanB.irqs=&z8530_nop;
1363 write_zsreg(&dev->chanA, R9, 0xC0);
1364
1365 udelay(100);
1366 spin_unlock_irqrestore(&dev->lock, flags);
1367 return 0;
1368}
1369
1370EXPORT_SYMBOL(z8530_shutdown);
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383int z8530_channel_load(struct z8530_channel *c, u8 *rtable)
1384{
1385 unsigned long flags;
1386
1387 spin_lock_irqsave(c->lock, flags);
1388
1389 while(*rtable!=255)
1390 {
1391 int reg=*rtable++;
1392 if(reg>0x0F)
1393 write_zsreg(c, R15, c->regs[15]|1);
1394 write_zsreg(c, reg&0x0F, *rtable);
1395 if(reg>0x0F)
1396 write_zsreg(c, R15, c->regs[15]&~1);
1397 c->regs[reg]=*rtable++;
1398 }
1399 c->rx_function=z8530_null_rx;
1400 c->skb=NULL;
1401 c->tx_skb=NULL;
1402 c->tx_next_skb=NULL;
1403 c->mtu=1500;
1404 c->max=0;
1405 c->count=0;
1406 c->status=read_zsreg(c, R0);
1407 c->sync=1;
1408 write_zsreg(c, R3, c->regs[R3]|RxENABLE);
1409
1410 spin_unlock_irqrestore(c->lock, flags);
1411 return 0;
1412}
1413
1414EXPORT_SYMBOL(z8530_channel_load);
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431static void z8530_tx_begin(struct z8530_channel *c)
1432{
1433 unsigned long flags;
1434 if(c->tx_skb)
1435 return;
1436
1437 c->tx_skb=c->tx_next_skb;
1438 c->tx_next_skb=NULL;
1439 c->tx_ptr=c->tx_next_ptr;
1440
1441 if(c->tx_skb==NULL)
1442 {
1443
1444 if(c->dma_tx)
1445 {
1446 flags=claim_dma_lock();
1447 disable_dma(c->txdma);
1448
1449
1450
1451 if (get_dma_residue(c->txdma))
1452 {
1453 c->netdevice->stats.tx_dropped++;
1454 c->netdevice->stats.tx_fifo_errors++;
1455 }
1456 release_dma_lock(flags);
1457 }
1458 c->txcount=0;
1459 }
1460 else
1461 {
1462 c->txcount=c->tx_skb->len;
1463
1464
1465 if(c->dma_tx)
1466 {
1467
1468
1469
1470
1471
1472
1473
1474 flags=claim_dma_lock();
1475 disable_dma(c->txdma);
1476
1477
1478
1479
1480
1481
1482 if(c->dev->type!=Z85230)
1483 {
1484 write_zsctrl(c, RES_Tx_CRC);
1485 write_zsctrl(c, RES_EOM_L);
1486 }
1487 write_zsreg(c, R10, c->regs[10]&~ABUNDER);
1488 clear_dma_ff(c->txdma);
1489 set_dma_addr(c->txdma, virt_to_bus(c->tx_ptr));
1490 set_dma_count(c->txdma, c->txcount);
1491 enable_dma(c->txdma);
1492 release_dma_lock(flags);
1493 write_zsctrl(c, RES_EOM_L);
1494 write_zsreg(c, R5, c->regs[R5]|TxENAB);
1495 }
1496 else
1497 {
1498
1499
1500 write_zsreg(c, R10, c->regs[10]);
1501 write_zsctrl(c, RES_Tx_CRC);
1502
1503 while(c->txcount && (read_zsreg(c,R0)&Tx_BUF_EMP))
1504 {
1505 write_zsreg(c, R8, *c->tx_ptr++);
1506 c->txcount--;
1507 }
1508
1509 }
1510 }
1511
1512
1513
1514 netif_wake_queue(c->netdevice);
1515}
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528static void z8530_tx_done(struct z8530_channel *c)
1529{
1530 struct sk_buff *skb;
1531
1532
1533 if (c->tx_skb == NULL)
1534 return;
1535
1536 skb = c->tx_skb;
1537 c->tx_skb = NULL;
1538 z8530_tx_begin(c);
1539 c->netdevice->stats.tx_packets++;
1540 c->netdevice->stats.tx_bytes += skb->len;
1541 dev_kfree_skb_irq(skb);
1542}
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553void z8530_null_rx(struct z8530_channel *c, struct sk_buff *skb)
1554{
1555 dev_kfree_skb_any(skb);
1556}
1557
1558EXPORT_SYMBOL(z8530_null_rx);
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573static void z8530_rx_done(struct z8530_channel *c)
1574{
1575 struct sk_buff *skb;
1576 int ct;
1577
1578
1579
1580
1581
1582 if(c->rxdma_on)
1583 {
1584
1585
1586
1587
1588
1589 int ready=c->dma_ready;
1590 unsigned char *rxb=c->rx_buf[c->dma_num];
1591 unsigned long flags;
1592
1593
1594
1595
1596
1597 flags=claim_dma_lock();
1598
1599 disable_dma(c->rxdma);
1600 clear_dma_ff(c->rxdma);
1601 c->rxdma_on=0;
1602 ct=c->mtu-get_dma_residue(c->rxdma);
1603 if(ct<0)
1604 ct=2;
1605 c->dma_ready=0;
1606
1607
1608
1609
1610
1611
1612 if(ready)
1613 {
1614 c->dma_num^=1;
1615 set_dma_mode(c->rxdma, DMA_MODE_READ|0x10);
1616 set_dma_addr(c->rxdma, virt_to_bus(c->rx_buf[c->dma_num]));
1617 set_dma_count(c->rxdma, c->mtu);
1618 c->rxdma_on = 1;
1619 enable_dma(c->rxdma);
1620
1621
1622 write_zsreg(c, R0, RES_Rx_CRC);
1623 }
1624 else
1625
1626
1627 netdev_warn(c->netdevice, "DMA flip overrun!\n");
1628
1629 release_dma_lock(flags);
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639 skb = dev_alloc_skb(ct);
1640 if (skb == NULL) {
1641 c->netdevice->stats.rx_dropped++;
1642 netdev_warn(c->netdevice, "Memory squeeze\n");
1643 } else {
1644 skb_put(skb, ct);
1645 skb_copy_to_linear_data(skb, rxb, ct);
1646 c->netdevice->stats.rx_packets++;
1647 c->netdevice->stats.rx_bytes += ct;
1648 }
1649 c->dma_ready = 1;
1650 } else {
1651 RT_LOCK;
1652 skb = c->skb;
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666 ct=c->count;
1667
1668 c->skb = c->skb2;
1669 c->count = 0;
1670 c->max = c->mtu;
1671 if (c->skb) {
1672 c->dptr = c->skb->data;
1673 c->max = c->mtu;
1674 } else {
1675 c->count = 0;
1676 c->max = 0;
1677 }
1678 RT_UNLOCK;
1679
1680 c->skb2 = dev_alloc_skb(c->mtu);
1681 if (c->skb2 == NULL)
1682 netdev_warn(c->netdevice, "memory squeeze\n");
1683 else
1684 skb_put(c->skb2, c->mtu);
1685 c->netdevice->stats.rx_packets++;
1686 c->netdevice->stats.rx_bytes += ct;
1687 }
1688
1689
1690
1691 if (skb) {
1692 skb_trim(skb, ct);
1693 c->rx_function(c, skb);
1694 } else {
1695 c->netdevice->stats.rx_dropped++;
1696 netdev_err(c->netdevice, "Lost a frame\n");
1697 }
1698}
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708static inline int spans_boundary(struct sk_buff *skb)
1709{
1710 unsigned long a=(unsigned long)skb->data;
1711 a^=(a+skb->len);
1712 if(a&0x00010000)
1713 return 1;
1714 return 0;
1715}
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731netdev_tx_t z8530_queue_xmit(struct z8530_channel *c, struct sk_buff *skb)
1732{
1733 unsigned long flags;
1734
1735 netif_stop_queue(c->netdevice);
1736 if(c->tx_next_skb)
1737 return NETDEV_TX_BUSY;
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747 if(c->dma_tx && ((unsigned long)(virt_to_bus(skb->data+skb->len))>=16*1024*1024 || spans_boundary(skb)))
1748 {
1749
1750
1751
1752
1753
1754
1755
1756 c->tx_next_ptr=c->tx_dma_buf[c->tx_dma_used];
1757 c->tx_dma_used^=1;
1758 skb_copy_from_linear_data(skb, c->tx_next_ptr, skb->len);
1759 }
1760 else
1761 c->tx_next_ptr=skb->data;
1762 RT_LOCK;
1763 c->tx_next_skb=skb;
1764 RT_UNLOCK;
1765
1766 spin_lock_irqsave(c->lock, flags);
1767 z8530_tx_begin(c);
1768 spin_unlock_irqrestore(c->lock, flags);
1769
1770 return NETDEV_TX_OK;
1771}
1772
1773EXPORT_SYMBOL(z8530_queue_xmit);
1774
1775
1776
1777
1778static const char banner[] __initconst =
1779 KERN_INFO "Generic Z85C30/Z85230 interface driver v0.02\n";
1780
1781static int __init z85230_init_driver(void)
1782{
1783 printk(banner);
1784 return 0;
1785}
1786module_init(z85230_init_driver);
1787
1788static void __exit z85230_cleanup_driver(void)
1789{
1790}
1791module_exit(z85230_cleanup_driver);
1792
1793MODULE_AUTHOR("Red Hat Inc.");
1794MODULE_DESCRIPTION("Z85x30 synchronous driver core");
1795MODULE_LICENSE("GPL");
1796