xref: /openbmc/u-boot/cmd/aspeed/nettest/ncsi.c (revision d82a9689b6a3d8e7d1058971a7057844ca07fe4a)
1*d82a9689SDylan Hung // SPDX-License-Identifier: GPL-2.0+
25c8f9400Sryan_chen /*
3*d82a9689SDylan Hung  * Copyright (C) ASPEED Technology Inc.
45c8f9400Sryan_chen  */
55c8f9400Sryan_chen 
65c8f9400Sryan_chen #define NCSI_C
75c8f9400Sryan_chen 
85c8f9400Sryan_chen #include "swfunc.h"
95c8f9400Sryan_chen 
105c8f9400Sryan_chen #include "comminf.h"
115c8f9400Sryan_chen //#include "io.h"
125c8f9400Sryan_chen #include "ncsi.h"
135c8f9400Sryan_chen #include <command.h>
145c8f9400Sryan_chen #include <common.h>
155c8f9400Sryan_chen #include "mac_api.h"
165c8f9400Sryan_chen 
175c8f9400Sryan_chen //------------------------------------------------------------
ncsi_set_error_flag(MAC_ENGINE * eng,int eflag)18783c0c9bSDylan Hung int ncsi_set_error_flag(MAC_ENGINE *eng, int eflag)
19783c0c9bSDylan Hung {
20783c0c9bSDylan Hung 	eng->flg.ncsi = eng->flg.ncsi | eflag;
21783c0c9bSDylan Hung 	eng->flg.error = eng->flg.error | ERR_FLAG_NCSI_LINKFAIL;
22783c0c9bSDylan Hung 	if (DBG_PRINT_ERR_FLAG)
23783c0c9bSDylan Hung 		printf("\nflags: error = %08x, ncsi = %08x\n",
24783c0c9bSDylan Hung 		       eng->flg.error, eng->flg.ncsi);
255c8f9400Sryan_chen 
265c8f9400Sryan_chen 	return (1);
275c8f9400Sryan_chen }
285c8f9400Sryan_chen 
295c8f9400Sryan_chen //------------------------------------------------------------
305c8f9400Sryan_chen // PHY IC(NC-SI)
315c8f9400Sryan_chen //------------------------------------------------------------
ncsi_reqdump(MAC_ENGINE * eng,NCSI_Command_Packet * in)32783c0c9bSDylan Hung void ncsi_reqdump(MAC_ENGINE *eng, NCSI_Command_Packet *in)
33783c0c9bSDylan Hung {
345c8f9400Sryan_chen 	int     i;
355c8f9400Sryan_chen 	PRINTF( FP_LOG, "[NCSI-Request] DA             : %02x %02x %02x %02x %02x %02x\n", in->DA[ 0 ], in->DA[ 1 ], in->DA[ 2 ], in->DA[ 3 ], in->DA[ 4 ] , in->DA[ 5 ]);
365c8f9400Sryan_chen 	PRINTF( FP_LOG, "[NCSI-Request] SA             : %02x %02x %02x %02x %02x %02x\n", in->SA[ 0 ], in->SA[ 1 ], in->SA[ 2 ], in->SA[ 3 ], in->SA[ 4 ] , in->SA[ 5 ]);
375c8f9400Sryan_chen 	PRINTF( FP_LOG, "[NCSI-Request] EtherType      : %04x\n", SWAP_2B_BEDN( in->EtherType )             );//DMTF NC-SI
385c8f9400Sryan_chen 	PRINTF( FP_LOG, "[NCSI-Request] MC_ID          : %02x\n", in->MC_ID                                 );//Management Controller should set this field to 0x00
395c8f9400Sryan_chen 	PRINTF( FP_LOG, "[NCSI-Request] Header_Revision: %02x\n", in->Header_Revision                       );//For NC-SI 1.0 spec, this field has to set 0x01
405c8f9400Sryan_chen //	PRINTF( FP_LOG, "[NCSI-Request] Reserved_1     : %02x\n", in->Reserved_1                            ); //Reserved has to set to 0x00
415c8f9400Sryan_chen 	PRINTF( FP_LOG, "[NCSI-Request] IID            : %02x\n", in->IID                                   );//Instance ID
425c8f9400Sryan_chen 	PRINTF( FP_LOG, "[NCSI-Request] Command        : %02x\n", in->Command                               );
435c8f9400Sryan_chen 	PRINTF( FP_LOG, "[NCSI-Request] ChID           : %02x\n", in->ChID                                  );
445c8f9400Sryan_chen 	PRINTF( FP_LOG, "[NCSI-Request] Payload_Length : %04x\n", SWAP_2B_BEDN( in->Payload_Length )        );//Payload Length = 12 bits, 4 bits are reserved
455c8f9400Sryan_chen //	PRINTF( FP_LOG, "[NCSI-Request] Reserved_2     : %04x\n", in->Reserved_2                            );
465c8f9400Sryan_chen //	PRINTF( FP_LOG, "[NCSI-Request] Reserved_3     : %04x\n", in->Reserved_3                            );
475c8f9400Sryan_chen //	PRINTF( FP_LOG, "[NCSI-Request] Reserved_4     : %04x\n", in->Reserved_4                            );
485c8f9400Sryan_chen //	PRINTF( FP_LOG, "[NCSI-Request] Reserved_5     : %04x\n", in->Reserved_5                            );
495c8f9400Sryan_chen 	PRINTF( FP_LOG, "[NCSI-Request] Response_Code  : %04x\n", SWAP_2B_BEDN( in->Response_Code )         );
505c8f9400Sryan_chen 	PRINTF( FP_LOG, "[NCSI-Request] Reason_Code    : %04x\n", SWAP_2B_BEDN( in->Reason_Code )           );
515c8f9400Sryan_chen 	for ( i = 0; i < SWAP_2B_BEDN( in->Payload_Length ); i++ ) {
525c8f9400Sryan_chen 		switch ( i % 4 ) {
535c8f9400Sryan_chen 			case 0	: PRINTF( FP_LOG, "[NCSI-Request] Payload_Data   : %02x", in->Payload_Data[ i ]); break;
545c8f9400Sryan_chen 			case 3	: PRINTF( FP_LOG, " %02x\n", in->Payload_Data[ i ]); break;
555c8f9400Sryan_chen 			default	: PRINTF( FP_LOG, " %02x", in->Payload_Data[ i ]); break;
565c8f9400Sryan_chen 		}
575c8f9400Sryan_chen 	}
585c8f9400Sryan_chen 	if ( ( i % 4 ) != 3 )
595c8f9400Sryan_chen 		PRINTF( FP_LOG, "\n");
605c8f9400Sryan_chen }
ncsi_respdump(MAC_ENGINE * eng,NCSI_Response_Packet * in)615c8f9400Sryan_chen void ncsi_respdump (MAC_ENGINE *eng, NCSI_Response_Packet *in) {
625c8f9400Sryan_chen 	int     i;
635c8f9400Sryan_chen //	PRINTF( FP_LOG, "[NCSI-Respond] DA             : %02x %02x %02x %02x %02x %02x\n", in->DA[ 5 ], in->DA[ 4 ], in->DA[ 3 ], in->DA[ 2 ], in->DA[ 1] , in->DA[ 0 ]);
645c8f9400Sryan_chen //	PRINTF( FP_LOG, "[NCSI-Respond] SA             : %02x %02x %02x %02x %02x %02x\n", in->SA[ 5 ], in->SA[ 4 ], in->SA[ 3 ], in->SA[ 2 ], in->SA[ 1] , in->SA[ 0 ]);
655c8f9400Sryan_chen 	PRINTF( FP_LOG, "[NCSI-Respond] DA             : %02x %02x %02x %02x %02x %02x\n", in->DA[ 0 ], in->DA[ 1 ], in->DA[ 2 ], in->DA[ 3 ], in->DA[ 4 ] , in->DA[ 5 ]);
665c8f9400Sryan_chen 	PRINTF( FP_LOG, "[NCSI-Respond] SA             : %02x %02x %02x %02x %02x %02x\n", in->SA[ 0 ], in->SA[ 1 ], in->SA[ 2 ], in->SA[ 3 ], in->SA[ 4 ] , in->SA[ 5 ]);
675c8f9400Sryan_chen 	PRINTF( FP_LOG, "[NCSI-Respond] EtherType      : %04x\n", SWAP_2B_BEDN( in->EtherType )             );//DMTF NC-SI
685c8f9400Sryan_chen 	PRINTF( FP_LOG, "[NCSI-Respond] MC_ID          : %02x\n", in->MC_ID                                 );//Management Controller should set this field to 0x00
695c8f9400Sryan_chen 	PRINTF( FP_LOG, "[NCSI-Respond] Header_Revision: %02x\n", in->Header_Revision                       );//For NC-SI 1.0 spec, this field has to set 0x01
705c8f9400Sryan_chen //	PRINTF( FP_LOG, "[NCSI-Respond] Reserved_1     : %02x\n", in->Reserved_1                            ); //Reserved has to set to 0x00
715c8f9400Sryan_chen 	PRINTF( FP_LOG, "[NCSI-Respond] IID            : %02x\n", in->IID                                   );//Instance ID
725c8f9400Sryan_chen 	PRINTF( FP_LOG, "[NCSI-Respond] Command        : %02x\n", in->Command                               );
735c8f9400Sryan_chen 	PRINTF( FP_LOG, "[NCSI-Respond] ChID           : %02x\n", in->ChID                                  );
745c8f9400Sryan_chen 	PRINTF( FP_LOG, "[NCSI-Respond] Payload_Length : %04x\n", SWAP_2B_BEDN( in->Payload_Length )        );//Payload Length = 12 bits, 4 bits are reserved
755c8f9400Sryan_chen //	PRINTF( FP_LOG, "[NCSI-Respond] Reserved_2     : %04x\n", in->Reserved_2                            );
765c8f9400Sryan_chen //	PRINTF( FP_LOG, "[NCSI-Respond] Reserved_3     : %04x\n", in->Reserved_3                            );
775c8f9400Sryan_chen //	PRINTF( FP_LOG, "[NCSI-Respond] Reserved_4     : %04x\n", in->Reserved_4                            );
785c8f9400Sryan_chen //	PRINTF( FP_LOG, "[NCSI-Respond] Reserved_5     : %04x\n", in->Reserved_5                            );
795c8f9400Sryan_chen 	PRINTF( FP_LOG, "[NCSI-Respond] Response_Code  : %04x\n", SWAP_2B_BEDN( in->Response_Code )         );
805c8f9400Sryan_chen 	PRINTF( FP_LOG, "[NCSI-Respond] Reason_Code    : %04x\n", SWAP_2B_BEDN( in->Reason_Code )           );
815c8f9400Sryan_chen 	for ( i = 0; i < SWAP_2B_BEDN( in->Payload_Length ); i++ ) {
825c8f9400Sryan_chen 		switch ( i % 4 ) {
835c8f9400Sryan_chen 			case 0	: PRINTF( FP_LOG, "[NCSI-Respond] Payload_Data   : %02x", in->Payload_Data[ i ]); break;
845c8f9400Sryan_chen 			case 3	: PRINTF( FP_LOG, " %02x\n", in->Payload_Data[ i ]); break;
855c8f9400Sryan_chen 			default	: PRINTF( FP_LOG, " %02x", in->Payload_Data[ i ]); break;
865c8f9400Sryan_chen 		}
875c8f9400Sryan_chen 	}
885c8f9400Sryan_chen 	if ( ( i % 4 ) != 3 )
895c8f9400Sryan_chen 		PRINTF( FP_LOG, "\n");
905c8f9400Sryan_chen }
915c8f9400Sryan_chen 
925c8f9400Sryan_chen //------------------------------------------------------------
NCSI_PrintCommandStr(MAC_ENGINE * eng,unsigned char command,unsigned iid)935c8f9400Sryan_chen void NCSI_PrintCommandStr (MAC_ENGINE *eng, unsigned char command, unsigned iid) {
945c8f9400Sryan_chen 	switch ( command & 0x80 ) {
955c8f9400Sryan_chen 		case 0x80   : sprintf(eng->dat.NCSI_CommandStr, "IID:%3d [%02x:Respond]", iid, command); break;
965c8f9400Sryan_chen 		default     : sprintf(eng->dat.NCSI_CommandStr, "IID:%3d [%02x:Request]", iid, command); break;
975c8f9400Sryan_chen 	}
985c8f9400Sryan_chen 	switch ( command & 0x7f ) {
995c8f9400Sryan_chen 		case 0x00   : sprintf(eng->dat.NCSI_CommandStr, "%s[CLEAR_INITIAL_STATE                ]", eng->dat.NCSI_CommandStr); break;
1005c8f9400Sryan_chen 		case 0x01   : sprintf(eng->dat.NCSI_CommandStr, "%s[SELECT_PACKAGE                     ]", eng->dat.NCSI_CommandStr); break;
1015c8f9400Sryan_chen 		case 0x02   : sprintf(eng->dat.NCSI_CommandStr, "%s[DESELECT_PACKAGE                   ]", eng->dat.NCSI_CommandStr); break;
1025c8f9400Sryan_chen 		case 0x03   : sprintf(eng->dat.NCSI_CommandStr, "%s[ENABLE_CHANNEL                     ]", eng->dat.NCSI_CommandStr); break;
1035c8f9400Sryan_chen 		case 0x04   : sprintf(eng->dat.NCSI_CommandStr, "%s[DISABLE_CHANNEL                    ]", eng->dat.NCSI_CommandStr); break;
1045c8f9400Sryan_chen 		case 0x05   : sprintf(eng->dat.NCSI_CommandStr, "%s[RESET_CHANNEL                      ]", eng->dat.NCSI_CommandStr); break;
1055c8f9400Sryan_chen 		case 0x06   : sprintf(eng->dat.NCSI_CommandStr, "%s[ENABLE_CHANNEL_NETWORK_TX          ]", eng->dat.NCSI_CommandStr); break;
1065c8f9400Sryan_chen 		case 0x07   : sprintf(eng->dat.NCSI_CommandStr, "%s[DISABLE_CHANNEL_NETWORK_TX         ]", eng->dat.NCSI_CommandStr); break;
1075c8f9400Sryan_chen 		case 0x08   : sprintf(eng->dat.NCSI_CommandStr, "%s[AEN_ENABLE                         ]", eng->dat.NCSI_CommandStr); break;
1085c8f9400Sryan_chen 		case 0x09   : sprintf(eng->dat.NCSI_CommandStr, "%s[SET_LINK                           ]", eng->dat.NCSI_CommandStr); break;
1095c8f9400Sryan_chen 		case 0x0A   : sprintf(eng->dat.NCSI_CommandStr, "%s[GET_LINK_STATUS                    ]", eng->dat.NCSI_CommandStr); break;
1105c8f9400Sryan_chen 		case 0x0B   : sprintf(eng->dat.NCSI_CommandStr, "%s[SET_VLAN_FILTER                    ]", eng->dat.NCSI_CommandStr); break;
1115c8f9400Sryan_chen 		case 0x0C   : sprintf(eng->dat.NCSI_CommandStr, "%s[ENABLE_VLAN                        ]", eng->dat.NCSI_CommandStr); break;
1125c8f9400Sryan_chen 		case 0x0D   : sprintf(eng->dat.NCSI_CommandStr, "%s[DISABLE_VLAN                       ]", eng->dat.NCSI_CommandStr); break;
1135c8f9400Sryan_chen 		case 0x0E   : sprintf(eng->dat.NCSI_CommandStr, "%s[SET_MAC_ADDRESS                    ]", eng->dat.NCSI_CommandStr); break;
1145c8f9400Sryan_chen 		case 0x10   : sprintf(eng->dat.NCSI_CommandStr, "%s[ENABLE_BROADCAST_FILTERING         ]", eng->dat.NCSI_CommandStr); break;
1155c8f9400Sryan_chen 		case 0x11   : sprintf(eng->dat.NCSI_CommandStr, "%s[DISABLE_BROADCAST_FILTERING        ]", eng->dat.NCSI_CommandStr); break;
1165c8f9400Sryan_chen 		case 0x12   : sprintf(eng->dat.NCSI_CommandStr, "%s[ENABLE_GLOBAL_MULTICAST_FILTERING  ]", eng->dat.NCSI_CommandStr); break;
1175c8f9400Sryan_chen 		case 0x13   : sprintf(eng->dat.NCSI_CommandStr, "%s[DISABLE_GLOBAL_MULTICAST_FILTERING ]", eng->dat.NCSI_CommandStr); break;
1185c8f9400Sryan_chen 		case 0x14   : sprintf(eng->dat.NCSI_CommandStr, "%s[SET_NCSI_FLOW_CONTROL              ]", eng->dat.NCSI_CommandStr); break;
1195c8f9400Sryan_chen 		case 0x15   : sprintf(eng->dat.NCSI_CommandStr, "%s[GET_VERSION_ID                     ]", eng->dat.NCSI_CommandStr); break;
1205c8f9400Sryan_chen 		case 0x16   : sprintf(eng->dat.NCSI_CommandStr, "%s[GET_CAPABILITIES                   ]", eng->dat.NCSI_CommandStr); break;
1215c8f9400Sryan_chen 		case 0x17   : sprintf(eng->dat.NCSI_CommandStr, "%s[GET_PARAMETERS                     ]", eng->dat.NCSI_CommandStr); break;
1225c8f9400Sryan_chen 		case 0x18   : sprintf(eng->dat.NCSI_CommandStr, "%s[GET_CONTROLLER_PACKET_STATISTICS   ]", eng->dat.NCSI_CommandStr); break;
1235c8f9400Sryan_chen 		case 0x19   : sprintf(eng->dat.NCSI_CommandStr, "%s[GET_NCSI_STATISTICS                ]", eng->dat.NCSI_CommandStr); break;
1245c8f9400Sryan_chen 		case 0x1A   : sprintf(eng->dat.NCSI_CommandStr, "%s[GET_NCSI_PASS_THROUGH_STATISTICS   ]", eng->dat.NCSI_CommandStr); break;
1255c8f9400Sryan_chen 		case 0x50   : sprintf(eng->dat.NCSI_CommandStr, "%s[OEM_COMMAND                        ]", eng->dat.NCSI_CommandStr); break;
1265c8f9400Sryan_chen 		default     : sprintf(eng->dat.NCSI_CommandStr, "%s Not Support Command", eng->dat.NCSI_CommandStr); break ;
1275c8f9400Sryan_chen 	}
1285c8f9400Sryan_chen } // End void NCSI_PrintCommandStr (MAC_ENGINE *eng, unsigned char command, unsigned iid)
1295c8f9400Sryan_chen 
1305c8f9400Sryan_chen //------------------------------------------------------------
NCSI_PrintCommandType(MAC_ENGINE * eng,unsigned char command,unsigned iid)1315c8f9400Sryan_chen void NCSI_PrintCommandType (MAC_ENGINE *eng, unsigned char command, unsigned iid) {
1325c8f9400Sryan_chen 	NCSI_PrintCommandStr( eng, command, iid );
1335c8f9400Sryan_chen 	printf("[NCSI-commd]%s\n", eng->dat.NCSI_CommandStr);
1345c8f9400Sryan_chen }
1355c8f9400Sryan_chen 
1365c8f9400Sryan_chen //------------------------------------------------------------
NCSI_PrintCommandType2File(MAC_ENGINE * eng,unsigned char command,unsigned iid)1375c8f9400Sryan_chen void NCSI_PrintCommandType2File (MAC_ENGINE *eng, unsigned char command, unsigned iid) {
1385c8f9400Sryan_chen 	NCSI_PrintCommandStr( eng, command, iid );
1395c8f9400Sryan_chen 	PRINTF( FP_LOG, "[NCSI-commd]%s\n", eng->dat.NCSI_CommandStr );
1405c8f9400Sryan_chen }
1415c8f9400Sryan_chen 
1425c8f9400Sryan_chen //------------------------------------------------------------
NCSI_Struct_Initialize_SLT(MAC_ENGINE * eng)1435c8f9400Sryan_chen void NCSI_Struct_Initialize_SLT (MAC_ENGINE *eng)
1445c8f9400Sryan_chen {
1455c8f9400Sryan_chen 	int i;
1465c8f9400Sryan_chen 	uint32_t NCSI_RxDatBase;
1475c8f9400Sryan_chen 
1485c8f9400Sryan_chen 	eng->run.NCSI_RxTimeOutScale = 1;
1495c8f9400Sryan_chen 
1505c8f9400Sryan_chen 	for (i = 0; i < 6; i++) {
1515c8f9400Sryan_chen 		eng->ncsi_req.DA[i] = 0xFF;
1525c8f9400Sryan_chen 		eng->ncsi_req.SA[i] = eng->inf.SA[i];
1535c8f9400Sryan_chen 	}
1545c8f9400Sryan_chen 
1555c8f9400Sryan_chen 	/* EtherType = 0x88F8 (DMTF DSP0222 NC-SI spec)
1565c8f9400Sryan_chen 	ethernet frame header format, table 8 */
1575c8f9400Sryan_chen 	eng->ncsi_req.EtherType = SWAP_2B_BEDN(0x88F8);
1585c8f9400Sryan_chen 
1595c8f9400Sryan_chen 	eng->ncsi_req.MC_ID           = 0;
1605c8f9400Sryan_chen 	eng->ncsi_req.Header_Revision = 0x01;
1615c8f9400Sryan_chen 	eng->ncsi_req.Reserved_1      = 0;
1625c8f9400Sryan_chen 	eng->ncsi_req.IID             = 0;
1635c8f9400Sryan_chen //	eng->ncsi_req.Command         = 0;
1645c8f9400Sryan_chen //	eng->ncsi_req.ChID            = 0;
1655c8f9400Sryan_chen //	eng->ncsi_req.Payload_Length  = 0;
1665c8f9400Sryan_chen 
1675c8f9400Sryan_chen 	eng->ncsi_req.Response_Code   = 0;
1685c8f9400Sryan_chen 	eng->ncsi_req.Reason_Code     = 0;
1695c8f9400Sryan_chen 	eng->ncsi_req.Reserved_2      = 0;
1705c8f9400Sryan_chen 	eng->ncsi_req.Reserved_3      = 0;
1715c8f9400Sryan_chen 
1725c8f9400Sryan_chen 	eng->dat.NCSI_TxByteBUF = (unsigned char *) &eng->dat.NCSI_TxDWBUF[0];
1735c8f9400Sryan_chen 	eng->dat.NCSI_RxByteBUF = (unsigned char *) &eng->dat.NCSI_RxDWBUF[0];
1745c8f9400Sryan_chen 
1755c8f9400Sryan_chen 	eng->run.ncsi_tdes_base = eng->run.tdes_base;//base for read/write
1765c8f9400Sryan_chen 	Write_Mem_Des_NCSI_DD( eng->run.ncsi_tdes_base + 0x04, 0                        );
1775c8f9400Sryan_chen 	Write_Mem_Des_NCSI_DD( eng->run.ncsi_tdes_base + 0x08, 0                        );
1785c8f9400Sryan_chen 	Write_Mem_Des_NCSI_DD( eng->run.ncsi_tdes_base + 0x0C, DMA_BASE - ASPEED_DRAM_BASE);
1795c8f9400Sryan_chen 
1805c8f9400Sryan_chen 	eng->run.ncsi_rdes_base = eng->run.rdes_base;//base for read/write
1815c8f9400Sryan_chen 	NCSI_RxDatBase = AT_MEMRW_BUF( NCSI_RxDMA_BASE );//base of the descriptor
1825c8f9400Sryan_chen 
1835c8f9400Sryan_chen 	for (i = 0; i < NCSI_RxDESNum - 1; i++) {
1845c8f9400Sryan_chen 		Write_Mem_Des_NCSI_DD( ( eng->run.ncsi_rdes_base        ), 0x00000000     );
1855c8f9400Sryan_chen 		Write_Mem_Des_NCSI_DD( ( eng->run.ncsi_rdes_base + 0x04 ), 0x00000000     );
1865c8f9400Sryan_chen 		Write_Mem_Des_NCSI_DD( ( eng->run.ncsi_rdes_base + 0x08 ), 0x00000000     );
1875c8f9400Sryan_chen 		Write_Mem_Des_NCSI_DD( ( eng->run.ncsi_rdes_base + 0x0C ), NCSI_RxDatBase );
1885c8f9400Sryan_chen 		eng->run.ncsi_rdes_base += 16;
1895c8f9400Sryan_chen 		NCSI_RxDatBase += NCSI_RxDMA_PakSize;
1905c8f9400Sryan_chen 	}
1915c8f9400Sryan_chen 	Write_Mem_Des_NCSI_DD( ( eng->run.ncsi_rdes_base        ), EOR_IniVal     );
1925c8f9400Sryan_chen 	Write_Mem_Des_NCSI_DD( ( eng->run.ncsi_rdes_base + 0x04 ), 0x00000000     );
1935c8f9400Sryan_chen 	Write_Mem_Des_NCSI_DD( ( eng->run.ncsi_rdes_base + 0x08 ), 0x00000000     );
1945c8f9400Sryan_chen //	Write_Mem_Des_NCSI_DD( ( eng->run.ncsi_rdes_base + 0x0C ), (NCSI_RxDatBase + CPU_BUS_ADDR_SDRAM_OFFSET) ); // 20130730
1955c8f9400Sryan_chen 	Write_Mem_Des_NCSI_DD( ( eng->run.ncsi_rdes_base + 0x0C ), NCSI_RxDatBase ); // 20130730
1965c8f9400Sryan_chen 
1975c8f9400Sryan_chen 	eng->run.ncsi_rdes_base = eng->run.rdes_base;//base for read/write
1985c8f9400Sryan_chen }
1995c8f9400Sryan_chen 
2005c8f9400Sryan_chen //------------------------------------------------------------
Calculate_Checksum_NCSI(MAC_ENGINE * eng,unsigned char * buffer_base,int Length)2015c8f9400Sryan_chen void Calculate_Checksum_NCSI (MAC_ENGINE *eng, unsigned char *buffer_base, int Length) {
2025c8f9400Sryan_chen 	uint32_t      CheckSum = 0;
2035c8f9400Sryan_chen 	uint32_t      Data;
2045c8f9400Sryan_chen 	uint32_t      Data1;
2055c8f9400Sryan_chen 	int        i;
2065c8f9400Sryan_chen 
2075c8f9400Sryan_chen 	// Calculate checksum is from byte 14 of ethernet Haeder and Control packet header
2085c8f9400Sryan_chen 	// Page 50, NC-SI spec. ver. 1.0.0 form DMTF
2095c8f9400Sryan_chen 	for (i = 14; i < Length; i += 2 ) {
2105c8f9400Sryan_chen 		Data      = buffer_base[i];
2115c8f9400Sryan_chen 		Data1     = buffer_base[i + 1];
2125c8f9400Sryan_chen 		CheckSum += ((Data << 8) + Data1);
2135c8f9400Sryan_chen 	}
2145c8f9400Sryan_chen 	eng->dat.Payload_Checksum_NCSI = SWAP_4B_BEDN(~(CheckSum) + 1); //2's complement
2155c8f9400Sryan_chen }
2165c8f9400Sryan_chen 
2175c8f9400Sryan_chen /**
2185c8f9400Sryan_chen  * @brief	check error mask in RX descriptor
2195c8f9400Sryan_chen  * @param	rx_desc0	RX descript[0]
2205c8f9400Sryan_chen */
check_rx_desc_err(MAC_ENGINE * p_eng,uint32_t rx_desc0)2215c8f9400Sryan_chen static int check_rx_desc_err(MAC_ENGINE *p_eng, uint32_t rx_desc0)
2225c8f9400Sryan_chen {
2235c8f9400Sryan_chen 	uint8_t prefix[8] = "[RxDes]";
2245c8f9400Sryan_chen 
2255c8f9400Sryan_chen 	if (rx_desc0 & RXDES_EM_ALL) {
2265c8f9400Sryan_chen #ifdef CheckRxErr
2275c8f9400Sryan_chen 		if (rx_desc0 & RXDES_EM_RXERR) {
2285c8f9400Sryan_chen 			PRINTF(STD_OUT, "%s Error RxErr        %08x\n", prefix,
2295c8f9400Sryan_chen 			       rx_desc0);
2305c8f9400Sryan_chen 			p_eng->dat.NCSI_RxEr = 1;
2315c8f9400Sryan_chen 		}
2325c8f9400Sryan_chen #endif
2335c8f9400Sryan_chen 
2345c8f9400Sryan_chen #ifdef CheckCRC
2355c8f9400Sryan_chen 		if (rx_desc0 & RXDES_EM_CRC) {
2365c8f9400Sryan_chen 			PRINTF(STD_OUT, "%s Error CRC          %08x\n", prefix,
2375c8f9400Sryan_chen 			       rx_desc0);
2385c8f9400Sryan_chen 			FindErr_Des(p_eng, Des_Flag_CRC);
2395c8f9400Sryan_chen 		}
2405c8f9400Sryan_chen #endif
2415c8f9400Sryan_chen 
2425c8f9400Sryan_chen #ifdef CheckFTL
2435c8f9400Sryan_chen 		if (rx_desc0 & RXDES_EM_FTL) {
2445c8f9400Sryan_chen 			PRINTF(STD_OUT, "%s Error FTL          %08x\n", prefix,
2455c8f9400Sryan_chen 			       rx_desc0);
2465c8f9400Sryan_chen 			FindErr_Des(p_eng, Des_Flag_FTL);
2475c8f9400Sryan_chen 		}
2485c8f9400Sryan_chen #endif
2495c8f9400Sryan_chen 
2505c8f9400Sryan_chen #ifdef CheckRunt
2515c8f9400Sryan_chen 		if (rx_desc0 & RXDES_EM_RUNT) {
2525c8f9400Sryan_chen 			PRINTF(STD_OUT, "%s Error Runt         %08x\n", prefix,
2535c8f9400Sryan_chen 			       rx_desc0);
2545c8f9400Sryan_chen 			FindErr_Des(p_eng, Des_Flag_Runt);
2555c8f9400Sryan_chen 		}
2565c8f9400Sryan_chen #endif
2575c8f9400Sryan_chen 
2585c8f9400Sryan_chen #ifdef CheckOddNibble
2595c8f9400Sryan_chen 		if (rx_desc0 & RXDES_EM_ODD_NB) {
2605c8f9400Sryan_chen 			PRINTF(STD_OUT, "%s Odd Nibble         %08x\n", prefix,
2615c8f9400Sryan_chen 			       rx_desc0);
2625c8f9400Sryan_chen 			FindErr_Des(p_eng, Des_Flag_OddNibble);
2635c8f9400Sryan_chen 		}
2645c8f9400Sryan_chen #endif
2655c8f9400Sryan_chen 
2665c8f9400Sryan_chen #ifdef CheckRxFIFOFull
2675c8f9400Sryan_chen 		if (rx_desc0 & RXDES_EM_FIFO_FULL) {
2685c8f9400Sryan_chen 			PRINTF(STD_OUT, "%s Error Rx FIFO Full %08x\n", prefix,
2695c8f9400Sryan_chen 			       rx_desc0);
2705c8f9400Sryan_chen 			FindErr_Des(p_eng, Des_Flag_RxFIFOFull);
2715c8f9400Sryan_chen 		}
2725c8f9400Sryan_chen #endif
2735c8f9400Sryan_chen 	}
2745c8f9400Sryan_chen 
2755c8f9400Sryan_chen 	return 0;
2765c8f9400Sryan_chen }
2775c8f9400Sryan_chen 
2785c8f9400Sryan_chen //------------------------------------------------------------
2795c8f9400Sryan_chen // return 0: it is PASS
2805c8f9400Sryan_chen // return 1: it is FAIL
2815c8f9400Sryan_chen //------------------------------------------------------------
NCSI_Rx_SLT(MAC_ENGINE * eng)2825c8f9400Sryan_chen char NCSI_Rx_SLT (MAC_ENGINE *eng) {
2835c8f9400Sryan_chen 	int        timeout = 0;
2845c8f9400Sryan_chen 	int        bytesize;
2855c8f9400Sryan_chen 	int        dwsize;
2865c8f9400Sryan_chen 	int        i;
2875c8f9400Sryan_chen 	int        retry   = 0;
2885c8f9400Sryan_chen 	char       ret     = 1;
2895c8f9400Sryan_chen 
2905c8f9400Sryan_chen 	uint32_t      NCSI_RxDatBase;
2915c8f9400Sryan_chen 	uint32_t      NCSI_RxDesDat;
2925c8f9400Sryan_chen 	uint32_t      NCSI_RxData;
2935c8f9400Sryan_chen 	uint32_t      NCSI_BufData;
2945c8f9400Sryan_chen 
2955c8f9400Sryan_chen 	do {
2965c8f9400Sryan_chen 		mac_reg_write( eng, 0x1C, 0x00000000 );//Rx Poll
2975c8f9400Sryan_chen 
2985c8f9400Sryan_chen 		timeout = 0;
2995c8f9400Sryan_chen 		do {
3005c8f9400Sryan_chen 			NCSI_RxDesDat = Read_Mem_Des_NCSI_DD( eng->run.ncsi_rdes_base );
3015c8f9400Sryan_chen 			if ( ++timeout > TIME_OUT_NCSI * eng->run.NCSI_RxTimeOutScale ) {
3025c8f9400Sryan_chen 				PRINTF( FP_LOG, "[RxDes] DesOwn timeout     %08x\n", NCSI_RxDesDat );
3035c8f9400Sryan_chen 				return( FindErr( eng, Err_Flag_NCSI_Check_RxOwnTimeOut ) );
3045c8f9400Sryan_chen 			}
3055c8f9400Sryan_chen 		} while( HWOwnRx( NCSI_RxDesDat ) );
3065c8f9400Sryan_chen 
3075c8f9400Sryan_chen 		check_rx_desc_err(eng, NCSI_RxDesDat);
3085c8f9400Sryan_chen 
3095c8f9400Sryan_chen 		// Get point of RX DMA buffer
3105c8f9400Sryan_chen 		NCSI_RxDatBase = AT_BUF_MEMRW( Read_Mem_Des_NCSI_DD( eng->run.ncsi_rdes_base + 0x0C ) );//base for read/write
3115c8f9400Sryan_chen 		NCSI_RxData    = SWAP_4B_LEDN_NCSI( SWAP_4B_LEDN( Read_Mem_Dat_NCSI_DD( NCSI_RxDatBase + 0x0C ) ) );
3125c8f9400Sryan_chen 
3135c8f9400Sryan_chen 		// Get RX valid data in offset 00h of RXDS#0
3145c8f9400Sryan_chen #ifdef NCSI_Skip_RxCRCData
3155c8f9400Sryan_chen 		bytesize  = (NCSI_RxDesDat & 0x3fff) - 4;
3165c8f9400Sryan_chen #else
3175c8f9400Sryan_chen 		bytesize  = (NCSI_RxDesDat & 0x3fff);
3185c8f9400Sryan_chen #endif
3195c8f9400Sryan_chen 		// Fill up to multiple of 4
3205c8f9400Sryan_chen 		if ( ( bytesize % 4 ) != 0 )
3215c8f9400Sryan_chen 			dwsize = ( bytesize >> 2 ) + 1;
3225c8f9400Sryan_chen 		else
3235c8f9400Sryan_chen 			dwsize = bytesize >> 2;
3245c8f9400Sryan_chen 
3255c8f9400Sryan_chen 		if ( eng->arg.ctrl.b.print_ncsi ) {
3265c8f9400Sryan_chen #ifdef NCSI_Skip_RxCRCData
3275c8f9400Sryan_chen 			PRINTF( FP_LOG ,"----->[Rx] %d bytes(%xh) [Remove CRC data]\n", bytesize, bytesize );
3285c8f9400Sryan_chen #else
3295c8f9400Sryan_chen 			PRINTF( FP_LOG ,"----->[Rx] %d bytes(%xh)\n", bytesize, bytesize );
3305c8f9400Sryan_chen #endif
3315c8f9400Sryan_chen 			for (i = 0; i < dwsize - 1; i++) {
3325c8f9400Sryan_chen 				NCSI_BufData = SWAP_4B_LEDN_NCSI( Read_Mem_Dat_NCSI_DD( NCSI_RxDatBase + ( i << 2 ) ) );
3335c8f9400Sryan_chen 				PRINTF( FP_LOG ,"      [Rx]%02d:%08x %08x\n", i, NCSI_BufData, SWAP_4B( NCSI_BufData ) );
3345c8f9400Sryan_chen 			}
3355c8f9400Sryan_chen 
3365c8f9400Sryan_chen 			i = ( dwsize - 1 );
3375c8f9400Sryan_chen 			NCSI_BufData = SWAP_4B_LEDN_NCSI( Read_Mem_Dat_NCSI_DD( NCSI_RxDatBase + ( i << 2 ) ) );
3385c8f9400Sryan_chen 			switch ( bytesize % 4 ) {
3395c8f9400Sryan_chen 				case 0  : PRINTF( FP_LOG ,"      [Rx]%02d:%08x %08x\n",                          i, NCSI_BufData & SWAP_4B_LEDN_NCSI( 0xffffffff ), SWAP_4B( NCSI_BufData ) & SWAP_4B_BEDN_NCSI( 0xffffffff ) ); break;
3405c8f9400Sryan_chen 				case 3  : PRINTF( FP_LOG ,"      [Rx]%02d:%08x %08x [%08x %08x][%08x %08x]\n", i, NCSI_BufData & SWAP_4B_LEDN_NCSI( 0x00ffffff ), SWAP_4B( NCSI_BufData ) & SWAP_4B_BEDN_NCSI( 0x00ffffff ), NCSI_BufData, SWAP_4B( NCSI_BufData ), SWAP_4B_LEDN_NCSI( 0x00ffffff ), SWAP_4B_BEDN_NCSI( 0x00ffffff ) ); break;
3415c8f9400Sryan_chen 				case 2  : PRINTF( FP_LOG ,"      [Rx]%02d:%08x %08x [%08x %08x][%08x %08x]\n", i, NCSI_BufData & SWAP_4B_LEDN_NCSI( 0x0000ffff ), SWAP_4B( NCSI_BufData ) & SWAP_4B_BEDN_NCSI( 0x0000ffff ), NCSI_BufData, SWAP_4B( NCSI_BufData ), SWAP_4B_LEDN_NCSI( 0x0000ffff ), SWAP_4B_BEDN_NCSI( 0x0000ffff ) ); break;
3425c8f9400Sryan_chen 				case 1  : PRINTF( FP_LOG ,"      [Rx]%02d:%08x %08x [%08x %08x][%08x %08x]\n", i, NCSI_BufData & SWAP_4B_LEDN_NCSI( 0x000000ff ), SWAP_4B( NCSI_BufData ) & SWAP_4B_BEDN_NCSI( 0x000000ff ), NCSI_BufData, SWAP_4B( NCSI_BufData ), SWAP_4B_LEDN_NCSI( 0x000000ff ), SWAP_4B_BEDN_NCSI( 0x000000ff ) ); break;
3435c8f9400Sryan_chen 				default : PRINTF( FP_LOG ,"      [Rx]%02d:error", i ); break;
3445c8f9400Sryan_chen 			}
3455c8f9400Sryan_chen 		}
3465c8f9400Sryan_chen 
3475c8f9400Sryan_chen 		// EtherType field of the response packet should be 0x88F8
3485c8f9400Sryan_chen //
3495c8f9400Sryan_chen 		if ( ( NCSI_RxData & 0xffff ) == 0xf888 ) {
3505c8f9400Sryan_chen 			for (i = 0; i < dwsize; i++)
3515c8f9400Sryan_chen 				eng->dat.NCSI_RxDWBUF[i] = SWAP_4B_LEDN_NCSI( Read_Mem_Dat_NCSI_DD( NCSI_RxDatBase + ( i << 2 ) ) );
3525c8f9400Sryan_chen 
3535c8f9400Sryan_chen 			memcpy ( &eng->ncsi_rsp, eng->dat.NCSI_RxByteBUF, bytesize );
3545c8f9400Sryan_chen 
3555c8f9400Sryan_chen 			if ( eng->arg.ctrl.b.print_ncsi )
3565c8f9400Sryan_chen 				PRINTF( FP_LOG ,"[Frm-NCSI][Rx IID:%2d]\n", eng->ncsi_rsp.IID );
3575c8f9400Sryan_chen 
3585c8f9400Sryan_chen 			if ( ( eng->ncsi_rsp.IID == 0x0 ) && ( eng->ncsi_rsp.Command == 0xff ) ) { // AEN Packet
3595c8f9400Sryan_chen 				if ( eng->arg.ctrl.b.print_ncsi )
3605c8f9400Sryan_chen 					PRINTF( FP_LOG ,"[Frm-NCSI][AEN Packet]Type:%2d\n", SWAP_2B_BEDN( eng->ncsi_rsp.Reason_Code ) & 0xff );
3615c8f9400Sryan_chen 			}
3625c8f9400Sryan_chen 			else {
3635c8f9400Sryan_chen 				ret = 0;
3645c8f9400Sryan_chen 			}
3655c8f9400Sryan_chen 		}
3665c8f9400Sryan_chen 		else {
3675c8f9400Sryan_chen 			if ( eng->arg.ctrl.b.print_ncsi )
3685c8f9400Sryan_chen 				PRINTF( FP_LOG, "[Frm-Skip] Not NCSI Response: [%08x & %08x = %08x]!=[%08x]\n", NCSI_RxData, 0xffff, NCSI_RxData & 0xffff, 0xf888 );
3695c8f9400Sryan_chen 		} // End if ( ( NCSI_RxData & 0xffff ) == 0xf888 )
3705c8f9400Sryan_chen 
3715c8f9400Sryan_chen 		if ( HWEOR( NCSI_RxDesDat ) ) {
3725c8f9400Sryan_chen 			// it is last the descriptor in the receive Ring
3735c8f9400Sryan_chen 			Write_Mem_Des_NCSI_DD( eng->run.ncsi_rdes_base     , EOR_IniVal    );
3745c8f9400Sryan_chen 			eng->run.ncsi_rdes_base = eng->run.rdes_base;//base for read/write
3755c8f9400Sryan_chen 		}
3765c8f9400Sryan_chen 		else {
3775c8f9400Sryan_chen 			Write_Mem_Des_NCSI_DD( eng->run.ncsi_rdes_base     , 0x00000000    );
3785c8f9400Sryan_chen 			eng->run.ncsi_rdes_base += 16;
3795c8f9400Sryan_chen 		}
3805c8f9400Sryan_chen 
3815c8f9400Sryan_chen 		if ( ret == 0 )
3825c8f9400Sryan_chen 			break;
3835c8f9400Sryan_chen 		retry++;
3845c8f9400Sryan_chen 	} while ( retry < NCSI_RxDESNum );
3855c8f9400Sryan_chen 
3865c8f9400Sryan_chen 	if ( ( ret == 0 ) && eng->arg.ctrl.b.print_ncsi ) {
3875c8f9400Sryan_chen #ifdef Print_DetailFrame
3885c8f9400Sryan_chen 		ncsi_respdump ( eng, &eng->ncsi_rsp );
3895c8f9400Sryan_chen #else
3905c8f9400Sryan_chen 		PRINTF( FP_LOG, "[NCSI-Respond] ETyp:%04x MC_ID:%02x HeadVer:%02x IID:%02x Comm:%02x ChlID:%02x PayLen:%04x ResCd:%02x ReaCd:%02x\n",
3915c8f9400Sryan_chen 		SWAP_2B_BEDN( eng->ncsi_rsp.EtherType ),
3925c8f9400Sryan_chen 		eng->ncsi_rsp.MC_ID,
3935c8f9400Sryan_chen 		eng->ncsi_rsp.Header_Revision,
3945c8f9400Sryan_chen 		eng->ncsi_rsp.IID,
3955c8f9400Sryan_chen 		eng->ncsi_rsp.Command,
3965c8f9400Sryan_chen 		eng->ncsi_rsp.ChID,
3975c8f9400Sryan_chen 		SWAP_2B_BEDN( eng->ncsi_rsp.Payload_Length ),
3985c8f9400Sryan_chen 		SWAP_2B_BEDN( eng->ncsi_rsp.Response_Code ),
3995c8f9400Sryan_chen 		SWAP_2B_BEDN( eng->ncsi_rsp.Reason_Code ));
4005c8f9400Sryan_chen #endif
4015c8f9400Sryan_chen 
4025c8f9400Sryan_chen 		NCSI_PrintCommandType2File( eng, eng->ncsi_rsp.Command, eng->ncsi_rsp.IID );
4035c8f9400Sryan_chen 	}
4045c8f9400Sryan_chen 
4055c8f9400Sryan_chen 	return( ret );
4065c8f9400Sryan_chen } // End char NCSI_Rx_SLT (MAC_ENGINE *eng)
4075c8f9400Sryan_chen 
4085c8f9400Sryan_chen //------------------------------------------------------------
NCSI_Tx(MAC_ENGINE * eng,unsigned char command,unsigned char allid,uint16_t length)4095c8f9400Sryan_chen char NCSI_Tx (MAC_ENGINE *eng, unsigned char command, unsigned char allid, uint16_t length) {
4105c8f9400Sryan_chen 	int        bytesize;
4115c8f9400Sryan_chen 	int        dwsize;
4125c8f9400Sryan_chen 	int        i;
4135c8f9400Sryan_chen 	int        timeout = 0;
4145c8f9400Sryan_chen 	uint32_t      NCSI_TxDesDat;
4155c8f9400Sryan_chen 
4165c8f9400Sryan_chen 	eng->ncsi_req.IID++;
4175c8f9400Sryan_chen 	eng->ncsi_req.Command        = command;
4185c8f9400Sryan_chen 	eng->ncsi_req.ChID           = allid;
4195c8f9400Sryan_chen 	eng->ncsi_req.Payload_Length = SWAP_2B_BEDN( length );
4205c8f9400Sryan_chen 
4215c8f9400Sryan_chen 	memcpy (  eng->dat.NCSI_TxByteBUF               , &eng->ncsi_req                 , 30     );
4225c8f9400Sryan_chen 	memcpy ( (eng->dat.NCSI_TxByteBUF + 30         ), &eng->dat.NCSI_Payload_Data    , length );
4235c8f9400Sryan_chen 	Calculate_Checksum_NCSI( eng, eng->dat.NCSI_TxByteBUF, 30 + length );
4245c8f9400Sryan_chen 	memcpy ( (eng->dat.NCSI_TxByteBUF + 30 + length), &eng->dat.Payload_Checksum_NCSI, 4      );
4255c8f9400Sryan_chen 
4265c8f9400Sryan_chen 	// Header of NC-SI command format is 34 bytes. page 58, NC-SI spec. ver 1.0.0 from DMTF
4275c8f9400Sryan_chen 	// The minimum size of a NC-SI package is 64 bytes.
4285c8f9400Sryan_chen 	bytesize = 34 + length;
4295c8f9400Sryan_chen 	if ( bytesize < 60 ) {
4305c8f9400Sryan_chen 		memset ( eng->dat.NCSI_TxByteBUF + bytesize, 0, 60 - bytesize );
4315c8f9400Sryan_chen 		bytesize = 60;
4325c8f9400Sryan_chen 	}
4335c8f9400Sryan_chen 
4345c8f9400Sryan_chen 	// Fill up to multiple of 4
4355c8f9400Sryan_chen 	//    dwsize = (bytesize + 3) >> 2;
4365c8f9400Sryan_chen 	if ( ( bytesize % 4 ) != 0 )
4375c8f9400Sryan_chen 		dwsize = ( bytesize >> 2 ) + 1;
4385c8f9400Sryan_chen 	else
4395c8f9400Sryan_chen 		dwsize = bytesize >> 2;
4405c8f9400Sryan_chen 
4415c8f9400Sryan_chen 	if ( eng->arg.ctrl.b.print_ncsi ) {
4425c8f9400Sryan_chen 		if ( bytesize % 4 )
4435c8f9400Sryan_chen 			memset ( eng->dat.NCSI_TxByteBUF + bytesize, 0, (dwsize << 2) - bytesize );
4445c8f9400Sryan_chen 
4455c8f9400Sryan_chen 		PRINTF( FP_LOG ,"----->[Tx] %d bytes(%xh)\n", bytesize, bytesize );
4465c8f9400Sryan_chen 		for ( i = 0; i < dwsize-1; i++ )
4475c8f9400Sryan_chen 			PRINTF( FP_LOG, "      [Tx]%02d:%08x %08x\n", i, eng->dat.NCSI_TxDWBUF[i], SWAP_4B( eng->dat.NCSI_TxDWBUF[i] ) );
4485c8f9400Sryan_chen 
4495c8f9400Sryan_chen 		i = dwsize - 1;
4505c8f9400Sryan_chen 		switch ( bytesize % 4 ) {
4515c8f9400Sryan_chen 			case 0  : PRINTF( FP_LOG ,"      [Tx]%02d:%08x %08x\n",                          i, eng->dat.NCSI_TxDWBUF[i] & SWAP_4B_LEDN_NCSI( 0xffffffff ), SWAP_4B( eng->dat.NCSI_TxDWBUF[i] ) & SWAP_4B_BEDN_NCSI( 0xffffffff ) ); break;
4525c8f9400Sryan_chen 			case 3  : PRINTF( FP_LOG ,"      [Tx]%02d:%08x %08x [%08x %08x][%08x %08x]\n", i, eng->dat.NCSI_TxDWBUF[i] & SWAP_4B_LEDN_NCSI( 0x00ffffff ), SWAP_4B( eng->dat.NCSI_TxDWBUF[i] ) & SWAP_4B_BEDN_NCSI( 0x00ffffff ), eng->dat.NCSI_TxDWBUF[i], SWAP_4B( eng->dat.NCSI_TxDWBUF[i] ), SWAP_4B_LEDN_NCSI( 0x00ffffff ), SWAP_4B_BEDN_NCSI( 0x00ffffff ) ); break;
4535c8f9400Sryan_chen 			case 2  : PRINTF( FP_LOG ,"      [Tx]%02d:%08x %08x [%08x %08x][%08x %08x]\n", i, eng->dat.NCSI_TxDWBUF[i] & SWAP_4B_LEDN_NCSI( 0x0000ffff ), SWAP_4B( eng->dat.NCSI_TxDWBUF[i] ) & SWAP_4B_BEDN_NCSI( 0x0000ffff ), eng->dat.NCSI_TxDWBUF[i], SWAP_4B( eng->dat.NCSI_TxDWBUF[i] ), SWAP_4B_LEDN_NCSI( 0x0000ffff ), SWAP_4B_BEDN_NCSI( 0x0000ffff ) ); break;
4545c8f9400Sryan_chen 			case 1  : PRINTF( FP_LOG ,"      [Tx]%02d:%08x %08x [%08x %08x][%08x %08x]\n", i, eng->dat.NCSI_TxDWBUF[i] & SWAP_4B_LEDN_NCSI( 0x000000ff ), SWAP_4B( eng->dat.NCSI_TxDWBUF[i] ) & SWAP_4B_BEDN_NCSI( 0x000000ff ), eng->dat.NCSI_TxDWBUF[i], SWAP_4B( eng->dat.NCSI_TxDWBUF[i] ), SWAP_4B_LEDN_NCSI( 0x000000ff ), SWAP_4B_BEDN_NCSI( 0x000000ff ) ); break;
4555c8f9400Sryan_chen 			default : PRINTF( FP_LOG ,"      [Tx]%02d:error", i ); break;
4565c8f9400Sryan_chen 		}
4575c8f9400Sryan_chen 		PRINTF( FP_LOG ,"[Frm-NCSI][Tx IID:%2d]\n", eng->ncsi_req.IID );
4585c8f9400Sryan_chen 	}
4595c8f9400Sryan_chen 
4605c8f9400Sryan_chen #if 1
4615c8f9400Sryan_chen 	// Copy data to DMA buffer
4625c8f9400Sryan_chen 	for ( i = 0; i < dwsize; i++ )
4635c8f9400Sryan_chen 		Write_Mem_Dat_NCSI_DD( DMA_BASE + ( i << 2 ), SWAP_4B_LEDN_NCSI( eng->dat.NCSI_TxDWBUF[i] ) );
4645c8f9400Sryan_chen #endif
4655c8f9400Sryan_chen 
4665c8f9400Sryan_chen 	// Setting one TX descriptor
4675c8f9400Sryan_chen 	Write_Mem_Des_NCSI_DD( eng->run.ncsi_tdes_base       , 0xf0008000 + bytesize );
4685c8f9400Sryan_chen 
4695c8f9400Sryan_chen //	mac_reg_write( eng, 0x40, eng->reg.MAC_040 ); // 20170505
4705c8f9400Sryan_chen 
4715c8f9400Sryan_chen 	// Fire
4725c8f9400Sryan_chen 	mac_reg_write( eng, 0x18, 0x00000000 );//Tx Poll
4735c8f9400Sryan_chen 
4745c8f9400Sryan_chen 	do {
4755c8f9400Sryan_chen 		NCSI_TxDesDat = Read_Mem_Des_NCSI_DD( eng->run.ncsi_tdes_base );
4765c8f9400Sryan_chen 		if ( ++timeout > TIME_OUT_NCSI ) {
4775c8f9400Sryan_chen 			PRINTF( FP_LOG, "[TxDes] DesOwn timeout     %08X\n", NCSI_TxDesDat );
4785c8f9400Sryan_chen 			return( FindErr( eng, Err_Flag_NCSI_Check_TxOwnTimeOut  ));
4795c8f9400Sryan_chen 		}
4805c8f9400Sryan_chen 	} while ( HWOwnTx( NCSI_TxDesDat ) );
4815c8f9400Sryan_chen 
4825c8f9400Sryan_chen 	if ( eng->arg.ctrl.b.print_ncsi ) {
4835c8f9400Sryan_chen #ifdef Print_DetailFrame
4845c8f9400Sryan_chen 		ncsi_reqdump ( eng, &eng->ncsi_req );
4855c8f9400Sryan_chen #else
4865c8f9400Sryan_chen 		PRINTF( FP_LOG, "[NCSI-Request] ETyp:%04x MC_ID:%02x HeadVer:%02x IID:%02x Comm:%02x ChlID:%02x PayLen:%04x\n",
4875c8f9400Sryan_chen 		SWAP_2B_BEDN( eng->ncsi_req.EtherType ),
4885c8f9400Sryan_chen 		eng->ncsi_req.MC_ID,
4895c8f9400Sryan_chen 		eng->ncsi_req.Header_Revision,
4905c8f9400Sryan_chen 		eng->ncsi_req.IID,
4915c8f9400Sryan_chen 		eng->ncsi_req.Command,
4925c8f9400Sryan_chen 		eng->ncsi_req.ChID,
4935c8f9400Sryan_chen 		SWAP_2B_BEDN( eng->ncsi_req.Payload_Length ) );
4945c8f9400Sryan_chen #endif
4955c8f9400Sryan_chen 
4965c8f9400Sryan_chen 		NCSI_PrintCommandType2File( eng, eng->ncsi_req.Command, eng->ncsi_req.IID );
4975c8f9400Sryan_chen 	}
4985c8f9400Sryan_chen #ifdef Print_PackageName
4995c8f9400Sryan_chen 	NCSI_PrintCommandType( eng, eng->ncsi_req.Command, eng->ncsi_req.IID );
5005c8f9400Sryan_chen #endif
5015c8f9400Sryan_chen 
5025c8f9400Sryan_chen 	return(0);
5035c8f9400Sryan_chen } // End char NCSI_Tx (MAC_ENGINE *eng, unsigned char command, unsigned char allid, uint16_t length)
5045c8f9400Sryan_chen 
5055c8f9400Sryan_chen //------------------------------------------------------------
NCSI_ARP(MAC_ENGINE * eng)5065c8f9400Sryan_chen char NCSI_ARP (MAC_ENGINE *eng) {
5075c8f9400Sryan_chen 	int        i;
5085c8f9400Sryan_chen 	int        timeout = 0;
5095c8f9400Sryan_chen 	uint32_t      NCSI_TxDesDat;
5105c8f9400Sryan_chen 
5115c8f9400Sryan_chen 	if ( eng->arg.ctrl.b.print_ncsi )
5125c8f9400Sryan_chen 		PRINTF( FP_LOG ,"----->[ARP] 60 bytes x%d\n", eng->arg.GARPNumCnt );
5135c8f9400Sryan_chen 
5145c8f9400Sryan_chen 	for (i = 0; i < 15; i++) {
5155c8f9400Sryan_chen 		if ( eng->arg.ctrl.b.print_ncsi )
5165c8f9400Sryan_chen 			PRINTF( FP_LOG, "      [Tx%02d] %08x %08x\n", i, eng->dat.ARP_data[i], SWAP_4B( eng->dat.ARP_data[i] ) );
5175c8f9400Sryan_chen 
5185c8f9400Sryan_chen 		Write_Mem_Dat_NCSI_DD(((uint32_t)&dma_buf) + ( i << 2 ), eng->dat.ARP_data[i] );
5195c8f9400Sryan_chen 	}
5205c8f9400Sryan_chen 
5215c8f9400Sryan_chen //	Write_Mem_Des_NCSI_DD( eng->run.ncsi_tdes_base + 0x04, 0                        );
5225c8f9400Sryan_chen //	Write_Mem_Des_NCSI_DD( eng->run.ncsi_tdes_base + 0x08, 0                        );
5235c8f9400Sryan_chen //	Write_Mem_Des_NCSI_DD( eng->run.ncsi_tdes_base + 0x0C, AT_MEMRW_BUF( DMA_BASE ) );
5245c8f9400Sryan_chen 	for (i = 0; i < eng->arg.GARPNumCnt; i++) {
5255c8f9400Sryan_chen 		Write_Mem_Des_NCSI_DD( eng->run.ncsi_tdes_base      , 0xf0008000 + 60);
5265c8f9400Sryan_chen 		mac_reg_write( eng, 0x18, 0x00000000 );//Tx Poll
5275c8f9400Sryan_chen 
5285c8f9400Sryan_chen 		do {
5295c8f9400Sryan_chen 			NCSI_TxDesDat = Read_Mem_Des_NCSI_DD( eng->run.ncsi_tdes_base );
5305c8f9400Sryan_chen 			if ( ++timeout > TIME_OUT_NCSI ) {
5315c8f9400Sryan_chen 				PRINTF( FP_LOG, "[TxDes-ARP] DesOwn timeout %08x\n", NCSI_TxDesDat );
5325c8f9400Sryan_chen 				return( FindErr( eng, Err_Flag_NCSI_Check_ARPOwnTimeOut ) );
5335c8f9400Sryan_chen 			}
5345c8f9400Sryan_chen 		} while ( HWOwnTx( NCSI_TxDesDat ) );
5355c8f9400Sryan_chen 	}
5365c8f9400Sryan_chen 	return(0);
5375c8f9400Sryan_chen } // End char NCSI_ARP (MAC_ENGINE *eng)
5385c8f9400Sryan_chen 
5395c8f9400Sryan_chen //------------------------------------------------------------
NCSI_SentWaitPacket(MAC_ENGINE * eng,unsigned char command,unsigned char allid,uint16_t length)5405c8f9400Sryan_chen char NCSI_SentWaitPacket (MAC_ENGINE *eng, unsigned char command, unsigned char allid, uint16_t length) {
5415c8f9400Sryan_chen 	int        Retry = 0;
5425c8f9400Sryan_chen 
5435c8f9400Sryan_chen 	do {
5445c8f9400Sryan_chen 		if ( NCSI_Tx( eng, command, allid, length ) )
5455c8f9400Sryan_chen 			return( 1 );
5465c8f9400Sryan_chen 
5475c8f9400Sryan_chen #ifdef NCSI_EnableDelay_EachPackage
5485c8f9400Sryan_chen 		DELAY( Delay_EachPackage );
5495c8f9400Sryan_chen #endif
5505c8f9400Sryan_chen 		if ( NCSI_Rx_SLT( eng ) )
5515c8f9400Sryan_chen 			return( 2 );
5525c8f9400Sryan_chen 
5535c8f9400Sryan_chen 		if (    ( eng->ncsi_rsp.IID           != eng->ncsi_req.IID                        )
5545c8f9400Sryan_chen 		     || ( eng->ncsi_rsp.Command       != ( command | 0x80 )                       )
5555c8f9400Sryan_chen 		     || ( eng->ncsi_rsp.Response_Code != SWAP_2B_BEDN( COMMAND_COMPLETED ) ) ) {
5565c8f9400Sryan_chen 			if ( eng->arg.ctrl.b.print_ncsi ) {
5575c8f9400Sryan_chen 				PRINTF( FP_LOG, "Retry: Command = %x, Response_Code = %x", eng->ncsi_req.Command, SWAP_2B_BEDN( eng->ncsi_rsp.Response_Code ) );
5585c8f9400Sryan_chen 				switch ( SWAP_2B_BEDN( eng->ncsi_rsp.Response_Code ) ) {
5595c8f9400Sryan_chen 					case COMMAND_COMPLETED  	: PRINTF( FP_LOG, "(completed  )\n" ); break;
5605c8f9400Sryan_chen 					case COMMAND_FAILED     	: PRINTF( FP_LOG, "(failed     )\n" ); break;
5615c8f9400Sryan_chen 					case COMMAND_UNAVAILABLE	: PRINTF( FP_LOG, "(unavailable)\n" ); break;
5625c8f9400Sryan_chen 					case COMMAND_UNSUPPORTED	: PRINTF( FP_LOG, "(unsupported)\n" ); break;
5635c8f9400Sryan_chen 					default                 	: PRINTF( FP_LOG, "(-----------)\n" ); break;
5645c8f9400Sryan_chen 				}
5655c8f9400Sryan_chen 			}
5665c8f9400Sryan_chen 			Retry++;
5675c8f9400Sryan_chen 		}
5685c8f9400Sryan_chen 		else {
5695c8f9400Sryan_chen 			return( 0 );
5705c8f9400Sryan_chen 		}
5715c8f9400Sryan_chen 	} while (Retry <= SENT_RETRY_COUNT);
5725c8f9400Sryan_chen 
5735c8f9400Sryan_chen 	return( 3 );
5745c8f9400Sryan_chen } // End char NCSI_SentWaitPacket (unsigned char command, unsigned char id, uint16_t length)
5755c8f9400Sryan_chen 
5765c8f9400Sryan_chen //------------------------------------------------------------
Clear_Initial_State_SLT(MAC_ENGINE * eng)5775c8f9400Sryan_chen char Clear_Initial_State_SLT (MAC_ENGINE *eng) {//Command:0x00
5785c8f9400Sryan_chen 	char       return_value;
5795c8f9400Sryan_chen 
580783c0c9bSDylan Hung 	eng->flg.error_backup  = eng->flg.error;
581783c0c9bSDylan Hung 	eng->flg.ncsi_backup = eng->flg.ncsi;
5825c8f9400Sryan_chen 
5835c8f9400Sryan_chen 	return_value = NCSI_SentWaitPacket( eng, CLEAR_INITIAL_STATE, eng->ncsi_cap.All_ID, 0 );//Internal Channel ID = 0
5845c8f9400Sryan_chen 
585783c0c9bSDylan Hung 	eng->flg.error  = eng->flg.error_backup;
586783c0c9bSDylan Hung 	eng->flg.ncsi = eng->flg.ncsi_backup;
5875c8f9400Sryan_chen 	return( return_value );//Internal Channel ID = 0
5885c8f9400Sryan_chen }
5895c8f9400Sryan_chen 
5905c8f9400Sryan_chen //------------------------------------------------------------
Select_Package_SLT(MAC_ENGINE * eng,char skipflag)5915c8f9400Sryan_chen char Select_Package_SLT (MAC_ENGINE *eng, char skipflag) {//Command:0x01
5925c8f9400Sryan_chen 	char       return_value;
5935c8f9400Sryan_chen 
5945c8f9400Sryan_chen 	if ( skipflag ) {
595783c0c9bSDylan Hung 		eng->flg.error_backup  = eng->flg.error;
596783c0c9bSDylan Hung 		eng->flg.ncsi_backup = eng->flg.ncsi;
5975c8f9400Sryan_chen 	}
5985c8f9400Sryan_chen 
5995c8f9400Sryan_chen 	memset ((void *)eng->dat.NCSI_Payload_Data, 0, 4);
6005c8f9400Sryan_chen 	eng->dat.NCSI_Payload_Data[ 3 ] = 1; //Arbitration Disable
6015c8f9400Sryan_chen 	return_value = NCSI_SentWaitPacket( eng, SELECT_PACKAGE, ( eng->ncsi_cap.Package_ID << 5 ) + 0x1F, 4 );//Internal Channel ID = 0x1F, 0x1F means all channel
6025c8f9400Sryan_chen 	if ( return_value )
603783c0c9bSDylan Hung 		ncsi_set_error_flag( eng, NCSI_Flag_Select_Package );
6045c8f9400Sryan_chen 
6055c8f9400Sryan_chen 	if ( skipflag ) {
606783c0c9bSDylan Hung 		eng->flg.error  = eng->flg.error_backup;
607783c0c9bSDylan Hung 		eng->flg.ncsi = eng->flg.ncsi_backup;
6085c8f9400Sryan_chen 	}
6095c8f9400Sryan_chen 	return( return_value );
6105c8f9400Sryan_chen }
6115c8f9400Sryan_chen 
6125c8f9400Sryan_chen //------------------------------------------------------------
Select_Active_Package_SLT(MAC_ENGINE * eng)6135c8f9400Sryan_chen void Select_Active_Package_SLT (MAC_ENGINE *eng) {//Command:0x01
6145c8f9400Sryan_chen 	memset ((void *)eng->dat.NCSI_Payload_Data, 0, 4);
6155c8f9400Sryan_chen 	eng->dat.NCSI_Payload_Data[ 3 ] = 1; //Arbitration Disable
6165c8f9400Sryan_chen 
6175c8f9400Sryan_chen 	if ( NCSI_SentWaitPacket( eng, SELECT_PACKAGE, ( eng->ncsi_cap.Package_ID << 5 ) + 0x1F, 4 ) ) //Internal Channel ID = 0x1F, 0x1F means all channel
618783c0c9bSDylan Hung 		ncsi_set_error_flag( eng, NCSI_Flag_Select_Active_Package );
6195c8f9400Sryan_chen }
6205c8f9400Sryan_chen 
6215c8f9400Sryan_chen //------------------------------------------------------------
DeSelect_Package_SLT(MAC_ENGINE * eng)6225c8f9400Sryan_chen void DeSelect_Package_SLT (MAC_ENGINE *eng) {//Command:0x02
6235c8f9400Sryan_chen 	if ( NCSI_SentWaitPacket( eng, DESELECT_PACKAGE, ( eng->ncsi_cap.Package_ID << 5 ) + 0x1F, 0 ) ) //Internal Channel ID = 0x1F, 0x1F means all channel
624783c0c9bSDylan Hung 		ncsi_set_error_flag( eng, NCSI_Flag_Deselect_Package );
6255c8f9400Sryan_chen 
6265c8f9400Sryan_chen #ifdef NCSI_EnableDelay_DeSelectPackage
6275c8f9400Sryan_chen 	DELAY( Delay_DeSelectPackage );
6285c8f9400Sryan_chen #endif
6295c8f9400Sryan_chen }
6305c8f9400Sryan_chen 
6315c8f9400Sryan_chen //------------------------------------------------------------
Enable_Channel_SLT(MAC_ENGINE * eng)6325c8f9400Sryan_chen void Enable_Channel_SLT (MAC_ENGINE *eng) {//Command:0x03
6335c8f9400Sryan_chen 	if ( NCSI_SentWaitPacket( eng, ENABLE_CHANNEL, eng->ncsi_cap.All_ID, 0 ) )
634783c0c9bSDylan Hung 		ncsi_set_error_flag( eng, NCSI_Flag_Enable_Channel );
6355c8f9400Sryan_chen }
6365c8f9400Sryan_chen 
6375c8f9400Sryan_chen //------------------------------------------------------------
Disable_Channel_SLT(MAC_ENGINE * eng,char skipflag)6385c8f9400Sryan_chen void Disable_Channel_SLT (MAC_ENGINE *eng, char skipflag) {//Command:0x04
6395c8f9400Sryan_chen 	if ( skipflag ) {
640783c0c9bSDylan Hung 		eng->flg.error_backup  = eng->flg.error;
641783c0c9bSDylan Hung 		eng->flg.ncsi_backup = eng->flg.ncsi;
6425c8f9400Sryan_chen 	}
6435c8f9400Sryan_chen 
6445c8f9400Sryan_chen 	memset ((void *)eng->dat.NCSI_Payload_Data, 0, 4);
6455c8f9400Sryan_chen 	eng->dat.NCSI_Payload_Data[ 3 ] = 0x1; //ALD
6465c8f9400Sryan_chen 	if ( NCSI_SentWaitPacket( eng, DISABLE_CHANNEL, eng->ncsi_cap.All_ID, 4 ) )
647783c0c9bSDylan Hung 		ncsi_set_error_flag( eng, NCSI_Flag_Disable_Channel );
6485c8f9400Sryan_chen 
6495c8f9400Sryan_chen 	if ( skipflag ) {
650783c0c9bSDylan Hung 		eng->flg.error  = eng->flg.error_backup;
651783c0c9bSDylan Hung 		eng->flg.ncsi = eng->flg.ncsi_backup;
6525c8f9400Sryan_chen 	}
6535c8f9400Sryan_chen }
6545c8f9400Sryan_chen 
6555c8f9400Sryan_chen //------------------------------------------------------------
Enable_Network_TX_SLT(MAC_ENGINE * eng)6565c8f9400Sryan_chen void Enable_Network_TX_SLT (MAC_ENGINE *eng) {//Command:0x06
6575c8f9400Sryan_chen 	if ( NCSI_SentWaitPacket( eng, ENABLE_CHANNEL_NETWORK_TX, eng->ncsi_cap.All_ID, 0 ) )
658783c0c9bSDylan Hung 		ncsi_set_error_flag( eng, NCSI_Flag_Enable_Network_TX );
6595c8f9400Sryan_chen }
6605c8f9400Sryan_chen 
6615c8f9400Sryan_chen //------------------------------------------------------------
Disable_Network_TX_SLT(MAC_ENGINE * eng)6625c8f9400Sryan_chen void Disable_Network_TX_SLT (MAC_ENGINE *eng) {//Command:0x07
6635c8f9400Sryan_chen 	if ( NCSI_SentWaitPacket( eng, DISABLE_CHANNEL_NETWORK_TX, eng->ncsi_cap.All_ID, 0 ) )
664783c0c9bSDylan Hung 		ncsi_set_error_flag( eng, NCSI_Flag_Disable_Network_TX );
6655c8f9400Sryan_chen }
6665c8f9400Sryan_chen 
6675c8f9400Sryan_chen //------------------------------------------------------------
Set_Link_SLT(MAC_ENGINE * eng)6685c8f9400Sryan_chen void Set_Link_SLT (MAC_ENGINE *eng) {//Command:0x09
6695c8f9400Sryan_chen 	memset ((void *)eng->dat.NCSI_Payload_Data, 0, 8);
6705c8f9400Sryan_chen 	eng->dat.NCSI_Payload_Data[ 2 ] = 0x02; //full duplex
6715c8f9400Sryan_chen //	eng->dat.NCSI_Payload_Data[ 3 ] = 0x04; //100M, auto-disable
6725c8f9400Sryan_chen 	eng->dat.NCSI_Payload_Data[ 3 ] = 0x05; //100M, auto-enable
6735c8f9400Sryan_chen 
6745c8f9400Sryan_chen 	if ( NCSI_SentWaitPacket( eng, SET_LINK, eng->ncsi_cap.All_ID, 8 ) )
675783c0c9bSDylan Hung 		ncsi_set_error_flag( eng, NCSI_Flag_Set_Link );
6765c8f9400Sryan_chen }
6775c8f9400Sryan_chen 
6785c8f9400Sryan_chen //------------------------------------------------------------
Get_Link_Status_SLT(MAC_ENGINE * eng)6795c8f9400Sryan_chen char Get_Link_Status_SLT (MAC_ENGINE *eng) {//Command:0x0a
6805c8f9400Sryan_chen 	if ( NCSI_SentWaitPacket( eng, GET_LINK_STATUS, eng->ncsi_cap.All_ID, 0 ) )
6815c8f9400Sryan_chen 		return(0);
6825c8f9400Sryan_chen 	else {
6835c8f9400Sryan_chen 		if ( eng->ncsi_rsp.Payload_Data[ 3 ] & 0x20 ) {
6845c8f9400Sryan_chen 			if ( eng->ncsi_rsp.Payload_Data[ 3 ] & 0x40 ) {
6855c8f9400Sryan_chen 				if ( eng->ncsi_rsp.Payload_Data[ 3 ] & 0x01 )
6865c8f9400Sryan_chen 					return(1); //Link Up or Not
6875c8f9400Sryan_chen 				else
6885c8f9400Sryan_chen 					return(0);
6895c8f9400Sryan_chen 			}
6905c8f9400Sryan_chen 			else
6915c8f9400Sryan_chen 				return(0); //Auto Negotiate did not finish
6925c8f9400Sryan_chen 		}
6935c8f9400Sryan_chen 		else {
6945c8f9400Sryan_chen 			if ( eng->ncsi_rsp.Payload_Data[ 3 ] & 0x01 )
6955c8f9400Sryan_chen 				return(1); //Link Up or Not
6965c8f9400Sryan_chen 			else
6975c8f9400Sryan_chen 				return(0);
6985c8f9400Sryan_chen 		}
6995c8f9400Sryan_chen 	}
7005c8f9400Sryan_chen } // End char Get_Link_Status_SLT (MAC_ENGINE *eng)
7015c8f9400Sryan_chen 
7025c8f9400Sryan_chen //------------------------------------------------------------
Enable_Set_MAC_Address_SLT(MAC_ENGINE * eng)7035c8f9400Sryan_chen void Enable_Set_MAC_Address_SLT (MAC_ENGINE *eng)
7045c8f9400Sryan_chen {
7055c8f9400Sryan_chen 	//Command:0x0e
7065c8f9400Sryan_chen 
7075c8f9400Sryan_chen 	int        i;
7085c8f9400Sryan_chen 
7095c8f9400Sryan_chen 	for ( i = 0; i < 6; i++ )
7105c8f9400Sryan_chen 		eng->dat.NCSI_Payload_Data[ i ] = eng->ncsi_req.SA[ i ];
7115c8f9400Sryan_chen 	eng->dat.NCSI_Payload_Data[ 6 ] = 1; //MAC Address Num = 1 --> address filter 1, fixed in sample code
7125c8f9400Sryan_chen 
7135c8f9400Sryan_chen 	if ( eng->ncsi_req.SA[ 0 ] & 0x1 )
7145c8f9400Sryan_chen 		eng->dat.NCSI_Payload_Data[ 7 ] = MULTICAST + ENABLE_MAC_ADDRESS_FILTER; //AT + E
7155c8f9400Sryan_chen 	else
7165c8f9400Sryan_chen 		eng->dat.NCSI_Payload_Data[ 7 ] = UNICAST   + ENABLE_MAC_ADDRESS_FILTER; //AT + E
7175c8f9400Sryan_chen 
7185c8f9400Sryan_chen 	if ( NCSI_SentWaitPacket( eng, SET_MAC_ADDRESS, eng->ncsi_cap.All_ID, 8 ) )
719783c0c9bSDylan Hung 		ncsi_set_error_flag( eng, NCSI_Flag_Enable_Set_MAC_Address );
7205c8f9400Sryan_chen }
7215c8f9400Sryan_chen 
7225c8f9400Sryan_chen //------------------------------------------------------------
Enable_Broadcast_Filter_SLT(MAC_ENGINE * eng)7235c8f9400Sryan_chen void Enable_Broadcast_Filter_SLT (MAC_ENGINE *eng) {//Command:0x10
7245c8f9400Sryan_chen 	memset ((void *)eng->dat.NCSI_Payload_Data, 0, 4);
7255c8f9400Sryan_chen 	eng->dat.NCSI_Payload_Data[ 3 ] = 0xF; //ARP, DHCP, NetBIOS
7265c8f9400Sryan_chen 
7275c8f9400Sryan_chen 	if ( NCSI_SentWaitPacket( eng, ENABLE_BROADCAST_FILTERING, eng->ncsi_cap.All_ID, 4 ) )
728783c0c9bSDylan Hung 		ncsi_set_error_flag( eng, NCSI_Flag_Enable_Broadcast_Filter );
7295c8f9400Sryan_chen }
7305c8f9400Sryan_chen 
7315c8f9400Sryan_chen //------------------------------------------------------------
Get_Version_ID_SLT(MAC_ENGINE * eng)7325c8f9400Sryan_chen void Get_Version_ID_SLT (MAC_ENGINE *eng) {//Command:0x15
7335c8f9400Sryan_chen 	if ( NCSI_SentWaitPacket( eng, GET_VERSION_ID, eng->ncsi_cap.All_ID, 0 ) )
734783c0c9bSDylan Hung 		ncsi_set_error_flag( eng, NCSI_Flag_Get_Version_ID );
7355c8f9400Sryan_chen 	else {
7365c8f9400Sryan_chen #ifdef Print_Version_ID
7375c8f9400Sryan_chen 		printf("NCSI Version        : %02x %02x %02x %02x\n", eng->ncsi_rsp.Payload_Data[  0 ], eng->ncsi_rsp.Payload_Data[  1 ], eng->ncsi_rsp.Payload_Data[  2 ], eng->ncsi_rsp.Payload_Data[  3 ]);
7385c8f9400Sryan_chen 		printf("NCSI Version        : %02x %02x %02x %02x\n", eng->ncsi_rsp.Payload_Data[  4 ], eng->ncsi_rsp.Payload_Data[  5 ], eng->ncsi_rsp.Payload_Data[  6 ], eng->ncsi_rsp.Payload_Data[  7 ]);
7395c8f9400Sryan_chen 		printf("Firmware Name String: %02x %02x %02x %02x\n", eng->ncsi_rsp.Payload_Data[  8 ], eng->ncsi_rsp.Payload_Data[  9 ], eng->ncsi_rsp.Payload_Data[ 10 ], eng->ncsi_rsp.Payload_Data[ 11 ]);
7405c8f9400Sryan_chen 		printf("Firmware Name String: %02x %02x %02x %02x\n", eng->ncsi_rsp.Payload_Data[ 12 ], eng->ncsi_rsp.Payload_Data[ 13 ], eng->ncsi_rsp.Payload_Data[ 14 ], eng->ncsi_rsp.Payload_Data[ 15 ]);
7415c8f9400Sryan_chen 		printf("Firmware Name String: %02x %02x %02x %02x\n", eng->ncsi_rsp.Payload_Data[ 16 ], eng->ncsi_rsp.Payload_Data[ 17 ], eng->ncsi_rsp.Payload_Data[ 18 ], eng->ncsi_rsp.Payload_Data[ 19 ]);
7425c8f9400Sryan_chen 		printf("Firmware Version    : %02x %02x %02x %02x\n", eng->ncsi_rsp.Payload_Data[ 20 ], eng->ncsi_rsp.Payload_Data[ 21 ], eng->ncsi_rsp.Payload_Data[ 22 ], eng->ncsi_rsp.Payload_Data[ 23 ]);
7435c8f9400Sryan_chen 		printf("PCI DID/VID         : %02x %02x/%02x %02x\n", eng->ncsi_rsp.Payload_Data[ 24 ], eng->ncsi_rsp.Payload_Data[ 25 ], eng->ncsi_rsp.Payload_Data[ 26 ], eng->ncsi_rsp.Payload_Data[ 27 ]);
7445c8f9400Sryan_chen 		printf("PCI SSID/SVID       : %02x %02x/%02x %02x\n", eng->ncsi_rsp.Payload_Data[ 28 ], eng->ncsi_rsp.Payload_Data[ 29 ], eng->ncsi_rsp.Payload_Data[ 30 ], eng->ncsi_rsp.Payload_Data[ 31 ]);
7455c8f9400Sryan_chen 		printf("Manufacturer ID     : %02x %02x %02x %02x\n", eng->ncsi_rsp.Payload_Data[ 32 ], eng->ncsi_rsp.Payload_Data[ 33 ], eng->ncsi_rsp.Payload_Data[ 34 ], eng->ncsi_rsp.Payload_Data[ 35 ]);
7465c8f9400Sryan_chen 		printf("Checksum            : %02x %02x %02x %02x\n", eng->ncsi_rsp.Payload_Data[ 36 ], eng->ncsi_rsp.Payload_Data[ 37 ], eng->ncsi_rsp.Payload_Data[ 38 ], eng->ncsi_rsp.Payload_Data[ 39 ]);
7475c8f9400Sryan_chen #endif
7485c8f9400Sryan_chen 		eng->ncsi_cap.PCI_DID_VID    = (eng->ncsi_rsp.Payload_Data[ 24 ]<<24)
7495c8f9400Sryan_chen 		                             | (eng->ncsi_rsp.Payload_Data[ 25 ]<<16)
7505c8f9400Sryan_chen 		                             | (eng->ncsi_rsp.Payload_Data[ 26 ]<< 8)
7515c8f9400Sryan_chen 		                             | (eng->ncsi_rsp.Payload_Data[ 27 ]    );
7525c8f9400Sryan_chen 		eng->ncsi_cap.manufacturer_id = (eng->ncsi_rsp.Payload_Data[ 32 ]<<24)
7535c8f9400Sryan_chen 		                             | (eng->ncsi_rsp.Payload_Data[ 33 ]<<16)
7545c8f9400Sryan_chen 		                             | (eng->ncsi_rsp.Payload_Data[ 34 ]<< 8)
7555c8f9400Sryan_chen 		                             | (eng->ncsi_rsp.Payload_Data[ 35 ]    );
7565c8f9400Sryan_chen 	}
7575c8f9400Sryan_chen } // End void Get_Version_ID_SLT (MAC_ENGINE *eng)
7585c8f9400Sryan_chen 
7595c8f9400Sryan_chen //------------------------------------------------------------
Get_Capabilities_SLT(MAC_ENGINE * eng)7605c8f9400Sryan_chen void Get_Capabilities_SLT (MAC_ENGINE *eng) {//Command:0x16
7615c8f9400Sryan_chen 	if ( NCSI_SentWaitPacket( eng, GET_CAPABILITIES, eng->ncsi_cap.All_ID, 0 ) )
762783c0c9bSDylan Hung 		ncsi_set_error_flag( eng, NCSI_Flag_Get_Capabilities );
7635c8f9400Sryan_chen 	else {
7645c8f9400Sryan_chen //		eng->ncsi_cap.Capabilities_Flags                   = (eng->ncsi_rsp.Payload_Data[  0 ]<<24)
7655c8f9400Sryan_chen //		                                                   | (eng->ncsi_rsp.Payload_Data[  1 ]<<16)
7665c8f9400Sryan_chen //		                                                   | (eng->ncsi_rsp.Payload_Data[  2 ]<< 8)
7675c8f9400Sryan_chen //		                                                   | (eng->ncsi_rsp.Payload_Data[  3 ]    );
7685c8f9400Sryan_chen //		eng->ncsi_cap.Broadcast_Packet_Filter_Capabilities = (eng->ncsi_rsp.Payload_Data[  4 ]<<24)
7695c8f9400Sryan_chen //		                                                   | (eng->ncsi_rsp.Payload_Data[  5 ]<<16)
7705c8f9400Sryan_chen //		                                                   | (eng->ncsi_rsp.Payload_Data[  6 ]<< 8)
7715c8f9400Sryan_chen //		                                                   | (eng->ncsi_rsp.Payload_Data[  7 ]    );
7725c8f9400Sryan_chen //		eng->ncsi_cap.Multicast_Packet_Filter_Capabilities = (eng->ncsi_rsp.Payload_Data[  8 ]<<24)
7735c8f9400Sryan_chen //		                                                   | (eng->ncsi_rsp.Payload_Data[  9 ]<<16)
7745c8f9400Sryan_chen //		                                                   | (eng->ncsi_rsp.Payload_Data[ 10 ]<< 8)
7755c8f9400Sryan_chen //		                                                   | (eng->ncsi_rsp.Payload_Data[ 11 ]    );
7765c8f9400Sryan_chen //		eng->ncsi_cap.Buffering_Capabilities               = (eng->ncsi_rsp.Payload_Data[ 12 ]<<24)
7775c8f9400Sryan_chen //		                                                   | (eng->ncsi_rsp.Payload_Data[ 13 ]<<16)
7785c8f9400Sryan_chen //		                                                   | (eng->ncsi_rsp.Payload_Data[ 14 ]<< 8)
7795c8f9400Sryan_chen //		                                                   | (eng->ncsi_rsp.Payload_Data[ 15 ]    );
7805c8f9400Sryan_chen //		eng->ncsi_cap.AEN_Control_Support                  = (eng->ncsi_rsp.Payload_Data[ 16 ]<<24)
7815c8f9400Sryan_chen //		                                                   | (eng->ncsi_rsp.Payload_Data[ 17 ]<<16)
7825c8f9400Sryan_chen //		                                                   | (eng->ncsi_rsp.Payload_Data[ 18 ]<< 8)
7835c8f9400Sryan_chen //		                                                   | (eng->ncsi_rsp.Payload_Data[ 19 ]    );
7845c8f9400Sryan_chen //		eng->ncsi_cap.VLAN_Filter_Count                    =  eng->ncsi_rsp.Payload_Data[ 20 ];
7855c8f9400Sryan_chen 		eng->ncsi_cap.Mixed_Filter_Count                   =  eng->ncsi_rsp.Payload_Data[ 21 ];
7865c8f9400Sryan_chen //		eng->ncsi_cap.Multicast_Filter_Count               =  eng->ncsi_rsp.Payload_Data[ 22 ];
7875c8f9400Sryan_chen 		eng->ncsi_cap.Unicast_Filter_Count                 =  eng->ncsi_rsp.Payload_Data[ 23 ];
7885c8f9400Sryan_chen //		eng->ncsi_cap.VLAN_Mode_Support                    =  eng->ncsi_rsp.Payload_Data[ 26 ]
7895c8f9400Sryan_chen 		eng->ncsi_cap.Channel_Count                        =  eng->ncsi_rsp.Payload_Data[ 27 ];
7905c8f9400Sryan_chen 	}
7915c8f9400Sryan_chen }
7925c8f9400Sryan_chen 
7935c8f9400Sryan_chen //------------------------------------------------------------
Get_Controller_Packet_Statistics_SLT(MAC_ENGINE * eng)7945c8f9400Sryan_chen void Get_Controller_Packet_Statistics_SLT (MAC_ENGINE *eng) {//Command:0x18
7955c8f9400Sryan_chen 	if ( NCSI_SentWaitPacket( eng, GET_CONTROLLER_PACKET_STATISTICS, eng->ncsi_cap.All_ID, 0 ) )
796783c0c9bSDylan Hung 		ncsi_set_error_flag( eng, NCSI_Flag_Get_Controller_Packet_Statistics );
7975c8f9400Sryan_chen }
7985c8f9400Sryan_chen 
7995c8f9400Sryan_chen //------------------------------------------------------------
phy_ncsi(MAC_ENGINE * eng)8005c8f9400Sryan_chen char phy_ncsi (MAC_ENGINE *eng)
8015c8f9400Sryan_chen {
8025c8f9400Sryan_chen 	uint32_t pkg_idx;
8035c8f9400Sryan_chen 	uint32_t chl_idx;
8045c8f9400Sryan_chen 	uint32_t select_flag[MAX_PACKAGE_NUM];
805530a1991SDylan Hung #ifdef NCSI_VERBOSE_TEST
8065c8f9400Sryan_chen 	uint32_t Re_Send;
8075c8f9400Sryan_chen 	uint32_t Link_Status;
808530a1991SDylan Hung #endif
8095c8f9400Sryan_chen 	eng->dat.NCSI_RxEr = 0;
8105c8f9400Sryan_chen 	eng->dat.number_chl = 0;
8115c8f9400Sryan_chen 	eng->dat.number_pak = 0;
8125c8f9400Sryan_chen 	eng->ncsi_cap.Package_ID = 0;
8135c8f9400Sryan_chen 	eng->ncsi_cap.Channel_ID = 0x1F;
8145c8f9400Sryan_chen 	eng->ncsi_cap.All_ID = 0x1F;
8155c8f9400Sryan_chen 	PRINTF(FP_LOG, "\n\n======> Start:\n");
8165c8f9400Sryan_chen 
8175c8f9400Sryan_chen 	NCSI_Struct_Initialize_SLT(eng);
8185c8f9400Sryan_chen 
8195c8f9400Sryan_chen #ifdef NCSI_Skip_Phase1_DeSelectPackage
8205c8f9400Sryan_chen #else
8215c8f9400Sryan_chen 	//NCSI Start
8225c8f9400Sryan_chen 	//Disable Channel then DeSelect Package
8235c8f9400Sryan_chen 	for (pkg_idx = 0; pkg_idx < MAX_PACKAGE_NUM; pkg_idx++) {
8245c8f9400Sryan_chen 		eng->ncsi_cap.Package_ID = pkg_idx;
8255c8f9400Sryan_chen 		eng->ncsi_cap.Channel_ID = 0x1F;
8265c8f9400Sryan_chen 		eng->ncsi_cap.All_ID     = ( eng->ncsi_cap.Package_ID << 5) + eng->ncsi_cap.Channel_ID;
8275c8f9400Sryan_chen 
8285c8f9400Sryan_chen 		select_flag[ pkg_idx ] = Select_Package_SLT ( eng, 1 ); //skipflag// Command:0x01
8295c8f9400Sryan_chen 
8305c8f9400Sryan_chen 		if ( select_flag[ pkg_idx ] == 0 ) {
8315c8f9400Sryan_chen 			if ( !eng->run.IO_MrgChk ) {
8325c8f9400Sryan_chen 				printf("----Find Package ID: %d\n", eng->ncsi_cap.Package_ID);
8335c8f9400Sryan_chen 				PRINTF(FP_LOG, "----Find Package ID: %d\n", eng->ncsi_cap.Package_ID );
8345c8f9400Sryan_chen 			}
8355c8f9400Sryan_chen 			for ( chl_idx = 0; chl_idx < MAX_CHANNEL_NUM; chl_idx++ ) {
8365c8f9400Sryan_chen 				eng->ncsi_cap.Channel_ID = chl_idx;
8375c8f9400Sryan_chen 				eng->ncsi_cap.All_ID     = ( eng->ncsi_cap.Package_ID << 5) + eng->ncsi_cap.Channel_ID;
8385c8f9400Sryan_chen 
8395c8f9400Sryan_chen 				Disable_Channel_SLT( eng, 1 );//skipflag // Command: 0x04
8405c8f9400Sryan_chen 			}
8415c8f9400Sryan_chen   #ifdef NCSI_Skip_DeSelectPackage
8425c8f9400Sryan_chen   #else
8435c8f9400Sryan_chen 			DeSelect_Package_SLT ( eng ); // Command:0x02
8445c8f9400Sryan_chen   #endif
8455c8f9400Sryan_chen 		} else {
8465c8f9400Sryan_chen 			if ( !eng->run.IO_MrgChk ) {
8475c8f9400Sryan_chen 				printf("----Absence of Package ID: %d\n", pkg_idx);
8485c8f9400Sryan_chen 				PRINTF( FP_LOG, "----Absence of Package ID: %d\n", pkg_idx );
8495c8f9400Sryan_chen 			}
8505c8f9400Sryan_chen 		} // End if ( select_flag[ pkg_idx ] == 0 )
8515c8f9400Sryan_chen 	} // End for (pkg_idx = 0; pkg_idx < MAX_PACKAGE_NUM; pkg_idx++)
8525c8f9400Sryan_chen #endif
8535c8f9400Sryan_chen 
8545c8f9400Sryan_chen 	//Select Package
8555c8f9400Sryan_chen 	for ( pkg_idx = 0; pkg_idx < MAX_PACKAGE_NUM; pkg_idx++ ) {
8565c8f9400Sryan_chen 		eng->ncsi_cap.Package_ID = pkg_idx;
8575c8f9400Sryan_chen 		eng->ncsi_cap.Channel_ID = 0x1F;
8585c8f9400Sryan_chen 		eng->ncsi_cap.All_ID     = ( eng->ncsi_cap.Package_ID << 5) + eng->ncsi_cap.Channel_ID;
8595c8f9400Sryan_chen 
8605c8f9400Sryan_chen #ifdef NCSI_Skip_Phase1_DeSelectPackage
8615c8f9400Sryan_chen 		select_flag[ pkg_idx ] = Select_Package_SLT ( eng, 1 ); //skipflag//Command:0x01
8625c8f9400Sryan_chen #endif
8635c8f9400Sryan_chen 
8645c8f9400Sryan_chen 		if ( select_flag[ pkg_idx ] == 0 ) {
8655c8f9400Sryan_chen 			//eng->run.NCSI_RxTimeOutScale = 1000;
8665c8f9400Sryan_chen 			eng->run.NCSI_RxTimeOutScale = 10;
8675c8f9400Sryan_chen 
8685c8f9400Sryan_chen #ifdef NCSI_Skip_Phase1_DeSelectPackage
8695c8f9400Sryan_chen #else
8705c8f9400Sryan_chen 			Select_Package_SLT ( eng, 0 );//Command:0x01
8715c8f9400Sryan_chen #endif
8725c8f9400Sryan_chen 			eng->dat.number_pak++;
8735c8f9400Sryan_chen 			if ( !eng->run.IO_MrgChk ) {
8745c8f9400Sryan_chen 				printf("====Find Package ID: %d\n", eng->ncsi_cap.Package_ID);
8755c8f9400Sryan_chen 				PRINTF(FP_LOG, "====Find Package ID: %d\n", eng->ncsi_cap.Package_ID );
8765c8f9400Sryan_chen 			}
8775c8f9400Sryan_chen 
8785c8f9400Sryan_chen 			// Scan all channel in the package
8795c8f9400Sryan_chen 			for ( chl_idx = 0; chl_idx < MAX_CHANNEL_NUM; chl_idx++ ) {
8805c8f9400Sryan_chen 				eng->ncsi_cap.Channel_ID = chl_idx;
8815c8f9400Sryan_chen 				eng->ncsi_cap.All_ID     = ( eng->ncsi_cap.Package_ID << 5) + eng->ncsi_cap.Channel_ID;
8825c8f9400Sryan_chen 
8835c8f9400Sryan_chen 				if ( Clear_Initial_State_SLT( eng ) == 0 ) { //Command:0x00
8845c8f9400Sryan_chen 					eng->dat.number_chl++;
8855c8f9400Sryan_chen 					if ( !eng->run.IO_MrgChk ) {
8865c8f9400Sryan_chen 						printf("--------Find Channel ID: %d\n", eng->ncsi_cap.Channel_ID);
8875c8f9400Sryan_chen 						PRINTF( FP_LOG, "--------Find Channel ID: %d\n", eng->ncsi_cap.Channel_ID );
8885c8f9400Sryan_chen 					}
8895c8f9400Sryan_chen 
8905c8f9400Sryan_chen 					// Get Version and Capabilities
8915c8f9400Sryan_chen 					Get_Version_ID_SLT( eng );          //Command:0x15
892530a1991SDylan Hung #ifdef NCSI_VERBOSE_TEST
8935c8f9400Sryan_chen 					Get_Capabilities_SLT( eng );        //Command:0x16
8945c8f9400Sryan_chen 					Select_Active_Package_SLT( eng );   //Command:0x01
8955c8f9400Sryan_chen 					Enable_Set_MAC_Address_SLT( eng );  //Command:0x0e
8965c8f9400Sryan_chen 					Enable_Broadcast_Filter_SLT( eng ); //Command:0x10
8975c8f9400Sryan_chen 
8985c8f9400Sryan_chen 					// Enable TX
8995c8f9400Sryan_chen 					Enable_Network_TX_SLT( eng );       //Command:0x06
9005c8f9400Sryan_chen 
9015c8f9400Sryan_chen 					// Enable Channel
9025c8f9400Sryan_chen 					Enable_Channel_SLT( eng );          //Command:0x03
9035c8f9400Sryan_chen 
9045c8f9400Sryan_chen 					// Get Link Status
9055c8f9400Sryan_chen 					Re_Send = 0;
9065c8f9400Sryan_chen 					do {
9075c8f9400Sryan_chen #ifdef NCSI_EnableDelay_GetLinkStatus
9085c8f9400Sryan_chen 						if ( Re_Send )
9095c8f9400Sryan_chen 							DELAY( Delay_GetLinkStatus );
9105c8f9400Sryan_chen #endif
9115c8f9400Sryan_chen 
9125c8f9400Sryan_chen 						Link_Status = Get_Link_Status_SLT( eng );//Command:0x0a
9135c8f9400Sryan_chen 						if ( Link_Status == LINK_UP ) {
9145c8f9400Sryan_chen 							if ( eng->arg.GARPNumCnt )
9155c8f9400Sryan_chen 								NCSI_ARP ( eng );
9165c8f9400Sryan_chen 							break;
9175c8f9400Sryan_chen 						} // End if ( Link_Status == LINK_UP )
9185c8f9400Sryan_chen 					} while ( Re_Send++ <= 2 );
9195c8f9400Sryan_chen 
9205c8f9400Sryan_chen 					if ( !eng->run.IO_MrgChk ) {
9215c8f9400Sryan_chen 						if ( Link_Status == LINK_UP ) {
9225c8f9400Sryan_chen 							printf("        This Channel is LINK_UP (MFC:%d, UFC:%d, CC:%d)\n", eng->ncsi_cap.Mixed_Filter_Count, eng->ncsi_cap.Unicast_Filter_Count, eng->ncsi_cap.Channel_Count);
9235c8f9400Sryan_chen 							PRINTF( FP_LOG, "        This Channel is LINK_UP (MFC:%d, UFC:%d, CC:%d)\n", eng->ncsi_cap.Mixed_Filter_Count, eng->ncsi_cap.Unicast_Filter_Count, eng->ncsi_cap.Channel_Count);
9245c8f9400Sryan_chen 						}
9255c8f9400Sryan_chen 						else {
9265c8f9400Sryan_chen 							printf("        This Channel is LINK_DOWN (MFC:%d, UFC:%d, CC:%d)\n", eng->ncsi_cap.Mixed_Filter_Count, eng->ncsi_cap.Unicast_Filter_Count, eng->ncsi_cap.Channel_Count);
9275c8f9400Sryan_chen 							PRINTF( FP_LOG, "        This Channel is LINK_DOWN (MFC:%d, UFC:%d, CC:%d)\n", eng->ncsi_cap.Mixed_Filter_Count, eng->ncsi_cap.Unicast_Filter_Count, eng->ncsi_cap.Channel_Count);
9285c8f9400Sryan_chen 						}
9295c8f9400Sryan_chen 					}
930530a1991SDylan Hung #endif	/* endof "#ifdef NCSI_VERBOSE_TEST" */
9315c8f9400Sryan_chen 
9325c8f9400Sryan_chen #ifdef NCSI_Skip_DiSChannel
9335c8f9400Sryan_chen #else
9345c8f9400Sryan_chen 					if ( eng->run.TM_NCSI_DiSChannel ) {
9355c8f9400Sryan_chen 						// Disable TX
9365c8f9400Sryan_chen 						Disable_Network_TX_SLT( eng ); //Command:0x07
9375c8f9400Sryan_chen 						// Disable Channel
9385c8f9400Sryan_chen 						Disable_Channel_SLT( eng, 0 );    //Command:0x04
9395c8f9400Sryan_chen 					}
9405c8f9400Sryan_chen #endif
9415c8f9400Sryan_chen 				} // End if ( Clear_Initial_State_SLT( eng, chl_idx ) == 0 )
9425c8f9400Sryan_chen 			} // End for ( chl_idx = 0; chl_idx < MAX_CHANNEL_NUM; chl_idx++ )
9435c8f9400Sryan_chen 
9445c8f9400Sryan_chen #ifdef NCSI_Skip_DeSelectPackage
9455c8f9400Sryan_chen #else
9465c8f9400Sryan_chen 			DeSelect_Package_SLT ( eng );//Command:0x02
9475c8f9400Sryan_chen #endif
9485c8f9400Sryan_chen 			eng->run.NCSI_RxTimeOutScale = 1;
9495c8f9400Sryan_chen 		}
9505c8f9400Sryan_chen 		else {
9515c8f9400Sryan_chen 			if ( !eng->run.IO_MrgChk ) {
9525c8f9400Sryan_chen 				printf("====Absence of Package ID: %d\n", pkg_idx);
9535c8f9400Sryan_chen 				PRINTF( FP_LOG, "====Absence of Package ID: %d\n", pkg_idx );
9545c8f9400Sryan_chen 			}
9555c8f9400Sryan_chen 		} // End if ( select_flag[pkg_idx] == 0 )
9565c8f9400Sryan_chen 	} // End for ( pkg_idx = 0; pkg_idx < MAX_PACKAGE_NUM; pkg_idx++ )
9575c8f9400Sryan_chen 
9585c8f9400Sryan_chen 	if ( eng->dat.number_pak == 0                       ) FindErr( eng, Err_Flag_NCSI_No_PHY      );
9595c8f9400Sryan_chen 	if ( eng->dat.number_pak != eng->arg.GPackageTolNum ) FindErr( eng, Err_Flag_NCSI_Package_Num );
9605c8f9400Sryan_chen 	if ( eng->dat.number_chl != eng->arg.GChannelTolNum ) FindErr( eng, Err_Flag_NCSI_Channel_Num );
9615c8f9400Sryan_chen //	if ( eng->dat.number_chl == 0                       ) FindErr( eng );
9625c8f9400Sryan_chen 
963783c0c9bSDylan Hung 	if ( eng->flg.error ) {
9645c8f9400Sryan_chen 		if ( eng->dat.NCSI_RxEr )
9655c8f9400Sryan_chen 			FindErr_Des( eng, Des_Flag_RxErr );
9665c8f9400Sryan_chen 		return(1);
9675c8f9400Sryan_chen 	}
9685c8f9400Sryan_chen 	else {
9695c8f9400Sryan_chen 		if ( eng->dat.NCSI_RxEr ) {
970783c0c9bSDylan Hung 			eng->flg.warn = eng->flg.warn | Wrn_Flag_RxErFloatting;
9715c8f9400Sryan_chen 			if ( eng->arg.ctrl.b.skip_rx_err ) {
9725c8f9400Sryan_chen 				eng->flg.all_fail = 0;
9735c8f9400Sryan_chen 				return(0);
9745c8f9400Sryan_chen 			}
9755c8f9400Sryan_chen 			else {
9765c8f9400Sryan_chen 				FindErr_Des( eng, Des_Flag_RxErr );
9775c8f9400Sryan_chen 				return(1);
9785c8f9400Sryan_chen 			}
9795c8f9400Sryan_chen 		}
9805c8f9400Sryan_chen 		else {
9815c8f9400Sryan_chen 			eng->flg.all_fail = 0;
9825c8f9400Sryan_chen 			return(0);
9835c8f9400Sryan_chen 		}
9845c8f9400Sryan_chen 	}
9855c8f9400Sryan_chen }
986