1 /****************************************************************************
4 Infineon Technologies AG
5 St. Martin Strasse 53; 81669 Munich, Germany
7 Any use of this Software is subject to the conclusion of a respective
8 License Agreement. Without such a License Agreement no rights to the
11 *****************************************************************************/
15 09/08/2006 Removed DEMO_ONLY define
17 31/08/2006 Add IOCTL AUTOBOOT_ENABLE_SET
19 14/09/2006 Add min snr margin check for in Annex B DMT mode
21 18/09/2006 Add G.lite support
23 10/11/2006 change quiet mode and showtime lock implement mechanism (old: using cmv, new: using ioctl to kernel mode, and the mei driver keep the value) per the mail from Oliver Salomon on 08/11/2006
25 13/11/2006 TC Chen: Fix minimal snr issue for ADSL Annex B.
27 08/12/2006 TC Chen: Fix loop diagnostic warning issue
29 27/12/2006 TC Chen: Fix the issue that "The autoboot daemon will call "./translate" which is a problem when started through scripts."
31 1/09/2007 Bing Tao: Fix AnnexJ issue
34 #define _IFXMIPS_ADSL_APP
35 //#define IFXMIPS_PORT_RTEMS 1
38 #if defined(IFXMIPS_PORT_RTEMS)
39 #include "ifxmips_mei_rtems.h"
40 #define KERNEL_SPACE_APPLICATION 1
43 #define u32 unsigned int
45 #define VERSION_MAJOR 1
46 #define VERSION_MINOR 10
48 #if defined(__LINUX__)
52 #include <sys/ioctl.h>
58 #include <asm/ifxmips/ifxmips_mei_app.h>
59 #include <asm/ifxmips/ifxmips_mei_app_ioctl.h>
60 #include <asm/ifxmips/ifxmips_mei_ioctl.h>
61 #include <sys/types.h>
65 #define IFXMIPS_MEI_DEV "/dev/ifxmips/mei"
68 #if defined(KERNEL_SPACE_APPLICATION)
69 #include "ifxmips_adsl_fw.h"
72 #define IFXMIPS_GPIO_DEVICE "/dev/ifxmips_port"
73 #undef DEMO_ONLY //todo: remove for normal release
75 #define SEGMENT_SIZE (64*1024)
88 #define MODE_992_5I 10
89 #define MODE_992_5J 11
90 #define MODE_992_5M 12
93 #define MODE_M_B_ALL 15
96 #if defined(KERNEL_SPACE_APPLICATION)
97 extern int mei_ioctl(int ino
, int * fil
, unsigned int command
, unsigned long lon
);
98 #define ioctl(fd,cmd,arg) mei_ioctl(1,0,cmd,(unsigned long)arg)
99 extern void makeCMV(u8 opcode
, u8 group
, u16 address
, u16 index
, int size
, u16
* data
,u16
*CMVMSG
);
102 static u16 Message
[16]__attribute__ ((aligned(4)));
104 #if !defined(KERNEL_SPACE_APPLICATION)
105 void makeCMV(u8 opcode
, u8 group
, u16 address
, u16 index
, int size
, u16
* data
, u16
*CMVMSG
);
106 void makeCMV(u8 opcode
, u8 group
, u16 address
, u16 index
, int size
, u16
* data
, u16
*CMVMSG
)
108 memset(CMVMSG
, 0, 16*2);
109 CMVMSG
[0]= (opcode
<<4) + (size
&0xf);
110 if(opcode
== H2D_DEBUG_WRITE_DM
)
111 CMVMSG
[1]= (group
&0x7f);
113 CMVMSG
[1]= (((index
==0)?0:1)<<7) + (group
&0x7f);
116 if((opcode
== H2D_CMV_WRITE
)||(opcode
== H2D_DEBUG_WRITE_DM
))
117 memcpy(CMVMSG
+4, data
, size
*2);
122 void print_usage(char *program_name
)
124 printf("Usage: %s ADSL_Firmware ADSL_MODE \n",program_name
);
125 printf("\tADSL_Firmeare: Specify the ADSL firmware file to use.\n");
126 printf("\tADSL_MODE:Specify the ADSL mode to use for training.\n");
127 printf("\t\tSupported Mode: all,1a,3a,5a,1b,3b,5b,3i,3j,3m,5i,5j,5m,m_all,b_all,mb_all\n");
131 #if defined(KERNEL_SPACE_APPLICATION)
133 int Download_Firmware(char *filename
, int fd_mei
)
135 extern ssize_t
mei_write(char * filp
, const char * buf
, size_t size
, loff_t
* loff
);
136 extern unsigned long cgi_pFileData_modemfw_bin
[];
137 unsigned long offset
=0;
139 mei_write(0,(char *)cgi_pFileData_modemfw_bin
,sizeof(cgi_pFileData_modemfw_bin
),&offset
);
143 int Download_Firmware(char *filename
, int fd_mei
)
147 int size
=0,read_size
= SEGMENT_SIZE
;
148 struct stat file_stat
;
150 fd_image
=open(filename
, O_RDONLY
);
153 printf("\n open %s fail.\n",filename
);
156 if(lstat(filename
, &file_stat
)<0){
157 printf("\n lstat error");
160 size
=file_stat
.st_size
;
161 buf
=malloc(read_size
);
163 printf("\n malloc failed in MEI main()");
167 lseek(fd_image
, 0, SEEK_SET
);
168 lseek(fd_mei
, 0, SEEK_SET
);
172 if (size
>SEGMENT_SIZE
)
173 read_size
=SEGMENT_SIZE
;
176 if(read(fd_image
, buf
, read_size
)<=0){
177 printf("\n amazon_mei_image not present");
180 if(write(fd_mei
, buf
, read_size
)!=read_size
){
181 printf("\n write to mei driver fail");
192 // 609141:tc.chen :read min margin from CO for Annex B in DMT mode
193 int read_min_snr_margin(int fd
, s16
*rt_ne_ds_min_margin
)
195 makeCMV(H2D_CMV_READ
,STAT
, 1, 0, 1, NULL
, Message
);
196 if (ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)!=0)
198 if (Message
[4] == 0x8) //992.1 AnnexB
201 makeCMV(H2D_CMV_READ
,INFO
, 33, 1, 1, NULL
, Message
);
202 if (ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)!=0)
206 // INFO 33 is 6 bits sign value
207 min_margin
= (Message
[4] & 0x3f);
210 *rt_ne_ds_min_margin
= min_margin
- 64;
213 *rt_ne_ds_min_margin
= min_margin
;
217 *rt_ne_ds_min_margin
= 0;
221 // 609141:tc.chen end
223 #if !defined(KERNEL_SPACE_APPLICATION)
224 int main(int argc
, char **argv
)
226 int ifxmips_autoboot_main (int argc
, char **argv
)
240 int reboot_flag
, rt_ne_los_flag
;
241 u16 rt_ne_failure_flags
=0;
242 s16 rt_ne_ds_margin
=0;
243 s16 rt_ne_ds_min_margin
=0; //609141:tc.chen:
244 u16 rt_buildcode_lsw
=0, rt_buildcode_msw
=0;
245 u32 rt_buildcode
= 0;
246 int FarEndResponseReceived
;
249 int tmpShowTimeLockEnabled
= 0;
254 u16 first_power_on
=1;
256 int pre_loop_diagnostics_mode
=0;
257 int loop_diagnostics_mode
=0;
259 if ((argc
< 2) || (argc
> 5) )
260 { printf("\n Wrong Argument\n");
261 print_usage(argv
[0]);
266 // translate is called with "./translate -ef", but if the autoboot daemon
267 // is started during system boot, the current directory is "/", which
268 // makes the "system" call fail.
269 // Thus we make the program's directory the working directory.
271 char *argv0
, *prog_dir
;
273 /* The dirname system call might change its argument,
274 thus we need a local copy */
275 argv0_size
= strlen(argv
[0]) + 1;
276 argv0
= malloc(argv0_size
);
278 printf("\n Insufficient memory\n");
281 /* make sure there is no buffer overflow and
282 the string is null-terminated */
283 strncpy(argv0
, argv
[0], argv0_size
);
284 argv0
[argv0_size
-1] = '\0';
286 prog_dir
= dirname(argv0
);
292 //display version info or download firmware
295 if ((strncmp(argv
[1], "ver", 3)==0) || (strncmp(argv
[1], "VER", 3)==0)){
296 printf("\n ifxmips_autoboot_daemon version: %d.%02d.00\n",VERSION_MAJOR
,VERSION_MINOR
);
299 #if !defined(KERNEL_SPACE_APPLICATION)
300 fd
=open(IFXMIPS_MEI_DEV
, O_RDWR
);
302 printf("autoboot open %s fail\n",IFXMIPS_MEI_DEV
);
306 // Notify mei driver that it is controlled by autoboot daemon
308 if (ioctl(fd
, AUTOBOOT_ENABLE_SET
, &i
)<0){
309 printf("\n\n mei ioctl AUTOBOOT_ENABLE_SET fail.\n");
312 Download_Firmware(argv
[1],fd
);
313 if (ioctl(fd
, IFXMIPS_MEI_START
,NULL
)<0){
314 printf("\n\n mei start fail.\n");
315 #if !defined(KERNEL_SPACE_APPLICATION)
320 #if !defined(KERNEL_SPACE_APPLICATION)
327 if (strncmp(argv
[2], "all", 3) == 0)
329 else if ((strncmp(argv
[2], "1a", 2) == 0) || (strncmp(argv
[2], "1A", 2) == 0))
331 else if ((strncmp(argv
[2], "1b", 2) == 0) || (strncmp(argv
[2], "1B", 2) == 0))
333 else if ((strncmp(argv
[2], "3a", 2) == 0) || (strncmp(argv
[2], "3A", 2) == 0))
335 else if ((strncmp(argv
[2], "3b", 2) == 0) || (strncmp(argv
[2], "3B", 2) == 0))
337 else if ((strncmp(argv
[2], "5a", 2) == 0) || (strncmp(argv
[2], "5A", 2) == 0))
339 else if ((strncmp(argv
[2], "5b", 2) == 0) || (strncmp(argv
[2], "5B", 2) == 0))
342 else if ((strncmp(argv
[2], "3i",2) == 0) || (strncmp(argv
[2], "3I",2) == 0))
344 else if ((strncmp(argv
[2], "3j",2) == 0) || (strncmp(argv
[2], "3J",2) == 0))
346 else if ((strncmp(argv
[2], "3m",2) == 0) || (strncmp(argv
[2], "3M",2) == 0))
348 else if ((strncmp(argv
[2], "5i",2) == 0) || (strncmp(argv
[2], "5I",2) == 0))
350 else if ((strncmp(argv
[2], "5j",2) == 0) || (strncmp(argv
[2], "5J",2) == 0))
352 else if ((strncmp(argv
[2], "5m",2) == 0) || (strncmp(argv
[2], "5M",2) == 0))
354 else if (strncmp(argv
[2], "m_all",5) == 0)
356 else if (strncmp(argv
[2], "b_all",5) == 0)
358 else if (strncmp(argv
[2], "mb_all",6) == 0)
362 { printf("\n Wrong Argument\n");
363 print_usage(argv
[0]);
367 #if !defined(KERNEL_SPACE_APPLICATION)
368 fd
=open(IFXMIPS_MEI_DEV
, O_RDWR
);
370 printf("autoboot open %s fail\n",IFXMIPS_MEI_DEV
);
376 if (ioctl(fd
, AUTOBOOT_ENABLE_SET
, &i
)<0){
377 printf("\n\n mei ioctl AUTOBOOT_ENABLE_SET fail.\n");
379 Download_Firmware(argv
[1],fd
);
381 if (ioctl(fd
, IFXMIPS_MEI_START
,NULL
)<0){
382 printf("\n\n mei start fail.\n");
383 ioctl(fd
, IFXMIPS_MEI_REBOOT
,NULL
);
388 makeCMV(H2D_CMV_READ
, INFO
, 54,1, 1, &temp
, Message
);
389 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
390 printf("\n\n read INFO 54 1 fail");
394 if(((Message
[4]>>8)&0x3f)==0x1){//Annex A
396 if ((mode
== MODE_992_1B
) || (mode
== MODE_992_3B
) || (mode
== MODE_992_5B
))
397 { printf("\n\nWrong Argument, Annex A is running!\n\n");
401 else if(((Message
[4]>>8)&0x3f)==0x2){// Annex B
403 if ( (mode
== MODE_992_1A
) || (mode
== MODE_992_3A
) || (mode
== MODE_992_5A
)\
404 // changed by xu bingtao 09/01/2007
406 || (mode == MODE_992_3I) || (mode == MODE_992_3J) ||(mode == MODE_992_3M)\
407 || (mode == MODE_992_5I) || (mode == MODE_992_5J) || (mode == MODE_992_5M))
409 || (mode
== MODE_992_3I
) ||(mode
== MODE_992_3M
)\
410 || (mode
== MODE_992_5I
) || (mode
== MODE_992_5M
))
411 // changed by xu bingtao 09/01/2007
412 { printf("\n\nWrong Argument, Annex B is running!\n\n");
417 printf("\n\n Firmware Neither Annex A nor B\n\n");
422 system("echo \"0\" > /tmp/adsl_status");
424 makeCMV(H2D_CMV_READ
, INFO
, 55, 0, 1, &temp
, Message
);
425 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
426 printf("\n\n read INFO 55 0 fail");
430 rt_buildcode_lsw
= Message
[4];
432 makeCMV(H2D_CMV_READ
, INFO
, 55, 1, 1, &temp
, Message
);
433 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
434 printf("\n\n read INFO 55 1 fail");
437 rt_buildcode_msw
= Message
[4];
439 rt_buildcode
= rt_buildcode_lsw
+ (rt_buildcode_msw
<< 16);
440 printf("date: %d, month: %d, hour: %d, minute: %d\n",
441 (rt_buildcode
>> 0) & 0xFF,
442 (rt_buildcode
>> 8) & 0xFF,
443 (rt_buildcode
>> 16) & 0xFF,
444 (rt_buildcode
>> 25) & 0xFF
448 makeCMV(H2D_CMV_WRITE
, OPTN
, 0, 0, 1, &zero
, Message
);
449 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
450 printf("\n\n write OPTN 0 0 fail");
453 if (mode
== MODE_992_1A
)
454 { makeCMV(H2D_CMV_READ
, OPTN
, 0, 0, 1, &temp
, Message
);
455 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
456 printf("\n\n read OPTN 0 0 fail");
461 makeCMV(H2D_CMV_WRITE
, OPTN
, 0, 0, 1, &temp
, Message
);
462 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
463 printf("\n\n write OPTN 0 0 fail");
467 else if (mode
== MODE_992_3A
)
468 { makeCMV(H2D_CMV_READ
, OPTN
, 0, 0, 1, &temp
, Message
);
469 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
470 printf("\n\n read OPTN 0 0 fail");
475 makeCMV(H2D_CMV_WRITE
, OPTN
, 0, 0, 1, &temp
, Message
);
476 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
477 printf("\n\n write OPTN 0 0 fail");
481 else if (mode
== MODE_992_5A
)
482 { makeCMV(H2D_CMV_READ
, OPTN
, 0, 0, 1, &temp
, Message
);
483 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
484 printf("\n\n read OPTN 0 0 fail");
489 makeCMV(H2D_CMV_WRITE
, OPTN
, 0, 0, 1, &temp
, Message
);
490 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
491 printf("\n\n write OPTN 0 0 fail");
495 else if (mode
== MODE_992_1B
)
496 { makeCMV(H2D_CMV_READ
, OPTN
, 0, 0, 1, &temp
, Message
);
497 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
498 printf("\n\n read OPTN 0 0 fail");
503 makeCMV(H2D_CMV_WRITE
, OPTN
, 0, 0, 1, &temp
, Message
);
504 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
505 printf("\n\n write OPTN 0 0 fail");
509 else if (mode
== MODE_992_3B
)
510 { makeCMV(H2D_CMV_READ
, OPTN
, 0, 0, 1, &temp
, Message
);
511 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
512 printf("\n\n read OPTN 0 0 fail");
517 makeCMV(H2D_CMV_WRITE
, OPTN
, 0, 0, 1, &temp
, Message
);
518 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
519 printf("\n\n write OPTN 0 0 fail");
523 else if (mode
== MODE_992_5B
)
524 { makeCMV(H2D_CMV_READ
, OPTN
, 0, 0, 1, &temp
, Message
);
525 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
526 printf("\n\n read OPTN 0 0 fail");
531 makeCMV(H2D_CMV_WRITE
, OPTN
, 0, 0, 1, &temp
, Message
);
532 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
533 printf("\n\n write OPTN 0 0 fail");
538 else if (mode
== MODE_992_3I
)
539 { makeCMV(H2D_CMV_READ
, OPTN
, 0, 0, 1, &temp
, Message
);
540 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
541 printf("\n\n read OPTN 0 0 fail");
546 makeCMV(H2D_CMV_WRITE
, OPTN
, 0, 0, 1, &temp
, Message
);
547 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
548 printf("\n\n write OPTN 0 0 fail");
552 else if (mode
== MODE_992_3J
)
553 { makeCMV(H2D_CMV_READ
, OPTN
, 0, 0, 1, &temp
, Message
);
554 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
555 printf("\n\n read OPTN 0 0 fail");
560 makeCMV(H2D_CMV_WRITE
, OPTN
, 0, 0, 1, &temp
, Message
);
561 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
562 printf("\n\n write OPTN 0 0 fail");
566 else if (mode
== MODE_992_3M
)
567 { makeCMV(H2D_CMV_READ
, OPTN
, 0, 0, 1, &temp
, Message
);
568 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
569 printf("\n\n read OPTN 0 0 fail");
574 makeCMV(H2D_CMV_WRITE
, OPTN
, 0, 0, 1, &temp
, Message
);
575 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
576 printf("\n\n write OPTN 0 0 fail");
580 else if (mode
== MODE_992_5I
)
581 { makeCMV(H2D_CMV_READ
, OPTN
, 7, 0, 1, &temp
, Message
);
582 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
583 printf("\n\n read OPTN 7 0 fail");
588 makeCMV(H2D_CMV_WRITE
, OPTN
, 7, 0, 1, &temp
, Message
);
589 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
590 printf("\n\n write OPTN 7 0 fail");
594 else if (mode
== MODE_992_5J
)
595 { makeCMV(H2D_CMV_READ
, OPTN
, 7, 0, 1, &temp
, Message
);
596 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
597 printf("\n\n read OPTN 7 0 fail");
602 makeCMV(H2D_CMV_WRITE
, OPTN
, 7, 0, 1, &temp
, Message
);
603 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
604 printf("\n\n write OPTN 7 0 fail");
608 else if (mode
== MODE_992_5M
)
609 { makeCMV(H2D_CMV_READ
, OPTN
, 7, 0, 1, &temp
, Message
);
610 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
611 printf("\n\n read OPTN 7 0 fail");
616 makeCMV(H2D_CMV_WRITE
, OPTN
, 7, 0, 1, &temp
, Message
);
617 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
618 printf("\n\n write OPTN 7 0 fail");
622 else if (mode
== MODE_M_ALL
){
623 makeCMV(H2D_CMV_READ
, OPTN
, 0, 0, 1, &temp
, Message
);
624 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
625 printf("\n\n read OPTN 0 0 fail");
630 makeCMV(H2D_CMV_WRITE
, OPTN
, 0, 0, 1, &temp
, Message
);
631 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
632 printf("\n\n write OPTN 0 0 fail");
636 makeCMV(H2D_CMV_READ
, OPTN
, 7, 0, 1, &temp
, Message
);
637 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
638 printf("\n\n read OPTN 7 0 fail");
643 makeCMV(H2D_CMV_WRITE
, OPTN
, 7, 0, 1, &temp
, Message
);
644 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
645 printf("\n\n write OPTN 7 0 fail");
649 else if (mode
== MODE_B_ALL
){
650 makeCMV(H2D_CMV_READ
, OPTN
, 0, 0, 1, &temp
, Message
);
651 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
652 printf("\n\n read OPTN 0 0 fail");
657 makeCMV(H2D_CMV_WRITE
, OPTN
, 0, 0, 1, &temp
, Message
);
658 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
659 printf("\n\n write OPTN 0 0 fail");
662 }else if (mode
== MODE_M_B_ALL
){
663 makeCMV(H2D_CMV_READ
, OPTN
, 0, 0, 1, &temp
, Message
);
664 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
665 printf("\n\n read OPTN 0 0 fail");
670 makeCMV(H2D_CMV_WRITE
, OPTN
, 0, 0, 1, &temp
, Message
);
671 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
672 printf("\n\n write OPTN 0 0 fail");
676 else if (mode
== MODE_ALL
)
677 { makeCMV(H2D_CMV_READ
, OPTN
, 0, 0, 1, &temp
, Message
);
678 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
679 printf("\n\n read OPTN 0 0 fail");
684 temp
|= 2; //609181:tc.chen support G.lite
686 makeCMV(H2D_CMV_WRITE
, OPTN
, 0, 0, 1, &temp
, Message
);
687 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
688 printf("\n\n write OPTN 0 0 fail");
693 if(ioctl(fd
, GET_ADSL_LOOP_DIAGNOSTICS_MODE
, &j
)<0){
694 printf("\n\n ioctl GET_ADSL_LOOP_DIAGNOSTICS_MODE fail");
697 if (j
== 1) // LOOP DIAGNOSTICS enabled
699 makeCMV(H2D_CMV_READ
, OPTN
, 9, 0, 1, &temp
, Message
);
700 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
701 printf("\n\n read OPTN 9 0 fail");
707 makeCMV(H2D_CMV_WRITE
, OPTN
, 9, 0, 1, &temp
, Message
);
708 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
709 printf("\n\n write OPTN 9 0 fail");
714 /************ remove in future ***********/
716 if(argc
==4){ //execute script file
717 strncpy(systemstr
, "./translate -ef ",16);
718 strcpy(systemstr
+16, argv
[3]);
723 if (mode
== MODE_992_1A
)
727 makeCMV(H2D_CMV_WRITE
, OPTN
, 1, 0, 1, &temp
, Message
);
728 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
729 printf("\n\n write OPTN 1 0 fail");
733 makeCMV(H2D_CMV_WRITE
, OPTN
, 2, 0, 1, &temp
, Message
);
734 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
735 printf("\n\n write OPTN 2 0 fail");
740 makeCMV(H2D_CMV_WRITE
, CNTL
, 0, 0, 1, &link
, Message
);
741 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
742 printf("\n\n set CNTL 0 0 fail");
746 FarEndResponseReceived
=0;
751 int tmpQuietModeEnabled
;
752 tmpQuietModeEnabled
= 0;
753 if(ioctl(fd
, QUIET_MODE_GET
, &tmpQuietModeEnabled
)<0){
754 printf("\n\n ioctl QUIET_MODE_GET fail");
757 #if 0 // 611101:tc.chen : change to use ioctl QUIET_MODE_GET
758 makeCMV(H2D_CMV_READ
, INFO
, 94, 0, 1, &temp
, Message
);
759 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
760 printf("\n\n INFO 94 0 read fail");
763 if( Message
[4] == 0x0 )
764 tmpQuietModeEnabled
= 1;
766 // check if loop diagnostic mode is changed
767 if(ioctl(fd
, GET_ADSL_LOOP_DIAGNOSTICS_MODE
, &loop_diagnostics_mode
)<0)
769 printf("\n\n ioctl GET_ADSL_LOOP_DIAGNOSTICS_MODE fail");
772 if (loop_diagnostics_mode
!= pre_loop_diagnostics_mode
)
774 pre_loop_diagnostics_mode
= loop_diagnostics_mode
;
778 makeCMV(H2D_CMV_READ
, STAT
, 0, 0, 1, &rt_macrostate
, Message
);
779 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
780 printf("\n\n STAT read fail");
786 if( tmpQuietModeEnabled
== 0 )
790 if((FarEndResponseReceived
==0) && ((Message
[4]==5) || (Message
[4]==6))){
791 FarEndResponseReceived
=1;
798 if(FarEndResponseReceived
==0){
799 FarEndResponseReceived
=1;
805 if( tmpQuietModeEnabled
== 0 ){
815 if(time((time_t *)0)-start_time
> timeout_limit
){
816 if( tmpQuietModeEnabled
== 0 )
824 if (Message
[4] == 3) // Done with loop diagnostics
826 ioctl(fd
,LOOP_DIAGNOSTIC_MODE_COMPLETE
,NULL
);
829 if(ioctl(fd
, GET_ADSL_LOOP_DIAGNOSTICS_MODE
, &loop_diagnostics_mode
)<0)
831 printf("\n\n ioctl GET_ADSL_LOOP_DIAGNOSTICS_MODE fail");
834 if (loop_diagnostics_mode
== 0)
836 pre_loop_diagnostics_mode
= loop_diagnostics_mode
;
843 printf("\n\n Keep trying to reboot!");
850 while(reboot_flag
==0){
851 if(ioctl(fd
, GET_ADSL_LOOP_DIAGNOSTICS_MODE
, &loop_diagnostics_mode
)<0)
853 printf("\n\n ioctl GET_ADSL_LOOP_DIAGNOSTICS_MODE fail");
856 if (loop_diagnostics_mode
!= pre_loop_diagnostics_mode
)
858 pre_loop_diagnostics_mode
= loop_diagnostics_mode
;
862 makeCMV(H2D_CMV_READ
, PLAM
, 0, 0, 1, &rt_ne_failure_flags
, Message
);
863 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
864 printf("\n\n PLAM 0 0 read fail");
868 rt_ne_failure_flags
= Message
[4];
869 rt_ne_los_flag
=rt_ne_failure_flags
& 0x1;
873 ioctl(fd
, IFXMIPS_MIB_LO_ATUC
, (u32
*)rt_ne_failure_flags
);
874 makeCMV(H2D_CMV_READ
, PLAM
, 1, 0, 1, &temp
, Message
);
876 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
877 printf("\n\n PLAM 1 0 read fail");
881 ioctl(fd
, IFXMIPS_MIB_LO_ATUR
, (u32
*)Message
[4]);
886 makeCMV(H2D_CMV_READ
, PLAM
, 46, 0, 1, &rt_ne_ds_margin
, Message
);
888 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
889 printf("\n\n PLAM 46 0 read fail");
893 rt_ne_ds_margin
= (s16
)Message
[4];
895 if(ioctl(fd
, SHOWTIME_LOCK_GET
, &tmpShowTimeLockEnabled
)<0){
896 printf("\n\n ioctl SHOWTIME_LOCK_GET fail!");
899 #if 0 //611101:tc.chen change to ioctl SHOWTIME_LOCK
900 makeCMV(H2D_CMV_READ
, TEST
, 29, 0, 1, &temp
, Message
);
901 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
902 printf("\n\n TEST 29 0 read fail");
905 if( Message
[4] == 0xffff )
906 tmpShowTimeLockEnabled
= 1;
908 /* rt_ne_ds_margin is SNR *2 */
909 if((rt_ne_los_flag
!=0)|| ( rt_ne_ds_margin
<(rt_ne_ds_min_margin
* 2))){
910 if(tmpShowTimeLockEnabled
== 1) {
911 // changed by xu bingtao 09/01/2007
913 printf("NE_LOS or NE_DS_MARGIN detected but no rebooting because of the showtime lock\n");
915 printf("NE_LOS or NE_DS_MARGIN detected but no rebooting because of the showtime lock\n");
916 printf(" Minimum Margin: %d/2 dB - Expected Margin: %d dB - LOS : %d\n",rt_ne_ds_margin
, rt_ne_ds_min_margin
, rt_ne_los_flag
);
917 // changed by xu bingtao 09/01/2007
925 if(j
<3){//wait for several seconds before setting showtime
926 makeCMV(H2D_CMV_READ
, STAT
, 4, 0, 1, &temp
, Message
);
927 if(ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
)<0){
928 printf("\n\n STAT 4 0 read fail");
931 if((Message
[4]&0x2)==0x2){
932 printf("\n\n setting showtime to driver\n\n");
933 system("/etc/rc.d/adsl_up &"); //000001:tc.chen
934 system("echo \"7\" > /tmp/adsl_status");
935 printf("ADSL SHOWTIME!!\n");
939 if (!first_power_on
){
941 makeCMV(H2D_CMV_WRITE
,PLAM
, 6, 0, 1, &nFECS_L_count
, Message
);
942 ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
);
944 makeCMV(H2D_CMV_WRITE
,PLAM
, 7, 0, 1, &nES_L_count
, Message
);
945 ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
);
948 makeCMV(H2D_CMV_WRITE
,PLAM
, 8, 0, 1, &nSES_L_count
, Message
);
949 ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
);
952 makeCMV(H2D_CMV_WRITE
,PLAM
, 9, 0, 1, &nLOSS_L_count
, Message
);
953 ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
);
956 ioctl(fd
, IFXMIPS_MEI_SHOWTIME
,NULL
); //set showtime=1 in driver
957 // 609141:tc.chen :read min margin from CO for Annex B in DMT mode
958 // read adsl link mode
959 read_min_snr_margin(fd
, &rt_ne_ds_min_margin
);
963 if(j
==3){//timeout, set showtimei
964 printf("\n\n timeout, setting showtime to driver\n\n");
965 //system("echo \"7\" > /tmp/adsl_status");
966 printf("ADSL SHOWTIME!!\n");
968 ioctl(fd
, IFXMIPS_MEI_SHOWTIME
,NULL
); //set showtime=1 in driver
969 // 609141:tc.chen :read min margin from CO for Annex B in DMT mode
970 // read adsl link mode
971 read_min_snr_margin( fd
, &rt_ne_ds_min_margin
);
978 makeCMV(H2D_CMV_READ
,PLAM
, 6, 0, 1, &temp
, Message
);
979 ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
);
980 nFECS_L_count
=nFECS_L_count
+Message
[4];
982 makeCMV(H2D_CMV_READ
,PLAM
, 7, 0, 1, &temp
, Message
);
983 ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
);
984 nES_L_count
=nES_L_count
+Message
[4];
986 makeCMV(H2D_CMV_READ
,PLAM
, 8, 0, 1, &temp
, Message
);
987 ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
);
988 nSES_L_count
=nSES_L_count
+Message
[4];
990 makeCMV(H2D_CMV_READ
,PLAM
, 9, 0, 1, &temp
, Message
);
991 ioctl(fd
, IFXMIPS_MEI_CMV_WINHOST
, &Message
);
992 nLOSS_L_count
=nLOSS_L_count
+Message
[4];
996 system("echo \"0\" > /tmp/adsl_status");
997 printf("\n Rebooting ARC\n");
999 ioctl(fd
, IFXMIPS_MEI_REBOOT
,NULL
);
1000 Download_Firmware(argv
[1],fd
);
1001 if (ioctl(fd
, IFXMIPS_MEI_START
,NULL
)<0){
1002 printf("\n\n mei start fail.\n");
1007 #if !defined(KERNEL_SPACE_APPLICATION)