-
Notifications
You must be signed in to change notification settings - Fork 0
/
tn7atm.c
2737 lines (2301 loc) · 70.8 KB
/
tn7atm.c
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
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
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/****************************************************************************************
* tn7atm.c
* Linux atm module implementation.
* Zhicheng Tang 01/08/2003
* 2003 (c) Texas Instruments Inc.
*
* 01/17/05 AV Fixed the clock selection based on the DHAL
* version in tn7atm_autoDetectDspBoost().
* 02/16/05 CPH Added Ohio250 clock support.
* 03/19/05 CPH Added Inter-Op DSL phy Control.
* 04/22/05 AV Changed the default value of the SAR Interrupt pacing
* to 4 from 2 for Ohio250 to reflect the change in the
* IPACEP register in the BasePSP. (MR 2344).
* 05/10/05 AV Added support for the proc file for exporting the
* different training modes.(CQ9605).
* 05/23/05 AV Fixing the reported ability for the chip to be able to
* support ADSL2/ADSL2+ and Re-ADSL modes.
* 06/29/05 SAN Added a delay of 10 ms before resing the trimReg register.
* 07/26/05 AV Integrating the NSP changes for the packet detection. These
* changes can be disabled by defining the __NO__VOICE_PATCH__ macro.
* 08/10/05 CPH CQ9776 (partial) Added proc avsar_SNRpsds & avsar_QLNpsds.
* 08/15/05 AV Added two functions to set and get the capability of the chip,
* tn7atm_read_can_support_adsl2 and tn7atm_set_can_support_adsl2.
* 08/24/05 AV Removed disabling of the queue for upstream performance in Annex M.
* 09/01/05 AV Adding Instrumentation code for some of the key functions.(CQ 9907).
* 09/06/05 AV Adding support for VBR-rt and VBR-nrt modes.(CQ9808).
* 09/13/05 AV Relocating the turbodsl code here, as the source code has to be released.
* 09/21/05 AV Renamed the overloaded memcmp and memcpy functions to
* tn7atm_memcmp and tn7atm_memcpy respectively to allow support
* for being compiled directly into the kernel.
* 9/22/05 AV Adding support for the new LED driver in BasePSP 7.4. A new macro TN7DSL_LED_ACTION
* has been used to replace the direct calls to the old LED handler.
* 10/04/05 CPH Added new (1.61v) 7100 support
* 10/07/05 AV/CPH Changed compile time selection of dslhal_api_getQLNpsds() dslhal_api_getSNRpsds()
* and for code size reduction.
* 11/03/05 CPH Added ClearEoc ACK.
* 11/07/05 CPH/ZChang Change 'sbk' to 'skb' in tn7atm_send() TIATM_INST_SUPP. (was typo)
* 11/20/05 CT CQ10076 - Added code to report chipset ID to avsar_ver
* in the proc file system
*
* 12/07/05 AV Added a check in the tn7atm_init() to verify that the dslhal_api_boostDspFrequency()
* was able to boost the frequency of the DSP and SAR.
* 01/25/06 JZ CQ: 10273 Aztech/Singtel oam pvc management issue, new PDSP 0.54
* 01/25/06 JZ CQ: 10275 Add Remote Data Log code. Search ADV_DIAG_STATS in ATM
* driver code and manually turn on it for enabling the feature
* 02/04/06 CPH CQ10280: Add DSL_PHY_CNTL_0 and DSL_PHY_CNTL_1 support
* UR8_MERGE_START CQ10450 Jack Zhang
* 4/04/06 JZ CQ10450: Increase Interrupt pacing to 6 when downstream connection rate is higher than 20Mbps
* UR8_MERGE_END CQ10450*
* UR8_MERGE_START CQ10682 Jack Zhang
* 6/15/06 JZ CQ10682: Display ADSL training messages in ATM driver proc file system
* UR8_MERGE_END CQ10682*
* UR8_MERGE_START CQ10700 Manjula K
* 07/24/06 MK CQ10700: Added counters for reporting packets dropped by ATM Driver/SAR
* UR8_MERGE_END CQ10700
* UR8_MERGE_START CQ10979 Jack Zhang
* 10/4/06 JZ CQ10979: Request for TR-069 Support for RP7.1
* UR8_MERGE_END CQ10979*
* UR8_MERGE_START CQ11057 Jack Zhang
* 11/03/06 JZ CQ11057: Request US PMD test parameters from CO side
* UR8_MERGE_END CQ11057*
* UR8_MERGE_START CQ11813 Hao-Ting Lin
* 06/08/07 Hao-Ting CQ11813: CLI redirect support in Linux
* Add read and init funciton for Cli redirect
* UR8_MERGE_END CQ11813
* 09/18/07 CPH CQ11466 Added EFM Support
*********************************************************************************************/
#include <linux/config.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/atmdev.h>
#include <linux/delay.h>
#include <linux/spinlock.h>
#include <linux/smp_lock.h>
#include <asm/io.h>
#include <asm/mips-boards/prom.h>
#include <linux/proc_fs.h>
#include <linux/string.h>
#include <linux/ctype.h>
#include "dsl_hal_api.h"
#ifdef AR7_EFM
#include "tn7efm.h"
#endif
#include "tn7atm.h"
#include "tn7api.h"
#include "version.h"
#define _SIZE_T_
#include "dsl_hal_register.h"
#ifdef MODULE
MODULE_DESCRIPTION ("Tnetd73xx ATM Device Driver");
MODULE_AUTHOR ("Zhicheng Tang");
#endif
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#define STOP_EMPTY_BUFF 2
#define START_EMPTY_BUFF 3
/* externs */
/*end of externs */
#ifndef TI_STATIC_ALLOCATIONS
#define TI_STATIC_ALLOCATIONS
#endif
#define tn7atm_kfree_skb(x) dev_kfree_skb(x)
#ifdef AR7_EFM
extern void tn7dsl_disable_alarm(void);
extern int tn7efm_proc_channels (char *buf, char **start,
off_t offset, int count, int *eof, void *data);
extern int tn7efm_proc_ctrl_read (char *buf, char **start, off_t offset, int count, int *eof, void *data);
extern int tn7efm_proc_ctrl_write (struct file *fp, const char *buf, unsigned long count, void *data);
extern int tn7efm_proc_info (char *buf, char **start, off_t offset, int count, int *eof, void *data);
extern unsigned int g_efm_proc_ctl;
extern struct net_device *mydev_efm;
extern Tn7AtmPrivate *mypriv;
#endif
extern unsigned int SAR_FREQUNCY;
static int CanSuppADSL2 = TRUE;
static int EnableQoS = FALSE;
/* prototypes */
static int tn7atm_set_can_support_adsl2 (int can);
static int tn7atm_open (struct atm_vcc *vcc, short vpi, int vci);
void tn7atm_close (struct atm_vcc *vcc);
static int tn7atm_ioctl (struct atm_dev *dev, unsigned int cmd, void *arg);
static int tn7atm_send (struct atm_vcc *vcc, struct sk_buff *skb);
static int tn7atm_change_qos (struct atm_vcc *vcc, struct atm_qos *qos,
int flags);
static int tn7atm_detect (void);
static int tn7atm_init (struct atm_dev *dev);
#ifdef AR7_EFM
int tn7atm_irq_request (struct atm_dev *dev);
extern int tn7efm_register (Tn7AtmPrivate * priv);
#else
static int tn7atm_irq_request (struct atm_dev *dev);
#endif
static int tn7atm_proc_version (char *buf, char **start, off_t offset,
int count, int *eof, void *data);
static void tn7atm_exit (void);
static int tn7atm_proc_channels (char *buf, char **start, off_t offset,
int count, int *eof, void *data);
static int tn7atm_proc_private (char *buf, char **start, off_t offset,
int count, int *eof, void *data);
inline static int tn7atm_queue_packet_to_sar (void *vcc1, void *skb1,
int chan);
static int tn7atm_xlate_proc_name (const char *name,
struct proc_dir_entry **ret,
const char **residual);
static int tn7atm_proc_match (int len, const char *name,
struct proc_dir_entry *de);
static int tn7atm_proc_qos_read (char *buf, char **start, off_t offset,
int count, int *eof, void *data);
static int tn7atm_proc_qos_write (struct file *fp, const char *buf,
unsigned long count, void *data);
// [KT]
static int tn7atm_proc_turbodsl_read (char *buf, char **start, off_t offset,
int count, int *eof, void *data);
static int tn7atm_proc_turbodsl_write (struct file *fp, const char *buf,
unsigned long count, void *data);
//CT - Added function to return chipset Id
void tn7atm_get_chipsetId (char *pVerId);
/*
*
* Turbo DSL Implementaion
*
* Zhicheng Tang [email protected]
*
* 2003 (c) Texas Instruments Inc.
*
*/
/* defines and variables */
#define RFC2684_BRIDGED_HDR_SIZE 10
unsigned char LLC_BRIDGED_HEADER_2684[RFC2684_BRIDGED_HDR_SIZE] =
{0xAA, 0xAA, 0x03, 0x00, 0x80, 0xC2, 0x00, 0x07, 0x00, 0x00};
#define RFC2684_ROUTED_HDR_SIZE 6
unsigned char LLC_ROUTED_HEADER_2684[6] ={0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
unsigned long PPP_LLC_HEADER = 0xCF03FEFE;
/* struct definition */
enum
{
AAL5_ENCAP_PPP_LLC,
AAL5_ENCAP_PPP_VCMUX,
AAL5_ENCAP_RFC2684_LLC_BRIDGED,
AAL5_ENCAP_RFC2684_LLC_ROUTED
};
/* Etherent header */
typedef struct _turbodsl_ether_header
{
unsigned char dst_mac_addr[6];
unsigned char src_mac_addr[6];
unsigned short ether_type;
} turbodsl_ether_header_t;
/* Ip header define */
typedef struct _turbodsl_ip_header
{
unsigned short vit;
unsigned short total_length;
unsigned short ip_id;
unsigned char flag; /* bit 0 = 0, bit1 = don't fragment, bit2=more frag */
unsigned char fragment_offset; /* offset include remaining 5 bits above, which make it 13 bits */
unsigned char time_to_live;
unsigned char protocol;
unsigned short checksum;
unsigned int src_ip;
unsigned int dst_ip;
} turbodsl_ip_header_t;
/* Arp packet define */
typedef struct _turbodsl_arp_header
{
unsigned short hardware_type;
unsigned short protocol_type;
unsigned char h_len;
unsigned char p_len;
unsigned short operation ;
unsigned char snd_hw_address[6];
unsigned char snd_pt_address[4];
unsigned char dst_hw_address[6];
unsigned char dst_pt_address[4];
} turbodsl_arp_header_t;
#define FIN_FLAG 1
#define SYN_FLAG 1<<1
#define RST_FLAG 1<<2
#define PSH_FLAG 1<<3
#define ACK_FLAG 1<<4
#define URG_FLAG 1<<5
typedef struct _turbodsl_tcp_header
{
unsigned short src_port;
unsigned short dst_port;
unsigned int seq_num;
unsigned int ack_num;
unsigned char offset; /* only bits 4-7 are for offset */
unsigned char flags; /* bits: 0-FIN, 1-SYN, 2-RST, 3-PSH, 4-ACK, 5-URG */
unsigned short windows;
unsigned short checksum;
unsigned short urgent_ptr;
} turbodsl_tcp_header_t;
/* TurboDSL function declarations. */
__inline__ static int turbodsl_check_aal5_encap_type(unsigned char *pData);
static int turbodsl_check_priority_type(unsigned char *pData);
/* ATM device operations */
struct atm_dev *mydev;
#ifdef CPATM_TASKLET_MODE
void tn7atm_handle_tasklet (unsigned long data);
struct tasklet_struct tn7atm_tasklet;
#endif
#ifdef AR7_EFM
void tn7efm_handle_autoswitch_tasklet (unsigned long data);
extern unsigned int _dsl_PhyControl_0_defined;
extern unsigned int _dsl_PhyControl_0;
#endif
/* *INDENT-OFF* */
static const struct atmdev_ops tn7atm_ops = {
open: tn7atm_open,
close: tn7atm_close,
ioctl: tn7atm_ioctl,
getsockopt: NULL,
setsockopt: NULL,
send: tn7atm_send,
sg_send: NULL,
phy_put: NULL,
phy_get: NULL,
change_qos: tn7atm_change_qos,
};
const char drv_proc_root_folder[] = "avalanche/";
static struct proc_dir_entry *root_proc_dir_entry = NULL;
#define DRV_PROC_MODE 0644
static int proc_root_already_exists = TRUE;
static struct
{
const unsigned char name[32];
int (*read_func) (char* , char **, off_t , int ,int *, void *);
int (*write_func) (struct file *, const char * , unsigned long , void *);
} proc_if[] = {
#ifdef AR7_EFM
#ifdef EFM_DEBUG
{"avsar_efm_channel", tn7efm_proc_channels, NULL},
#endif
{"avsar_efm_info", tn7efm_proc_info, NULL},
{"avsar_efm_ctl", tn7efm_proc_ctrl_read, tn7efm_proc_ctrl_write},
#endif
{"avsar_ver", tn7atm_proc_version, NULL},
{"avsar_channels", tn7atm_proc_channels, NULL},
{"avsar_sarhal_stats", tn7sar_proc_sar_stat, NULL},
{"avsar_oam_ping", tn7sar_proc_oam_ping, NULL},
{"avsar_pvc_table", tn7sar_proc_pvc_table, NULL},
{"avsar_rxsnr0", tn7dsl_proc_snr0, NULL},
{"avsar_rxsnr1", tn7dsl_proc_snr1, NULL},
{"avsar_rxsnr2", tn7dsl_proc_snr2, NULL},
{"clear_eoc_stats", tn7dsl_proc_eoc, NULL},
{"avsar_bit_allocation_table", tn7dsl_proc_bit_allocation, NULL},
{"avsar_dsl_modulation_schemes",tn7dsl_proc_train_mode_export, NULL},
#ifndef NO_ADV_STATS
{"avsar_SNRpsds", tn7dsl_proc_SNRpsds, NULL},
{"avsar_QLNpsds", tn7dsl_proc_QLNpsds, NULL},
// * UR8_MERGE_START CQ10979 Jack Zhang
#ifdef TR69_HLIN_IN
// {"avsar_HLINpsds", tn7dsl_proc_HLINpsds, NULL},
{"avsar_HLINpsds1", tn7dsl_proc_HLINpsds1, NULL},
{"avsar_HLINpsds2", tn7dsl_proc_HLINpsds2, NULL},
{"avsar_HLINpsds3", tn7dsl_proc_HLINpsds3, NULL},
{"avsar_HLINpsds4", tn7dsl_proc_HLINpsds4, NULL},
#endif //TR69_HLIN_IN
// * UR8_MERGE_END CQ10979*
// * UR8_MERGE_START CQ11057 Jack Zhang
#define TR69_PMD_IN
#ifdef TR69_PMD_IN
{"avsar_PMDTestus", tn7dsl_proc_PMDus, NULL},
// {"avsar_PMDTestus1", tn7dsl_proc_PMDus1, NULL},
#endif //TR69_PMD_IN
// * UR8_MERGE_END CQ11057 *
#endif
{"avsar_private", tn7atm_proc_private, NULL},
{"avsar_modem_training", tn7dsl_proc_modem, NULL},
{"avsar_modem_stats", tn7dsl_proc_stats, tn7dsl_proc_write_stats},
#ifdef ADV_DIAG_STATS //CQ10275
//for 2.6 {"avsar_modem_adv_stats", tn7dsl_proc_adv_stats, NULL},
//For 2.4 kernel, due to proc file system size limitation
{"avsar_modem_adv_stats1", tn7dsl_proc_adv_stats1, NULL},
{"avsar_modem_adv_stats2", tn7dsl_proc_adv_stats2, NULL},
{"avsar_modem_adv_stats3", tn7dsl_proc_adv_stats3, NULL},
//UR8_MERGE_START CQ10682 Jack Zhang
{"avsar_modem_dbg_cmsgs", tn7dsl_proc_dbg_cmsgs, NULL},
{"avsar_modem_dbg_rmsgs1", tn7dsl_proc_dbg_rmsgs1, NULL},
{"avsar_modem_dbg_rmsgs2", tn7dsl_proc_dbg_rmsgs2, NULL},
{"avsar_modem_dbg_rmsgs3", tn7dsl_proc_dbg_rmsgs3, NULL},
{"avsar_modem_dbg_rmsgs4", tn7dsl_proc_dbg_rmsgs4, NULL},
// UR8_MERGE_END CQ10682*
#endif //ADV_DIAG_STATS
//UR8_MERGE_START CQ11813 Hao-Ting
#ifdef LINUX_CLI_SUPPORT
{"avsar_dbg_enable", tn7dsl_proc_dbgmsg_read, tn7dsl_proc_dbgmsg_write},
#endif
//UR8_MERGE_END CQ11813
{"avsar_qos_enable", tn7atm_proc_qos_read, tn7atm_proc_qos_write},
#if 1 /* [MS] */
{"avsar_turbodsl", tn7atm_proc_turbodsl_read, tn7atm_proc_turbodsl_write}
#endif
};
/* *INDENT-ON* */
static unsigned int ATM_DSL_INT;
unsigned int def_sar_inter_pace;
int __guDbgLevel = 0;
//[MS]
static int bTurboDsl = 1;
//static spinlock_t chan_init_lock;
#ifdef DEBUG_BUILD
void xadump (unsigned char *buff, int len, int debugLev)
{
int i, j;
if (__guDbgLevel < debugLev)
return;
j = 0;
for (i = 0; i < len; i++)
{
printk ("%02x ", buff[i]);
j++;
if (j == 8)
{
j = 0;
printk ("\n");
}
}
printk ("\n");
}
#endif
/* Optimized memcpy for 32-bit processors. */
void * tn7atm_memcpy(void * dst, void const * src, size_t len)
{
long * plDst = (long *) dst;
long const * plSrc = (long const *) src;
char * pcDst;
char const * pcSrc;
if (!((int)src & 0xFFFFFFFC) && !((int)dst & 0xFFFFFFFC))
{
while (len >= 4)
{
*plDst++ = *plSrc++;
len -= 4;
}
}
pcDst = (char *) plDst;
pcSrc = (char const *) plSrc;
while (len--)
{
*pcDst++ = *pcSrc++;
}
return (dst);
}
/* Optimized memcmp for 32-bit processors. */
int tn7atm_memcmp(void * dst, void const * src, size_t len)
{
long * plDst = (long *) dst;
long const * plSrc = (long const *) src;
char * pcDst;
char const * pcSrc;
if (!((int)src & 0xFFFFFFFC) && !((int)dst & 0xFFFFFFFC))
{
while (len >= 4)
{
if(*plDst++ != *plSrc++)
return -1; /* Not equal*/
len -= 4;
}
}
pcDst = (char *) plDst;
pcSrc = (char const *) plSrc;
while (len--)
{
if(*pcDst++ != *pcSrc++)
return -1; /* Not equal*/
}
/* They are equal */
return 0;
}
/* Moved these definitions here for all modules to use. */
__inline__ void tn7atm_data_invalidate(void *pmem, int size)
{
unsigned int i,Size=(((unsigned int)pmem)&0xf)+size;
if(!pmem)
return;
for (i=0;i<Size;i+=16,pmem+=16)
{
__asm__(" .set mips3 ");
__asm__("cache 17, (%0)" : : "r" (pmem));
__asm__(" .set mips0 ");
}
}
__inline__ void tn7atm_data_writeback(void *pmem, int size)
{
unsigned int i,Size=(((unsigned int)pmem)&0xf)+size;
if(!pmem)
return;
for (i=0;i<Size;i+=16,pmem+=16)
{
__asm__(" .set mips3 ");
__asm__(" cache 25, (%0)" : : "r" (pmem));
__asm__(" .set mips0 ");
}
}
/***************************************************************************
* Turbo DSL Implementaion
*
* Zhicheng Tang [email protected]
*
* 2003 (c) Texas Instruments Inc.
*
* Function: turbodsl_check_aal5_encap_type
* Descripation: Determine AAL5 Encapsulation type
* Input:
* unsigned char *pData, AAL5 Packet buffer pointer
****************************************************************************/
__inline__ static int turbodsl_check_aal5_encap_type(unsigned char *pData)
{
if(!tn7atm_memcmp(pData, LLC_BRIDGED_HEADER_2684, 6))
return AAL5_ENCAP_RFC2684_LLC_BRIDGED;
if(!tn7atm_memcmp(pData, LLC_ROUTED_HEADER_2684, 6))
return AAL5_ENCAP_RFC2684_LLC_ROUTED;
if(!tn7atm_memcmp(pData, (unsigned char *)&PPP_LLC_HEADER, sizeof(PPP_LLC_HEADER)))
return AAL5_ENCAP_PPP_LLC;
return AAL5_ENCAP_PPP_VCMUX;
}
/***************************************************************************
* Turbo DSL Implementaion
*
* Zhicheng Tang [email protected]
*
* 2003 (c) Texas Instruments Inc.
*
* Function: turbodsl_check_priority_type
* Descripation: Determine AAL5 Encapsulation type
* Input:
* unsigned char *pData, AAL5 Packet buffer pointer.
* short vpi, VPI.
* int vci, VCI
****************************************************************************/
static int turbodsl_check_priority_type(unsigned char *pData)
{
/* int encap;*/
unsigned char *pP;
unsigned short etherType;
turbodsl_ip_header_t *pIp;
turbodsl_tcp_header_t *pTcp;
/* unsigned short ip_length;*/
dgprintf(2, "turbodsl_check_priority_type ==>\n");
/*** Viren: Eliminated local VAriable */
/* encap = turbodsl_check_aal5_encap_type(pData); */
pP = pData;
switch(turbodsl_check_aal5_encap_type(pData))
{
case AAL5_ENCAP_RFC2684_LLC_BRIDGED:
pP += RFC2684_BRIDGED_HDR_SIZE; //skip off aal5 encap
pP += 12; //skip of mac address
etherType = *(unsigned short *)pP;
if((etherType != 0x6488) && (etherType != 0x0008))
{
//Not an IP packet
return 1;
}
pP +=2; //skip ether type
if(etherType == 0x6488)
{
#if 1 /* [MS] PPPoE header + PPP header = 8 bytes */
pP += 8;
#else
pP += 6;
#endif
}
break;
case AAL5_ENCAP_RFC2684_LLC_ROUTED:
pP += RFC2684_ROUTED_HDR_SIZE; //skip of encap
pP += 2; //skip ether type
break;
case AAL5_ENCAP_PPP_LLC:
pP += sizeof(PPP_LLC_HEADER);
if((*pP == 0xff) && (*(pP+1) == 0x03)) //ppp hdlc header
pP += 2;
break;
case AAL5_ENCAP_PPP_VCMUX:
if((*pP == 0xff) && (*(pP+1) == 0x03)) //ppp hdlc header
pP += 2;
break;
default:
return 1;
}
pIp = (turbodsl_ip_header_t *)pP;
if(pIp->vit != 0x0045)
{
//Not a IP packet
return 1;
}
if(pIp->protocol != 0x06)
{
//not tcp packet
return 1;
}
pTcp = (turbodsl_tcp_header_t *)(pP + sizeof(turbodsl_ip_header_t));
/*** Viren: not required ***/
/*ip_length = ((pIp->total_length>>8) + (pIp->total_length<<8));*/
#if 1 /* [MS] */
if((pTcp->flags & ACK_FLAG) && (((unsigned short)(pIp->total_length>>8) + (unsigned short)(pIp->total_length<<8)) <=40))
#else
if((pTcp->flags & ACK_FLAG) && (((pIp->total_length>>8) + (pIp->total_length<<8)) <=40))
#endif
return 0;
return 1;
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* Function: int tn7atm_walk_vccs(struct atm_dev *dev, short *vcc, int *vci)
*
* Description: retrieve VPI/VCI for connection
*
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
static int tn7atm_walk_vccs (struct atm_vcc *vcc, short *vpi, int *vci)
{
struct atm_vcc *walk;
/*
* find a free VPI
*/
if (*vpi == ATM_VPI_ANY)
{
for (*vpi = 0, walk = vcc->dev->vccs; walk; walk = walk->next)
{
if ((walk->vci == *vci) && (walk->vpi == *vpi))
{
(*vpi)++;
walk = vcc->dev->vccs;
}
}
}
/*
* find a free VCI
*/
if (*vci == ATM_VCI_ANY)
{
for (*vci = ATM_NOT_RSV_VCI, walk = vcc->dev->vccs; walk;
walk = walk->next)
{
if ((walk->vpi = *vpi) && (walk->vci == *vci))
{
*vci = walk->vci + 1;
walk = vcc->dev->vccs;
}
}
}
return 0;
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* Function: int tn7atm_sar_irq(void)
*
* Description: tnetd73xx SAR interrupt.
*
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
static void tn7atm_sar_irq (int irq, void *voiddev, struct pt_regs *regs)
{
struct atm_dev *atmdev;
Tn7AtmPrivate *priv;
int more;
int retval;
dgprintf (6, "tn7atm_sar_irq\n");
#ifdef TIATM_INST_SUPP
psp_trace (ATM_DRV_SAR_ISR_ENTER);
#endif
atmdev = (struct atm_dev *) voiddev;
priv = (Tn7AtmPrivate *) atmdev->dev_data;
#ifdef CPATM_TASKLET_MODE
tasklet_schedule (&tn7atm_tasklet);
#else
retval = tn7sar_handle_interrupt (atmdev, priv, &more);
#endif
dgprintf (6, "Leaving tn7atm_sar_irq\n");
#ifdef TIATM_INST_SUPP
psp_trace_par (ATM_DRV_SAR_ISR_EXIT, retval);
#endif
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* Function: int tn7atm_dsl_irq(void)
*
* Description: tnetd73xx DSL interrupt.
*
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
static void tn7atm_dsl_irq (int irq, void *voiddev, struct pt_regs *regs)
{
struct atm_dev *atmdev;
Tn7AtmPrivate *priv;
int retval;
dgprintf (4, "tn7atm_dsl_irq\n");
#ifdef TIATM_INST_SUPP
psp_trace (ATM_DRV_DSL_ISR_ENTER);
#endif
atmdev = (struct atm_dev *) voiddev;
priv = (Tn7AtmPrivate *) atmdev->dev_data;
retval = tn7dsl_handle_interrupt ();
dgprintf (4, "Leaving tn7atm_dsl_irq\n");
#ifdef TIATM_INST_SUPP
psp_trace_par (ATM_DRV_DSL_ISR_EXIT, retval);
#endif
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* Function: int tn7atm_irq_request(struct atm_dev *dev)
*
* Description: Initialize Interrupt handler
*
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
#ifdef AR7_EFM
int tn7atm_irq_request (struct atm_dev *dev)
#else
static int __init tn7atm_irq_request (struct atm_dev *dev)
#endif
{
Tn7AtmPrivate *priv;
char *ptr;
dgprintf (4, "tn7atm_irq_request()\n");
priv = (Tn7AtmPrivate *) dev->dev_data;
/*
* Register SAR interrupt
*/
priv->sar_irq = LNXINTNUM (ATM_SAR_INT); /* Interrupt line # */
if (request_irq (priv->sar_irq, tn7atm_sar_irq, SA_INTERRUPT, "SAR ", dev))
printk ("Could not register tn7atm_sar_irq\n");
/*
* interrupt pacing
*/
ptr = prom_getenv ("sar_ipacemax");
if (ptr)
{
def_sar_inter_pace = os_atoi (ptr);
}
avalanche_request_pacing (priv->sar_irq, ATM_SAR_INT_PACING_BLOCK_NUM,
def_sar_inter_pace);
#ifdef AR7_EFM
if (priv->mode_switching)
return 0; // skip following
#endif
/*
* Reigster Receive interrupt A
*/
priv->dsl_irq = LNXINTNUM (ATM_DSL_INT); /* Interrupt line # */
if (request_irq (priv->dsl_irq, tn7atm_dsl_irq, SA_INTERRUPT, "DSL ", dev))
printk ("Could not register tn7atm_dsl_irq\n");
/***** VRB Tasklet Mode ****/
#ifdef CPATM_TASKLET_MODE
tasklet_init (&tn7atm_tasklet, tn7atm_handle_tasklet, (unsigned long) dev);
#endif
/***************/
#ifdef AR7_EFM
tasklet_init (&priv->tn7efm_tasklet, tn7efm_handle_autoswitch_tasklet, (unsigned long) dev);
#endif
return 0;
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* Function: int tn7atm_lut_find(struct atm_vcc *vcc)
*
* Description: find an TX DMA channel
* that matches a vpi/vci pair
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
int tn7atm_lut_find (short vpi, int vci)
{
int i;
Tn7AtmPrivate *priv;
priv = (Tn7AtmPrivate *) mydev->dev_data;
if (vci == 0) // find first vpi channel
{
for (i = 0; i < MAX_DMA_CHAN; i++)
{
if ((priv->lut[i].vpi == vpi))
return i;
}
}
dgprintf (4, "vpi=%d, vci=%d\n", vpi, vci);
for (i = 0; i < MAX_DMA_CHAN; i++)
{
if ((priv->lut[i].vpi == vpi) && (priv->lut[i].vci == vci))
return i;
}
return ATM_NO_DMA_CHAN;
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* Function: int tn7atm_lut_clear(struct atm_vcc *vcc,int chan)
*
* Description: find an TX DMA channel
* that matches a vpi/vci pair
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
static int tn7atm_lut_clear (struct atm_vcc *vcc, int chan)
{
Tn7AtmPrivate *priv;
priv = (Tn7AtmPrivate *) vcc->dev->dev_data;
memset (&priv->lut[chan], 0, sizeof (priv->lut[chan]));
return 0;
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* Function: int tn7atm_walk_lut(void)
*
* Description: find an available TX DMA channel
* and initialize LUT
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
static int tn7atm_walk_lut (Tn7AtmPrivate * priv)
{
int i;
for (i = 0; i < MAX_DMA_CHAN; i++)
{
if (!priv->lut[i].inuse)
{
return i; /* return available dma channel number */
}
}
return ATM_NO_DMA_CHAN; /* no tx dma channels available */
}
static int tn7atm_set_lut (Tn7AtmPrivate * priv, struct atm_vcc *vcc,
int chan)
{
int retval;
if (!priv->lut[chan].inuse)
{
priv->lut[chan].vpi = (int) vcc->vpi;
priv->lut[chan].vci = vcc->vci;
priv->lut[chan].chanid = chan;
priv->lut[chan].inuse = 1; /* claim the channel */
priv->lut[chan].vcc = (void *) vcc;
priv->lut[chan].bClosing = 0;
priv->lut[chan].ready = 0;
priv->lut[chan].tx_total_bufs = TX_BUFFER_NUM;
priv->lut[chan].tx_used_bufs[0] = 0;
priv->lut[chan].tx_used_bufs[1] = 0;
retval = 0;
}
else
retval = -1; /* no tx dma channels available */
return retval;
}
static void str2eaddr (char *pMac, char *pStr)
{
char tmp[3];
int i;
for (i = 0; i < 6; i++)
{
tmp[0] = pStr[i * 3];
tmp[1] = pStr[i * 3 + 1];
tmp[2] = 0;
pMac[i] = os_atoh (tmp);
}
}
static int __init tn7atm_get_ESI (struct atm_dev *dev)
{
int i;
char esi_addr[ESI_LEN] = { 0x00, 0x00, 0x11, 0x22, 0x33, 0x44 };
char *esiaddr_str = NULL;
esiaddr_str = prom_getenv ("macc");
if (!esiaddr_str)
{
// printk("Using default macc address = 00:01:02:03:04:05\n");
esiaddr_str = "00:00:02:03:04:05";
}
str2eaddr (esi_addr, esiaddr_str);
for (i = 0; i < ESI_LEN; i++)
dev->esi[i] = esi_addr[i];
return 0;
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* Function: int tn7atm_open(struct atm_vcc *vcc, short vpi, int vci)
*
* Description: Device operation: open
*
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
/* AV: Temporary fix, till this is imported in the atm.h header file. */
/* Adding support for VBR-rt and VBR-nrt, default VBR is treated as VBR-nrt */
#ifndef ATM_VBR_NRT
#define ATM_VBR_NRT ATM_VBR
#endif
#ifndef ATM_VBR_RT
#define ATM_VBR_RT 5
#endif
int tn7atm_open (struct atm_vcc *vcc, short vpi, int vci)
{
tn7atm_activate_vc_parm_t tn7atm_activate_vc_parm;
int rc;
//int flags;
dgprintf(1, "tn7atm_open()\n");
tn7atm_activate_vc_parm.priv = (Tn7AtmPrivate *)vcc->dev->dev_data;
if(tn7atm_activate_vc_parm.priv==NULL)
{
printk("null priv\n");
return -1;
}
MOD_INC_USE_COUNT;
/* find a free VPI/VCI */
tn7atm_walk_vccs(vcc, &vpi, &vci);
vcc->vpi = vpi;
vcc->vci = vci;
if ((vci == ATM_VCI_UNSPEC) || (vpi == ATM_VCI_UNSPEC))
{
MOD_DEC_USE_COUNT;
return -EBUSY;
}
tn7atm_activate_vc_parm.vpi = vpi;
tn7atm_activate_vc_parm.vci = vci;
if ((vpi == CLEAR_EOC_VPI) && (vci == CLEAR_EOC_VCI))
{
/* always use (max_dma_chan+1) for clear eoc */
tn7atm_activate_vc_parm.chan = EOC_DMA_CHAN;
/* check to see whether clear eoc is opened or not */
if (tn7atm_activate_vc_parm.priv->lut[tn7atm_activate_vc_parm.chan].inuse)