lua: Fixed some cross-platform issues for PPC (and probably other architectures)
[openwrt.git] / target / linux / amazon / files / drivers / char / amazon_mei.c
1 /* ============================================================================
2 * Copyright (C) 2004 -Infineon Technologies AG.
3 *
4 * All rights reserved.
5 * ============================================================================
6 *
7 *============================================================================
8 * Licensed under GNU GPL v2
9 * ============================================================================
10 */
11
12
13 /* ===========================================================================
14 *
15 * File Name: amazon_mei.c
16 * Author : Ou Ke
17 *
18 * ===========================================================================
19 *
20 * Project: Amazon
21 *
22 * ===========================================================================
23 * Contents:This file implements the MEI driver for Amazon ADSL/ADSL2+
24 * controller.
25 *
26 * ===========================================================================
27 * References:
28 *
29 */
30
31
32 /* ===========================================================================
33 * Revision History:
34 * 12/1/2005 : Ritesh Banerjee
35 * - Create a kernel thread kmibpoll to poll for periodic RFC 2662
36 * and RFC 3440 counters. Removes the need for user space
37 * adsl_mibpoll_daemon and saves atleast 30KB of RAM.
38 *
39 * $Log$
40 * ===========================================================================
41 */
42
43 /*
44 * ===========================================================================
45 * INCLUDE FILES
46 * ===========================================================================
47 */
48 //000002:fchang 2005/6/2 joelin 04/27/2005 for pcm clock
49 //000003:fchang 2005/6/2 Henry added for Amazon-E support
50 //165001:henryhsu 2005/9/6 Modify for adsl firmware version 1.2.1.2.0.1 DATA_LED can't flash.
51 // 509221:tc.chen 2005/09/22 Reset DFE added when MEI_TO_ARC_CS_DONE not cleared by ARC
52 // 603221:tc.chen 2006/03/21 added APIs to support the WEB related parameters for ADSL Statistics
53
54 #ifndef EXPORT_SYMTAB
55 #define EXPORT_SYMTAB
56 #endif
57 #define AMAZON_MEI_MIB_RFC3440
58
59 #include <linux/config.h>
60 #include <linux/kernel.h>
61 #include <linux/module.h>
62 #include <linux/version.h>
63 #include <linux/types.h>
64 #include <linux/fs.h>
65 #include <linux/mm.h>
66 #include <linux/errno.h>
67 #include <linux/interrupt.h>
68 #include <linux/netdevice.h>
69 #include <linux/etherdevice.h>
70 #include <asm/irq.h>
71 #include <asm/segment.h>
72 #include <asm/semaphore.h>
73 #include <linux/init.h>
74 #include <linux/ioport.h>
75 #include <asm/uaccess.h>
76 #include <linux/proc_fs.h>
77 #include <asm/io.h>
78 #include <linux/vmalloc.h>
79 #include <linux/delay.h>
80 #include <linux/poll.h>
81 #include <linux/list.h>
82 #include <linux/time.h>
83
84 #include <asm/amazon/amazon.h>
85 #include <asm/irq.h>
86 #include <asm/amazon/irq.h>
87 #include <asm/amazon/amazon_mei.h>
88 #include <asm/amazon/amazon_mei_app.h>
89 #include <asm/amazon/amazon_mei_ioctl.h>
90 #include <asm/amazon/amazon_mei_app_ioctl.h>
91
92 #define SET_BIT(reg, mask) reg |= (mask)
93 #define CLEAR_BIT(reg, mask) reg &= (~mask)
94 #define CLEAR_BITS(reg, mask) CLEAR_BIT(reg, mask)
95 #define SET_BITS(reg, mask) SET_BIT(reg, mask)
96 #define SET_BITFIELD(reg, mask, off, val) {reg &= (~mask); reg |= (val << off);}
97
98 extern void mask_and_ack_amazon_irq(unsigned int irq_nr);
99
100 #ifdef AMAZON_CHECK_LINK
101 //amazon_tpe.c
102 extern int (*adsl_link_notify)(int);
103 #endif //AMAZON_CHECK_LINK
104
105 // for ARC memory access
106 #define WHILE_DELAY 20000
107 #define AMAZON_DMA_DEBUG_MUTEX
108
109
110 //TODO
111 #undef DFE_LOOPBACK
112 #define ARC_READY_ACK
113
114 static amazon_mei_mib * current_intvl;
115 static struct list_head interval_list;
116 static amazon_mei_mib * mei_mib;
117
118 static int reboot_firsttime=1;//000002:fchang
119
120 //PCM
121 #define PCM_CHANNEL_NUM 2 //1 rx, 1 tx
122 static pcm_data_struct pcm_data[PCM_CHANNEL_NUM]__attribute__ ((aligned(4))); //0=tx0, 1=rx0, 2=tx1, 3=rx1
123 static u32 pcm_start_addr;
124 //#define PCM_HRT_TIME_HZ 4000 //?us
125 #define PCM_ACCESS_DEBUG
126 static int irqtimes=0;
127 #undef DATA_LED_ON_MODE
128 #define ADSL_LED_SUPPORT //joelin for adsl led
129 #ifdef ADSL_LED_SUPPORT
130 static int firmware_support_led=0; //joelin version check for adsl led
131 static int stop_led_module=0; //wakeup and clean led module
132 static int led_support_check=0; //1.1.2.7.1.1
133 #endif //ADSL_LED_SUPPORT
134 #define IFX_DYING_GASP
135 #ifdef IFX_DYING_GASP
136 static wait_queue_head_t wait_queue_dying_gasp; //dying gasp
137 //struct tq_struct dying_gasp_task; //dying gasp
138 static wait_queue_head_t wait_queue_uas_poll; //joelin 04/16/2005
139 static u16 unavailable_seconds=0; //joelin 04/16/2005
140 static meidebug lop_debugwr; //dying gasp
141 #endif //IFX_DYING_GASP
142 static int dbg_int=0;
143 //#define DEBUG_ACCESS_DELAY for(dbg_int=0;dbg_int<100;dbg_int++){;}
144 #define DEBUG_ACCESS_DELAY
145 static u8 sampledata[512];
146 static int firsttime[PCM_CHANNEL_NUM]={0,1};
147 static int num_cmp[PCM_CHANNEL_NUM]={0,0};
148 static int pcm_start_loc[PCM_CHANNEL_NUM]={0,0};
149
150 // for clearEoC
151 //#define MEI_CLREOC_BUFF_SIZE 512 //double the receive fifo size, bytes
152 //static u8 clreoc[MEI_CLREOC_BUFF_SIZE]__attribute__ ((aligned(4))); //buffer to hold clearEoC data in bytes
153 #undef AMAZON_CLEAR_EOC
154 #ifdef AMAZON_CLEAR_EOC
155 extern void ifx_push_eoc(struct sk_buff * pkt);
156 #endif
157 static int meiResetArc(void);
158 #define IFX_POP_EOC_DONE 0
159 #define IFX_POP_EOC_FAIL -1
160 static struct list_head clreoc_list;
161 static amazon_clreoc_pkt * clreoc_pkt;
162 #define CLREOC_BUFF_SIZE 12 //number of clreoc commands being buffered
163 //static int clreoc_wr=0;
164 //static int clreoc_rd=0; //used to control clreoc circular buffer
165 static wait_queue_head_t wait_queue_clreoc;
166 #ifdef ADSL_LED_SUPPORT
167 static wait_queue_head_t wait_queue_led; //adsl led
168 static wait_queue_head_t wait_queue_led_polling;// adsl led
169 struct tq_struct led_task; // adsl led
170 static DECLARE_TASK_QUEUE(tq_ifx_led); // task
171 int adsl_led_flash_task(void *ptr); // adsl led
172 #endif //ADSL_LED_SUPPORT
173 static void * clreoc_command_pkt=NULL;
174 static int clreoc_max_tx_len=0;
175
176 // 603221:tc.chen start
177 #define ME_HDLC_IDLE 0
178 #define ME_HDLC_INVALID_MSG 1
179 #define ME_HDLC_MSG_QUEUED 2
180 #define ME_HDLC_MSG_SENT 3
181 #define ME_HDLC_RESP_RCVD 4
182 #define ME_HDLC_RESP_TIMEOUT 5
183 #define ME_HDLC_RX_BUF_OVERFLOW 6
184 #define ME_HDLC_UNRESOLVED 1
185 #define ME_HDLC_RESOLVED 2
186 // 603221:tc.chen end
187
188 #ifdef LOCK_RETRY
189 static int reboot_lock=0;
190 #endif
191
192 static mib_previous_read mib_pread={0,0,0,0,0,0,0,0,0,0,0,0};
193 static mib_flags_pretime mib_pflagtime;// initialized when module loaded
194
195 static u32 ATUC_PERF_LOFS=0;
196 static u32 ATUC_PERF_LOSS=0;
197 static u32 ATUC_PERF_ESS=0;
198 static u32 ATUC_PERF_INITS=0;
199 static u32 ATUR_PERF_LOFS=0;
200 static u32 ATUR_PERF_LOSS=0;
201 static u32 ATUR_PERF_LPR=0;
202 static u32 ATUR_PERF_ESS=0;
203 static u32 ATUR_CHAN_RECV_BLK=0;
204 static u32 ATUR_CHAN_TX_BLK=0;
205 static u32 ATUR_CHAN_CORR_BLK=0;
206 static u32 ATUR_CHAN_UNCORR_BLK=0;
207 //RFC-3440
208 static u32 ATUC_PERF_STAT_FASTR=0;
209 static u32 ATUC_PERF_STAT_FAILED_FASTR=0;
210 static u32 ATUC_PERF_STAT_SESL=0;
211 static u32 ATUC_PERF_STAT_UASL=0;
212 static u32 ATUR_PERF_STAT_SESL=0;
213 static u32 ATUR_PERF_STAT_UASL=0;
214
215 static adslChanPrevTxRate PrevTxRate={0,0};
216 static adslPhysCurrStatus CurrStatus={0,0};
217 static ChanType chantype={0,0};
218 static adslLineAlarmConfProfileEntry AlarmConfProfile={"No Name\0",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1};
219 // 603221:tc.chen start
220 static adslFarEndPerfStats FarendStatsData;
221 struct timeval FarendData_acquire_time={0};
222 static u32 adsl_mode,adsl_mode_extend; // adsl mode : adsl/ 2/ 2+
223 static adslInitStats AdslInitStatsData;
224 //603221:tc.chen end
225 static u32 loop_diagnostics_mode=0;
226 static wait_queue_head_t wait_queue_loop_diagnostic;
227 #ifdef AMAZON_MEI_MIB_RFC3440
228 static adslLineAlarmConfProfileExtEntry AlarmConfProfileExt={"No Name\0",0,0,0,0,0,0};
229 #endif
230
231 static int showtime=0;
232 static int loop_diagnostics_completed=0;
233 //////////////////////////////////////////////////////////////////////////////////
234 static int phy_mei_net_init(struct net_device * dev);
235 static int interleave_mei_net_init(struct net_device * dev);
236 static int fast_mei_net_init(struct net_device * dev);
237 static struct net_device_stats * phy_mei_net_get_stats(struct net_device * dev);
238 static struct net_device_stats * interleave_mei_net_get_stats(struct net_device * dev);
239 static struct net_device_stats * fast_mei_net_get_stats(struct net_device * dev);
240
241 typedef struct mei_priv{
242 struct net_device_stats stats;
243 }mei_priv;
244
245 static struct net_device phy_mei_net = { init: phy_mei_net_init, name: "MEI_PHY"};
246 static struct net_device interleave_mei_net = { init: interleave_mei_net_init, name: "MEI_INTL"};
247 static struct net_device fast_mei_net = { init: fast_mei_net_init, name: "MEI_FAST"};
248 ///////////////////////////////////////////////////////////////////////////////////
249
250 static int major=AMAZON_MEI_MAJOR;
251
252 static struct semaphore mei_sema;
253
254 // Mei to ARC CMV count, reply count, ARC Indicator count
255 static int indicator_count=0;
256 static int cmv_count=0;
257 static int reply_count=0;
258 static u16 Recent_indicator[MSG_LENGTH];
259
260 // Used in interrupt handler as flags
261 static int arcmsgav=0;
262 static int cmv_reply=0;
263 static int cmv_waiting=0;
264
265 #define PROC_ITEMS 8
266
267 long mei_debug_mode = 0; //509221:tc.chen for adsl firmware debug
268
269 // to wait for arc cmv reply, sleep on wait_queue_arcmsgav;
270 static wait_queue_head_t wait_queue_arcmsgav;
271 static wait_queue_head_t wait_queue_codeswap;
272 static wait_queue_head_t wait_queue_mibdaemon;
273 static wait_queue_head_t wait_queue_reboot;
274 static u32 * image_buffer=NULL; // holding adsl firmware image
275 static u16 RxMessage[MSG_LENGTH]__attribute__ ((aligned(4)));
276 static u16 TxMessage[MSG_LENGTH]__attribute__ ((aligned(4)));
277 static u32 * mei_arc_swap_buff=NULL; // holding swap pages
278 static ARC_IMG_HDR * img_hdr;
279 static int reboot_flag;
280
281 #ifdef DFE_LOOPBACK
282 #include "arc_pm.h"
283 #endif
284
285
286 ///////////////// net device ///////////////////////////////////////////////////
287 static int phy_mei_net_init(struct net_device * dev)
288 {
289 //ether_setup(dev);
290 dev->get_stats = phy_mei_net_get_stats;
291 dev->ip_ptr = NULL;
292 dev->type = 94;
293
294 // dev->mtu=12345;
295 dev->flags=IFF_UP;
296
297 dev->priv = kmalloc(sizeof(struct mei_priv), GFP_KERNEL);
298 if(dev->priv == NULL)
299 return -ENOMEM;
300 memset(dev->priv, 0, sizeof(struct mei_priv));
301 return 0;
302 }
303
304 static int interleave_mei_net_init(struct net_device * dev)
305 {
306 //ether_setup(dev);
307 dev->get_stats = interleave_mei_net_get_stats;
308 dev->ip_ptr = NULL;
309 dev->type = 124;
310 dev->flags=IFF_UP;
311 dev->priv = kmalloc(sizeof(struct mei_priv), GFP_KERNEL);
312 if(dev->priv == NULL)
313 return -ENOMEM;
314 memset(dev->priv, 0, sizeof(struct mei_priv));
315 return 0;
316 }
317
318 static int fast_mei_net_init(struct net_device * dev)
319 {
320 //ether_setup(dev);
321 dev->get_stats = fast_mei_net_get_stats;
322 dev->ip_ptr = NULL;
323 dev->type = 125;
324 dev->flags=IFF_UP;
325 dev->priv = kmalloc(sizeof(struct mei_priv), GFP_KERNEL);
326 if(dev->priv == NULL)
327 return -ENOMEM;
328 memset(dev->priv, 0, sizeof(struct mei_priv));
329 return 0;
330 }
331
332 static struct net_device_stats * phy_mei_net_get_stats(struct net_device * dev)
333 {
334 struct mei_priv * priv;
335 priv = (struct mei_priv *)dev->priv;
336 // update statistics
337 (priv->stats).rx_packets = ATUR_CHAN_RECV_BLK;
338 (priv->stats).tx_packets = ATUR_CHAN_TX_BLK;
339 (priv->stats).rx_errors = ATUR_CHAN_CORR_BLK + ATUR_CHAN_UNCORR_BLK;
340 (priv->stats).rx_dropped = ATUR_CHAN_UNCORR_BLK;
341
342 return &(priv->stats);
343 }
344
345 static struct net_device_stats * interleave_mei_net_get_stats(struct net_device * dev)
346 {
347 struct mei_priv * priv;
348 priv = (struct mei_priv *)dev->priv;
349 // update statistics
350 (priv->stats).rx_packets = ATUR_CHAN_RECV_BLK;
351 (priv->stats).tx_packets = ATUR_CHAN_TX_BLK;
352 (priv->stats).rx_errors = ATUR_CHAN_CORR_BLK + ATUR_CHAN_UNCORR_BLK;
353 (priv->stats).rx_dropped = ATUR_CHAN_UNCORR_BLK;
354
355 return &(priv->stats);
356 }
357
358 static struct net_device_stats * fast_mei_net_get_stats(struct net_device * dev)
359 {
360 struct mei_priv * priv;
361 priv = (struct mei_priv *)dev->priv;
362 // update statistics
363 (priv->stats).rx_packets = ATUR_CHAN_RECV_BLK;
364 (priv->stats).tx_packets = ATUR_CHAN_TX_BLK;
365 (priv->stats).rx_errors = ATUR_CHAN_CORR_BLK + ATUR_CHAN_UNCORR_BLK;
366 (priv->stats).rx_dropped = ATUR_CHAN_UNCORR_BLK;
367
368 return &(priv->stats);
369 }
370 ///////////////// mei access Rd/Wr methods ///////////////////////////////////////////////////
371 void meiLongwordWrite(u32 ul_address, u32 ul_data)
372 {
373 *((volatile u32 *)ul_address) = ul_data;
374 asm("SYNC");
375 return;
376 } // end of "meiLongwordWrite(..."
377
378 void meiLongwordRead(u32 ul_address, u32 *pul_data)
379 {
380 *pul_data = *((volatile u32 *)ul_address);
381 asm("SYNC");
382 return;
383 } // end of "meiLongwordRead(..."
384
385 MEI_ERROR meiDMAWrite(u32 destaddr, u32 *databuff, u32 databuffsize)
386 {
387 u32 *p = databuff;
388 u32 temp;
389 u32 flags;
390
391 if( destaddr & 3)
392 return MEI_FAILURE;
393
394 #ifdef AMAZON_DMA_DEBUG_MUTEX
395 save_flags(flags);
396 cli();
397 #endif
398
399
400 // Set the write transfer address
401 meiLongwordWrite(MEI_XFR_ADDR, destaddr);
402
403 // Write the data pushed across DMA
404 while (databuffsize--)
405 {
406 temp = *p;
407 if(databuff==(u32 *)TxMessage) // swap half word
408 temp = ((temp & 0xffff)<<16) + ((temp & 0xffff0000)>>16);
409 meiLongwordWrite(MEI_DATA_XFR, temp);
410 p++;
411 } // end of "while(..."
412
413 #ifdef AMAZON_DMA_DEBUG_MUTEX
414 restore_flags(flags);
415 #endif
416
417 return MEI_SUCCESS;
418
419 } // end of "meiDMAWrite(..."
420
421 MEI_ERROR meiDMAWrite_16(u32 destaddr, u32 *databuff, u32 databuffsize)
422 {
423 u32 *p = databuff;
424 u32 temp;
425 u32 flags;
426
427 if( destaddr & 3)
428 return MEI_FAILURE;
429
430 #ifdef AMAZON_DMA_DEBUG_MUTEX
431 save_flags(flags);
432 cli();
433 #endif
434
435
436 // Set the write transfer address
437 meiLongwordWrite(MEI_XFR_ADDR, destaddr);
438
439 // Write the data pushed across DMA
440 while (databuffsize--)
441 {
442 temp = *p;
443 temp = ((temp & 0xffff)<<16) + ((temp & 0xffff0000)>>16);//swap half word
444 meiLongwordWrite(MEI_DATA_XFR, temp);
445 p++;
446 } // end of "while(..."
447
448 #ifdef AMAZON_DMA_DEBUG_MUTEX
449 restore_flags(flags);
450 #endif
451
452 return MEI_SUCCESS;
453
454 } // end of "meiDMAWrite_16(..."
455
456 MEI_ERROR meiDMAWrite_8(u32 destaddr, u32 *databuff, u32 databuffsize)
457 {
458 u32 *p = databuff;
459 u32 temp;
460 u32 flags;
461
462 if( destaddr & 3)
463 return MEI_FAILURE;
464
465 #ifdef AMAZON_DMA_DEBUG_MUTEX
466 save_flags(flags);
467 cli();
468 #endif
469
470
471 // Set the write transfer address
472 meiLongwordWrite(MEI_XFR_ADDR, destaddr);
473
474 // Write the data pushed across DMA
475 while (databuffsize--)
476 {
477 temp = *p;
478 temp = ((temp & 0xff)<<24) + ((temp & 0xff00)<<8)+ ((temp & 0xff0000)>>8)+ ((temp & 0xff000000)>>24);//swap byte
479 meiLongwordWrite(MEI_DATA_XFR, temp);
480 p++;
481 } // end of "while(..."
482
483 #ifdef AMAZON_DMA_DEBUG_MUTEX
484 restore_flags(flags);
485 #endif
486
487 return MEI_SUCCESS;
488
489 } // end of "meiDMAWrite_8(..."
490
491 MEI_ERROR meiDMARead(u32 srcaddr, u32 *databuff, u32 databuffsize)
492 {
493 u32 *p = databuff;
494 u32 temp;
495 u32 flags;
496
497 if( srcaddr & 3)
498 return MEI_FAILURE;
499
500 #ifdef AMAZON_DMA_DEBUG_MUTEX
501 save_flags(flags);
502 cli();
503 #endif
504
505
506 // Set the read transfer address
507 meiLongwordWrite(MEI_XFR_ADDR, srcaddr);
508
509 // Read the data popped across DMA
510 while (databuffsize--)
511 {
512 meiLongwordRead(MEI_DATA_XFR, &temp);
513 if(databuff==(u32 *)RxMessage) // swap half word
514 temp = ((temp & 0xffff)<<16) + ((temp & 0xffff0000)>>16);
515 *p=temp;
516 p++;
517 } // end of "while(..."
518
519 #ifdef AMAZON_DMA_DEBUG_MUTEX
520 restore_flags(flags);
521 #endif
522
523 return MEI_SUCCESS;
524
525 } // end of "meiDMARead(..."
526
527 MEI_ERROR meiDMARead_16(u32 srcaddr, u32 *databuff, u32 databuffsize)
528 {
529 u32 *p = databuff;
530 u32 temp;
531 u32 flags;
532
533 if( srcaddr & 3)
534 return MEI_FAILURE;
535
536 #ifdef AMAZON_DMA_DEBUG_MUTEX
537 save_flags(flags);
538 cli();
539 #endif
540
541
542 // Set the read transfer address
543 meiLongwordWrite(MEI_XFR_ADDR, srcaddr);
544
545 // Read the data popped across DMA
546 while (databuffsize--)
547 {
548 meiLongwordRead(MEI_DATA_XFR, &temp);
549 temp = ((temp & 0xffff)<<16) + ((temp & 0xffff0000)>>16);
550 *p=temp;
551 p++;
552 } // end of "while(..."
553
554 #ifdef AMAZON_DMA_DEBUG_MUTEX
555 restore_flags(flags);
556 #endif
557
558 return MEI_SUCCESS;
559
560 } // end of "meiDMARead_16(..."
561
562 MEI_ERROR meiDMARead_8(u32 srcaddr, u32 *databuff, u32 databuffsize)
563 {
564 u32 *p = databuff;
565 u32 temp;
566 u32 flags;
567
568 if( srcaddr & 3)
569 return MEI_FAILURE;
570
571 #ifdef AMAZON_DMA_DEBUG_MUTEX
572 save_flags(flags);
573 cli();
574 #endif
575
576
577 // Set the read transfer address
578 meiLongwordWrite(MEI_XFR_ADDR, srcaddr);
579
580 // Read the data popped across DMA
581 while (databuffsize--)
582 {
583 meiLongwordRead(MEI_DATA_XFR, &temp);
584 temp = ((temp & 0xff)<<24) + ((temp & 0xff00)<<8)+ ((temp & 0xff0000)>>8)+ ((temp & 0xff000000)>>24);//swap byte
585 *p=temp;
586 p++;
587 } // end of "while(..."
588
589 #ifdef AMAZON_DMA_DEBUG_MUTEX
590 restore_flags(flags);
591 #endif
592
593 return MEI_SUCCESS;
594
595 } // end of "meiDMARead_8(..."
596
597 void meiPollForDbgDone(void)
598 {
599 u32 query = 0;
600 int i=0;
601 while (i<WHILE_DELAY)
602 {
603 meiLongwordRead(ARC_TO_MEI_INT, &query);
604 query &= (ARC_TO_MEI_DBG_DONE);
605 if(query)
606 break;
607 i++;
608 if(i==WHILE_DELAY){
609 #ifdef AMAZON_MEI_DEBUG_ON
610 printk("\n\n PollforDbg fail");
611 #endif
612 }
613 DEBUG_ACCESS_DELAY;
614 }
615 meiLongwordWrite(ARC_TO_MEI_INT, ARC_TO_MEI_DBG_DONE); // to clear this interrupt
616 } // end of "meiPollForDbgDone(..."
617
618 MEI_ERROR meiDebugWrite_8(u32 destaddr, u32 *databuff, u32 databuffsize)
619 {
620 u32 i;
621 u32 temp = 0x0;
622 u32 address = 0x0;
623 u32 *buffer = 0x0;
624 u32 flags;
625
626 #ifdef AMAZON_DMA_DEBUG_MUTEX
627 save_flags(flags);
628 cli();
629 #endif
630
631
632 // Open the debug port before DMP memory write
633 meiLongwordRead(MEI_CONTROL, &temp);
634 DEBUG_ACCESS_DELAY;
635 temp |= (HOST_MSTR);
636 meiLongwordWrite(MEI_CONTROL, temp);
637 DEBUG_ACCESS_DELAY;
638 meiLongwordWrite(MEI_DEBUG_DEC, MEI_DEBUG_DEC_DMP1_MASK);
639 DEBUG_ACCESS_DELAY;
640
641 // For the requested length, write the address and write the data
642 address = destaddr;
643 buffer = databuff;
644 for (i=0; i < databuffsize; i++)
645 {
646 meiLongwordWrite(MEI_DEBUG_WAD, address);
647 DEBUG_ACCESS_DELAY;
648 temp=*buffer;
649 temp = ((temp & 0xff)<<24) + ((temp & 0xff00)<<8)+ ((temp & 0xff0000)>>8)+ ((temp & 0xff000000)>>24);//swap byte
650 meiLongwordWrite(MEI_DEBUG_DATA, temp);
651 DEBUG_ACCESS_DELAY;
652 meiPollForDbgDone();
653 address += 4;
654 buffer++;
655 } // end of "for(..."
656
657 // Close the debug port after DMP memory write
658 meiLongwordRead(MEI_CONTROL, &temp);
659 DEBUG_ACCESS_DELAY;
660 temp &= ~(HOST_MSTR);
661 meiLongwordWrite(MEI_CONTROL, temp);
662 DEBUG_ACCESS_DELAY;
663
664 #ifdef AMAZON_DMA_DEBUG_MUTEX
665 restore_flags(flags);
666 #endif
667
668 // Return
669 return MEI_SUCCESS;
670
671 } // end of "meiDebugWrite_8(..."
672
673 MEI_ERROR meiDebugRead_8(u32 srcaddr, u32 *databuff, u32 databuffsize)
674 {
675 u32 i;
676 u32 temp = 0x0;
677 u32 address = 0x0;
678 u32 *buffer = 0x0;
679 u32 flags;
680
681 #ifdef AMAZON_DMA_DEBUG_MUTEX
682 save_flags(flags);
683 cli();
684 #endif
685
686
687 // Open the debug port before DMP memory read
688 meiLongwordRead(MEI_CONTROL, &temp);
689 DEBUG_ACCESS_DELAY;
690 temp |= (HOST_MSTR);
691 meiLongwordWrite(MEI_CONTROL, temp);
692 DEBUG_ACCESS_DELAY;
693 meiLongwordWrite(MEI_DEBUG_DEC, MEI_DEBUG_DEC_DMP2_MASK);
694 DEBUG_ACCESS_DELAY;
695
696 // For the requested length, write the address and read the data
697 address = srcaddr;
698 buffer = databuff;
699 for (i=0; i<databuffsize; i++)
700 {
701 meiLongwordWrite(MEI_DEBUG_RAD, address);
702 DEBUG_ACCESS_DELAY;
703 meiPollForDbgDone();
704 meiLongwordRead(MEI_DEBUG_DATA, &temp);
705 DEBUG_ACCESS_DELAY;
706 temp = ((temp & 0xff)<<24) + ((temp & 0xff00)<<8)+ ((temp & 0xff0000)>>8)+ ((temp & 0xff000000)>>24);//swap byte
707 *buffer=temp;
708 address += 4;
709 buffer++;
710 } // end of "for(..."
711
712 // Close the debug port after DMP memory read
713 meiLongwordRead(MEI_CONTROL, &temp);
714 DEBUG_ACCESS_DELAY;
715 temp &= ~(HOST_MSTR);
716 meiLongwordWrite(MEI_CONTROL, temp);
717 DEBUG_ACCESS_DELAY;
718
719 #ifdef AMAZON_DMA_DEBUG_MUTEX
720 restore_flags(flags);
721 #endif
722
723 // Return
724 return MEI_SUCCESS;
725
726 } // end of "meiDebugRead_8(..."
727
728 MEI_ERROR meiDebugWrite_16(u32 destaddr, u32 *databuff, u32 databuffsize)
729 {
730 u32 i;
731 u32 temp = 0x0;
732 u32 address = 0x0;
733 u32 *buffer = 0x0;
734 u32 flags;
735
736 #ifdef AMAZON_DMA_DEBUG_MUTEX
737 save_flags(flags);
738 cli();
739 #endif
740
741
742 // Open the debug port before DMP memory write
743 meiLongwordRead(MEI_CONTROL, &temp);
744 DEBUG_ACCESS_DELAY;
745 temp |= (HOST_MSTR);
746 meiLongwordWrite(MEI_CONTROL, temp);
747 DEBUG_ACCESS_DELAY;
748 meiLongwordWrite(MEI_DEBUG_DEC, MEI_DEBUG_DEC_DMP1_MASK);
749 DEBUG_ACCESS_DELAY;
750
751 // For the requested length, write the address and write the data
752 address = destaddr;
753 buffer = databuff;
754 for (i=0; i < databuffsize; i++)
755 {
756 meiLongwordWrite(MEI_DEBUG_WAD, address);
757 DEBUG_ACCESS_DELAY;
758 temp=*buffer;
759 temp = ((temp & 0xffff)<<16) + ((temp & 0xffff0000)>>16);//swap half word
760 meiLongwordWrite(MEI_DEBUG_DATA, temp);
761 DEBUG_ACCESS_DELAY;
762 meiPollForDbgDone();
763 address += 4;
764 buffer++;
765 } // end of "for(..."
766
767 // Close the debug port after DMP memory write
768 meiLongwordRead(MEI_CONTROL, &temp);
769 DEBUG_ACCESS_DELAY;
770 temp &= ~(HOST_MSTR);
771 meiLongwordWrite(MEI_CONTROL, temp);
772 DEBUG_ACCESS_DELAY;
773
774 #ifdef AMAZON_DMA_DEBUG_MUTEX
775 restore_flags(flags);
776 #endif
777
778 // Return
779 return MEI_SUCCESS;
780
781 } // end of "meiDebugWrite_16(..."
782
783 MEI_ERROR meiDebugRead_16(u32 srcaddr, u32 *databuff, u32 databuffsize)
784 {
785 u32 i;
786 u32 temp = 0x0;
787 u32 address = 0x0;
788 u32 *buffer = 0x0;
789 u32 flags;
790
791 #ifdef AMAZON_DMA_DEBUG_MUTEX
792 save_flags(flags);
793 cli();
794 #endif
795
796
797 // Open the debug port before DMP memory read
798 meiLongwordRead(MEI_CONTROL, &temp);
799 DEBUG_ACCESS_DELAY;
800 temp |= (HOST_MSTR);
801 meiLongwordWrite(MEI_CONTROL, temp);
802 DEBUG_ACCESS_DELAY;
803 meiLongwordWrite(MEI_DEBUG_DEC, MEI_DEBUG_DEC_DMP2_MASK);
804 DEBUG_ACCESS_DELAY;
805
806 // For the requested length, write the address and read the data
807 address = srcaddr;
808 buffer = databuff;
809 for (i=0; i<databuffsize; i++)
810 {
811 meiLongwordWrite(MEI_DEBUG_RAD, address);
812 DEBUG_ACCESS_DELAY;
813 meiPollForDbgDone();
814 meiLongwordRead(MEI_DEBUG_DATA, &temp);
815 DEBUG_ACCESS_DELAY;
816 temp = ((temp & 0xffff)<<16) + ((temp & 0xffff0000)>>16);//swap half word
817 *buffer=temp;
818 address += 4;
819 buffer++;
820 } // end of "for(..."
821
822 // Close the debug port after DMP memory read
823 meiLongwordRead(MEI_CONTROL, &temp);
824 DEBUG_ACCESS_DELAY;
825 temp &= ~(HOST_MSTR);
826 meiLongwordWrite(MEI_CONTROL, temp);
827 DEBUG_ACCESS_DELAY;
828
829 #ifdef AMAZON_DMA_DEBUG_MUTEX
830 restore_flags(flags);
831 #endif
832
833 // Return
834 return MEI_SUCCESS;
835
836 } // end of "meiDebugRead_16(..."
837
838 MEI_ERROR meiDebugWrite(u32 destaddr, u32 *databuff, u32 databuffsize)
839 {
840 u32 i;
841 u32 temp = 0x0;
842 u32 address = 0x0;
843 u32 *buffer = 0x0;
844 u32 flags;
845
846 #ifdef AMAZON_DMA_DEBUG_MUTEX
847 save_flags(flags);
848 cli();
849 #endif
850
851
852 // Open the debug port before DMP memory write
853 meiLongwordRead(MEI_CONTROL, &temp);
854 DEBUG_ACCESS_DELAY;
855 temp |= (HOST_MSTR);
856 meiLongwordWrite(MEI_CONTROL, temp);
857 DEBUG_ACCESS_DELAY;
858 meiLongwordWrite(MEI_DEBUG_DEC, MEI_DEBUG_DEC_DMP1_MASK);
859 DEBUG_ACCESS_DELAY;
860
861 // For the requested length, write the address and write the data
862 address = destaddr;
863 buffer = databuff;
864 for (i=0; i < databuffsize; i++)
865 {
866 meiLongwordWrite(MEI_DEBUG_WAD, address);
867 DEBUG_ACCESS_DELAY;
868 temp=*buffer;
869 meiLongwordWrite(MEI_DEBUG_DATA, temp);
870 DEBUG_ACCESS_DELAY;
871 meiPollForDbgDone();
872 address += 4;
873 buffer++;
874 } // end of "for(..."
875
876 // Close the debug port after DMP memory write
877 meiLongwordRead(MEI_CONTROL, &temp);
878 DEBUG_ACCESS_DELAY;
879 temp &= ~(HOST_MSTR);
880 meiLongwordWrite(MEI_CONTROL, temp);
881 DEBUG_ACCESS_DELAY;
882
883 #ifdef AMAZON_DMA_DEBUG_MUTEX
884 restore_flags(flags);
885 #endif
886
887 // Return
888 return MEI_SUCCESS;
889
890 } // end of "meiDebugWrite(..."
891
892 MEI_ERROR meiDebugRead(u32 srcaddr, u32 *databuff, u32 databuffsize)
893 {
894 u32 i;
895 u32 temp = 0x0;
896 u32 address = 0x0;
897 u32 *buffer = 0x0;
898 u32 flags;
899
900 #ifdef AMAZON_DMA_DEBUG_MUTEX
901 save_flags(flags);
902 cli();
903 #endif
904
905
906 // Open the debug port before DMP memory read
907 meiLongwordRead(MEI_CONTROL, &temp);
908 DEBUG_ACCESS_DELAY;
909 temp |= (HOST_MSTR);
910 meiLongwordWrite(MEI_CONTROL, temp);
911 DEBUG_ACCESS_DELAY;
912 meiLongwordWrite(MEI_DEBUG_DEC, MEI_DEBUG_DEC_DMP2_MASK);
913 DEBUG_ACCESS_DELAY;
914
915 // For the requested length, write the address and read the data
916 address = srcaddr;
917 buffer = databuff;
918 for (i=0; i<databuffsize; i++)
919 {
920 meiLongwordWrite(MEI_DEBUG_RAD, address);
921 DEBUG_ACCESS_DELAY;
922 meiPollForDbgDone();
923 meiLongwordRead(MEI_DEBUG_DATA, &temp);
924 DEBUG_ACCESS_DELAY;
925 *buffer=temp;
926 address += 4;
927 buffer++;
928 } // end of "for(..."
929
930 // Close the debug port after DMP memory read
931 meiLongwordRead(MEI_CONTROL, &temp);
932 DEBUG_ACCESS_DELAY;
933 temp &= ~(HOST_MSTR);
934 meiLongwordWrite(MEI_CONTROL, temp);
935 DEBUG_ACCESS_DELAY;
936
937 #ifdef AMAZON_DMA_DEBUG_MUTEX
938 restore_flags(flags);
939 #endif
940
941 // Return
942 return MEI_SUCCESS;
943
944 } // end of "meiDebugRead(..."
945 EXPORT_SYMBOL(meiDebugRead);
946
947 void meiMailboxInterruptsDisable(void)
948 {
949 meiLongwordWrite(ARC_TO_MEI_INT_MASK, 0x0);
950 } // end of "meiMailboxInterruptsDisable(..."
951
952 void meiMailboxInterruptsEnable(void)
953 {
954 meiLongwordWrite(ARC_TO_MEI_INT_MASK, MSGAV_EN);
955 } // end of "meiMailboxInterruptsEnable(..."
956
957 MEI_ERROR meiMailboxWrite(u16 *msgsrcbuffer, u16 msgsize)
958 {
959 int i;
960 u32 arc_mailbox_status = 0x0;
961 u32 temp=0;
962 MEI_ERROR meiMailboxError = MEI_SUCCESS;
963
964 // Check arc if mailbox write can be initiated
965 /* meiLongwordRead(MEI_TO_ARC_INT, &arc_mailbox_status);
966 if ((arc_mailbox_status & MEI_TO_ARC_MSGAV))
967 {
968 return MEI_MAILBOX_FULL;
969 }
970 */
971 // Write to mailbox
972 meiMailboxError = meiDMAWrite(MEI_TO_ARC_MAILBOX, (u32*)msgsrcbuffer, msgsize/2);
973 meiMailboxError = meiDMAWrite(MEI_TO_ARC_MAILBOXR, (u32 *)(&temp), 1);
974
975 // Notify arc that mailbox write completed
976 cmv_waiting=1;
977 meiLongwordWrite(MEI_TO_ARC_INT, MEI_TO_ARC_MSGAV);
978
979 i=0;
980 while(i<WHILE_DELAY){ // wait for ARC to clear the bit
981 meiLongwordRead(MEI_TO_ARC_INT, &arc_mailbox_status);
982 if((arc_mailbox_status & MEI_TO_ARC_MSGAV) != MEI_TO_ARC_MSGAV)
983 break;
984 i++;
985 if(i==WHILE_DELAY){
986 #ifdef AMAZON_MEI_DEBUG_ON
987 printk("\n\n MEI_TO_ARC_MSGAV not cleared by ARC");
988 #endif
989 meiMailboxError = MEI_FAILURE;
990 #if 0
991 for(i=0;i<msgsize;i++)
992 printk("\n %8x", (*(msgsrcbuffer+i)));
993 #endif
994 }
995 }
996
997 // Return
998 return meiMailboxError;
999
1000 } // end of "meiMailboxWrite(..."
1001
1002 MEI_ERROR meiMailboxRead(u16 *msgdestbuffer, u16 msgsize)
1003 {
1004 //u32 arc_mailbox_status = 0x0;
1005 //u32 *mei_arc_msgbuff = 0x0;
1006 MEI_ERROR meiMailboxError = MEI_SUCCESS;
1007
1008 /*
1009 // Check arc if mailbox read can be initiated
1010 meiLongwordRead(ARC_TO_MEI_INT, &arc_mailbox_status);
1011 if ((arc_mailbox_status & ARC_TO_MEI_MSGAV) == 0)
1012 {
1013 return MEI_MAILBOX_EMPTY;
1014 } // end of "if(..."
1015 */
1016
1017 // Read from mailbox
1018 meiMailboxError = meiDMARead(ARC_TO_MEI_MAILBOX, (u32*)msgdestbuffer, msgsize/2);
1019
1020 // Notify arc that mailbox read completed
1021 meiLongwordWrite(ARC_TO_MEI_INT, ARC_TO_MEI_MSGAV);
1022
1023 // Return
1024 return meiMailboxError;
1025
1026 } // end of "meiMailboxRead(..."
1027
1028 MEI_ERROR meiHaltArc(void)
1029 {
1030 u32 arc_control_mode = 0x0;
1031 u32 arc_debug_addr = 0x5;
1032 u32 arc_debug_data = 0x0;
1033
1034 // Switch arc control from JTAG mode to MEI mode- write '1' to bit0
1035 meiLongwordRead(MEI_CONTROL, &arc_control_mode);
1036 arc_control_mode |= (HOST_MSTR);
1037 meiLongwordWrite(MEI_CONTROL, arc_control_mode);
1038
1039 // Write arc aux reg access mask (0x0) into debug addr decode reg
1040 meiLongwordWrite(MEI_DEBUG_DEC, MEI_DEBUG_DEC_AUX_MASK);
1041
1042 // Write arc debug reg addr (0x5) into debug read addr reg
1043 meiLongwordWrite(MEI_DEBUG_RAD, arc_debug_addr);
1044 meiPollForDbgDone();
1045
1046 // Read debug data reg and save content
1047 meiLongwordRead(MEI_DEBUG_DATA, &arc_debug_data);
1048
1049 // Write arc debug reg addr (0x5) into debug write addr reg
1050 meiLongwordWrite(MEI_DEBUG_WAD, arc_debug_addr);
1051
1052 // Write debug data reg with content ORd with 0x2 (halt bit set)
1053 arc_debug_data |= (BIT1);
1054 meiLongwordWrite(MEI_DEBUG_DATA, arc_debug_data);
1055 meiPollForDbgDone();
1056
1057 // Switch arc control from MEI mode to JTAG mode- write '0' to bit0
1058 meiLongwordRead(MEI_CONTROL, &arc_control_mode);
1059 arc_control_mode &= ~(HOST_MSTR);
1060 meiLongwordWrite(MEI_CONTROL, arc_control_mode);
1061
1062 // Return
1063 return MEI_SUCCESS;
1064
1065 } // end of "meiHalt(..."
1066
1067 MEI_ERROR meiDownloadBootCode(void)
1068 {
1069 u32 arc_control_mode;
1070 u32 boot_loop;
1071 u32 page_size;
1072 u32 dest_addr;
1073
1074 u32 arc_debug_addr = 0x31F00;
1075 u32 arc_debug_data = 0x10;
1076 u32 temp;
1077 // int i;
1078
1079 //MEI_ERROR meiDMAError = MEI_SUCCESS;
1080
1081 // Disable mask for arc codeswap interrupts
1082 meiMailboxInterruptsDisable();
1083
1084 // Switch arc control from JTAG mode to MEI mode- write '1' to bit0
1085 meiLongwordRead(MEI_CONTROL, &arc_control_mode);
1086 arc_control_mode |= (HOST_MSTR);
1087 meiLongwordWrite(MEI_CONTROL, arc_control_mode);
1088
1089 // Write (0x10) to CRI_CCR0(0x31F00) to enable ac_clk signal
1090 meiLongwordWrite(MEI_DEBUG_DEC, MEI_DEBUG_DEC_DMP1_MASK);
1091 meiLongwordWrite(MEI_DEBUG_RAD, arc_debug_addr);
1092 meiPollForDbgDone();
1093 meiLongwordRead(MEI_DEBUG_DATA, &temp);
1094 temp |=arc_debug_data;
1095
1096 meiLongwordWrite(MEI_DEBUG_WAD, arc_debug_addr);
1097 meiLongwordWrite(MEI_DEBUG_DATA, temp);
1098 meiPollForDbgDone();
1099 //meiLongwordWrite(MEI_DEBUG_DEC, MEI_DEBUG_DEC_AUX_MASK);
1100
1101 // Switch arc control from MEI mode to JTAG mode- write '0' to bit0
1102 meiLongwordRead(MEI_CONTROL, &arc_control_mode);
1103 arc_control_mode &= ~(HOST_MSTR);
1104 meiLongwordWrite(MEI_CONTROL, arc_control_mode);
1105
1106 #ifdef AMAZON_MEI_DEBUG_ON //to test ac_clk setting correctness
1107 meiLongwordRead(MEI_CONTROL, &arc_control_mode);
1108 arc_control_mode |= (HOST_MSTR);
1109 meiLongwordWrite(MEI_CONTROL, arc_control_mode);
1110
1111 meiLongwordWrite(MEI_DEBUG_DEC, MEI_DEBUG_DEC_DMP1_MASK);
1112 meiLongwordWrite(MEI_DEBUG_RAD, arc_debug_addr);
1113 meiPollForDbgDone();
1114 meiLongwordRead(MEI_DEBUG_DATA, &arc_debug_data);
1115
1116 meiLongwordRead(MEI_CONTROL, &arc_control_mode);
1117 arc_control_mode &= ~(HOST_MSTR);
1118 meiLongwordWrite(MEI_CONTROL, arc_control_mode);
1119
1120 // printk("\n\n ac_clk is %8x\n", arc_debug_data);
1121 #endif
1122
1123 /*
1124 ** DMA the boot code page(s)
1125 */
1126 #ifdef AMAZON_MEI_DEBUG_ON
1127 // printk("\n\n start download pages");
1128 #endif
1129 for( boot_loop = 0; boot_loop < img_hdr->count; boot_loop++)
1130 {
1131 if( img_hdr->page[boot_loop].p_size & BOOT_FLAG)
1132 {
1133 page_size = meiGetPage( boot_loop, GET_PROG, MAXSWAPSIZE, mei_arc_swap_buff, &dest_addr);
1134 if( page_size > 0)
1135 {
1136 meiDMAWrite(dest_addr, mei_arc_swap_buff, page_size);
1137 }
1138 }
1139 if( img_hdr->page[boot_loop].d_size & BOOT_FLAG)
1140 {
1141 page_size = meiGetPage( boot_loop, GET_DATA, MAXSWAPSIZE, mei_arc_swap_buff, &dest_addr);
1142 if( page_size > 0)
1143 {
1144 meiDMAWrite( dest_addr, mei_arc_swap_buff, page_size);
1145 }
1146 }
1147 }
1148 #ifdef AMAZON_MEI_DEBUG_ON
1149 // printk("\n\n pages downloaded");
1150 #endif
1151 return MEI_SUCCESS;
1152
1153 } // end of "meiDownloadBootCode(..."
1154
1155 MEI_ERROR meiRunArc(void)
1156 {
1157 u32 arc_control_mode = 0x0;
1158 u32 arc_debug_addr = 0x0;
1159 u32 arc_debug_data = 0x0;
1160
1161 // Switch arc control from JTAG mode to MEI mode- write '1' to bit0
1162 meiLongwordRead(MEI_CONTROL, &arc_control_mode);
1163 arc_control_mode |= (HOST_MSTR);
1164 meiLongwordWrite(MEI_CONTROL, arc_control_mode);
1165
1166 // Write arc aux reg access mask (0x0) into debug addr decode reg
1167 meiLongwordWrite(MEI_DEBUG_DEC, MEI_DEBUG_DEC_AUX_MASK);
1168
1169 // Write arc status aux reg addr (0x0) into debug read addr reg
1170 meiLongwordWrite(MEI_DEBUG_RAD, arc_debug_addr);
1171 meiPollForDbgDone();
1172
1173 // Read debug data reg and save content
1174 meiLongwordRead(MEI_DEBUG_DATA, &arc_debug_data);
1175
1176 // Write arc status aux reg addr (0x0) into debug write addr reg
1177 meiLongwordWrite(MEI_DEBUG_WAD, arc_debug_addr);
1178
1179 // Write debug data reg with content ANDd with 0xFDFFFFFF (halt bit cleared)
1180 arc_debug_data &= ~(BIT25);
1181 meiLongwordWrite(MEI_DEBUG_DATA, arc_debug_data);
1182 meiPollForDbgDone();
1183
1184 // Switch arc control from MEI mode to JTAG mode- write '0' to bit0
1185 meiLongwordRead(MEI_CONTROL, &arc_control_mode);
1186 arc_control_mode &= ~(HOST_MSTR);
1187 meiLongwordWrite(MEI_CONTROL, arc_control_mode);
1188
1189 // Enable mask for arc codeswap interrupts
1190 meiMailboxInterruptsEnable();
1191
1192 // Return
1193 return MEI_SUCCESS;
1194
1195 } // end of "meiActivate(..."
1196
1197 int meiGetPage( u32 Page, u32 data, u32 MaxSize, u32 *Buffer, u32 *Dest)
1198 {
1199 u32 size;
1200 u32 i;
1201 u32 *p;
1202
1203 if( Page > img_hdr->count)
1204 return -2;
1205
1206 /*
1207 ** Get program or data size, depending on "data" flag
1208 */
1209 size = (data == GET_DATA) ? img_hdr->page[ Page].d_size : img_hdr->page[ Page].p_size;
1210
1211 size &= BOOT_FLAG_MASK; // Clear boot bit!
1212 if( size > MaxSize)
1213 return -1;
1214
1215 if( size == 0)
1216 return 0;
1217 /*
1218 ** Get program or data offset, depending on "data" flag
1219 */
1220 i = data ? img_hdr->page[ Page].d_offset : img_hdr->page[ Page].p_offset;
1221
1222 /*
1223 ** Copy data/program to buffer
1224 */
1225
1226 i /= 4; // Adjust offset for byte-to-UINT for array operation
1227
1228 p = (u32 *)img_hdr + i;
1229 for(i = 0; i < size; i++)
1230 Buffer[i] = *p++;
1231 /*
1232 ** Pass back data/program destination address
1233 */
1234 *Dest = data ? img_hdr->page[Page].d_dest : img_hdr->page[Page].p_dest;
1235
1236 return size;
1237 }
1238
1239 MEI_ERROR meiCMV(u16 * request, int reply) // write cmv to arc, if reply needed, wait for reply
1240 {
1241 MEI_ERROR meierror;
1242 wait_queue_t wait;
1243
1244 cmv_reply=reply;
1245
1246 meierror = meiMailboxWrite(request, MSG_LENGTH);
1247
1248 if(meierror != MEI_SUCCESS){
1249 #ifdef AMAZON_MEI_DEBUG_ON
1250 printk("\n\n MailboxWrite Fail.");
1251 #endif
1252 return meierror;
1253 }
1254 else{
1255 cmv_count++;
1256 }
1257
1258 if(cmv_reply == NO_REPLY)
1259 return MEI_SUCCESS;
1260
1261 init_waitqueue_entry(&wait, current);
1262 add_wait_queue(&wait_queue_arcmsgav, &wait);
1263 set_current_state(TASK_INTERRUPTIBLE);
1264 // cmv_waiting=1;
1265
1266 if(arcmsgav==1){
1267 set_current_state(TASK_RUNNING);
1268 remove_wait_queue(&wait_queue_arcmsgav, &wait);
1269 }
1270 else{
1271 schedule_timeout(CMV_TIMEOUT);
1272 remove_wait_queue(&wait_queue_arcmsgav, &wait);
1273 }
1274 if(arcmsgav==0){//CMV_timeout
1275 cmv_waiting=0;
1276 arcmsgav=0;
1277 #ifdef AMAZON_MEI_DEBUG_ON
1278 printk("\nmeiCMV: MEI_MAILBOX_TIMEOUT\n");
1279 #endif
1280 return MEI_MAILBOX_TIMEOUT;
1281 }
1282 else{
1283 arcmsgav=0;
1284 reply_count++;
1285 return MEI_SUCCESS;
1286 }
1287 }
1288
1289 //TODO, for loopback test
1290 #ifdef DFE_LOOPBACK
1291 #define mte_reg_base (0x4800*4+0x20000)
1292
1293 /* Iridia Registers Address Constants */
1294 #define MTE_Reg(r) (int)(mte_reg_base + (r*4))
1295
1296 #define IT_AMODE MTE_Reg(0x0004)
1297
1298
1299 #define OMBOX_BASE 0x15F80
1300 #define IMBOX_BASE 0x15FC0
1301
1302 #define TIMER_DELAY (1024)
1303 #define BC0_BYTES (32)
1304 #define BC1_BYTES (30)
1305 #define NUM_MB (12)
1306 #define TIMEOUT_VALUE 2000
1307
1308 void BFMWait (u32 cycle) {
1309 u32 i;
1310 for (i = 0 ; i< cycle ; i++);
1311 }
1312
1313 void WriteRegLong(u32 addr, u32 data){
1314 //printk("[%8x] <= %8x \n\n", addr, data);
1315 *((volatile u32 *)(addr)) = data;
1316 }
1317
1318 u32 ReadRegLong (u32 addr) {
1319 u32 rd_val;
1320
1321 rd_val = *((volatile u32 *)(addr));
1322 //printk("[%8x] => %8x \n\n", addr, rd_val);
1323 return rd_val;
1324
1325 }
1326
1327 /* This routine writes the mailbox with the data in an input array */
1328 void WriteMbox(u32 *mboxarray,u32 size) {
1329 u32 i;
1330
1331 WriteRegLong(MEI_XFR_ADDR,IMBOX_BASE);
1332 for (i=0;i<size;i++) {
1333 WriteRegLong(MEI_DATA_XFR,*(mboxarray+i));
1334 }
1335 }
1336
1337 /* This routine reads the output mailbox and places the results into an array */
1338 void ReadMbox(u32 *mboxarray,u32 size) {
1339 u32 i;
1340
1341 WriteRegLong(MEI_XFR_ADDR,OMBOX_BASE);
1342 for (i=0;i<size;i++) {
1343 mboxarray[i] = ReadRegLong(MEI_DATA_XFR);
1344 }
1345 }
1346
1347 void MEIWriteARCValue(u32 address, u32 value)
1348 {
1349 u32 i,check = 0;
1350 /* Write address register */
1351 *((volatile u32 *)MEI_DEBUG_WAD) = address;
1352
1353 /* Write data register */
1354 *((volatile u32 *)MEI_DEBUG_DATA) = value;
1355
1356 /* wait until complete - timeout at 40*/
1357 for (i=0;i<40;i++) {
1358 check = *((volatile u32 *)ARC_TO_MEI_INT);
1359 if ((check & 0x20)) break;
1360 //printk("MEIWriteARCValue: check:%8x\n\n", check);
1361 }
1362
1363 /* clear the flag */
1364 *((volatile u32 *)ARC_TO_MEI_INT) = 0x20;
1365
1366 }
1367
1368
1369 void post_mei_init(void)
1370 {
1371 u32 mailbox[NUM_MB];
1372
1373 mailbox[0] = TIMER_DELAY;
1374
1375 /* set bytes per bearer channel */
1376 mailbox[1] = BC0_BYTES;
1377 mailbox[2] = BC1_BYTES;
1378 WriteMbox(mailbox, 3);
1379
1380 WriteRegLong(AAI_ACCESS, 0x00000001);
1381
1382 /* enable ADSL block clock, ac_clk */
1383 WriteRegLong(MEI_CONTROL, 0x01);
1384 WriteRegLong(MEI_DEBUG_DEC, 0x00000001); // select ld/st space
1385 MEIWriteARCValue(0x31F00, 0x00000010); // write CRI_CCR0 to enable ac_clk
1386
1387 /* set the MTE to register start */
1388 MEIWriteARCValue(IT_AMODE, 0xF);
1389 BFMWait(10);
1390 }
1391
1392
1393 int wait_sync(void)
1394 {
1395 u32 mailbox[NUM_MB];
1396 /* wait for ATM sync to be achieved on both BC0 and BC1 */
1397 u32 timeout=0;
1398 ReadMbox(mailbox, 1);
1399 u32 readval = mailbox[0];
1400 while( ((readval & 0xFFFFFFFF) == 0) && (timeout < TIMEOUT_VALUE) ) {
1401 BFMWait(1);
1402 //printk("wait_sync\n\n");
1403 ReadMbox(mailbox, 1);
1404 readval = mailbox[0];
1405 timeout++;
1406 }
1407 if(timeout == TIMEOUT_VALUE)return 0;
1408 else return 1;
1409 }
1410 #endif //DFE_LOOPBACK
1411 //end of TODO, for loopback test
1412
1413 MEI_ERROR meiForceRebootAdslModem(void)
1414 {
1415 #if 0
1416 //#ifdef ARC_READY_ACK
1417 if(down_interruptible(&mei_sema)) //disable CMV access until ARC ready
1418 {
1419 return -ERESTARTSYS;
1420 }
1421 #endif
1422 if(reboot_firsttime==1){//000002:fchang Start
1423 // reset ARC
1424 *((volatile u32 *)0xB0100910) = 0x80; //reset DFE
1425 asm("SYNC");
1426 *((volatile u32 *)0xB0100910) = 0x0;
1427 asm("SYNC");
1428 if((*((volatile u32 *)0xB0100910))!=0x0)
1429 #ifdef AMAZON_MEI_DEBUG_ON
1430 printk("\n reset DFE fail");
1431 #endif
1432
1433 // reset ARC
1434 meiLongwordWrite(MEI_CONTROL, SOFT_RESET);
1435 asm("SYNC");
1436 meiLongwordWrite(MEI_CONTROL, 0);
1437 asm("SYNC");
1438
1439 } //000002:fchang End
1440 #ifdef DFE_LOOPBACK
1441 img_hdr=(ARC_IMG_HDR *)lp_image;
1442 #else
1443 img_hdr=(ARC_IMG_HDR *)image_buffer;
1444 #endif
1445 // printk("\n\n enter haltarc");
1446 meiHaltArc();
1447 // printk("\n\n haltarc done");
1448 //000002:fchang Start
1449 if(reboot_firsttime==0){
1450 printk("\n\n new reboot");
1451 meiResetArc();
1452 meiResetCore();
1453 }
1454 if(reboot_firsttime==1)
1455 meiDownloadBootCode();
1456 else
1457 mei_ioctl((struct inode *)NULL, (struct file *)NULL, AMAZON_MEI_DOWNLOAD, (unsigned long)NULL);
1458
1459 //000002:fchang End
1460 #ifdef AMAZON_MEI_DEBUG_ON
1461 // printk("\n\n Download Done");
1462 #endif
1463
1464 #ifdef DFE_LOOPBACK
1465 post_mei_init();
1466 #endif
1467
1468 // sema_init(&mei_sema, 1);
1469 //up(&mei_sema);
1470
1471 // enable_irq(AMAZON_MEI_INT);
1472
1473 meiRunArc();
1474 //000002:fchang Start
1475 if(reboot_firsttime==0){
1476 meiEnalbeMailboxInt();
1477 }
1478 //000002:fchang End
1479
1480 #ifdef AMAZON_MEI_DEBUG_ON
1481 // printk("\n\n ARC Running");
1482 #endif
1483
1484 #ifdef AMAZON_MEI_DEBUG_ON //to test ac_clk setting correctness
1485 {
1486 u32 arc_control_mode;
1487 u32 arc_debug_addr = 0x31F00;
1488 u32 arc_debug_data = 0x10;
1489 meiLongwordRead(MEI_CONTROL, &arc_control_mode);
1490 arc_control_mode |= (HOST_MSTR);
1491 meiLongwordWrite(MEI_CONTROL, arc_control_mode);
1492
1493 meiLongwordWrite(MEI_DEBUG_DEC, MEI_DEBUG_DEC_DMP1_MASK);
1494 meiLongwordWrite(MEI_DEBUG_RAD, arc_debug_addr);
1495 meiPollForDbgDone();
1496 meiLongwordRead(MEI_DEBUG_DATA, &arc_debug_data);
1497
1498 meiLongwordRead(MEI_CONTROL, &arc_control_mode);
1499 arc_control_mode &= ~(HOST_MSTR);
1500 meiLongwordWrite(MEI_CONTROL, arc_control_mode);
1501
1502 // printk("\n\n ac_clk is %8x\n", arc_debug_data);
1503 }
1504 #endif
1505
1506
1507 #ifdef DFE_LOOPBACK
1508 if (wait_sync() == 0){
1509 printk("ARC fails to run: time out\n\n");
1510 }else{
1511 // printk("ARC is ready\n\n");
1512 }
1513 #endif
1514 if(reboot_firsttime==1) //000002:fchang
1515 reboot_firsttime=0; //000002:fchang
1516
1517 return MEI_SUCCESS;
1518 }
1519
1520 //////////////////// procfs debug ////////////////////////////////////////////////////////
1521 #define MEI_DIRNAME "mei"
1522 static struct proc_dir_entry *meidir;
1523
1524 static ssize_t proc_write(struct file *, const char *, size_t, loff_t *);
1525 static ssize_t proc_read(struct file *, char *, size_t, loff_t *);
1526
1527 static struct file_operations proc_operations = {
1528 read: proc_read,
1529 write: proc_write,
1530 };
1531
1532 typedef struct reg_entry {
1533 int * flag;
1534 char name[30]; // big enough to hold names
1535 char description[100]; // big enough to hold description
1536 unsigned short low_ino;
1537 } reg_entry_t;
1538
1539 static reg_entry_t regs[PROC_ITEMS]; // total items to be monitored by /proc/mei
1540
1541 #define NUM_OF_REG_ENTRY (sizeof(regs)/sizeof(reg_entry_t))
1542
1543 static int proc_read(struct file * file, char * buf, size_t nbytes, loff_t *ppos)
1544 {
1545 int i_ino = (file->f_dentry->d_inode)->i_ino;
1546 char outputbuf[64];
1547 int count=0;
1548 int i;
1549 u32 version=0;
1550 reg_entry_t* current_reg=NULL;
1551
1552 for (i=0;i<NUM_OF_REG_ENTRY;i++) {
1553 if (regs[i].low_ino==i_ino) {
1554 current_reg = &regs[i];
1555 break;
1556 }
1557 }
1558 if (current_reg==NULL)
1559 return -EINVAL;
1560
1561 if (current_reg->flag == (int *) 8){
1562 ///proc/mei/version
1563 //format:
1564 //Firmware version: major.minor.sub_version.int_version.rel_state.spl_appl
1565 //Firmware Date Time Code: date/month min:hour
1566 if (*ppos>0) /* Assume reading completed in previous read*/
1567 return 0; // indicates end of file
1568 if(down_interruptible(&mei_sema))
1569 return -ERESTARTSYS;
1570
1571 //if (indicator_count != 1){
1572 if (indicator_count < 1){
1573 up(&mei_sema);
1574 return -EAGAIN;
1575 }
1576 //major:bits 0-7
1577 //minor:bits 8-15
1578 makeCMV(H2D_CMV_READ, INFO, 54, 0, 1, NULL);
1579 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
1580 #if 0
1581 #ifdef AMAZON_MEI_DEBUG_ON
1582 printk("\n\n WINHOST CMV fail");
1583 #endif
1584 #endif
1585 up(&mei_sema);
1586 return -EIO;
1587 }
1588 version = RxMessage[4];
1589 count = sprintf(outputbuf, "%d.%d.",(version)&0xff,(version>>8)&0xff);
1590
1591 //sub_version:bits 4-7
1592 //int_version:bits 0-3
1593 //spl_appl:bits 8-13
1594 //rel_state:bits 14-15
1595 makeCMV(H2D_CMV_READ, INFO, 54, 1, 1, NULL);
1596 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
1597 #if 0
1598 #ifdef AMAZON_MEI_DEBUG_ON
1599 printk("\n\n WINHOST CMV fail");
1600 #endif
1601 #endif
1602 up(&mei_sema);
1603 return -EFAULT;
1604 }
1605 version =RxMessage[4];
1606 count += sprintf(outputbuf+count, "%d.%d.%d.%d",
1607 (version>>4)&0xf,
1608 version&0xf,
1609 (version>>14)&0x3,
1610 (version>>8)&0x3f);
1611 #ifdef ADSL_LED_SUPPORT
1612 // version check -start for adsl led
1613 if ((((version>>4)&0xf)==2)&&((version&0xf)>=3)&&((version&0xf)<7)) firmware_support_led=1;
1614 else if ((((version>>4)&0xf)==2)&&((version&0xf)>=7)) firmware_support_led=2;
1615 else if (((version>>4)&0xf)>2) firmware_support_led=2;
1616
1617 //165001:henryhsu:20050906:Modify for adsl firmware version 1.2.1.2.0.1 DATA_LED can't flash.
1618 //else firmware_support_led=0;
1619 else firmware_support_led=2;
1620 //165001
1621
1622
1623 // version check -end
1624 #endif
1625 //Date:bits 0-7
1626 //Month:bits 8-15
1627 makeCMV(H2D_CMV_READ, INFO, 55, 0, 1, NULL);
1628 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
1629 #if 0
1630 #ifdef AMAZON_MEI_DEBUG_ON
1631 printk("\n\n WINHOST CMV fail");
1632 #endif
1633 #endif
1634 up(&mei_sema);
1635 return -EIO;
1636 }
1637 version = RxMessage[4];
1638
1639 //Hour:bits 0-7
1640 //Minute:bits 8-15
1641 makeCMV(H2D_CMV_READ, INFO, 55, 1, 1, NULL);
1642 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
1643 #if 0
1644 #ifdef AMAZON_MEI_DEBUG_ON
1645 printk("\n\n WINHOST CMV fail");
1646 #endif
1647 #endif
1648 up(&mei_sema);
1649 return -EFAULT;
1650 }
1651 version += (RxMessage[4]<<16);
1652 count += sprintf(outputbuf+count, " %d/%d %d:%d\n"
1653 ,version&0xff
1654 ,(version>>8)&0xff
1655 ,(version>>25)&0xff
1656 ,(version>>16)&0xff);
1657
1658 up(&mei_sema);
1659
1660 *ppos+=count;
1661 }else if(current_reg->flag != (int *)Recent_indicator){
1662 if (*ppos>0) /* Assume reading completed in previous read*/
1663 return 0; // indicates end of file
1664 count = sprintf(outputbuf, "0x%08X\n\n", *(current_reg->flag));
1665 *ppos+=count;
1666 if (count>nbytes) /* Assume output can be read at one time */
1667 return -EINVAL;
1668 }else{
1669 if((int)(*ppos)/((int)7)==16)
1670 return 0; // indicate end of the message
1671 count = sprintf(outputbuf, "0x%04X\n\n", *(((u16 *)(current_reg->flag))+ (int)(*ppos)/((int)7)));
1672 *ppos+=count;
1673 }
1674 if (copy_to_user(buf, outputbuf, count))
1675 return -EFAULT;
1676 return count;
1677 }
1678
1679 static ssize_t proc_write(struct file * file, const char * buffer, size_t count, loff_t *ppos)
1680 {
1681 int i_ino = (file->f_dentry->d_inode)->i_ino;
1682 reg_entry_t* current_reg=NULL;
1683 int i;
1684 unsigned long newRegValue;
1685 char *endp;
1686
1687 for (i=0;i<NUM_OF_REG_ENTRY;i++) {
1688 if (regs[i].low_ino==i_ino) {
1689 current_reg = &regs[i];
1690 break;
1691 }
1692 }
1693 if ((current_reg==NULL) || (current_reg->flag == (int *)Recent_indicator))
1694 return -EINVAL;
1695
1696 newRegValue = simple_strtoul(buffer,&endp,0);
1697 *(current_reg->flag)=(int)newRegValue;
1698 return (count+endp-buffer);
1699 }
1700 ////////////////makeCMV(Opcode, Group, Address, Index, Size, Data), CMV in u16 TxMessage[MSG_LENGTH]///////////////////////////
1701 void makeCMV(u8 opcode, u8 group, u16 address, u16 index, int size, u16 * data)
1702 {
1703 memset(TxMessage, 0, MSG_LENGTH*2);
1704 TxMessage[0]= (opcode<<4) + (size&0xf);
1705 TxMessage[1]= (((index==0)?0:1)<<7) + (group&0x7f);
1706 TxMessage[2]= address;
1707 TxMessage[3]= index;
1708 if(opcode == H2D_CMV_WRITE)
1709 memcpy(TxMessage+4, data, size*2);
1710 return;
1711 }
1712
1713 ////////////////makeCMV(Opcode, Group, Address, Index, Size, Data), CMV in u16 TxMessage[MSG_LENGTH]///////////////////////////
1714 void makeCMV_local(u8 opcode, u8 group, u16 address, u16 index, int size, u16 * data,u16 *CMVMSG)
1715 {
1716 memset(CMVMSG, 0, MSG_LENGTH*2);
1717 CMVMSG[0]= (opcode<<4) + (size&0xf);
1718 CMVMSG[1]= (((index==0)?0:1)<<7) + (group&0x7f);
1719 CMVMSG[2]= address;
1720 CMVMSG[3]= index;
1721 if(opcode == H2D_CMV_WRITE)
1722 memcpy(CMVMSG+4, data, size*2);
1723 return;
1724 }
1725
1726 //////////////// Driver Structure /////////////////////////////////////////////////////////////////////////////
1727 static ssize_t mei_write(struct file *, const char *, size_t, loff_t *);
1728 static int mei_ioctl(struct inode *, struct file *, unsigned int, unsigned long);
1729
1730 static struct file_operations mei_operations = {
1731 write: mei_write,
1732 ioctl: mei_ioctl,
1733 };
1734
1735
1736 static ssize_t mei_write(struct file * filp, const char * buf, size_t size, loff_t * loff)
1737 {
1738 // printk("\n\n mei_write entered");
1739 // image_buffer = (u32 *)kmalloc(size, GFP_KERNEL);
1740 image_buffer = (u32 *)vmalloc(size);
1741 // printk("\n\n image_buffer kmalloc done");
1742 if(image_buffer == NULL){
1743 #ifdef AMAZON_MEI_DEBUG_ON
1744 // printk("\n\n kmalloc for firmware image fail");
1745 printk("\n\n vmalloc for firmware image fail");
1746 #endif
1747 return -1;
1748 }
1749 copy_from_user((char *)image_buffer, buf, size);
1750 // printk("\n\n copy_from_user done");
1751 return size;
1752 }
1753
1754 ////////// ISR GPTU Timer 6 for high resolution timer /////////////
1755 void amazon_timer6_interrupt_MEI(int irq, void *dev_id, struct pt_regs *regs)
1756 {
1757 int i,j;
1758 u32 temp;
1759 u16 temp16;
1760 u16 rdindex, wrindex;
1761 u16 num_rd=0; //num of byte can be read
1762 u16 bytes_to_wr=0;
1763
1764 // printk("\n\nenter timer\n\n");
1765 irqtimes++;
1766 // printk("\n%d\n",irqtimes);
1767
1768
1769 /*
1770 #ifdef PCM_ACCESS_DEBUG
1771 meiDebugRead_8(0x30f20, &temp, 1);
1772 #else
1773 meiDMARead_8(0x30f20, &temp, 1);
1774 #endif
1775 if((temp&0x4000)!=0){
1776 printk("\nER_ERR");
1777 #ifdef PCM_ACCESS_DEBUG
1778 meiDebugWrite_8(0x30f20, &temp, 1);
1779 #else
1780 meiDMAWrite_8(0x30f20, &temp, 1);
1781 #endif
1782 #ifdef PCM_ACCESS_DEBUG
1783 meiDebugRead_8(0x30f20, &temp, 1);
1784 #else
1785 meiDMARead_8(0x30f20, &temp, 1);
1786 #endif
1787 if((temp&0x4000)!=0)
1788 printk("\nER_ERR not cleared");
1789 }
1790 */
1791
1792 for(i=PCM_CHANNEL_NUM-1;i>=0;i--){// start from last channel, which is rx
1793 #ifdef PCM_ACCESS_DEBUG
1794 meiDebugRead_16(pcm_start_addr+i*16+12, &temp, 1);
1795 #else
1796 meiDMARead_16(pcm_start_addr+i*16+12, &temp, 1);
1797 #endif
1798 wrindex = (u16)((temp & 0xffff0000)>>16);
1799 // printk(" %d",wrindex);
1800 #ifdef PCM_ACCESS_DEBUG
1801 meiDebugRead_16(pcm_start_addr+i*16+8, &temp, 1);
1802 #else
1803 meiDMARead_16(pcm_start_addr+i*16+8, &temp, 1);
1804 #endif
1805 rdindex = (u16)(temp & 0xffff);
1806 // printk(" %d",rdindex);
1807 if(rdindex<=wrindex)
1808 num_rd=((wrindex-rdindex)/4)*4; //read multiply of 4 bytes
1809 else
1810 num_rd=((pcm_data[i].len-(rdindex-wrindex))/4)*4; //read multiply of 4 bytes
1811
1812 if(i%2!=0){//rx channel
1813 pcm_data[i].point=0;
1814 for(j=0;j<num_rd/4;j++){
1815 if(pcm_data[i].finish!=1){
1816 if((rdindex+j*4)>=pcm_data[i].len)
1817 temp16=(rdindex+j*4) - pcm_data[i].len;
1818 else
1819 temp16=rdindex+j*4;
1820 #ifdef PCM_ACCESS_DEBUG
1821 meiDebugRead_8((((u32)(pcm_data[i].LSW))+(((u32)(pcm_data[i].MSW))<<16))+temp16, (u32*)(pcm_data[i].buff+pcm_data[i].point), 1);
1822 #else
1823 meiDMARead_8((((u32)(pcm_data[i].LSW))+(((u32)(pcm_data[i].MSW))<<16))+temp16, (u32*)(pcm_data[i].buff+pcm_data[i].point), 1);
1824 #endif
1825 // printk(" %8x", *((u32*)(pcm_data[i].buff+pcm_data[i].point)));
1826 /* if(pcm_data[i].point==0){
1827 if(pcm_data[i].buff[0]==0xA5){// start of loopback data
1828 pcm_data[i].point+=4;
1829 printk("\nstart receive data");
1830 }
1831 }
1832 else*/
1833 pcm_data[i].point+=4;
1834 /* if(pcm_data[i].point==PCM_BUFF_SIZE){ //finish rx
1835 pcm_data[i].finish=1;
1836 printk("\nchannel[%d] finished", i);
1837 } */
1838 }
1839 }
1840 if(firsttime[i]==1){
1841 for(j=0;j<num_rd;j++){
1842 if(pcm_data[i].buff[j]==0x1){
1843 num_cmp[i]=num_rd-j;
1844 firsttime[i]=0;
1845 break;
1846 }
1847 }
1848 if(memcmp(sampledata+1, pcm_data[i].buff+j, num_cmp[i])!=0)
1849 printk("\n\ndata wrong,1st\n\n");
1850 else
1851 pcm_start_loc[i] = num_cmp[i]+1;
1852 }
1853 else{
1854 if(memcmp(sampledata+pcm_start_loc[i], pcm_data[i].buff, num_rd)!=0)
1855 printk("\n\ndata wrong\n\n");
1856 else{
1857 pcm_start_loc[i]+=num_rd;
1858 if(pcm_start_loc[i]>=256)
1859 pcm_start_loc[i]=pcm_start_loc[i]-256;
1860 }
1861 }
1862
1863 rdindex +=num_rd;
1864 if(rdindex>=pcm_data[i].len)
1865 rdindex=rdindex-pcm_data[i].len;
1866 #ifdef PCM_ACCESS_DEBUG
1867 meiDebugRead_16(pcm_start_addr+i*16+8, &temp, 1);
1868 #else
1869 meiDMARead_16(pcm_start_addr+i*16+8, &temp, 1);
1870 #endif
1871 temp= (temp & 0xffff0000) + rdindex;
1872 #ifdef PCM_ACCESS_DEBUG
1873 meiDebugWrite_16(pcm_start_addr+i*16+8, &temp, 1); // update rdindex
1874 #else
1875 meiDMAWrite_16(pcm_start_addr+i*16+8, &temp, 1); // update rdindex
1876 #endif
1877
1878 bytes_to_wr = num_rd;
1879
1880 // if(bytes_to_wr>0){
1881 // printk(" %d", num_rd);
1882 // printk(" %d", rdindex);
1883 // printk("\n\nrdindex = %d", rdindex);
1884 //}
1885 }
1886 else{ //tx channel
1887 // if((bytes_to_wr + num_rd) < pcm_data[i].len){
1888 for(j=0;j<bytes_to_wr/4;j++){
1889 if(pcm_data[i].finish!=1){
1890 if((wrindex+j*4)>=pcm_data[i].len)
1891 temp16=(wrindex+j*4) - pcm_data[i].len;
1892 else
1893 temp16=wrindex + j*4;
1894 /*
1895 #ifdef PCM_ACCESS_DEBUG
1896 meiDebugWrite_8((((u32)(pcm_data[i].LSW))+(((u32)(pcm_data[i].MSW))<<16))+temp16,(u32*)(pcm_data[i+1].buff+j*4), 1);
1897 #else
1898 meiDMAWrite_8((((u32)(pcm_data[i].LSW))+(((u32)(pcm_data[i].MSW))<<16))+temp16,(u32*)(pcm_data[i+1].buff+j*4), 1);
1899 #endif*/
1900
1901 #ifdef PCM_ACCESS_DEBUG
1902 meiDebugWrite_8((((u32)(pcm_data[i].LSW))+(((u32)(pcm_data[i].MSW))<<16))+temp16,(u32*)(pcm_data[i].buff+pcm_data[i].point), 1);
1903 // meiDebugWrite_8((((u32)(pcm_data[i].LSW))+(((u32)(pcm_data[i].MSW))<<16))+temp16,(u32*)(pcm_data[i].buff), 1);
1904 #else
1905 meiDMAWrite_8((((u32)(pcm_data[i].LSW))+(((u32)(pcm_data[i].MSW))<<16))+temp16,(u32*)(pcm_data[i].buff+pcm_data[i].point), 1);
1906 #endif
1907 pcm_data[i].point+=4;
1908 if(pcm_data[i].point==PCM_BUFF_SIZE){
1909 // pcm_data[i].finish=1;
1910 // printk("\nchannel[%d] finished", i);
1911 pcm_data[i].point=0;
1912 }
1913 }
1914 }
1915 wrindex+=bytes_to_wr;
1916 if(wrindex>=pcm_data[i].len)
1917 wrindex=wrindex-pcm_data[i].len;
1918 #ifdef PCM_ACCESS_DEBUG
1919 meiDebugRead_16(pcm_start_addr+i*16+12, &temp, 1);
1920 #else
1921 meiDMARead_16(pcm_start_addr+i*16+12, &temp, 1);
1922 #endif
1923 temp=(temp&0xffff) + (wrindex<<16);
1924 #ifdef PCM_ACCESS_DEBUG
1925 meiDebugWrite_16(pcm_start_addr+i*16+12, &temp, 1); // update wrindex
1926 #else
1927 meiDMAWrite_16(pcm_start_addr+i*16+12, &temp, 1); // update wrindex
1928 #endif
1929
1930 //if(bytes_to_wr>0){
1931 // printk(" %d", bytes_to_wr);
1932 // printk(" %d", wrindex);
1933 // printk("\n\nwrindex = %d", wrindex);
1934 //}
1935 // }
1936 }
1937 }
1938 return;
1939 }
1940 //000002:fchang Start
1941 static int meiResetArc(void)
1942 {
1943 u32 auxreg0;
1944 u32 auxreg5;
1945 int flshcnt=0;
1946 int flshcnt1=0;
1947 int flshcnt2=0;
1948
1949 meiLongwordWrite(MEI_CONTROL, 1);
1950 meiLongwordWrite(MEI_DEBUG_DEC, 3);
1951 meiLongwordWrite(MEI_DEBUG_WAD, 0x3c);
1952 meiLongwordWrite(MEI_DEBUG_DATA, 0x10);
1953 meiPollForDbgDone();
1954 meiLongwordWrite(MEI_DEBUG_DEC, 0x0);
1955 meiLongwordWrite(MEI_DEBUG_WAD, 0x2);
1956 meiLongwordWrite(MEI_DEBUG_DATA, 0x0);
1957 meiPollForDbgDone();
1958 meiLongwordWrite(MEI_DEBUG_WAD, 0x3);
1959 meiLongwordWrite(MEI_DEBUG_DATA, 0x0);
1960 meiPollForDbgDone();
1961 meiLongwordWrite(MEI_DEBUG_DEC, 0x0);
1962 meiLongwordWrite(MEI_DEBUG_RAD, 0x0);
1963 meiPollForDbgDone();
1964 meiLongwordRead(MEI_DEBUG_DATA, &auxreg0);
1965 auxreg0 = auxreg0 & 0x03ffffff;
1966 meiLongwordWrite(MEI_DEBUG_WAD, 0x0);
1967 meiLongwordWrite(MEI_DEBUG_DATA, auxreg0);
1968 meiPollForDbgDone();
1969 meiLongwordWrite(MEI_DEBUG_WAD, 0x10a);
1970 meiLongwordWrite(MEI_DEBUG_DATA, 0x0);
1971 meiPollForDbgDone();
1972 meiLongwordWrite(MEI_DEBUG_DEC, 0x2);
1973 meiLongwordWrite(MEI_DEBUG_WAD, 0xfffc);
1974 meiLongwordWrite(MEI_DEBUG_DATA, 0x1fffffff);
1975 meiPollForDbgDone();
1976 while(flshcnt<3){
1977 meiLongwordWrite(MEI_DEBUG_DEC, 0x0);
1978 meiLongwordWrite(MEI_DEBUG_RAD, 0x0);
1979 meiPollForDbgDone();
1980 meiLongwordRead(MEI_DEBUG_DATA, &auxreg0);
1981 auxreg0 = auxreg0 & 0xff000000;
1982 auxreg0 = auxreg0 | 0x3fff;
1983 meiLongwordWrite(MEI_DEBUG_WAD, 0x0);
1984 meiLongwordWrite(MEI_DEBUG_DATA, auxreg0);
1985 meiPollForDbgDone();
1986
1987 meiLongwordWrite(MEI_DEBUG_DEC, 0x0);
1988 meiLongwordWrite(MEI_DEBUG_RAD, 0x5);
1989 meiPollForDbgDone();
1990 meiLongwordRead(MEI_DEBUG_DATA, &auxreg5);
1991 auxreg5 = auxreg5 | 0x801;
1992 meiLongwordWrite(MEI_DEBUG_WAD, 0x5);
1993 meiLongwordWrite(MEI_DEBUG_DATA, auxreg5);
1994 meiPollForDbgDone();
1995 meiLongwordWrite(MEI_DEBUG_RAD, 0x0);
1996 meiPollForDbgDone();
1997 meiLongwordRead(MEI_DEBUG_DATA, &auxreg0);
1998 auxreg0 = auxreg0 & 0x00ffffff;
1999 if(auxreg0 == 0x4000)
2000 flshcnt = flshcnt+1;
2001 else{
2002 if(flshcnt == 0)
2003 flshcnt1 = flshcnt1 +1;
2004 else
2005 flshcnt2 = flshcnt2 +1;
2006 }
2007 }
2008
2009 return 1;
2010 }
2011
2012 static int meiResetCore(void)
2013 {
2014 meiLongwordWrite(MEI_CONTROL, 0x1);
2015 meiLongwordWrite(MEI_DEBUG_DEC, 0x2);
2016 meiLongwordWrite(MEI_DEBUG_WAD, 0x31f10);
2017 meiLongwordWrite(MEI_DEBUG_DATA, 0xf);
2018 meiPollForDbgDone();
2019 meiLongwordWrite(MEI_DEBUG_WAD, 0x31f10);
2020 meiLongwordWrite(MEI_DEBUG_DATA, 0x0);
2021 meiPollForDbgDone();
2022 meiLongwordWrite(MEI_DEBUG_WAD, 0x31f00);
2023 meiLongwordWrite(MEI_DEBUG_DATA, 0x55);
2024 meiPollForDbgDone();
2025 return 1;
2026 }
2027
2028 static int meiEnalbeMailboxInt(void)
2029 {
2030 u32 arc2meiintmsk;
2031 meiLongwordRead(ARC_TO_MEI_INT_MASK, &arc2meiintmsk);
2032 arc2meiintmsk = arc2meiintmsk | 0x1;
2033 meiLongwordWrite(ARC_TO_MEI_INT_MASK, arc2meiintmsk);
2034 meiLongwordWrite(MEI_CONTROL, 0x0);
2035 return 1;
2036 }
2037
2038
2039
2040 //000002:fchang End
2041
2042 static int mei_ioctl(struct inode * ino, struct file * fil, unsigned int command, unsigned long lon)
2043 {
2044 int i,k;
2045 u32 boot_loop;
2046 u32 page_size;
2047 u32 dest_addr;
2048 u32 j;
2049 u32 temp;
2050 u32 temp2;
2051 u16 trapsflag=0;
2052 amazon_clreoc_pkt * current_clreoc;
2053 struct timeval time_now;
2054 struct timeval time_fini;
2055 struct list_head * ptr;
2056 amazon_mei_mib * mib_ptr;
2057 // u16 buff[MSG_LENGTH]__attribute__ ((aligned(4)));
2058 structpts pts;
2059 int meierr=MEI_SUCCESS;
2060 u16 data[12]; //used in makeCMV, to pass in payload when CMV set, ignored when CMV read.
2061 meireg regrdwr;
2062 meidebug debugrdwr;
2063 amazon_mei_mib * temp_intvl;
2064 struct sk_buff * eoc_skb;
2065 // 603221:tc.chen start
2066 u16 hdlc_cmd[2];
2067 u16 hdlc_rx_buffer[32];
2068 int hdlc_rx_len=0;
2069 // 603221:tc.chen end
2070
2071 int from_kernel = 0;//joelin
2072 if (ino == (struct inode *)0) from_kernel = 1;//joelin
2073
2074 // printk("\n switch.command = %i\n", command);
2075 switch(command){
2076 case GET_ADSL_LINE_CODE:
2077 pts.adslLineTableEntry_pt = (adslLineTableEntry *)kmalloc(sizeof(adslLineTableEntry), GFP_KERNEL);
2078 copy_from_user((char *)pts.adslLineTableEntry_pt, (char *)lon, sizeof(adslLineTableEntry));
2079 if(IS_FLAG_SET((&(pts.adslLineTableEntry_pt->flags)), LINE_CODE_FLAG)){
2080 pts.adslLineTableEntry_pt->adslLineCode = 2;
2081 }
2082 copy_to_user((char *)lon, (char *)pts.adslLineTableEntry_pt, sizeof(adslLineTableEntry));
2083 kfree(pts.adslLineTableEntry_pt);
2084 break;
2085 #ifdef AMAZON_MEI_MIB_RFC3440
2086 case GET_ADSL_ATUC_LINE_EXT:
2087 if(down_interruptible(&mei_sema))
2088 return -ERESTARTSYS;
2089 pts.adslLineExtTableEntry_pt = (adslLineExtTableEntry *)kmalloc(sizeof(adslLineExtTableEntry), GFP_KERNEL);
2090 copy_from_user((char *)pts.adslLineExtTableEntry_pt, (char *)lon, sizeof(adslLineExtTableEntry));
2091 if(IS_FLAG_SET((&(pts.adslLineExtTableEntry_pt->flags)), ATUC_LINE_TRANS_CAP_FLAG)){
2092 ATUC_LINE_TRANS_CAP_FLAG_MAKECMV;
2093 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
2094 #ifdef AMAZON_MEI_DEBUG_ON
2095 printk("\n\nCMV fail, Group 3 Address 67 Index 0");
2096 #endif
2097 CLR_FLAG((&(pts.adslLineExtTableEntry_pt->flags)), ATUC_LINE_TRANS_CAP_FLAG);
2098 }
2099 else{
2100 memcpy((&(pts.adslLineExtTableEntry_pt->adslLineTransAtucCap)), RxMessage+4, ((RxMessage[0]&0xf)*2));
2101 }
2102 }
2103 if(IS_FLAG_SET((&(pts.adslLineExtTableEntry_pt->flags)), ATUC_LINE_TRANS_CONFIG_FLAG)){
2104 ATUC_LINE_TRANS_CONFIG_FLAG_MAKECMV;
2105 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
2106 #ifdef AMAZON_MEI_DEBUG_ON
2107 printk("\n\nCMV fail, Group 3 Address 67 Index 0");
2108 #endif
2109 CLR_FLAG((&(pts.adslLineExtTableEntry_pt->flags)), ATUC_LINE_TRANS_CONFIG_FLAG);
2110 }
2111 else{
2112 memcpy((&(pts.adslLineExtTableEntry_pt->adslLineTransAtucConfig)), RxMessage+4, ((RxMessage[0]&0xf)*2));
2113 }
2114 }
2115 if(IS_FLAG_SET((&(pts.adslLineExtTableEntry_pt->flags)), ATUC_LINE_TRANS_ACTUAL_FLAG)){
2116 ATUC_LINE_TRANS_ACTUAL_FLAG_MAKECMV;
2117 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
2118 #ifdef AMAZON_MEI_DEBUG_ON
2119 printk("\n\nCMV fail, Group 2 Address 1 Index 0");
2120 #endif
2121 CLR_FLAG((&(pts.adslLineExtTableEntry_pt->flags)), ATUC_LINE_TRANS_ACTUAL_FLAG);
2122 }
2123 else{
2124 memcpy((&(pts.adslLineExtTableEntry_pt->adslLineTransAtucActual)), RxMessage+4, ((RxMessage[0]&0xf)*2));
2125 }
2126 }
2127 if(IS_FLAG_SET((&(pts.adslLineExtTableEntry_pt->flags)), LINE_GLITE_POWER_STATE_FLAG)){ // not supported currently
2128 /*
2129 LINE_GLITE_POWER_STATE_FLAG_MAKECMV;
2130 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
2131 #ifdef AMAZON_MEI_DEBUG_ON
2132 printk("\n\nCMV fail, Group 2 Address 0 Index 0");
2133 #endif
2134 CLR_FLAG((&(pts.adslLineExtTableEntry_pt->flags)), LINE_GLITE_POWER_STATE_FLAG);
2135 }
2136 else{
2137 memcpy((&(pts.adslLineExtTableEntry_pt->adslLineGlitePowerState)), RxMessage+4, ((RxMessage[0]&0xf)*2));
2138 }
2139 */
2140 CLR_FLAG((&(pts.adslLineExtTableEntry_pt->flags)), LINE_GLITE_POWER_STATE_FLAG);
2141 }
2142 copy_to_user((char *)lon, (char *)pts.adslLineExtTableEntry_pt, sizeof(adslLineExtTableEntry));
2143 kfree(pts.adslLineTableEntry_pt);
2144 up(&mei_sema);
2145 break;
2146 #endif
2147
2148 #ifdef AMAZON_MEI_MIB_RFC3440
2149 case SET_ADSL_ATUC_LINE_EXT:
2150 if(down_interruptible(&mei_sema))
2151 return -ERESTARTSYS;
2152 pts.adslLineExtTableEntry_pt = (adslLineExtTableEntry *)kmalloc(sizeof(adslLineExtTableEntry), GFP_KERNEL);
2153 copy_from_user((char *)pts.adslLineExtTableEntry_pt, (char *)lon, sizeof(adslLineExtTableEntry));
2154
2155 //only adslLineTransAtucConfig can be set.
2156 CLR_FLAG((&(pts.adslLineExtTableEntry_pt->flags)), ATUC_LINE_TRANS_CAP_FLAG);
2157 if(IS_FLAG_SET((&(pts.adslLineExtTableEntry_pt->flags)), ATUC_LINE_TRANS_CONFIG_FLAG)){
2158 memcpy(data,(&(pts.adslLineExtTableEntry_pt->adslLineTransAtucConfig)), 2);
2159 ATUC_LINE_TRANS_CONFIG_FLAG_MAKECMV_WR;
2160 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
2161 #ifdef AMAZON_MEI_DEBUG_ON
2162 printk("\n\nCMV fail, Group 3 Address 67 Index 0");
2163 #endif
2164 CLR_FLAG((&(pts.adslLineExtTableEntry_pt->flags)), ATUC_LINE_TRANS_CONFIG_FLAG);
2165 }
2166 }
2167 CLR_FLAG((&(pts.adslLineExtTableEntry_pt->flags)), ATUC_LINE_TRANS_ACTUAL_FLAG);
2168 CLR_FLAG((&(pts.adslLineExtTableEntry_pt->flags)), LINE_GLITE_POWER_STATE_FLAG);
2169
2170 copy_to_user((char *)lon, (char *)pts.adslLineExtTableEntry_pt, sizeof(adslLineExtTableEntry));
2171 kfree(pts.adslLineTableEntry_pt);
2172 up(&mei_sema);
2173 break;
2174 #endif
2175
2176 case GET_ADSL_ATUC_PHY:
2177 if(down_interruptible(&mei_sema))
2178 return -ERESTARTSYS;
2179
2180 pts.adslAtucPhysEntry_pt = (adslAtucPhysEntry *)kmalloc(sizeof(adslAtucPhysEntry), GFP_KERNEL);
2181 copy_from_user((char *)pts.adslAtucPhysEntry_pt, (char *)lon, sizeof(adslAtucPhysEntry));
2182 if(IS_FLAG_SET((&(pts.adslAtucPhysEntry_pt->flags)), ATUC_PHY_SER_NUM_FLAG)){
2183 ATUC_PHY_SER_NUM_FLAG_MAKECMV1;
2184 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
2185 #ifdef AMAZON_MEI_DEBUG_ON
2186 printk("\n\nCMV fail, Group 3 Address 57 Index 0");
2187 #endif
2188 CLR_FLAG((&(pts.adslAtucPhysEntry_pt->flags)), ATUC_PHY_SER_NUM_FLAG);
2189 }
2190 else{
2191 memcpy(pts.adslAtucPhysEntry_pt->serial_no, RxMessage+4, ((RxMessage[0]&0xf)*2));
2192 }
2193 ATUC_PHY_SER_NUM_FLAG_MAKECMV2;
2194 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
2195 #ifdef AMAZON_MEI_DEBUG_ON
2196 printk("\n\nCMV fail, Group 3 Address 57 Index 12");
2197 #endif
2198 CLR_FLAG((&(pts.adslAtucPhysEntry_pt->flags)), ATUC_PHY_SER_NUM_FLAG);
2199 }
2200 else{
2201 memcpy((pts.adslAtucPhysEntry_pt->serial_no+24), RxMessage+4, ((RxMessage[0]&0xf)*2));
2202 }
2203 }
2204 if(IS_FLAG_SET((&(pts.adslAtucPhysEntry_pt->flags)), ATUC_PHY_VENDOR_ID_FLAG)){
2205 ATUC_PHY_VENDOR_ID_FLAG_MAKECMV;
2206 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
2207 #ifdef AMAZON_MEI_DEBUG_ON
2208 printk("\n\nCMV fail, Group 3 Address 64 Index 0");
2209 #endif
2210 CLR_FLAG((&(pts.adslAtucPhysEntry_pt->flags)), ATUC_PHY_VENDOR_ID_FLAG);
2211 }
2212 else{
2213 memcpy(pts.adslAtucPhysEntry_pt->vendor_id.vendor_id, RxMessage+4, ((RxMessage[0]&0xf)*2));
2214 }
2215 }
2216 if(IS_FLAG_SET((&(pts.adslAtucPhysEntry_pt->flags)), ATUC_PHY_VER_NUM_FLAG)){
2217 ATUC_PHY_VER_NUM_FLAG_MAKECMV;
2218 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
2219 #ifdef AMAZON_MEI_DEBUG_ON
2220 printk("\n\nCMV fail, Group 3 Address 58 Index 0");
2221 #endif
2222 CLR_FLAG((&(pts.adslAtucPhysEntry_pt->flags)), ATUC_PHY_VER_NUM_FLAG);
2223 }
2224 else{
2225 memcpy(pts.adslAtucPhysEntry_pt->version_no, RxMessage+4, ((RxMessage[0]&0xf)*2));
2226 }
2227 }
2228 if(IS_FLAG_SET((&(pts.adslAtucPhysEntry_pt->flags)), ATUC_CURR_STAT_FLAG)){
2229 pts.adslAtucPhysEntry_pt->status = CurrStatus.adslAtucCurrStatus;
2230 }
2231 if(IS_FLAG_SET((&(pts.adslAtucPhysEntry_pt->flags)), ATUC_CURR_OUT_PWR_FLAG)){
2232 ATUC_CURR_OUT_PWR_FLAG_MAKECMV;
2233 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
2234 #ifdef AMAZON_MEI_DEBUG_ON
2235 printk("\n\nCMV fail, Group 3 Address 68 Index 5");
2236 #endif
2237 CLR_FLAG((&(pts.adslAtucPhysEntry_pt->flags)), ATUC_CURR_OUT_PWR_FLAG);
2238 }
2239 else{
2240 memcpy((&(pts.adslAtucPhysEntry_pt->outputPwr)), RxMessage+4, ((RxMessage[0]&0xf)*2));
2241 }
2242 }
2243 if(IS_FLAG_SET((&(pts.adslAtucPhysEntry_pt->flags)), ATUC_CURR_ATTR_FLAG)){
2244 ATUC_CURR_ATTR_FLAG_MAKECMV;
2245 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
2246 #ifdef AMAZON_MEI_DEBUG_ON
2247 printk("\n\nCMV fail, Group 3 Address 69 Index 0");
2248 #endif
2249 CLR_FLAG((&(pts.adslAtucPhysEntry_pt->flags)), ATUC_CURR_ATTR_FLAG);
2250 }
2251 else{
2252 memcpy((&(pts.adslAtucPhysEntry_pt->attainableRate)), RxMessage+4, ((RxMessage[0]&0xf)*2));
2253 }
2254 }
2255 copy_to_user((char *)lon, (char *)pts.adslAtucPhysEntry_pt, sizeof(adslAtucPhysEntry));
2256 kfree(pts.adslAtucPhysEntry_pt);
2257
2258 up(&mei_sema);
2259 break;
2260 case GET_ADSL_ATUR_PHY:
2261 if(down_interruptible(&mei_sema))
2262 return -ERESTARTSYS;
2263
2264 pts.adslAturPhysEntry_pt = (adslAturPhysEntry *)kmalloc(sizeof(adslAturPhysEntry), GFP_KERNEL);
2265 copy_from_user((char *)pts.adslAturPhysEntry_pt, (char *)lon, sizeof(adslAturPhysEntry));
2266 if(IS_FLAG_SET((&(pts.adslAturPhysEntry_pt->flags)), ATUR_PHY_SER_NUM_FLAG)){
2267 ATUR_PHY_SER_NUM_FLAG_MAKECMV1;
2268 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
2269 #ifdef AMAZON_MEI_DEBUG_ON
2270 printk("\n\nCMV fail, Group 3 Address 62 Index 0");
2271 #endif
2272 CLR_FLAG((&(pts.adslAturPhysEntry_pt->flags)), ATUR_PHY_SER_NUM_FLAG);
2273 }
2274 else{
2275 memcpy(pts.adslAturPhysEntry_pt->serial_no, RxMessage+4, ((RxMessage[0]&0xf)*2));
2276 }
2277 ATUR_PHY_SER_NUM_FLAG_MAKECMV2;
2278 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
2279 #ifdef AMAZON_MEI_DEBUG_ON
2280 printk("\n\nCMV fail, Group 3 Address 62 Index 12");
2281 #endif
2282 CLR_FLAG((&(pts.adslAturPhysEntry_pt->flags)), ATUR_PHY_SER_NUM_FLAG);
2283 }
2284 else{
2285 memcpy((pts.adslAturPhysEntry_pt->serial_no+24), RxMessage+4, ((RxMessage[0]&0xf)*2));
2286 }
2287 }
2288 if(IS_FLAG_SET((&(pts.adslAturPhysEntry_pt->flags)), ATUR_PHY_VENDOR_ID_FLAG)){
2289 ATUR_PHY_VENDOR_ID_FLAG_MAKECMV;
2290 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
2291 #ifdef AMAZON_MEI_DEBUG_ON
2292 printk("\n\nCMV fail, Group 3 Address 65 Index 0");
2293 #endif
2294 CLR_FLAG((&(pts.adslAturPhysEntry_pt->flags)), ATUR_PHY_VENDOR_ID_FLAG);
2295 }
2296 else{
2297 memcpy(pts.adslAturPhysEntry_pt->vendor_id.vendor_id, RxMessage+4, ((RxMessage[0]&0xf)*2));
2298 }
2299 }
2300 if(IS_FLAG_SET((&(pts.adslAturPhysEntry_pt->flags)), ATUR_PHY_VER_NUM_FLAG)){
2301 ATUR_PHY_VER_NUM_FLAG_MAKECMV;
2302 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
2303 #ifdef AMAZON_MEI_DEBUG_ON
2304 printk("\n\nCMV fail, Group 3 Address 61 Index 0");
2305 #endif
2306 CLR_FLAG((&(pts.adslAturPhysEntry_pt->flags)), ATUR_PHY_VER_NUM_FLAG);
2307 }
2308 else{
2309 memcpy(pts.adslAturPhysEntry_pt->version_no, RxMessage+4, ((RxMessage[0]&0xf)*2));
2310 }
2311 }
2312 if(IS_FLAG_SET((&(pts.adslAturPhysEntry_pt->flags)), ATUR_SNRMGN_FLAG)){
2313 ATUR_SNRMGN_FLAG_MAKECMV;
2314 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
2315 #ifdef AMAZON_MEI_DEBUG_ON
2316 printk("\n\nCMV fail, Group 3 Address 68 Index 4");
2317 #endif
2318 CLR_FLAG((&(pts.adslAturPhysEntry_pt->flags)), ATUR_SNRMGN_FLAG);
2319 }
2320 else{
2321 memcpy((&(pts.adslAturPhysEntry_pt->SnrMgn)), RxMessage+4, ((RxMessage[0]&0xf)*2));
2322 }
2323 }
2324 if(IS_FLAG_SET((&(pts.adslAturPhysEntry_pt->flags)), ATUR_ATTN_FLAG)){
2325 ATUR_ATTN_FLAG_MAKECMV;
2326 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
2327 #ifdef AMAZON_MEI_DEBUG_ON
2328 printk("\n\nCMV fail, Group 3 Address 68 Index 2");
2329 #endif
2330 CLR_FLAG((&(pts.adslAturPhysEntry_pt->flags)), ATUR_ATTN_FLAG);
2331 }
2332 else{
2333 memcpy((&(pts.adslAturPhysEntry_pt->Attn)), RxMessage+4, ((RxMessage[0]&0xf)*2));
2334 }
2335 }
2336 if(IS_FLAG_SET((&(pts.adslAturPhysEntry_pt->flags)), ATUR_CURR_STAT_FLAG)){
2337 pts.adslAturPhysEntry_pt->status = CurrStatus.adslAturCurrStatus;
2338 }
2339 if(IS_FLAG_SET((&(pts.adslAturPhysEntry_pt->flags)), ATUR_CURR_OUT_PWR_FLAG)){
2340 ATUR_CURR_OUT_PWR_FLAG_MAKECMV;
2341 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
2342 #ifdef AMAZON_MEI_DEBUG_ON
2343 printk("\n\nCMV fail, Group 3 Address 69 Index 5");
2344 #endif
2345 CLR_FLAG((&(pts.adslAturPhysEntry_pt->flags)), ATUR_CURR_OUT_PWR_FLAG);
2346 }
2347 else{
2348 memcpy((&(pts.adslAturPhysEntry_pt->outputPwr)), RxMessage+4, ((RxMessage[0]&0xf)*2));
2349 }
2350 }
2351 if(IS_FLAG_SET((&(pts.adslAturPhysEntry_pt->flags)), ATUR_CURR_ATTR_FLAG)){
2352 ATUR_CURR_ATTR_FLAG_MAKECMV;
2353 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
2354 #ifdef AMAZON_MEI_DEBUG_ON
2355 printk("\n\nCMV fail, Group 3 Address 68 Index 0");
2356 #endif
2357 CLR_FLAG((&(pts.adslAturPhysEntry_pt->flags)), ATUR_CURR_ATTR_FLAG);
2358 }
2359 else{
2360 memcpy((&(pts.adslAturPhysEntry_pt->attainableRate)), RxMessage+4, ((RxMessage[0]&0xf)*2));
2361 }
2362 }
2363 copy_to_user((char *)lon, (char *)pts.adslAturPhysEntry_pt, sizeof(adslAturPhysEntry));
2364 kfree(pts.adslAturPhysEntry_pt);
2365
2366 up(&mei_sema);
2367 break;
2368 case GET_ADSL_ATUC_CHAN_INFO:
2369 if(down_interruptible(&mei_sema))
2370 return -ERESTARTSYS;
2371
2372 pts.adslAtucChanInfo_pt = (adslAtucChanInfo *)kmalloc(sizeof(adslAtucChanInfo), GFP_KERNEL);
2373 copy_from_user((char *)pts.adslAtucChanInfo_pt, (char *)lon, sizeof(adslAtucChanInfo));
2374 if(IS_FLAG_SET((&(pts.adslAtucChanInfo_pt->flags)), ATUC_CHAN_INTLV_DELAY_FLAG)){
2375 if((chantype.interleave!=1) || (chantype.fast==1)){
2376 CLR_FLAG((&(pts.adslAtucChanInfo_pt->flags)), ATUC_CHAN_INTLV_DELAY_FLAG);
2377 }
2378 else{
2379 ATUC_CHAN_INTLV_DELAY_FLAG_MAKECMV;
2380 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
2381 #ifdef AMAZON_MEI_DEBUG_ON
2382 printk("\n\nCMV fail, Group 6 Address 3 Index 1");
2383 #endif
2384 CLR_FLAG((&(pts.adslAtucChanInfo_pt->flags)), ATUC_CHAN_INTLV_DELAY_FLAG);
2385 }
2386 else{
2387 memcpy((&(pts.adslAtucChanInfo_pt->interleaveDelay)), RxMessage+4, ((RxMessage[0]&0xf)*2));
2388 }
2389 }
2390 }
2391 if(IS_FLAG_SET((&(pts.adslAtucChanInfo_pt->flags)), ATUC_CHAN_CURR_TX_RATE_FLAG)){
2392 ATUC_CHAN_CURR_TX_RATE_FLAG_MAKECMV;
2393 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
2394 #ifdef AMAZON_MEI_DEBUG_ON
2395 printk("\n\nCMV fail, Group 6 Address 1 Index 0");
2396 #endif
2397 CLR_FLAG((&(pts.adslAtucChanInfo_pt->flags)), ATUC_CHAN_CURR_TX_RATE_FLAG);
2398 }
2399 else{
2400 pts.adslAtucChanInfo_pt->currTxRate = (u32)(RxMessage[4]) + (((u32)(RxMessage[5]))<<16);
2401 }
2402 }
2403 if(IS_FLAG_SET((&(pts.adslAtucChanInfo_pt->flags)), ATUC_CHAN_PREV_TX_RATE_FLAG)){
2404 pts.adslAtucChanInfo_pt->prevTxRate = PrevTxRate.adslAtucChanPrevTxRate;
2405 }
2406 copy_to_user((char *)lon, (char *)pts.adslAtucChanInfo_pt, sizeof(adslAtucChanInfo));
2407 kfree(pts.adslAtucChanInfo_pt);
2408
2409 up(&mei_sema);
2410 break;
2411 case GET_ADSL_ATUR_CHAN_INFO:
2412 if(down_interruptible(&mei_sema))
2413 return -ERESTARTSYS;
2414
2415 pts.adslAturChanInfo_pt = (adslAturChanInfo *)kmalloc(sizeof(adslAturChanInfo), GFP_KERNEL);
2416 copy_from_user((char *)pts.adslAturChanInfo_pt, (char *)lon, sizeof(adslAturChanInfo));
2417 if(IS_FLAG_SET((&(pts.adslAturChanInfo_pt->flags)), ATUR_CHAN_INTLV_DELAY_FLAG)){
2418 if((chantype.interleave!=1) || (chantype.fast==1)){
2419 CLR_FLAG((&(pts.adslAturChanInfo_pt->flags)), ATUR_CHAN_INTLV_DELAY_FLAG);
2420 }
2421 else{
2422 ATUR_CHAN_INTLV_DELAY_FLAG_MAKECMV;
2423 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
2424 #ifdef AMAZON_MEI_DEBUG_ON
2425 printk("\n\nCMV fail, Group 6 Address 2 Index 1");
2426 #endif
2427 CLR_FLAG((&(pts.adslAturChanInfo_pt->flags)), ATUR_CHAN_INTLV_DELAY_FLAG);
2428 }
2429 else{
2430 memcpy((&(pts.adslAturChanInfo_pt->interleaveDelay)), RxMessage+4, ((RxMessage[0]&0xf)*2));
2431 }
2432 }
2433 }
2434 if(IS_FLAG_SET((&(pts.adslAturChanInfo_pt->flags)), ATUR_CHAN_CURR_TX_RATE_FLAG)){
2435 ATUR_CHAN_CURR_TX_RATE_FLAG_MAKECMV;
2436 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
2437 #ifdef AMAZON_MEI_DEBUG_ON
2438 printk("\n\nCMV fail, Group 6 Address 0 Index 0");
2439 #endif
2440 CLR_FLAG((&(pts.adslAturChanInfo_pt->flags)), ATUR_CHAN_CURR_TX_RATE_FLAG);
2441 }
2442 else{
2443 pts.adslAturChanInfo_pt->currTxRate = (u32)(RxMessage[4]) + (((u32)(RxMessage[5]))<<16);
2444 }
2445 }
2446 if(IS_FLAG_SET((&(pts.adslAturChanInfo_pt->flags)), ATUR_CHAN_PREV_TX_RATE_FLAG)){
2447 pts.adslAturChanInfo_pt->prevTxRate = PrevTxRate.adslAturChanPrevTxRate;
2448 }
2449 if(IS_FLAG_SET((&(pts.adslAturChanInfo_pt->flags)), ATUR_CHAN_CRC_BLK_LEN_FLAG)){
2450 // ? no CMV to update this
2451 CLR_FLAG((&(pts.adslAturChanInfo_pt->flags)), ATUR_CHAN_CRC_BLK_LEN_FLAG);
2452 }
2453 copy_to_user((char *)lon, (char *)pts.adslAturChanInfo_pt, sizeof(adslAturChanInfo));
2454 kfree(pts.adslAturChanInfo_pt);
2455
2456 up(&mei_sema);
2457 break;
2458 case GET_ADSL_ATUC_PERF_DATA:
2459 pts.atucPerfDataEntry_pt = (atucPerfDataEntry *)kmalloc(sizeof(atucPerfDataEntry), GFP_KERNEL);
2460 copy_from_user((char *)pts.atucPerfDataEntry_pt, (char *)lon, sizeof(atucPerfDataEntry));
2461 if(IS_FLAG_SET((&(pts.atucPerfDataEntry_pt->flags)), ATUC_PERF_LOFS_FLAG)){
2462 pts.atucPerfDataEntry_pt->adslAtucPerfLofs=ATUC_PERF_LOFS;
2463 }
2464 if(IS_FLAG_SET((&(pts.atucPerfDataEntry_pt->flags)), ATUC_PERF_LOSS_FLAG)){
2465 pts.atucPerfDataEntry_pt->adslAtucPerfLoss=ATUC_PERF_LOSS;
2466 }
2467 if(IS_FLAG_SET((&(pts.atucPerfDataEntry_pt->flags)), ATUC_PERF_ESS_FLAG)){
2468 pts.atucPerfDataEntry_pt->adslAtucPerfESs=ATUC_PERF_ESS;
2469 }
2470 if(IS_FLAG_SET((&(pts.atucPerfDataEntry_pt->flags)), ATUC_PERF_INITS_FLAG)){
2471 pts.atucPerfDataEntry_pt->adslAtucPerfInits=ATUC_PERF_INITS;
2472 }
2473 if(IS_FLAG_SET((&(pts.atucPerfDataEntry_pt->flags)), ATUC_PERF_VALID_INTVLS_FLAG)){
2474 i=0;
2475 for(ptr=(current_intvl->list).prev; ptr!=&interval_list; ptr=ptr->prev){
2476 i++;
2477 if(i==96)
2478 break;
2479 }
2480 pts.atucPerfDataEntry_pt->adslAtucPerfValidIntervals=i;
2481 }
2482 if(IS_FLAG_SET((&(pts.atucPerfDataEntry_pt->flags)), ATUC_PERF_INVALID_INTVLS_FLAG)){
2483 pts.atucPerfDataEntry_pt->adslAtucPerfInvalidIntervals=0;
2484 }
2485 if(IS_FLAG_SET((&(pts.atucPerfDataEntry_pt->flags)), ATUC_PERF_CURR_15MIN_TIME_ELAPSED_FLAG)){
2486 do_gettimeofday(&time_now);
2487 pts.atucPerfDataEntry_pt->adslAtucPerfCurr15MinTimeElapsed=time_now.tv_sec - (current_intvl->start_time).tv_sec;
2488 }
2489 if(IS_FLAG_SET((&(pts.atucPerfDataEntry_pt->flags)), ATUC_PERF_CURR_15MIN_LOFS_FLAG)){
2490 pts.atucPerfDataEntry_pt->adslAtucPerfCurr15MinLofs=current_intvl->AtucPerfLof;
2491 }
2492 if(IS_FLAG_SET((&(pts.atucPerfDataEntry_pt->flags)), ATUC_PERF_CURR_15MIN_LOSS_FLAG)){
2493 pts.atucPerfDataEntry_pt->adslAtucPerfCurr15MinLoss=current_intvl->AtucPerfLos;
2494 }
2495 if(IS_FLAG_SET((&(pts.atucPerfDataEntry_pt->flags)), ATUC_PERF_CURR_15MIN_ESS_FLAG)){
2496 pts.atucPerfDataEntry_pt->adslAtucPerfCurr15MinESs=current_intvl->AtucPerfEs;
2497 }
2498 if(IS_FLAG_SET((&(pts.atucPerfDataEntry_pt->flags)), ATUC_PERF_CURR_15MIN_INIT_FLAG)){
2499 pts.atucPerfDataEntry_pt->adslAtucPerfCurr15MinInits=current_intvl->AtucPerfInit;
2500 }
2501 if(IS_FLAG_SET((&(pts.atucPerfDataEntry_pt->flags)), ATUC_PERF_CURR_1DAY_TIME_ELAPSED_FLAG)){
2502 i=0;
2503 for(ptr=(current_intvl->list).prev; ptr!=&interval_list; ptr=ptr->prev){
2504 i+=900;
2505 }
2506 do_gettimeofday(&time_now);
2507 i+=time_now.tv_sec - (current_intvl->start_time).tv_sec;
2508 if(i>=86400)
2509 pts.atucPerfDataEntry_pt->adslAtucPerfCurr1DayTimeElapsed=i-86400;
2510 else
2511 pts.atucPerfDataEntry_pt->adslAtucPerfCurr1DayTimeElapsed=i;
2512 }
2513 if(IS_FLAG_SET((&(pts.atucPerfDataEntry_pt->flags)), ATUC_PERF_CURR_1DAY_LOFS_FLAG)){
2514 i=0;
2515 j=0;
2516 for(ptr=interval_list.next; ptr!=&(current_intvl->list); ptr=ptr->next){
2517 mib_ptr = list_entry(ptr, amazon_mei_mib, list);
2518 j+=mib_ptr->AtucPerfLof;
2519 i++;
2520 if(i==96)
2521 j=0;
2522 }
2523 j+=current_intvl->AtucPerfLof;
2524 pts.atucPerfDataEntry_pt->adslAtucPerfCurr1DayLofs=j;
2525 }
2526 if(IS_FLAG_SET((&(pts.atucPerfDataEntry_pt->flags)), ATUC_PERF_CURR_1DAY_LOSS_FLAG)){
2527 i=0;
2528 j=0;
2529 for(ptr=interval_list.next; ptr!=&(current_intvl->list); ptr=ptr->next){
2530 mib_ptr = list_entry(ptr, amazon_mei_mib, list);
2531 j+=mib_ptr->AtucPerfLos;
2532 i++;
2533 if(i==96)
2534 j=0;
2535 }
2536 j+=current_intvl->AtucPerfLos;
2537 pts.atucPerfDataEntry_pt->adslAtucPerfCurr1DayLoss=j;
2538 }
2539 if(IS_FLAG_SET((&(pts.atucPerfDataEntry_pt->flags)), ATUC_PERF_CURR_1DAY_ESS_FLAG)){
2540 i=0;
2541 j=0;
2542 for(ptr=interval_list.next; ptr!=&(current_intvl->list); ptr=ptr->next){
2543 mib_ptr = list_entry(ptr, amazon_mei_mib, list);
2544 j+=mib_ptr->AtucPerfEs;
2545 i++;
2546 if(i==96)
2547 j=0;
2548 }
2549 j+=current_intvl->AtucPerfEs;
2550 pts.atucPerfDataEntry_pt->adslAtucPerfCurr1DayESs=j;
2551 }
2552 if(IS_FLAG_SET((&(pts.atucPerfDataEntry_pt->flags)), ATUC_PERF_CURR_1DAY_INIT_FLAG)){
2553 i=0;
2554 j=0;
2555 for(ptr=interval_list.next; ptr!=&(current_intvl->list); ptr=ptr->next){
2556 mib_ptr = list_entry(ptr, amazon_mei_mib, list);
2557 j+=mib_ptr->AtucPerfInit;
2558 i++;
2559 if(i==96)
2560 j=0;
2561 }
2562 j+=current_intvl->AtucPerfInit;
2563 pts.atucPerfDataEntry_pt->adslAtucPerfCurr1DayInits=j;
2564 }
2565 if(IS_FLAG_SET((&(pts.atucPerfDataEntry_pt->flags)), ATUC_PERF_PREV_1DAY_MON_SEC_FLAG)){
2566 i=0;
2567 for(ptr=interval_list.next; ptr!=&(current_intvl->list); ptr=ptr->next){
2568 i++;
2569 }
2570 if(i>=96)
2571 pts.atucPerfDataEntry_pt->adslAtucPerfPrev1DayMoniSecs=86400;
2572 else
2573 pts.atucPerfDataEntry_pt->adslAtucPerfPrev1DayMoniSecs=0;
2574 }
2575 if(IS_FLAG_SET((&(pts.atucPerfDataEntry_pt->flags)), ATUC_PERF_PREV_1DAY_LOFS_FLAG)){
2576 i=0;
2577 j=0;
2578 for(ptr=interval_list.next; ptr!=&(current_intvl->list); ptr=ptr->next){
2579 mib_ptr = list_entry(ptr, amazon_mei_mib, list);
2580 j+=mib_ptr->AtucPerfLof;
2581 i++;
2582 if(i==96)
2583 break;
2584 }
2585 if(i==96)
2586 pts.atucPerfDataEntry_pt->adslAtucPerfPrev1DayLofs=j;
2587 else
2588 pts.atucPerfDataEntry_pt->adslAtucPerfPrev1DayLofs=0;
2589 }
2590 if(IS_FLAG_SET((&(pts.atucPerfDataEntry_pt->flags)), ATUC_PERF_PREV_1DAY_LOSS_FLAG)){
2591 i=0;
2592 j=0;
2593 for(ptr=interval_list.next; ptr!=&(current_intvl->list); ptr=ptr->next){
2594 mib_ptr = list_entry(ptr, amazon_mei_mib, list);
2595 j+=mib_ptr->AtucPerfLos;
2596 i++;
2597 if(i==96)
2598 break;
2599 }
2600 if(i==96)
2601 pts.atucPerfDataEntry_pt->adslAtucPerfPrev1DayLoss=j;
2602 else
2603 pts.atucPerfDataEntry_pt->adslAtucPerfPrev1DayLoss=0;
2604 }
2605 if(IS_FLAG_SET((&(pts.atucPerfDataEntry_pt->flags)), ATUC_PERF_PREV_1DAY_ESS_FLAG)){
2606 i=0;
2607 j=0;
2608 for(ptr=interval_list.next; ptr!=&(current_intvl->list); ptr=ptr->next){
2609 mib_ptr = list_entry(ptr, amazon_mei_mib, list);
2610 j+=mib_ptr->AtucPerfEs;
2611 i++;
2612 if(i==96)
2613 break;
2614 }
2615 if(i==96)
2616 pts.atucPerfDataEntry_pt->adslAtucPerfPrev1DayESs=j;
2617 else
2618 pts.atucPerfDataEntry_pt->adslAtucPerfPrev1DayESs=0;
2619 }
2620 if(IS_FLAG_SET((&(pts.atucPerfDataEntry_pt->flags)), ATUC_PERF_PREV_1DAY_INITS_FLAG)){
2621 i=0;
2622 j=0;
2623 for(ptr=interval_list.next; ptr!=&(current_intvl->list); ptr=ptr->next){
2624 mib_ptr = list_entry(ptr, amazon_mei_mib, list);
2625 j+=mib_ptr->AtucPerfInit;
2626 i++;
2627 if(i==96)
2628 break;
2629 }
2630 if(i==96)
2631 pts.atucPerfDataEntry_pt->adslAtucPerfPrev1DayInits=j;
2632 else
2633 pts.atucPerfDataEntry_pt->adslAtucPerfPrev1DayInits=0;
2634 }
2635
2636 copy_to_user((char *)lon, (char *)pts.atucPerfDataEntry_pt, sizeof(atucPerfDataEntry));
2637 kfree(pts.atucPerfDataEntry_pt);
2638 break;
2639 #ifdef AMAZON_MEI_MIB_RFC3440
2640 case GET_ADSL_ATUC_PERF_DATA_EXT: //??? CMV mapping not available
2641 pts.atucPerfDataExtEntry_pt = (atucPerfDataExtEntry *)kmalloc(sizeof(atucPerfDataExtEntry), GFP_KERNEL);
2642 copy_from_user((char *)pts.atucPerfDataExtEntry_pt, (char *)lon, sizeof(atucPerfDataExtEntry));
2643 if(IS_FLAG_SET((&(pts.atucPerfDataExtEntry_pt->flags)), ATUC_PERF_STAT_FASTR_FLAG)){
2644 pts.atucPerfDataExtEntry_pt->adslAtucPerfStatFastR=ATUC_PERF_STAT_FASTR;
2645 }
2646 if(IS_FLAG_SET((&(pts.atucPerfDataExtEntry_pt->flags)), ATUC_PERF_STAT_FAILED_FASTR_FLAG)){
2647 pts.atucPerfDataExtEntry_pt->adslAtucPerfStatFailedFastR=ATUC_PERF_STAT_FAILED_FASTR;
2648 }
2649 if(IS_FLAG_SET((&(pts.atucPerfDataExtEntry_pt->flags)), ATUC_PERF_STAT_SESL_FLAG)){
2650 pts.atucPerfDataExtEntry_pt->adslAtucPerfStatSesL=ATUC_PERF_STAT_SESL;
2651 }
2652 if(IS_FLAG_SET((&(pts.atucPerfDataExtEntry_pt->flags)), ATUC_PERF_STAT_UASL_FLAG)){
2653 pts.atucPerfDataExtEntry_pt->adslAtucPerfStatUasL=ATUC_PERF_STAT_UASL;
2654 }
2655 if(IS_FLAG_SET((&(pts.atucPerfDataExtEntry_pt->flags)), ATUC_PERF_CURR_15MIN_FASTR_FLAG)){
2656 pts.atucPerfDataExtEntry_pt->adslAtucPerfCurr15MinFastR=current_intvl->AtucPerfStatFastR;
2657 }
2658 if(IS_FLAG_SET((&(pts.atucPerfDataExtEntry_pt->flags)), ATUC_PERF_CURR_15MIN_FAILED_FASTR_FLAG)){
2659 pts.atucPerfDataExtEntry_pt->adslAtucPerfCurr15MinFailedFastR=current_intvl->AtucPerfStatFailedFastR;
2660 }
2661 if(IS_FLAG_SET((&(pts.atucPerfDataExtEntry_pt->flags)), ATUC_PERF_CURR_15MIN_SESL_FLAG)){
2662 pts.atucPerfDataExtEntry_pt->adslAtucPerfCurr15MinSesL=current_intvl->AtucPerfStatSesL;
2663 }
2664 if(IS_FLAG_SET((&(pts.atucPerfDataExtEntry_pt->flags)), ATUC_PERF_CURR_15MIN_UASL_FLAG)){
2665 pts.atucPerfDataExtEntry_pt->adslAtucPerfCurr15MinUasL=current_intvl->AtucPerfStatUasL;
2666 }
2667 if(IS_FLAG_SET((&(pts.atucPerfDataExtEntry_pt->flags)), ATUC_PERF_CURR_1DAY_FASTR_FLAG)){
2668 i=0;
2669 j=0;
2670 for(ptr=interval_list.next; ptr!=&(current_intvl->list); ptr=ptr->next){
2671 mib_ptr = list_entry(ptr, amazon_mei_mib, list);
2672 j+=mib_ptr->AtucPerfStatFastR;
2673 i++;
2674 if(i==96)
2675 j=0;
2676 }
2677 j+=current_intvl->AtucPerfStatFastR;
2678 pts.atucPerfDataExtEntry_pt->adslAtucPerfCurr1DayFastR=j;
2679 }
2680 if(IS_FLAG_SET((&(pts.atucPerfDataExtEntry_pt->flags)), ATUC_PERF_CURR_1DAY_FAILED_FASTR_FLAG)){
2681 i=0;
2682 j=0;
2683 for(ptr=interval_list.next; ptr!=&(current_intvl->list); ptr=ptr->next){
2684 mib_ptr = list_entry(ptr, amazon_mei_mib, list);
2685 j+=mib_ptr->AtucPerfStatFailedFastR;
2686 i++;
2687 if(i==96)
2688 j=0;
2689 }
2690 j+=current_intvl->AtucPerfStatFailedFastR;
2691 pts.atucPerfDataExtEntry_pt->adslAtucPerfCurr1DayFailedFastR=j;
2692 }
2693 if(IS_FLAG_SET((&(pts.atucPerfDataExtEntry_pt->flags)), ATUC_PERF_CURR_1DAY_SESL_FLAG)){
2694 i=0;
2695 j=0;
2696 for(ptr=interval_list.next; ptr!=&(current_intvl->list); ptr=ptr->next){
2697 mib_ptr = list_entry(ptr, amazon_mei_mib, list);
2698 j+=mib_ptr->AtucPerfStatSesL;
2699 i++;
2700 if(i==96)
2701 j=0;
2702 }
2703 j+=current_intvl->AtucPerfStatSesL;
2704 pts.atucPerfDataExtEntry_pt->adslAtucPerfCurr1DaySesL=j;
2705 }
2706 if(IS_FLAG_SET((&(pts.atucPerfDataExtEntry_pt->flags)), ATUC_PERF_CURR_1DAY_UASL_FLAG)){
2707 i=0;
2708 j=0;
2709 for(ptr=interval_list.next; ptr!=&(current_intvl->list); ptr=ptr->next){
2710 mib_ptr = list_entry(ptr, amazon_mei_mib, list);
2711 j+=mib_ptr->AtucPerfStatUasL;
2712 i++;
2713 if(i==96)
2714 j=0;
2715 }
2716 j+=current_intvl->AtucPerfStatUasL;
2717 pts.atucPerfDataExtEntry_pt->adslAtucPerfCurr1DayUasL=j;
2718 }
2719 if(IS_FLAG_SET((&(pts.atucPerfDataExtEntry_pt->flags)), ATUC_PERF_PREV_1DAY_FASTR_FLAG)){
2720 i=0;
2721 j=0;
2722 for(ptr=interval_list.next; ptr!=&(current_intvl->list); ptr=ptr->next){
2723 mib_ptr = list_entry(ptr, amazon_mei_mib, list);
2724 j+=mib_ptr->AtucPerfStatFastR;
2725 i++;
2726 if(i==96)
2727 break;
2728 }
2729 if(i==96)
2730 pts.atucPerfDataExtEntry_pt->adslAtucPerfPrev1DayFastR=j;
2731 else
2732 pts.atucPerfDataExtEntry_pt->adslAtucPerfPrev1DayFastR=0;
2733 }
2734 if(IS_FLAG_SET((&(pts.atucPerfDataExtEntry_pt->flags)), ATUC_PERF_PREV_1DAY_FAILED_FASTR_FLAG)){
2735 i=0;
2736 j=0;
2737 for(ptr=interval_list.next; ptr!=&(current_intvl->list); ptr=ptr->next){
2738 mib_ptr = list_entry(ptr, amazon_mei_mib, list);
2739 j+=mib_ptr->AtucPerfStatFailedFastR;
2740 i++;
2741 if(i==96)
2742 break;
2743 }
2744 if(i==96)
2745 pts.atucPerfDataExtEntry_pt->adslAtucPerfPrev1DayFailedFastR=j;
2746 else
2747 pts.atucPerfDataExtEntry_pt->adslAtucPerfPrev1DayFailedFastR=0;
2748 }
2749 if(IS_FLAG_SET((&(pts.atucPerfDataExtEntry_pt->flags)), ATUC_PERF_PREV_1DAY_SESL_FLAG)){
2750 i=0;
2751 j=0;
2752 for(ptr=interval_list.next; ptr!=&(current_intvl->list); ptr=ptr->next){
2753 mib_ptr = list_entry(ptr, amazon_mei_mib, list);
2754 j+=mib_ptr->AtucPerfStatSesL;
2755 i++;
2756 if(i==96)
2757 break;
2758 }
2759 if(i==96)
2760 pts.atucPerfDataExtEntry_pt->adslAtucPerfPrev1DaySesL=j;
2761 else
2762 pts.atucPerfDataExtEntry_pt->adslAtucPerfPrev1DaySesL=0;
2763 }
2764 if(IS_FLAG_SET((&(pts.atucPerfDataExtEntry_pt->flags)), ATUC_PERF_PREV_1DAY_UASL_FLAG)){
2765 i=0;
2766 j=0;
2767 for(ptr=interval_list.next; ptr!=&(current_intvl->list); ptr=ptr->next){
2768 mib_ptr = list_entry(ptr, amazon_mei_mib, list);
2769 j+=mib_ptr->AtucPerfStatUasL;
2770 i++;
2771 if(i==96)
2772 break;
2773 }
2774 if(i==96)
2775 pts.atucPerfDataExtEntry_pt->adslAtucPerfPrev1DayUasL=j;
2776 else
2777 pts.atucPerfDataExtEntry_pt->adslAtucPerfPrev1DayUasL=0;
2778 }
2779 copy_to_user((char *)lon, (char *)pts.atucPerfDataExtEntry_pt, sizeof(atucPerfDataExtEntry));
2780 kfree(pts.atucPerfDataExtEntry_pt);
2781 break;
2782 #endif
2783 case GET_ADSL_ATUR_PERF_DATA:
2784 pts.aturPerfDataEntry_pt = (aturPerfDataEntry *)kmalloc(sizeof(aturPerfDataEntry), GFP_KERNEL);
2785 copy_from_user((char *)pts.aturPerfDataEntry_pt, (char *)lon, sizeof(aturPerfDataEntry));
2786 if(IS_FLAG_SET((&(pts.aturPerfDataEntry_pt->flags)), ATUR_PERF_LOFS_FLAG)){
2787 pts.aturPerfDataEntry_pt->adslAturPerfLofs=ATUR_PERF_LOFS;
2788 }
2789 if(IS_FLAG_SET((&(pts.aturPerfDataEntry_pt->flags)), ATUR_PERF_LOSS_FLAG)){
2790 pts.aturPerfDataEntry_pt->adslAturPerfLoss=ATUR_PERF_LOSS;
2791 }
2792 if(IS_FLAG_SET((&(pts.aturPerfDataEntry_pt->flags)), ATUR_PERF_LPR_FLAG)){
2793 pts.aturPerfDataEntry_pt->adslAturPerfLprs=ATUR_PERF_LPR;
2794 }
2795 if(IS_FLAG_SET((&(pts.aturPerfDataEntry_pt->flags)), ATUR_PERF_ESS_FLAG)){
2796 pts.aturPerfDataEntry_pt->adslAturPerfESs=ATUR_PERF_ESS;
2797 }
2798 if(IS_FLAG_SET((&(pts.aturPerfDataEntry_pt->flags)), ATUR_PERF_VALID_INTVLS_FLAG)){
2799 i=0;
2800 for(ptr=(current_intvl->list).prev; ptr!=&interval_list; ptr=ptr->prev){
2801 i++;
2802 if(i==96)
2803 break;
2804 }
2805 pts.aturPerfDataEntry_pt->adslAturPerfValidIntervals=i;
2806 }
2807 if(IS_FLAG_SET((&(pts.aturPerfDataEntry_pt->flags)), ATUR_PERF_INVALID_INTVLS_FLAG)){
2808 pts.aturPerfDataEntry_pt->adslAturPerfInvalidIntervals=0;
2809 }
2810 if(IS_FLAG_SET((&(pts.aturPerfDataEntry_pt->flags)), ATUR_PERF_CURR_15MIN_TIME_ELAPSED_FLAG)){
2811 do_gettimeofday(&time_now);
2812 pts.aturPerfDataEntry_pt->adslAturPerfCurr15MinTimeElapsed=time_now.tv_sec - (current_intvl->start_time).tv_sec;
2813 }
2814 if(IS_FLAG_SET((&(pts.aturPerfDataEntry_pt->flags)), ATUR_PERF_CURR_15MIN_LOFS_FLAG)){
2815 pts.aturPerfDataEntry_pt->adslAturPerfCurr15MinLofs=current_intvl->AturPerfLof;
2816 }
2817 if(IS_FLAG_SET((&(pts.aturPerfDataEntry_pt->flags)), ATUR_PERF_CURR_15MIN_LOSS_FLAG)){
2818 pts.aturPerfDataEntry_pt->adslAturPerfCurr15MinLoss=current_intvl->AturPerfLos;
2819 }
2820 if(IS_FLAG_SET((&(pts.aturPerfDataEntry_pt->flags)), ATUR_PERF_CURR_15MIN_LPR_FLAG)){
2821 pts.aturPerfDataEntry_pt->adslAturPerfCurr15MinLprs=current_intvl->AturPerfLpr;
2822 }
2823 if(IS_FLAG_SET((&(pts.aturPerfDataEntry_pt->flags)), ATUR_PERF_CURR_15MIN_ESS_FLAG)){
2824 pts.aturPerfDataEntry_pt->adslAturPerfCurr15MinESs=current_intvl->AturPerfEs;
2825 }
2826 if(IS_FLAG_SET((&(pts.aturPerfDataEntry_pt->flags)), ATUR_PERF_CURR_1DAY_TIME_ELAPSED_FLAG)){
2827 i=0;
2828 for(ptr=(current_intvl->list).prev; ptr!=&interval_list; ptr=ptr->prev){
2829 i+=900;
2830 }
2831 do_gettimeofday(&time_now);
2832 i+=time_now.tv_sec - (current_intvl->start_time).tv_sec;
2833 if(i>=86400)
2834 pts.aturPerfDataEntry_pt->adslAturPerfCurr1DayTimeElapsed=i-86400;
2835 else
2836 pts.aturPerfDataEntry_pt->adslAturPerfCurr1DayTimeElapsed=i;
2837 }
2838 if(IS_FLAG_SET((&(pts.aturPerfDataEntry_pt->flags)), ATUR_PERF_CURR_1DAY_LOFS_FLAG)){
2839 i=0;
2840 j=0;
2841 for(ptr=interval_list.next; ptr!=&(current_intvl->list); ptr=ptr->next){
2842 mib_ptr = list_entry(ptr, amazon_mei_mib, list);
2843 j+=mib_ptr->AturPerfLof;
2844 i++;
2845 if(i==96)
2846 j=0;
2847 }
2848 j+=current_intvl->AturPerfLof;
2849 pts.aturPerfDataEntry_pt->adslAturPerfCurr1DayLofs=j;
2850 }
2851 if(IS_FLAG_SET((&(pts.aturPerfDataEntry_pt->flags)), ATUR_PERF_CURR_1DAY_LOSS_FLAG)){
2852 i=0;
2853 j=0;
2854 for(ptr=interval_list.next; ptr!=&(current_intvl->list); ptr=ptr->next){
2855 mib_ptr = list_entry(ptr, amazon_mei_mib, list);
2856 j+=mib_ptr->AturPerfLos;
2857 i++;
2858 if(i==96)
2859 j=0;
2860 }
2861 j+=current_intvl->AturPerfLos;
2862 pts.aturPerfDataEntry_pt->adslAturPerfCurr1DayLoss=j;
2863 }
2864 if(IS_FLAG_SET((&(pts.aturPerfDataEntry_pt->flags)), ATUR_PERF_CURR_1DAY_LPR_FLAG)){
2865 i=0;
2866 j=0;
2867 for(ptr=interval_list.next; ptr!=&(current_intvl->list); ptr=ptr->next){
2868 mib_ptr = list_entry(ptr, amazon_mei_mib, list);
2869 j+=mib_ptr->AturPerfLpr;
2870 i++;
2871 if(i==96)
2872 j=0;
2873 }
2874 j+=current_intvl->AturPerfLpr;
2875 pts.aturPerfDataEntry_pt->adslAturPerfCurr1DayLprs=j;
2876 }
2877 if(IS_FLAG_SET((&(pts.aturPerfDataEntry_pt->flags)), ATUR_PERF_CURR_1DAY_ESS_FLAG)){
2878 i=0;
2879 j=0;
2880 for(ptr=interval_list.next; ptr!=&(current_intvl->list); ptr=ptr->next){
2881 mib_ptr = list_entry(ptr, amazon_mei_mib, list);
2882 j+=mib_ptr->AturPerfEs;
2883 i++;
2884 if(i==96)
2885 j=0;
2886 }
2887 j+=current_intvl->AturPerfEs;
2888 pts.aturPerfDataEntry_pt->adslAturPerfCurr1DayESs=j;
2889 }
2890 if(IS_FLAG_SET((&(pts.aturPerfDataEntry_pt->flags)), ATUR_PERF_PREV_1DAY_MON_SEC_FLAG)){
2891 i=0;
2892 for(ptr=interval_list.next; ptr!=&(current_intvl->list); ptr=ptr->next){
2893 i++;
2894 }
2895 if(i>=96)
2896 pts.aturPerfDataEntry_pt->adslAturPerfPrev1DayMoniSecs=86400;
2897 else
2898 pts.aturPerfDataEntry_pt->adslAturPerfPrev1DayMoniSecs=0;
2899 }
2900 if(IS_FLAG_SET((&(pts.aturPerfDataEntry_pt->flags)), ATUR_PERF_PREV_1DAY_LOFS_FLAG)){
2901 i=0;
2902 j=0;
2903 for(ptr=interval_list.next; ptr!=&(current_intvl->list); ptr=ptr->next){
2904 mib_ptr = list_entry(ptr, amazon_mei_mib, list);
2905 j+=mib_ptr->AturPerfLof;
2906 i++;
2907 if(i==96)
2908 break;
2909 }
2910 if(i==96)
2911 pts.aturPerfDataEntry_pt->adslAturPerfPrev1DayLofs=j;
2912 else
2913 pts.aturPerfDataEntry_pt->adslAturPerfPrev1DayLofs=0;
2914 }
2915 if(IS_FLAG_SET((&(pts.aturPerfDataEntry_pt->flags)), ATUR_PERF_PREV_1DAY_LOSS_FLAG)){
2916 i=0;
2917 j=0;
2918 for(ptr=interval_list.next; ptr!=&(current_intvl->list); ptr=ptr->next){
2919 mib_ptr = list_entry(ptr, amazon_mei_mib, list);
2920 j+=mib_ptr->AturPerfLos;
2921 i++;
2922 if(i==96)
2923 break;
2924 }
2925 if(i==96)
2926 pts.aturPerfDataEntry_pt->adslAturPerfPrev1DayLoss=j;
2927 else
2928 pts.aturPerfDataEntry_pt->adslAturPerfPrev1DayLoss=0;
2929 }
2930 if(IS_FLAG_SET((&(pts.aturPerfDataEntry_pt->flags)), ATUR_PERF_PREV_1DAY_LPR_FLAG)){
2931 i=0;
2932 j=0;
2933 for(ptr=interval_list.next; ptr!=&(current_intvl->list); ptr=ptr->next){
2934 mib_ptr = list_entry(ptr, amazon_mei_mib, list);
2935 j+=mib_ptr->AturPerfLpr;
2936 i++;
2937 if(i==96)
2938 break;
2939 }
2940 if(i==96)
2941 pts.aturPerfDataEntry_pt->adslAturPerfPrev1DayLprs=j;
2942 else
2943 pts.aturPerfDataEntry_pt->adslAturPerfPrev1DayLprs=0;
2944 }
2945 if(IS_FLAG_SET((&(pts.aturPerfDataEntry_pt->flags)), ATUR_PERF_PREV_1DAY_ESS_FLAG)){
2946 i=0;
2947 j=0;
2948 for(ptr=interval_list.next; ptr!=&(current_intvl->list); ptr=ptr->next){
2949 mib_ptr = list_entry(ptr, amazon_mei_mib, list);
2950 j+=mib_ptr->AturPerfEs;
2951 i++;
2952 if(i==96)
2953 break;
2954 }
2955 if(i==96)
2956 pts.aturPerfDataEntry_pt->adslAturPerfPrev1DayESs=j;
2957 else
2958 pts.aturPerfDataEntry_pt->adslAturPerfPrev1DayESs=0;
2959 }
2960
2961 copy_to_user((char *)lon, (char *)pts.aturPerfDataEntry_pt, sizeof(aturPerfDataEntry));
2962 kfree(pts.aturPerfDataEntry_pt);
2963 break;
2964 #ifdef AMAZON_MEI_MIB_RFC3440
2965 case GET_ADSL_ATUR_PERF_DATA_EXT:
2966 pts.aturPerfDataExtEntry_pt = (aturPerfDataExtEntry *)kmalloc(sizeof(aturPerfDataExtEntry), GFP_KERNEL);
2967 copy_from_user((char *)pts.aturPerfDataExtEntry_pt, (char *)lon, sizeof(aturPerfDataExtEntry));
2968 if(IS_FLAG_SET((&(pts.aturPerfDataExtEntry_pt->flags)), ATUR_PERF_STAT_SESL_FLAG)){
2969 pts.aturPerfDataExtEntry_pt->adslAturPerfStatSesL=ATUR_PERF_STAT_SESL;
2970 }
2971 if(IS_FLAG_SET((&(pts.aturPerfDataExtEntry_pt->flags)), ATUR_PERF_STAT_UASL_FLAG)){
2972 pts.aturPerfDataExtEntry_pt->adslAturPerfStatUasL=ATUR_PERF_STAT_UASL;
2973 }
2974 if(IS_FLAG_SET((&(pts.aturPerfDataExtEntry_pt->flags)), ATUR_PERF_CURR_15MIN_SESL_FLAG)){
2975 pts.aturPerfDataExtEntry_pt->adslAturPerfCurr15MinSesL=current_intvl->AturPerfStatSesL;
2976 }
2977 if(IS_FLAG_SET((&(pts.aturPerfDataExtEntry_pt->flags)), ATUR_PERF_CURR_15MIN_UASL_FLAG)){
2978 pts.aturPerfDataExtEntry_pt->adslAturPerfCurr15MinUasL=current_intvl->AturPerfStatUasL;
2979 }
2980 if(IS_FLAG_SET((&(pts.aturPerfDataExtEntry_pt->flags)), ATUR_PERF_CURR_1DAY_SESL_FLAG)){
2981 i=0;
2982 j=0;
2983 for(ptr=interval_list.next; ptr!=&(current_intvl->list); ptr=ptr->next){
2984 mib_ptr = list_entry(ptr, amazon_mei_mib, list);
2985 j+=mib_ptr->AturPerfStatSesL;
2986 i++;
2987 if(i==96)
2988 j=0;
2989 }
2990 j+=current_intvl->AturPerfStatSesL;
2991 pts.aturPerfDataExtEntry_pt->adslAturPerfCurr1DaySesL=j;
2992 }
2993 if(IS_FLAG_SET((&(pts.aturPerfDataExtEntry_pt->flags)), ATUR_PERF_CURR_1DAY_UASL_FLAG)){
2994 i=0;
2995 j=0;
2996 for(ptr=interval_list.next; ptr!=&(current_intvl->list); ptr=ptr->next){
2997 mib_ptr = list_entry(ptr, amazon_mei_mib, list);
2998 j+=mib_ptr->AturPerfStatUasL;
2999 i++;
3000 if(i==96)
3001 j=0;
3002 }
3003 j+=current_intvl->AturPerfStatUasL;
3004 pts.aturPerfDataExtEntry_pt->adslAturPerfCurr1DayUasL=j;
3005 }
3006 if(IS_FLAG_SET((&(pts.aturPerfDataExtEntry_pt->flags)), ATUR_PERF_PREV_1DAY_SESL_FLAG)){
3007 i=0;
3008 j=0;
3009 for(ptr=interval_list.next; ptr!=&(current_intvl->list); ptr=ptr->next){
3010 mib_ptr = list_entry(ptr, amazon_mei_mib, list);
3011 j+=mib_ptr->AturPerfStatSesL;
3012 i++;
3013 if(i==96)
3014 break;
3015 }
3016 if(i==96)
3017 pts.aturPerfDataExtEntry_pt->adslAturPerfPrev1DaySesL=j;
3018 else
3019 pts.aturPerfDataExtEntry_pt->adslAturPerfPrev1DaySesL=0;
3020 }
3021 if(IS_FLAG_SET((&(pts.aturPerfDataExtEntry_pt->flags)), ATUR_PERF_PREV_1DAY_UASL_FLAG)){
3022 i=0;
3023 j=0;
3024 for(ptr=interval_list.next; ptr!=&(current_intvl->list); ptr=ptr->next){
3025 mib_ptr = list_entry(ptr, amazon_mei_mib, list);
3026 j+=mib_ptr->AturPerfStatUasL;
3027 i++;
3028 if(i==96)
3029 break;
3030 }
3031 if(i==96)
3032 pts.aturPerfDataExtEntry_pt->adslAturPerfPrev1DayUasL=j;
3033 else
3034 pts.aturPerfDataExtEntry_pt->adslAturPerfPrev1DayUasL=0;
3035 }
3036 copy_to_user((char *)lon, (char *)pts.aturPerfDataExtEntry_pt, sizeof(aturPerfDataExtEntry));
3037 kfree(pts.aturPerfDataExtEntry_pt);
3038 break;
3039 #endif
3040 case GET_ADSL_ATUC_INTVL_INFO:
3041 pts.adslAtucIntvlInfo_pt = (adslAtucIntvlInfo *)kmalloc(sizeof(adslAtucIntvlInfo), GFP_KERNEL);
3042 copy_from_user((char *)pts.adslAtucIntvlInfo_pt, (char *)lon, sizeof(adslAtucIntvlInfo));
3043
3044 if(pts.adslAtucIntvlInfo_pt->IntervalNumber <1){
3045 pts.adslAtucIntvlInfo_pt->intervalLOF = ATUC_PERF_LOFS;
3046 pts.adslAtucIntvlInfo_pt->intervalLOS = ATUC_PERF_LOSS;
3047 pts.adslAtucIntvlInfo_pt->intervalES = ATUC_PERF_ESS;
3048 pts.adslAtucIntvlInfo_pt->intervalInits = ATUC_PERF_INITS;
3049 pts.adslAtucIntvlInfo_pt->intervalValidData = 1;
3050 }
3051 else{
3052 i=0;
3053 for(ptr=(current_intvl->list).prev; ptr!=&interval_list; ptr=ptr->prev){
3054 i++;
3055 if(i==pts.adslAtucIntvlInfo_pt->IntervalNumber){
3056 temp_intvl = list_entry(ptr, amazon_mei_mib, list);
3057 pts.adslAtucIntvlInfo_pt->intervalLOF = temp_intvl->AtucPerfLof;
3058 pts.adslAtucIntvlInfo_pt->intervalLOS = temp_intvl->AtucPerfLos;
3059 pts.adslAtucIntvlInfo_pt->intervalES = temp_intvl->AtucPerfEs;
3060 pts.adslAtucIntvlInfo_pt->intervalInits = temp_intvl->AtucPerfInit;
3061 pts.adslAtucIntvlInfo_pt->intervalValidData = 1;
3062 break;
3063 }
3064 }
3065 if(ptr==&interval_list){
3066 pts.adslAtucIntvlInfo_pt->intervalValidData = 0;
3067 pts.adslAtucIntvlInfo_pt->flags = 0;
3068 pts.adslAtucIntvlInfo_pt->intervalLOF = 0;
3069 pts.adslAtucIntvlInfo_pt->intervalLOS = 0;
3070 pts.adslAtucIntvlInfo_pt->intervalES = 0;
3071 pts.adslAtucIntvlInfo_pt->intervalInits = 0;
3072 }
3073 }
3074
3075 copy_to_user((char *)lon, (char *)pts.adslAtucIntvlInfo_pt, sizeof(adslAtucIntvlInfo));
3076 kfree(pts.adslAtucIntvlInfo_pt);
3077 break;
3078 #ifdef AMAZON_MEI_MIB_RFC3440
3079 case GET_ADSL_ATUC_INTVL_EXT_INFO:
3080 pts.adslAtucInvtlExtInfo_pt = (adslAtucInvtlExtInfo *)kmalloc(sizeof(adslAtucInvtlExtInfo), GFP_KERNEL);
3081 copy_from_user((char *)pts.adslAtucInvtlExtInfo_pt, (char *)lon, sizeof(adslAtucInvtlExtInfo));
3082 if(pts.adslAtucInvtlExtInfo_pt->IntervalNumber <1){
3083 pts.adslAtucInvtlExtInfo_pt->adslAtucIntervalFastR = ATUC_PERF_STAT_FASTR;
3084 pts.adslAtucInvtlExtInfo_pt->adslAtucIntervalFailedFastR = ATUC_PERF_STAT_FAILED_FASTR;
3085 pts.adslAtucInvtlExtInfo_pt->adslAtucIntervalSesL = ATUC_PERF_STAT_SESL;
3086 pts.adslAtucInvtlExtInfo_pt->adslAtucIntervalUasL = ATUC_PERF_STAT_UASL;
3087 // pts.adslAtucInvtlExtInfo_pt->intervalValidData = 1;
3088 }
3089 else{
3090 i=0;
3091 for(ptr=(current_intvl->list).prev; ptr!=&interval_list; ptr=ptr->prev){
3092 i++;
3093 if(i==pts.adslAtucInvtlExtInfo_pt->IntervalNumber){
3094 temp_intvl = list_entry(ptr, amazon_mei_mib, list);
3095 pts.adslAtucInvtlExtInfo_pt->adslAtucIntervalFastR = temp_intvl->AtucPerfStatFastR;
3096 pts.adslAtucInvtlExtInfo_pt->adslAtucIntervalFailedFastR = temp_intvl->AtucPerfStatFailedFastR;
3097 pts.adslAtucInvtlExtInfo_pt->adslAtucIntervalSesL = temp_intvl->AtucPerfStatSesL;
3098 pts.adslAtucInvtlExtInfo_pt->adslAtucIntervalUasL = temp_intvl->AtucPerfStatUasL;
3099 // pts.adslAtucInvtlExtInfo_pt->intervalValidData = 1;
3100 break;
3101 }
3102 }
3103 if(ptr==&interval_list){
3104 // pts.adslAtucInvtlExtInfo_pt->intervalValidData = 0;
3105 pts.adslAtucInvtlExtInfo_pt->flags = 0;
3106 pts.adslAtucInvtlExtInfo_pt->adslAtucIntervalFastR = 0;
3107 pts.adslAtucInvtlExtInfo_pt->adslAtucIntervalFailedFastR = 0;
3108 pts.adslAtucInvtlExtInfo_pt->adslAtucIntervalSesL = 0;
3109 pts.adslAtucInvtlExtInfo_pt->adslAtucIntervalUasL = 0;
3110 }
3111 }
3112 copy_to_user((char *)lon, (char *)pts.adslAtucInvtlExtInfo_pt, sizeof(adslAtucInvtlExtInfo));
3113 kfree(pts.adslAtucInvtlExtInfo_pt);
3114 break;
3115 #endif
3116 case GET_ADSL_ATUR_INTVL_INFO:
3117 pts.adslAturIntvlInfo_pt = (adslAturIntvlInfo *)kmalloc(sizeof(adslAturIntvlInfo), GFP_KERNEL);
3118 copy_from_user((char *)pts.adslAturIntvlInfo_pt, (char *)lon, sizeof(adslAturIntvlInfo));
3119
3120 if(pts.adslAturIntvlInfo_pt->IntervalNumber <1){
3121 pts.adslAturIntvlInfo_pt->intervalLOF = ATUR_PERF_LOFS;
3122 pts.adslAturIntvlInfo_pt->intervalLOS = ATUR_PERF_LOSS;
3123 pts.adslAturIntvlInfo_pt->intervalES = ATUR_PERF_ESS;
3124 pts.adslAturIntvlInfo_pt->intervalLPR = ATUR_PERF_LPR;
3125 pts.adslAturIntvlInfo_pt->intervalValidData = 1;
3126 }
3127 else{
3128 i=0;
3129 for(ptr=(current_intvl->list).prev; ptr!=&interval_list; ptr=ptr->prev){
3130 i++;
3131 if(i==pts.adslAturIntvlInfo_pt->IntervalNumber){
3132 temp_intvl = list_entry(ptr, amazon_mei_mib, list);
3133 pts.adslAturIntvlInfo_pt->intervalLOF = temp_intvl->AturPerfLof;
3134 pts.adslAturIntvlInfo_pt->intervalLOS = temp_intvl->AturPerfLos;
3135 pts.adslAturIntvlInfo_pt->intervalES = temp_intvl->AturPerfEs;
3136 pts.adslAturIntvlInfo_pt->intervalLPR = temp_intvl->AturPerfLpr;
3137 pts.adslAturIntvlInfo_pt->intervalValidData = 1;
3138 break;
3139 }
3140 }
3141 if(ptr==&interval_list){
3142 pts.adslAturIntvlInfo_pt->intervalValidData = 0;
3143 pts.adslAturIntvlInfo_pt->flags = 0;
3144 pts.adslAturIntvlInfo_pt->intervalLOF = 0;
3145 pts.adslAturIntvlInfo_pt->intervalLOS = 0;
3146 pts.adslAturIntvlInfo_pt->intervalES = 0;
3147 pts.adslAturIntvlInfo_pt->intervalLPR = 0;
3148 }
3149 }
3150
3151 copy_to_user((char *)lon, (char *)pts.adslAturIntvlInfo_pt, sizeof(adslAturIntvlInfo));
3152 kfree(pts.adslAturIntvlInfo_pt);
3153 break;
3154 #ifdef AMAZON_MEI_MIB_RFC3440
3155 case GET_ADSL_ATUR_INTVL_EXT_INFO:
3156 pts.adslAturInvtlExtInfo_pt = (adslAturInvtlExtInfo *)kmalloc(sizeof(adslAturInvtlExtInfo), GFP_KERNEL);
3157 copy_from_user((char *)pts.adslAturInvtlExtInfo_pt, (char *)lon, sizeof(adslAturInvtlExtInfo));
3158
3159 if(pts.adslAturInvtlExtInfo_pt->IntervalNumber <1){
3160 pts.adslAturInvtlExtInfo_pt->adslAturIntervalSesL = ATUR_PERF_STAT_SESL;
3161 pts.adslAturInvtlExtInfo_pt->adslAturIntervalUasL = ATUR_PERF_STAT_UASL;
3162 // pts.adslAturInvtlExtInfo_pt->intervalValidData = 1;
3163 }
3164 else{
3165 i=0;
3166 for(ptr=(current_intvl->list).prev; ptr!=&interval_list; ptr=ptr->prev){
3167 i++;
3168 if(i==pts.adslAturInvtlExtInfo_pt->IntervalNumber){
3169 temp_intvl = list_entry(ptr, amazon_mei_mib, list);
3170 pts.adslAturInvtlExtInfo_pt->adslAturIntervalSesL = temp_intvl->AturPerfStatSesL;
3171 pts.adslAturInvtlExtInfo_pt->adslAturIntervalUasL = temp_intvl->AturPerfStatUasL;
3172 // pts.adslAturInvtlExtInfo_pt->intervalValidData = 1;
3173 break;
3174 }
3175 }
3176 if(ptr==&interval_list){
3177 // pts.adslAturInvtlExtInfo_pt->intervalValidData = 0;
3178 pts.adslAturInvtlExtInfo_pt->flags = 0;
3179 pts.adslAturInvtlExtInfo_pt->adslAturIntervalSesL = 0;
3180 pts.adslAturInvtlExtInfo_pt->adslAturIntervalUasL = 0;
3181 }
3182 }
3183
3184 copy_to_user((char *)lon, (char *)pts.adslAturInvtlExtInfo_pt, sizeof(adslAturInvtlExtInfo));
3185 kfree(pts.adslAturInvtlExtInfo_pt);
3186 break;
3187 #endif
3188 case GET_ADSL_ATUC_CHAN_PERF_DATA:
3189 pts.atucChannelPerfDataEntry_pt = (atucChannelPerfDataEntry *)kmalloc(sizeof(atucChannelPerfDataEntry), GFP_KERNEL);
3190 copy_from_user((char *)pts.atucChannelPerfDataEntry_pt, (char *)lon, sizeof(atucChannelPerfDataEntry));
3191
3192 pts.atucChannelPerfDataEntry_pt->flags = 0;
3193
3194 copy_to_user((char *)lon, (char *)pts.atucChannelPerfDataEntry_pt, sizeof(atucChannelPerfDataEntry));
3195 kfree(pts.atucChannelPerfDataEntry_pt);
3196 break;
3197 case GET_ADSL_ATUR_CHAN_PERF_DATA:
3198 pts.aturChannelPerfDataEntry_pt = (aturChannelPerfDataEntry *)kmalloc(sizeof(aturChannelPerfDataEntry), GFP_KERNEL);
3199 copy_from_user((char *)pts.aturChannelPerfDataEntry_pt, (char *)lon, sizeof(aturChannelPerfDataEntry));
3200 if(IS_FLAG_SET((&(pts.aturChannelPerfDataEntry_pt->flags)), ATUR_CHAN_RECV_BLK_FLAG)){
3201 pts.aturChannelPerfDataEntry_pt->adslAturChanReceivedBlks=ATUR_CHAN_RECV_BLK;
3202 }
3203 if(IS_FLAG_SET((&(pts.aturChannelPerfDataEntry_pt->flags)), ATUR_CHAN_TX_BLK_FLAG)){
3204 pts.aturChannelPerfDataEntry_pt->adslAturChanTransmittedBlks=ATUR_CHAN_TX_BLK;
3205 }
3206 if(IS_FLAG_SET((&(pts.aturChannelPerfDataEntry_pt->flags)), ATUR_CHAN_CORR_BLK_FLAG)){
3207 pts.aturChannelPerfDataEntry_pt->adslAturChanCorrectedBlks=ATUR_CHAN_CORR_BLK;
3208 }
3209 if(IS_FLAG_SET((&(pts.aturChannelPerfDataEntry_pt->flags)), ATUR_CHAN_UNCORR_BLK_FLAG)){
3210 pts.aturChannelPerfDataEntry_pt->adslAturChanUncorrectBlks=ATUR_CHAN_UNCORR_BLK;
3211 }
3212 if(IS_FLAG_SET((&(pts.aturChannelPerfDataEntry_pt->flags)), ATUR_CHAN_PERF_VALID_INTVL_FLAG)){
3213 i=0;
3214 for(ptr=(current_intvl->list).prev; ptr!=&interval_list; ptr=ptr->prev){
3215 i++;
3216 if(i==96)
3217 break;
3218 }
3219 pts.aturChannelPerfDataEntry_pt->adslAturChanPerfValidIntervals=i;
3220 }
3221 if(IS_FLAG_SET((&(pts.aturChannelPerfDataEntry_pt->flags)), ATUR_CHAN_PERF_INVALID_INTVL_FLAG)){
3222 pts.aturChannelPerfDataEntry_pt->adslAturChanPerfInvalidIntervals=0;
3223 }
3224 if(IS_FLAG_SET((&(pts.aturChannelPerfDataEntry_pt->flags)), ATUR_CHAN_PERF_CURR_15MIN_TIME_ELAPSED_FLAG)){
3225 do_gettimeofday(&time_now);
3226 pts.aturChannelPerfDataEntry_pt->adslAturChanPerfCurr15MinTimeElapsed=time_now.tv_sec - (current_intvl->start_time).tv_sec;
3227 }
3228 if(IS_FLAG_SET((&(pts.aturChannelPerfDataEntry_pt->flags)), ATUR_CHAN_PERF_CURR_15MIN_RECV_BLK_FLAG)){
3229 pts.aturChannelPerfDataEntry_pt->adslAturChanPerfCurr15MinReceivedBlks=current_intvl->AturChanPerfRxBlk;
3230 }
3231 if(IS_FLAG_SET((&(pts.aturChannelPerfDataEntry_pt->flags)), ATUR_CHAN_PERF_CURR_15MIN_TX_BLK_FLAG)){
3232 pts.aturChannelPerfDataEntry_pt->adslAturChanPerfCurr15MinTransmittedBlks=current_intvl->AturChanPerfTxBlk;
3233 }
3234 if(IS_FLAG_SET((&(pts.aturChannelPerfDataEntry_pt->flags)), ATUR_CHAN_PERF_CURR_15MIN_CORR_BLK_FLAG)){
3235 pts.aturChannelPerfDataEntry_pt->adslAturChanPerfCurr15MinCorrectedBlks=current_intvl->AturChanPerfCorrBlk;
3236 }
3237 if(IS_FLAG_SET((&(pts.aturChannelPerfDataEntry_pt->flags)), ATUR_CHAN_PERF_CURR_15MIN_UNCORR_BLK_FLAG)){
3238 pts.aturChannelPerfDataEntry_pt->adslAturChanPerfCurr15MinUncorrectBlks=current_intvl->AturChanPerfUncorrBlk;
3239 }
3240 if(IS_FLAG_SET((&(pts.aturChannelPerfDataEntry_pt->flags)), ATUR_CHAN_PERF_CURR_1DAY_TIME_ELAPSED_FLAG)){
3241 i=0;
3242 for(ptr=(current_intvl->list).prev; ptr!=&interval_list; ptr=ptr->prev){
3243 i+=900;
3244 }
3245 do_gettimeofday(&time_now);
3246 i+=time_now.tv_sec - (current_intvl->start_time).tv_sec;
3247 if(i>=86400)
3248 pts.aturChannelPerfDataEntry_pt->adslAturChanPerfCurr1DayTimeElapsed=i-86400;
3249 else
3250 pts.aturChannelPerfDataEntry_pt->adslAturChanPerfCurr1DayTimeElapsed=i;
3251 }
3252 if(IS_FLAG_SET((&(pts.aturChannelPerfDataEntry_pt->flags)), ATUR_CHAN_PERF_CURR_1DAY_RECV_BLK_FLAG)){
3253 i=0;
3254 j=0;
3255 for(ptr=interval_list.next; ptr!=&(current_intvl->list); ptr=ptr->next){
3256 mib_ptr = list_entry(ptr, amazon_mei_mib, list);
3257 j+=mib_ptr->AturChanPerfRxBlk;
3258 i++;
3259 if(i==96)
3260 j=0;
3261 }
3262 j+=current_intvl->AturChanPerfRxBlk;
3263 pts.aturChannelPerfDataEntry_pt->adslAturChanPerfCurr1DayReceivedBlks=j;
3264 }
3265 if(IS_FLAG_SET((&(pts.aturChannelPerfDataEntry_pt->flags)), ATUR_CHAN_PERF_CURR_1DAY_TX_BLK_FLAG)){
3266 i=0;
3267 j=0;
3268 for(ptr=interval_list.next; ptr!=&(current_intvl->list); ptr=ptr->next){
3269 mib_ptr = list_entry(ptr, amazon_mei_mib, list);
3270 j+=mib_ptr->AturChanPerfTxBlk;
3271 i++;
3272 if(i==96)
3273 j=0;
3274 }
3275 j+=current_intvl->AturChanPerfTxBlk;
3276 pts.aturChannelPerfDataEntry_pt->adslAturChanPerfCurr1DayTransmittedBlks=j;
3277 }
3278 if(IS_FLAG_SET((&(pts.aturChannelPerfDataEntry_pt->flags)), ATUR_CHAN_PERF_CURR_1DAY_CORR_BLK_FLAG)){
3279 i=0;
3280 j=0;
3281 for(ptr=interval_list.next; ptr!=&(current_intvl->list); ptr=ptr->next){
3282 mib_ptr = list_entry(ptr, amazon_mei_mib, list);
3283 j+=mib_ptr->AturChanPerfCorrBlk;
3284 i++;
3285 if(i==96)
3286 j=0;
3287 }
3288 j+=current_intvl->AturChanPerfCorrBlk;
3289 pts.aturChannelPerfDataEntry_pt->adslAturChanPerfCurr1DayCorrectedBlks=j;
3290 }
3291 if(IS_FLAG_SET((&(pts.aturChannelPerfDataEntry_pt->flags)), ATUR_CHAN_PERF_CURR_1DAY_UNCORR_BLK_FLAG)){
3292 i=0;
3293 j=0;
3294 for(ptr=interval_list.next; ptr!=&(current_intvl->list); ptr=ptr->next){
3295 mib_ptr = list_entry(ptr, amazon_mei_mib, list);
3296 j+=mib_ptr->AturChanPerfUncorrBlk;
3297 i++;
3298 if(i==96)
3299 j=0;
3300 }
3301 j+=current_intvl->AturChanPerfUncorrBlk;
3302 pts.aturChannelPerfDataEntry_pt->adslAturChanPerfCurr1DayUncorrectBlks=j;
3303 }
3304 if(IS_FLAG_SET((&(pts.aturChannelPerfDataEntry_pt->flags)), ATUR_CHAN_PERF_PREV_1DAY_MONI_SEC_FLAG)){
3305 i=0;
3306 for(ptr=interval_list.next; ptr!=&(current_intvl->list); ptr=ptr->next){
3307 i++;
3308 }
3309 if(i>=96)
3310 pts.aturChannelPerfDataEntry_pt->adslAturChanPerfPrev1DayMoniSecs=86400;
3311 else
3312 pts.aturChannelPerfDataEntry_pt->adslAturChanPerfPrev1DayMoniSecs=0;
3313 }
3314 if(IS_FLAG_SET((&(pts.aturChannelPerfDataEntry_pt->flags)), ATUR_CHAN_PERF_PREV_1DAY_RECV_BLK_FLAG)){
3315 i=0;
3316 j=0;
3317 for(ptr=interval_list.next; ptr!=&(current_intvl->list); ptr=ptr->next){
3318 mib_ptr = list_entry(ptr, amazon_mei_mib, list);
3319 j+=mib_ptr->AturChanPerfRxBlk;
3320 i++;
3321 if(i==96)
3322 break;
3323 }
3324 if(i==96)
3325 pts.aturChannelPerfDataEntry_pt->adslAturChanPerfPrev1DayReceivedBlks=j;
3326 else
3327 pts.aturChannelPerfDataEntry_pt->adslAturChanPerfPrev1DayReceivedBlks=0;
3328 }
3329 if(IS_FLAG_SET((&(pts.aturChannelPerfDataEntry_pt->flags)), ATUR_CHAN_PERF_PREV_1DAY_TRANS_BLK_FLAG)){
3330 i=0;
3331 j=0;
3332 for(ptr=interval_list.next; ptr!=&(current_intvl->list); ptr=ptr->next){
3333 mib_ptr = list_entry(ptr, amazon_mei_mib, list);
3334 j+=mib_ptr->AturChanPerfTxBlk;
3335 i++;
3336 if(i==96)
3337 break;
3338 }
3339 if(i==96)
3340 pts.aturChannelPerfDataEntry_pt->adslAturChanPerfPrev1DayTransmittedBlks=j;
3341 else
3342 pts.aturChannelPerfDataEntry_pt->adslAturChanPerfPrev1DayTransmittedBlks=0;
3343 }
3344 if(IS_FLAG_SET((&(pts.aturChannelPerfDataEntry_pt->flags)), ATUR_CHAN_PERF_PREV_1DAY_CORR_BLK_FLAG)){
3345 i=0;
3346 j=0;
3347 for(ptr=interval_list.next; ptr!=&(current_intvl->list); ptr=ptr->next){
3348 mib_ptr = list_entry(ptr, amazon_mei_mib, list);
3349 j+=mib_ptr->AturChanPerfCorrBlk;
3350 i++;
3351 if(i==96)
3352 break;
3353 }
3354 if(i==96)
3355 pts.aturChannelPerfDataEntry_pt->adslAturChanPerfPrev1DayCorrectedBlks=j;
3356 else
3357 pts.aturChannelPerfDataEntry_pt->adslAturChanPerfPrev1DayCorrectedBlks=0;
3358 }
3359 if(IS_FLAG_SET((&(pts.aturChannelPerfDataEntry_pt->flags)), ATUR_CHAN_PERF_PREV_1DAY_UNCORR_BLK_FLAG)){
3360 i=0;
3361 j=0;
3362 for(ptr=interval_list.next; ptr!=&(current_intvl->list); ptr=ptr->next){
3363 mib_ptr = list_entry(ptr, amazon_mei_mib, list);
3364 j+=mib_ptr->AturChanPerfUncorrBlk;
3365 i++;
3366 if(i==96)
3367 break;
3368 }
3369 if(i==96)
3370 pts.aturChannelPerfDataEntry_pt->adslAturChanPerfPrev1DayUncorrectBlks=j;
3371 else
3372 pts.aturChannelPerfDataEntry_pt->adslAturChanPerfPrev1DayUncorrectBlks=0;
3373 }
3374
3375 copy_to_user((char *)lon, (char *)pts.aturChannelPerfDataEntry_pt, sizeof(aturChannelPerfDataEntry));
3376 kfree(pts.aturChannelPerfDataEntry_pt);
3377 break;
3378 case GET_ADSL_ATUC_CHAN_INTVL_INFO:
3379 pts.adslAtucChanIntvlInfo_pt = (adslAtucChanIntvlInfo *)kmalloc(sizeof(adslAtucChanIntvlInfo), GFP_KERNEL);
3380 copy_from_user((char *)pts.adslAtucChanIntvlInfo_pt, (char *)lon, sizeof(adslAtucChanIntvlInfo));
3381
3382 pts.adslAtucChanIntvlInfo_pt->flags = 0;
3383
3384 copy_to_user((char *)lon, (char *)pts.adslAtucChanIntvlInfo_pt, sizeof(adslAtucChanIntvlInfo));
3385 kfree(pts.adslAtucChanIntvlInfo_pt);
3386 break;
3387 case GET_ADSL_ATUR_CHAN_INTVL_INFO:
3388 pts.adslAturChanIntvlInfo_pt = (adslAturChanIntvlInfo *)kmalloc(sizeof(adslAturChanIntvlInfo), GFP_KERNEL);
3389 copy_from_user((char *)pts.adslAturChanIntvlInfo_pt, (char *)lon, sizeof(adslAturChanIntvlInfo));
3390
3391 if(pts.adslAturChanIntvlInfo_pt->IntervalNumber <1){
3392 pts.adslAturChanIntvlInfo_pt->chanIntervalRecvdBlks = ATUR_CHAN_RECV_BLK;
3393 pts.adslAturChanIntvlInfo_pt->chanIntervalXmitBlks = ATUR_CHAN_TX_BLK;
3394 pts.adslAturChanIntvlInfo_pt->chanIntervalCorrectedBlks = ATUR_CHAN_CORR_BLK;
3395 pts.adslAturChanIntvlInfo_pt->chanIntervalUncorrectBlks = ATUR_CHAN_UNCORR_BLK;
3396 pts.adslAturChanIntvlInfo_pt->intervalValidData = 1;
3397 }
3398 else{
3399 i=0;
3400 for(ptr=(current_intvl->list).prev; ptr!=&interval_list; ptr=ptr->prev){
3401 i++;
3402 if(i==pts.adslAturChanIntvlInfo_pt->IntervalNumber){
3403 temp_intvl = list_entry(ptr, amazon_mei_mib, list);
3404 pts.adslAturChanIntvlInfo_pt->chanIntervalRecvdBlks = temp_intvl->AturChanPerfRxBlk;
3405 pts.adslAturChanIntvlInfo_pt->chanIntervalXmitBlks = temp_intvl->AturChanPerfTxBlk;
3406 pts.adslAturChanIntvlInfo_pt->chanIntervalCorrectedBlks = temp_intvl->AturChanPerfCorrBlk;
3407 pts.adslAturChanIntvlInfo_pt->chanIntervalUncorrectBlks = temp_intvl->AturChanPerfUncorrBlk;
3408 pts.adslAturChanIntvlInfo_pt->intervalValidData = 1;
3409 break;
3410 }
3411 }
3412 if(ptr==&interval_list){
3413 pts.adslAturChanIntvlInfo_pt->intervalValidData = 0;
3414 pts.adslAturChanIntvlInfo_pt->flags = 0;
3415 }
3416 }
3417
3418 copy_to_user((char *)lon, (char *)pts.adslAturChanIntvlInfo_pt, sizeof(adslAturChanIntvlInfo));
3419 kfree(pts.adslAturChanIntvlInfo_pt);
3420 break;
3421 case GET_ADSL_ALRM_CONF_PROF:
3422 pts.adslLineAlarmConfProfileEntry_pt = (adslLineAlarmConfProfileEntry *)kmalloc(sizeof(adslLineAlarmConfProfileEntry), GFP_KERNEL);
3423 copy_from_user((char *)pts.adslLineAlarmConfProfileEntry_pt, (char *)lon, sizeof(adslLineAlarmConfProfileEntry));
3424
3425 strncpy(pts.adslLineAlarmConfProfileEntry_pt->adslLineAlarmConfProfileName, AlarmConfProfile.adslLineAlarmConfProfileName, 32);
3426 if(IS_FLAG_SET((&(pts.adslLineAlarmConfProfileEntry_pt->flags)), ATUC_THRESH_15MIN_LOFS_FLAG)){
3427 pts.adslLineAlarmConfProfileEntry_pt->adslAtucThresh15MinLofs=AlarmConfProfile.adslAtucThresh15MinLofs;
3428 }
3429 if(IS_FLAG_SET((&(pts.adslLineAlarmConfProfileEntry_pt->flags)), ATUC_THRESH_15MIN_LOSS_FLAG)){
3430 pts.adslLineAlarmConfProfileEntry_pt->adslAtucThresh15MinLoss=AlarmConfProfile.adslAtucThresh15MinLoss;
3431 }
3432 if(IS_FLAG_SET((&(pts.adslLineAlarmConfProfileEntry_pt->flags)), ATUC_THRESH_15MIN_ESS_FLAG)){
3433 pts.adslLineAlarmConfProfileEntry_pt->adslAtucThresh15MinESs=AlarmConfProfile.adslAtucThresh15MinESs;
3434 }
3435 if(IS_FLAG_SET((&(pts.adslLineAlarmConfProfileEntry_pt->flags)), ATUC_THRESH_FAST_RATEUP_FLAG)){
3436 pts.adslLineAlarmConfProfileEntry_pt->adslAtucThreshFastRateUp=AlarmConfProfile.adslAtucThreshFastRateUp;
3437 }
3438 if(IS_FLAG_SET((&(pts.adslLineAlarmConfProfileEntry_pt->flags)), ATUC_THRESH_INTERLEAVE_RATEUP_FLAG)){
3439 pts.adslLineAlarmConfProfileEntry_pt->adslAtucThreshInterleaveRateUp=AlarmConfProfile.adslAtucThreshInterleaveRateUp;
3440 }
3441 if(IS_FLAG_SET((&(pts.adslLineAlarmConfProfileEntry_pt->flags)), ATUC_THRESH_FAST_RATEDOWN_FLAG)){
3442 pts.adslLineAlarmConfProfileEntry_pt->adslAtucThreshFastRateDown=AlarmConfProfile.adslAtucThreshFastRateDown;
3443 }
3444 if(IS_FLAG_SET((&(pts.adslLineAlarmConfProfileEntry_pt->flags)), ATUC_THRESH_INTERLEAVE_RATEDOWN_FLAG)){
3445 pts.adslLineAlarmConfProfileEntry_pt->adslAtucThreshInterleaveRateDown=AlarmConfProfile.adslAtucThreshInterleaveRateDown;
3446 }
3447 if(IS_FLAG_SET((&(pts.adslLineAlarmConfProfileEntry_pt->flags)), ATUC_INIT_FAILURE_TRAP_ENABLE_FLAG)){
3448 pts.adslLineAlarmConfProfileEntry_pt->adslAtucInitFailureTrapEnable=AlarmConfProfile.adslAtucInitFailureTrapEnable;
3449 }
3450 if(IS_FLAG_SET((&(pts.adslLineAlarmConfProfileEntry_pt->flags)), ATUR_THRESH_15MIN_LOFS_FLAG)){
3451 pts.adslLineAlarmConfProfileEntry_pt->adslAturThresh15MinLofs=AlarmConfProfile.adslAturThresh15MinLofs;
3452 }
3453 if(IS_FLAG_SET((&(pts.adslLineAlarmConfProfileEntry_pt->flags)), ATUR_THRESH_15MIN_LOSS_FLAG)){
3454 pts.adslLineAlarmConfProfileEntry_pt->adslAturThresh15MinLoss=AlarmConfProfile.adslAturThresh15MinLoss;
3455 }
3456 if(IS_FLAG_SET((&(pts.adslLineAlarmConfProfileEntry_pt->flags)), ATUR_THRESH_15MIN_LPRS_FLAG)){
3457 pts.adslLineAlarmConfProfileEntry_pt->adslAturThresh15MinLprs=AlarmConfProfile.adslAturThresh15MinLprs;
3458 }
3459 if(IS_FLAG_SET((&(pts.adslLineAlarmConfProfileEntry_pt->flags)), ATUR_THRESH_15MIN_ESS_FLAG)){
3460 pts.adslLineAlarmConfProfileEntry_pt->adslAturThresh15MinESs=AlarmConfProfile.adslAturThresh15MinESs;
3461 }
3462 if(IS_FLAG_SET((&(pts.adslLineAlarmConfProfileEntry_pt->flags)), ATUR_THRESH_FAST_RATEUP_FLAG)){
3463 pts.adslLineAlarmConfProfileEntry_pt->adslAturThreshFastRateUp=AlarmConfProfile.adslAturThreshFastRateUp;
3464 }
3465 if(IS_FLAG_SET((&(pts.adslLineAlarmConfProfileEntry_pt->flags)), ATUR_THRESH_INTERLEAVE_RATEUP_FLAG)){
3466 pts.adslLineAlarmConfProfileEntry_pt->adslAturThreshInterleaveRateUp=AlarmConfProfile.adslAturThreshInterleaveRateUp;
3467 }
3468 if(IS_FLAG_SET((&(pts.adslLineAlarmConfProfileEntry_pt->flags)), ATUR_THRESH_FAST_RATEDOWN_FLAG)){
3469 pts.adslLineAlarmConfProfileEntry_pt->adslAturThreshFastRateDown=AlarmConfProfile.adslAturThreshFastRateDown;
3470 }
3471 if(IS_FLAG_SET((&(pts.adslLineAlarmConfProfileEntry_pt->flags)), ATUR_THRESH_INTERLEAVE_RATEDOWN_FLAG)){
3472 pts.adslLineAlarmConfProfileEntry_pt->adslAturThreshInterleaveRateDown=AlarmConfProfile.adslAturThreshInterleaveRateDown;
3473 }
3474 if(IS_FLAG_SET((&(pts.adslLineAlarmConfProfileEntry_pt->flags)), LINE_ALARM_CONF_PROFILE_ROWSTATUS_FLAG)){
3475 pts.adslLineAlarmConfProfileEntry_pt->adslLineAlarmConfProfileRowStatus=AlarmConfProfile.adslLineAlarmConfProfileRowStatus;
3476 }
3477 copy_to_user((char *)lon, (char *)pts.adslLineAlarmConfProfileEntry_pt, sizeof(adslLineAlarmConfProfileEntry));
3478 kfree(pts.adslLineAlarmConfProfileEntry_pt);
3479 break;
3480 #ifdef AMAZON_MEI_MIB_RFC3440
3481 case GET_ADSL_ALRM_CONF_PROF_EXT:
3482 pts.adslLineAlarmConfProfileExtEntry_pt = (adslLineAlarmConfProfileExtEntry *)kmalloc(sizeof(adslLineAlarmConfProfileExtEntry), GFP_KERNEL);
3483 copy_from_user((char *)pts.adslLineAlarmConfProfileExtEntry_pt, (char *)lon, sizeof(adslLineAlarmConfProfileExtEntry));
3484 if(IS_FLAG_SET((&(pts.adslLineAlarmConfProfileExtEntry_pt->flags)), ATUC_THRESH_15MIN_FAILED_FASTR_FLAG)){
3485 pts.adslLineAlarmConfProfileExtEntry_pt->adslAtucThreshold15MinFailedFastR=AlarmConfProfileExt.adslAtucThreshold15MinFailedFastR;
3486 }
3487 if(IS_FLAG_SET((&(pts.adslLineAlarmConfProfileExtEntry_pt->flags)), ATUC_THRESH_15MIN_SESL_FLAG)){
3488 pts.adslLineAlarmConfProfileExtEntry_pt->adslAtucThreshold15MinSesL=AlarmConfProfileExt.adslAtucThreshold15MinSesL;
3489 }
3490 if(IS_FLAG_SET((&(pts.adslLineAlarmConfProfileExtEntry_pt->flags)), ATUC_THRESH_15MIN_UASL_FLAG)){
3491 pts.adslLineAlarmConfProfileExtEntry_pt->adslAtucThreshold15MinUasL=AlarmConfProfileExt.adslAtucThreshold15MinUasL;
3492 }
3493 if(IS_FLAG_SET((&(pts.adslLineAlarmConfProfileExtEntry_pt->flags)), ATUR_THRESH_15MIN_SESL_FLAG)){
3494 pts.adslLineAlarmConfProfileExtEntry_pt->adslAturThreshold15MinSesL=AlarmConfProfileExt.adslAturThreshold15MinSesL;
3495 }
3496 if(IS_FLAG_SET((&(pts.adslLineAlarmConfProfileExtEntry_pt->flags)), ATUR_THRESH_15MIN_UASL_FLAG)){
3497 pts.adslLineAlarmConfProfileExtEntry_pt->adslAturThreshold15MinUasL=AlarmConfProfileExt.adslAturThreshold15MinUasL;
3498 }
3499 copy_to_user((char *)lon, (char *)pts.adslLineAlarmConfProfileExtEntry_pt, sizeof(adslLineAlarmConfProfileExtEntry));
3500 kfree(pts.adslLineAlarmConfProfileExtEntry_pt);
3501 break;
3502 #endif
3503 case SET_ADSL_ALRM_CONF_PROF:
3504 pts.adslLineAlarmConfProfileEntry_pt = (adslLineAlarmConfProfileEntry *)kmalloc(sizeof(adslLineAlarmConfProfileEntry), GFP_KERNEL);
3505 copy_from_user((char *)pts.adslLineAlarmConfProfileEntry_pt, (char *)lon, sizeof(adslLineAlarmConfProfileEntry));
3506
3507 strncpy(AlarmConfProfile.adslLineAlarmConfProfileName, pts.adslLineAlarmConfProfileEntry_pt->adslLineAlarmConfProfileName, 32);
3508 if(IS_FLAG_SET((&(pts.adslLineAlarmConfProfileEntry_pt->flags)), ATUC_THRESH_15MIN_LOFS_FLAG)){
3509 AlarmConfProfile.adslAtucThresh15MinLofs=pts.adslLineAlarmConfProfileEntry_pt->adslAtucThresh15MinLofs;
3510 }
3511 if(IS_FLAG_SET((&(pts.adslLineAlarmConfProfileEntry_pt->flags)), ATUC_THRESH_15MIN_LOSS_FLAG)){
3512 AlarmConfProfile.adslAtucThresh15MinLoss=pts.adslLineAlarmConfProfileEntry_pt->adslAtucThresh15MinLoss;
3513 }
3514 if(IS_FLAG_SET((&(pts.adslLineAlarmConfProfileEntry_pt->flags)), ATUC_THRESH_15MIN_ESS_FLAG)){
3515 AlarmConfProfile.adslAtucThresh15MinESs=pts.adslLineAlarmConfProfileEntry_pt->adslAtucThresh15MinESs;
3516 }
3517 if(IS_FLAG_SET((&(pts.adslLineAlarmConfProfileEntry_pt->flags)), ATUC_THRESH_FAST_RATEUP_FLAG)){
3518 AlarmConfProfile.adslAtucThreshFastRateUp=pts.adslLineAlarmConfProfileEntry_pt->adslAtucThreshFastRateUp;
3519 }
3520 if(IS_FLAG_SET((&(pts.adslLineAlarmConfProfileEntry_pt->flags)), ATUC_THRESH_INTERLEAVE_RATEUP_FLAG)){
3521 AlarmConfProfile.adslAtucThreshInterleaveRateUp=pts.adslLineAlarmConfProfileEntry_pt->adslAtucThreshInterleaveRateUp;
3522 }
3523 if(IS_FLAG_SET((&(pts.adslLineAlarmConfProfileEntry_pt->flags)), ATUC_THRESH_FAST_RATEDOWN_FLAG)){
3524 AlarmConfProfile.adslAtucThreshFastRateDown=pts.adslLineAlarmConfProfileEntry_pt->adslAtucThreshFastRateDown;
3525 }
3526 if(IS_FLAG_SET((&(pts.adslLineAlarmConfProfileEntry_pt->flags)), ATUC_THRESH_INTERLEAVE_RATEDOWN_FLAG)){
3527 AlarmConfProfile.adslAtucThreshInterleaveRateDown=pts.adslLineAlarmConfProfileEntry_pt->adslAtucThreshInterleaveRateDown;
3528 }
3529 if(IS_FLAG_SET((&(pts.adslLineAlarmConfProfileEntry_pt->flags)), ATUC_INIT_FAILURE_TRAP_ENABLE_FLAG)){
3530 AlarmConfProfile.adslAtucInitFailureTrapEnable=pts.adslLineAlarmConfProfileEntry_pt->adslAtucInitFailureTrapEnable;
3531 }
3532 if(IS_FLAG_SET((&(pts.adslLineAlarmConfProfileEntry_pt->flags)), ATUR_THRESH_15MIN_LOFS_FLAG)){
3533 AlarmConfProfile.adslAturThresh15MinLofs=pts.adslLineAlarmConfProfileEntry_pt->adslAturThresh15MinLofs;
3534 }
3535 if(IS_FLAG_SET((&(pts.adslLineAlarmConfProfileEntry_pt->flags)), ATUR_THRESH_15MIN_LOSS_FLAG)){
3536 AlarmConfProfile.adslAturThresh15MinLoss=pts.adslLineAlarmConfProfileEntry_pt->adslAturThresh15MinLoss;
3537 }
3538 if(IS_FLAG_SET((&(pts.adslLineAlarmConfProfileEntry_pt->flags)), ATUR_THRESH_15MIN_LPRS_FLAG)){
3539 AlarmConfProfile.adslAturThresh15MinLprs=pts.adslLineAlarmConfProfileEntry_pt->adslAturThresh15MinLprs;
3540 }
3541 if(IS_FLAG_SET((&(pts.adslLineAlarmConfProfileEntry_pt->flags)), ATUR_THRESH_15MIN_ESS_FLAG)){
3542 AlarmConfProfile.adslAturThresh15MinESs=pts.adslLineAlarmConfProfileEntry_pt->adslAturThresh15MinESs;
3543 }
3544 if(IS_FLAG_SET((&(pts.adslLineAlarmConfProfileEntry_pt->flags)), ATUR_THRESH_FAST_RATEUP_FLAG)){
3545 AlarmConfProfile.adslAturThreshFastRateUp=pts.adslLineAlarmConfProfileEntry_pt->adslAturThreshFastRateUp;
3546 }
3547 if(IS_FLAG_SET((&(pts.adslLineAlarmConfProfileEntry_pt->flags)), ATUR_THRESH_INTERLEAVE_RATEUP_FLAG)){
3548 AlarmConfProfile.adslAturThreshInterleaveRateUp=pts.adslLineAlarmConfProfileEntry_pt->adslAturThreshInterleaveRateUp;
3549 }
3550 if(IS_FLAG_SET((&(pts.adslLineAlarmConfProfileEntry_pt->flags)), ATUR_THRESH_FAST_RATEDOWN_FLAG)){
3551 AlarmConfProfile.adslAturThreshFastRateDown=pts.adslLineAlarmConfProfileEntry_pt->adslAturThreshFastRateDown;
3552 }
3553 if(IS_FLAG_SET((&(pts.adslLineAlarmConfProfileEntry_pt->flags)), ATUR_THRESH_INTERLEAVE_RATEDOWN_FLAG)){
3554 AlarmConfProfile.adslAturThreshInterleaveRateDown=pts.adslLineAlarmConfProfileEntry_pt->adslAturThreshInterleaveRateDown;
3555 }
3556 if(IS_FLAG_SET((&(pts.adslLineAlarmConfProfileEntry_pt->flags)), LINE_ALARM_CONF_PROFILE_ROWSTATUS_FLAG)){
3557 AlarmConfProfile.adslLineAlarmConfProfileRowStatus=pts.adslLineAlarmConfProfileEntry_pt->adslLineAlarmConfProfileRowStatus;
3558 }
3559 copy_to_user((char *)lon, (char *)pts.adslLineAlarmConfProfileEntry_pt, sizeof(adslLineAlarmConfProfileEntry));
3560 kfree(pts.adslLineAlarmConfProfileEntry_pt);
3561 break;
3562
3563 #ifdef AMAZON_MEI_MIB_RFC3440
3564 case SET_ADSL_ALRM_CONF_PROF_EXT:
3565 pts.adslLineAlarmConfProfileExtEntry_pt = (adslLineAlarmConfProfileExtEntry *)kmalloc(sizeof(adslLineAlarmConfProfileExtEntry), GFP_KERNEL);
3566 copy_from_user((char *)pts.adslLineAlarmConfProfileExtEntry_pt, (char *)lon, sizeof(adslLineAlarmConfProfileExtEntry));
3567 if(IS_FLAG_SET((&(pts.adslLineAlarmConfProfileExtEntry_pt->flags)), ATUC_THRESH_15MIN_FAILED_FASTR_FLAG)){
3568 AlarmConfProfileExt.adslAtucThreshold15MinFailedFastR=pts.adslLineAlarmConfProfileExtEntry_pt->adslAtucThreshold15MinFailedFastR;
3569 }
3570 if(IS_FLAG_SET((&(pts.adslLineAlarmConfProfileExtEntry_pt->flags)), ATUC_THRESH_15MIN_SESL_FLAG)){
3571 AlarmConfProfileExt.adslAtucThreshold15MinSesL=pts.adslLineAlarmConfProfileExtEntry_pt->adslAtucThreshold15MinSesL;
3572 }
3573 if(IS_FLAG_SET((&(pts.adslLineAlarmConfProfileExtEntry_pt->flags)), ATUC_THRESH_15MIN_UASL_FLAG)){
3574 AlarmConfProfileExt.adslAtucThreshold15MinUasL=pts.adslLineAlarmConfProfileExtEntry_pt->adslAtucThreshold15MinUasL;
3575 }
3576 if(IS_FLAG_SET((&(pts.adslLineAlarmConfProfileExtEntry_pt->flags)), ATUR_THRESH_15MIN_SESL_FLAG)){
3577 AlarmConfProfileExt.adslAturThreshold15MinSesL=pts.adslLineAlarmConfProfileExtEntry_pt->adslAturThreshold15MinSesL;
3578 }
3579 if(IS_FLAG_SET((&(pts.adslLineAlarmConfProfileExtEntry_pt->flags)), ATUR_THRESH_15MIN_UASL_FLAG)){
3580 AlarmConfProfileExt.adslAturThreshold15MinUasL=pts.adslLineAlarmConfProfileExtEntry_pt->adslAturThreshold15MinUasL;
3581 }
3582 copy_to_user((char *)lon, (char *)pts.adslLineAlarmConfProfileExtEntry_pt, sizeof(adslLineAlarmConfProfileExtEntry));
3583 kfree(pts.adslLineAlarmConfProfileExtEntry_pt);
3584 break;
3585 #endif
3586
3587 case ADSL_ATUR_TRAPS:
3588 if(down_interruptible(&mei_sema))
3589 return -ERESTARTSYS;
3590
3591 trapsflag=0;
3592 if(AlarmConfProfile.adslAtucThresh15MinLofs!=0 && current_intvl->AtucPerfLof>=AlarmConfProfile.adslAtucThresh15MinLofs)
3593 trapsflag|=ATUC_PERF_LOFS_THRESH_FLAG;
3594 if(AlarmConfProfile.adslAtucThresh15MinLoss!=0 && current_intvl->AtucPerfLos>=AlarmConfProfile.adslAtucThresh15MinLoss)
3595 trapsflag|=ATUC_PERF_LOSS_THRESH_FLAG;
3596 if(AlarmConfProfile.adslAtucThresh15MinESs!=0 && current_intvl->AtucPerfEs>=AlarmConfProfile.adslAtucThresh15MinESs)
3597 trapsflag|=ATUC_PERF_ESS_THRESH_FLAG;
3598 if(chantype.fast==1){
3599 if(AlarmConfProfile.adslAtucThreshFastRateUp!=0 || AlarmConfProfile.adslAtucThreshFastRateDown!=0){
3600 ATUC_CHAN_CURR_TX_RATE_FLAG_MAKECMV;
3601 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
3602 #ifdef AMAZON_MEI_DEBUG_ON
3603 printk("\n\nCMV fail, Group 6 Address 1 Index 0");
3604 #endif
3605 }
3606 else{
3607 temp = (u32)(RxMessage[4]) + (((u32)(RxMessage[5]))<<16);
3608 if((AlarmConfProfile.adslAtucThreshFastRateUp!=0) && (temp>=PrevTxRate.adslAtucChanPrevTxRate+AlarmConfProfile.adslAtucThreshFastRateUp)){
3609 trapsflag|=ATUC_RATE_CHANGE_FLAG;
3610 PrevTxRate.adslAtucChanPrevTxRate = temp;
3611 }
3612 if((AlarmConfProfile.adslAtucThreshFastRateDown!=0) && (temp<=PrevTxRate.adslAtucChanPrevTxRate-AlarmConfProfile.adslAtucThreshFastRateDown)){
3613 trapsflag|=ATUC_RATE_CHANGE_FLAG;
3614 PrevTxRate.adslAtucChanPrevTxRate = temp;
3615 }
3616 }
3617 }
3618 }
3619 if(chantype.interleave==1){
3620 if(AlarmConfProfile.adslAtucThreshInterleaveRateUp!=0 || AlarmConfProfile.adslAtucThreshInterleaveRateDown!=0){
3621 ATUC_CHAN_CURR_TX_RATE_FLAG_MAKECMV;
3622 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
3623 #ifdef AMAZON_MEI_DEBUG_ON
3624 printk("\n\nCMV fail, Group 6 Address 1 Index 0");
3625 #endif
3626 }
3627 else{
3628 temp = (u32)(RxMessage[4]) + (((u32)(RxMessage[5]))<<16);
3629 if((AlarmConfProfile.adslAtucThreshInterleaveRateUp!=0) && (temp>=PrevTxRate.adslAtucChanPrevTxRate+AlarmConfProfile.adslAtucThreshInterleaveRateUp)){
3630 trapsflag|=ATUC_RATE_CHANGE_FLAG;
3631 PrevTxRate.adslAtucChanPrevTxRate = temp;
3632 }
3633 if((AlarmConfProfile.adslAtucThreshInterleaveRateDown!=0) && (temp<=PrevTxRate.adslAtucChanPrevTxRate-AlarmConfProfile.adslAtucThreshInterleaveRateDown)){
3634 trapsflag|=ATUC_RATE_CHANGE_FLAG;
3635 PrevTxRate.adslAtucChanPrevTxRate = temp;
3636 }
3637 }
3638 }
3639 }
3640 if(AlarmConfProfile.adslAturThresh15MinLofs!=0 && current_intvl->AturPerfLof>=AlarmConfProfile.adslAturThresh15MinLofs)
3641 trapsflag|=ATUR_PERF_LOFS_THRESH_FLAG;
3642 if(AlarmConfProfile.adslAturThresh15MinLoss!=0 && current_intvl->AturPerfLos>=AlarmConfProfile.adslAturThresh15MinLoss)
3643 trapsflag|=ATUR_PERF_LOSS_THRESH_FLAG;
3644 if(AlarmConfProfile.adslAturThresh15MinLprs!=0 && current_intvl->AturPerfLpr>=AlarmConfProfile.adslAturThresh15MinLprs)
3645 trapsflag|=ATUR_PERF_LPRS_THRESH_FLAG;
3646 if(AlarmConfProfile.adslAturThresh15MinESs!=0 && current_intvl->AturPerfEs>=AlarmConfProfile.adslAturThresh15MinESs)
3647 trapsflag|=ATUR_PERF_ESS_THRESH_FLAG;
3648 if(chantype.fast==1){
3649 if(AlarmConfProfile.adslAturThreshFastRateUp!=0 || AlarmConfProfile.adslAturThreshFastRateDown!=0){
3650 ATUR_CHAN_CURR_TX_RATE_FLAG_MAKECMV;
3651 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
3652 #ifdef AMAZON_MEI_DEBUG_ON
3653 printk("\n\nCMV fail, Group 6 Address 0 Index 0");
3654 #endif
3655 }
3656 else{
3657 temp = (u32)(RxMessage[4]) + (((u32)(RxMessage[5]))<<16);
3658 if((AlarmConfProfile.adslAturThreshFastRateUp!=0) && (temp>=PrevTxRate.adslAturChanPrevTxRate+AlarmConfProfile.adslAturThreshFastRateUp)){
3659 trapsflag|=ATUR_RATE_CHANGE_FLAG;
3660 PrevTxRate.adslAturChanPrevTxRate = temp;
3661 }
3662 if((AlarmConfProfile.adslAturThreshFastRateDown!=0) && (temp<=PrevTxRate.adslAturChanPrevTxRate-AlarmConfProfile.adslAturThreshFastRateDown)){
3663 trapsflag|=ATUR_RATE_CHANGE_FLAG;
3664 PrevTxRate.adslAturChanPrevTxRate = temp;
3665 }
3666 }
3667 }
3668 }
3669 if(chantype.interleave==1){
3670 if(AlarmConfProfile.adslAturThreshInterleaveRateUp!=0 || AlarmConfProfile.adslAturThreshInterleaveRateDown!=0){
3671 ATUR_CHAN_CURR_TX_RATE_FLAG_MAKECMV;
3672 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
3673 #ifdef AMAZON_MEI_DEBUG_ON
3674 printk("\n\nCMV fail, Group 6 Address 0 Index 0");
3675 #endif
3676 }
3677 else{
3678 temp = (u32)(RxMessage[4]) + (((u32)(RxMessage[5]))<<16);
3679 if((AlarmConfProfile.adslAturThreshInterleaveRateUp!=0) && (temp>=PrevTxRate.adslAturChanPrevTxRate+AlarmConfProfile.adslAturThreshInterleaveRateUp)){
3680 trapsflag|=ATUR_RATE_CHANGE_FLAG;
3681 PrevTxRate.adslAturChanPrevTxRate = temp;
3682 }
3683 if((AlarmConfProfile.adslAturThreshInterleaveRateDown!=0) && (temp<=PrevTxRate.adslAturChanPrevTxRate-AlarmConfProfile.adslAturThreshInterleaveRateDown)){
3684 trapsflag|=ATUR_RATE_CHANGE_FLAG;
3685 PrevTxRate.adslAturChanPrevTxRate = temp;
3686 }
3687 }
3688 }
3689 }
3690 copy_to_user((char *)lon, (char *)(&trapsflag), 2);
3691
3692 up(&mei_sema);
3693 break;
3694
3695 #ifdef AMAZON_MEI_MIB_RFC3440
3696 case ADSL_ATUR_EXT_TRAPS:
3697 trapsflag=0;
3698 if(AlarmConfProfileExt.adslAtucThreshold15MinFailedFastR!=0 && current_intvl->AtucPerfStatFailedFastR>=AlarmConfProfileExt.adslAtucThreshold15MinFailedFastR)
3699 trapsflag|=ATUC_15MIN_FAILED_FASTR_TRAP_FLAG;
3700 if(AlarmConfProfileExt.adslAtucThreshold15MinSesL!=0 && current_intvl->AtucPerfStatSesL>=AlarmConfProfileExt.adslAtucThreshold15MinSesL)
3701 trapsflag|=ATUC_15MIN_SESL_TRAP_FLAG;
3702 if(AlarmConfProfileExt.adslAtucThreshold15MinUasL!=0 && current_intvl->AtucPerfStatUasL>=AlarmConfProfileExt.adslAtucThreshold15MinUasL)
3703 trapsflag|=ATUC_15MIN_UASL_TRAP_FLAG;
3704 if(AlarmConfProfileExt.adslAturThreshold15MinSesL!=0 && current_intvl->AturPerfStatSesL>=AlarmConfProfileExt.adslAturThreshold15MinSesL)
3705 trapsflag|=ATUR_15MIN_SESL_TRAP_FLAG;
3706 if(AlarmConfProfileExt.adslAturThreshold15MinUasL!=0 && current_intvl->AturPerfStatUasL>=AlarmConfProfileExt.adslAturThreshold15MinUasL)
3707 trapsflag|=ATUR_15MIN_UASL_TRAP_FLAG;
3708 copy_to_user((char *)lon, (char *)(&trapsflag), 2);
3709 break;
3710 #endif
3711
3712 // 603221:tc.chen start
3713 case GET_ADSL_LINE_STATUS:
3714 if(down_interruptible(&mei_sema))
3715 return -ERESTARTSYS;
3716
3717 pts.adslLineStatusInfo_pt = (adslLineStatusInfo *)kmalloc(sizeof(adslLineStatusInfo), GFP_KERNEL);
3718 copy_from_user((char *)pts.adslLineStatusInfo_pt, (char *)lon, sizeof(adslLineStatusInfo));
3719
3720 if(IS_FLAG_SET((&(pts.adslLineStatusInfo_pt->flags)), LINE_STAT_MODEM_STATUS_FLAG)){
3721 LINE_STAT_MODEM_STATUS_FLAG_MAKECMV;
3722 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
3723 #ifdef AMAZON_MEI_DEBUG_ON
3724 printk("\n\nCMV fail, Group STAT Address 0 Index 0");
3725 #endif
3726 pts.adslLineStatusInfo_pt->adslModemStatus = 0;
3727 }
3728 else{
3729 pts.adslLineStatusInfo_pt->adslModemStatus = RxMessage[4];
3730 }
3731 }
3732
3733 if(IS_FLAG_SET((&(pts.adslLineStatusInfo_pt->flags)), LINE_STAT_MODE_SEL_FLAG)){
3734 LINE_STAT_MODE_SEL_FLAG_MAKECMV;
3735 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
3736 #ifdef AMAZON_MEI_DEBUG_ON
3737 printk("\n\nCMV fail, Group STAT Address 1 Index 0");
3738 #endif
3739 pts.adslLineStatusInfo_pt->adslModeSelected = 0;
3740 }
3741 else{
3742 pts.adslLineStatusInfo_pt->adslModeSelected = RxMessage[4];
3743 }
3744 }
3745
3746 if(IS_FLAG_SET((&(pts.adslLineStatusInfo_pt->flags)), LINE_STAT_TRELLCOD_ENABLE_FLAG)){
3747 LINE_STAT_TRELLCOD_ENABLE_FLAG_MAKECMV;
3748 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
3749 #ifdef AMAZON_MEI_DEBUG_ON
3750 printk("\n\nCMV fail, Group OPTN Address 2 Index 0");
3751 #endif
3752 pts.adslLineStatusInfo_pt->adslTrellisCodeEnable = 0;
3753 }
3754 else{
3755
3756 pts.adslLineStatusInfo_pt->adslTrellisCodeEnable = (RxMessage[4]>>13)&0x1==0x1?0:1;
3757 }
3758 }
3759
3760 if(IS_FLAG_SET((&(pts.adslLineStatusInfo_pt->flags)), LINE_STAT_LATENCY_FLAG)){
3761 LINE_STAT_LATENCY_FLAG_MAKECMV;
3762 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
3763 #ifdef AMAZON_MEI_DEBUG_ON
3764 printk("\n\nCMV fail, Group STAT Address 12 Index 0");
3765 #endif
3766 pts.adslLineStatusInfo_pt->adslLatency = 0;
3767 }
3768 else{
3769 pts.adslLineStatusInfo_pt->adslLatency = RxMessage[4];
3770 }
3771 }
3772
3773 copy_to_user((char *)lon, (char *)pts.adslLineStatusInfo_pt, sizeof(adslLineStatusInfo));
3774 kfree(pts.adslLineStatusInfo_pt);
3775
3776 up(&mei_sema);
3777 break;
3778
3779
3780 case GET_ADSL_LINE_RATE:
3781 if (showtime!=1)
3782 return -ERESTARTSYS;
3783 if(down_interruptible(&mei_sema))
3784 return -ERESTARTSYS;
3785
3786 pts.adslLineRateInfo_pt = (adslLineRateInfo *)kmalloc(sizeof(adslLineRateInfo), GFP_KERNEL);
3787 copy_from_user((char *)pts.adslLineRateInfo_pt, (char *)lon, sizeof(adslLineRateInfo));
3788
3789 if(IS_FLAG_SET((&(pts.adslLineRateInfo_pt->flags)), LINE_RATE_DATA_RATEDS_FLAG)){
3790 if (adsl_mode <=8 && adsl_mode_extend==0) // adsl mode
3791 {
3792 if (chantype.interleave)
3793 LINE_RATE_DATA_RATEDS_FLAG_ADSL1_LP0_MAKECMV;
3794 else
3795 LINE_RATE_DATA_RATEDS_FLAG_ADSL1_LP1_MAKECMV;
3796
3797 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
3798 #ifdef AMAZON_MEI_DEBUG_ON
3799 printk("\n\nCMV fail, Group RATE Address 1 Index 0");
3800 #endif
3801 pts.adslLineRateInfo_pt->adslDataRateds = 0;
3802 }
3803 else{
3804 pts.adslLineRateInfo_pt->adslDataRateds = (u32)(RxMessage[4]) + (((u32)(RxMessage[5]))<<16);
3805 }
3806 }else // adsl 2/2+
3807 {
3808 unsigned long Mp,Lp,Tp,Rp,Kp,Bpn,DataRate,DataRate_remain;
3809 Mp=Lp=Tp=Rp=Kp=Bpn=DataRate=DataRate_remain=0;
3810 //// up stream data rate
3811
3812 if (chantype.interleave)
3813 {
3814 LINE_RATE_DATA_RATEUS_FLAG_ADSL2_LP_LP0_MAKECMV;
3815 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
3816 #ifdef AMAZON_MEI_DEBUG_ON
3817 printk("\n\nCMV fail, Group CNFG Address 25 Index 0");
3818 #endif
3819 Lp = 0;
3820 }else
3821 Lp=RxMessage[4];
3822
3823 LINE_RATE_DATA_RATEUS_FLAG_ADSL2_RP_LP0_MAKECMV;
3824 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
3825 #ifdef AMAZON_MEI_DEBUG_ON
3826 printk("\n\nCMV fail, Group CNFG Address 23 Index 0");
3827 #endif
3828 Rp = 0;
3829 }else
3830 Rp=RxMessage[4];
3831
3832 LINE_RATE_DATA_RATEUS_FLAG_ADSL2_MP_LP0_MAKECMV;
3833 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
3834 #ifdef AMAZON_MEI_DEBUG_ON
3835 printk("\n\nCMV fail, Group CNFG Address 24 Index 0");
3836 #endif
3837 Mp = 0;
3838 }else
3839 Mp=RxMessage[4];
3840
3841 LINE_RATE_DATA_RATEUS_FLAG_ADSL2_TP_LP0_MAKECMV;
3842 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
3843 #ifdef AMAZON_MEI_DEBUG_ON
3844 printk("\n\nCMV fail, Group CNFG Address 26 Index 0");
3845 #endif
3846 Tp = 0;
3847 }else
3848 Tp=RxMessage[4];
3849
3850 LINE_RATE_DATA_RATEUS_FLAG_ADSL2_KP_LP0_MAKECMV;
3851 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
3852 #ifdef AMAZON_MEI_DEBUG_ON
3853 printk("\n\nCMV fail, Group CNFG Address 28 Index 0");
3854 #endif
3855 Kp = 0;
3856 }else
3857 {
3858 Kp=RxMessage[4]+ RxMessage[5]+1;
3859 Bpn=RxMessage[4]+ RxMessage[5];
3860 }
3861 }else
3862 {
3863 LINE_RATE_DATA_RATEUS_FLAG_ADSL2_LP_LP1_MAKECMV;
3864 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
3865 #ifdef AMAZON_MEI_DEBUG_ON
3866 printk("\n\nCMV fail, Group CNFG Address 25 Index 1");
3867 #endif
3868 Lp = 0;
3869 }else
3870 Lp=RxMessage[4];
3871
3872 LINE_RATE_DATA_RATEUS_FLAG_ADSL2_RP_LP1_MAKECMV;
3873 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
3874 #ifdef AMAZON_MEI_DEBUG_ON
3875 printk("\n\nCMV fail, Group CNFG Address 23 Index 1");
3876 #endif
3877 Rp = 0;
3878 }else
3879 Rp=RxMessage[4];
3880
3881 LINE_RATE_DATA_RATEUS_FLAG_ADSL2_MP_LP1_MAKECMV;
3882 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
3883 #ifdef AMAZON_MEI_DEBUG_ON
3884 printk("\n\nCMV fail, Group CNFG Address 24 Index 1");
3885 #endif
3886 Mp = 0;
3887 }else
3888 Mp=RxMessage[4];
3889
3890 LINE_RATE_DATA_RATEUS_FLAG_ADSL2_TP_LP1_MAKECMV;
3891 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
3892 #ifdef AMAZON_MEI_DEBUG_ON
3893 printk("\n\nCMV fail, Group CNFG Address 26 Index 1");
3894 #endif
3895 Tp = 0;
3896 }else
3897 Tp=RxMessage[4];
3898
3899 LINE_RATE_DATA_RATEUS_FLAG_ADSL2_KP_LP1_MAKECMV;
3900 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
3901 #ifdef AMAZON_MEI_DEBUG_ON
3902 printk("\n\nCMV fail, Group CNFG Address 28 Index 2");
3903 #endif
3904 Kp = 0;
3905 }else
3906 {
3907 Kp=RxMessage[4]+ RxMessage[5]+1;
3908 Bpn=RxMessage[4]+ RxMessage[5];
3909 }
3910 }
3911 DataRate=((Tp*(Bpn+1)-1)*Mp*Lp*4)/(Tp*(Kp*Mp+Rp));
3912 //DataRate_remain=((((Tp*(Bpn+1)-1)*Mp*Lp*4)%(Tp*(Kp*Mp+Rp)))*1000)/(Tp*(Kp*Mp+Rp));
3913 //pts.adslLineRateInfo_pt->adslDataRateds = DataRate * 1000 + DataRate_remain;
3914 pts.adslLineRateInfo_pt->adslDataRateds = DataRate;
3915 }
3916 }
3917
3918 if(IS_FLAG_SET((&(pts.adslLineRateInfo_pt->flags)), LINE_RATE_DATA_RATEUS_FLAG)){
3919 if (adsl_mode <=8 && adsl_mode_extend==0) // adsl mode
3920 {
3921 if (chantype.interleave)
3922 LINE_RATE_DATA_RATEUS_FLAG_ADSL1_LP0_MAKECMV;
3923 else
3924 LINE_RATE_DATA_RATEUS_FLAG_ADSL1_LP1_MAKECMV;
3925
3926 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
3927 #ifdef AMAZON_MEI_DEBUG_ON
3928 printk("\n\nCMV fail, Group RATE Address 0 Index 0");
3929 #endif
3930 pts.adslLineRateInfo_pt->adslDataRateus = 0;
3931 }
3932 else{
3933 pts.adslLineRateInfo_pt->adslDataRateus = (u32)(RxMessage[4]) + (((u32)(RxMessage[5]))<<16);
3934 }
3935 }else // adsl 2/2+
3936 {
3937 unsigned long Mp,Lp,Tp,Rp,Kp,Bpn,DataRate,DataRate_remain;
3938 Mp=Lp=Tp=Rp=Kp=Bpn=DataRate=DataRate_remain=0;
3939 //// down stream data rate
3940
3941 if (chantype.interleave)
3942 {
3943 LINE_RATE_DATA_RATEDS_FLAG_ADSL2_LP_LP0_MAKECMV;
3944 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
3945 #ifdef AMAZON_MEI_DEBUG_ON
3946 printk("\n\nCMV fail, Group CNFG Address 14 Index 0");
3947 #endif
3948 Lp = 0;
3949 }else
3950 Lp=RxMessage[4];
3951
3952 LINE_RATE_DATA_RATEDS_FLAG_ADSL2_RP_LP0_MAKECMV;
3953 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
3954 #ifdef AMAZON_MEI_DEBUG_ON
3955 printk("\n\nCMV fail, Group CNFG Address 12 Index 0");
3956 #endif
3957 Rp = 0;
3958 }else
3959 Rp=RxMessage[4];
3960
3961 LINE_RATE_DATA_RATEDS_FLAG_ADSL2_MP_LP0_MAKECMV;
3962 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
3963 #ifdef AMAZON_MEI_DEBUG_ON
3964 printk("\n\nCMV fail, Group CNFG Address 13 Index 0");
3965 #endif
3966 Mp = 0;
3967 }else
3968 Mp=RxMessage[4];
3969
3970 LINE_RATE_DATA_RATEDS_FLAG_ADSL2_TP_LP0_MAKECMV;
3971 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
3972 #ifdef AMAZON_MEI_DEBUG_ON
3973 printk("\n\nCMV fail, Group CNFG Address 15 Index 0");
3974 #endif
3975 Tp = 0;
3976 }else
3977 Tp=RxMessage[4];
3978
3979 LINE_RATE_DATA_RATEDS_FLAG_ADSL2_KP_LP0_MAKECMV;
3980 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
3981 #ifdef AMAZON_MEI_DEBUG_ON
3982 printk("\n\nCMV fail, Group CNFG Address 17 Index 0");
3983 #endif
3984 Kp = 0;
3985 }else
3986 {
3987 Kp=RxMessage[4]+ RxMessage[5]+1;
3988 Bpn=RxMessage[4]+ RxMessage[5];
3989 }
3990 }else
3991 {
3992 LINE_RATE_DATA_RATEDS_FLAG_ADSL2_LP_LP1_MAKECMV;
3993 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
3994 #ifdef AMAZON_MEI_DEBUG_ON
3995 printk("\n\nCMV fail, Group CNFG Address 14 Index 1");
3996 #endif
3997 Lp = 0;
3998 }else
3999 Lp=RxMessage[4];
4000
4001 LINE_RATE_DATA_RATEDS_FLAG_ADSL2_RP_LP1_MAKECMV;
4002 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
4003 #ifdef AMAZON_MEI_DEBUG_ON
4004 printk("\n\nCMV fail, Group CNFG Address 12 Index 1");
4005 #endif
4006 Rp = 0;
4007 }else
4008 Rp=RxMessage[4];
4009
4010 LINE_RATE_DATA_RATEDS_FLAG_ADSL2_MP_LP1_MAKECMV;
4011 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
4012 #ifdef AMAZON_MEI_DEBUG_ON
4013 printk("\n\nCMV fail, Group CNFG Address 13 Index 1");
4014 #endif
4015 Mp = 0;
4016 }else
4017 Mp=RxMessage[4];
4018
4019 LINE_RATE_DATA_RATEDS_FLAG_ADSL2_TP_LP1_MAKECMV;
4020 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
4021 #ifdef AMAZON_MEI_DEBUG_ON
4022 printk("\n\nCMV fail, Group CNFG Address 15 Index 1");
4023 #endif
4024 Tp = 0;
4025 }else
4026 Tp=RxMessage[4];
4027
4028 LINE_RATE_DATA_RATEDS_FLAG_ADSL2_KP_LP1_MAKECMV;
4029 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
4030 #ifdef AMAZON_MEI_DEBUG_ON
4031 printk("\n\nCMV fail, Group CNFG Address 17 Index 2");
4032 #endif
4033 Kp = 0;
4034 }else
4035 {
4036 Kp=RxMessage[4]+ RxMessage[5]+1;
4037 Bpn=RxMessage[4]+ RxMessage[5];
4038 }
4039 }
4040 DataRate=((Tp*(Bpn+1)-1)*Mp*Lp*4)/(Tp*(Kp*Mp+Rp));
4041 //DataRate_remain=((((Tp*(Bpn+1)-1)*Mp*Lp*4)%(Tp*(Kp*Mp+Rp)))*1000)/(Tp*(Kp*Mp+Rp));
4042 //pts.adslLineRateInfo_pt->adslDataRateus = DataRate * 1000 + DataRate_remain;
4043 pts.adslLineRateInfo_pt->adslDataRateus = DataRate;
4044 }
4045 }
4046
4047 if(IS_FLAG_SET((&(pts.adslLineRateInfo_pt->flags)), LINE_RATE_ATTNDRDS_FLAG)){
4048 LINE_RATE_ATTNDRDS_FLAG_MAKECMV;
4049 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
4050 #ifdef AMAZON_MEI_DEBUG_ON
4051 printk("\n\nCMV fail, Group INFO Address 68 Index 4");
4052 #endif
4053 pts.adslLineRateInfo_pt->adslATTNDRds = 0;
4054 }
4055 else{
4056 pts.adslLineRateInfo_pt->adslATTNDRds = (u32)(RxMessage[4]) + (((u32)(RxMessage[5]))<<16);
4057 }
4058 }
4059
4060 if(IS_FLAG_SET((&(pts.adslLineRateInfo_pt->flags)), LINE_RATE_ATTNDRUS_FLAG)){
4061 if (adsl_mode <=8 && adsl_mode_extend==0) // adsl mode
4062 {
4063 LINE_RATE_ATTNDRUS_FLAG_MAKECMV;
4064 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
4065 #ifdef AMAZON_MEI_DEBUG_ON
4066 printk("\n\nCMV fail, Group INFO Address 69 Index 4");
4067 #endif
4068 pts.adslLineRateInfo_pt->adslATTNDRus = 0;
4069 }
4070 else{
4071 pts.adslLineRateInfo_pt->adslATTNDRus = (u32)(RxMessage[4]) + (((u32)(RxMessage[5]))<<16);
4072 }
4073 }else
4074 {
4075 hdlc_cmd[0]=0x0181;
4076 hdlc_cmd[1]=0x24;
4077 up(&mei_sema);
4078 if (ifx_me_hdlc_send((unsigned char *)&hdlc_cmd[0],4)!= -EBUSY)
4079 {
4080 set_current_state(TASK_INTERRUPTIBLE);
4081 schedule_timeout(1);
4082 hdlc_rx_len=0;
4083 hdlc_rx_len = ifx_mei_hdlc_read(&hdlc_rx_buffer,32*2);
4084 if (hdlc_rx_len <=0)
4085 {
4086 meierr = -ERESTARTSYS;
4087 goto GET_ADSL_LINE_RATE_END;
4088 }
4089 pts.adslLineRateInfo_pt->adslATTNDRus = (u32)le16_to_cpu(hdlc_rx_buffer[1])<<16 | (u32)le16_to_cpu(hdlc_rx_buffer[2]);
4090 }
4091 if(down_interruptible(&mei_sema))
4092 {
4093 meierr = -ERESTARTSYS;
4094 goto GET_ADSL_LINE_RATE_END;
4095 }
4096 }
4097 }
4098 copy_to_user((char *)lon, (char *)pts.adslLineRateInfo_pt, sizeof(adslLineRateInfo));
4099 up(&mei_sema);
4100
4101 GET_ADSL_LINE_RATE_END:
4102 kfree(pts.adslLineRateInfo_pt);
4103 break;
4104
4105 case GET_ADSL_LINE_INFO:
4106 if (showtime!=1)
4107 return -ERESTARTSYS;
4108 if(down_interruptible(&mei_sema))
4109 return -ERESTARTSYS;
4110
4111 pts.adslLineInfo_pt = (adslLineInfo *)kmalloc(sizeof(adslLineInfo), GFP_KERNEL);
4112 copy_from_user((char *)pts.adslLineInfo_pt, (char *)lon, sizeof(adslLineInfo));
4113
4114 if(IS_FLAG_SET((&(pts.adslLineInfo_pt->flags)), LINE_INFO_INTLV_DEPTHDS_FLAG)){
4115 if (chantype.interleave)
4116 LINE_INFO_INTLV_DEPTHDS_FLAG_LP0_MAKECMV;
4117 else
4118 LINE_INFO_INTLV_DEPTHDS_FLAG_LP1_MAKECMV;
4119
4120 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
4121 #ifdef AMAZON_MEI_DEBUG_ON
4122 printk("\n\nCMV fail, Group CNFG Address 27 Index 0");
4123 #endif
4124 pts.adslLineInfo_pt->adslInterleaveDepthds = 0;
4125 }
4126 else{
4127 pts.adslLineInfo_pt->adslInterleaveDepthds = RxMessage[4];
4128 }
4129 }
4130
4131 if(IS_FLAG_SET((&(pts.adslLineInfo_pt->flags)), LINE_INFO_INTLV_DEPTHUS_FLAG)){
4132 if (chantype.interleave)
4133 LINE_INFO_INTLV_DEPTHUS_FLAG_LP0_MAKECMV;
4134 else
4135 LINE_INFO_INTLV_DEPTHUS_FLAG_LP1_MAKECMV;
4136
4137 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
4138 #ifdef AMAZON_MEI_DEBUG_ON
4139 printk("\n\nCMV fail, Group CNFG Address 16 Index 0");
4140 #endif
4141 pts.adslLineInfo_pt->adslInterleaveDepthus = 0;
4142 }
4143 else{
4144 pts.adslLineInfo_pt->adslInterleaveDepthus = RxMessage[4];
4145 }
4146 }
4147
4148 if(IS_FLAG_SET((&(pts.adslLineInfo_pt->flags)), LINE_INFO_LATNDS_FLAG)){
4149 LINE_INFO_LATNDS_FLAG_MAKECMV;
4150 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
4151 #ifdef AMAZON_MEI_DEBUG_ON
4152 printk("\n\nCMV fail, Group INFO Address 68 Index 1");
4153 #endif
4154 pts.adslLineInfo_pt->adslLATNds = 0;
4155 }
4156 else{
4157 pts.adslLineInfo_pt->adslLATNds = RxMessage[4];
4158 }
4159 }
4160
4161 if(IS_FLAG_SET((&(pts.adslLineInfo_pt->flags)), LINE_INFO_LATNUS_FLAG)){
4162 if (adsl_mode <=8 && adsl_mode_extend==0) // adsl mode
4163 {
4164 LINE_INFO_LATNUS_FLAG_MAKECMV;
4165 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
4166 #ifdef AMAZON_MEI_DEBUG_ON
4167 printk("\n\nCMV fail, Group INFO Address 69 Index 1");
4168 #endif
4169 pts.adslLineInfo_pt->adslLATNus = 0;
4170 }
4171 else{
4172 pts.adslLineInfo_pt->adslLATNus = RxMessage[4];
4173 }
4174 }else
4175 {
4176 hdlc_cmd[0]=0x0181;
4177 hdlc_cmd[1]=0x21;
4178 up(&mei_sema);
4179 if (ifx_me_hdlc_send((unsigned char *)&hdlc_cmd[0],4)!= -EBUSY)
4180 {
4181 set_current_state(TASK_INTERRUPTIBLE);
4182 schedule_timeout(1);
4183 hdlc_rx_len=0;
4184 hdlc_rx_len = ifx_mei_hdlc_read(&hdlc_rx_buffer,32*2);
4185 if (hdlc_rx_len <=0)
4186 {
4187 meierr = -ERESTARTSYS;
4188 goto GET_ADSL_LINE_INFO_END;
4189 }
4190 pts.adslLineInfo_pt->adslLATNus = le16_to_cpu(hdlc_rx_buffer[1]);
4191 }
4192 if(down_interruptible(&mei_sema))
4193 {
4194 meierr = -ERESTARTSYS;
4195 goto GET_ADSL_LINE_INFO_END;
4196 }
4197 }
4198 }
4199
4200 if(IS_FLAG_SET((&(pts.adslLineInfo_pt->flags)), LINE_INFO_SATNDS_FLAG)){
4201 LINE_INFO_SATNDS_FLAG_MAKECMV;
4202 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
4203 #ifdef AMAZON_MEI_DEBUG_ON
4204 printk("\n\nCMV fail, Group INFO Address 68 Index 2");
4205 #endif
4206 pts.adslLineInfo_pt->adslSATNds = 0;
4207 }
4208 else{
4209 pts.adslLineInfo_pt->adslSATNds = RxMessage[4];
4210 }
4211 }
4212
4213 if(IS_FLAG_SET((&(pts.adslLineInfo_pt->flags)), LINE_INFO_SATNUS_FLAG)){
4214 if (adsl_mode <=8 && adsl_mode_extend==0) // adsl mode
4215 {
4216 LINE_INFO_SATNUS_FLAG_MAKECMV;
4217 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
4218 #ifdef AMAZON_MEI_DEBUG_ON
4219 printk("\n\nCMV fail, Group INFO Address 69 Index 2");
4220 #endif
4221 pts.adslLineInfo_pt->adslSATNus = 0;
4222 }
4223 else{
4224 pts.adslLineInfo_pt->adslSATNus = RxMessage[4];
4225 }
4226 }else
4227 {
4228 hdlc_cmd[0]=0x0181;
4229 hdlc_cmd[1]=0x22;
4230 up(&mei_sema);
4231 if (ifx_me_hdlc_send((unsigned char *)&hdlc_cmd[0],4)!= -EBUSY)
4232 {
4233 set_current_state(TASK_INTERRUPTIBLE);
4234 schedule_timeout(1);
4235 hdlc_rx_len=0;
4236 hdlc_rx_len = ifx_mei_hdlc_read(&hdlc_rx_buffer,32*2);
4237 if (hdlc_rx_len <=0)
4238 {
4239 meierr = -ERESTARTSYS;
4240 goto GET_ADSL_LINE_INFO_END;
4241 }
4242 pts.adslLineInfo_pt->adslSATNus = le16_to_cpu(hdlc_rx_buffer[1]);
4243 }
4244 if(down_interruptible(&mei_sema))
4245 {
4246 meierr = -ERESTARTSYS;
4247 goto GET_ADSL_LINE_INFO_END;
4248 }
4249 }
4250 }
4251
4252 if(IS_FLAG_SET((&(pts.adslLineInfo_pt->flags)), LINE_INFO_SNRMNDS_FLAG)){
4253 if (adsl_mode <=8 && adsl_mode_extend==0) // adsl mode
4254 {
4255 LINE_INFO_SNRMNDS_FLAG_ADSL1_MAKECMV;
4256 }
4257 else if ((adsl_mode == 0x4000) || (adsl_mode == 0x8000) || adsl_mode_extend > 0)
4258 {
4259 LINE_INFO_SNRMNDS_FLAG_ADSL2PLUS_MAKECMV;
4260 }
4261 else
4262 {
4263 LINE_INFO_SNRMNDS_FLAG_ADSL2_MAKECMV;
4264 }
4265 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
4266 #ifdef AMAZON_MEI_DEBUG_ON
4267 printk("\n\nCMV fail, Group INFO Address 68 Index 3");
4268 #endif
4269 pts.adslLineInfo_pt->adslSNRMds = 0;
4270 }
4271 else{
4272 if (adsl_mode>8 || adsl_mode_extend>0)
4273 {
4274 int SNRMds,SNRMds_remain;
4275 SNRMds=RxMessage[4];
4276 SNRMds_remain=((SNRMds&0xff)*1000)/256;
4277 SNRMds=(SNRMds>>8)&0xff;
4278 if ((SNRMds_remain%100)>=50) SNRMds_remain=(SNRMds_remain/100)+1;
4279 else SNRMds_remain=(SNRMds_remain/100);
4280 pts.adslLineInfo_pt->adslSNRMds = SNRMds*10 + SNRMds_remain;
4281 }else
4282 {
4283 pts.adslLineInfo_pt->adslSNRMds = RxMessage[4];
4284 }
4285 }
4286 }
4287
4288 if(IS_FLAG_SET((&(pts.adslLineInfo_pt->flags)), LINE_INFO_SNRMNUS_FLAG)){
4289 if (adsl_mode <=8 && adsl_mode_extend == 0)
4290 {
4291 LINE_INFO_SNRMNUS_FLAG_MAKECMV;
4292 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
4293 #ifdef AMAZON_MEI_DEBUG_ON
4294 printk("\n\nCMV fail, Group INFO Address 69 Index 3");
4295 #endif
4296 pts.adslLineInfo_pt->adslSNRMus = 0;
4297 }
4298 else{
4299 pts.adslLineInfo_pt->adslSNRMus = RxMessage[4];
4300 }
4301 }else
4302 {
4303 hdlc_cmd[0]=0x0181;
4304 hdlc_cmd[1]=0x23;
4305 up(&mei_sema);
4306 if (ifx_me_hdlc_send((unsigned char *)&hdlc_cmd[0],4)!= -EBUSY)
4307 {
4308 set_current_state(TASK_INTERRUPTIBLE);
4309 schedule_timeout(1);
4310 hdlc_rx_len=0;
4311 hdlc_rx_len = ifx_mei_hdlc_read(&hdlc_rx_buffer,32*2);
4312 if (hdlc_rx_len <=0)
4313 {
4314 meierr = -ERESTARTSYS;
4315 goto GET_ADSL_LINE_INFO_END;
4316 }
4317 pts.adslLineInfo_pt->adslSNRMus = le16_to_cpu(hdlc_rx_buffer[1]);
4318 }
4319 if(down_interruptible(&mei_sema))
4320 {
4321 meierr = -ERESTARTSYS;
4322 goto GET_ADSL_LINE_INFO_END;
4323 }
4324 }
4325 }
4326
4327 if(IS_FLAG_SET((&(pts.adslLineInfo_pt->flags)), LINE_INFO_ACATPDS_FLAG)){
4328 if (adsl_mode <=8 && adsl_mode_extend == 0)
4329 {
4330 LINE_INFO_ACATPDS_FLAG_MAKECMV;
4331 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
4332 #ifdef AMAZON_MEI_DEBUG_ON
4333 printk("\n\nCMV fail, Group INFO Address 68 Index 6");
4334 #endif
4335 pts.adslLineInfo_pt->adslACATPds = 0;
4336 }
4337 else{
4338 pts.adslLineInfo_pt->adslACATPds = RxMessage[4];
4339 }
4340 }else
4341 {
4342 hdlc_cmd[0]=0x0181;
4343 hdlc_cmd[1]=0x25;
4344 up(&mei_sema);
4345 if (ifx_me_hdlc_send((unsigned char *)&hdlc_cmd[0],4)!= -EBUSY)
4346 {
4347 set_current_state(TASK_INTERRUPTIBLE);
4348 schedule_timeout(1);
4349 hdlc_rx_len=0;
4350 hdlc_rx_len = ifx_mei_hdlc_read(&hdlc_rx_buffer,32*2);
4351 if (hdlc_rx_len <=0)
4352 {
4353 meierr = -ERESTARTSYS;
4354 goto GET_ADSL_LINE_INFO_END;
4355 }
4356 pts.adslLineInfo_pt->adslACATPds = le16_to_cpu(hdlc_rx_buffer[1]);
4357 }
4358 if(down_interruptible(&mei_sema))
4359 {
4360 meierr = -ERESTARTSYS;
4361 goto GET_ADSL_LINE_INFO_END;
4362 }
4363 }
4364 }
4365
4366 if(IS_FLAG_SET((&(pts.adslLineInfo_pt->flags)), LINE_INFO_ACATPUS_FLAG)){
4367 if (adsl_mode <=8 && adsl_mode_extend == 0)
4368 {
4369 LINE_INFO_ACATPUS_FLAG_MAKECMV;
4370 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
4371 #ifdef AMAZON_MEI_DEBUG_ON
4372 printk("\n\nCMV fail, Group INFO Address 69 Index 6");
4373 #endif
4374 pts.adslLineInfo_pt->adslACATPus = 0;
4375 }
4376 else{
4377 pts.adslLineInfo_pt->adslACATPus = RxMessage[4];
4378 }
4379 }else
4380 {
4381 hdlc_cmd[0]=0x0181;
4382 hdlc_cmd[1]=0x26;
4383 up(&mei_sema);
4384 if (ifx_me_hdlc_send((unsigned char *)&hdlc_cmd[0],4)!= -EBUSY)
4385 {
4386 set_current_state(TASK_INTERRUPTIBLE);
4387 schedule_timeout(1);
4388 hdlc_rx_len=0;
4389 hdlc_rx_len = ifx_mei_hdlc_read(&hdlc_rx_buffer,32*2);
4390 if (hdlc_rx_len <=0)
4391 {
4392 meierr = -ERESTARTSYS;
4393 goto GET_ADSL_LINE_INFO_END;
4394 }
4395 pts.adslLineInfo_pt->adslACATPus = le16_to_cpu(hdlc_rx_buffer[1]);
4396 }
4397 if(down_interruptible(&mei_sema))
4398 {
4399 meierr = -ERESTARTSYS;
4400 goto GET_ADSL_LINE_INFO_END;
4401 }
4402 }
4403 }
4404
4405 copy_to_user((char *)lon, (char *)pts.adslLineInfo_pt, sizeof(adslLineInfo));
4406 up(&mei_sema);
4407
4408 GET_ADSL_LINE_INFO_END:
4409 kfree(pts.adslLineInfo_pt);
4410 break;
4411
4412 case GET_ADSL_NEAREND_STATS:
4413 if (showtime!=1)
4414 return -ERESTARTSYS;
4415 if(down_interruptible(&mei_sema))
4416 return -ERESTARTSYS;
4417
4418 pts.adslNearEndPerfStats_pt = (adslNearEndPerfStats *)kmalloc(sizeof(adslNearEndPerfStats), GFP_KERNEL);
4419 copy_from_user((char *)pts.adslNearEndPerfStats_pt, (char *)lon, sizeof(adslNearEndPerfStats));
4420
4421 if(IS_FLAG_SET((&(pts.adslNearEndPerfStats_pt->flags)), NEAREND_PERF_SUPERFRAME_FLAG)){
4422 NEAREND_PERF_SUPERFRAME_FLAG_LSW_MAKECMV;
4423 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
4424 #ifdef AMAZON_MEI_DEBUG_ON
4425 printk("\n\nCMV fail, Group PLAM Address 20 Index 0");
4426 #endif
4427 pts.adslNearEndPerfStats_pt->adslSuperFrames = 0;
4428 }
4429 else{
4430 pts.adslNearEndPerfStats_pt->adslSuperFrames = (u32)(RxMessage[4]);
4431 }
4432 NEAREND_PERF_SUPERFRAME_FLAG_MSW_MAKECMV;
4433 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
4434 #ifdef AMAZON_MEI_DEBUG_ON
4435 printk("\n\nCMV fail, Group PLAM Address 21 Index 0");
4436 #endif
4437 pts.adslNearEndPerfStats_pt->adslSuperFrames = 0;
4438 }
4439 else{
4440 pts.adslNearEndPerfStats_pt->adslSuperFrames += (((u32)(RxMessage[4]))<<16);
4441 }
4442 }
4443
4444 if(IS_FLAG_SET((&(pts.adslNearEndPerfStats_pt->flags)), NEAREND_PERF_LOS_FLAG) ||
4445 IS_FLAG_SET((&(pts.adslNearEndPerfStats_pt->flags)), NEAREND_PERF_LOF_FLAG) ||
4446 IS_FLAG_SET((&(pts.adslNearEndPerfStats_pt->flags)), NEAREND_PERF_LPR_FLAG) ||
4447 IS_FLAG_SET((&(pts.adslNearEndPerfStats_pt->flags)), NEAREND_PERF_NCD_FLAG) ||
4448 IS_FLAG_SET((&(pts.adslNearEndPerfStats_pt->flags)), NEAREND_PERF_LCD_FLAG) ){
4449 NEAREND_PERF_LOS_FLAG_MAKECMV;
4450 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
4451 #ifdef AMAZON_MEI_DEBUG_ON
4452 printk("\n\nCMV fail, Group PLAM Address 0 Index 0");
4453 #endif
4454 RxMessage[4] = 0;
4455 }
4456 if(IS_FLAG_SET((&(pts.adslNearEndPerfStats_pt->flags)), NEAREND_PERF_LOS_FLAG)){
4457 if( (RxMessage[4]&0x1) == 0x1)
4458 pts.adslNearEndPerfStats_pt->adslneLOS = 1;
4459 else
4460 pts.adslNearEndPerfStats_pt->adslneLOS = 0;
4461 }
4462
4463 if(IS_FLAG_SET((&(pts.adslNearEndPerfStats_pt->flags)), NEAREND_PERF_LOF_FLAG)){
4464 if( (RxMessage[4]&0x2) == 0x2)
4465 pts.adslNearEndPerfStats_pt->adslneLOF = 1;
4466 else
4467 pts.adslNearEndPerfStats_pt->adslneLOF = 0;
4468 }
4469
4470 if(IS_FLAG_SET((&(pts.adslNearEndPerfStats_pt->flags)), NEAREND_PERF_LPR_FLAG)){
4471 if( (RxMessage[4]&0x4) == 0x4)
4472 pts.adslNearEndPerfStats_pt->adslneLPR = 1;
4473 else
4474 pts.adslNearEndPerfStats_pt->adslneLPR = 0;
4475 }
4476
4477 if(IS_FLAG_SET((&(pts.adslNearEndPerfStats_pt->flags)), NEAREND_PERF_NCD_FLAG)){
4478 pts.adslNearEndPerfStats_pt->adslneNCD = (RxMessage[4]>>4)&0x3;
4479 }
4480
4481 if(IS_FLAG_SET((&(pts.adslNearEndPerfStats_pt->flags)), NEAREND_PERF_LCD_FLAG)){
4482 pts.adslNearEndPerfStats_pt->adslneLCD = (RxMessage[4]>>6)&0x3;
4483 }
4484 }
4485
4486 if(IS_FLAG_SET((&(pts.adslNearEndPerfStats_pt->flags)), NEAREND_PERF_CRC_FLAG)){
4487 if (chantype.interleave)
4488 NEAREND_PERF_CRC_FLAG_LP0_MAKECMV;
4489 else
4490 NEAREND_PERF_CRC_FLAG_LP1_MAKECMV;
4491 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
4492 #ifdef AMAZON_MEI_DEBUG_ON
4493 printk("\n\nCMV fail, Group PLAM Address 2 Index 0");
4494 #endif
4495 pts.adslNearEndPerfStats_pt->adslneCRC = 0;
4496 }
4497 else{
4498 pts.adslNearEndPerfStats_pt->adslneCRC = (u32)(RxMessage[4]) + (((u32)(RxMessage[5]))<<16);
4499 }
4500 }
4501
4502 if(IS_FLAG_SET((&(pts.adslNearEndPerfStats_pt->flags)), NEAREND_PERF_RSCORR_FLAG)){
4503 if (chantype.interleave)
4504 NEAREND_PERF_RSCORR_FLAG_LP0_MAKECMV;
4505 else
4506 NEAREND_PERF_RSCORR_FLAG_LP1_MAKECMV;
4507
4508 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
4509 #ifdef AMAZON_MEI_DEBUG_ON
4510 printk("\n\nCMV fail, Group PLAM Address 3 Index 0");
4511 #endif
4512 pts.adslNearEndPerfStats_pt->adslneRSCorr = 0;
4513 }
4514 else{
4515 pts.adslNearEndPerfStats_pt->adslneRSCorr = RxMessage[4];
4516 }
4517 }
4518
4519 if(IS_FLAG_SET((&(pts.adslNearEndPerfStats_pt->flags)), NEAREND_PERF_FECS_FLAG)){
4520 NEAREND_PERF_FECS_FLAG_MAKECMV;
4521 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
4522 #ifdef AMAZON_MEI_DEBUG_ON
4523 printk("\n\nCMV fail, Group PLAM Address 6 Index 0");
4524 #endif
4525 pts.adslNearEndPerfStats_pt->adslneFECS = 0;
4526 }
4527 else{
4528 pts.adslNearEndPerfStats_pt->adslneFECS = RxMessage[4];
4529 }
4530 }
4531
4532 if(IS_FLAG_SET((&(pts.adslNearEndPerfStats_pt->flags)), NEAREND_PERF_ES_FLAG)){
4533 NEAREND_PERF_ES_FLAG_MAKECMV;
4534 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
4535 #ifdef AMAZON_MEI_DEBUG_ON
4536 printk("\n\nCMV fail, Group PLAM Address 7 Index 0");
4537 #endif
4538 pts.adslNearEndPerfStats_pt->adslneES = 0;
4539 }
4540 else{
4541 pts.adslNearEndPerfStats_pt->adslneES = RxMessage[4];
4542 }
4543 }
4544
4545 if(IS_FLAG_SET((&(pts.adslNearEndPerfStats_pt->flags)), NEAREND_PERF_SES_FLAG)){
4546 NEAREND_PERF_SES_FLAG_MAKECMV;
4547 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
4548 #ifdef AMAZON_MEI_DEBUG_ON
4549 printk("\n\nCMV fail, Group PLAM Address 8 Index 0");
4550 #endif
4551 pts.adslNearEndPerfStats_pt->adslneSES = 0;
4552 }
4553 else{
4554 pts.adslNearEndPerfStats_pt->adslneSES = RxMessage[4];
4555 }
4556 }
4557
4558 if(IS_FLAG_SET((&(pts.adslNearEndPerfStats_pt->flags)), NEAREND_PERF_LOSS_FLAG)){
4559 NEAREND_PERF_LOSS_FLAG_MAKECMV;
4560 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
4561 #ifdef AMAZON_MEI_DEBUG_ON
4562 printk("\n\nCMV fail, Group PLAM Address 9 Index 0");
4563 #endif
4564 pts.adslNearEndPerfStats_pt->adslneLOSS = 0;
4565 }
4566 else{
4567 pts.adslNearEndPerfStats_pt->adslneLOSS = RxMessage[4];
4568 }
4569 }
4570
4571 if(IS_FLAG_SET((&(pts.adslNearEndPerfStats_pt->flags)), NEAREND_PERF_UAS_FLAG)){
4572 NEAREND_PERF_UAS_FLAG_MAKECMV;
4573 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
4574 #ifdef AMAZON_MEI_DEBUG_ON
4575 printk("\n\nCMV fail, Group PLAM Address 10 Index 0");
4576 #endif
4577 pts.adslNearEndPerfStats_pt->adslneUAS = 0;
4578 }
4579 else{
4580 pts.adslNearEndPerfStats_pt->adslneUAS = RxMessage[4];
4581 }
4582 }
4583
4584 if(IS_FLAG_SET((&(pts.adslNearEndPerfStats_pt->flags)), NEAREND_PERF_HECERR_FLAG)){
4585 if (chantype.bearchannel0)
4586 {
4587 NEAREND_PERF_HECERR_FLAG_BC0_MAKECMV;
4588 }else if (chantype.bearchannel1)
4589 {
4590 NEAREND_PERF_HECERR_FLAG_BC1_MAKECMV;
4591 }
4592 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
4593 #ifdef AMAZON_MEI_DEBUG_ON
4594 printk("\n\nCMV fail, Group PLAM Address 11 Index 0");
4595 #endif
4596 pts.adslNearEndPerfStats_pt->adslneHECErrors = 0;
4597 }
4598 else{
4599 pts.adslNearEndPerfStats_pt->adslneHECErrors = (u32)(RxMessage[4]) + (((u32)(RxMessage[5]))<<16);
4600 }
4601 }
4602
4603 copy_to_user((char *)lon, (char *)pts.adslNearEndPerfStats_pt, sizeof(adslNearEndPerfStats));
4604 kfree(pts.adslNearEndPerfStats_pt);
4605
4606 up(&mei_sema);
4607 break;
4608
4609 case GET_ADSL_FAREND_STATS:
4610
4611 if (showtime!=1)
4612 return -ERESTARTSYS;
4613
4614 if (adsl_mode>8 || adsl_mode_extend > 0)
4615 {
4616 do_gettimeofday(&time_now);
4617 if( FarendData_acquire_time.tv_sec==0 || time_now.tv_sec - FarendData_acquire_time.tv_sec>=1)
4618 {
4619 hdlc_cmd[0]=0x105;
4620
4621 if (ifx_me_hdlc_send((unsigned char *)&hdlc_cmd[0],2)!= -EBUSY)
4622 {
4623 set_current_state(TASK_INTERRUPTIBLE);
4624 schedule_timeout(1);
4625 hdlc_rx_len=0;
4626 hdlc_rx_len = ifx_mei_hdlc_read(&hdlc_rx_buffer,32*2);
4627 if (hdlc_rx_len <=0)
4628 {
4629 return -ERESTARTSYS;
4630 }
4631 FarendStatsData.adslfeRSCorr = ((u32)le16_to_cpu(hdlc_rx_buffer[1]) << 16) + (u32)le16_to_cpu(hdlc_rx_buffer[2]);
4632 FarendStatsData.adslfeCRC = ((u32)le16_to_cpu(hdlc_rx_buffer[3]) << 16) + (u32)le16_to_cpu(hdlc_rx_buffer[4]);
4633 FarendStatsData.adslfeFECS = ((u32)le16_to_cpu(hdlc_rx_buffer[5]) << 16) + (u32)le16_to_cpu(hdlc_rx_buffer[6]);
4634 FarendStatsData.adslfeES = ((u32)le16_to_cpu(hdlc_rx_buffer[7]) << 16) + (u32)le16_to_cpu(hdlc_rx_buffer[8]);
4635 FarendStatsData.adslfeSES = ((u32)le16_to_cpu(hdlc_rx_buffer[9]) << 16) + (u32)le16_to_cpu(hdlc_rx_buffer[10]);
4636 FarendStatsData.adslfeLOSS = ((u32)le16_to_cpu(hdlc_rx_buffer[11]) << 16) + (u32)le16_to_cpu(hdlc_rx_buffer[12]);
4637 FarendStatsData.adslfeUAS = ((u32)le16_to_cpu(hdlc_rx_buffer[13]) << 16) + (u32)le16_to_cpu(hdlc_rx_buffer[14]);
4638 do_gettimeofday(&FarendData_acquire_time);
4639 }
4640
4641 }
4642 }
4643
4644 if(down_interruptible(&mei_sema))
4645 return -ERESTARTSYS;
4646 pts.adslFarEndPerfStats_pt = (adslFarEndPerfStats *)kmalloc(sizeof(adslFarEndPerfStats), GFP_KERNEL);
4647 copy_from_user((char *)pts.adslFarEndPerfStats_pt, (char *)lon, sizeof(adslFarEndPerfStats));
4648 if(IS_FLAG_SET((&(pts.adslFarEndPerfStats_pt->flags)), FAREND_PERF_LOS_FLAG) ||
4649 IS_FLAG_SET((&(pts.adslFarEndPerfStats_pt->flags)), FAREND_PERF_LOF_FLAG) ||
4650 IS_FLAG_SET((&(pts.adslFarEndPerfStats_pt->flags)), FAREND_PERF_LPR_FLAG) ||
4651 IS_FLAG_SET((&(pts.adslFarEndPerfStats_pt->flags)), FAREND_PERF_NCD_FLAG) ||
4652 IS_FLAG_SET((&(pts.adslFarEndPerfStats_pt->flags)), FAREND_PERF_LCD_FLAG) ){
4653 FAREND_PERF_LOS_FLAG_MAKECMV;
4654 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
4655 #ifdef AMAZON_MEI_DEBUG_ON
4656 printk("\n\nCMV fail, Group PLAM Address 1 Index 0");
4657 #endif
4658 RxMessage[4] = 0;
4659 }
4660 if(IS_FLAG_SET((&(pts.adslFarEndPerfStats_pt->flags)), FAREND_PERF_LOS_FLAG)){
4661 if((RxMessage[4]&0x1) == 0x1)
4662 pts.adslFarEndPerfStats_pt->adslfeLOS = 1;
4663 else
4664 pts.adslFarEndPerfStats_pt->adslfeLOS = 0;
4665 }
4666
4667 if(IS_FLAG_SET((&(pts.adslFarEndPerfStats_pt->flags)), FAREND_PERF_LOF_FLAG)){
4668 if((RxMessage[4]&0x2) == 0x2)
4669 pts.adslFarEndPerfStats_pt->adslfeLOF = 1;
4670 else
4671 pts.adslFarEndPerfStats_pt->adslfeLOF = 0;
4672 }
4673
4674 if(IS_FLAG_SET((&(pts.adslFarEndPerfStats_pt->flags)), FAREND_PERF_LPR_FLAG)){
4675 if((RxMessage[4]&0x4) == 0x4)
4676 pts.adslFarEndPerfStats_pt->adslfeLPR = 1;
4677 else
4678 pts.adslFarEndPerfStats_pt->adslfeLPR = 0;
4679 }
4680
4681 if(IS_FLAG_SET((&(pts.adslFarEndPerfStats_pt->flags)), FAREND_PERF_NCD_FLAG)){
4682 pts.adslFarEndPerfStats_pt->adslfeNCD = (RxMessage[4]>>4)&0x3;
4683 }
4684
4685 if(IS_FLAG_SET((&(pts.adslFarEndPerfStats_pt->flags)), FAREND_PERF_LCD_FLAG)){
4686 pts.adslFarEndPerfStats_pt->adslfeLCD = (RxMessage[4]>>6)&0x3;
4687 }
4688 }
4689
4690 if(IS_FLAG_SET((&(pts.adslFarEndPerfStats_pt->flags)), FAREND_PERF_CRC_FLAG)){
4691 if (adsl_mode<=8 && adsl_mode_extend == 0)
4692 {
4693 if (chantype.interleave)
4694 {
4695 FAREND_PERF_CRC_FLAG_LP0_MAKECMV;
4696 }
4697 else
4698 {
4699 FAREND_PERF_CRC_FLAG_LP1_MAKECMV;
4700 }
4701 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
4702 #ifdef AMAZON_MEI_DEBUG_ON
4703 printk("\n\nCMV fail, Group PLAM Address 24 Index 0");
4704 #endif
4705 pts.adslFarEndPerfStats_pt->adslfeCRC = 0;
4706 }
4707 else{
4708 pts.adslFarEndPerfStats_pt->adslfeCRC = RxMessage[4];
4709 }
4710 }else
4711 {
4712 pts.adslFarEndPerfStats_pt->adslfeCRC = FarendStatsData.adslfeCRC;
4713 }
4714 }
4715
4716 if(IS_FLAG_SET((&(pts.adslFarEndPerfStats_pt->flags)), FAREND_PERF_RSCORR_FLAG)){
4717 if (adsl_mode<=8 && adsl_mode_extend == 0)
4718 {
4719 if (chantype.interleave)
4720 FAREND_PERF_RSCORR_FLAG_LP0_MAKECMV;
4721 else
4722 FAREND_PERF_RSCORR_FLAG_LP1_MAKECMV;
4723 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
4724 #ifdef AMAZON_MEI_DEBUG_ON
4725 printk("\n\nCMV fail, Group PLAM Address 28 Index 0");
4726 #endif
4727 pts.adslFarEndPerfStats_pt->adslfeRSCorr = 0;
4728 }
4729 else{
4730 pts.adslFarEndPerfStats_pt->adslfeRSCorr = RxMessage[4];
4731
4732 }
4733 }
4734 else
4735 {
4736 pts.adslFarEndPerfStats_pt->adslfeRSCorr = FarendStatsData.adslfeRSCorr;
4737 }
4738 }
4739
4740 if(IS_FLAG_SET((&(pts.adslFarEndPerfStats_pt->flags)), FAREND_PERF_FECS_FLAG)){
4741 if (adsl_mode<=8 && adsl_mode_extend == 0)
4742 {
4743 FAREND_PERF_FECS_FLAG_MAKECMV;
4744 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
4745 #ifdef AMAZON_MEI_DEBUG_ON
4746 printk("\n\nCMV fail, Group PLAM Address 32 Index 0");
4747 #endif
4748 pts.adslFarEndPerfStats_pt->adslfeFECS = 0;
4749 }
4750 else{
4751 pts.adslFarEndPerfStats_pt->adslfeFECS = RxMessage[4];
4752 }
4753 }else {
4754 pts.adslFarEndPerfStats_pt->adslfeFECS = FarendStatsData.adslfeFECS;
4755 }
4756 }
4757
4758 if(IS_FLAG_SET((&(pts.adslFarEndPerfStats_pt->flags)), FAREND_PERF_ES_FLAG)){
4759 if (adsl_mode<=8 && adsl_mode_extend == 0)
4760 {
4761 FAREND_PERF_ES_FLAG_MAKECMV;
4762 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
4763 #ifdef AMAZON_MEI_DEBUG_ON
4764 printk("\n\nCMV fail, Group PLAM Address 33 Index 0");
4765 #endif
4766 pts.adslFarEndPerfStats_pt->adslfeES = 0;
4767 }
4768 else{
4769 pts.adslFarEndPerfStats_pt->adslfeES = RxMessage[4];
4770 }
4771 }else
4772 {
4773 pts.adslFarEndPerfStats_pt->adslfeES = FarendStatsData.adslfeES;
4774 }
4775 }
4776
4777 if(IS_FLAG_SET((&(pts.adslFarEndPerfStats_pt->flags)), FAREND_PERF_SES_FLAG)){
4778 if (adsl_mode<=8 && adsl_mode_extend == 0)
4779 {
4780 FAREND_PERF_SES_FLAG_MAKECMV;
4781 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
4782 #ifdef AMAZON_MEI_DEBUG_ON
4783 printk("\n\nCMV fail, Group PLAM Address 34 Index 0");
4784 #endif
4785 pts.adslFarEndPerfStats_pt->adslfeSES = 0;
4786 }
4787 else{
4788 pts.adslFarEndPerfStats_pt->adslfeSES = RxMessage[4];
4789
4790 }
4791 }else
4792 {
4793 pts.adslFarEndPerfStats_pt->adslfeSES = FarendStatsData.adslfeSES;
4794 }
4795 }
4796
4797 if(IS_FLAG_SET((&(pts.adslFarEndPerfStats_pt->flags)), FAREND_PERF_LOSS_FLAG)){
4798 if (adsl_mode<=8 && adsl_mode_extend == 0)
4799 {
4800 FAREND_PERF_LOSS_FLAG_MAKECMV;
4801 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
4802 #ifdef AMAZON_MEI_DEBUG_ON
4803 printk("\n\nCMV fail, Group PLAM Address 35 Index 0");
4804 #endif
4805 pts.adslFarEndPerfStats_pt->adslfeLOSS = 0;
4806 }
4807 else{
4808 pts.adslFarEndPerfStats_pt->adslfeLOSS = RxMessage[4];
4809
4810 }
4811 }else
4812 {
4813 pts.adslFarEndPerfStats_pt->adslfeLOSS = FarendStatsData.adslfeLOSS;
4814 }
4815 }
4816
4817 if(IS_FLAG_SET((&(pts.adslFarEndPerfStats_pt->flags)), FAREND_PERF_UAS_FLAG)){
4818 if (adsl_mode<=8 && adsl_mode_extend == 0)
4819 {
4820 FAREND_PERF_UAS_FLAG_MAKECMV;
4821 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
4822 #ifdef AMAZON_MEI_DEBUG_ON
4823 printk("\n\nCMV fail, Group PLAM Address 36 Index 0");
4824 #endif
4825 pts.adslFarEndPerfStats_pt->adslfeUAS = 0;
4826 }
4827 else{
4828 pts.adslFarEndPerfStats_pt->adslfeUAS = RxMessage[4];
4829
4830 }
4831 }else
4832 {
4833 pts.adslFarEndPerfStats_pt->adslfeUAS = FarendStatsData.adslfeUAS;
4834 }
4835 }
4836
4837 if(IS_FLAG_SET((&(pts.adslFarEndPerfStats_pt->flags)), FAREND_PERF_HECERR_FLAG)){
4838 if (chantype.bearchannel0)
4839 {
4840 FAREND_PERF_HECERR_FLAG_BC0_MAKECMV;
4841 }else if (chantype.bearchannel1)
4842 {
4843 FAREND_PERF_HECERR_FLAG_BC1_MAKECMV;
4844 }
4845 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
4846 #ifdef AMAZON_MEI_DEBUG_ON
4847 printk("\n\nCMV fail, Group PLAM Address 37 Index 0");
4848 #endif
4849 pts.adslFarEndPerfStats_pt->adslfeHECErrors = 0;
4850 }
4851 else{
4852 pts.adslFarEndPerfStats_pt->adslfeHECErrors = (u32)(RxMessage[4]) + (((u32)(RxMessage[5]))<<16);
4853 }
4854 }
4855
4856 copy_to_user((char *)lon, (char *)pts.adslFarEndPerfStats_pt, sizeof(adslFarEndPerfStats));
4857 kfree(pts.adslFarEndPerfStats_pt);
4858
4859 up(&mei_sema);
4860
4861 break;
4862 // 603221:tc.chen end
4863 case GET_ADSL_LOOP_DIAGNOSTICS_MODE:
4864 //lon = loop_diagnostics_mode;
4865 copy_to_user((char *)lon, (char *)&loop_diagnostics_mode, sizeof(int));
4866 break;
4867 //>> SHC
4868 case IS_ADSL_LOOP_DIAGNOSTICS_MODE_COMPLETE:
4869 copy_to_user((char *)lon, (char *)&loop_diagnostics_completed, sizeof(int));
4870 break;
4871
4872 //<< end SHC
4873 case LOOP_DIAGNOSTIC_MODE_COMPLETE:
4874 loop_diagnostics_completed = 1;
4875 // read adsl mode
4876 makeCMV(H2D_CMV_READ, STAT, 1, 0, 1, data);
4877 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
4878 #ifdef AMAZON_MEI_DEBUG_ON
4879 printk("\n\nCMV fail, Group STAT Address 1 Index 0");
4880 #endif
4881 }
4882 adsl_mode = RxMessage[4];
4883
4884 makeCMV(H2D_CMV_READ, STAT, 17, 0, 1, data);
4885 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
4886 #ifdef AMAZON_MEI_DEBUG_ON
4887 printk("\n\nCMV fail, Group STAT Address 1 Index 0");
4888 #endif
4889 }
4890 adsl_mode_extend = RxMessage[4];
4891 wake_up_interruptible(&wait_queue_loop_diagnostic);
4892 break;
4893 case SET_ADSL_LOOP_DIAGNOSTICS_MODE:
4894 if (lon != loop_diagnostics_mode)
4895 {
4896 loop_diagnostics_completed = 0;
4897 loop_diagnostics_mode = lon;
4898
4899 mei_ioctl((struct inode *)0,NULL, AMAZON_MEI_REBOOT, NULL);
4900
4901 }
4902 break;
4903 case GET_ADSL_ATUR_SUBCARRIER_STATS:
4904 if (loop_diagnostics_completed == 0)
4905 {
4906 interruptible_sleep_on_timeout(&wait_queue_loop_diagnostic,300*HZ);
4907 if (loop_diagnostics_completed==0)
4908 {
4909 return -ERESTARTSYS;
4910 }
4911 }
4912 if(down_interruptible(&mei_sema))
4913 return -ERESTARTSYS;
4914
4915 pts.adslATURSubcarrierInfo_pt = (adslATURSubcarrierInfo *)kmalloc(sizeof(adslATURSubcarrierInfo), GFP_KERNEL);
4916 copy_from_user((char *)pts.adslATURSubcarrierInfo_pt, (char *)lon, sizeof(adslATURSubcarrierInfo));
4917
4918 if(IS_FLAG_SET((&(pts.adslATURSubcarrierInfo_pt->flags)), FAREND_HLINSC)){
4919 FAREND_HLINSC_MAKECMV(H2D_CMV_READ);
4920 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
4921 #ifdef AMAZON_MEI_DEBUG_ON
4922 printk("\n\nCMV fail, Group PLAM Address 35 Index 0");
4923 #endif
4924 pts.adslATURSubcarrierInfo_pt->HLINSCds = 0;
4925 }
4926 else{
4927 pts.adslATURSubcarrierInfo_pt->HLINSCds = RxMessage[4];
4928
4929 }
4930 }
4931 if(IS_FLAG_SET((&(pts.adslATURSubcarrierInfo_pt->flags)), FAREND_HLINPS)){
4932 int index=0,size=12;
4933 //printk("FAREND_HLINPS\n");
4934 for (index=0;index<1024;index+=size)
4935 {
4936 if (index+size>=1024)
4937 size = 1024-index;
4938 FAREND_HLINPS_MAKECMV(H2D_CMV_READ,index,size);
4939 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
4940 #ifdef AMAZON_MEI_DEBUG_ON
4941 printk("\n\nCMV fail, Group PLAM Address 35 Index 0");
4942 #endif
4943 }
4944 else{
4945 memcpy(&pts.adslATURSubcarrierInfo_pt->HLINpsds[index],&RxMessage[4],size*2);
4946 #if 0
4947 int msg_idx;
4948 for(msg_idx=0;msg_idx<size;msg_idx++)
4949 printk("index:%d ,cmv_result: %04X\n",index+msg_idx,RxMessage[4+msg_idx]);
4950 #endif
4951 }
4952 }
4953 }
4954
4955 if(IS_FLAG_SET((&(pts.adslATURSubcarrierInfo_pt->flags)), FAREND_HLOGMT)){
4956 FAREND_HLOGMT_MAKECMV(H2D_CMV_READ);
4957 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
4958 #ifdef AMAZON_MEI_DEBUG_ON
4959 printk("\n\nCMV fail, Group PLAM Address 35 Index 0");
4960 #endif
4961 pts.adslATURSubcarrierInfo_pt->HLOGMTds = 0;
4962 }
4963 else{
4964 pts.adslATURSubcarrierInfo_pt->HLOGMTds = RxMessage[4];
4965
4966 }
4967 }
4968
4969 /////////////////////////////////////////////////////////////////////////
4970 if(IS_FLAG_SET((&(pts.adslATURSubcarrierInfo_pt->flags)), FAREND_HLOGPS)){
4971 //printk("FAREND_HLOGPS\n");
4972 int index=0,size=12;
4973 for (index=0;index<256;index+=size)
4974 {
4975 if (index+size>=256)
4976 size = 256-index;
4977
4978 FAREND_HLOGPS_MAKECMV(H2D_CMV_READ,index,size);
4979 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
4980 #ifdef AMAZON_MEI_DEBUG_ON
4981 printk("\n\nCMV fail, Group PLAM Address 35 Index 0");
4982 #endif
4983 }
4984 else{
4985 if (adsl_mode < 0x4000 && adsl_mode_extend==0)//adsl2 mode
4986 {
4987 memcpy(&pts.adslATURSubcarrierInfo_pt->HLOGpsds[index],&RxMessage[4],size*2);
4988 }else
4989 {
4990 int msg_idx=0;
4991 for (msg_idx=0;msg_idx<size;msg_idx++)
4992 {
4993 pts.adslATURSubcarrierInfo_pt->HLOGpsds[(index+msg_idx)*2+1] = RxMessage[4+msg_idx];
4994 //printk("index:%d ,cmv_result: %04X\n",index+msg_idx,RxMessage[4+msg_idx]);
4995 }
4996 }
4997 }
4998 }
4999 if (adsl_mode >= 0x4000 || adsl_mode_extend >0)//adsl2+ mode
5000 {
5001 pts.adslATURSubcarrierInfo_pt->HLOGpsds[0] = pts.adslATURSubcarrierInfo_pt->HLOGpsds[1];
5002 for (index=1;index<256;index++)
5003 {
5004 pts.adslATURSubcarrierInfo_pt->HLOGpsds[index*2] = (pts.adslATURSubcarrierInfo_pt->HLOGpsds[(index)*2-1] + pts.adslATURSubcarrierInfo_pt->HLOGpsds[(index)*2+1] +1) >>1;
5005 }
5006 }
5007 }
5008 if(IS_FLAG_SET((&(pts.adslATURSubcarrierInfo_pt->flags)), FAREND_QLNMT)){
5009 FAREND_QLNMT_MAKECMV(H2D_CMV_READ);
5010 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
5011 #ifdef AMAZON_MEI_DEBUG_ON
5012 printk("\n\nCMV fail, Group PLAM Address 35 Index 0");
5013 #endif
5014 pts.adslATURSubcarrierInfo_pt->QLNMTds = 0;
5015 }
5016 else{
5017 pts.adslATURSubcarrierInfo_pt->QLNMTds = RxMessage[4];
5018 }
5019 }
5020
5021 /////////////////////////////////////////////////////////////////////////
5022 if(IS_FLAG_SET((&(pts.adslATURSubcarrierInfo_pt->flags)), FAREND_QLNPS)){
5023 int index=0,size=12;
5024 //printk("FAREND_QLNPS\n");
5025 for (index=0;index<128;index+=size)
5026 {
5027 if (index+size>=128)
5028 size = 128-index;
5029 FAREND_QLNPS_MAKECMV(H2D_CMV_READ,index,size);
5030 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
5031 #ifdef AMAZON_MEI_DEBUG_ON
5032 printk("\n\nCMV fail, Group PLAM Address 35 Index 0");
5033 #endif
5034 }
5035 else{
5036 int msg_idx=0;
5037 for (msg_idx=0;msg_idx<size;msg_idx++)
5038 {
5039 //memcpy(&pts.adslATURSubcarrierInfo_pt->QLNpsds[index],&RxMessage[4],size*2);
5040 if (adsl_mode < 0x4000 && adsl_mode_extend==0)//adsl2 mode
5041 {
5042 pts.adslATURSubcarrierInfo_pt->QLNpsds[(index+msg_idx)*2] = (u16)(RxMessage[4+msg_idx]&0xFF);
5043 pts.adslATURSubcarrierInfo_pt->QLNpsds[(index+msg_idx)*2+1] = (u16)((RxMessage[4+msg_idx]>>8)&0xFF);
5044 }else
5045 {
5046 pts.adslATURSubcarrierInfo_pt->QLNpsds[(index+msg_idx)*4+1] = (u16)(RxMessage[4+msg_idx]&0xFF);
5047 pts.adslATURSubcarrierInfo_pt->QLNpsds[(index+msg_idx)*4+3] = (u16)((RxMessage[4+msg_idx]>>8)&0xFF);
5048 //printk("index:%d ,cmv_result: %04X\n",index+msg_idx,RxMessage[4+msg_idx]);
5049 }
5050 }
5051
5052
5053 }
5054 }
5055 if (adsl_mode >= 0x4000 || adsl_mode_extend >0)//adsl2+ mode
5056 {
5057 pts.adslATURSubcarrierInfo_pt->QLNpsds[0] = pts.adslATURSubcarrierInfo_pt->QLNpsds[1];
5058 for (index=1;index<256;index++)
5059 {
5060 pts.adslATURSubcarrierInfo_pt->QLNpsds[index*2] = (pts.adslATURSubcarrierInfo_pt->QLNpsds[(index)*2-1] + pts.adslATURSubcarrierInfo_pt->QLNpsds[(index)*2+1]) >>1;
5061 }
5062 }
5063 }
5064 if(IS_FLAG_SET((&(pts.adslATURSubcarrierInfo_pt->flags)), FAREND_SNRMT)){
5065 FAREND_SNRMT_MAKECMV(H2D_CMV_READ);
5066 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
5067 #ifdef AMAZON_MEI_DEBUG_ON
5068 printk("\n\nCMV fail, Group PLAM Address 35 Index 0");
5069 #endif
5070 pts.adslATURSubcarrierInfo_pt->SNRMTds = 0;
5071 }
5072 else{
5073 pts.adslATURSubcarrierInfo_pt->SNRMTds = RxMessage[4];
5074 }
5075 }
5076 if(IS_FLAG_SET((&(pts.adslATURSubcarrierInfo_pt->flags)), FAREND_SNRPS)){
5077 int index=0,size=12;
5078 //printk("FAREND_SNRPS\n");
5079 for (index=0;index<512;index+=size)
5080 {
5081 if (index+size>=512)
5082 size = 512-index;
5083 FAREND_SNRPS_MAKECMV(H2D_CMV_READ,index,size);
5084 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
5085 #ifdef AMAZON_MEI_DEBUG_ON
5086 printk("\n\nCMV fail, Group PLAM Address 35 Index 0");
5087 #endif
5088 }
5089 else{
5090 //memcpy(&pts.adslATURSubcarrierInfo_pt->SNRpsds[index],&RxMessage[4],size*2);
5091 int msg_idx=0;
5092 for (msg_idx=0;msg_idx<size;msg_idx++)
5093 {
5094 pts.adslATURSubcarrierInfo_pt->SNRpsds[index+msg_idx] = (u16)(RxMessage[4+msg_idx]&0xFF);
5095 //printk("index:%d ,cmv_result: %04X\n",index+msg_idx,RxMessage[4+msg_idx]);
5096 }
5097
5098 }
5099 }
5100 }
5101 if(IS_FLAG_SET((&(pts.adslATURSubcarrierInfo_pt->flags)), FAREND_BITPS)){
5102 int index=0,size=12;
5103 //printk("FAREND_BITPS\n");
5104 for (index=0;index<256;index+=size)
5105 {
5106 if (index+size>=256)
5107 size = 256-index;
5108 FAREND_BITPS_MAKECMV(H2D_CMV_READ,index,size);
5109 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
5110 #ifdef AMAZON_MEI_DEBUG_ON
5111 printk("\n\nCMV fail, Group PLAM Address 35 Index 0");
5112 #endif
5113 }
5114 else{
5115 int msg_idx=0;
5116 for (msg_idx=0;msg_idx<size;msg_idx++)
5117 {
5118 pts.adslATURSubcarrierInfo_pt->BITpsds[(index+msg_idx)*2] = (u16)(RxMessage[4+msg_idx]&0xFF);
5119 pts.adslATURSubcarrierInfo_pt->BITpsds[(index+msg_idx)*2+1] = (u16)((RxMessage[4+msg_idx]>>8)&0xFF);
5120 //printk("index:%d ,cmv_result: %04X, %d\n",index+msg_idx,RxMessage[4+msg_idx],RxMessage[4+msg_idx]);
5121
5122 }
5123
5124 }
5125 }
5126 }
5127 if(IS_FLAG_SET((&(pts.adslATURSubcarrierInfo_pt->flags)), FAREND_GAINPS)){
5128 int index=0,size=12;
5129 //printk("FAREND_GAINPS\n");
5130 for (index=0;index<512;index+=size)
5131 {
5132 FAREND_GAINPS_MAKECMV(H2D_CMV_READ,index,size);
5133 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
5134 #ifdef AMAZON_MEI_DEBUG_ON
5135 printk("\n\nCMV fail, Group PLAM Address 35 Index 0");
5136 #endif
5137 }
5138 else{
5139 /*
5140 int msg_idx=0;
5141 for (msg_idx=0;msg_idx<size;msg_idx++)
5142 {
5143 pts.adslATURSubcarrierInfo_pt->GAINpsds[(index+msg_idx)*2] = RxMessage[4+msg_idx]&0xFF;
5144 pts.adslATURSubcarrierInfo_pt->GAINpsds[(index+msg_idx)*2+1] = (RxMessage[4+msg_idx]>>8)&0xFF;
5145
5146 }
5147 */
5148 memcpy(&pts.adslATURSubcarrierInfo_pt->GAINpsds[index],&RxMessage[4],size*2);
5149 #if 0
5150 int msg_idx=0;
5151 for (msg_idx=0;msg_idx<size;msg_idx++)
5152 {
5153 printk("index:%d ,cmv_result: %04X\n",index+msg_idx,RxMessage[4+msg_idx]);
5154
5155 }
5156 #endif
5157 }
5158 }
5159 }
5160 copy_to_user((char *)lon, (char *)pts.adslATURSubcarrierInfo_pt, sizeof(adslATURSubcarrierInfo));
5161 kfree(pts.adslATURSubcarrierInfo_pt);
5162
5163 up(&mei_sema);
5164 break;
5165 case GET_ADSL_ATUC_SUBCARRIER_STATS:
5166 if (loop_diagnostics_completed == 0)
5167 {
5168 interruptible_sleep_on_timeout(&wait_queue_loop_diagnostic,300*HZ);
5169 if (loop_diagnostics_completed==0)
5170 {
5171 return -ERESTARTSYS;
5172 }
5173 }
5174 if(down_interruptible(&mei_sema))
5175 return -ERESTARTSYS;
5176 pts.adslATUCSubcarrierInfo_pt = (adslATUCSubcarrierInfo *)kmalloc(sizeof(adslATUCSubcarrierInfo), GFP_KERNEL);
5177 copy_from_user((char *)pts.adslATUCSubcarrierInfo_pt, (char *)lon, sizeof(adslATUCSubcarrierInfo));
5178
5179
5180 if(IS_FLAG_SET((&(pts.adslATUCSubcarrierInfo_pt->flags)), NEAREND_HLINSC)){
5181 NEAREND_HLINSC_MAKECMV(H2D_CMV_READ);
5182 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
5183 #ifdef AMAZON_MEI_DEBUG_ON
5184 printk("\n\nCMV fail, Group INFO Address 71 Index 2");
5185 #endif
5186 pts.adslATUCSubcarrierInfo_pt->HLINSCus = 0;
5187 }
5188 else{
5189 pts.adslATUCSubcarrierInfo_pt->HLINSCus = RxMessage[4];
5190
5191 }
5192 }
5193 if(IS_FLAG_SET((&(pts.adslATUCSubcarrierInfo_pt->flags)), NEAREND_HLINPS)){
5194 int index=0,size=12;
5195 //printk("NEAREND_HLINPS\n");
5196 for (index=0;index<128;index+=size)
5197 {
5198 if (index+size>=128)
5199 size = 128-index;
5200 NEAREND_HLINPS_MAKECMV(H2D_CMV_READ,index,size);
5201 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
5202 #ifdef AMAZON_MEI_DEBUG_ON
5203 printk("\n\nCMV fail, Group INFO Address 73 Index 0");
5204 #endif
5205 }
5206 else{
5207 memcpy(&pts.adslATUCSubcarrierInfo_pt->HLINpsus[index],&RxMessage[4],size*2);
5208 #if 0
5209 int msg_idx;
5210 for (msg_idx=0;msg_idx<size;msg_idx++)
5211 {
5212 printk("index:%d ,cmv_result: %04X\n",index+msg_idx,RxMessage[4+msg_idx]);
5213 }
5214 #endif
5215 }
5216 }
5217 }
5218
5219 if(IS_FLAG_SET((&(pts.adslATUCSubcarrierInfo_pt->flags)), NEAREND_HLOGMT)){
5220 NEAREND_HLOGMT_MAKECMV(H2D_CMV_READ);
5221 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
5222 #ifdef AMAZON_MEI_DEBUG_ON
5223 printk("\n\nCMV fail, Group INFO Address 80 Index 0");
5224 #endif
5225 pts.adslATUCSubcarrierInfo_pt->HLOGMTus = 0;
5226 }
5227 else{
5228 pts.adslATUCSubcarrierInfo_pt->HLOGMTus = RxMessage[4];
5229
5230 }
5231 }
5232
5233 /////////////////////////////////////////////////////////////////////////
5234 if(IS_FLAG_SET((&(pts.adslATUCSubcarrierInfo_pt->flags)), NEAREND_HLOGPS)){
5235 int index=0,size=12;
5236 //printk("NEAREND_HLOGPS\n");
5237 for (index=0;index<64;index+=size)
5238 {
5239 if (index+size>=64)
5240 size = 64-index;
5241 NEAREND_HLOGPS_MAKECMV(H2D_CMV_READ,index,size);
5242 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
5243 #ifdef AMAZON_MEI_DEBUG_ON
5244 printk("\n\nCMV fail, Group INFO Address 75 Index 0");
5245 #endif
5246 }
5247 else{
5248 #if 0
5249 if (adsl_mode <0x4000)//adsl /adsl2 mode
5250 {
5251 #endif
5252 memcpy(&pts.adslATUCSubcarrierInfo_pt->HLOGpsus[index],&RxMessage[4],size*2);
5253 #if 0
5254 }else
5255 {
5256 int msg_idx=0;
5257 for (msg_idx=0;msg_idx<size;msg_idx++)
5258 {
5259 //pts.adslATUCSubcarrierInfo_pt->HLOGpsus[(index+msg_idx)*2+1] = RxMessage[4+msg_idx];
5260 pts.adslATUCSubcarrierInfo_pt->HLOGpsus[(index+msg_idx)] = RxMessage[4+msg_idx];
5261 }
5262 }
5263 #endif
5264 }
5265 }
5266 #if 0
5267 if (adsl_mode >= 0x4000)//adsl2 mode
5268 {
5269 pts.adslATUCSubcarrierInfo_pt->HLOGpsus[0] = pts.adslATUCSubcarrierInfo_pt->HLOGpsus[1];
5270 for (index=1;index<64;index++)
5271 {
5272 pts.adslATUCSubcarrierInfo_pt->HLOGpsus[index*2] = (pts.adslATUCSubcarrierInfo_pt->HLOGpsus[(index)*2-1] + pts.adslATUCSubcarrierInfo_pt->HLOGpsus[(index)*2+1]) >>1;
5273 }
5274 }
5275 #endif
5276 }
5277 if(IS_FLAG_SET((&(pts.adslATUCSubcarrierInfo_pt->flags)), NEAREND_QLNMT)){
5278 NEAREND_QLNMT_MAKECMV(H2D_CMV_READ);
5279 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
5280 #ifdef AMAZON_MEI_DEBUG_ON
5281 printk("\n\nCMV fail, Group INFO Address 80 Index 1");
5282 #endif
5283 pts.adslATUCSubcarrierInfo_pt->QLNMTus = 0;
5284 }
5285 else{
5286 pts.adslATUCSubcarrierInfo_pt->QLNMTus = RxMessage[4];
5287 }
5288 }
5289
5290 /////////////////////////////////////////////////////////////////////////
5291 if(IS_FLAG_SET((&(pts.adslATUCSubcarrierInfo_pt->flags)), NEAREND_QLNPS)){
5292 int index=0,size=12;
5293 //printk("NEAREND_QLNPS\n");
5294 for (index=0;index<32;index+=size)
5295 {
5296 if (index+size>=32)
5297 size = 32-index;
5298 NEAREND_QLNPS_MAKECMV(H2D_CMV_READ,index,size);
5299 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
5300 #ifdef AMAZON_MEI_DEBUG_ON
5301 printk("\n\nCMV fail, Group INFO Address 77 Index 0");
5302 #endif
5303 }
5304 else{
5305 int msg_idx=0;
5306 for (msg_idx=0;msg_idx<size;msg_idx++)
5307 {
5308
5309 #if 0
5310 //memcpy(&pts.adslATUCSubcarrierInfo_pt->QLNpsds[index],&RxMessage[4],size*2);
5311 if (adsl_mode == 0x200 || adsl_mode == 0x800 || adsl_mode ==0x2000 || adsl_mode ==0x4000 || (adsl_mode == 0 && (adsl_mode_extend == 0x4 || adsl_mode_extend == 0x2))//ADSL 2 Annex B(0x200)/J(0x800)/M(0x2000) //ADSL 2+ B,J,M
5312 if (adsl_mode < 0x4000 && adsl_mode_extend==0)//adsl2 mode
5313 {
5314 pts.adslATUCSubcarrierInfo_pt->QLNpsus[(index+msg_idx)*4+1] = (u16)(RxMessage[4+msg_idx]&0xFF);
5315 pts.adslATUCSubcarrierInfo_pt->QLNpsus[(index+msg_idx)*4+3] = (u16)((RxMessage[4+msg_idx]>>8)&0xFF);
5316 }else
5317 #endif
5318 {
5319 pts.adslATUCSubcarrierInfo_pt->QLNpsus[(index+msg_idx)*2] = (u16)(RxMessage[4+msg_idx]&0xFF);
5320 pts.adslATUCSubcarrierInfo_pt->QLNpsus[(index+msg_idx)*2+1] = (u16)((RxMessage[4+msg_idx]>>8)&0xFF);
5321 //printk("index:%d ,cmv_result: %04X\n",index+msg_idx,RxMessage[4+msg_idx]);
5322 }
5323 }
5324
5325
5326 }
5327 }
5328 #if 0
5329 //if (adsl_mode <0x4000)//Annex I/J/L/M
5330 if (adsl_mode == 0x200 || adsl_mode == 0x800 || adsl_mode ==0x2000 || adsl_mode ==0x4000 || (adsl_mode == 0 && (adsl_mode_extend == 0x4 || adsl_mode_extend == 0x2))//ADSL 2 Annex B(0x200)/J(0x800)/M(0x2000) //ADSL 2+ B,J,M
5331 {
5332 pts.adslATUCSubcarrierInfo_pt->QLNpsus[0] = pts.adslATUCSubcarrierInfo_pt->QLNpsus[1];
5333 for (index=1;index<64;index++)
5334 {
5335 pts.adslATUCSubcarrierInfo_pt->QLNpsus[index*2] = (pts.adslATUCSubcarrierInfo_pt->QLNpsus[(index)*2-1] + pts.adslATUCSubcarrierInfo_pt->QLNpsus[(index)*2+1]) >>1;
5336 }
5337 }
5338 #endif
5339 }
5340 if(IS_FLAG_SET((&(pts.adslATUCSubcarrierInfo_pt->flags)), NEAREND_SNRMT)){
5341 NEAREND_SNRMT_MAKECMV(H2D_CMV_READ);
5342 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
5343 #ifdef AMAZON_MEI_DEBUG_ON
5344 printk("\n\nCMV fail, Group INFO Address 80 Index 2");
5345 #endif
5346 pts.adslATUCSubcarrierInfo_pt->SNRMTus = 0;
5347 }
5348 else{
5349 pts.adslATUCSubcarrierInfo_pt->SNRMTus = RxMessage[4];
5350 }
5351 }
5352 if(IS_FLAG_SET((&(pts.adslATUCSubcarrierInfo_pt->flags)), NEAREND_SNRPS)){
5353 int index=0,size=12;
5354 //printk("NEAREND_SNRPS\n");
5355 for (index=0;index<64;index+=size)
5356 {
5357 if (index+size>=64)
5358 size = 64-index;
5359 NEAREND_SNRPS_MAKECMV(H2D_CMV_READ,index,size);
5360 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
5361 #ifdef AMAZON_MEI_DEBUG_ON
5362 printk("\n\nCMV fail, Group INFO Address 78 Index 0");
5363 #endif
5364 }
5365 else{
5366 //memcpy(&pts.adslATUCSubcarrierInfo_pt->SNRpsus[index],&RxMessage[4],size*2);
5367 int msg_idx=0;
5368 for (msg_idx=0;msg_idx<size;msg_idx++)
5369 {
5370 pts.adslATUCSubcarrierInfo_pt->SNRpsus[index+msg_idx] = (u16)(RxMessage[4+msg_idx]&0xFF);
5371 //printk("index:%d ,cmv_result: %04X\n",index+msg_idx,RxMessage[4+msg_idx]);
5372 }
5373
5374 }
5375 }
5376 }
5377 if(IS_FLAG_SET((&(pts.adslATUCSubcarrierInfo_pt->flags)), NEAREND_BITPS)){
5378 int index=0,size=12;
5379 //printk("NEAREND_BITPS\n");
5380 for (index=0;index<32;index+=size)
5381 {
5382 if (index+size>=32)
5383 size = 32-index;
5384 NEAREND_BITPS_MAKECMV(H2D_CMV_READ,index,size);
5385 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
5386 #ifdef AMAZON_MEI_DEBUG_ON
5387 printk("\n\nCMV fail, Group INFO Address 22 Index 0");
5388 #endif
5389 }
5390 else{
5391 int msg_idx=0;
5392 for (msg_idx=0;msg_idx<size;msg_idx++)
5393 {
5394 pts.adslATUCSubcarrierInfo_pt->BITpsus[(index+msg_idx)*2] = (u16)(RxMessage[4+msg_idx]&0xFF);
5395 pts.adslATUCSubcarrierInfo_pt->BITpsus[(index+msg_idx)*2+1] = (u16)((RxMessage[4+msg_idx]>>8)&0xFF);
5396 //printk("index:%d ,cmv_result: %04X\n",index+msg_idx,RxMessage[4+msg_idx]);
5397 }
5398
5399 }
5400 }
5401 }
5402 if(IS_FLAG_SET((&(pts.adslATUCSubcarrierInfo_pt->flags)), NEAREND_GAINPS)){
5403 int index=0,size=12;
5404 //printk("NEAREND_GAINPS\n");
5405 for (index=0;index<64;index+=size)
5406 {
5407 if (index+size>=64)
5408 size = 64-index;
5409 NEAREND_GAINPS_MAKECMV(H2D_CMV_READ,index,size);
5410 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
5411 #ifdef AMAZON_MEI_DEBUG_ON
5412 printk("\n\nCMV fail, Group INFO Address 24 Index 0");
5413 #endif
5414 }
5415 else{
5416 /*
5417 int msg_idx=0;
5418 for (msg_idx=0;msg_idx<size;msg_idx++)
5419 {
5420 pts.adslATUCSubcarrierInfo_pt->GAINpsds[(index+msg_idx)*2] = RxMessage[4+msg_idx]&0xFF;
5421 pts.adslATUCSubcarrierInfo_pt->GAINpsds[(index+msg_idx)*2+1] = (RxMessage[4+msg_idx]>>8)&0xFF;
5422
5423 }
5424 */
5425 memcpy(&pts.adslATUCSubcarrierInfo_pt->GAINpsus[index],&RxMessage[4],size*2);
5426 #if 0
5427 int msg_idx;
5428 for (msg_idx=0;msg_idx<size;msg_idx++)
5429 {
5430 printk("index:%d ,cmv_result: %04X\n",index+msg_idx,RxMessage[4+msg_idx]);
5431 }
5432 #endif
5433 }
5434 }
5435 }
5436 copy_to_user((char *)lon, (char *)pts.adslATUCSubcarrierInfo_pt, sizeof(adslATUCSubcarrierInfo));
5437 kfree(pts.adslATUCSubcarrierInfo_pt);
5438 up(&mei_sema);
5439 break;
5440 case GET_ADSL_LINE_INIT_STATS:
5441 copy_to_user((char *)lon, (char *)&AdslInitStatsData, sizeof(AdslInitStatsData));
5442 break;
5443
5444 case GET_ADSL_POWER_SPECTRAL_DENSITY:
5445 if(down_interruptible(&mei_sema))
5446 return -ERESTARTSYS;
5447 i=0;
5448 pts.adslPowerSpectralDensity_pt = (adslPowerSpectralDensity *)kmalloc(sizeof(adslPowerSpectralDensity), GFP_KERNEL);
5449 memset((char *)pts.adslPowerSpectralDensity_pt, 0, sizeof(adslPowerSpectralDensity));
5450
5451 //US
5452 NOMPSD_US_MAKECMV;
5453 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
5454 #ifdef AMAZON_MEI_DEBUG_ON
5455 printk("\n\nCMV fail, Group PLAM Address 35 Index 0");
5456 #endif
5457 i=-1;
5458 }
5459 else{
5460 j=RxMessage[4];
5461 }
5462 PCB_US_MAKECMV;
5463 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
5464 #ifdef AMAZON_MEI_DEBUG_ON
5465 printk("\n\nCMV fail, Group PLAM Address 35 Index 0");
5466 #endif
5467 i=-1;
5468 }
5469 else{
5470 temp=RxMessage[4];
5471 }
5472 RMSGI_US_MAKECMV;
5473 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
5474 #ifdef AMAZON_MEI_DEBUG_ON
5475 printk("\n\nCMV fail, Group PLAM Address 35 Index 0");
5476 #endif
5477 i=-1;
5478 }
5479 else{
5480 k=(int16_t)RxMessage[4];
5481 }
5482 if (i==0)
5483 {
5484 pts.adslPowerSpectralDensity_pt->ACTPSDus = ((int )(j*256 - temp*10*256 + k*10)) /256;
5485 }
5486 // DS
5487 i=0;
5488 j=temp=temp2=0;
5489 NOMPSD_DS_MAKECMV;
5490 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
5491 #ifdef AMAZON_MEI_DEBUG_ON
5492 printk("\n\nCMV fail, Group PLAM Address 35 Index 0");
5493 #endif
5494 i=-1;
5495 }
5496 else{
5497 j=RxMessage[4];
5498 }
5499 PCB_DS_MAKECMV;
5500 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
5501 #ifdef AMAZON_MEI_DEBUG_ON
5502 printk("\n\nCMV fail, Group PLAM Address 35 Index 0");
5503 #endif
5504 i=-1;
5505 }
5506 else{
5507 temp=RxMessage[4];
5508 }
5509 RMSGI_DS_MAKECMV;
5510 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
5511 #ifdef AMAZON_MEI_DEBUG_ON
5512 printk("\n\nCMV fail, Group PLAM Address 35 Index 0");
5513 #endif
5514 i=-1;
5515 }
5516 else{
5517 //temp2=RxMessage[4];
5518 k=(int16_t)RxMessage[4];
5519 }
5520 if (i==0)
5521 {
5522 pts.adslPowerSpectralDensity_pt->ACTPSDds = ((int )(j*256 - temp*10*256 + k*10)) /256;
5523 }
5524 copy_to_user((char *)lon, (char *)pts.adslPowerSpectralDensity_pt, sizeof(adslPowerSpectralDensity));
5525 kfree(pts.adslPowerSpectralDensity_pt);
5526 up(&mei_sema);
5527 break;
5528 case AMAZON_MEI_START:
5529 showtime=0;
5530 loop_diagnostics_completed = 0;
5531 #ifdef ARC_READY_ACK
5532 #ifdef LOCK_RETRY
5533 i=0;
5534 lock_retry:
5535 if(down_trylock(&mei_sema)!=0)
5536 {
5537 reboot_lock = 1;
5538 printk("lock fail\n");
5539 i++;
5540 if (i <=5)
5541 {
5542 set_current_state(TASK_INTERRUPTIBLE);
5543 schedule_timeout(10);
5544 goto lock_retry;
5545 }else
5546 {
5547 printk("Force to Reboot ADSL!\n");
5548 up(&mei_sema);
5549 set_current_state(TASK_INTERRUPTIBLE);
5550 schedule_timeout(1000);
5551 sema_init(&mei_sema, 1); // semaphore initialization, mutex
5552 }
5553 }else
5554 {
5555 reboot_lock = 1;
5556 }
5557 #else
5558 if(down_interruptible(&mei_sema)) //disable CMV access until ARC ready
5559 {
5560 return -ERESTARTSYS;
5561 }
5562 #endif
5563 #endif
5564 //CLEAR_BIT((*((volatile u32 *)0xB0100B40)), 0x40); //Warning LED GPIO ON
5565 if(chantype.interleave==1){
5566 kfree(interleave_mei_net.priv);
5567 unregister_netdev(&interleave_mei_net);
5568 }
5569 else if(chantype.fast==1){
5570 kfree(fast_mei_net.priv);
5571 unregister_netdev(&fast_mei_net);
5572 }
5573 chantype.interleave=0;
5574 chantype.fast=0;
5575 meiMailboxInterruptsDisable(); //disable all MEI interrupts
5576 if(mei_arc_swap_buff == NULL){
5577 mei_arc_swap_buff = (u32 *)kmalloc(MAXSWAPSIZE*4, GFP_KERNEL);
5578 if(mei_arc_swap_buff==NULL){
5579 #ifdef AMAZON_MEI_DEBUG_ON
5580 printk("\n\n malloc fail for codeswap buff");
5581 #endif
5582 meierr=MEI_FAILURE;
5583 }
5584 }
5585 if(meiForceRebootAdslModem() != MEI_SUCCESS){
5586 #ifdef AMAZON_MEI_DEBUG_ON
5587 printk("\n\n meiForceRebootAdslModem() error...");
5588 #endif
5589 meierr=MEI_FAILURE;
5590 }
5591 interruptible_sleep_on(&wait_queue_codeswap);
5592 // reset is called
5593 break;
5594 case AMAZON_MEI_MIB_DAEMON:
5595 #ifdef IFX_SMALL_FOOTPRINT /* [ */
5596 return -1;
5597 #else /* ][ !IFX_SMALL_FOOTPRINT */
5598 i=0;
5599 while(1){
5600 if(i<MIB_INTERVAL)
5601 interruptible_sleep_on_timeout(&wait_queue_mibdaemon, ((MIB_INTERVAL-i)/(1000/HZ)));
5602 i=0;
5603 if(showtime==1){
5604 // printk("\n\n update mib");
5605
5606 do_gettimeofday(&time_now);
5607 if(time_now.tv_sec - current_intvl->start_time.tv_sec>=900){
5608 if(current_intvl->list.next!=&interval_list){
5609 current_intvl = list_entry(current_intvl->list.next, amazon_mei_mib, list);
5610 do_gettimeofday(&(current_intvl->start_time));
5611 }
5612 else{
5613 mib_ptr = list_entry(interval_list.next, amazon_mei_mib, list);
5614 list_del(interval_list.next);
5615 memset(mib_ptr, 0, sizeof(amazon_mei_mib));
5616 list_add_tail(&(mib_ptr->list), &interval_list);
5617 if(current_intvl->list.next==&interval_list)
5618 #ifdef AMAZON_MEI_DEBUG_ON
5619 printk("\n\nlink list error");
5620 #endif
5621 current_intvl = list_entry(current_intvl->list.next, amazon_mei_mib, list);
5622 do_gettimeofday(&(current_intvl->start_time));
5623 }
5624 }
5625
5626 if(down_interruptible(&mei_sema))
5627 return -ERESTARTSYS;
5628 /*
5629 ATUC_PERF_LO_FLAG_MAKECMV;
5630 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
5631 #ifdef AMAZON_MEI_DEBUG_ON
5632 printk("\n\nCMV fail, Group 7 Address 0 Index 0");
5633 #endif
5634 }
5635 else{
5636 if(RxMessage[4]&PLAM_LOS_FailureBit){
5637 current_intvl->AtucPerfLos++;
5638 ATUC_PERF_LOSS++;
5639 CurrStatus.adslAtucCurrStatus = 2;
5640 }
5641 if(RxMessage[4]&PLAM_LOF_FailureBit){
5642 current_intvl->AtucPerfLof++;
5643 ATUC_PERF_LOFS++;
5644 CurrStatus.adslAtucCurrStatus = 1;
5645 }
5646 if(!(RxMessage[4]&(PLAM_LOS_FailureBit|PLAM_LOF_FailureBit)))
5647 CurrStatus.adslAtucCurrStatus = 0;
5648 }
5649 */
5650 ATUC_PERF_ESS_FLAG_MAKECMV;
5651 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
5652 #ifdef AMAZON_MEI_DEBUG_ON
5653 printk("\n\nCMV fail, Group 7 Address 7 Index 0");
5654 #endif
5655 }
5656 else{
5657 temp = RxMessage[4]-mib_pread.ATUC_PERF_ESS;
5658 if(temp>=0){
5659 current_intvl->AtucPerfEs+=temp;
5660 ATUC_PERF_ESS+=temp;
5661 mib_pread.ATUC_PERF_ESS = RxMessage[4];
5662 }
5663 else{
5664 current_intvl->AtucPerfEs+=0xffff-mib_pread.ATUC_PERF_ESS+RxMessage[4];
5665 ATUC_PERF_ESS+=0xffff-mib_pread.ATUC_PERF_ESS+RxMessage[4];
5666 mib_pread.ATUC_PERF_ESS = RxMessage[4];
5667 }
5668 }
5669 /*
5670 ATUR_PERF_LO_FLAG_MAKECMV;
5671 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
5672 #ifdef AMAZON_MEI_DEBUG_ON
5673 printk("\n\nCMV fail, Group 7 Address 1 Index 0");
5674 #endif
5675 }
5676 else{
5677 if(RxMessage[4]&PLAM_LOS_FailureBit){
5678 current_intvl->AturPerfLos++;
5679 ATUR_PERF_LOSS++;
5680 CurrStatus.adslAturCurrStatus = 2;
5681 }
5682 if(RxMessage[4]&PLAM_LOF_FailureBit){
5683 current_intvl->AturPerfLof++;
5684 ATUR_PERF_LOFS++;
5685 CurrStatus.adslAturCurrStatus = 1;
5686 }
5687 if(RxMessage[4]&PLAM_LPR_FailureBit){
5688 current_intvl->AturPerfLpr++;
5689 ATUR_PERF_LPR++;
5690 CurrStatus.adslAturCurrStatus = 3;
5691 }
5692 if(!(RxMessage[4]&(PLAM_LOS_FailureBit|PLAM_LOF_FailureBit|PLAM_LPR_FailureBit)))
5693 CurrStatus.adslAturCurrStatus = 0;
5694 }
5695 */
5696 ATUR_PERF_ESS_FLAG_MAKECMV;
5697 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
5698 #ifdef AMAZON_MEI_DEBUG_ON
5699 printk("\n\nCMV fail, Group 7 Address 33 Index 0");
5700 #endif
5701 }
5702 else{
5703 temp = RxMessage[4]-mib_pread.ATUR_PERF_ESS;
5704 if(temp>=0){
5705 current_intvl->AturPerfEs+=temp;
5706 ATUR_PERF_ESS+=temp;
5707 mib_pread.ATUR_PERF_ESS = RxMessage[4];
5708 }
5709 else{
5710 current_intvl->AturPerfEs+=0xffff-mib_pread.ATUR_PERF_ESS+RxMessage[4];
5711 ATUR_PERF_ESS+= 0xffff-mib_pread.ATUR_PERF_ESS+RxMessage[4];
5712 mib_pread.ATUR_PERF_ESS=RxMessage[4];
5713 }
5714 }
5715 // to update rx/tx blocks
5716 ATUR_CHAN_RECV_BLK_FLAG_MAKECMV_LSW;
5717 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
5718 #ifdef AMAZON_MEI_DEBUG_ON
5719 printk("\n\nCMV fail, Group 7 Address 20 Index 0");
5720 #endif
5721 }
5722 else{
5723 temp = RxMessage[4];
5724 }
5725 ATUR_CHAN_RECV_BLK_FLAG_MAKECMV_MSW;
5726 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
5727 #ifdef AMAZON_MEI_DEBUG_ON
5728 printk("\n\nCMV fail, Group 7 Address 21 Index 0");
5729 #endif
5730 }
5731 else{
5732 temp2 = RxMessage[4];
5733 }
5734 if((temp + (temp2<<16) - mib_pread.ATUR_CHAN_RECV_BLK)>=0){
5735 current_intvl->AturChanPerfRxBlk+=temp + (temp2<<16) - mib_pread.ATUR_CHAN_RECV_BLK;
5736 ATUR_CHAN_RECV_BLK+=temp + (temp2<<16) - mib_pread.ATUR_CHAN_RECV_BLK;
5737 mib_pread.ATUR_CHAN_RECV_BLK = temp + (temp2<<16);
5738 }
5739 else{
5740 current_intvl->AturChanPerfRxBlk+=0xffffffff - mib_pread.ATUR_CHAN_RECV_BLK +(temp + (temp2<<16));
5741 ATUR_CHAN_RECV_BLK+=0xffffffff - mib_pread.ATUR_CHAN_RECV_BLK +(temp + (temp2<<16));
5742 mib_pread.ATUR_CHAN_RECV_BLK = temp + (temp2<<16);
5743 }
5744 current_intvl->AturChanPerfTxBlk = current_intvl->AturChanPerfRxBlk;
5745 ATUR_CHAN_TX_BLK = ATUR_CHAN_RECV_BLK;
5746 /*
5747 ATUR_CHAN_TX_BLK_FLAG_MAKECMV_LSW;
5748 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS)
5749 printk("\n\nCMV fail, Group 7 Address 20 Index 0");
5750 else{
5751 if(RxMessage[4]){
5752 current_intvl->AturChanPerfTxBlk+=RxMessage[4];
5753 ATUR_CHAN_TX_BLK+=RxMessage[4];
5754 }
5755 }
5756 ATUR_CHAN_TX_BLK_FLAG_MAKECMV_MSW;
5757 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS)
5758 printk("\n\nCMV fail, Group 7 Address 21 Index 0");
5759 else{
5760 if(RxMessage[4]){
5761 current_intvl->AturChanPerfTxBlk+=(int)((RxMessage[4])<<16);
5762 ATUR_CHAN_TX_BLK+=(int)((RxMessage[4])<<16);
5763 }
5764 }
5765 */
5766 if(chantype.interleave == 1){
5767 ATUR_CHAN_CORR_BLK_FLAG_MAKECMV_INTL;
5768 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
5769 #ifdef AMAZON_MEI_DEBUG_ON
5770 printk("\n\nCMV fail, Group 7 Address 3 Index 0");
5771 #endif
5772 }
5773 else{
5774 temp = RxMessage[4] - mib_pread.ATUR_CHAN_CORR_BLK_INTL;
5775 if(temp>=0){
5776 current_intvl->AturChanPerfCorrBlk+=temp;
5777 ATUR_CHAN_CORR_BLK+=temp;
5778 mib_pread.ATUR_CHAN_CORR_BLK_INTL = RxMessage[4];
5779 }
5780 else{
5781 current_intvl->AturChanPerfCorrBlk+=0xffff - mib_pread.ATUR_CHAN_CORR_BLK_INTL +RxMessage[4];
5782 ATUR_CHAN_CORR_BLK+=0xffff - mib_pread.ATUR_CHAN_CORR_BLK_INTL +RxMessage[4];
5783 mib_pread.ATUR_CHAN_CORR_BLK_INTL = RxMessage[4];
5784 }
5785 }
5786 }
5787 else if(chantype.fast == 1){
5788 ATUR_CHAN_CORR_BLK_FLAG_MAKECMV_FAST;
5789 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
5790 #ifdef AMAZON_MEI_DEBUG_ON
5791 printk("\n\nCMV fail, Group 7 Address 3 Index 1");
5792 #endif
5793 }
5794 else{
5795 temp = RxMessage[4] - mib_pread.ATUR_CHAN_CORR_BLK_FAST;
5796 if(temp>=0){
5797 current_intvl->AturChanPerfCorrBlk+=temp;
5798 ATUR_CHAN_CORR_BLK+=temp;
5799 mib_pread.ATUR_CHAN_CORR_BLK_FAST = RxMessage[4];
5800 }
5801 else{
5802 current_intvl->AturChanPerfCorrBlk+=0xffff - mib_pread.ATUR_CHAN_CORR_BLK_FAST + RxMessage[4];
5803 ATUR_CHAN_CORR_BLK+=0xffff - mib_pread.ATUR_CHAN_CORR_BLK_FAST + RxMessage[4];
5804 mib_pread.ATUR_CHAN_CORR_BLK_FAST = RxMessage[4];
5805 }
5806 }
5807 }
5808
5809 if(chantype.interleave == 1){
5810 ATUR_CHAN_UNCORR_BLK_FLAG_MAKECMV_INTL;
5811 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
5812 #ifdef AMAZON_MEI_DEBUG_ON
5813 printk("\n\nCMV fail, Group 7 Address 2 Index 0");
5814 #endif
5815 }
5816 else{
5817 temp = RxMessage[4] - mib_pread.ATUR_CHAN_UNCORR_BLK_INTL;
5818 if(temp>=0){
5819 current_intvl->AturChanPerfUncorrBlk+=temp;
5820 ATUR_CHAN_UNCORR_BLK+=temp;
5821 mib_pread.ATUR_CHAN_UNCORR_BLK_INTL = RxMessage[4];
5822 }
5823 else{
5824 current_intvl->AturChanPerfUncorrBlk+=0xffff - mib_pread.ATUR_CHAN_UNCORR_BLK_INTL + RxMessage[4];
5825 ATUR_CHAN_UNCORR_BLK+=0xffff - mib_pread.ATUR_CHAN_UNCORR_BLK_INTL + RxMessage[4];
5826 mib_pread.ATUR_CHAN_UNCORR_BLK_INTL = RxMessage[4];
5827 }
5828 }
5829 }
5830 else if(chantype.fast == 1){
5831 ATUR_CHAN_UNCORR_BLK_FLAG_MAKECMV_FAST;
5832 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
5833 #ifdef AMAZON_MEI_DEBUG_ON
5834 printk("\n\nCMV fail, Group 7 Address 2 Index 1");
5835 #endif
5836 }
5837 else{
5838 temp = RxMessage[4] - mib_pread.ATUR_CHAN_UNCORR_BLK_FAST;
5839 if(temp>=0){
5840 current_intvl->AturChanPerfUncorrBlk+=temp;
5841 ATUR_CHAN_UNCORR_BLK+=temp;
5842 mib_pread.ATUR_CHAN_UNCORR_BLK_FAST = RxMessage[4];
5843 }
5844 else{
5845 current_intvl->AturChanPerfUncorrBlk+=0xffff - mib_pread.ATUR_CHAN_UNCORR_BLK_FAST + RxMessage[4];
5846 ATUR_CHAN_UNCORR_BLK+=0xffff - mib_pread.ATUR_CHAN_UNCORR_BLK_FAST + RxMessage[4];
5847 mib_pread.ATUR_CHAN_UNCORR_BLK_FAST = RxMessage[4];
5848 }
5849 }
5850 }
5851
5852 //RFC-3440
5853
5854 #ifdef AMAZON_MEI_MIB_RFC3440
5855 ATUC_PERF_STAT_FASTR_FLAG_MAKECMV; //???
5856 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
5857 #ifdef AMAZON_MEI_DEBUG_ON
5858 printk("\n\nCMV fail, Group 0 Address 0 Index 0");
5859 #endif
5860 }
5861 else{
5862 temp = RxMessage[4] - mib_pread.ATUC_PERF_STAT_FASTR;
5863 if(temp>=0){
5864 current_intvl->AtucPerfStatFastR+=temp;
5865 ATUC_PERF_STAT_FASTR+=temp;
5866 mib_pread.ATUC_PERF_STAT_FASTR = RxMessage[4];
5867 }
5868 else{
5869 current_intvl->AtucPerfStatFastR+=0xffff - mib_pread.ATUC_PERF_STAT_FASTR + RxMessage[4];
5870 ATUC_PERF_STAT_FASTR+=0xffff - mib_pread.ATUC_PERF_STAT_FASTR + RxMessage[4];
5871 mib_pread.ATUC_PERF_STAT_FASTR = RxMessage[4];
5872 }
5873 }
5874 ATUC_PERF_STAT_FAILED_FASTR_FLAG_MAKECMV; //???
5875 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
5876 #ifdef AMAZON_MEI_DEBUG_ON
5877 printk("\n\nCMV fail, Group 0 Address 0 Index 0");
5878 #endif
5879 }
5880 else{
5881 temp = RxMessage[4] - mib_pread.ATUC_PERF_STAT_FAILED_FASTR;
5882 if(temp>=0){
5883 current_intvl->AtucPerfStatFailedFastR+=temp;
5884 ATUC_PERF_STAT_FAILED_FASTR+=temp;
5885 mib_pread.ATUC_PERF_STAT_FAILED_FASTR = RxMessage[4];
5886 }
5887 else{
5888 current_intvl->AtucPerfStatFailedFastR+=0xffff - mib_pread.ATUC_PERF_STAT_FAILED_FASTR + RxMessage[4];
5889 ATUC_PERF_STAT_FAILED_FASTR+=0xffff - mib_pread.ATUC_PERF_STAT_FAILED_FASTR + RxMessage[4];
5890 mib_pread.ATUC_PERF_STAT_FAILED_FASTR = RxMessage[4];
5891 }
5892 }
5893 ATUC_PERF_STAT_SESL_FLAG_MAKECMV;
5894 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
5895 #ifdef AMAZON_MEI_DEBUG_ON
5896 printk("\n\nCMV fail, Group 7 Address 8 Index 0");
5897 #endif
5898 }
5899 else{
5900 temp = RxMessage[4] - mib_pread.ATUC_PERF_STAT_SESL;
5901 if(temp>=0){
5902 current_intvl->AtucPerfStatSesL+=temp;
5903 ATUC_PERF_STAT_SESL+=temp;
5904 mib_pread.ATUC_PERF_STAT_SESL = RxMessage[4];
5905 }
5906 else{
5907 current_intvl->AtucPerfStatSesL+=0xffff - mib_pread.ATUC_PERF_STAT_SESL + RxMessage[4];
5908 ATUC_PERF_STAT_SESL+=0xffff - mib_pread.ATUC_PERF_STAT_SESL + RxMessage[4];
5909 mib_pread.ATUC_PERF_STAT_SESL = RxMessage[4];
5910 }
5911 }
5912 ATUC_PERF_STAT_UASL_FLAG_MAKECMV;
5913 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
5914 #ifdef AMAZON_MEI_DEBUG_ON
5915 printk("\n\nCMV fail, Group 7 Address 10 Index 0");
5916 #endif
5917 }
5918 else{
5919 temp = RxMessage[4] - mib_pread.ATUC_PERF_STAT_UASL;
5920 if(temp>=0){
5921 current_intvl->AtucPerfStatUasL+=temp;
5922 ATUC_PERF_STAT_UASL+=temp;
5923 mib_pread.ATUC_PERF_STAT_UASL = RxMessage[4];
5924 }
5925 else{
5926 current_intvl->AtucPerfStatUasL+=0xffff - mib_pread.ATUC_PERF_STAT_UASL + RxMessage[4];
5927 ATUC_PERF_STAT_UASL+=0xffff - mib_pread.ATUC_PERF_STAT_UASL + RxMessage[4];
5928 mib_pread.ATUC_PERF_STAT_UASL = RxMessage[4];
5929 }
5930 }
5931 ATUR_PERF_STAT_SESL_FLAG_MAKECMV;
5932 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
5933 #ifdef AMAZON_MEI_DEBUG_ON
5934 printk("\n\nCMV fail, Group 7 Address 34 Index 0");
5935 #endif
5936 }
5937 else{
5938 temp = RxMessage[4] - mib_pread.ATUR_PERF_STAT_SESL;
5939 if(temp>=0){
5940 current_intvl->AtucPerfStatUasL+=temp;
5941 ATUC_PERF_STAT_UASL+=temp;
5942 mib_pread.ATUR_PERF_STAT_SESL = RxMessage[4];
5943 }
5944 else{
5945 current_intvl->AtucPerfStatUasL+=0xffff - mib_pread.ATUR_PERF_STAT_SESL + RxMessage[4];
5946 ATUC_PERF_STAT_UASL+=0xffff - mib_pread.ATUR_PERF_STAT_SESL + RxMessage[4];
5947 mib_pread.ATUR_PERF_STAT_SESL = RxMessage[4];
5948 }
5949 }
5950
5951 #endif
5952 up(&mei_sema);
5953
5954 do_gettimeofday(&time_fini);
5955 i = ((int)((time_fini.tv_sec-time_now.tv_sec)*1000)) + ((int)((time_fini.tv_usec-time_now.tv_usec)/1000)) ; //msec
5956 }//showtime==1
5957 }
5958 break;
5959 #endif /* ] !IFX_SMALL_FOOTPRINT */
5960 case AMAZON_MEI_RESET:
5961 case AMAZON_MEI_REBOOT:
5962 case AMAZON_MEI_SHOWTIME:
5963 /* if(mei_arc_swap_buff !=NULL){
5964 kfree(mei_arc_swap_buff);
5965 mei_arc_swap_buff=NULL;
5966 }
5967 if(image_buffer !=NULL){
5968 // kfree(image_buffer);
5969 vfree(image_buffer);
5970 image_buffer =NULL;
5971 }
5972 */
5973 if(clreoc_command_pkt !=NULL){
5974 kfree(clreoc_command_pkt);
5975 clreoc_command_pkt =NULL;
5976 }
5977 for(i=0;i<CLREOC_BUFF_SIZE;i++)
5978 clreoc_pkt[i].len=0; //flush all remaining clreoc commands in buffer
5979 /*
5980 memset(mei_mib, 0, (sizeof(amazon_mei_mib)*INTERVAL_NUM));
5981 INIT_LIST_HEAD(&interval_list);
5982 for(i=0;i<INTERVAL_NUM;i++)
5983 list_add_tail(&(mei_mib[i].list), &interval_list);
5984 current_intvl = list_entry(interval_list.next, amazon_mei_mib, list);
5985 do_gettimeofday(&(current_intvl->start_time));
5986 ATUC_PERF_LOFS=0;
5987 ATUC_PERF_LOSS=0;
5988 ATUC_PERF_ESS=0;
5989 ATUC_PERF_INITS=0;
5990 ATUR_PERF_LOFS=0;
5991 ATUR_PERF_LOSS=0;
5992 ATUR_PERF_LPR=0;
5993 ATUR_PERF_ESS=0;
5994 ATUR_CHAN_RECV_BLK=0;
5995 ATUR_CHAN_TX_BLK=0;
5996 ATUR_CHAN_CORR_BLK=0;
5997 ATUR_CHAN_UNCORR_BLK=0;
5998 memset((((u8 *)&AlarmConfProfile)+32), 0, 16*4);
5999 AlarmConfProfile.adslLineAlarmConfProfileRowStatus=1;
6000 */
6001 PrevTxRate.adslAtucChanPrevTxRate=0;
6002 PrevTxRate.adslAturChanPrevTxRate=0;
6003 CurrStatus.adslAtucCurrStatus=0;
6004 CurrStatus.adslAturCurrStatus=0;
6005
6006 if((command==AMAZON_MEI_RESET) || (command==AMAZON_MEI_REBOOT)){
6007 #ifdef AMAZON_CHECK_LINK
6008 if (adsl_link_notify){
6009 (*adsl_link_notify)(0);
6010 }
6011 #endif
6012 showtime=0;
6013 //CLEAR_BIT((*((volatile u32 *)0xB0100B40)), 0x40); //Warning LED GPIO ON
6014 // disconnect net_dev
6015 if(chantype.interleave==1){
6016 kfree(interleave_mei_net.priv);
6017 unregister_netdev(&interleave_mei_net);
6018 // if(unregister_netdev(&interleave_mei_net)!=0)
6019 // printk("\n unregister interleave fail");
6020 }
6021 else if(chantype.fast==1){
6022 kfree(fast_mei_net.priv);
6023 unregister_netdev(&fast_mei_net);
6024 // if(unregister_netdev(&fast_mei_net)!=0)
6025 // printk("\n unregister fast fail");
6026 }
6027 chantype.interleave=0;
6028 chantype.fast=0;
6029 // 603221:tc.chen start
6030 chantype.bearchannel0 = 0;
6031 chantype.bearchannel1 = 0;
6032 adsl_mode = 0;
6033 // 603221:tc.chen end
6034
6035 while(1){
6036
6037 makeCMV(H2D_CMV_READ, STAT, 0, 0, 1, NULL); //maximum allowed tx message length, in bytes
6038 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
6039 //printk("AdslInitStatsData.FullInitializationCount++\n");
6040 AdslInitStatsData.FullInitializationCount++;
6041 //printk("AdslInitStatsData.FailedFullInitializationCount++\n");
6042 AdslInitStatsData.FailedFullInitializationCount++;
6043 //printk("AdslInitStatsData.LINIT_Errors++\n");
6044 AdslInitStatsData.LINIT_Errors++;
6045 }else
6046 {
6047 //printk("RxMessage=%X\n",RxMessage[4]);
6048 if ( RxMessage[4]!=0x1)
6049 {
6050 //printk("AdslInitStatsData.FullInitializationCount++\n");
6051 AdslInitStatsData.FullInitializationCount++;
6052 if ( RxMessage[4] != 0x7)
6053 {
6054 //printk("AdslInitStatsData.LINIT_Errors++\n");
6055 AdslInitStatsData.LINIT_Errors++;
6056 //printk("AdslInitStatsData.FailedFullInitializationCount++\n");
6057 AdslInitStatsData.FailedFullInitializationCount++;
6058
6059 }
6060 }
6061 }
6062
6063 reboot_flag=0;
6064 wake_up_interruptible(&wait_queue_codeswap); //wake up codeswap daemon
6065
6066 interruptible_sleep_on_timeout(&wait_queue_reboot, 1*HZ); // sleep until arc ready
6067 #ifdef ARC_READY_ACK
6068 if(reboot_flag!=0)
6069 break;
6070 else
6071 {
6072 up(&mei_sema);
6073 printk("\n reboot retry");
6074 }
6075 #else
6076 break;
6077 #endif
6078 }
6079 }
6080 else{ //AMAZON_MEI_SHOWTIME
6081 if(down_interruptible(&mei_sema))
6082 return -ERESTARTSYS;
6083
6084 // clreoc stuff
6085 makeCMV(H2D_CMV_READ, INFO, 83, 0, 1, data); //maximum allowed tx message length, in bytes
6086 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
6087 #ifdef AMAZON_MEI_DEBUG_ON
6088 printk("\n\nCMV fail, Group 3 Address 83 Index 0");
6089 #endif
6090 }
6091 else{
6092 clreoc_max_tx_len = (int)RxMessage[4];
6093 clreoc_command_pkt = kmalloc((clreoc_max_tx_len*CLREOC_BUFF_SIZE), GFP_KERNEL);
6094 if(clreoc_command_pkt == NULL){
6095 #ifdef AMAZON_MEI_DEBUG_ON
6096 printk("kmalloc error for clreoc_command_pkt\n\n");
6097 #endif
6098 up(&mei_sema);
6099 return -1;
6100 }
6101 for(i=0;i<CLREOC_BUFF_SIZE;i++){
6102 clreoc_pkt[i].command = (u8 *)(((u8 *)clreoc_command_pkt) + (clreoc_max_tx_len*i));
6103 clreoc_pkt[i].len=0;
6104 }
6105 }
6106
6107 // decide what channel, then register
6108 makeCMV(H2D_CMV_READ, STAT, 12, 0, 1, data);
6109 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
6110 #ifdef AMAZON_MEI_DEBUG_ON
6111 printk("\n\nCMV fail, Group 2 Address 12 Index 0");
6112 #endif
6113 }
6114 else{
6115 if((RxMessage[4]&0x1)==1){
6116 if(register_netdev(&interleave_mei_net)!=0){
6117 #ifdef AMAZON_MEI_DEBUG_ON
6118 printk("\n\n Register interleave Device Failed.");
6119 #endif
6120 }
6121 else{
6122 chantype.interleave = 1;
6123 chantype.fast= 0;
6124 #ifdef AMAZON_MEI_DEBUG_ON
6125 printk("\n channel is interleave");
6126 #endif
6127 }
6128 }
6129 else if((RxMessage[4]&0x2)==2){
6130 if(register_netdev(&fast_mei_net)!=0){
6131 #ifdef AMAZON_MEI_DEBUG_ON
6132 printk("\n\n Register fast Device Failed.");
6133 #endif
6134 }
6135 else{
6136 chantype.fast = 1;
6137 chantype.interleave = 0;
6138 #ifdef AMAZON_MEI_DEBUG_ON
6139 printk("\n channel is fast");
6140 #endif
6141 }
6142 }
6143 else{
6144 #ifdef AMAZON_MEI_DEBUG_ON
6145 printk("\nunknown channel type, 0x%8x", RxMessage[4]);
6146 #endif
6147 }
6148 // 603221:tc.chen start
6149 if ( (RxMessage[4]&0x100) == 0x100)
6150 {
6151 chantype.bearchannel0 = 1;
6152 }else if ( (RxMessage[4]&0x100) == 0x200)
6153 {
6154 chantype.bearchannel1 = 1;
6155 }
6156 // 603221:tc.chen end
6157 }
6158 // 603221:tc.chen start
6159 // read adsl mode
6160 makeCMV(H2D_CMV_READ, STAT, 1, 0, 1, data);
6161 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
6162 #ifdef AMAZON_MEI_DEBUG_ON
6163 printk("\n\nCMV fail, Group STAT Address 1 Index 0");
6164 #endif
6165 }
6166 adsl_mode = RxMessage[4];
6167 // 603221:tc.chen end
6168 makeCMV(H2D_CMV_READ, STAT, 17, 0, 1, data);
6169 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
6170 #ifdef AMAZON_MEI_DEBUG_ON
6171 printk("\n\nCMV fail, Group STAT Address 1 Index 0");
6172 #endif
6173 }
6174 adsl_mode_extend = RxMessage[4];
6175
6176 // update previous channel tx rate
6177 ATUC_CHAN_CURR_TX_RATE_FLAG_MAKECMV;
6178 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
6179 #ifdef AMAZON_MEI_DEBUG_ON
6180 printk("\n\nCMV fail, Group 6 Address 1 Index 0");
6181 #endif
6182 PrevTxRate.adslAtucChanPrevTxRate = 0;
6183 }
6184 else{
6185 PrevTxRate.adslAtucChanPrevTxRate = (u32)(RxMessage[4]) + (((u32)(RxMessage[5]))<<16);
6186 }
6187 ATUR_CHAN_CURR_TX_RATE_FLAG_MAKECMV;
6188 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
6189 #ifdef AMAZON_MEI_DEBUG_ON
6190 printk("\n\nCMV fail, Group 6 Address 0 Index 0");
6191 #endif
6192 PrevTxRate.adslAturChanPrevTxRate = 0;
6193 }
6194 else{
6195 PrevTxRate.adslAturChanPrevTxRate = (u32)(RxMessage[4]) + (((u32)(RxMessage[5]))<<16);
6196 }
6197
6198 // up(&mei_sema);
6199
6200 // showtime=1;
6201 //SET_BIT((*((volatile u32 *)0xB0100B40)), 0x40); //Warning LED GPIO OFF
6202 //dying gasp -start
6203 #ifdef IFX_DYING_GASP
6204 lop_debugwr.buffer[0]=0xffffffff; //dying gasp
6205 lop_debugwr.iCount=1; //dying gasp
6206 makeCMV(H2D_CMV_READ, INFO, 66, 4, 1, NULL);
6207 //mei_ioctl((struct inode *)0,NULL, AMAZON_MEI_CMV_WINHOST, &RxMessage);
6208 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
6209 #ifdef AMAZON_MEI_DEBUG_ON
6210 printk("\n\nCMV fail, Group 3 Address 66 Index 4");
6211 }
6212 #endif
6213 lop_debugwr.iAddress=(u32)RxMessage[4];
6214 makeCMV(H2D_CMV_READ, INFO, 66, 5, 1, NULL);
6215 //mei_ioctl((struct inode *)0,NULL, AMAZON_MEI_CMV_WINHOST, &RxMessage);
6216 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
6217 #ifdef AMAZON_MEI_DEBUG_ON
6218 printk("\n\nCMV fail, Group 3 Address 66 Index 5");
6219 }
6220 #endif
6221 lop_debugwr.iAddress+=((u32)RxMessage[4])<<16;
6222
6223 //dying gasp -end
6224 #endif // IFX_DYING_GASP
6225
6226 //joelin 04/16/2005-start
6227 makeCMV(H2D_CMV_WRITE, PLAM, 10, 0, 1, &unavailable_seconds);
6228 //mei_ioctl((struct inode *)0,NULL, AMAZON_MEI_CMV_WINHOST, &RxMessage);
6229 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
6230 #ifdef AMAZON_MEI_DEBUG_ON
6231 printk("\n\nCMV fail, Group 7 Address 10 Index 0");
6232
6233 #endif
6234 }
6235
6236
6237 //joelin 04/16/2005-end
6238 showtime=1;
6239 up(&mei_sema);
6240 #ifdef AMAZON_CHECK_LINK
6241 if (adsl_link_notify){
6242 (*adsl_link_notify)(1);
6243 }
6244 #endif
6245
6246
6247 }
6248 break;
6249 /*
6250 case AMAZON_MEI_REPLY:
6251 copy_from_user((char *)buff, (char *)lon, MSG_LENGTH * 2);
6252 if(meiCMV(buff, YES_REPLY) != MEI_SUCCESS){
6253 printk("\n\n meiCMV no reply back");
6254 meierr=MEI_FAILURE;
6255 }
6256 else
6257 copy_to_user((char *)lon, (char *)RxMessage, MSG_LENGTH * 2);
6258 break;
6259 case AMAZON_MEI_NOREPLY:
6260 copy_from_user((char *)buff, (char *)lon, MSG_LENGTH * 2);
6261 if(meiCMV(buff, NO_REPLY) != MEI_SUCCESS){
6262 printk("\n\n meiCMV Host to DSP failed");
6263 meierr=MEI_FAILURE;
6264 }
6265 break;
6266 */
6267
6268 case AMAZON_MEI_HALT:
6269 meiHaltArc();
6270 break;
6271 case AMAZON_MEI_CMV_WINHOST:
6272 if(down_interruptible(&mei_sema))
6273 return -ERESTARTSYS;
6274
6275 if (!from_kernel )
6276 copy_from_user((char *)TxMessage, (char *)lon, MSG_LENGTH*2);//joelin
6277 else
6278 memcpy(TxMessage,(char *)lon,MSG_LENGTH*2);
6279
6280 #if 0
6281 // if((TxMessage[0]&0xff0)==0x0a0){
6282 for(i=0;i<16;i++){
6283 printk("\nTxMessage[%i]=%8x", i, TxMessage[i]);
6284 }
6285 // }
6286 #endif
6287
6288 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
6289 #ifdef AMAZON_MEI_DEBUG_ON
6290 // printk("\n\n WINHOST CMV fail ");
6291 printk("\n\nWINHOST CMV fail :TxMessage:%X %X %X %X, RxMessage:%X %X %X %X %X\n",TxMessage[0],TxMessage[1],TxMessage[2],TxMessage[3],RxMessage[0],RxMessage[1],RxMessage[2],RxMessage[3],RxMessage[4]);
6292 #endif
6293 meierr = MEI_FAILURE;
6294 }
6295 else
6296 {
6297 if (!from_kernel ) //joelin
6298 copy_to_user((char *)lon, (char *)RxMessage, MSG_LENGTH*2);
6299 else
6300 memcpy((char *)lon,(char *)RxMessage,MSG_LENGTH*2);
6301 }
6302
6303 up(&mei_sema);
6304 break;
6305 #ifdef AMAZON_MEI_CMV_EXTRA
6306 case AMAZON_MEI_CMV_READ:
6307 copy_from_user((char *)(&regrdwr), (char *)lon, sizeof(meireg));
6308 meiLongwordRead(regrdwr.iAddress, &(regrdwr.iData));
6309 {
6310 // printk("\n\n iAddress = %8x",regrdwr.iAddress);
6311 }
6312 copy_to_user((char *)lon, (char *)(&regrdwr), sizeof(meireg));
6313 {
6314 // printk("\n\n iData readback = %8x", regrdwr.iData);
6315 }
6316 break;
6317 #endif
6318
6319 #ifdef AMAZON_MEI_CMV_EXTRA
6320 case AMAZON_MEI_CMV_WRITE:
6321 copy_from_user((char *)(&regrdwr), (char *)lon, sizeof(meireg));
6322 {
6323 // printk("\n\n iAddress = %8x",regrdwr.iAddress);
6324 // printk("\n\n iData = %8x",regrdwr.iData);
6325 }
6326 meiLongwordWrite(regrdwr.iAddress, regrdwr.iData);
6327 break;
6328 #endif
6329
6330 #ifdef AMAZON_MEI_CMV_EXTRA
6331 case AMAZON_MEI_REMOTE:
6332 copy_from_user((char *)(&i), (char *)lon, sizeof(int));
6333 if(i==0){
6334 meiMailboxInterruptsEnable();
6335
6336 up(&mei_sema);
6337 }
6338 else if(i==1){
6339 meiMailboxInterruptsDisable();
6340 if(down_interruptible(&mei_sema))
6341 return -ERESTARTSYS;
6342 }
6343 else{
6344 #ifdef AMAZON_MEI_DEBUG_ON
6345 printk("\n\n AMAZON_MEI_REMOTE argument error");
6346 #endif
6347 meierr=MEI_FAILURE;
6348 }
6349 break;
6350 #endif
6351
6352 #ifdef AMAZON_MEI_CMV_EXTRA
6353 case AMAZON_MEI_READDEBUG:
6354 case AMAZON_MEI_WRITEDEBUG:
6355 if(down_interruptible(&mei_sema))
6356 return -ERESTARTSYS;
6357 #ifdef IFX_DYING_GASP
6358 if (!from_kernel) copy_from_user((char *)(&debugrdwr), (char *)lon, sizeof(debugrdwr));//dying gasp
6359 else memcpy((char *)(&debugrdwr), (char *)lon, sizeof(debugrdwr));
6360 #else //IFX_DYING_GASP
6361 copy_from_user((char *)(&debugrdwr), (char *)lon, sizeof(debugrdwr));
6362
6363 #endif //IFX_DYING_GASP
6364 #if 0
6365 printk("\nIN iAddress: %8x, iCount:%8x\n", debugrdwr.iAddress, debugrdwr.iCount);
6366 #endif
6367
6368 if(command==AMAZON_MEI_READDEBUG)
6369 meiDebugRead(debugrdwr.iAddress, debugrdwr.buffer, debugrdwr.iCount);
6370 else
6371 meiDebugWrite(debugrdwr.iAddress, debugrdwr.buffer, debugrdwr.iCount);
6372
6373 #ifdef IFX_DYING_GASP
6374 if (!from_kernel) copy_to_user((char *)lon, (char*)(&debugrdwr), sizeof(debugrdwr));//dying gasp
6375 #else //IFX_DYING_GASP
6376 copy_to_user((char *)lon, (char*)(&debugrdwr), sizeof(debugrdwr));
6377 #endif //IFX_DYING_GASP
6378 up(&mei_sema);
6379
6380 #if 0
6381 printk("\nOUT iAddress: %8x, iCount:%8x\n", debugrdwr.iAddress, debugrdwr.iCount);
6382 for(i=0;i<debugrdwr.iCount;i++)
6383 printk("\n %8x",debugrdwr.buffer[i]);
6384 #endif
6385 break;
6386 #endif
6387
6388 case AMAZON_MEI_LOP:
6389 //GPIO31 :dying gasp event indication
6390 // (1) logic high: dying gasp event is false (default)
6391 // (2) logic low: dying gasp event is true
6392 #ifdef IFX_DYING_GASP
6393 break;
6394 #else
6395 CLEAR_BIT((*((volatile u32 *)0xB0100B48)), 0x8000);
6396 CLEAR_BIT((*((volatile u32 *)0xB0100B4C)), 0x8000);
6397 CLEAR_BIT((*((volatile u32 *)0xB0100B50)), 0x8000);
6398 SET_BIT((*((volatile u32 *)0xB0100B54)), 0x8000);
6399 asm("SYNC");
6400 if(((*((volatile u32 *)0xB0100B44))&0x8000)==0x0)
6401 meierr=MEI_FAILURE; //return - to indicate loss of power
6402 break;
6403 #endif //#ifdef IFX_DYING_GASP
6404
6405 //for PCM
6406 case AMAZON_MEI_PCM_SETUP:
6407 //gpio
6408
6409 *AMAZON_GPIO_P0_DIR |=1<<15;
6410 *AMAZON_GPIO_P0_ALTSEL0 |=1<<15;
6411 *AMAZON_GPIO_P0_ALTSEL1 &=~(1<<15);
6412 *AMAZON_GPIO_P0_OD |=1<<15;
6413
6414 /*GPIO 16 TDM_DI*/
6415 *AMAZON_GPIO_P1_DIR &=~1;
6416 *AMAZON_GPIO_P1_ALTSEL0 |=1;
6417 *AMAZON_GPIO_P1_ALTSEL1 &=~1;
6418
6419 /*GPIO 17 TDM_DCL */
6420 *AMAZON_GPIO_P1_DIR|=0x02;
6421 *AMAZON_GPIO_P1_ALTSEL0|=0x02;
6422 *AMAZON_GPIO_P1_ALTSEL1 &=(u32)~0x02;
6423 *AMAZON_GPIO_P1_OD|=0x02;
6424
6425 /*GPIO 18 TDM FSC*/
6426 *AMAZON_GPIO_P1_DIR|=0x04;
6427 *AMAZON_GPIO_P1_ALTSEL0|=0x04;
6428 *AMAZON_GPIO_P1_ALTSEL1 &=(u32)~0x04;
6429 *AMAZON_GPIO_P1_OD|=0x04;
6430
6431 for(i=0;i<2;i++){
6432 for(j=0;j<256;j++)
6433 sampledata[i*256+j]=j;
6434 }
6435
6436 pcm_start_addr = lon;
6437
6438 printk("\n\n pcm_start_addr is %8x", lon);
6439
6440 for(i=0;i<PCM_CHANNEL_NUM;i++){
6441 #ifdef PCM_ACCESS_DEBUG
6442 meiDebugRead_16((pcm_start_addr+i*16), (u32*)(pcm_data+i), 4);
6443 #else
6444 meiDMARead_16((pcm_start_addr+i*16), (u32*)(pcm_data+i), 4);
6445 #endif
6446 if((pcm_data[i].S!=8)||(pcm_data[i].len<1)||(pcm_data[i].rdindex!=0)||(pcm_data[i].wrindex!=0)||(pcm_data[i].flow!=0))
6447 printk("\n\n pcm_data fill in wrongly\n\n");
6448 printk("\npcm_data %d",i);
6449 printk("\n S = %d", pcm_data[i].S);
6450 printk("\n LSW = %4x", pcm_data[i].LSW);
6451 printk("\n MSW = %4x", pcm_data[i].MSW);
6452 printk("\n len = %d", pcm_data[i].len);
6453 printk("\n rdindex = %d", pcm_data[i].rdindex);
6454 printk("\n wrindex = %d", pcm_data[i].wrindex);
6455 printk("\n flow = %d", pcm_data[i].flow);
6456 pcm_data[i].finish=0;
6457 if(i%2==0){//tx channel
6458 for(j=0;j<PCM_BUFF_SIZE/256;j++){
6459 for(k=0;k<256;k++){
6460 pcm_data[i].buff[j*256+k]=k;
6461 /* if(k%2==0)
6462 pcm_data[i].buff[j*256+k]=0xaa;
6463 else
6464 pcm_data[i].buff[j*256+k]=0x55;*/
6465 }
6466 }
6467 #ifdef PCM_ACCESS_DEBUG
6468 meiDebugWrite_8((((u32)(pcm_data[i].LSW))+(((u32)(pcm_data[i].MSW))<<16)), (u32*)(pcm_data[i].buff),((pcm_data[i].len/4)/2));//fill half first
6469 // meiDebugWrite_8((((u32)(pcm_data[i].LSW))+(((u32)(pcm_data[i].MSW))<<16)), (u32*)(pcm_data[i].buff),2);//fill half first
6470 #else
6471 meiDMAWrite_8((((u32)(pcm_data[i].LSW))+(((u32)(pcm_data[i].MSW))<<16)), (u32*)(pcm_data[i].buff),((pcm_data[i].len/4)/2));//fill half first
6472 // meiDMAWrite_8((((u32)(pcm_data[i].LSW))+(((u32)(pcm_data[i].MSW))<<16)), (u32*)(pcm_data[i].buff),2);//fill half first
6473 #endif
6474 pcm_data[i].point=(pcm_data[i].len)/2;
6475 // pcm_data[i].point=8;
6476 #ifdef PCM_ACCESS_DEBUG
6477 meiDebugRead_16(pcm_start_addr+i*16+12, &temp, 1);
6478 #else
6479 meiDMARead_16(pcm_start_addr+i*16+12, &temp, 1);
6480 #endif
6481 temp = (temp &0xffff) + (((u32)(pcm_data[i].point))<<16);
6482 #ifdef PCM_ACCESS_DEBUG
6483 meiDebugWrite_16(pcm_start_addr+i*16+12,&temp, 1);//update wrindex
6484 #else
6485 meiDMAWrite_16(pcm_start_addr+i*16+12,&temp, 1);//update wrindex
6486 #endif
6487 }
6488 else{// rx channel
6489 pcm_data[i].point=0;
6490 }
6491 }
6492 break;
6493 case AMAZON_MEI_PCM_START_TIMER:
6494 /* GPTU timer 6 */
6495 /* enable the timer in the PMU */
6496 *(AMAZON_PMU_PWDCR) = (*(AMAZON_PMU_PWDCR))| AMAZON_PMU_PWDCR_GPT|AMAZON_PMU_PWDCR_FPI;
6497 /* setup the GPTU for timer tick f_fpi == f_gptu*/
6498 *(AMAZON_GPTU_CLC) = 0x100;
6499 //reload value = fpi/(HZ * P), timer mode, Prescaler = 4 ( T6I = 000, T6BPS2 = 0)
6500 *(AMAZON_GPTU_CAPREL) = (int)(117500000/(lon*4));
6501 *(AMAZON_GPTU_T6CON) = 0x80C0;
6502
6503 if (request_irq(AMAZON_TIMER6_INT, amazon_timer6_interrupt_MEI,0, "hrt", NULL)!=0){
6504 #ifdef AMAZON_MEI_DEBUG_ON
6505 printk("\n\n unable to register irq for hrt!!!");
6506 #endif
6507 return -1;
6508 }
6509 enable_irq(AMAZON_TIMER6_INT);
6510 break;
6511 case AMAZON_MEI_PCM_STOP_TIMER:
6512 disable_irq(AMAZON_TIMER6_INT);
6513 free_irq(AMAZON_TIMER6_INT, NULL);
6514 break;
6515 case AMAZON_MEI_PCM_CHECK:
6516 for(i=0;i<PCM_CHANNEL_NUM;i++){
6517 if(pcm_data[i].finish!=1)
6518 return 0;
6519 }
6520 for(i=0;i<PCM_CHANNEL_NUM/2;i++){
6521 j=0;
6522 while(1){
6523 if((pcm_data[i*2+1].buff[j]==0x0) && (pcm_data[i*2+1].buff[j+1]==0x1)&& (pcm_data[i*2+1].buff[j+2]==0x2))
6524 break;
6525 else
6526 j++;
6527 }
6528 printk("\n j=%d", j);
6529 temp=0;
6530 for(k=0;k<((PCM_BUFF_SIZE-j)/4);k++){
6531 if(memcmp(pcm_data[i*2].buff+k*4, pcm_data[i*2+1].buff+j+k*4, 4)!=0){
6532 temp++;
6533 printk("\n\n%2x %2x %2x %2x %2x %2x %2x %2x\n\n", *((u8*)(pcm_data[i*2].buff+k*4)), *((u8*)(pcm_data[i*2].buff+k*4+1)),*((u8*)(pcm_data[i*2].buff+k*4+2)),*((u8*)(pcm_data[i*2].buff+k*4+3)),*((u8*)(pcm_data[i*2+1].buff+j+k*4)),*((u8*)(pcm_data[i*2+1].buff+j+k*4+1)),*((u8*)(pcm_data[i*2+1].buff+j+k*4+2)),*((u8*)(pcm_data[i*2+1].buff+j+k*4+3)));
6534 break;
6535 }
6536 }
6537 if(temp!=0)
6538 printk("\n\n Channel pair %d not match: err32 %d\n\n", i, temp);
6539 else
6540 printk("\n\n Channel pair %d match\n\n", i);
6541 }
6542 for(i=0;i<PCM_CHANNEL_NUM;i++){
6543 if(i%2==1){//rx channel
6544 #ifdef PCM_ACCESS_DEBUG
6545 meiDebugRead_16(pcm_start_addr+i*16+12, &temp, 1);
6546 #else
6547 meiDMARead_16(pcm_start_addr+i*16+12, &temp, 1);
6548 #endif
6549 printk("\n\nRx channel %d: Overflow Bytes %d", i, (temp&0xffff));
6550 }
6551 else{//tx channel
6552 #ifdef PCM_ACCESS_DEBUG
6553 meiDebugRead_16(pcm_start_addr+i*16, &temp, 1);
6554 #else
6555 meiDMARead_16(pcm_start_addr+i*16, &temp, 1);
6556 #endif
6557 printk("\n\nElectra Err: %d",(temp&0xffff));
6558 }
6559 }
6560 //check electra overflow
6561
6562 meierr=1;
6563 break;
6564 case AMAZON_MEI_PCM_GETDATA:
6565 copy_to_user(lon, pcm_data[1].buff, PCM_BUFF_SIZE);
6566 break;
6567 case AMAZON_MEI_PCM_GPIO:
6568 //gpio
6569
6570 *AMAZON_GPIO_P0_DIR |=1<<15;
6571 *AMAZON_GPIO_P0_ALTSEL0 |=1<<15;
6572 *AMAZON_GPIO_P0_ALTSEL1 &=~(1<<15);
6573 *AMAZON_GPIO_P0_OD |=1<<15;
6574
6575 /*GPIO 16 TDM_DI*/
6576 *AMAZON_GPIO_P1_DIR &=~1;
6577 *AMAZON_GPIO_P1_ALTSEL0 |=1;
6578 *AMAZON_GPIO_P1_ALTSEL1 &=~1;
6579
6580 /*GPIO 17 TDM_DCL */
6581 *AMAZON_GPIO_P1_DIR|=0x02;
6582 *AMAZON_GPIO_P1_ALTSEL0|=0x02;
6583 *AMAZON_GPIO_P1_ALTSEL1 &=(u32)~0x02;
6584 *AMAZON_GPIO_P1_OD|=0x02;
6585
6586 /*GPIO 18 TDM FSC*/
6587 *AMAZON_GPIO_P1_DIR|=0x04;
6588 *AMAZON_GPIO_P1_ALTSEL0|=0x04;
6589 *AMAZON_GPIO_P1_ALTSEL1 &=(u32)~0x04;
6590 *AMAZON_GPIO_P1_OD|=0x04;
6591 break;
6592
6593
6594
6595 //for clearEoC
6596 #ifdef AMAZON_CLEAR_EOC
6597 case AMAZON_MEI_GET_EOC_LEN:
6598 while(1){
6599 current_clreoc = list_entry(clreoc_list.next, amazon_clreoc_pkt, list);
6600 if((current_clreoc->len)>0){
6601 copy_to_user((char *)lon, (char*)(&(current_clreoc->len)), 4);
6602 break;
6603 }
6604 else//wait for eoc data from higher layer
6605 interruptible_sleep_on(&wait_queue_clreoc);
6606 }
6607 break;
6608 case AMAZON_MEI_GET_EOC_DATA:
6609 current_clreoc = list_entry(clreoc_list.next, amazon_clreoc_pkt, list);
6610 if((current_clreoc->len)>0){
6611 copy_to_user((char*)lon, (char*)(current_clreoc->command), current_clreoc->len);
6612 meierr=1;
6613 list_del(clreoc_list.next); //remove and add to end of list
6614 current_clreoc->len = 0;
6615 list_add_tail(&(current_clreoc->list), &clreoc_list);
6616 }
6617 else
6618 meierr=-1;
6619 break;
6620 case AMAZON_MEI_EOC_SEND:
6621 copy_from_user((char *)(&debugrdwr), (char *)lon, sizeof(debugrdwr));
6622 eoc_skb = dev_alloc_skb(debugrdwr.iCount*4);
6623 if(eoc_skb==NULL){
6624 printk("\n\nskb alloc fail");
6625 break;
6626 }
6627
6628 eoc_skb->len=debugrdwr.iCount*4;
6629 memcpy(skb_put(eoc_skb, debugrdwr.iCount*4), (char *)debugrdwr.buffer, debugrdwr.iCount*4);
6630
6631 ifx_push_eoc(eoc_skb); //pass data to higher layer
6632 break;
6633 #endif //#ifdef AMAZON_CLEAR_EOC
6634 case AMAZON_MIB_LO_ATUC:
6635 do_gettimeofday(&time_now);
6636 if(lon&0x1){
6637 if((time_now.tv_sec-(mib_pflagtime.ATUC_PERF_LOSS_PTIME).tv_sec)>2){
6638 current_intvl->AtucPerfLos++;
6639 ATUC_PERF_LOSS++;
6640 CurrStatus.adslAtucCurrStatus = 2;
6641 }
6642 (mib_pflagtime.ATUC_PERF_LOSS_PTIME).tv_sec = time_now.tv_sec;
6643 }
6644 if(lon&0x2){
6645 if((time_now.tv_sec-(mib_pflagtime.ATUC_PERF_LOFS_PTIME).tv_sec)>2){
6646 current_intvl->AtucPerfLof++;
6647 ATUC_PERF_LOFS++;
6648 CurrStatus.adslAtucCurrStatus = 1;
6649 }
6650 (mib_pflagtime.ATUC_PERF_LOFS_PTIME).tv_sec = time_now.tv_sec;
6651 }
6652 if(!(lon&0x3))
6653 CurrStatus.adslAtucCurrStatus = 0;
6654 break;
6655 case AMAZON_MIB_LO_ATUR:
6656 do_gettimeofday(&time_now);
6657 if(lon&0x1){
6658 if((time_now.tv_sec-(mib_pflagtime.ATUR_PERF_LOSS_PTIME).tv_sec)>2){
6659 current_intvl->AturPerfLos++;
6660 ATUR_PERF_LOSS++;
6661 CurrStatus.adslAturCurrStatus = 2;
6662 }
6663 (mib_pflagtime.ATUR_PERF_LOSS_PTIME).tv_sec = time_now.tv_sec;
6664 }
6665 if(lon&0x2){
6666 if((time_now.tv_sec-(mib_pflagtime.ATUR_PERF_LOFS_PTIME).tv_sec)>2){
6667 current_intvl->AturPerfLof++;
6668 ATUR_PERF_LOFS++;
6669 CurrStatus.adslAturCurrStatus = 1;
6670 }
6671 (mib_pflagtime.ATUR_PERF_LOFS_PTIME).tv_sec = time_now.tv_sec;
6672 }
6673 if(lon&0x4){
6674 if((time_now.tv_sec-(mib_pflagtime.ATUR_PERF_LPR_PTIME).tv_sec)>2){
6675 current_intvl->AturPerfLpr++;
6676 ATUR_PERF_LPR++;
6677 CurrStatus.adslAturCurrStatus = 3;
6678 }
6679 (mib_pflagtime.ATUR_PERF_LPR_PTIME).tv_sec = time_now.tv_sec;
6680 }
6681 if(!(lon&0x7))
6682 CurrStatus.adslAturCurrStatus = 0;
6683 break;
6684 case AMAZON_MEI_DOWNLOAD:
6685 // DMA the boot code page(s)
6686 #ifdef AMAZON_MEI_DEBUG_ON
6687 printk("\n\n start download pages");
6688 #endif
6689 for( boot_loop = 0; boot_loop < img_hdr->count; boot_loop++){
6690 if( img_hdr->page[boot_loop].p_size & BOOT_FLAG){
6691 page_size = meiGetPage( boot_loop, GET_PROG, MAXSWAPSIZE, mei_arc_swap_buff, &dest_addr);
6692 if( page_size > 0){
6693 meiDMAWrite(dest_addr, mei_arc_swap_buff, page_size);
6694 }
6695 }
6696 if( img_hdr->page[boot_loop].d_size & BOOT_FLAG){
6697 page_size = meiGetPage( boot_loop, GET_DATA, MAXSWAPSIZE, mei_arc_swap_buff, &dest_addr);
6698 if( page_size > 0){
6699 meiDMAWrite( dest_addr, mei_arc_swap_buff, page_size);
6700 }
6701 }
6702 }
6703 #ifdef AMAZON_MEI_DEBUG_ON
6704 printk("\n\n pages downloaded");
6705 #endif
6706 break;
6707 //509221:tc.chen start
6708 case AMAZON_MEI_DEBUG_MODE:
6709 mei_debug_mode = lon;
6710 break;
6711 //509221:tc.chen end
6712 }
6713 return meierr;
6714 }
6715
6716
6717 ////////////////////// Interrupt handler /////////////////////////////////////////////////////
6718 static void mei_interrupt_arcmsgav(int,void *,struct pt_regs *);
6719 static void mei_interrupt_arcmsgav(int int1, void * void0, struct pt_regs * regs)
6720 {
6721 u32 scratch;
6722 u32 fetchpage;
6723 u32 size;
6724 u32 dest_addr;
6725 u32 temp;
6726 int i;
6727
6728 meiDebugRead(ARC_MEI_MAILBOXR, &scratch, 1);
6729 if(scratch & OMB_CODESWAP_MESSAGE_MSG_TYPE_MASK)
6730 {
6731 if(showtime==1){
6732 #ifdef AMAZON_MEI_DEBUG_ON
6733 printk("\n\n Code Swap Request After ShowTime !!!");
6734 #endif
6735 }
6736 else{
6737 #ifdef AMAZON_MEI_DEBUG_ON
6738 // printk("\n\n Code Swap Request");
6739 #endif
6740 fetchpage = scratch & ~OMB_CODESWAP_MESSAGE_MSG_TYPE_MASK;
6741 size = meiGetPage( fetchpage, GET_PROG, MAXSWAPSIZE, mei_arc_swap_buff, &dest_addr);
6742 if( size > 0)
6743 {
6744 #ifdef AMAZON_MEI_DEBUG_ON
6745 // printk(" : prom page num %d",fetchpage);
6746 #endif
6747 meiDMAWrite( dest_addr, mei_arc_swap_buff, size);
6748 }
6749
6750 size = meiGetPage( fetchpage, GET_DATA, MAXSWAPSIZE, mei_arc_swap_buff, &dest_addr);
6751 if( size > 0)
6752 {
6753 #ifdef AMAZON_MEI_DEBUG_ON
6754 // printk(" : data page num %d",fetchpage);
6755 #endif
6756 meiDMAWrite( dest_addr, mei_arc_swap_buff, size);
6757 }
6758 }
6759 // Notify arc that mailbox read complete
6760 meiLongwordWrite(ARC_TO_MEI_INT, ARC_TO_MEI_MSGAV);
6761
6762 // Tell ARC Codeswap is done
6763 meiLongwordWrite(MEI_TO_ARC_INT, MEI_TO_ARC_CS_DONE);
6764 asm("SYNC");
6765 i=0;
6766 while(i<WHILE_DELAY){
6767 meiLongwordRead(MEI_TO_ARC_INT, &temp);
6768 if((temp & MEI_TO_ARC_CS_DONE) ==0){
6769 #ifdef AMAZON_MEI_DEBUG_ON
6770 // printk("\n\n Code Swap Done");
6771 #endif
6772 break;
6773 }
6774 i++;
6775 if(i==WHILE_DELAY){
6776 #ifdef AMAZON_MEI_DEBUG_ON
6777 printk("\n\n MEI_TO_ARC_CS_DONE not cleared by ARC");
6778 //509221:tc.chen start
6779 if (!mei_debug_mode)
6780 {
6781 //printk("Reset Arc!\n");
6782 //printk("AdslInitStatsData.FullInitializationCount++\n");
6783 AdslInitStatsData.FullInitializationCount++;
6784 if (!showtime)
6785 {
6786 //printk("AdslInitStatsData.FailedFullInitializationCount++\n");
6787 AdslInitStatsData.FailedFullInitializationCount++;
6788 //printk("AdslInitStatsData.LINIT_Errors++\n");
6789 AdslInitStatsData.LINIT_Errors++;
6790 }
6791
6792 wake_up_interruptible(&wait_queue_codeswap); // wait up ioctl reboot
6793 }
6794 //509221:tc.chen end
6795 #endif
6796 }
6797 }
6798 }
6799 else{ // normal message
6800 // printk("\n\n interrupt");
6801 meiMailboxRead(RxMessage, MSG_LENGTH);
6802 if(cmv_waiting==1){
6803 arcmsgav=1;
6804 cmv_waiting=0;
6805 wake_up_interruptible(&wait_queue_arcmsgav);
6806 }
6807 else{
6808 indicator_count++;
6809 memcpy((char *)Recent_indicator, (char *)RxMessage, MSG_LENGTH *2);
6810 #ifdef ARC_READY_ACK
6811 if(((RxMessage[0]&0xff0)>>4)==D2H_AUTONOMOUS_MODEM_READY_MSG){ //check ARC ready message
6812
6813 #ifdef LOCK_RETRY
6814 if (reboot_lock)
6815 {
6816 reboot_lock = 0;
6817 up(&mei_sema); // allow cmv access
6818 }
6819 #else
6820 up(&mei_sema); // allow cmv access
6821 #endif
6822 reboot_flag=1;
6823 //#ifdef ADSL_LED_SUPPORT
6824 #if 0
6825 led_support_check=1;//adsl led for 1.1.2.7.1.1
6826 adsl_led_flash();//adsl led for 1.1.2.7.1.1
6827 #endif
6828 wake_up_interruptible(&wait_queue_reboot); // wait up ioctl reboot
6829 }
6830 #endif
6831 }
6832 }
6833 // meiLongwordWrite(ARC_TO_MEI_INT, ARC_TO_MEI_MSGAV);
6834 mask_and_ack_amazon_irq(AMAZON_MEI_INT);
6835 return;
6836 }
6837
6838 // 603221:tc.chen start
6839 ////////////////////////hdlc ////////////////
6840
6841 // get hdlc status
6842 static unsigned int ifx_me_hdlc_status(void)
6843 {
6844 u16 CMVMSG[MSG_LENGTH];
6845 int ret;
6846
6847 if (showtime!=1)
6848 return -ENETRESET;
6849
6850 makeCMV_local(H2D_CMV_READ, STAT, 14, 0, 1, NULL,CMVMSG); //Get HDLC status
6851 ret = mei_ioctl((struct inode *)0,NULL, AMAZON_MEI_CMV_WINHOST, CMVMSG);
6852 if (ret != 0)
6853 {
6854 return -EIO;
6855 }
6856 return CMVMSG[4]&0x0F;
6857 }
6858
6859 int ifx_me_is_resloved(int status)
6860 {
6861 u16 CMVMSG[MSG_LENGTH];
6862 int ret;
6863
6864 if (status == ME_HDLC_MSG_QUEUED || status == ME_HDLC_MSG_SENT)
6865 return ME_HDLC_UNRESOLVED;
6866 if (status == ME_HDLC_IDLE)
6867 {
6868 makeCMV_local(H2D_CMV_READ, CNTL, 2, 0, 1, NULL,CMVMSG); //Get ME-HDLC Control
6869 ret = mei_ioctl((struct inode *)0,NULL, AMAZON_MEI_CMV_WINHOST, CMVMSG);
6870 if (ret != 0)
6871 {
6872 return IFX_POP_EOC_FAIL;
6873 }
6874 if (CMVMSG[4]&(1<<0))
6875 {
6876 return ME_HDLC_UNRESOLVED;
6877 }
6878
6879 }
6880 return ME_HDLC_RESOLVED;
6881 }
6882
6883 int _ifx_me_hdlc_send(unsigned char *hdlc_pkt,int len,int max_length)
6884 {
6885 int ret;
6886 u16 CMVMSG[MSG_LENGTH];
6887 u16 data=0;
6888 u16 pkt_len=len;
6889 if (pkt_len > max_length)
6890 {
6891 printk("Exceed maximum eoc message length\n");
6892 return -ENOBUFS;
6893 }
6894 //while(pkt_len > 0)
6895 {
6896 makeCMV_local(H2D_CMV_WRITE, INFO, 81, 0, (pkt_len+1)/2,(u16 *)hdlc_pkt,CMVMSG); //Write clear eoc message to ARC
6897 ret = mei_ioctl((struct inode *)0,NULL, AMAZON_MEI_CMV_WINHOST, CMVMSG);
6898 if (ret != 0)
6899 {
6900 return -EIO;
6901 }
6902
6903 makeCMV_local(H2D_CMV_WRITE, INFO, 83, 2, 1,&pkt_len,CMVMSG); //Update tx message length
6904 ret = mei_ioctl((struct inode *)0,NULL, AMAZON_MEI_CMV_WINHOST, CMVMSG);
6905 if (ret != 0)
6906 {
6907 return -EIO;
6908 }
6909
6910 data = (1<<0);
6911 makeCMV_local(H2D_CMV_WRITE, CNTL, 2, 0, 1,&data,CMVMSG); //Start to send
6912 ret = mei_ioctl((struct inode *)0,NULL, AMAZON_MEI_CMV_WINHOST, CMVMSG);
6913 if (ret != 0)
6914 {
6915 return -EIO;
6916 }
6917 return 0;
6918 }
6919 }
6920
6921 static int ifx_me_hdlc_send(unsigned char *hdlc_pkt,int hdlc_pkt_len)
6922 {
6923 int hdlc_status=0;
6924 u16 CMVMSG[MSG_LENGTH];
6925 int max_hdlc_tx_length=0,ret=0,retry=0;
6926
6927 while(retry<10)
6928 {
6929 hdlc_status = ifx_me_hdlc_status();
6930 if (ifx_me_is_resloved(hdlc_status)==ME_HDLC_RESOLVED) // arc ready to send HDLC message
6931 {
6932 makeCMV_local(H2D_CMV_READ, INFO, 83, 0, 1, NULL,CMVMSG); //Get Maximum Allowed HDLC Tx Message Length
6933 ret = mei_ioctl((struct inode *)0,NULL, AMAZON_MEI_CMV_WINHOST, CMVMSG);
6934 if (ret != 0)
6935 {
6936 return -EIO;
6937 }
6938 max_hdlc_tx_length = CMVMSG[4];
6939 ret = _ifx_me_hdlc_send(hdlc_pkt,hdlc_pkt_len,max_hdlc_tx_length);
6940 return ret;
6941 }
6942 set_current_state(TASK_INTERRUPTIBLE);
6943 schedule_timeout(10);
6944 }
6945 return -EBUSY;
6946 }
6947
6948 int ifx_mei_hdlc_read(char *hdlc_pkt,int max_hdlc_pkt_len)
6949 {
6950 u16 CMVMSG[MSG_LENGTH];
6951 int msg_read_len,ret=0,pkt_len=0,retry = 0;
6952
6953 while(retry<10)
6954 {
6955 ret = ifx_me_hdlc_status();
6956 if (ret == ME_HDLC_RESP_RCVD)
6957 {
6958 int current_size=0;
6959 makeCMV_local(H2D_CMV_READ, INFO, 83, 3, 1, NULL,CMVMSG); //Get EoC packet length
6960 ret = mei_ioctl((struct inode *)0,NULL, AMAZON_MEI_CMV_WINHOST, CMVMSG);
6961 if (ret != 0)
6962 {
6963 return -EIO;
6964 }
6965
6966 pkt_len = CMVMSG[4];
6967 if (pkt_len > max_hdlc_pkt_len)
6968 {
6969 ret = -ENOMEM;
6970 goto error;
6971 }
6972 while( current_size < pkt_len)
6973 {
6974 if (pkt_len - current_size >(MSG_LENGTH*2-8))
6975 msg_read_len = (MSG_LENGTH*2-8);
6976 else
6977 msg_read_len = pkt_len - (current_size);
6978 makeCMV_local(H2D_CMV_READ, INFO, 82, 0 + (current_size/2), (msg_read_len+1)/2, NULL,CMVMSG); //Get hdlc packet
6979 ret = mei_ioctl((struct inode *)0,NULL, AMAZON_MEI_CMV_WINHOST, CMVMSG);
6980 if (ret != 0)
6981 {
6982 goto error;
6983 }
6984 memcpy(hdlc_pkt+current_size,&CMVMSG[4],msg_read_len);
6985 current_size +=msg_read_len;
6986 }
6987 ret = current_size;
6988 break;
6989 }else
6990 {
6991 ret = -ENODATA;
6992 }
6993
6994 retry++;
6995 set_current_state(TASK_INTERRUPTIBLE);
6996 schedule_timeout(10);
6997
6998 }
6999 return ret;
7000 error:
7001
7002 return ret;
7003 }
7004
7005 ////////////////////////hdlc ////////////////
7006 // 603221:tc.chen end
7007
7008 /////////////////////// clearEoC, int ifx_pop_eoc(sk_buff * pkt) //////////
7009 int ifx_pop_eoc(struct sk_buff * pkt);
7010 int ifx_pop_eoc(struct sk_buff * pkt)
7011 {
7012 amazon_clreoc_pkt * current;
7013 if(showtime!=1){
7014 dev_kfree_skb(pkt);
7015 return IFX_POP_EOC_FAIL;
7016 }
7017 if((pkt->len)>clreoc_max_tx_len){
7018 dev_kfree_skb(pkt);
7019 return IFX_POP_EOC_FAIL;
7020 }
7021 current = list_entry(clreoc_list.next, amazon_clreoc_pkt, list);
7022 while(1){
7023 if(current->len==0){
7024 memcpy(current->command, pkt->data, pkt->len);
7025 current->len=pkt->len;
7026 break;
7027 }
7028 else{
7029 if((current->list).next==&clreoc_list){
7030 dev_kfree_skb(pkt);
7031 return IFX_POP_EOC_FAIL; //buffer full
7032 }
7033 current = list_entry((current->list).next,amazon_clreoc_pkt, list);
7034 }
7035 }
7036 wake_up_interruptible(&wait_queue_clreoc);
7037
7038 dev_kfree_skb(pkt);
7039 return IFX_POP_EOC_DONE;
7040 }
7041 /* this is used in circular fifo mode */
7042 /*
7043 int ifx_pop_eoc(sk_buff * pkt);
7044 int ifx_pop_eoc(sk_buff * pkt)
7045 {
7046 int buff_space,i;
7047 if(showtime!=1)
7048 return IFX_POP_EOC_FAIL;
7049
7050 if(clreoc_wr>=clreoc_rd)
7051 buff_space = (MEI_CLREOC_BUFF_SIZE-1)-(clreoc_wr - clreoc_rd);
7052 else
7053 buff_space = clreoc_rd - clreoc_wr - 1;
7054 if((pkt->len)>buff_space)
7055 return IFX_POP_EOC_FAIL;
7056
7057 if((clreoc_wr+pkt->len)>MEI_CLREOC_BUFF_SIZE){
7058 memcpy((clreoc+clreoc_wr), pkt->data, ((clreoc_wr+pkt->len)-MEI_CLREOC_BUFF_SIZE+1));
7059 memcpy(clreoc, (pkt->data)+((clreoc_wr+pkt->len)-MEI_CLREOC_BUFF_SIZE+1), (pkt->len)-((clreoc_wr+pkt->len)-MEI_CLREOC_BUFF_SIZE+1));
7060 clreoc_wr=(clreoc_wr+pkt->len)-MEI_CLREOC_BUFF_SIZE;
7061 }
7062 else{
7063 memcpy((clreoc+clreoc_wr), pkt->data, pkt->len);
7064 if((clreoc_wr+pkt->len)=MEI_CLREOC_BUFF_SIZE)
7065 clreoc_wr=0;
7066 else
7067 clreoc_wr+=pkt->len;
7068 }
7069 wake_up_interruptible(&wait_queue_clreoc);
7070 return IFX_POP_EOC_DONE;
7071 }
7072 */
7073
7074
7075 ////////////////////////////////////////////////////////////////////////////
7076 //int amazon_mei_init_module (void);
7077 //void amazon_mei_cleanup_module (void);
7078 //int __init init_module (void);
7079 //void __exit cleanup_module (void);
7080
7081 int __init amazon_mei_init_module(void)
7082 //int __init init_module(void)
7083 {
7084 struct proc_dir_entry *entry;
7085 int i;
7086
7087 //dying gasp-start
7088 #ifdef IFX_DYING_GASP
7089
7090 //000003:fchang Start
7091 #ifdef CONFIG_CPU_AMAZON_E
7092 //GPIO31 :dying gasp event indication
7093 // (1) logic high: dying gasp event is false (default)
7094 // (2) logic low: dying gasp event is true
7095 CLEAR_BIT((*((volatile u32 *)0xB0100B18)), 0x4);
7096 CLEAR_BIT((*((volatile u32 *)0xB0100B1c)), 0x4);
7097 CLEAR_BIT((*((volatile u32 *)0xB0100B20)), 0x4);
7098 SET_BIT((*((volatile u32 *)0xB0100B24)), 0x4);
7099 asm("SYNC");
7100 #else //000003:fchang End
7101
7102 //GPIO31 :dying gasp event indication
7103 // (1) logic high: dying gasp event is false (default)
7104 // (2) logic low: dying gasp event is true
7105 CLEAR_BIT((*((volatile u32 *)0xB0100B48)), 0x8000);
7106 CLEAR_BIT((*((volatile u32 *)0xB0100B4C)), 0x8000);
7107 CLEAR_BIT((*((volatile u32 *)0xB0100B50)), 0x8000);
7108 SET_BIT((*((volatile u32 *)0xB0100B54)), 0x8000);
7109 #if 0
7110 //warning-led-start
7111 //GPIO 22
7112 SET_BIT ((*((volatile u32 *)0xB0100B48)), 0x40);
7113 CLEAR_BIT((*((volatile u32 *)0xB0100B4C)), 0x40);
7114 CLEAR_BIT((*((volatile u32 *)0xB0100B50)), 0x40);
7115 SET_BIT((*((volatile u32 *)0xB0100B54)), 0x40);
7116 CLEAR_BIT((*((volatile u32 *)0xB0100B40)), 0x40); //GPIO ON
7117 printk("LED ON ON ON ON ON ON.....");
7118 //warning-led-end
7119 #endif
7120 asm("SYNC");
7121 #endif //000003:fchang
7122
7123 #endif //IFX_DYING_GASP
7124 //dying gasp -end
7125
7126
7127 reg_entry_t regs_temp[PROC_ITEMS] = // Items being debugged
7128 {
7129 /* { flag, name, description } */
7130 { &arcmsgav, "arcmsgav", "arc to mei message ", 0 },
7131 { &cmv_reply, "cmv_reply", "cmv needs reply", 0},
7132 { &cmv_waiting, "cmv_waiting", "waiting for cmv reply from arc", 0},
7133 { &indicator_count, "indicator_count", "ARC to MEI indicator count", 0},
7134 { &cmv_count, "cmv_count", "MEI to ARC CMVs", 0},
7135 { &reply_count, "reply_count", "ARC to MEI Reply", 0},
7136 { (int *)Recent_indicator, "Recent_indicator", "most recent indicator", 0},
7137 { (int *)8, "version", "version of firmware", 0},
7138 };
7139 memcpy((char *)regs, (char *)regs_temp, sizeof(regs_temp));
7140
7141
7142 //sema_init(&mei_sema, 0); // semaphore initialization, mutex
7143 sema_init(&mei_sema, 1); // semaphore initialization, mutex
7144
7145 init_waitqueue_head(&wait_queue_arcmsgav); // for ARCMSGAV
7146 init_waitqueue_head(&wait_queue_codeswap); // for codeswap daemon
7147 init_waitqueue_head(&wait_queue_mibdaemon); // for mib daemon
7148 init_waitqueue_head(&wait_queue_reboot); // for ioctl reboot
7149 init_waitqueue_head(&wait_queue_clreoc); // for clreoc_wr function
7150 init_waitqueue_head(&wait_queue_loop_diagnostic); // for loop diagnostic function
7151 #ifdef ADSL_LED_SUPPORT
7152 init_waitqueue_head(&wait_queue_led); // adsl led for led function
7153 init_waitqueue_head(&wait_queue_led_polling); // adsl led for led function
7154 led_task.routine = adsl_led_flash_task; // adsl led for led function
7155 led_poll_init(); // adsl led for led function
7156 #endif //ADSL_LED_SUPPORT
7157 #ifdef IFX_DYING_GASP
7158 init_waitqueue_head(&wait_queue_dying_gasp); // IFX_DYING_GASP
7159 lop_poll_init(); // IFX_DYING_GASP
7160 #endif //IFX_DYING_GASP
7161
7162 init_waitqueue_head(&wait_queue_uas_poll);//joelin 04/16/2005
7163 unavailable_seconds_poll_init();//joelin 04/16/2005
7164 memset(&mib_pflagtime, 0, (sizeof(mib_flags_pretime)));
7165
7166 // initialize link list for intervals
7167 mei_mib = (amazon_mei_mib *)kmalloc((sizeof(amazon_mei_mib)*INTERVAL_NUM), GFP_KERNEL);
7168 if(mei_mib == NULL){
7169 #ifdef AMAZON_MEI_DEBUG_ON
7170 printk("kmalloc error for amazon_mei_mib\n\n");
7171 #endif
7172 return -1;
7173 }
7174 memset(mei_mib, 0, (sizeof(amazon_mei_mib)*INTERVAL_NUM));
7175 INIT_LIST_HEAD(&interval_list);
7176 for(i=0;i<INTERVAL_NUM;i++)
7177 list_add_tail(&(mei_mib[i].list), &interval_list);
7178 current_intvl = list_entry(interval_list.next, amazon_mei_mib, list);
7179 do_gettimeofday(&(current_intvl->start_time));
7180 // initialize clreoc list
7181 clreoc_pkt = (amazon_clreoc_pkt *)kmalloc((sizeof(amazon_clreoc_pkt)*CLREOC_BUFF_SIZE), GFP_KERNEL);
7182 if(clreoc_pkt == NULL){
7183 #ifdef AMAZON_MEI_DEBUG_ON
7184 printk("kmalloc error for clreoc_pkt\n\n");
7185 #endif
7186 return -1;
7187 }
7188 memset(clreoc_pkt, 0, (sizeof(amazon_clreoc_pkt)*CLREOC_BUFF_SIZE));
7189 INIT_LIST_HEAD(&clreoc_list);
7190 for(i=0;i<CLREOC_BUFF_SIZE;i++)
7191 list_add_tail(&(clreoc_pkt[i].list), &clreoc_list);
7192
7193 memset(&AdslInitStatsData, 0, sizeof(AdslInitStatsData));
7194 if (register_chrdev(major, "amazon_mei", &mei_operations)!=0) {
7195 #ifdef AMAZON_MEI_DEBUG_ON
7196 printk("\n\n unable to register major for amazon_mei!!!");
7197 #endif
7198 return -1;
7199 }
7200 if (request_irq(AMAZON_MEI_INT, mei_interrupt_arcmsgav,0, "amazon_mei_arcmsgav", NULL)!=0){
7201 #ifdef AMAZON_MEI_DEBUG_ON
7202 printk("\n\n unable to register irq for amazon_mei!!!");
7203 #endif
7204 return -1;
7205 }
7206 // disable_irq(AMAZON_MEI_INT);
7207 enable_irq(AMAZON_MEI_INT);
7208 // procfs
7209 meidir=proc_mkdir(MEI_DIRNAME, &proc_root);
7210 if ( meidir == NULL) {
7211 #ifdef AMAZON_MEI_DEBUG_ON
7212 printk(KERN_ERR ": can't create /proc/" MEI_DIRNAME "\n\n");
7213 #endif
7214 return(-ENOMEM);
7215 }
7216
7217 for(i=0;i<NUM_OF_REG_ENTRY;i++) {
7218 entry = create_proc_entry(regs[i].name,
7219 S_IWUSR |S_IRUSR | S_IRGRP | S_IROTH,
7220 meidir);
7221 if(entry) {
7222 regs[i].low_ino = entry->low_ino;
7223 entry->proc_fops = &proc_operations;
7224 } else {
7225 #ifdef AMAZON_MEI_DEBUG_ON
7226 printk( KERN_ERR
7227 ": can't create /proc/" MEI_DIRNAME
7228 "/%s\n\n", regs[i].name);
7229 #endif
7230 return(-ENOMEM);
7231 }
7232 }
7233 ///////////////////////////////// register net device ////////////////////////////
7234 if(register_netdev(&phy_mei_net)!=0){
7235 #ifdef AMAZON_MEI_DEBUG_ON
7236 printk("\n\n Register phy Device Failed.");
7237 #endif
7238 return -1;
7239 }
7240 /*
7241 if(register_netdev(&interleave_mei_net)!=0){
7242 printk("\n\n Register interleave Device Failed.");
7243 return -1;
7244 }
7245 if(register_netdev(&fast_mei_net)!=0){
7246 printk("\n\n Register fast Device Failed.");
7247 return -1;
7248 }
7249 */
7250 #ifdef DFE_LOOPBACK
7251 mei_arc_swap_buff = (u32 *)kmalloc(MAXSWAPSIZE*4, GFP_KERNEL);
7252 if (mei_arc_swap_buff){
7253 #ifdef ARC_READY_ACK
7254 if(down_interruptible(&mei_sema)) //disable CMV access until ARC ready
7255 {
7256 return -ERESTARTSYS;
7257 }
7258 #ifdef LOCK_RETRY
7259 reboot_lock = 1;
7260 #endif
7261 #endif
7262 meiForceRebootAdslModem();
7263 kfree(mei_arc_swap_buff);
7264 }else{
7265 #ifdef AMAZON_MEI_DEBUG_ON
7266 printk("cannot load image: no memory\n\n");
7267 #endif
7268 }
7269 #endif
7270 #ifdef IFX_SMALL_FOOTPRINT
7271 mib_poll_init();
7272 #endif
7273 return 0;
7274 }
7275
7276 void __exit amazon_mei_cleanup_module(void)
7277 //void __exit cleanup_module(void)
7278 {
7279 int i;
7280 #ifdef ADSL_LED_SUPPORT
7281 stop_led_module=1; //wake up and clean led module
7282 led_support_check=0;//joelin , clear task
7283 showtime=0;//joelin,clear task
7284 //CLEAR_BIT((*((volatile u32 *)0xB0100B40)), 0x40); //Warning LED GPIO ON
7285 firmware_support_led=0;//joelin ,clear task
7286 wake_up_interruptible(&wait_queue_led); //wake up and clean led module
7287 wake_up_interruptible(&wait_queue_led_polling); //wake up and clean led module
7288 #endif
7289 for(i=0;i<NUM_OF_REG_ENTRY;i++)
7290 remove_proc_entry(regs[i].name, meidir);
7291 remove_proc_entry(MEI_DIRNAME, &proc_root);
7292
7293 disable_irq(AMAZON_MEI_INT);
7294 free_irq(AMAZON_MEI_INT, NULL);
7295 unregister_chrdev(major, "amazon_mei");
7296
7297 kfree(mei_mib);
7298 kfree(clreoc_pkt);
7299
7300 kfree(phy_mei_net.priv);
7301 unregister_netdev(&phy_mei_net);
7302
7303 return;
7304 }
7305 #ifdef IFX_SMALL_FOOTPRINT
7306
7307
7308 int adsl_mib_poll(void *unused)
7309 {
7310 struct task_struct *tsk = current;
7311 int i=0;
7312 struct timeval time_now;
7313 struct timeval time_fini;
7314 u32 temp,temp2;
7315
7316 amazon_mei_mib * mib_ptr;
7317 // u16 buff[MSG_LENGTH]__attribute__ ((aligned(4)));
7318 u16 * data=NULL; //used in makeCMV, to pass in payload when CMV set, ignored when CMV read.
7319
7320 daemonize();
7321 strcpy(tsk->comm, "kmibpoll");
7322 sigfillset(&tsk->blocked);
7323
7324 printk("Inside mib poll loop ...\n");
7325 i=0;
7326 while(1){
7327 if(i<MIB_INTERVAL)
7328 interruptible_sleep_on_timeout(&wait_queue_mibdaemon, ((MIB_INTERVAL-i)/(1000/HZ)));
7329 i=0;
7330 if(showtime==1){
7331 // printk("\n\n update mib");
7332
7333 do_gettimeofday(&time_now);
7334 if(time_now.tv_sec - current_intvl->start_time.tv_sec>=900){
7335 if(current_intvl->list.next!=&interval_list){
7336 current_intvl = list_entry(current_intvl->list.next, amazon_mei_mib, list);
7337 do_gettimeofday(&(current_intvl->start_time));
7338 }
7339 else{
7340 mib_ptr = list_entry(interval_list.next, amazon_mei_mib, list);
7341 list_del(interval_list.next);
7342 memset(mib_ptr, 0, sizeof(amazon_mei_mib));
7343 list_add_tail(&(mib_ptr->list), &interval_list);
7344 if(current_intvl->list.next==&interval_list)
7345 #ifdef AMAZON_MEI_DEBUG_ON
7346 printk("\n\nlink list error");
7347 #endif
7348 current_intvl = list_entry(current_intvl->list.next, amazon_mei_mib, list);
7349 do_gettimeofday(&(current_intvl->start_time));
7350 }
7351 }
7352
7353 if(down_interruptible(&mei_sema))
7354 return -ERESTARTSYS;
7355 /*
7356 ATUC_PERF_LO_FLAG_MAKECMV;
7357 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
7358 #ifdef AMAZON_MEI_DEBUG_ON
7359 printk("\n\nCMV fail, Group 7 Address 0 Index 0");
7360 #endif
7361 }
7362 else{
7363 if(RxMessage[4]&PLAM_LOS_FailureBit){
7364 current_intvl->AtucPerfLos++;
7365 ATUC_PERF_LOSS++;
7366 CurrStatus.adslAtucCurrStatus = 2;
7367 }
7368 if(RxMessage[4]&PLAM_LOF_FailureBit){
7369 current_intvl->AtucPerfLof++;
7370 ATUC_PERF_LOFS++;
7371 CurrStatus.adslAtucCurrStatus = 1;
7372 }
7373 if(!(RxMessage[4]&(PLAM_LOS_FailureBit|PLAM_LOF_FailureBit)))
7374 CurrStatus.adslAtucCurrStatus = 0;
7375 }
7376 */
7377
7378 if(showtime!=1)
7379 goto mib_poll_end;
7380 ATUC_PERF_ESS_FLAG_MAKECMV;
7381 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
7382 #ifdef AMAZON_MEI_DEBUG_ON
7383 printk("\n\nCMV fail, Group 7 Address 7 Index 0");
7384 #endif
7385 }
7386 else{
7387 temp = RxMessage[4]-mib_pread.ATUC_PERF_ESS;
7388 if(temp>=0){
7389 current_intvl->AtucPerfEs+=temp;
7390 ATUC_PERF_ESS+=temp;
7391 mib_pread.ATUC_PERF_ESS = RxMessage[4];
7392 }
7393 else{
7394 current_intvl->AtucPerfEs+=0xffff-mib_pread.ATUC_PERF_ESS+RxMessage[4];
7395 ATUC_PERF_ESS+=0xffff-mib_pread.ATUC_PERF_ESS+RxMessage[4];
7396 mib_pread.ATUC_PERF_ESS = RxMessage[4];
7397 }
7398 }
7399 /*
7400 ATUR_PERF_LO_FLAG_MAKECMV;
7401 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
7402 #ifdef AMAZON_MEI_DEBUG_ON
7403 printk("\n\nCMV fail, Group 7 Address 1 Index 0");
7404 #endif
7405 }
7406 else{
7407 if(RxMessage[4]&PLAM_LOS_FailureBit){
7408 current_intvl->AturPerfLos++;
7409 ATUR_PERF_LOSS++;
7410 CurrStatus.adslAturCurrStatus = 2;
7411 }
7412 if(RxMessage[4]&PLAM_LOF_FailureBit){
7413 current_intvl->AturPerfLof++;
7414 ATUR_PERF_LOFS++;
7415 CurrStatus.adslAturCurrStatus = 1;
7416 }
7417 if(RxMessage[4]&PLAM_LPR_FailureBit){
7418 current_intvl->AturPerfLpr++;
7419 ATUR_PERF_LPR++;
7420 CurrStatus.adslAturCurrStatus = 3;
7421 }
7422 if(!(RxMessage[4]&(PLAM_LOS_FailureBit|PLAM_LOF_FailureBit|PLAM_LPR_FailureBit)))
7423 CurrStatus.adslAturCurrStatus = 0;
7424 }
7425 */
7426 if(showtime!=1)
7427 goto mib_poll_end;
7428 ATUR_PERF_ESS_FLAG_MAKECMV;
7429 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
7430 #ifdef AMAZON_MEI_DEBUG_ON
7431 printk("\n\nCMV fail, Group 7 Address 33 Index 0");
7432 #endif
7433 }
7434 else{
7435 temp = RxMessage[4]-mib_pread.ATUR_PERF_ESS;
7436 if(temp>=0){
7437 current_intvl->AturPerfEs+=temp;
7438 ATUR_PERF_ESS+=temp;
7439 mib_pread.ATUR_PERF_ESS = RxMessage[4];
7440 }
7441 else{
7442 current_intvl->AturPerfEs+=0xffff-mib_pread.ATUR_PERF_ESS+RxMessage[4];
7443 ATUR_PERF_ESS+= 0xffff-mib_pread.ATUR_PERF_ESS+RxMessage[4];
7444 mib_pread.ATUR_PERF_ESS=RxMessage[4];
7445 }
7446 }
7447 if(showtime!=1)
7448 goto mib_poll_end;
7449 // to update rx/tx blocks
7450 ATUR_CHAN_RECV_BLK_FLAG_MAKECMV_LSW;
7451 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
7452 #ifdef AMAZON_MEI_DEBUG_ON
7453 printk("\n\nCMV fail, Group 7 Address 20 Index 0");
7454 #endif
7455 }
7456 else{
7457 temp = RxMessage[4];
7458 }
7459 if(showtime!=1)
7460 goto mib_poll_end;
7461 ATUR_CHAN_RECV_BLK_FLAG_MAKECMV_MSW;
7462 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
7463 #ifdef AMAZON_MEI_DEBUG_ON
7464 printk("\n\nCMV fail, Group 7 Address 21 Index 0");
7465 #endif
7466 }
7467 else{
7468 temp2 = RxMessage[4];
7469 }
7470 if((temp + (temp2<<16) - mib_pread.ATUR_CHAN_RECV_BLK)>=0){
7471 current_intvl->AturChanPerfRxBlk+=temp + (temp2<<16) - mib_pread.ATUR_CHAN_RECV_BLK;
7472 ATUR_CHAN_RECV_BLK+=temp + (temp2<<16) - mib_pread.ATUR_CHAN_RECV_BLK;
7473 mib_pread.ATUR_CHAN_RECV_BLK = temp + (temp2<<16);
7474 }
7475 else{
7476 current_intvl->AturChanPerfRxBlk+=0xffffffff - mib_pread.ATUR_CHAN_RECV_BLK +(temp + (temp2<<16));
7477 ATUR_CHAN_RECV_BLK+=0xffffffff - mib_pread.ATUR_CHAN_RECV_BLK +(temp + (temp2<<16));
7478 mib_pread.ATUR_CHAN_RECV_BLK = temp + (temp2<<16);
7479 }
7480 current_intvl->AturChanPerfTxBlk = current_intvl->AturChanPerfRxBlk;
7481 ATUR_CHAN_TX_BLK = ATUR_CHAN_RECV_BLK;
7482 /*
7483 ATUR_CHAN_TX_BLK_FLAG_MAKECMV_LSW;
7484 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS)
7485 printk("\n\nCMV fail, Group 7 Address 20 Index 0");
7486 else{
7487 if(RxMessage[4]){
7488 current_intvl->AturChanPerfTxBlk+=RxMessage[4];
7489 ATUR_CHAN_TX_BLK+=RxMessage[4];
7490 }
7491 }
7492 ATUR_CHAN_TX_BLK_FLAG_MAKECMV_MSW;
7493 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS)
7494 printk("\n\nCMV fail, Group 7 Address 21 Index 0");
7495 else{
7496 if(RxMessage[4]){
7497 current_intvl->AturChanPerfTxBlk+=(int)((RxMessage[4])<<16);
7498 ATUR_CHAN_TX_BLK+=(int)((RxMessage[4])<<16);
7499 }
7500 }
7501 */
7502 if(chantype.interleave == 1){
7503 if(showtime!=1)
7504 goto mib_poll_end;
7505 ATUR_CHAN_CORR_BLK_FLAG_MAKECMV_INTL;
7506 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
7507 #ifdef AMAZON_MEI_DEBUG_ON
7508 printk("\n\nCMV fail, Group 7 Address 3 Index 0");
7509 #endif
7510 }
7511 else{
7512 temp = RxMessage[4] - mib_pread.ATUR_CHAN_CORR_BLK_INTL;
7513 if(temp>=0){
7514 current_intvl->AturChanPerfCorrBlk+=temp;
7515 ATUR_CHAN_CORR_BLK+=temp;
7516 mib_pread.ATUR_CHAN_CORR_BLK_INTL = RxMessage[4];
7517 }
7518 else{
7519 current_intvl->AturChanPerfCorrBlk+=0xffff - mib_pread.ATUR_CHAN_CORR_BLK_INTL +RxMessage[4];
7520 ATUR_CHAN_CORR_BLK+=0xffff - mib_pread.ATUR_CHAN_CORR_BLK_INTL +RxMessage[4];
7521 mib_pread.ATUR_CHAN_CORR_BLK_INTL = RxMessage[4];
7522 }
7523 }
7524 }
7525 else if(chantype.fast == 1){
7526 if(showtime!=1)
7527 goto mib_poll_end;
7528 ATUR_CHAN_CORR_BLK_FLAG_MAKECMV_FAST;
7529 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
7530 #ifdef AMAZON_MEI_DEBUG_ON
7531 printk("\n\nCMV fail, Group 7 Address 3 Index 1");
7532 #endif
7533 }
7534 else{
7535 temp = RxMessage[4] - mib_pread.ATUR_CHAN_CORR_BLK_FAST;
7536 if(temp>=0){
7537 current_intvl->AturChanPerfCorrBlk+=temp;
7538 ATUR_CHAN_CORR_BLK+=temp;
7539 mib_pread.ATUR_CHAN_CORR_BLK_FAST = RxMessage[4];
7540 }
7541 else{
7542 current_intvl->AturChanPerfCorrBlk+=0xffff - mib_pread.ATUR_CHAN_CORR_BLK_FAST + RxMessage[4];
7543 ATUR_CHAN_CORR_BLK+=0xffff - mib_pread.ATUR_CHAN_CORR_BLK_FAST + RxMessage[4];
7544 mib_pread.ATUR_CHAN_CORR_BLK_FAST = RxMessage[4];
7545 }
7546 }
7547 }
7548
7549 if(chantype.interleave == 1){
7550 if(showtime!=1)
7551 goto mib_poll_end;
7552 ATUR_CHAN_UNCORR_BLK_FLAG_MAKECMV_INTL;
7553 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
7554 #ifdef AMAZON_MEI_DEBUG_ON
7555 printk("\n\nCMV fail, Group 7 Address 2 Index 0");
7556 #endif
7557 }
7558 else{
7559 temp = RxMessage[4] - mib_pread.ATUR_CHAN_UNCORR_BLK_INTL;
7560 if(temp>=0){
7561 current_intvl->AturChanPerfUncorrBlk+=temp;
7562 ATUR_CHAN_UNCORR_BLK+=temp;
7563 mib_pread.ATUR_CHAN_UNCORR_BLK_INTL = RxMessage[4];
7564 }
7565 else{
7566 current_intvl->AturChanPerfUncorrBlk+=0xffff - mib_pread.ATUR_CHAN_UNCORR_BLK_INTL + RxMessage[4];
7567 ATUR_CHAN_UNCORR_BLK+=0xffff - mib_pread.ATUR_CHAN_UNCORR_BLK_INTL + RxMessage[4];
7568 mib_pread.ATUR_CHAN_UNCORR_BLK_INTL = RxMessage[4];
7569 }
7570 }
7571 }
7572 else if(chantype.fast == 1){
7573 if(showtime!=1)
7574 goto mib_poll_end;
7575 ATUR_CHAN_UNCORR_BLK_FLAG_MAKECMV_FAST;
7576 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
7577 #ifdef AMAZON_MEI_DEBUG_ON
7578 printk("\n\nCMV fail, Group 7 Address 2 Index 1");
7579 #endif
7580 }
7581 else{
7582 temp = RxMessage[4] - mib_pread.ATUR_CHAN_UNCORR_BLK_FAST;
7583 if(temp>=0){
7584 current_intvl->AturChanPerfUncorrBlk+=temp;
7585 ATUR_CHAN_UNCORR_BLK+=temp;
7586 mib_pread.ATUR_CHAN_UNCORR_BLK_FAST = RxMessage[4];
7587 }
7588 else{
7589 current_intvl->AturChanPerfUncorrBlk+=0xffff - mib_pread.ATUR_CHAN_UNCORR_BLK_FAST + RxMessage[4];
7590 ATUR_CHAN_UNCORR_BLK+=0xffff - mib_pread.ATUR_CHAN_UNCORR_BLK_FAST + RxMessage[4];
7591 mib_pread.ATUR_CHAN_UNCORR_BLK_FAST = RxMessage[4];
7592 }
7593 }
7594 }
7595
7596 //RFC-3440
7597
7598 #ifdef AMAZON_MEI_MIB_RFC3440
7599 if(showtime!=1)
7600 goto mib_poll_end;
7601 ATUC_PERF_STAT_FASTR_FLAG_MAKECMV; //???
7602 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
7603 #ifdef AMAZON_MEI_DEBUG_ON
7604 printk("\n\nCMV fail, Group 0 Address 0 Index 0");
7605 #endif
7606 }
7607 else{
7608 temp = RxMessage[4] - mib_pread.ATUC_PERF_STAT_FASTR;
7609 if(temp>=0){
7610 current_intvl->AtucPerfStatFastR+=temp;
7611 ATUC_PERF_STAT_FASTR+=temp;
7612 mib_pread.ATUC_PERF_STAT_FASTR = RxMessage[4];
7613 }
7614 else{
7615 current_intvl->AtucPerfStatFastR+=0xffff - mib_pread.ATUC_PERF_STAT_FASTR + RxMessage[4];
7616 ATUC_PERF_STAT_FASTR+=0xffff - mib_pread.ATUC_PERF_STAT_FASTR + RxMessage[4];
7617 mib_pread.ATUC_PERF_STAT_FASTR = RxMessage[4];
7618 }
7619 }
7620 if(showtime!=1)
7621 goto mib_poll_end;
7622 ATUC_PERF_STAT_FAILED_FASTR_FLAG_MAKECMV; //???
7623 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
7624 #ifdef AMAZON_MEI_DEBUG_ON
7625 printk("\n\nCMV fail, Group 0 Address 0 Index 0");
7626 #endif
7627 }
7628 else{
7629 temp = RxMessage[4] - mib_pread.ATUC_PERF_STAT_FAILED_FASTR;
7630 if(temp>=0){
7631 current_intvl->AtucPerfStatFailedFastR+=temp;
7632 ATUC_PERF_STAT_FAILED_FASTR+=temp;
7633 mib_pread.ATUC_PERF_STAT_FAILED_FASTR = RxMessage[4];
7634 }
7635 else{
7636 current_intvl->AtucPerfStatFailedFastR+=0xffff - mib_pread.ATUC_PERF_STAT_FAILED_FASTR + RxMessage[4];
7637 ATUC_PERF_STAT_FAILED_FASTR+=0xffff - mib_pread.ATUC_PERF_STAT_FAILED_FASTR + RxMessage[4];
7638 mib_pread.ATUC_PERF_STAT_FAILED_FASTR = RxMessage[4];
7639 }
7640 }
7641 if(showtime!=1)
7642 goto mib_poll_end;
7643 ATUC_PERF_STAT_SESL_FLAG_MAKECMV;
7644 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
7645 #ifdef AMAZON_MEI_DEBUG_ON
7646 printk("\n\nCMV fail, Group 7 Address 8 Index 0");
7647 #endif
7648 }
7649 else{
7650 temp = RxMessage[4] - mib_pread.ATUC_PERF_STAT_SESL;
7651 if(temp>=0){
7652 current_intvl->AtucPerfStatSesL+=temp;
7653 ATUC_PERF_STAT_SESL+=temp;
7654 mib_pread.ATUC_PERF_STAT_SESL = RxMessage[4];
7655 }
7656 else{
7657 current_intvl->AtucPerfStatSesL+=0xffff - mib_pread.ATUC_PERF_STAT_SESL + RxMessage[4];
7658 ATUC_PERF_STAT_SESL+=0xffff - mib_pread.ATUC_PERF_STAT_SESL + RxMessage[4];
7659 mib_pread.ATUC_PERF_STAT_SESL = RxMessage[4];
7660 }
7661 }
7662 if(showtime!=1)
7663 goto mib_poll_end;
7664 ATUC_PERF_STAT_UASL_FLAG_MAKECMV;
7665 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
7666 #ifdef AMAZON_MEI_DEBUG_ON
7667 printk("\n\nCMV fail, Group 7 Address 10 Index 0");
7668 #endif
7669 }
7670 else{
7671 temp = RxMessage[4] - mib_pread.ATUC_PERF_STAT_UASL;
7672 if(temp>=0){
7673 current_intvl->AtucPerfStatUasL+=temp;
7674 ATUC_PERF_STAT_UASL+=temp;
7675 mib_pread.ATUC_PERF_STAT_UASL = RxMessage[4];
7676 }
7677 else{
7678 current_intvl->AtucPerfStatUasL+=0xffff - mib_pread.ATUC_PERF_STAT_UASL + RxMessage[4];
7679 ATUC_PERF_STAT_UASL+=0xffff - mib_pread.ATUC_PERF_STAT_UASL + RxMessage[4];
7680 mib_pread.ATUC_PERF_STAT_UASL = RxMessage[4];
7681 }
7682 }
7683 if(showtime!=1)
7684 goto mib_poll_end;
7685 ATUR_PERF_STAT_SESL_FLAG_MAKECMV;
7686 if(meiCMV(TxMessage, YES_REPLY)!=MEI_SUCCESS){
7687 #ifdef AMAZON_MEI_DEBUG_ON
7688 printk("\n\nCMV fail, Group 7 Address 34 Index 0");
7689 #endif
7690 }
7691 else{
7692 temp = RxMessage[4] - mib_pread.ATUR_PERF_STAT_SESL;
7693 if(temp>=0){
7694 current_intvl->AtucPerfStatUasL+=temp;
7695 ATUC_PERF_STAT_UASL+=temp;
7696 mib_pread.ATUR_PERF_STAT_SESL = RxMessage[4];
7697 }
7698 else{
7699 current_intvl->AtucPerfStatUasL+=0xffff - mib_pread.ATUR_PERF_STAT_SESL + RxMessage[4];
7700 ATUC_PERF_STAT_UASL+=0xffff - mib_pread.ATUR_PERF_STAT_SESL + RxMessage[4];
7701 mib_pread.ATUR_PERF_STAT_SESL = RxMessage[4];
7702 }
7703 }
7704
7705 #endif
7706 mib_poll_end:
7707 up(&mei_sema);
7708
7709 do_gettimeofday(&time_fini);
7710 i = ((int)((time_fini.tv_sec-time_now.tv_sec)*1000)) + ((int)((time_fini.tv_usec-time_now.tv_usec)/1000)) ; //msec
7711 }//showtime==1
7712 }
7713
7714 }
7715 int mib_poll_init(void)
7716 {
7717 printk("Starting mib_poll...\n");
7718
7719 kernel_thread(adsl_mib_poll, NULL, CLONE_FS | CLONE_FILES | CLONE_SIGNAL);
7720 return 0;
7721 }
7722 #endif //IFX_SMALL_FOOTPRINT
7723 //EXPORT_NO_SYMBOLS;
7724
7725 #ifdef ADSL_LED_SUPPORT
7726 // adsl led -start
7727 int led_status_on=0,led_need_to_flash=0;
7728 int led_current_flashing=0;
7729 unsigned long led_delay=0;
7730 static int led_poll(void *unused)
7731 {
7732 stop_led_module=0; //begin polling ...
7733 while(!stop_led_module){
7734 if ((!led_status_on)&&(!led_need_to_flash)) interruptible_sleep_on_timeout (&wait_queue_led_polling,1000); //10 seconds timeout for waiting wakeup
7735 // else printk("direct running task, no waiting");
7736 run_task_queue(&tq_ifx_led);//joelin task
7737 // printk("led and LOP polling...\n");
7738 }
7739 return 0;
7740 }
7741 static int led_poll_init(void)
7742 {
7743 // printk("Starting adsl led polling...\n");
7744
7745 //warning-led-start
7746 // CLEAR_BIT((*((volatile u32 *)0xB0100B40)), 0x40); //Warning LED GPIO ON
7747 //warning-led-end
7748
7749 kernel_thread(led_poll, NULL, CLONE_FS | CLONE_FILES | CLONE_SIGNAL);
7750 return 0;
7751 }
7752
7753 int adsl_led_flash(void)
7754 {
7755 int i;
7756 if (!firmware_support_led) return 0; //joelin version check
7757
7758 if (led_status_on == 0 && led_need_to_flash == 0)
7759 {
7760 queue_task(&led_task, &tq_ifx_led);//joelin task
7761 wake_up_interruptible(&wait_queue_led_polling); //wake up and clean led module
7762 // printk("queue Task 1...\n"); //joelin test
7763 }
7764 led_need_to_flash=1;//asking to flash led
7765
7766 return 0;
7767 }
7768
7769 int adsl_led_flash_task(void *ptr)
7770 {
7771
7772 u16 one=1;
7773 u16 zero=0;
7774 u16 data=0x0600;
7775 int kernel_use=1;
7776 u16 CMVMSG[MSG_LENGTH];
7777 //adsl-led-start for >v1.1.2.7.1.1
7778 // printk("Task Running...\n"); //joelin test
7779 if ((firmware_support_led==2)&&(led_support_check))
7780 {
7781 led_support_check=0;
7782 data=0x0600;
7783 makeCMV_local(H2D_CMV_WRITE, INFO, 91, 0, 1, &data,CMVMSG); //configure GPIO9 GPIO10 as outputs
7784 mei_ioctl((struct inode *)0,NULL, AMAZON_MEI_CMV_WINHOST, CMVMSG);
7785
7786 makeCMV_local(H2D_CMV_WRITE, INFO, 91, 2, 1, &data,CMVMSG); //enable writing to bit 9 and bit10
7787 mei_ioctl((struct inode *)0,NULL, AMAZON_MEI_CMV_WINHOST, CMVMSG);
7788
7789 data=0x0a01;
7790 makeCMV_local(H2D_CMV_WRITE, INFO, 91, 4, 1, &data,CMVMSG); //use GPIO10 for TR68 .Enable and don't invert.
7791 mei_ioctl((struct inode *)0,NULL, AMAZON_MEI_CMV_WINHOST, CMVMSG);
7792
7793 #ifdef DATA_LED_ON_MODE
7794 data=0x0903;//tecom //use GPIO9 for TR68 data led .turn on.
7795 #else
7796 data=0x0900;
7797 #endif
7798 makeCMV_local(H2D_CMV_WRITE, INFO, 91, 5, 1, &data,CMVMSG); //use GPIO9 for TR68 data led .turn off.
7799 mei_ioctl((struct inode *)0,NULL, AMAZON_MEI_CMV_WINHOST, CMVMSG);
7800
7801 }
7802 if (!showtime) {led_need_to_flash=0; return 0;}
7803 //adsl-led-end for >v1.1.2.7.1.1
7804
7805 if (led_status_on == 0 || led_need_to_flash == 1)
7806 {
7807
7808 if (led_current_flashing==0)
7809 {
7810 if (firmware_support_led==1){//>1.1.2.3.1.1
7811 makeCMV_local(H2D_CMV_WRITE, INFO, 91, 0, 1, &one,CMVMSG); //flash
7812 mei_ioctl((struct inode *)0,NULL, AMAZON_MEI_CMV_WINHOST, &CMVMSG);
7813 }
7814 else if (firmware_support_led==2){//>1.1.2.7.1.1
7815 data=0x0901;//flash
7816 makeCMV_local(H2D_CMV_WRITE, INFO, 91, 5, 1, &data,CMVMSG); //use GPIO9 for TR68 data led .flash.
7817 mei_ioctl((struct inode *)0,NULL, AMAZON_MEI_CMV_WINHOST, &CMVMSG);
7818
7819 }//(firmware_support_led==2)
7820 led_current_flashing = 1;//turn on led
7821 }
7822 led_status_on=1;
7823
7824 do{//do nothing , waiting untill no data traffic
7825 led_need_to_flash=0;
7826 interruptible_sleep_on_timeout(&wait_queue_led, 25); //the time for LED Off , if no data traffic
7827 }while(led_need_to_flash==1);
7828
7829 }else if (led_status_on == 1 && led_need_to_flash==0)
7830 {
7831 if (led_current_flashing==1)
7832 {//turn off led
7833 if (firmware_support_led==1){//>1.1.2.3.1.1
7834 makeCMV_local(H2D_CMV_WRITE, INFO, 91, 0, 1, &zero,CMVMSG);//off
7835 mei_ioctl((struct inode *)0,NULL, AMAZON_MEI_CMV_WINHOST, &CMVMSG);
7836 } //>1.1.2.3.1.1
7837 else if (firmware_support_led==2){//>1.1.2.7.1.1
7838 #ifdef DATA_LED_ON_MODE
7839 data=0x0903;//tecom //use GPIO9 for TR68 data led .turn on.
7840 #else
7841 data=0x0900;//off
7842 #endif
7843 makeCMV_local(H2D_CMV_WRITE, INFO, 91, 5, 1, &data,CMVMSG); //use GPIO9 for TR68 data led .off.
7844 mei_ioctl((struct inode *)0,NULL, AMAZON_MEI_CMV_WINHOST, &CMVMSG);
7845
7846 }//(firmware_support_led==2)
7847 led_status_on=0;
7848 led_current_flashing = 0;
7849 }
7850 }
7851
7852 if (led_status_on == 1 || led_need_to_flash)
7853 {//led flash job on going or led need to flash
7854 queue_task(&led_task, &tq_ifx_led); //joelin task
7855 // printk("queue Task 2...\n"); //joelin test
7856 }
7857 return 0;
7858 }
7859 //joelin adsl led-end
7860 #else
7861 int adsl_led_flash(void)
7862 {
7863 return 0;
7864 }
7865 #endif //ADSL_LED_SUPPORT
7866 #ifdef IFX_DYING_GASP
7867 static int lop_poll(void *unused)
7868 {
7869
7870 while(1)
7871 {
7872 interruptible_sleep_on_timeout(&wait_queue_dying_gasp, 1);
7873 #ifdef CONFIG_CPU_AMAZON_E //000003:fchang
7874 if(showtime&&((*((volatile u32 *)0xB0100B14))&0x4)==0x0) {//000003:fchang
7875 #else //000003:fchang
7876 if(showtime&&((*((volatile u32 *)0xB0100B44))&0x8000)==0x0) {
7877 #endif //CONFIG_CPU_AMAZON_E
7878 mei_ioctl((struct inode *)0,NULL, AMAZON_MEI_WRITEDEBUG, &lop_debugwr);
7879 printk("send dying gasp..\n");}
7880
7881 }
7882 return 0;
7883 }
7884 static int lop_poll_init(void)
7885 {
7886 // printk("Starting LOP polling...\n");
7887 kernel_thread(lop_poll, NULL, CLONE_FS | CLONE_FILES | CLONE_SIGNAL);
7888 return 0;
7889 }
7890
7891 #endif //IFX_DYING_GASP
7892
7893 //joelin 04/16/2005-satrt
7894 static int unavailable_seconds_poll(void *unused)
7895 {
7896 while(1){
7897 interruptible_sleep_on_timeout (&wait_queue_uas_poll,100); //1 second timeout for waiting wakeup
7898 if (!showtime) unavailable_seconds++;
7899 }
7900 return 0;
7901 }
7902 static int unavailable_seconds_poll_init(void)
7903 {
7904
7905 kernel_thread(unavailable_seconds_poll, NULL, CLONE_FS | CLONE_FILES | CLONE_SIGNAL);
7906 return 0;
7907 }
7908
7909
7910 //joelin 04/16/2005-end
7911 EXPORT_SYMBOL(meiDebugWrite);
7912 EXPORT_SYMBOL(ifx_pop_eoc);
7913
7914 MODULE_LICENSE("GPL");
7915
7916 module_init(amazon_mei_init_module);
7917 module_exit(amazon_mei_cleanup_module);
7918
This page took 0.448006 seconds and 5 git commands to generate.