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#include <linux/module.h>
29#include <linux/kernel.h>
30#include <linux/mm.h>
31#include <linux/pci.h>
32#include <linux/errno.h>
33#include <linux/atm.h>
34#include <linux/atmdev.h>
35#include <linux/sonet.h>
36#include <linux/skbuff.h>
37#include <linux/time.h>
38#include <linux/delay.h>
39#include <linux/uio.h>
40#include <linux/init.h>
41#include <linux/interrupt.h>
42#include <linux/ioport.h>
43#include <linux/wait.h>
44#include <linux/slab.h>
45
46#include <asm/io.h>
47#include <linux/atomic.h>
48#include <asm/uaccess.h>
49#include <asm/string.h>
50#include <asm/byteorder.h>
51
52#include "horizon.h"
53
54#define maintainer_string "Giuliano Procida at Madge Networks <gprocida@madge.com>"
55#define description_string "Madge ATM Horizon [Ultra] driver"
56#define version_string "1.2.1"
57
58static inline void __init show_version (void) {
59 printk ("%s version %s\n", description_string, version_string);
60}
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359static void do_housekeeping (unsigned long arg);
360
361static unsigned short debug = 0;
362static unsigned short vpi_bits = 0;
363static int max_tx_size = 9000;
364static int max_rx_size = 9000;
365static unsigned char pci_lat = 0;
366
367
368
369
370static inline void wr_regl (const hrz_dev * dev, unsigned char reg, u32 data) {
371 outl (cpu_to_le32 (data), dev->iobase + reg);
372}
373
374static inline u32 rd_regl (const hrz_dev * dev, unsigned char reg) {
375 return le32_to_cpu (inl (dev->iobase + reg));
376}
377
378static inline void wr_regw (const hrz_dev * dev, unsigned char reg, u16 data) {
379 outw (cpu_to_le16 (data), dev->iobase + reg);
380}
381
382static inline u16 rd_regw (const hrz_dev * dev, unsigned char reg) {
383 return le16_to_cpu (inw (dev->iobase + reg));
384}
385
386static inline void wrs_regb (const hrz_dev * dev, unsigned char reg, void * addr, u32 len) {
387 outsb (dev->iobase + reg, addr, len);
388}
389
390static inline void rds_regb (const hrz_dev * dev, unsigned char reg, void * addr, u32 len) {
391 insb (dev->iobase + reg, addr, len);
392}
393
394
395
396
397static inline void wr_mem (const hrz_dev * dev, HDW * addr, u32 data) {
398
399 wr_regl (dev, MEM_WR_ADDR_REG_OFF, (addr - (HDW *) 0) * sizeof(HDW));
400 wr_regl (dev, MEMORY_PORT_OFF, data);
401}
402
403static inline u32 rd_mem (const hrz_dev * dev, HDW * addr) {
404
405 wr_regl (dev, MEM_RD_ADDR_REG_OFF, (addr - (HDW *) 0) * sizeof(HDW));
406 return rd_regl (dev, MEMORY_PORT_OFF);
407}
408
409static inline void wr_framer (const hrz_dev * dev, u32 addr, u32 data) {
410 wr_regl (dev, MEM_WR_ADDR_REG_OFF, (u32) addr | 0x80000000);
411 wr_regl (dev, MEMORY_PORT_OFF, data);
412}
413
414static inline u32 rd_framer (const hrz_dev * dev, u32 addr) {
415 wr_regl (dev, MEM_RD_ADDR_REG_OFF, (u32) addr | 0x80000000);
416 return rd_regl (dev, MEMORY_PORT_OFF);
417}
418
419
420
421
422
423static inline void FLUSH_RX_CHANNEL (hrz_dev * dev, u16 channel) {
424 wr_regw (dev, RX_CHANNEL_PORT_OFF, FLUSH_CHANNEL | channel);
425 return;
426}
427
428static void WAIT_FLUSH_RX_COMPLETE (hrz_dev * dev) {
429 while (rd_regw (dev, RX_CHANNEL_PORT_OFF) & FLUSH_CHANNEL)
430 ;
431 return;
432}
433
434static inline void SELECT_RX_CHANNEL (hrz_dev * dev, u16 channel) {
435 wr_regw (dev, RX_CHANNEL_PORT_OFF, channel);
436 return;
437}
438
439static void WAIT_UPDATE_COMPLETE (hrz_dev * dev) {
440 while (rd_regw (dev, RX_CHANNEL_PORT_OFF) & RX_CHANNEL_UPDATE_IN_PROGRESS)
441 ;
442 return;
443}
444
445
446
447static inline void SELECT_TX_CHANNEL (hrz_dev * dev, u16 tx_channel) {
448 wr_regl (dev, TX_CHANNEL_PORT_OFF, tx_channel);
449 return;
450}
451
452
453
454static inline void update_tx_channel_config (hrz_dev * dev, short chan, u8 mode, u16 value) {
455 wr_regw (dev, TX_CHANNEL_CONFIG_COMMAND_OFF,
456 chan * TX_CHANNEL_CONFIG_MULT | mode);
457 wr_regw (dev, TX_CHANNEL_CONFIG_DATA_OFF, value);
458 return;
459}
460
461static inline u16 query_tx_channel_config (hrz_dev * dev, short chan, u8 mode) {
462 wr_regw (dev, TX_CHANNEL_CONFIG_COMMAND_OFF,
463 chan * TX_CHANNEL_CONFIG_MULT | mode);
464 return rd_regw (dev, TX_CHANNEL_CONFIG_DATA_OFF);
465}
466
467
468
469static inline void dump_skb (char * prefix, unsigned int vc, struct sk_buff * skb) {
470#ifdef DEBUG_HORIZON
471 unsigned int i;
472 unsigned char * data = skb->data;
473 PRINTDB (DBG_DATA, "%s(%u) ", prefix, vc);
474 for (i=0; i<skb->len && i < 256;i++)
475 PRINTDM (DBG_DATA, "%02x ", data[i]);
476 PRINTDE (DBG_DATA,"");
477#else
478 (void) prefix;
479 (void) vc;
480 (void) skb;
481#endif
482 return;
483}
484
485static inline void dump_regs (hrz_dev * dev) {
486#ifdef DEBUG_HORIZON
487 PRINTD (DBG_REGS, "CONTROL 0: %#x", rd_regl (dev, CONTROL_0_REG));
488 PRINTD (DBG_REGS, "RX CONFIG: %#x", rd_regw (dev, RX_CONFIG_OFF));
489 PRINTD (DBG_REGS, "TX CONFIG: %#x", rd_regw (dev, TX_CONFIG_OFF));
490 PRINTD (DBG_REGS, "TX STATUS: %#x", rd_regw (dev, TX_STATUS_OFF));
491 PRINTD (DBG_REGS, "IRQ ENBLE: %#x", rd_regl (dev, INT_ENABLE_REG_OFF));
492 PRINTD (DBG_REGS, "IRQ SORCE: %#x", rd_regl (dev, INT_SOURCE_REG_OFF));
493#else
494 (void) dev;
495#endif
496 return;
497}
498
499static inline void dump_framer (hrz_dev * dev) {
500#ifdef DEBUG_HORIZON
501 unsigned int i;
502 PRINTDB (DBG_REGS, "framer registers:");
503 for (i = 0; i < 0x10; ++i)
504 PRINTDM (DBG_REGS, " %02x", rd_framer (dev, i));
505 PRINTDE (DBG_REGS,"");
506#else
507 (void) dev;
508#endif
509 return;
510}
511
512
513
514
515
516static inline int channel_to_vpivci (const u16 channel, short * vpi, int * vci) {
517 unsigned short vci_bits = 10 - vpi_bits;
518 if ((channel & RX_CHANNEL_MASK) == channel) {
519 *vci = channel & ((~0)<<vci_bits);
520 *vpi = channel >> vci_bits;
521 return channel ? 0 : -EINVAL;
522 }
523 return -EINVAL;
524}
525
526static inline int vpivci_to_channel (u16 * channel, const short vpi, const int vci) {
527 unsigned short vci_bits = 10 - vpi_bits;
528 if (0 <= vpi && vpi < 1<<vpi_bits && 0 <= vci && vci < 1<<vci_bits) {
529 *channel = vpi<<vci_bits | vci;
530 return *channel ? 0 : -EINVAL;
531 }
532 return -EINVAL;
533}
534
535
536
537static inline u16 rx_q_entry_to_length (u32 x) {
538 return x & RX_Q_ENTRY_LENGTH_MASK;
539}
540
541static inline u16 rx_q_entry_to_rx_channel (u32 x) {
542 return (x>>RX_Q_ENTRY_CHANNEL_SHIFT) & RX_CHANNEL_MASK;
543}
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591#define BR_UKN 1031250l
592#define BR_HRZ 4000000l
593#define BR_ULT 5000000l
594
595
596#define CR_MIND 0
597#define CR_MAXD 14
598
599
600#define CR_MAXPEXP 4
601
602static int make_rate (const hrz_dev * dev, u32 c, rounding r,
603 u16 * bits, unsigned int * actual)
604{
605
606 const unsigned long br = test_bit(ultra, &dev->flags) ? BR_ULT : BR_HRZ;
607
608 u32 div = CR_MIND;
609 u32 pre;
610
611
612
613
614
615 unsigned long br_man = br;
616 unsigned int br_exp = 0;
617
618 PRINTD (DBG_QOS|DBG_FLOW, "make_rate b=%lu, c=%u, %s", br, c,
619 r == round_up ? "up" : r == round_down ? "down" : "nearest");
620
621
622 if (!c) {
623 PRINTD (DBG_QOS|DBG_ERR, "zero rate is not allowed!");
624 return -EINVAL;
625 }
626
627 while (br_exp < CR_MAXPEXP + CR_MIND && (br_man % 2 == 0)) {
628 br_man = br_man >> 1;
629 ++br_exp;
630 }
631
632
633
634 if (br_man <= (c << (CR_MAXPEXP+CR_MIND-br_exp))) {
635
636
637 switch (r) {
638 case round_down:
639 pre = DIV_ROUND_UP(br, c<<div);
640
641 if (!pre)
642 pre = 1;
643 break;
644 case round_nearest:
645 pre = DIV_ROUND_CLOSEST(br, c<<div);
646
647 if (!pre)
648 pre = 1;
649 break;
650 default:
651 pre = br/(c<<div);
652
653 if (!pre)
654 return -EINVAL;
655 }
656 PRINTD (DBG_QOS, "A: p=%u, d=%u", pre, div);
657 goto got_it;
658 }
659
660
661
662 while (div < CR_MAXD) {
663 div++;
664 if (br_man <= (c << (CR_MAXPEXP+div-br_exp))) {
665
666
667
668
669
670 switch (r) {
671 case round_down:
672 pre = DIV_ROUND_UP(br, c<<div);
673 break;
674 case round_nearest:
675 pre = DIV_ROUND_CLOSEST(br, c<<div);
676 break;
677 default:
678 pre = br/(c<<div);
679 }
680 PRINTD (DBG_QOS, "B: p=%u, d=%u", pre, div);
681 goto got_it;
682 }
683 }
684
685
686
687
688 if (r == round_down)
689 return -EINVAL;
690 pre = 1 << CR_MAXPEXP;
691 PRINTD (DBG_QOS, "C: p=%u, d=%u", pre, div);
692got_it:
693
694 if (div > CR_MAXD || (!pre) || pre > 1<<CR_MAXPEXP) {
695 PRINTD (DBG_QOS, "set_cr internal failure: d=%u p=%u",
696 div, pre);
697 return -EINVAL;
698 } else {
699 if (bits)
700 *bits = (div<<CLOCK_SELECT_SHIFT) | (pre-1);
701 if (actual) {
702 *actual = DIV_ROUND_UP(br, pre<<div);
703 PRINTD (DBG_QOS, "actual rate: %u", *actual);
704 }
705 return 0;
706 }
707}
708
709static int make_rate_with_tolerance (const hrz_dev * dev, u32 c, rounding r, unsigned int tol,
710 u16 * bit_pattern, unsigned int * actual) {
711 unsigned int my_actual;
712
713 PRINTD (DBG_QOS|DBG_FLOW, "make_rate_with_tolerance c=%u, %s, tol=%u",
714 c, (r == round_up) ? "up" : (r == round_down) ? "down" : "nearest", tol);
715
716 if (!actual)
717
718 actual = &my_actual;
719
720 if (make_rate (dev, c, round_nearest, bit_pattern, actual))
721
722 return -1;
723
724 if (c - tol <= *actual && *actual <= c + tol)
725
726 return 0;
727 else
728
729 return make_rate (dev, c, r, bit_pattern, actual);
730}
731
732
733
734static int hrz_open_rx (hrz_dev * dev, u16 channel) {
735
736
737
738 unsigned long flags;
739 u32 channel_type;
740
741 u16 buf_ptr = RX_CHANNEL_IDLE;
742
743 rx_ch_desc * rx_desc = &memmap->rx_descs[channel];
744
745 PRINTD (DBG_FLOW, "hrz_open_rx %x", channel);
746
747 spin_lock_irqsave (&dev->mem_lock, flags);
748 channel_type = rd_mem (dev, &rx_desc->wr_buf_type) & BUFFER_PTR_MASK;
749 spin_unlock_irqrestore (&dev->mem_lock, flags);
750
751
752 if (channel_type != RX_CHANNEL_DISABLED) {
753 PRINTD (DBG_ERR|DBG_VCC, "RX channel for VC already open");
754 return -EBUSY;
755 }
756
757
758 if (dev->noof_spare_buffers) {
759 buf_ptr = dev->spare_buffers[--dev->noof_spare_buffers];
760 PRINTD (DBG_VCC, "using a spare buffer: %u", buf_ptr);
761
762 if (buf_ptr == RX_CHANNEL_DISABLED || buf_ptr == RX_CHANNEL_IDLE) {
763
764 PRINTD (DBG_ERR|DBG_VCC, "bad spare buffer pointer, using IDLE");
765 buf_ptr = RX_CHANNEL_IDLE;
766 }
767 } else {
768 PRINTD (DBG_VCC, "using IDLE buffer pointer");
769 }
770
771
772
773
774 spin_lock_irqsave (&dev->mem_lock, flags);
775
776 wr_mem (dev, &rx_desc->wr_buf_type,
777 buf_ptr | CHANNEL_TYPE_AAL5 | FIRST_CELL_OF_AAL5_FRAME);
778 if (buf_ptr != RX_CHANNEL_IDLE)
779 wr_mem (dev, &rx_desc->rd_buf_type, buf_ptr);
780
781 spin_unlock_irqrestore (&dev->mem_lock, flags);
782
783
784
785 PRINTD (DBG_FLOW, "hrz_open_rx ok");
786
787 return 0;
788}
789
790#if 0
791
792
793static void hrz_change_vc_qos (ATM_RXER * rxer, MAAL_QOS * qos) {
794 rxer->rate = make_rate (qos->peak_cells);
795}
796#endif
797
798
799
800static void hrz_kfree_skb (struct sk_buff * skb) {
801 if (ATM_SKB(skb)->vcc->pop) {
802 ATM_SKB(skb)->vcc->pop (ATM_SKB(skb)->vcc, skb);
803 } else {
804 dev_kfree_skb_any (skb);
805 }
806}
807
808
809
810static void hrz_close_rx (hrz_dev * dev, u16 vc) {
811 unsigned long flags;
812
813 u32 value;
814
815 u32 r1, r2;
816
817 rx_ch_desc * rx_desc = &memmap->rx_descs[vc];
818
819 int was_idle = 0;
820
821 spin_lock_irqsave (&dev->mem_lock, flags);
822 value = rd_mem (dev, &rx_desc->wr_buf_type) & BUFFER_PTR_MASK;
823 spin_unlock_irqrestore (&dev->mem_lock, flags);
824
825 if (value == RX_CHANNEL_DISABLED) {
826
827 PRINTD (DBG_VCC, "closing VC: RX channel %u already disabled", vc);
828 return;
829 }
830 if (value == RX_CHANNEL_IDLE)
831 was_idle = 1;
832
833 spin_lock_irqsave (&dev->mem_lock, flags);
834
835 for (;;) {
836 wr_mem (dev, &rx_desc->wr_buf_type, RX_CHANNEL_DISABLED);
837
838 if ((rd_mem (dev, &rx_desc->wr_buf_type) & BUFFER_PTR_MASK) == RX_CHANNEL_DISABLED)
839 break;
840
841 was_idle = 0;
842 }
843
844 if (was_idle) {
845 spin_unlock_irqrestore (&dev->mem_lock, flags);
846 return;
847 }
848
849 WAIT_FLUSH_RX_COMPLETE(dev);
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872 for (;;) {
873
874
875
876
877 u16 other = vc^(RX_CHANS/2);
878
879 SELECT_RX_CHANNEL (dev, other);
880 WAIT_UPDATE_COMPLETE (dev);
881
882 r1 = rd_mem (dev, &rx_desc->rd_buf_type);
883
884
885
886
887 SELECT_RX_CHANNEL (dev, vc);
888 WAIT_UPDATE_COMPLETE (dev);
889
890
891
892 FLUSH_RX_CHANNEL (dev, vc);
893 WAIT_FLUSH_RX_COMPLETE (dev);
894
895
896
897 SELECT_RX_CHANNEL (dev, other);
898 WAIT_UPDATE_COMPLETE (dev);
899
900 r2 = rd_mem (dev, &rx_desc->rd_buf_type);
901
902 PRINTD (DBG_VCC|DBG_RX, "r1 = %u, r2 = %u", r1, r2);
903
904 if (r1 == r2) {
905 dev->spare_buffers[dev->noof_spare_buffers++] = (u16)r1;
906 break;
907 }
908 }
909
910#if 0
911 {
912 rx_q_entry * wr_ptr = &memmap->rx_q_entries[rd_regw (dev, RX_QUEUE_WR_PTR_OFF)];
913 rx_q_entry * rd_ptr = dev->rx_q_entry;
914
915 PRINTD (DBG_VCC|DBG_RX, "rd_ptr = %u, wr_ptr = %u", rd_ptr, wr_ptr);
916
917 while (rd_ptr != wr_ptr) {
918 u32 x = rd_mem (dev, (HDW *) rd_ptr);
919
920 if (vc == rx_q_entry_to_rx_channel (x)) {
921 x |= SIMONS_DODGEY_MARKER;
922
923 PRINTD (DBG_RX|DBG_VCC|DBG_WARN, "marking a frame as dodgey");
924
925 wr_mem (dev, (HDW *) rd_ptr, x);
926 }
927
928 if (rd_ptr == dev->rx_q_wrap)
929 rd_ptr = dev->rx_q_reset;
930 else
931 rd_ptr++;
932 }
933 }
934#endif
935
936 spin_unlock_irqrestore (&dev->mem_lock, flags);
937
938 return;
939}
940
941
942
943
944
945
946
947
948
949static void rx_schedule (hrz_dev * dev, int irq) {
950 unsigned int rx_bytes;
951
952 int pio_instead = 0;
953#ifndef TAILRECURSIONWORKS
954 pio_instead = 1;
955 while (pio_instead) {
956#endif
957
958 rx_bytes = dev->rx_bytes;
959
960#if 0
961 spin_count = 0;
962 while (rd_regl (dev, MASTER_RX_COUNT_REG_OFF)) {
963 PRINTD (DBG_RX|DBG_WARN, "RX error: other PCI Bus Master RX still in progress!");
964 if (++spin_count > 10) {
965 PRINTD (DBG_RX|DBG_ERR, "spun out waiting PCI Bus Master RX completion");
966 wr_regl (dev, MASTER_RX_COUNT_REG_OFF, 0);
967 clear_bit (rx_busy, &dev->flags);
968 hrz_kfree_skb (dev->rx_skb);
969 return;
970 }
971 }
972#endif
973
974
975
976
977
978 if (rx_bytes) {
979
980 if (rx_bytes <= MAX_PIO_COUNT) {
981 PRINTD (DBG_RX|DBG_BUS, "(pio)");
982 pio_instead = 1;
983 }
984 if (rx_bytes <= MAX_TRANSFER_COUNT) {
985 PRINTD (DBG_RX|DBG_BUS, "(simple or last multi)");
986 dev->rx_bytes = 0;
987 } else {
988 PRINTD (DBG_RX|DBG_BUS, "(continuing multi)");
989 dev->rx_bytes = rx_bytes - MAX_TRANSFER_COUNT;
990 rx_bytes = MAX_TRANSFER_COUNT;
991 }
992 } else {
993
994
995#if 0
996 unsigned int rx_regions = dev->rx_regions;
997#else
998 unsigned int rx_regions = 0;
999#endif
1000
1001 if (rx_regions) {
1002#if 0
1003
1004 dev->rx_addr = dev->rx_iovec->iov_base;
1005 rx_bytes = dev->rx_iovec->iov_len;
1006 ++dev->rx_iovec;
1007 dev->rx_regions = rx_regions - 1;
1008
1009 if (rx_bytes <= MAX_PIO_COUNT) {
1010 PRINTD (DBG_RX|DBG_BUS, "(pio)");
1011 pio_instead = 1;
1012 }
1013 if (rx_bytes <= MAX_TRANSFER_COUNT) {
1014 PRINTD (DBG_RX|DBG_BUS, "(full region)");
1015 dev->rx_bytes = 0;
1016 } else {
1017 PRINTD (DBG_RX|DBG_BUS, "(start multi region)");
1018 dev->rx_bytes = rx_bytes - MAX_TRANSFER_COUNT;
1019 rx_bytes = MAX_TRANSFER_COUNT;
1020 }
1021#endif
1022 } else {
1023
1024
1025 struct sk_buff * skb = dev->rx_skb;
1026
1027
1028 FLUSH_RX_CHANNEL (dev, dev->rx_channel);
1029
1030 dump_skb ("<<<", dev->rx_channel, skb);
1031
1032 PRINTD (DBG_RX|DBG_SKB, "push %p %u", skb->data, skb->len);
1033
1034 {
1035 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
1036
1037 atomic_inc(&vcc->stats->rx);
1038 __net_timestamp(skb);
1039
1040 vcc->push (vcc, skb);
1041 }
1042 }
1043 }
1044
1045
1046 if (rx_bytes) {
1047 if (pio_instead) {
1048 if (irq)
1049 wr_regl (dev, MASTER_RX_COUNT_REG_OFF, 0);
1050 rds_regb (dev, DATA_PORT_OFF, dev->rx_addr, rx_bytes);
1051 } else {
1052 wr_regl (dev, MASTER_RX_ADDR_REG_OFF, virt_to_bus (dev->rx_addr));
1053 wr_regl (dev, MASTER_RX_COUNT_REG_OFF, rx_bytes);
1054 }
1055 dev->rx_addr += rx_bytes;
1056 } else {
1057 if (irq)
1058 wr_regl (dev, MASTER_RX_COUNT_REG_OFF, 0);
1059
1060 YELLOW_LED_ON(dev);
1061 clear_bit (rx_busy, &dev->flags);
1062 PRINTD (DBG_RX, "cleared rx_busy for dev %p", dev);
1063 }
1064
1065#ifdef TAILRECURSIONWORKS
1066
1067 if (pio_instead)
1068 return rx_schedule (dev, 0);
1069 return;
1070#else
1071
1072 irq = 0;
1073 }
1074 return;
1075#endif
1076}
1077
1078
1079
1080static void rx_bus_master_complete_handler (hrz_dev * dev) {
1081 if (test_bit (rx_busy, &dev->flags)) {
1082 rx_schedule (dev, 1);
1083 } else {
1084 PRINTD (DBG_RX|DBG_ERR, "unexpected RX bus master completion");
1085
1086 wr_regl (dev, MASTER_RX_COUNT_REG_OFF, 0);
1087 }
1088 return;
1089}
1090
1091
1092
1093static int tx_hold (hrz_dev * dev) {
1094 PRINTD (DBG_TX, "sleeping at tx lock %p %lu", dev, dev->flags);
1095 wait_event_interruptible(dev->tx_queue, (!test_and_set_bit(tx_busy, &dev->flags)));
1096 PRINTD (DBG_TX, "woken at tx lock %p %lu", dev, dev->flags);
1097 if (signal_pending (current))
1098 return -1;
1099 PRINTD (DBG_TX, "set tx_busy for dev %p", dev);
1100 return 0;
1101}
1102
1103
1104
1105static inline void tx_release (hrz_dev * dev) {
1106 clear_bit (tx_busy, &dev->flags);
1107 PRINTD (DBG_TX, "cleared tx_busy for dev %p", dev);
1108 wake_up_interruptible (&dev->tx_queue);
1109}
1110
1111
1112
1113static void tx_schedule (hrz_dev * const dev, int irq) {
1114 unsigned int tx_bytes;
1115
1116 int append_desc = 0;
1117
1118 int pio_instead = 0;
1119#ifndef TAILRECURSIONWORKS
1120 pio_instead = 1;
1121 while (pio_instead) {
1122#endif
1123
1124 tx_bytes = dev->tx_bytes;
1125
1126#if 0
1127 spin_count = 0;
1128 while (rd_regl (dev, MASTER_TX_COUNT_REG_OFF)) {
1129 PRINTD (DBG_TX|DBG_WARN, "TX error: other PCI Bus Master TX still in progress!");
1130 if (++spin_count > 10) {
1131 PRINTD (DBG_TX|DBG_ERR, "spun out waiting PCI Bus Master TX completion");
1132 wr_regl (dev, MASTER_TX_COUNT_REG_OFF, 0);
1133 tx_release (dev);
1134 hrz_kfree_skb (dev->tx_skb);
1135 return;
1136 }
1137 }
1138#endif
1139
1140 if (tx_bytes) {
1141
1142 if (!test_bit (ultra, &dev->flags) || tx_bytes <= MAX_PIO_COUNT) {
1143 PRINTD (DBG_TX|DBG_BUS, "(pio)");
1144 pio_instead = 1;
1145 }
1146 if (tx_bytes <= MAX_TRANSFER_COUNT) {
1147 PRINTD (DBG_TX|DBG_BUS, "(simple or last multi)");
1148 if (!dev->tx_iovec) {
1149
1150 append_desc = 1;
1151 }
1152 dev->tx_bytes = 0;
1153 } else {
1154 PRINTD (DBG_TX|DBG_BUS, "(continuing multi)");
1155 dev->tx_bytes = tx_bytes - MAX_TRANSFER_COUNT;
1156 tx_bytes = MAX_TRANSFER_COUNT;
1157 }
1158 } else {
1159
1160
1161 unsigned int tx_regions = dev->tx_regions;
1162
1163 if (tx_regions) {
1164
1165 dev->tx_addr = dev->tx_iovec->iov_base;
1166 tx_bytes = dev->tx_iovec->iov_len;
1167 ++dev->tx_iovec;
1168 dev->tx_regions = tx_regions - 1;
1169
1170 if (!test_bit (ultra, &dev->flags) || tx_bytes <= MAX_PIO_COUNT) {
1171 PRINTD (DBG_TX|DBG_BUS, "(pio)");
1172 pio_instead = 1;
1173 }
1174 if (tx_bytes <= MAX_TRANSFER_COUNT) {
1175 PRINTD (DBG_TX|DBG_BUS, "(full region)");
1176 dev->tx_bytes = 0;
1177 } else {
1178 PRINTD (DBG_TX|DBG_BUS, "(start multi region)");
1179 dev->tx_bytes = tx_bytes - MAX_TRANSFER_COUNT;
1180 tx_bytes = MAX_TRANSFER_COUNT;
1181 }
1182 } else {
1183
1184
1185 struct sk_buff * skb = dev->tx_skb;
1186 dev->tx_iovec = NULL;
1187
1188
1189 atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
1190
1191
1192 hrz_kfree_skb (skb);
1193 }
1194 }
1195
1196
1197 if (tx_bytes) {
1198 if (pio_instead) {
1199 if (irq)
1200 wr_regl (dev, MASTER_TX_COUNT_REG_OFF, 0);
1201 wrs_regb (dev, DATA_PORT_OFF, dev->tx_addr, tx_bytes);
1202 if (append_desc)
1203 wr_regl (dev, TX_DESCRIPTOR_PORT_OFF, cpu_to_be32 (dev->tx_skb->len));
1204 } else {
1205 wr_regl (dev, MASTER_TX_ADDR_REG_OFF, virt_to_bus (dev->tx_addr));
1206 if (append_desc)
1207 wr_regl (dev, TX_DESCRIPTOR_REG_OFF, cpu_to_be32 (dev->tx_skb->len));
1208 wr_regl (dev, MASTER_TX_COUNT_REG_OFF,
1209 append_desc
1210 ? tx_bytes | MASTER_TX_AUTO_APPEND_DESC
1211 : tx_bytes);
1212 }
1213 dev->tx_addr += tx_bytes;
1214 } else {
1215 if (irq)
1216 wr_regl (dev, MASTER_TX_COUNT_REG_OFF, 0);
1217 YELLOW_LED_ON(dev);
1218 tx_release (dev);
1219 }
1220
1221#ifdef TAILRECURSIONWORKS
1222
1223 if (pio_instead)
1224 return tx_schedule (dev, 0);
1225 return;
1226#else
1227
1228 irq = 0;
1229 }
1230 return;
1231#endif
1232}
1233
1234
1235
1236static void tx_bus_master_complete_handler (hrz_dev * dev) {
1237 if (test_bit (tx_busy, &dev->flags)) {
1238 tx_schedule (dev, 1);
1239 } else {
1240 PRINTD (DBG_TX|DBG_ERR, "unexpected TX bus master completion");
1241
1242 wr_regl (dev, MASTER_TX_COUNT_REG_OFF, 0);
1243 }
1244 return;
1245}
1246
1247
1248
1249
1250static u32 rx_queue_entry_next (hrz_dev * dev) {
1251 u32 rx_queue_entry;
1252 spin_lock (&dev->mem_lock);
1253 rx_queue_entry = rd_mem (dev, &dev->rx_q_entry->entry);
1254 if (dev->rx_q_entry == dev->rx_q_wrap)
1255 dev->rx_q_entry = dev->rx_q_reset;
1256 else
1257 dev->rx_q_entry++;
1258 wr_regw (dev, RX_QUEUE_RD_PTR_OFF, dev->rx_q_entry - dev->rx_q_reset);
1259 spin_unlock (&dev->mem_lock);
1260 return rx_queue_entry;
1261}
1262
1263
1264
1265static inline void rx_disabled_handler (hrz_dev * dev) {
1266 wr_regw (dev, RX_CONFIG_OFF, rd_regw (dev, RX_CONFIG_OFF) | RX_ENABLE);
1267
1268 PRINTK (KERN_WARNING, "RX was disabled!");
1269}
1270
1271
1272
1273
1274static void rx_data_av_handler (hrz_dev * dev) {
1275 u32 rx_queue_entry;
1276 u32 rx_queue_entry_flags;
1277 u16 rx_len;
1278 u16 rx_channel;
1279
1280 PRINTD (DBG_FLOW, "hrz_data_av_handler");
1281
1282
1283 if (test_and_set_bit (rx_busy, &dev->flags)) {
1284 PRINTD (DBG_RX, "locked out of rx lock");
1285 return;
1286 }
1287 PRINTD (DBG_RX, "set rx_busy for dev %p", dev);
1288
1289
1290 YELLOW_LED_OFF(dev);
1291
1292 rx_queue_entry = rx_queue_entry_next (dev);
1293
1294 rx_len = rx_q_entry_to_length (rx_queue_entry);
1295 rx_channel = rx_q_entry_to_rx_channel (rx_queue_entry);
1296
1297 WAIT_FLUSH_RX_COMPLETE (dev);
1298
1299 SELECT_RX_CHANNEL (dev, rx_channel);
1300
1301 PRINTD (DBG_RX, "rx_queue_entry is: %#x", rx_queue_entry);
1302 rx_queue_entry_flags = rx_queue_entry & (RX_CRC_32_OK|RX_COMPLETE_FRAME|SIMONS_DODGEY_MARKER);
1303
1304 if (!rx_len) {
1305
1306
1307 PRINTK (KERN_ERR, "zero-length frame!");
1308 rx_queue_entry_flags &= ~RX_COMPLETE_FRAME;
1309 }
1310
1311 if (rx_queue_entry_flags & SIMONS_DODGEY_MARKER) {
1312 PRINTD (DBG_RX|DBG_ERR, "Simon's marker detected!");
1313 }
1314 if (rx_queue_entry_flags == (RX_CRC_32_OK | RX_COMPLETE_FRAME)) {
1315 struct atm_vcc * atm_vcc;
1316
1317 PRINTD (DBG_RX, "got a frame on rx_channel %x len %u", rx_channel, rx_len);
1318
1319 atm_vcc = dev->rxer[rx_channel];
1320
1321
1322
1323 if (atm_vcc) {
1324
1325 if (atm_vcc->qos.rxtp.traffic_class != ATM_NONE) {
1326
1327 if (rx_len <= atm_vcc->qos.rxtp.max_sdu) {
1328
1329 struct sk_buff * skb = atm_alloc_charge (atm_vcc, rx_len, GFP_ATOMIC);
1330 if (skb) {
1331
1332 dev->rx_skb = skb;
1333
1334 dev->rx_channel = rx_channel;
1335
1336
1337 skb_put (skb, rx_len);
1338 ATM_SKB(skb)->vcc = atm_vcc;
1339
1340
1341
1342
1343 dev->rx_bytes = rx_len;
1344 dev->rx_addr = skb->data;
1345 PRINTD (DBG_RX, "RX start simple transfer (addr %p, len %d)",
1346 skb->data, rx_len);
1347
1348
1349 rx_schedule (dev, 0);
1350 return;
1351
1352 } else {
1353 PRINTD (DBG_SKB|DBG_WARN, "failed to get skb");
1354 }
1355
1356 } else {
1357 PRINTK (KERN_INFO, "frame received on TX-only VC %x", rx_channel);
1358
1359 }
1360
1361 } else {
1362 PRINTK (KERN_WARNING, "dropped over-size frame");
1363
1364 }
1365
1366 } else {
1367 PRINTD (DBG_WARN|DBG_VCC|DBG_RX, "no VCC for this frame (VC closed)");
1368
1369 }
1370
1371 } else {
1372
1373 }
1374
1375
1376 YELLOW_LED_ON(dev);
1377
1378 FLUSH_RX_CHANNEL (dev,rx_channel);
1379 clear_bit (rx_busy, &dev->flags);
1380
1381 return;
1382}
1383
1384
1385
1386static irqreturn_t interrupt_handler(int irq, void *dev_id)
1387{
1388 hrz_dev *dev = dev_id;
1389 u32 int_source;
1390 unsigned int irq_ok;
1391
1392 PRINTD (DBG_FLOW, "interrupt_handler: %p", dev_id);
1393
1394
1395 irq_ok = 0;
1396 while ((int_source = rd_regl (dev, INT_SOURCE_REG_OFF)
1397 & INTERESTING_INTERRUPTS)) {
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414 if (int_source & RX_BUS_MASTER_COMPLETE) {
1415 ++irq_ok;
1416 PRINTD (DBG_IRQ|DBG_BUS|DBG_RX, "rx_bus_master_complete asserted");
1417 rx_bus_master_complete_handler (dev);
1418 }
1419 if (int_source & TX_BUS_MASTER_COMPLETE) {
1420 ++irq_ok;
1421 PRINTD (DBG_IRQ|DBG_BUS|DBG_TX, "tx_bus_master_complete asserted");
1422 tx_bus_master_complete_handler (dev);
1423 }
1424 if (int_source & RX_DATA_AV) {
1425 ++irq_ok;
1426 PRINTD (DBG_IRQ|DBG_RX, "rx_data_av asserted");
1427 rx_data_av_handler (dev);
1428 }
1429 }
1430 if (irq_ok) {
1431 PRINTD (DBG_IRQ, "work done: %u", irq_ok);
1432 } else {
1433 PRINTD (DBG_IRQ|DBG_WARN, "spurious interrupt source: %#x", int_source);
1434 }
1435
1436 PRINTD (DBG_IRQ|DBG_FLOW, "interrupt_handler done: %p", dev_id);
1437 if (irq_ok)
1438 return IRQ_HANDLED;
1439 return IRQ_NONE;
1440}
1441
1442
1443
1444static void do_housekeeping (unsigned long arg) {
1445
1446 hrz_dev * dev = (hrz_dev *) arg;
1447
1448
1449 dev->tx_cell_count += rd_regw (dev, TX_CELL_COUNT_OFF);
1450 dev->rx_cell_count += rd_regw (dev, RX_CELL_COUNT_OFF);
1451 dev->hec_error_count += rd_regw (dev, HEC_ERROR_COUNT_OFF);
1452 dev->unassigned_cell_count += rd_regw (dev, UNASSIGNED_CELL_COUNT_OFF);
1453
1454 mod_timer (&dev->housekeeping, jiffies + HZ/10);
1455
1456 return;
1457}
1458
1459
1460
1461
1462static short setup_idle_tx_channel (hrz_dev * dev, hrz_vcc * vcc) {
1463 unsigned short idle_channels;
1464 short tx_channel = -1;
1465 unsigned int spin_count;
1466 PRINTD (DBG_FLOW|DBG_TX, "setup_idle_tx_channel %p", dev);
1467
1468
1469
1470 spin_count = 0;
1471 while (!(idle_channels = rd_regw (dev, TX_STATUS_OFF) & IDLE_CHANNELS_MASK)) {
1472 PRINTD (DBG_TX|DBG_WARN, "waiting for idle TX channel");
1473
1474 if (++spin_count > 100) {
1475 PRINTD (DBG_TX|DBG_ERR, "spun out waiting for idle TX channel");
1476 return -EBUSY;
1477 }
1478 }
1479
1480
1481 {
1482
1483 int chan = dev->tx_idle;
1484
1485 int keep_going = 1;
1486 while (keep_going) {
1487 if (idle_channels & (1<<chan)) {
1488 tx_channel = chan;
1489 keep_going = 0;
1490 }
1491 ++chan;
1492 if (chan == TX_CHANS)
1493 chan = 0;
1494 }
1495
1496 dev->tx_idle = chan;
1497 }
1498
1499
1500 {
1501
1502
1503
1504 tx_ch_desc * tx_desc = &memmap->tx_descs[tx_channel];
1505 u32 rd_ptr;
1506 u32 wr_ptr;
1507 u16 channel = vcc->channel;
1508
1509 unsigned long flags;
1510 spin_lock_irqsave (&dev->mem_lock, flags);
1511
1512
1513 dev->tx_channel_record[tx_channel] = channel;
1514
1515
1516 update_tx_channel_config (dev, tx_channel, RATE_TYPE_ACCESS,
1517 vcc->tx_xbr_bits);
1518
1519
1520 update_tx_channel_config (dev, tx_channel, PCR_TIMER_ACCESS,
1521 vcc->tx_pcr_bits);
1522
1523#if 0
1524 if (vcc->tx_xbr_bits == VBR_RATE_TYPE) {
1525
1526 update_tx_channel_config (dev, tx_channel, SCR_TIMER_ACCESS,
1527 vcc->tx_scr_bits);
1528
1529
1530 update_tx_channel_config (dev, tx_channel, BUCKET_CAPACITY_ACCESS,
1531 vcc->tx_bucket_bits);
1532
1533
1534 update_tx_channel_config (dev, tx_channel, BUCKET_FULLNESS_ACCESS,
1535 vcc->tx_bucket_bits);
1536 }
1537#endif
1538
1539
1540 rd_ptr = rd_mem (dev, &tx_desc->rd_buf_type) & BUFFER_PTR_MASK;
1541 wr_ptr = rd_mem (dev, &tx_desc->wr_buf_type) & BUFFER_PTR_MASK;
1542
1543
1544 if (rd_ptr != wr_ptr) {
1545 PRINTD (DBG_TX|DBG_ERR, "TX buffer pointers are broken!");
1546
1547
1548 }
1549 PRINTD (DBG_TX, "TX buffer pointers are: rd %x, wr %x.",
1550 rd_ptr, wr_ptr);
1551
1552 switch (vcc->aal) {
1553 case aal0:
1554 PRINTD (DBG_QOS|DBG_TX, "tx_channel: aal0");
1555 rd_ptr |= CHANNEL_TYPE_RAW_CELLS;
1556 wr_ptr |= CHANNEL_TYPE_RAW_CELLS;
1557 break;
1558 case aal34:
1559 PRINTD (DBG_QOS|DBG_TX, "tx_channel: aal34");
1560 rd_ptr |= CHANNEL_TYPE_AAL3_4;
1561 wr_ptr |= CHANNEL_TYPE_AAL3_4;
1562 break;
1563 case aal5:
1564 rd_ptr |= CHANNEL_TYPE_AAL5;
1565 wr_ptr |= CHANNEL_TYPE_AAL5;
1566
1567 wr_mem (dev, &tx_desc->partial_crc, INITIAL_CRC);
1568 break;
1569 }
1570
1571 wr_mem (dev, &tx_desc->rd_buf_type, rd_ptr);
1572 wr_mem (dev, &tx_desc->wr_buf_type, wr_ptr);
1573
1574
1575
1576 wr_mem (dev, &tx_desc->cell_header, channel);
1577
1578 spin_unlock_irqrestore (&dev->mem_lock, flags);
1579 }
1580
1581 return tx_channel;
1582}
1583
1584
1585
1586static int hrz_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
1587 unsigned int spin_count;
1588 int free_buffers;
1589 hrz_dev * dev = HRZ_DEV(atm_vcc->dev);
1590 hrz_vcc * vcc = HRZ_VCC(atm_vcc);
1591 u16 channel = vcc->channel;
1592
1593 u32 buffers_required;
1594
1595
1596 short tx_channel;
1597
1598 PRINTD (DBG_FLOW|DBG_TX, "hrz_send vc %x data %p len %u",
1599 channel, skb->data, skb->len);
1600
1601 dump_skb (">>>", channel, skb);
1602
1603 if (atm_vcc->qos.txtp.traffic_class == ATM_NONE) {
1604 PRINTK (KERN_ERR, "attempt to send on RX-only VC %x", channel);
1605 hrz_kfree_skb (skb);
1606 return -EIO;
1607 }
1608
1609
1610 ATM_SKB(skb)->vcc = atm_vcc;
1611
1612 if (skb->len > atm_vcc->qos.txtp.max_sdu) {
1613 PRINTK (KERN_ERR, "sk_buff length greater than agreed max_sdu, dropping...");
1614 hrz_kfree_skb (skb);
1615 return -EIO;
1616 }
1617
1618 if (!channel) {
1619 PRINTD (DBG_ERR|DBG_TX, "attempt to transmit on zero (rx_)channel");
1620 hrz_kfree_skb (skb);
1621 return -EIO;
1622 }
1623
1624#if 0
1625 {
1626
1627 u16 status;
1628 pci_read_config_word (dev->pci_dev, PCI_STATUS, &status);
1629 if (status & PCI_STATUS_REC_MASTER_ABORT) {
1630 PRINTD (DBG_BUS|DBG_ERR, "Clearing PCI Master Abort (and cleaning up)");
1631 status &= ~PCI_STATUS_REC_MASTER_ABORT;
1632 pci_write_config_word (dev->pci_dev, PCI_STATUS, status);
1633 if (test_bit (tx_busy, &dev->flags)) {
1634 hrz_kfree_skb (dev->tx_skb);
1635 tx_release (dev);
1636 }
1637 }
1638 }
1639#endif
1640
1641#ifdef DEBUG_HORIZON
1642
1643 if (channel == 1023) {
1644 unsigned int i;
1645 unsigned short d = 0;
1646 char * s = skb->data;
1647 if (*s++ == 'D') {
1648 for (i = 0; i < 4; ++i)
1649 d = (d << 4) | hex_to_bin(*s++);
1650 PRINTK (KERN_INFO, "debug bitmap is now %hx", debug = d);
1651 }
1652 }
1653#endif
1654
1655
1656 if (tx_hold (dev)) {
1657 hrz_kfree_skb (skb);
1658 return -ERESTARTSYS;
1659 }
1660
1661
1662
1663
1664
1665
1666 buffers_required = (skb->len+(ATM_AAL5_TRAILER-1)) / ATM_CELL_PAYLOAD + 3;
1667
1668
1669 spin_count = 0;
1670 while ((free_buffers = rd_regw (dev, TX_FREE_BUFFER_COUNT_OFF)) < buffers_required) {
1671 PRINTD (DBG_TX, "waiting for free TX buffers, got %d of %d",
1672 free_buffers, buffers_required);
1673
1674
1675
1676 schedule();
1677 if (++spin_count > 1000) {
1678 PRINTD (DBG_TX|DBG_ERR, "spun out waiting for tx buffers, got %d of %d",
1679 free_buffers, buffers_required);
1680 tx_release (dev);
1681 hrz_kfree_skb (skb);
1682 return -ERESTARTSYS;
1683 }
1684 }
1685
1686
1687 if (channel == dev->last_vc) {
1688 PRINTD (DBG_TX, "last vc hack: hit");
1689 tx_channel = dev->tx_last;
1690 } else {
1691 PRINTD (DBG_TX, "last vc hack: miss");
1692
1693 for (tx_channel = 0; tx_channel < TX_CHANS; ++tx_channel)
1694 if (dev->tx_channel_record[tx_channel] == channel) {
1695 PRINTD (DBG_TX, "vc already on channel: hit");
1696 break;
1697 }
1698 if (tx_channel == TX_CHANS) {
1699 PRINTD (DBG_TX, "vc already on channel: miss");
1700
1701 tx_channel = setup_idle_tx_channel (dev, vcc);
1702 if (tx_channel < 0) {
1703 PRINTD (DBG_TX|DBG_ERR, "failed to get channel");
1704 tx_release (dev);
1705 return tx_channel;
1706 }
1707 }
1708
1709 PRINTD (DBG_TX, "got channel");
1710 SELECT_TX_CHANNEL(dev, tx_channel);
1711
1712 dev->last_vc = channel;
1713 dev->tx_last = tx_channel;
1714 }
1715
1716 PRINTD (DBG_TX, "using channel %u", tx_channel);
1717
1718 YELLOW_LED_OFF(dev);
1719
1720
1721
1722 {
1723 unsigned int tx_len = skb->len;
1724 unsigned int tx_iovcnt = skb_shinfo(skb)->nr_frags;
1725
1726 dev->tx_skb = skb;
1727
1728 if (tx_iovcnt) {
1729
1730 dev->tx_regions = tx_iovcnt;
1731 dev->tx_iovec = NULL;
1732 dev->tx_bytes = 0;
1733 PRINTD (DBG_TX|DBG_BUS, "TX start scatter-gather transfer (iovec %p, len %d)",
1734 skb->data, tx_len);
1735 tx_release (dev);
1736 hrz_kfree_skb (skb);
1737 return -EIO;
1738 } else {
1739
1740 dev->tx_regions = 0;
1741 dev->tx_iovec = NULL;
1742 dev->tx_bytes = tx_len;
1743 dev->tx_addr = skb->data;
1744 PRINTD (DBG_TX|DBG_BUS, "TX start simple transfer (addr %p, len %d)",
1745 skb->data, tx_len);
1746 }
1747
1748
1749 tx_schedule (dev, 0);
1750
1751 }
1752
1753 return 0;
1754}
1755
1756
1757
1758static void hrz_reset (const hrz_dev * dev) {
1759 u32 control_0_reg = rd_regl (dev, CONTROL_0_REG);
1760
1761
1762
1763 control_0_reg = control_0_reg & RESET_HORIZON;
1764 wr_regl (dev, CONTROL_0_REG, control_0_reg);
1765 while (control_0_reg & RESET_HORIZON)
1766 control_0_reg = rd_regl (dev, CONTROL_0_REG);
1767
1768
1769 wr_regl (dev, CONTROL_0_REG, control_0_reg |
1770 RESET_ATM | RESET_RX | RESET_TX | RESET_HOST);
1771
1772 udelay (1000);
1773
1774 wr_regl (dev, CONTROL_0_REG, control_0_reg);
1775}
1776
1777
1778
1779static void WRITE_IT_WAIT (const hrz_dev *dev, u32 ctrl)
1780{
1781 wr_regl (dev, CONTROL_0_REG, ctrl);
1782 udelay (5);
1783}
1784
1785static void CLOCK_IT (const hrz_dev *dev, u32 ctrl)
1786{
1787
1788 WRITE_IT_WAIT(dev, ctrl & ~SEEPROM_SK);
1789 WRITE_IT_WAIT(dev, ctrl | SEEPROM_SK);
1790}
1791
1792static u16 __devinit read_bia (const hrz_dev * dev, u16 addr)
1793{
1794 u32 ctrl = rd_regl (dev, CONTROL_0_REG);
1795
1796 const unsigned int addr_bits = 6;
1797 const unsigned int data_bits = 16;
1798
1799 unsigned int i;
1800
1801 u16 res;
1802
1803 ctrl &= ~(SEEPROM_CS | SEEPROM_SK | SEEPROM_DI);
1804 WRITE_IT_WAIT(dev, ctrl);
1805
1806
1807 ctrl |= (SEEPROM_CS | SEEPROM_DI);
1808 CLOCK_IT(dev, ctrl);
1809
1810 ctrl |= SEEPROM_DI;
1811 CLOCK_IT(dev, ctrl);
1812
1813 ctrl &= ~SEEPROM_DI;
1814 CLOCK_IT(dev, ctrl);
1815
1816 for (i=0; i<addr_bits; i++) {
1817 if (addr & (1 << (addr_bits-1)))
1818 ctrl |= SEEPROM_DI;
1819 else
1820 ctrl &= ~SEEPROM_DI;
1821
1822 CLOCK_IT(dev, ctrl);
1823
1824 addr = addr << 1;
1825 }
1826
1827
1828 ctrl &= ~SEEPROM_DI;
1829
1830 res = 0;
1831 for (i=0;i<data_bits;i++) {
1832 res = res >> 1;
1833
1834 CLOCK_IT(dev, ctrl);
1835
1836 if (rd_regl (dev, CONTROL_0_REG) & SEEPROM_DO)
1837 res |= (1 << (data_bits-1));
1838 }
1839
1840 ctrl &= ~(SEEPROM_SK | SEEPROM_CS);
1841 WRITE_IT_WAIT(dev, ctrl);
1842
1843 return res;
1844}
1845
1846
1847
1848static int __devinit hrz_init (hrz_dev * dev) {
1849 int onefivefive;
1850
1851 u16 chan;
1852
1853 int buff_count;
1854
1855 HDW * mem;
1856
1857 cell_buf * tx_desc;
1858 cell_buf * rx_desc;
1859
1860 u32 ctrl;
1861
1862 ctrl = rd_regl (dev, CONTROL_0_REG);
1863 PRINTD (DBG_INFO, "ctrl0reg is %#x", ctrl);
1864 onefivefive = ctrl & ATM_LAYER_STATUS;
1865
1866 if (onefivefive)
1867 printk (DEV_LABEL ": Horizon Ultra (at 155.52 MBps)");
1868 else
1869 printk (DEV_LABEL ": Horizon (at 25 MBps)");
1870
1871 printk (":");
1872
1873
1874 printk (" reset");
1875 hrz_reset (dev);
1876
1877
1878
1879 printk (" clearing memory");
1880
1881 for (mem = (HDW *) memmap; mem < (HDW *) (memmap + 1); ++mem)
1882 wr_mem (dev, mem, 0);
1883
1884 printk (" tx channels");
1885
1886
1887
1888
1889
1890
1891
1892 for (chan = 0; chan < TX_CHANS; ++chan) {
1893 tx_ch_desc * tx_desc = &memmap->tx_descs[chan];
1894 cell_buf * buf = &memmap->inittxbufs[chan];
1895
1896
1897 wr_mem (dev, &tx_desc->rd_buf_type, BUF_PTR(buf));
1898 wr_mem (dev, &tx_desc->wr_buf_type, BUF_PTR(buf));
1899
1900
1901 wr_mem (dev, &buf->next, BUFF_STATUS_EMPTY);
1902 }
1903
1904
1905
1906 printk (" tx buffers");
1907
1908 tx_desc = memmap->bufn3;
1909
1910 wr_mem (dev, &memmap->txfreebufstart.next, BUF_PTR(tx_desc) | BUFF_STATUS_EMPTY);
1911
1912 for (buff_count = 0; buff_count < BUFN3_SIZE-1; buff_count++) {
1913 wr_mem (dev, &tx_desc->next, BUF_PTR(tx_desc+1) | BUFF_STATUS_EMPTY);
1914 tx_desc++;
1915 }
1916
1917 wr_mem (dev, &tx_desc->next, BUF_PTR(&memmap->txfreebufend) | BUFF_STATUS_EMPTY);
1918
1919
1920 wr_regw (dev, TX_FREE_BUFFER_COUNT_OFF, BUFN3_SIZE);
1921
1922 printk (" rx channels");
1923
1924
1925
1926
1927 for (chan = 0; chan < RX_CHANS; ++chan) {
1928 rx_ch_desc * rx_desc = &memmap->rx_descs[chan];
1929
1930 wr_mem (dev, &rx_desc->wr_buf_type, CHANNEL_TYPE_AAL5 | RX_CHANNEL_DISABLED);
1931 }
1932
1933 printk (" rx buffers");
1934
1935
1936
1937 rx_desc = memmap->bufn4;
1938
1939 wr_mem (dev, &memmap->rxfreebufstart.next, BUF_PTR(rx_desc) | BUFF_STATUS_EMPTY);
1940
1941 for (buff_count = 0; buff_count < BUFN4_SIZE-1; buff_count++) {
1942 wr_mem (dev, &rx_desc->next, BUF_PTR(rx_desc+1) | BUFF_STATUS_EMPTY);
1943
1944 rx_desc++;
1945 }
1946
1947 wr_mem (dev, &rx_desc->next, BUF_PTR(&memmap->rxfreebufend) | BUFF_STATUS_EMPTY);
1948
1949
1950 wr_regw (dev, RX_FREE_BUFFER_COUNT_OFF, BUFN4_SIZE);
1951
1952
1953
1954
1955 wr_regw (dev, TX_CONFIG_OFF,
1956 ABR_ROUND_ROBIN | TX_NORMAL_OPERATION | DRVR_DRVRBAR_ENABLE);
1957
1958
1959 wr_regw (dev, RX_CONFIG_OFF,
1960 DISCARD_UNUSED_VPI_VCI_BITS_SET | NON_USER_CELLS_IN_ONE_CHANNEL | vpi_bits);
1961
1962
1963 wr_regw (dev, RX_LINE_CONFIG_OFF,
1964 LOCK_DETECT_ENABLE | FREQUENCY_DETECT_ENABLE | GXTALOUT_SELECT_DIV4);
1965
1966
1967
1968 wr_regw (dev, MAX_AAL5_CELL_COUNT_OFF,
1969 DIV_ROUND_UP(max_rx_size + ATM_AAL5_TRAILER, ATM_CELL_PAYLOAD));
1970
1971
1972 wr_regw (dev, RX_CONFIG_OFF, rd_regw (dev, RX_CONFIG_OFF) | RX_ENABLE);
1973
1974 printk (" control");
1975
1976
1977 ctrl |= GREEN_LED_OE | YELLOW_LED_OE | GREEN_LED | YELLOW_LED;
1978 wr_regl (dev, CONTROL_0_REG, ctrl);
1979
1980
1981
1982 if (onefivefive) {
1983
1984
1985 ctrl |= ATM_LAYER_SELECT;
1986 wr_regl (dev, CONTROL_0_REG, ctrl);
1987
1988
1989
1990
1991
1992
1993
1994 if (rd_framer (dev, 0) & 0x00f0) {
1995
1996 printk (" SUNI");
1997
1998
1999 wr_framer (dev, 0x00, 0x0080);
2000 wr_framer (dev, 0x00, 0x0000);
2001
2002
2003 wr_framer (dev, 0x63, rd_framer (dev, 0x63) | 0x0002);
2004
2005
2006 wr_framer (dev, 0x05, rd_framer (dev, 0x05) | 0x0001);
2007 } else {
2008
2009 printk (" SAMBA");
2010
2011
2012 wr_framer (dev, 0, rd_framer (dev, 0) | 0x0001);
2013 wr_framer (dev, 0, rd_framer (dev, 0) &~ 0x0001);
2014
2015
2016 wr_framer (dev, 0, 0x0002);
2017
2018
2019 wr_framer (dev, 2, 0x0B80);
2020 }
2021 } else {
2022
2023 ctrl &= ~ATM_LAYER_SELECT;
2024
2025
2026
2027 }
2028
2029 printk (" LEDs");
2030
2031 GREEN_LED_ON(dev);
2032 YELLOW_LED_ON(dev);
2033
2034 printk (" ESI=");
2035
2036 {
2037 u16 b = 0;
2038 int i;
2039 u8 * esi = dev->atm_dev->esi;
2040
2041
2042
2043
2044
2045
2046
2047 for (i=0; i < ESI_LEN; ++i) {
2048 if (i % 2 == 0)
2049 b = read_bia (dev, i/2 + 2);
2050 else
2051 b = b >> 8;
2052 esi[i] = b & 0xFF;
2053 printk ("%02x", esi[i]);
2054 }
2055 }
2056
2057
2058 wr_regl (dev, INT_ENABLE_REG_OFF, INTERESTING_INTERRUPTS);
2059 printk (" IRQ on");
2060
2061 printk (".\n");
2062
2063 return onefivefive;
2064}
2065
2066
2067
2068static int check_max_sdu (hrz_aal aal, struct atm_trafprm * tp, unsigned int max_frame_size) {
2069 PRINTD (DBG_FLOW|DBG_QOS, "check_max_sdu");
2070
2071 switch (aal) {
2072 case aal0:
2073 if (!(tp->max_sdu)) {
2074 PRINTD (DBG_QOS, "defaulting max_sdu");
2075 tp->max_sdu = ATM_AAL0_SDU;
2076 } else if (tp->max_sdu != ATM_AAL0_SDU) {
2077 PRINTD (DBG_QOS|DBG_ERR, "rejecting max_sdu");
2078 return -EINVAL;
2079 }
2080 break;
2081 case aal34:
2082 if (tp->max_sdu == 0 || tp->max_sdu > ATM_MAX_AAL34_PDU) {
2083 PRINTD (DBG_QOS, "%sing max_sdu", tp->max_sdu ? "capp" : "default");
2084 tp->max_sdu = ATM_MAX_AAL34_PDU;
2085 }
2086 break;
2087 case aal5:
2088 if (tp->max_sdu == 0 || tp->max_sdu > max_frame_size) {
2089 PRINTD (DBG_QOS, "%sing max_sdu", tp->max_sdu ? "capp" : "default");
2090 tp->max_sdu = max_frame_size;
2091 }
2092 break;
2093 }
2094 return 0;
2095}
2096
2097
2098
2099
2100static int atm_pcr_check (struct atm_trafprm * tp, unsigned int pcr) {
2101
2102 if (tp->min_pcr == ATM_MAX_PCR)
2103 PRINTD (DBG_QOS, "luser gave min_pcr = ATM_MAX_PCR");
2104 else if (tp->min_pcr < 0)
2105 PRINTD (DBG_QOS, "luser gave negative min_pcr");
2106 else if (tp->min_pcr && tp->min_pcr > pcr)
2107 PRINTD (DBG_QOS, "pcr less than min_pcr");
2108 else
2109
2110
2111
2112 if ((0) && tp->max_pcr == ATM_MAX_PCR)
2113 PRINTD (DBG_QOS, "luser gave max_pcr = ATM_MAX_PCR");
2114 else if ((tp->max_pcr != ATM_MAX_PCR) && tp->max_pcr < 0)
2115 PRINTD (DBG_QOS, "luser gave negative max_pcr");
2116 else if (tp->max_pcr && tp->max_pcr != ATM_MAX_PCR && tp->max_pcr < pcr)
2117 PRINTD (DBG_QOS, "pcr greater than max_pcr");
2118 else {
2119
2120 PRINTD (DBG_QOS, "xBR(pcr) OK");
2121 return 0;
2122 }
2123 PRINTD (DBG_QOS, "pcr=%u, tp: min_pcr=%d, pcr=%d, max_pcr=%d",
2124 pcr, tp->min_pcr, tp->pcr, tp->max_pcr);
2125 return -EINVAL;
2126}
2127
2128
2129
2130static int hrz_open (struct atm_vcc *atm_vcc)
2131{
2132 int error;
2133 u16 channel;
2134
2135 struct atm_qos * qos;
2136 struct atm_trafprm * txtp;
2137 struct atm_trafprm * rxtp;
2138
2139 hrz_dev * dev = HRZ_DEV(atm_vcc->dev);
2140 hrz_vcc vcc;
2141 hrz_vcc * vccp;
2142 short vpi = atm_vcc->vpi;
2143 int vci = atm_vcc->vci;
2144 PRINTD (DBG_FLOW|DBG_VCC, "hrz_open %x %x", vpi, vci);
2145
2146#ifdef ATM_VPI_UNSPEC
2147
2148 if (vpi == ATM_VPI_UNSPEC || vci == ATM_VCI_UNSPEC) {
2149 PRINTK (KERN_WARNING, "rejecting open with unspecified VPI/VCI (deprecated)");
2150 return -EINVAL;
2151 }
2152#endif
2153
2154 error = vpivci_to_channel (&channel, vpi, vci);
2155 if (error) {
2156 PRINTD (DBG_WARN|DBG_VCC, "VPI/VCI out of range: %hd/%d", vpi, vci);
2157 return error;
2158 }
2159
2160 vcc.channel = channel;
2161
2162 vcc.tx_rate = 0x0;
2163
2164 qos = &atm_vcc->qos;
2165
2166
2167 switch (qos->aal) {
2168 case ATM_AAL0:
2169
2170 PRINTD (DBG_QOS|DBG_VCC, "AAL0");
2171 vcc.aal = aal0;
2172 break;
2173 case ATM_AAL34:
2174
2175 PRINTD (DBG_QOS|DBG_VCC, "AAL3/4");
2176 vcc.aal = aal34;
2177 break;
2178 case ATM_AAL5:
2179 PRINTD (DBG_QOS|DBG_VCC, "AAL5");
2180 vcc.aal = aal5;
2181 break;
2182 default:
2183 PRINTD (DBG_QOS|DBG_VCC, "Bad AAL!");
2184 return -EINVAL;
2185 break;
2186 }
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222 PRINTD (DBG_QOS, "TX:");
2223
2224 txtp = &qos->txtp;
2225
2226
2227 vcc.tx_rate = 0;
2228
2229 vcc.tx_xbr_bits = IDLE_RATE_TYPE;
2230 vcc.tx_pcr_bits = CLOCK_DISABLE;
2231#if 0
2232 vcc.tx_scr_bits = CLOCK_DISABLE;
2233 vcc.tx_bucket_bits = 0;
2234#endif
2235
2236 if (txtp->traffic_class != ATM_NONE) {
2237 error = check_max_sdu (vcc.aal, txtp, max_tx_size);
2238 if (error) {
2239 PRINTD (DBG_QOS, "TX max_sdu check failed");
2240 return error;
2241 }
2242
2243 switch (txtp->traffic_class) {
2244 case ATM_UBR: {
2245
2246
2247 vcc.tx_rate = 0;
2248 make_rate (dev, 1<<30, round_nearest, &vcc.tx_pcr_bits, NULL);
2249 vcc.tx_xbr_bits = ABR_RATE_TYPE;
2250 break;
2251 }
2252#if 0
2253 case ATM_ABR: {
2254
2255 vcc.tx_rate = 0;
2256 make_rate (dev, 1<<30, round_nearest, &vcc.tx_pcr_bits, 0);
2257 vcc.tx_xbr_bits = ABR_RATE_TYPE;
2258 break;
2259 }
2260#endif
2261 case ATM_CBR: {
2262 int pcr = atm_pcr_goal (txtp);
2263 rounding r;
2264 if (!pcr) {
2265
2266
2267
2268
2269
2270 r = round_down;
2271
2272
2273 PRINTD (DBG_QOS, "snatching all remaining TX bandwidth");
2274 pcr = dev->tx_avail;
2275 } else if (pcr < 0) {
2276 r = round_down;
2277 pcr = -pcr;
2278 } else {
2279 r = round_up;
2280 }
2281 error = make_rate_with_tolerance (dev, pcr, r, 10,
2282 &vcc.tx_pcr_bits, &vcc.tx_rate);
2283 if (error) {
2284 PRINTD (DBG_QOS, "could not make rate from TX PCR");
2285 return error;
2286 }
2287
2288 error = atm_pcr_check (txtp, vcc.tx_rate);
2289 if (error) {
2290 PRINTD (DBG_QOS, "TX PCR failed consistency check");
2291 return error;
2292 }
2293 vcc.tx_xbr_bits = CBR_RATE_TYPE;
2294 break;
2295 }
2296#if 0
2297 case ATM_VBR: {
2298 int pcr = atm_pcr_goal (txtp);
2299
2300 int scr = pcr/2;
2301 unsigned int mbs = 60;
2302 rounding pr;
2303 rounding sr;
2304 unsigned int bucket;
2305 if (!pcr) {
2306 pr = round_nearest;
2307 pcr = 1<<30;
2308 } else if (pcr < 0) {
2309 pr = round_down;
2310 pcr = -pcr;
2311 } else {
2312 pr = round_up;
2313 }
2314 error = make_rate_with_tolerance (dev, pcr, pr, 10,
2315 &vcc.tx_pcr_bits, 0);
2316 if (!scr) {
2317
2318 sr = round_down;
2319
2320
2321 PRINTD (DBG_QOS, "snatching all remaining TX bandwidth");
2322 scr = dev->tx_avail;
2323 } else if (scr < 0) {
2324 sr = round_down;
2325 scr = -scr;
2326 } else {
2327 sr = round_up;
2328 }
2329 error = make_rate_with_tolerance (dev, scr, sr, 10,
2330 &vcc.tx_scr_bits, &vcc.tx_rate);
2331 if (error) {
2332 PRINTD (DBG_QOS, "could not make rate from TX SCR");
2333 return error;
2334 }
2335
2336
2337 if (error) {
2338 PRINTD (DBG_QOS, "TX SCR failed consistency check");
2339 return error;
2340 }
2341
2342
2343
2344 bucket = mbs*(pcr-scr)/pcr;
2345 if (bucket*pcr != mbs*(pcr-scr))
2346 bucket += 1;
2347 if (bucket > BUCKET_MAX_SIZE) {
2348 PRINTD (DBG_QOS, "shrinking bucket from %u to %u",
2349 bucket, BUCKET_MAX_SIZE);
2350 bucket = BUCKET_MAX_SIZE;
2351 }
2352 vcc.tx_xbr_bits = VBR_RATE_TYPE;
2353 vcc.tx_bucket_bits = bucket;
2354 break;
2355 }
2356#endif
2357 default: {
2358 PRINTD (DBG_QOS, "unsupported TX traffic class");
2359 return -EINVAL;
2360 break;
2361 }
2362 }
2363 }
2364
2365
2366
2367 PRINTD (DBG_QOS, "RX:");
2368
2369 rxtp = &qos->rxtp;
2370
2371
2372 vcc.rx_rate = 0;
2373
2374 if (rxtp->traffic_class != ATM_NONE) {
2375 error = check_max_sdu (vcc.aal, rxtp, max_rx_size);
2376 if (error) {
2377 PRINTD (DBG_QOS, "RX max_sdu check failed");
2378 return error;
2379 }
2380 switch (rxtp->traffic_class) {
2381 case ATM_UBR: {
2382
2383 break;
2384 }
2385#if 0
2386 case ATM_ABR: {
2387
2388 vcc.rx_rate = 0;
2389 break;
2390 }
2391#endif
2392 case ATM_CBR: {
2393 int pcr = atm_pcr_goal (rxtp);
2394 if (!pcr) {
2395
2396
2397 PRINTD (DBG_QOS, "snatching all remaining RX bandwidth");
2398 pcr = dev->rx_avail;
2399 } else if (pcr < 0) {
2400 pcr = -pcr;
2401 }
2402 vcc.rx_rate = pcr;
2403
2404 error = atm_pcr_check (rxtp, vcc.rx_rate);
2405 if (error) {
2406 PRINTD (DBG_QOS, "RX PCR failed consistency check");
2407 return error;
2408 }
2409 break;
2410 }
2411#if 0
2412 case ATM_VBR: {
2413
2414 int scr = 1<<16;
2415 if (!scr) {
2416
2417
2418 PRINTD (DBG_QOS, "snatching all remaining RX bandwidth");
2419 scr = dev->rx_avail;
2420 } else if (scr < 0) {
2421 scr = -scr;
2422 }
2423 vcc.rx_rate = scr;
2424
2425
2426 if (error) {
2427 PRINTD (DBG_QOS, "RX SCR failed consistency check");
2428 return error;
2429 }
2430 break;
2431 }
2432#endif
2433 default: {
2434 PRINTD (DBG_QOS, "unsupported RX traffic class");
2435 return -EINVAL;
2436 break;
2437 }
2438 }
2439 }
2440
2441
2442
2443 if (vcc.aal != aal5) {
2444 PRINTD (DBG_QOS, "AAL not supported");
2445 return -EINVAL;
2446 }
2447
2448
2449 vccp = kmalloc (sizeof(hrz_vcc), GFP_KERNEL);
2450 if (!vccp) {
2451 PRINTK (KERN_ERR, "out of memory!");
2452 return -ENOMEM;
2453 }
2454 *vccp = vcc;
2455
2456
2457 error = 0;
2458 spin_lock (&dev->rate_lock);
2459
2460 if (vcc.tx_rate > dev->tx_avail) {
2461 PRINTD (DBG_QOS, "not enough TX PCR left");
2462 error = -EAGAIN;
2463 }
2464
2465 if (vcc.rx_rate > dev->rx_avail) {
2466 PRINTD (DBG_QOS, "not enough RX PCR left");
2467 error = -EAGAIN;
2468 }
2469
2470 if (!error) {
2471
2472 dev->tx_avail -= vcc.tx_rate;
2473 dev->rx_avail -= vcc.rx_rate;
2474 PRINTD (DBG_QOS|DBG_VCC, "reserving %u TX PCR and %u RX PCR",
2475 vcc.tx_rate, vcc.rx_rate);
2476 }
2477
2478
2479 spin_unlock (&dev->rate_lock);
2480 if (error) {
2481 PRINTD (DBG_QOS|DBG_VCC, "insufficient cell rate resources");
2482 kfree (vccp);
2483 return error;
2484 }
2485
2486
2487
2488 set_bit(ATM_VF_ADDR,&atm_vcc->flags);
2489
2490
2491
2492 if (rxtp->traffic_class != ATM_NONE) {
2493 if (dev->rxer[channel]) {
2494 PRINTD (DBG_ERR|DBG_VCC, "VC already open for RX");
2495 error = -EBUSY;
2496 }
2497 if (!error)
2498 error = hrz_open_rx (dev, channel);
2499 if (error) {
2500 kfree (vccp);
2501 return error;
2502 }
2503
2504 dev->rxer[channel] = atm_vcc;
2505 }
2506
2507
2508 atm_vcc->dev_data = (void *) vccp;
2509
2510
2511 set_bit(ATM_VF_READY,&atm_vcc->flags);
2512
2513 return 0;
2514}
2515
2516
2517
2518static void hrz_close (struct atm_vcc * atm_vcc) {
2519 hrz_dev * dev = HRZ_DEV(atm_vcc->dev);
2520 hrz_vcc * vcc = HRZ_VCC(atm_vcc);
2521 u16 channel = vcc->channel;
2522 PRINTD (DBG_VCC|DBG_FLOW, "hrz_close");
2523
2524
2525 clear_bit(ATM_VF_READY,&atm_vcc->flags);
2526
2527 if (atm_vcc->qos.txtp.traffic_class != ATM_NONE) {
2528 unsigned int i;
2529
2530
2531
2532 while (tx_hold (dev))
2533 ;
2534
2535 for (i = 0; i < TX_CHANS; ++i)
2536 if (dev->tx_channel_record[i] == channel) {
2537 dev->tx_channel_record[i] = -1;
2538 break;
2539 }
2540 if (dev->last_vc == channel)
2541 dev->tx_last = -1;
2542 tx_release (dev);
2543 }
2544
2545 if (atm_vcc->qos.rxtp.traffic_class != ATM_NONE) {
2546
2547 hrz_close_rx (dev, channel);
2548
2549 if (atm_vcc != dev->rxer[channel])
2550 PRINTK (KERN_ERR, "%s atm_vcc=%p rxer[channel]=%p",
2551 "arghhh! we're going to die!",
2552 atm_vcc, dev->rxer[channel]);
2553 dev->rxer[channel] = NULL;
2554 }
2555
2556
2557 spin_lock (&dev->rate_lock);
2558 PRINTD (DBG_QOS|DBG_VCC, "releasing %u TX PCR and %u RX PCR",
2559 vcc->tx_rate, vcc->rx_rate);
2560 dev->tx_avail += vcc->tx_rate;
2561 dev->rx_avail += vcc->rx_rate;
2562 spin_unlock (&dev->rate_lock);
2563
2564
2565 kfree (vcc);
2566
2567 clear_bit(ATM_VF_ADDR,&atm_vcc->flags);
2568}
2569
2570#if 0
2571static int hrz_getsockopt (struct atm_vcc * atm_vcc, int level, int optname,
2572 void *optval, int optlen) {
2573 hrz_dev * dev = HRZ_DEV(atm_vcc->dev);
2574 PRINTD (DBG_FLOW|DBG_VCC, "hrz_getsockopt");
2575 switch (level) {
2576 case SOL_SOCKET:
2577 switch (optname) {
2578
2579
2580
2581
2582 default:
2583 return -ENOPROTOOPT;
2584 break;
2585 };
2586 break;
2587 }
2588 return -EINVAL;
2589}
2590
2591static int hrz_setsockopt (struct atm_vcc * atm_vcc, int level, int optname,
2592 void *optval, unsigned int optlen) {
2593 hrz_dev * dev = HRZ_DEV(atm_vcc->dev);
2594 PRINTD (DBG_FLOW|DBG_VCC, "hrz_setsockopt");
2595 switch (level) {
2596 case SOL_SOCKET:
2597 switch (optname) {
2598
2599
2600
2601
2602 default:
2603 return -ENOPROTOOPT;
2604 break;
2605 };
2606 break;
2607 }
2608 return -EINVAL;
2609}
2610#endif
2611
2612#if 0
2613static int hrz_ioctl (struct atm_dev * atm_dev, unsigned int cmd, void *arg) {
2614 hrz_dev * dev = HRZ_DEV(atm_dev);
2615 PRINTD (DBG_FLOW, "hrz_ioctl");
2616 return -1;
2617}
2618
2619unsigned char hrz_phy_get (struct atm_dev * atm_dev, unsigned long addr) {
2620 hrz_dev * dev = HRZ_DEV(atm_dev);
2621 PRINTD (DBG_FLOW, "hrz_phy_get");
2622 return 0;
2623}
2624
2625static void hrz_phy_put (struct atm_dev * atm_dev, unsigned char value,
2626 unsigned long addr) {
2627 hrz_dev * dev = HRZ_DEV(atm_dev);
2628 PRINTD (DBG_FLOW, "hrz_phy_put");
2629}
2630
2631static int hrz_change_qos (struct atm_vcc * atm_vcc, struct atm_qos *qos, int flgs) {
2632 hrz_dev * dev = HRZ_DEV(vcc->dev);
2633 PRINTD (DBG_FLOW, "hrz_change_qos");
2634 return -1;
2635}
2636#endif
2637
2638
2639
2640static int hrz_proc_read (struct atm_dev * atm_dev, loff_t * pos, char * page) {
2641 hrz_dev * dev = HRZ_DEV(atm_dev);
2642 int left = *pos;
2643 PRINTD (DBG_FLOW, "hrz_proc_read");
2644
2645
2646
2647#if 0
2648 if (!left--) {
2649 unsigned int count = sprintf (page, "vbr buckets:");
2650 unsigned int i;
2651 for (i = 0; i < TX_CHANS; ++i)
2652 count += sprintf (page, " %u/%u",
2653 query_tx_channel_config (dev, i, BUCKET_FULLNESS_ACCESS),
2654 query_tx_channel_config (dev, i, BUCKET_CAPACITY_ACCESS));
2655 count += sprintf (page+count, ".\n");
2656 return count;
2657 }
2658#endif
2659
2660 if (!left--)
2661 return sprintf (page,
2662 "cells: TX %lu, RX %lu, HEC errors %lu, unassigned %lu.\n",
2663 dev->tx_cell_count, dev->rx_cell_count,
2664 dev->hec_error_count, dev->unassigned_cell_count);
2665
2666 if (!left--)
2667 return sprintf (page,
2668 "free cell buffers: TX %hu, RX %hu+%hu.\n",
2669 rd_regw (dev, TX_FREE_BUFFER_COUNT_OFF),
2670 rd_regw (dev, RX_FREE_BUFFER_COUNT_OFF),
2671 dev->noof_spare_buffers);
2672
2673 if (!left--)
2674 return sprintf (page,
2675 "cps remaining: TX %u, RX %u\n",
2676 dev->tx_avail, dev->rx_avail);
2677
2678 return 0;
2679}
2680
2681static const struct atmdev_ops hrz_ops = {
2682 .open = hrz_open,
2683 .close = hrz_close,
2684 .send = hrz_send,
2685 .proc_read = hrz_proc_read,
2686 .owner = THIS_MODULE,
2687};
2688
2689static int __devinit hrz_probe(struct pci_dev *pci_dev, const struct pci_device_id *pci_ent)
2690{
2691 hrz_dev * dev;
2692 int err = 0;
2693
2694
2695 u32 iobase = pci_resource_start (pci_dev, 0);
2696 u32 * membase = bus_to_virt (pci_resource_start (pci_dev, 1));
2697 unsigned int irq;
2698 unsigned char lat;
2699
2700 PRINTD (DBG_FLOW, "hrz_probe");
2701
2702 if (pci_enable_device(pci_dev))
2703 return -EINVAL;
2704
2705
2706 if (!request_region(iobase, HRZ_IO_EXTENT, DEV_LABEL)) {
2707 err = -EINVAL;
2708 goto out_disable;
2709 }
2710
2711 dev = kzalloc(sizeof(hrz_dev), GFP_KERNEL);
2712 if (!dev) {
2713
2714 PRINTD(DBG_ERR, "out of memory");
2715 err = -ENOMEM;
2716 goto out_release;
2717 }
2718
2719 pci_set_drvdata(pci_dev, dev);
2720
2721
2722 irq = pci_dev->irq;
2723 if (request_irq(irq,
2724 interrupt_handler,
2725 IRQF_SHARED,
2726 DEV_LABEL,
2727 dev)) {
2728 PRINTD(DBG_WARN, "request IRQ failed!");
2729 err = -EINVAL;
2730 goto out_free;
2731 }
2732
2733 PRINTD(DBG_INFO, "found Madge ATM adapter (hrz) at: IO %x, IRQ %u, MEM %p",
2734 iobase, irq, membase);
2735
2736 dev->atm_dev = atm_dev_register(DEV_LABEL, &pci_dev->dev, &hrz_ops, -1,
2737 NULL);
2738 if (!(dev->atm_dev)) {
2739 PRINTD(DBG_ERR, "failed to register Madge ATM adapter");
2740 err = -EINVAL;
2741 goto out_free_irq;
2742 }
2743
2744 PRINTD(DBG_INFO, "registered Madge ATM adapter (no. %d) (%p) at %p",
2745 dev->atm_dev->number, dev, dev->atm_dev);
2746 dev->atm_dev->dev_data = (void *) dev;
2747 dev->pci_dev = pci_dev;
2748
2749
2750 pci_set_master(pci_dev);
2751
2752
2753 pci_read_config_byte(pci_dev, PCI_LATENCY_TIMER, &lat);
2754 if (pci_lat) {
2755 PRINTD(DBG_INFO, "%s PCI latency timer from %hu to %hu",
2756 "changing", lat, pci_lat);
2757 pci_write_config_byte(pci_dev, PCI_LATENCY_TIMER, pci_lat);
2758 } else if (lat < MIN_PCI_LATENCY) {
2759 PRINTK(KERN_INFO, "%s PCI latency timer from %hu to %hu",
2760 "increasing", lat, MIN_PCI_LATENCY);
2761 pci_write_config_byte(pci_dev, PCI_LATENCY_TIMER, MIN_PCI_LATENCY);
2762 }
2763
2764 dev->iobase = iobase;
2765 dev->irq = irq;
2766 dev->membase = membase;
2767
2768 dev->rx_q_entry = dev->rx_q_reset = &memmap->rx_q_entries[0];
2769 dev->rx_q_wrap = &memmap->rx_q_entries[RX_CHANS-1];
2770
2771
2772 dev->last_vc = -1;
2773 dev->tx_last = -1;
2774 dev->tx_idle = 0;
2775
2776 dev->tx_regions = 0;
2777 dev->tx_bytes = 0;
2778 dev->tx_skb = NULL;
2779 dev->tx_iovec = NULL;
2780
2781 dev->tx_cell_count = 0;
2782 dev->rx_cell_count = 0;
2783 dev->hec_error_count = 0;
2784 dev->unassigned_cell_count = 0;
2785
2786 dev->noof_spare_buffers = 0;
2787
2788 {
2789 unsigned int i;
2790 for (i = 0; i < TX_CHANS; ++i)
2791 dev->tx_channel_record[i] = -1;
2792 }
2793
2794 dev->flags = 0;
2795
2796
2797
2798
2799
2800
2801 if (hrz_init(dev)) {
2802
2803 dev->tx_avail = ATM_OC3_PCR;
2804 dev->rx_avail = ATM_OC3_PCR;
2805 set_bit(ultra, &dev->flags);
2806 } else {
2807 dev->tx_avail = ((25600000/8)*26)/(27*53);
2808 dev->rx_avail = ((25600000/8)*26)/(27*53);
2809 PRINTD(DBG_WARN, "Buggy ASIC: no TX bus-mastering.");
2810 }
2811
2812
2813 spin_lock_init(&dev->rate_lock);
2814
2815
2816
2817 spin_lock_init(&dev->mem_lock);
2818
2819 init_waitqueue_head(&dev->tx_queue);
2820
2821
2822 dev->atm_dev->ci_range.vpi_bits = vpi_bits;
2823 dev->atm_dev->ci_range.vci_bits = 10-vpi_bits;
2824
2825 init_timer(&dev->housekeeping);
2826 dev->housekeeping.function = do_housekeeping;
2827 dev->housekeeping.data = (unsigned long) dev;
2828 mod_timer(&dev->housekeeping, jiffies);
2829
2830out:
2831 return err;
2832
2833out_free_irq:
2834 free_irq(dev->irq, dev);
2835out_free:
2836 kfree(dev);
2837out_release:
2838 release_region(iobase, HRZ_IO_EXTENT);
2839out_disable:
2840 pci_disable_device(pci_dev);
2841 goto out;
2842}
2843
2844static void __devexit hrz_remove_one(struct pci_dev *pci_dev)
2845{
2846 hrz_dev *dev;
2847
2848 dev = pci_get_drvdata(pci_dev);
2849
2850 PRINTD(DBG_INFO, "closing %p (atm_dev = %p)", dev, dev->atm_dev);
2851 del_timer_sync(&dev->housekeeping);
2852 hrz_reset(dev);
2853 atm_dev_deregister(dev->atm_dev);
2854 free_irq(dev->irq, dev);
2855 release_region(dev->iobase, HRZ_IO_EXTENT);
2856 kfree(dev);
2857
2858 pci_disable_device(pci_dev);
2859}
2860
2861static void __init hrz_check_args (void) {
2862#ifdef DEBUG_HORIZON
2863 PRINTK (KERN_NOTICE, "debug bitmap is %hx", debug &= DBG_MASK);
2864#else
2865 if (debug)
2866 PRINTK (KERN_NOTICE, "no debug support in this image");
2867#endif
2868
2869 if (vpi_bits > HRZ_MAX_VPI)
2870 PRINTK (KERN_ERR, "vpi_bits has been limited to %hu",
2871 vpi_bits = HRZ_MAX_VPI);
2872
2873 if (max_tx_size < 0 || max_tx_size > TX_AAL5_LIMIT)
2874 PRINTK (KERN_NOTICE, "max_tx_size has been limited to %hu",
2875 max_tx_size = TX_AAL5_LIMIT);
2876
2877 if (max_rx_size < 0 || max_rx_size > RX_AAL5_LIMIT)
2878 PRINTK (KERN_NOTICE, "max_rx_size has been limited to %hu",
2879 max_rx_size = RX_AAL5_LIMIT);
2880
2881 return;
2882}
2883
2884MODULE_AUTHOR(maintainer_string);
2885MODULE_DESCRIPTION(description_string);
2886MODULE_LICENSE("GPL");
2887module_param(debug, ushort, 0644);
2888module_param(vpi_bits, ushort, 0);
2889module_param(max_tx_size, int, 0);
2890module_param(max_rx_size, int, 0);
2891module_param(pci_lat, byte, 0);
2892MODULE_PARM_DESC(debug, "debug bitmap, see .h file");
2893MODULE_PARM_DESC(vpi_bits, "number of bits (0..4) to allocate to VPIs");
2894MODULE_PARM_DESC(max_tx_size, "maximum size of TX AAL5 frames");
2895MODULE_PARM_DESC(max_rx_size, "maximum size of RX AAL5 frames");
2896MODULE_PARM_DESC(pci_lat, "PCI latency in bus cycles");
2897
2898static struct pci_device_id hrz_pci_tbl[] = {
2899 { PCI_VENDOR_ID_MADGE, PCI_DEVICE_ID_MADGE_HORIZON, PCI_ANY_ID, PCI_ANY_ID,
2900 0, 0, 0 },
2901 { 0, }
2902};
2903
2904MODULE_DEVICE_TABLE(pci, hrz_pci_tbl);
2905
2906static struct pci_driver hrz_driver = {
2907 .name = "horizon",
2908 .probe = hrz_probe,
2909 .remove = __devexit_p(hrz_remove_one),
2910 .id_table = hrz_pci_tbl,
2911};
2912
2913
2914
2915static int __init hrz_module_init (void) {
2916
2917 if (sizeof(struct MEMMAP) != 128*1024/4) {
2918 PRINTK (KERN_ERR, "Fix struct MEMMAP (is %lu fakewords).",
2919 (unsigned long) sizeof(struct MEMMAP));
2920 return -ENOMEM;
2921 }
2922
2923 show_version();
2924
2925
2926 hrz_check_args();
2927
2928
2929 return pci_register_driver(&hrz_driver);
2930}
2931
2932
2933
2934static void __exit hrz_module_exit (void) {
2935 PRINTD (DBG_FLOW, "cleanup_module");
2936
2937 pci_unregister_driver(&hrz_driver);
2938}
2939
2940module_init(hrz_module_init);
2941module_exit(hrz_module_exit);
2942