1 /* 2 * This program is distributed in the hope that it will be useful, 3 * but WITHOUT ANY WARRANTY; without even the implied warranty of 4 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5 * GNU General Public License for more details. 6 * 7 * You should have received a copy of the GNU General Public License 8 * along with this program; if not, write to the Free Software 9 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 10 */ 11 12 #define NCSI_C 13 14 #include "swfunc.h" 15 16 #include "comminf.h" 17 //#include "io.h" 18 #include "ncsi.h" 19 #include <command.h> 20 #include <common.h> 21 #include "mac_api.h" 22 23 //------------------------------------------------------------ 24 int ncsi_set_error_flag(MAC_ENGINE *eng, int eflag) 25 { 26 eng->flg.ncsi = eng->flg.ncsi | eflag; 27 eng->flg.error = eng->flg.error | ERR_FLAG_NCSI_LINKFAIL; 28 if (DBG_PRINT_ERR_FLAG) 29 printf("\nflags: error = %08x, ncsi = %08x\n", 30 eng->flg.error, eng->flg.ncsi); 31 32 return (1); 33 } 34 35 //------------------------------------------------------------ 36 // PHY IC(NC-SI) 37 //------------------------------------------------------------ 38 void ncsi_reqdump(MAC_ENGINE *eng, NCSI_Command_Packet *in) 39 { 40 int i; 41 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 ]); 42 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 ]); 43 PRINTF( FP_LOG, "[NCSI-Request] EtherType : %04x\n", SWAP_2B_BEDN( in->EtherType ) );//DMTF NC-SI 44 PRINTF( FP_LOG, "[NCSI-Request] MC_ID : %02x\n", in->MC_ID );//Management Controller should set this field to 0x00 45 PRINTF( FP_LOG, "[NCSI-Request] Header_Revision: %02x\n", in->Header_Revision );//For NC-SI 1.0 spec, this field has to set 0x01 46 // PRINTF( FP_LOG, "[NCSI-Request] Reserved_1 : %02x\n", in->Reserved_1 ); //Reserved has to set to 0x00 47 PRINTF( FP_LOG, "[NCSI-Request] IID : %02x\n", in->IID );//Instance ID 48 PRINTF( FP_LOG, "[NCSI-Request] Command : %02x\n", in->Command ); 49 PRINTF( FP_LOG, "[NCSI-Request] ChID : %02x\n", in->ChID ); 50 PRINTF( FP_LOG, "[NCSI-Request] Payload_Length : %04x\n", SWAP_2B_BEDN( in->Payload_Length ) );//Payload Length = 12 bits, 4 bits are reserved 51 // PRINTF( FP_LOG, "[NCSI-Request] Reserved_2 : %04x\n", in->Reserved_2 ); 52 // PRINTF( FP_LOG, "[NCSI-Request] Reserved_3 : %04x\n", in->Reserved_3 ); 53 // PRINTF( FP_LOG, "[NCSI-Request] Reserved_4 : %04x\n", in->Reserved_4 ); 54 // PRINTF( FP_LOG, "[NCSI-Request] Reserved_5 : %04x\n", in->Reserved_5 ); 55 PRINTF( FP_LOG, "[NCSI-Request] Response_Code : %04x\n", SWAP_2B_BEDN( in->Response_Code ) ); 56 PRINTF( FP_LOG, "[NCSI-Request] Reason_Code : %04x\n", SWAP_2B_BEDN( in->Reason_Code ) ); 57 for ( i = 0; i < SWAP_2B_BEDN( in->Payload_Length ); i++ ) { 58 switch ( i % 4 ) { 59 case 0 : PRINTF( FP_LOG, "[NCSI-Request] Payload_Data : %02x", in->Payload_Data[ i ]); break; 60 case 3 : PRINTF( FP_LOG, " %02x\n", in->Payload_Data[ i ]); break; 61 default : PRINTF( FP_LOG, " %02x", in->Payload_Data[ i ]); break; 62 } 63 } 64 if ( ( i % 4 ) != 3 ) 65 PRINTF( FP_LOG, "\n"); 66 } 67 void ncsi_respdump (MAC_ENGINE *eng, NCSI_Response_Packet *in) { 68 int i; 69 // 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 ]); 70 // 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 ]); 71 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 ]); 72 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 ]); 73 PRINTF( FP_LOG, "[NCSI-Respond] EtherType : %04x\n", SWAP_2B_BEDN( in->EtherType ) );//DMTF NC-SI 74 PRINTF( FP_LOG, "[NCSI-Respond] MC_ID : %02x\n", in->MC_ID );//Management Controller should set this field to 0x00 75 PRINTF( FP_LOG, "[NCSI-Respond] Header_Revision: %02x\n", in->Header_Revision );//For NC-SI 1.0 spec, this field has to set 0x01 76 // PRINTF( FP_LOG, "[NCSI-Respond] Reserved_1 : %02x\n", in->Reserved_1 ); //Reserved has to set to 0x00 77 PRINTF( FP_LOG, "[NCSI-Respond] IID : %02x\n", in->IID );//Instance ID 78 PRINTF( FP_LOG, "[NCSI-Respond] Command : %02x\n", in->Command ); 79 PRINTF( FP_LOG, "[NCSI-Respond] ChID : %02x\n", in->ChID ); 80 PRINTF( FP_LOG, "[NCSI-Respond] Payload_Length : %04x\n", SWAP_2B_BEDN( in->Payload_Length ) );//Payload Length = 12 bits, 4 bits are reserved 81 // PRINTF( FP_LOG, "[NCSI-Respond] Reserved_2 : %04x\n", in->Reserved_2 ); 82 // PRINTF( FP_LOG, "[NCSI-Respond] Reserved_3 : %04x\n", in->Reserved_3 ); 83 // PRINTF( FP_LOG, "[NCSI-Respond] Reserved_4 : %04x\n", in->Reserved_4 ); 84 // PRINTF( FP_LOG, "[NCSI-Respond] Reserved_5 : %04x\n", in->Reserved_5 ); 85 PRINTF( FP_LOG, "[NCSI-Respond] Response_Code : %04x\n", SWAP_2B_BEDN( in->Response_Code ) ); 86 PRINTF( FP_LOG, "[NCSI-Respond] Reason_Code : %04x\n", SWAP_2B_BEDN( in->Reason_Code ) ); 87 for ( i = 0; i < SWAP_2B_BEDN( in->Payload_Length ); i++ ) { 88 switch ( i % 4 ) { 89 case 0 : PRINTF( FP_LOG, "[NCSI-Respond] Payload_Data : %02x", in->Payload_Data[ i ]); break; 90 case 3 : PRINTF( FP_LOG, " %02x\n", in->Payload_Data[ i ]); break; 91 default : PRINTF( FP_LOG, " %02x", in->Payload_Data[ i ]); break; 92 } 93 } 94 if ( ( i % 4 ) != 3 ) 95 PRINTF( FP_LOG, "\n"); 96 } 97 98 //------------------------------------------------------------ 99 void NCSI_PrintCommandStr (MAC_ENGINE *eng, unsigned char command, unsigned iid) { 100 switch ( command & 0x80 ) { 101 case 0x80 : sprintf(eng->dat.NCSI_CommandStr, "IID:%3d [%02x:Respond]", iid, command); break; 102 default : sprintf(eng->dat.NCSI_CommandStr, "IID:%3d [%02x:Request]", iid, command); break; 103 } 104 switch ( command & 0x7f ) { 105 case 0x00 : sprintf(eng->dat.NCSI_CommandStr, "%s[CLEAR_INITIAL_STATE ]", eng->dat.NCSI_CommandStr); break; 106 case 0x01 : sprintf(eng->dat.NCSI_CommandStr, "%s[SELECT_PACKAGE ]", eng->dat.NCSI_CommandStr); break; 107 case 0x02 : sprintf(eng->dat.NCSI_CommandStr, "%s[DESELECT_PACKAGE ]", eng->dat.NCSI_CommandStr); break; 108 case 0x03 : sprintf(eng->dat.NCSI_CommandStr, "%s[ENABLE_CHANNEL ]", eng->dat.NCSI_CommandStr); break; 109 case 0x04 : sprintf(eng->dat.NCSI_CommandStr, "%s[DISABLE_CHANNEL ]", eng->dat.NCSI_CommandStr); break; 110 case 0x05 : sprintf(eng->dat.NCSI_CommandStr, "%s[RESET_CHANNEL ]", eng->dat.NCSI_CommandStr); break; 111 case 0x06 : sprintf(eng->dat.NCSI_CommandStr, "%s[ENABLE_CHANNEL_NETWORK_TX ]", eng->dat.NCSI_CommandStr); break; 112 case 0x07 : sprintf(eng->dat.NCSI_CommandStr, "%s[DISABLE_CHANNEL_NETWORK_TX ]", eng->dat.NCSI_CommandStr); break; 113 case 0x08 : sprintf(eng->dat.NCSI_CommandStr, "%s[AEN_ENABLE ]", eng->dat.NCSI_CommandStr); break; 114 case 0x09 : sprintf(eng->dat.NCSI_CommandStr, "%s[SET_LINK ]", eng->dat.NCSI_CommandStr); break; 115 case 0x0A : sprintf(eng->dat.NCSI_CommandStr, "%s[GET_LINK_STATUS ]", eng->dat.NCSI_CommandStr); break; 116 case 0x0B : sprintf(eng->dat.NCSI_CommandStr, "%s[SET_VLAN_FILTER ]", eng->dat.NCSI_CommandStr); break; 117 case 0x0C : sprintf(eng->dat.NCSI_CommandStr, "%s[ENABLE_VLAN ]", eng->dat.NCSI_CommandStr); break; 118 case 0x0D : sprintf(eng->dat.NCSI_CommandStr, "%s[DISABLE_VLAN ]", eng->dat.NCSI_CommandStr); break; 119 case 0x0E : sprintf(eng->dat.NCSI_CommandStr, "%s[SET_MAC_ADDRESS ]", eng->dat.NCSI_CommandStr); break; 120 case 0x10 : sprintf(eng->dat.NCSI_CommandStr, "%s[ENABLE_BROADCAST_FILTERING ]", eng->dat.NCSI_CommandStr); break; 121 case 0x11 : sprintf(eng->dat.NCSI_CommandStr, "%s[DISABLE_BROADCAST_FILTERING ]", eng->dat.NCSI_CommandStr); break; 122 case 0x12 : sprintf(eng->dat.NCSI_CommandStr, "%s[ENABLE_GLOBAL_MULTICAST_FILTERING ]", eng->dat.NCSI_CommandStr); break; 123 case 0x13 : sprintf(eng->dat.NCSI_CommandStr, "%s[DISABLE_GLOBAL_MULTICAST_FILTERING ]", eng->dat.NCSI_CommandStr); break; 124 case 0x14 : sprintf(eng->dat.NCSI_CommandStr, "%s[SET_NCSI_FLOW_CONTROL ]", eng->dat.NCSI_CommandStr); break; 125 case 0x15 : sprintf(eng->dat.NCSI_CommandStr, "%s[GET_VERSION_ID ]", eng->dat.NCSI_CommandStr); break; 126 case 0x16 : sprintf(eng->dat.NCSI_CommandStr, "%s[GET_CAPABILITIES ]", eng->dat.NCSI_CommandStr); break; 127 case 0x17 : sprintf(eng->dat.NCSI_CommandStr, "%s[GET_PARAMETERS ]", eng->dat.NCSI_CommandStr); break; 128 case 0x18 : sprintf(eng->dat.NCSI_CommandStr, "%s[GET_CONTROLLER_PACKET_STATISTICS ]", eng->dat.NCSI_CommandStr); break; 129 case 0x19 : sprintf(eng->dat.NCSI_CommandStr, "%s[GET_NCSI_STATISTICS ]", eng->dat.NCSI_CommandStr); break; 130 case 0x1A : sprintf(eng->dat.NCSI_CommandStr, "%s[GET_NCSI_PASS_THROUGH_STATISTICS ]", eng->dat.NCSI_CommandStr); break; 131 case 0x50 : sprintf(eng->dat.NCSI_CommandStr, "%s[OEM_COMMAND ]", eng->dat.NCSI_CommandStr); break; 132 default : sprintf(eng->dat.NCSI_CommandStr, "%s Not Support Command", eng->dat.NCSI_CommandStr); break ; 133 } 134 } // End void NCSI_PrintCommandStr (MAC_ENGINE *eng, unsigned char command, unsigned iid) 135 136 //------------------------------------------------------------ 137 void NCSI_PrintCommandType (MAC_ENGINE *eng, unsigned char command, unsigned iid) { 138 NCSI_PrintCommandStr( eng, command, iid ); 139 printf("[NCSI-commd]%s\n", eng->dat.NCSI_CommandStr); 140 } 141 142 //------------------------------------------------------------ 143 void NCSI_PrintCommandType2File (MAC_ENGINE *eng, unsigned char command, unsigned iid) { 144 NCSI_PrintCommandStr( eng, command, iid ); 145 PRINTF( FP_LOG, "[NCSI-commd]%s\n", eng->dat.NCSI_CommandStr ); 146 } 147 148 //------------------------------------------------------------ 149 void NCSI_Struct_Initialize_SLT (MAC_ENGINE *eng) 150 { 151 int i; 152 uint32_t NCSI_RxDatBase; 153 154 eng->run.NCSI_RxTimeOutScale = 1; 155 156 for (i = 0; i < 6; i++) { 157 eng->ncsi_req.DA[i] = 0xFF; 158 eng->ncsi_req.SA[i] = eng->inf.SA[i]; 159 } 160 161 /* EtherType = 0x88F8 (DMTF DSP0222 NC-SI spec) 162 ethernet frame header format, table 8 */ 163 eng->ncsi_req.EtherType = SWAP_2B_BEDN(0x88F8); 164 165 eng->ncsi_req.MC_ID = 0; 166 eng->ncsi_req.Header_Revision = 0x01; 167 eng->ncsi_req.Reserved_1 = 0; 168 eng->ncsi_req.IID = 0; 169 // eng->ncsi_req.Command = 0; 170 // eng->ncsi_req.ChID = 0; 171 // eng->ncsi_req.Payload_Length = 0; 172 173 eng->ncsi_req.Response_Code = 0; 174 eng->ncsi_req.Reason_Code = 0; 175 eng->ncsi_req.Reserved_2 = 0; 176 eng->ncsi_req.Reserved_3 = 0; 177 178 eng->dat.NCSI_TxByteBUF = (unsigned char *) &eng->dat.NCSI_TxDWBUF[0]; 179 eng->dat.NCSI_RxByteBUF = (unsigned char *) &eng->dat.NCSI_RxDWBUF[0]; 180 181 eng->run.ncsi_tdes_base = eng->run.tdes_base;//base for read/write 182 Write_Mem_Des_NCSI_DD( eng->run.ncsi_tdes_base + 0x04, 0 ); 183 Write_Mem_Des_NCSI_DD( eng->run.ncsi_tdes_base + 0x08, 0 ); 184 Write_Mem_Des_NCSI_DD( eng->run.ncsi_tdes_base + 0x0C, DMA_BASE - ASPEED_DRAM_BASE); 185 186 eng->run.ncsi_rdes_base = eng->run.rdes_base;//base for read/write 187 NCSI_RxDatBase = AT_MEMRW_BUF( NCSI_RxDMA_BASE );//base of the descriptor 188 189 for (i = 0; i < NCSI_RxDESNum - 1; i++) { 190 Write_Mem_Des_NCSI_DD( ( eng->run.ncsi_rdes_base ), 0x00000000 ); 191 Write_Mem_Des_NCSI_DD( ( eng->run.ncsi_rdes_base + 0x04 ), 0x00000000 ); 192 Write_Mem_Des_NCSI_DD( ( eng->run.ncsi_rdes_base + 0x08 ), 0x00000000 ); 193 Write_Mem_Des_NCSI_DD( ( eng->run.ncsi_rdes_base + 0x0C ), NCSI_RxDatBase ); 194 eng->run.ncsi_rdes_base += 16; 195 NCSI_RxDatBase += NCSI_RxDMA_PakSize; 196 } 197 Write_Mem_Des_NCSI_DD( ( eng->run.ncsi_rdes_base ), EOR_IniVal ); 198 Write_Mem_Des_NCSI_DD( ( eng->run.ncsi_rdes_base + 0x04 ), 0x00000000 ); 199 Write_Mem_Des_NCSI_DD( ( eng->run.ncsi_rdes_base + 0x08 ), 0x00000000 ); 200 // Write_Mem_Des_NCSI_DD( ( eng->run.ncsi_rdes_base + 0x0C ), (NCSI_RxDatBase + CPU_BUS_ADDR_SDRAM_OFFSET) ); // 20130730 201 Write_Mem_Des_NCSI_DD( ( eng->run.ncsi_rdes_base + 0x0C ), NCSI_RxDatBase ); // 20130730 202 203 eng->run.ncsi_rdes_base = eng->run.rdes_base;//base for read/write 204 } 205 206 //------------------------------------------------------------ 207 void Calculate_Checksum_NCSI (MAC_ENGINE *eng, unsigned char *buffer_base, int Length) { 208 uint32_t CheckSum = 0; 209 uint32_t Data; 210 uint32_t Data1; 211 int i; 212 213 // Calculate checksum is from byte 14 of ethernet Haeder and Control packet header 214 // Page 50, NC-SI spec. ver. 1.0.0 form DMTF 215 for (i = 14; i < Length; i += 2 ) { 216 Data = buffer_base[i]; 217 Data1 = buffer_base[i + 1]; 218 CheckSum += ((Data << 8) + Data1); 219 } 220 eng->dat.Payload_Checksum_NCSI = SWAP_4B_BEDN(~(CheckSum) + 1); //2's complement 221 } 222 223 /** 224 * @brief check error mask in RX descriptor 225 * @param rx_desc0 RX descript[0] 226 */ 227 static int check_rx_desc_err(MAC_ENGINE *p_eng, uint32_t rx_desc0) 228 { 229 uint8_t prefix[8] = "[RxDes]"; 230 231 if (rx_desc0 & RXDES_EM_ALL) { 232 #ifdef CheckRxErr 233 if (rx_desc0 & RXDES_EM_RXERR) { 234 PRINTF(STD_OUT, "%s Error RxErr %08x\n", prefix, 235 rx_desc0); 236 p_eng->dat.NCSI_RxEr = 1; 237 } 238 #endif 239 240 #ifdef CheckCRC 241 if (rx_desc0 & RXDES_EM_CRC) { 242 PRINTF(STD_OUT, "%s Error CRC %08x\n", prefix, 243 rx_desc0); 244 FindErr_Des(p_eng, Des_Flag_CRC); 245 } 246 #endif 247 248 #ifdef CheckFTL 249 if (rx_desc0 & RXDES_EM_FTL) { 250 PRINTF(STD_OUT, "%s Error FTL %08x\n", prefix, 251 rx_desc0); 252 FindErr_Des(p_eng, Des_Flag_FTL); 253 } 254 #endif 255 256 #ifdef CheckRunt 257 if (rx_desc0 & RXDES_EM_RUNT) { 258 PRINTF(STD_OUT, "%s Error Runt %08x\n", prefix, 259 rx_desc0); 260 FindErr_Des(p_eng, Des_Flag_Runt); 261 } 262 #endif 263 264 #ifdef CheckOddNibble 265 if (rx_desc0 & RXDES_EM_ODD_NB) { 266 PRINTF(STD_OUT, "%s Odd Nibble %08x\n", prefix, 267 rx_desc0); 268 FindErr_Des(p_eng, Des_Flag_OddNibble); 269 } 270 #endif 271 272 #ifdef CheckRxFIFOFull 273 if (rx_desc0 & RXDES_EM_FIFO_FULL) { 274 PRINTF(STD_OUT, "%s Error Rx FIFO Full %08x\n", prefix, 275 rx_desc0); 276 FindErr_Des(p_eng, Des_Flag_RxFIFOFull); 277 } 278 #endif 279 } 280 281 return 0; 282 } 283 284 //------------------------------------------------------------ 285 // return 0: it is PASS 286 // return 1: it is FAIL 287 //------------------------------------------------------------ 288 char NCSI_Rx_SLT (MAC_ENGINE *eng) { 289 int timeout = 0; 290 int bytesize; 291 int dwsize; 292 int i; 293 int retry = 0; 294 char ret = 1; 295 296 uint32_t NCSI_RxDatBase; 297 uint32_t NCSI_RxDesDat; 298 uint32_t NCSI_RxData; 299 uint32_t NCSI_BufData; 300 301 do { 302 mac_reg_write( eng, 0x1C, 0x00000000 );//Rx Poll 303 304 timeout = 0; 305 do { 306 NCSI_RxDesDat = Read_Mem_Des_NCSI_DD( eng->run.ncsi_rdes_base ); 307 if ( ++timeout > TIME_OUT_NCSI * eng->run.NCSI_RxTimeOutScale ) { 308 PRINTF( FP_LOG, "[RxDes] DesOwn timeout %08x\n", NCSI_RxDesDat ); 309 return( FindErr( eng, Err_Flag_NCSI_Check_RxOwnTimeOut ) ); 310 } 311 } while( HWOwnRx( NCSI_RxDesDat ) ); 312 313 check_rx_desc_err(eng, NCSI_RxDesDat); 314 315 // Get point of RX DMA buffer 316 NCSI_RxDatBase = AT_BUF_MEMRW( Read_Mem_Des_NCSI_DD( eng->run.ncsi_rdes_base + 0x0C ) );//base for read/write 317 NCSI_RxData = SWAP_4B_LEDN_NCSI( SWAP_4B_LEDN( Read_Mem_Dat_NCSI_DD( NCSI_RxDatBase + 0x0C ) ) ); 318 319 // Get RX valid data in offset 00h of RXDS#0 320 #ifdef NCSI_Skip_RxCRCData 321 bytesize = (NCSI_RxDesDat & 0x3fff) - 4; 322 #else 323 bytesize = (NCSI_RxDesDat & 0x3fff); 324 #endif 325 // Fill up to multiple of 4 326 if ( ( bytesize % 4 ) != 0 ) 327 dwsize = ( bytesize >> 2 ) + 1; 328 else 329 dwsize = bytesize >> 2; 330 331 if ( eng->arg.ctrl.b.print_ncsi ) { 332 #ifdef NCSI_Skip_RxCRCData 333 PRINTF( FP_LOG ,"----->[Rx] %d bytes(%xh) [Remove CRC data]\n", bytesize, bytesize ); 334 #else 335 PRINTF( FP_LOG ,"----->[Rx] %d bytes(%xh)\n", bytesize, bytesize ); 336 #endif 337 for (i = 0; i < dwsize - 1; i++) { 338 NCSI_BufData = SWAP_4B_LEDN_NCSI( Read_Mem_Dat_NCSI_DD( NCSI_RxDatBase + ( i << 2 ) ) ); 339 PRINTF( FP_LOG ," [Rx]%02d:%08x %08x\n", i, NCSI_BufData, SWAP_4B( NCSI_BufData ) ); 340 } 341 342 i = ( dwsize - 1 ); 343 NCSI_BufData = SWAP_4B_LEDN_NCSI( Read_Mem_Dat_NCSI_DD( NCSI_RxDatBase + ( i << 2 ) ) ); 344 switch ( bytesize % 4 ) { 345 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; 346 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; 347 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; 348 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; 349 default : PRINTF( FP_LOG ," [Rx]%02d:error", i ); break; 350 } 351 } 352 353 // EtherType field of the response packet should be 0x88F8 354 // 355 if ( ( NCSI_RxData & 0xffff ) == 0xf888 ) { 356 for (i = 0; i < dwsize; i++) 357 eng->dat.NCSI_RxDWBUF[i] = SWAP_4B_LEDN_NCSI( Read_Mem_Dat_NCSI_DD( NCSI_RxDatBase + ( i << 2 ) ) ); 358 359 memcpy ( &eng->ncsi_rsp, eng->dat.NCSI_RxByteBUF, bytesize ); 360 361 if ( eng->arg.ctrl.b.print_ncsi ) 362 PRINTF( FP_LOG ,"[Frm-NCSI][Rx IID:%2d]\n", eng->ncsi_rsp.IID ); 363 364 if ( ( eng->ncsi_rsp.IID == 0x0 ) && ( eng->ncsi_rsp.Command == 0xff ) ) { // AEN Packet 365 if ( eng->arg.ctrl.b.print_ncsi ) 366 PRINTF( FP_LOG ,"[Frm-NCSI][AEN Packet]Type:%2d\n", SWAP_2B_BEDN( eng->ncsi_rsp.Reason_Code ) & 0xff ); 367 } 368 else { 369 ret = 0; 370 } 371 } 372 else { 373 if ( eng->arg.ctrl.b.print_ncsi ) 374 PRINTF( FP_LOG, "[Frm-Skip] Not NCSI Response: [%08x & %08x = %08x]!=[%08x]\n", NCSI_RxData, 0xffff, NCSI_RxData & 0xffff, 0xf888 ); 375 } // End if ( ( NCSI_RxData & 0xffff ) == 0xf888 ) 376 377 if ( HWEOR( NCSI_RxDesDat ) ) { 378 // it is last the descriptor in the receive Ring 379 Write_Mem_Des_NCSI_DD( eng->run.ncsi_rdes_base , EOR_IniVal ); 380 eng->run.ncsi_rdes_base = eng->run.rdes_base;//base for read/write 381 } 382 else { 383 Write_Mem_Des_NCSI_DD( eng->run.ncsi_rdes_base , 0x00000000 ); 384 eng->run.ncsi_rdes_base += 16; 385 } 386 387 if ( ret == 0 ) 388 break; 389 retry++; 390 } while ( retry < NCSI_RxDESNum ); 391 392 if ( ( ret == 0 ) && eng->arg.ctrl.b.print_ncsi ) { 393 #ifdef Print_DetailFrame 394 ncsi_respdump ( eng, &eng->ncsi_rsp ); 395 #else 396 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", 397 SWAP_2B_BEDN( eng->ncsi_rsp.EtherType ), 398 eng->ncsi_rsp.MC_ID, 399 eng->ncsi_rsp.Header_Revision, 400 eng->ncsi_rsp.IID, 401 eng->ncsi_rsp.Command, 402 eng->ncsi_rsp.ChID, 403 SWAP_2B_BEDN( eng->ncsi_rsp.Payload_Length ), 404 SWAP_2B_BEDN( eng->ncsi_rsp.Response_Code ), 405 SWAP_2B_BEDN( eng->ncsi_rsp.Reason_Code )); 406 #endif 407 408 NCSI_PrintCommandType2File( eng, eng->ncsi_rsp.Command, eng->ncsi_rsp.IID ); 409 } 410 411 return( ret ); 412 } // End char NCSI_Rx_SLT (MAC_ENGINE *eng) 413 414 //------------------------------------------------------------ 415 char NCSI_Tx (MAC_ENGINE *eng, unsigned char command, unsigned char allid, uint16_t length) { 416 int bytesize; 417 int dwsize; 418 int i; 419 int timeout = 0; 420 uint32_t NCSI_TxDesDat; 421 422 eng->ncsi_req.IID++; 423 eng->ncsi_req.Command = command; 424 eng->ncsi_req.ChID = allid; 425 eng->ncsi_req.Payload_Length = SWAP_2B_BEDN( length ); 426 427 memcpy ( eng->dat.NCSI_TxByteBUF , &eng->ncsi_req , 30 ); 428 memcpy ( (eng->dat.NCSI_TxByteBUF + 30 ), &eng->dat.NCSI_Payload_Data , length ); 429 Calculate_Checksum_NCSI( eng, eng->dat.NCSI_TxByteBUF, 30 + length ); 430 memcpy ( (eng->dat.NCSI_TxByteBUF + 30 + length), &eng->dat.Payload_Checksum_NCSI, 4 ); 431 432 // Header of NC-SI command format is 34 bytes. page 58, NC-SI spec. ver 1.0.0 from DMTF 433 // The minimum size of a NC-SI package is 64 bytes. 434 bytesize = 34 + length; 435 if ( bytesize < 60 ) { 436 memset ( eng->dat.NCSI_TxByteBUF + bytesize, 0, 60 - bytesize ); 437 bytesize = 60; 438 } 439 440 // Fill up to multiple of 4 441 // dwsize = (bytesize + 3) >> 2; 442 if ( ( bytesize % 4 ) != 0 ) 443 dwsize = ( bytesize >> 2 ) + 1; 444 else 445 dwsize = bytesize >> 2; 446 447 if ( eng->arg.ctrl.b.print_ncsi ) { 448 if ( bytesize % 4 ) 449 memset ( eng->dat.NCSI_TxByteBUF + bytesize, 0, (dwsize << 2) - bytesize ); 450 451 PRINTF( FP_LOG ,"----->[Tx] %d bytes(%xh)\n", bytesize, bytesize ); 452 for ( i = 0; i < dwsize-1; i++ ) 453 PRINTF( FP_LOG, " [Tx]%02d:%08x %08x\n", i, eng->dat.NCSI_TxDWBUF[i], SWAP_4B( eng->dat.NCSI_TxDWBUF[i] ) ); 454 455 i = dwsize - 1; 456 switch ( bytesize % 4 ) { 457 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; 458 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; 459 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; 460 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; 461 default : PRINTF( FP_LOG ," [Tx]%02d:error", i ); break; 462 } 463 PRINTF( FP_LOG ,"[Frm-NCSI][Tx IID:%2d]\n", eng->ncsi_req.IID ); 464 } 465 466 #if 1 467 // Copy data to DMA buffer 468 for ( i = 0; i < dwsize; i++ ) 469 Write_Mem_Dat_NCSI_DD( DMA_BASE + ( i << 2 ), SWAP_4B_LEDN_NCSI( eng->dat.NCSI_TxDWBUF[i] ) ); 470 #endif 471 472 // Setting one TX descriptor 473 Write_Mem_Des_NCSI_DD( eng->run.ncsi_tdes_base , 0xf0008000 + bytesize ); 474 475 // mac_reg_write( eng, 0x40, eng->reg.MAC_040 ); // 20170505 476 477 // Fire 478 mac_reg_write( eng, 0x18, 0x00000000 );//Tx Poll 479 480 do { 481 NCSI_TxDesDat = Read_Mem_Des_NCSI_DD( eng->run.ncsi_tdes_base ); 482 if ( ++timeout > TIME_OUT_NCSI ) { 483 PRINTF( FP_LOG, "[TxDes] DesOwn timeout %08X\n", NCSI_TxDesDat ); 484 return( FindErr( eng, Err_Flag_NCSI_Check_TxOwnTimeOut )); 485 } 486 } while ( HWOwnTx( NCSI_TxDesDat ) ); 487 488 if ( eng->arg.ctrl.b.print_ncsi ) { 489 #ifdef Print_DetailFrame 490 ncsi_reqdump ( eng, &eng->ncsi_req ); 491 #else 492 PRINTF( FP_LOG, "[NCSI-Request] ETyp:%04x MC_ID:%02x HeadVer:%02x IID:%02x Comm:%02x ChlID:%02x PayLen:%04x\n", 493 SWAP_2B_BEDN( eng->ncsi_req.EtherType ), 494 eng->ncsi_req.MC_ID, 495 eng->ncsi_req.Header_Revision, 496 eng->ncsi_req.IID, 497 eng->ncsi_req.Command, 498 eng->ncsi_req.ChID, 499 SWAP_2B_BEDN( eng->ncsi_req.Payload_Length ) ); 500 #endif 501 502 NCSI_PrintCommandType2File( eng, eng->ncsi_req.Command, eng->ncsi_req.IID ); 503 } 504 #ifdef Print_PackageName 505 NCSI_PrintCommandType( eng, eng->ncsi_req.Command, eng->ncsi_req.IID ); 506 #endif 507 508 return(0); 509 } // End char NCSI_Tx (MAC_ENGINE *eng, unsigned char command, unsigned char allid, uint16_t length) 510 511 //------------------------------------------------------------ 512 char NCSI_ARP (MAC_ENGINE *eng) { 513 int i; 514 int timeout = 0; 515 uint32_t NCSI_TxDesDat; 516 517 if ( eng->arg.ctrl.b.print_ncsi ) 518 PRINTF( FP_LOG ,"----->[ARP] 60 bytes x%d\n", eng->arg.GARPNumCnt ); 519 520 for (i = 0; i < 15; i++) { 521 if ( eng->arg.ctrl.b.print_ncsi ) 522 PRINTF( FP_LOG, " [Tx%02d] %08x %08x\n", i, eng->dat.ARP_data[i], SWAP_4B( eng->dat.ARP_data[i] ) ); 523 524 Write_Mem_Dat_NCSI_DD(((uint32_t)&dma_buf) + ( i << 2 ), eng->dat.ARP_data[i] ); 525 } 526 527 // Write_Mem_Des_NCSI_DD( eng->run.ncsi_tdes_base + 0x04, 0 ); 528 // Write_Mem_Des_NCSI_DD( eng->run.ncsi_tdes_base + 0x08, 0 ); 529 // Write_Mem_Des_NCSI_DD( eng->run.ncsi_tdes_base + 0x0C, AT_MEMRW_BUF( DMA_BASE ) ); 530 for (i = 0; i < eng->arg.GARPNumCnt; i++) { 531 Write_Mem_Des_NCSI_DD( eng->run.ncsi_tdes_base , 0xf0008000 + 60); 532 mac_reg_write( eng, 0x18, 0x00000000 );//Tx Poll 533 534 do { 535 NCSI_TxDesDat = Read_Mem_Des_NCSI_DD( eng->run.ncsi_tdes_base ); 536 if ( ++timeout > TIME_OUT_NCSI ) { 537 PRINTF( FP_LOG, "[TxDes-ARP] DesOwn timeout %08x\n", NCSI_TxDesDat ); 538 return( FindErr( eng, Err_Flag_NCSI_Check_ARPOwnTimeOut ) ); 539 } 540 } while ( HWOwnTx( NCSI_TxDesDat ) ); 541 } 542 return(0); 543 } // End char NCSI_ARP (MAC_ENGINE *eng) 544 545 //------------------------------------------------------------ 546 char NCSI_SentWaitPacket (MAC_ENGINE *eng, unsigned char command, unsigned char allid, uint16_t length) { 547 int Retry = 0; 548 549 do { 550 if ( NCSI_Tx( eng, command, allid, length ) ) 551 return( 1 ); 552 553 #ifdef NCSI_EnableDelay_EachPackage 554 DELAY( Delay_EachPackage ); 555 #endif 556 if ( NCSI_Rx_SLT( eng ) ) 557 return( 2 ); 558 559 if ( ( eng->ncsi_rsp.IID != eng->ncsi_req.IID ) 560 || ( eng->ncsi_rsp.Command != ( command | 0x80 ) ) 561 || ( eng->ncsi_rsp.Response_Code != SWAP_2B_BEDN( COMMAND_COMPLETED ) ) ) { 562 if ( eng->arg.ctrl.b.print_ncsi ) { 563 PRINTF( FP_LOG, "Retry: Command = %x, Response_Code = %x", eng->ncsi_req.Command, SWAP_2B_BEDN( eng->ncsi_rsp.Response_Code ) ); 564 switch ( SWAP_2B_BEDN( eng->ncsi_rsp.Response_Code ) ) { 565 case COMMAND_COMPLETED : PRINTF( FP_LOG, "(completed )\n" ); break; 566 case COMMAND_FAILED : PRINTF( FP_LOG, "(failed )\n" ); break; 567 case COMMAND_UNAVAILABLE : PRINTF( FP_LOG, "(unavailable)\n" ); break; 568 case COMMAND_UNSUPPORTED : PRINTF( FP_LOG, "(unsupported)\n" ); break; 569 default : PRINTF( FP_LOG, "(-----------)\n" ); break; 570 } 571 } 572 Retry++; 573 } 574 else { 575 return( 0 ); 576 } 577 } while (Retry <= SENT_RETRY_COUNT); 578 579 return( 3 ); 580 } // End char NCSI_SentWaitPacket (unsigned char command, unsigned char id, uint16_t length) 581 582 //------------------------------------------------------------ 583 char Clear_Initial_State_SLT (MAC_ENGINE *eng) {//Command:0x00 584 char return_value; 585 586 eng->flg.error_backup = eng->flg.error; 587 eng->flg.ncsi_backup = eng->flg.ncsi; 588 589 return_value = NCSI_SentWaitPacket( eng, CLEAR_INITIAL_STATE, eng->ncsi_cap.All_ID, 0 );//Internal Channel ID = 0 590 591 eng->flg.error = eng->flg.error_backup; 592 eng->flg.ncsi = eng->flg.ncsi_backup; 593 return( return_value );//Internal Channel ID = 0 594 } 595 596 //------------------------------------------------------------ 597 char Select_Package_SLT (MAC_ENGINE *eng, char skipflag) {//Command:0x01 598 char return_value; 599 600 if ( skipflag ) { 601 eng->flg.error_backup = eng->flg.error; 602 eng->flg.ncsi_backup = eng->flg.ncsi; 603 } 604 605 memset ((void *)eng->dat.NCSI_Payload_Data, 0, 4); 606 eng->dat.NCSI_Payload_Data[ 3 ] = 1; //Arbitration Disable 607 return_value = NCSI_SentWaitPacket( eng, SELECT_PACKAGE, ( eng->ncsi_cap.Package_ID << 5 ) + 0x1F, 4 );//Internal Channel ID = 0x1F, 0x1F means all channel 608 if ( return_value ) 609 ncsi_set_error_flag( eng, NCSI_Flag_Select_Package ); 610 611 if ( skipflag ) { 612 eng->flg.error = eng->flg.error_backup; 613 eng->flg.ncsi = eng->flg.ncsi_backup; 614 } 615 return( return_value ); 616 } 617 618 //------------------------------------------------------------ 619 void Select_Active_Package_SLT (MAC_ENGINE *eng) {//Command:0x01 620 memset ((void *)eng->dat.NCSI_Payload_Data, 0, 4); 621 eng->dat.NCSI_Payload_Data[ 3 ] = 1; //Arbitration Disable 622 623 if ( NCSI_SentWaitPacket( eng, SELECT_PACKAGE, ( eng->ncsi_cap.Package_ID << 5 ) + 0x1F, 4 ) ) //Internal Channel ID = 0x1F, 0x1F means all channel 624 ncsi_set_error_flag( eng, NCSI_Flag_Select_Active_Package ); 625 } 626 627 //------------------------------------------------------------ 628 void DeSelect_Package_SLT (MAC_ENGINE *eng) {//Command:0x02 629 if ( NCSI_SentWaitPacket( eng, DESELECT_PACKAGE, ( eng->ncsi_cap.Package_ID << 5 ) + 0x1F, 0 ) ) //Internal Channel ID = 0x1F, 0x1F means all channel 630 ncsi_set_error_flag( eng, NCSI_Flag_Deselect_Package ); 631 632 #ifdef NCSI_EnableDelay_DeSelectPackage 633 DELAY( Delay_DeSelectPackage ); 634 #endif 635 } 636 637 //------------------------------------------------------------ 638 void Enable_Channel_SLT (MAC_ENGINE *eng) {//Command:0x03 639 if ( NCSI_SentWaitPacket( eng, ENABLE_CHANNEL, eng->ncsi_cap.All_ID, 0 ) ) 640 ncsi_set_error_flag( eng, NCSI_Flag_Enable_Channel ); 641 } 642 643 //------------------------------------------------------------ 644 void Disable_Channel_SLT (MAC_ENGINE *eng, char skipflag) {//Command:0x04 645 if ( skipflag ) { 646 eng->flg.error_backup = eng->flg.error; 647 eng->flg.ncsi_backup = eng->flg.ncsi; 648 } 649 650 memset ((void *)eng->dat.NCSI_Payload_Data, 0, 4); 651 eng->dat.NCSI_Payload_Data[ 3 ] = 0x1; //ALD 652 if ( NCSI_SentWaitPacket( eng, DISABLE_CHANNEL, eng->ncsi_cap.All_ID, 4 ) ) 653 ncsi_set_error_flag( eng, NCSI_Flag_Disable_Channel ); 654 655 if ( skipflag ) { 656 eng->flg.error = eng->flg.error_backup; 657 eng->flg.ncsi = eng->flg.ncsi_backup; 658 } 659 } 660 661 //------------------------------------------------------------ 662 void Enable_Network_TX_SLT (MAC_ENGINE *eng) {//Command:0x06 663 if ( NCSI_SentWaitPacket( eng, ENABLE_CHANNEL_NETWORK_TX, eng->ncsi_cap.All_ID, 0 ) ) 664 ncsi_set_error_flag( eng, NCSI_Flag_Enable_Network_TX ); 665 } 666 667 //------------------------------------------------------------ 668 void Disable_Network_TX_SLT (MAC_ENGINE *eng) {//Command:0x07 669 if ( NCSI_SentWaitPacket( eng, DISABLE_CHANNEL_NETWORK_TX, eng->ncsi_cap.All_ID, 0 ) ) 670 ncsi_set_error_flag( eng, NCSI_Flag_Disable_Network_TX ); 671 } 672 673 //------------------------------------------------------------ 674 void Set_Link_SLT (MAC_ENGINE *eng) {//Command:0x09 675 memset ((void *)eng->dat.NCSI_Payload_Data, 0, 8); 676 eng->dat.NCSI_Payload_Data[ 2 ] = 0x02; //full duplex 677 // eng->dat.NCSI_Payload_Data[ 3 ] = 0x04; //100M, auto-disable 678 eng->dat.NCSI_Payload_Data[ 3 ] = 0x05; //100M, auto-enable 679 680 if ( NCSI_SentWaitPacket( eng, SET_LINK, eng->ncsi_cap.All_ID, 8 ) ) 681 ncsi_set_error_flag( eng, NCSI_Flag_Set_Link ); 682 } 683 684 //------------------------------------------------------------ 685 char Get_Link_Status_SLT (MAC_ENGINE *eng) {//Command:0x0a 686 if ( NCSI_SentWaitPacket( eng, GET_LINK_STATUS, eng->ncsi_cap.All_ID, 0 ) ) 687 return(0); 688 else { 689 if ( eng->ncsi_rsp.Payload_Data[ 3 ] & 0x20 ) { 690 if ( eng->ncsi_rsp.Payload_Data[ 3 ] & 0x40 ) { 691 if ( eng->ncsi_rsp.Payload_Data[ 3 ] & 0x01 ) 692 return(1); //Link Up or Not 693 else 694 return(0); 695 } 696 else 697 return(0); //Auto Negotiate did not finish 698 } 699 else { 700 if ( eng->ncsi_rsp.Payload_Data[ 3 ] & 0x01 ) 701 return(1); //Link Up or Not 702 else 703 return(0); 704 } 705 } 706 } // End char Get_Link_Status_SLT (MAC_ENGINE *eng) 707 708 //------------------------------------------------------------ 709 void Enable_Set_MAC_Address_SLT (MAC_ENGINE *eng) 710 { 711 //Command:0x0e 712 713 int i; 714 715 for ( i = 0; i < 6; i++ ) 716 eng->dat.NCSI_Payload_Data[ i ] = eng->ncsi_req.SA[ i ]; 717 eng->dat.NCSI_Payload_Data[ 6 ] = 1; //MAC Address Num = 1 --> address filter 1, fixed in sample code 718 719 if ( eng->ncsi_req.SA[ 0 ] & 0x1 ) 720 eng->dat.NCSI_Payload_Data[ 7 ] = MULTICAST + ENABLE_MAC_ADDRESS_FILTER; //AT + E 721 else 722 eng->dat.NCSI_Payload_Data[ 7 ] = UNICAST + ENABLE_MAC_ADDRESS_FILTER; //AT + E 723 724 if ( NCSI_SentWaitPacket( eng, SET_MAC_ADDRESS, eng->ncsi_cap.All_ID, 8 ) ) 725 ncsi_set_error_flag( eng, NCSI_Flag_Enable_Set_MAC_Address ); 726 } 727 728 //------------------------------------------------------------ 729 void Enable_Broadcast_Filter_SLT (MAC_ENGINE *eng) {//Command:0x10 730 memset ((void *)eng->dat.NCSI_Payload_Data, 0, 4); 731 eng->dat.NCSI_Payload_Data[ 3 ] = 0xF; //ARP, DHCP, NetBIOS 732 733 if ( NCSI_SentWaitPacket( eng, ENABLE_BROADCAST_FILTERING, eng->ncsi_cap.All_ID, 4 ) ) 734 ncsi_set_error_flag( eng, NCSI_Flag_Enable_Broadcast_Filter ); 735 } 736 737 //------------------------------------------------------------ 738 void Get_Version_ID_SLT (MAC_ENGINE *eng) {//Command:0x15 739 if ( NCSI_SentWaitPacket( eng, GET_VERSION_ID, eng->ncsi_cap.All_ID, 0 ) ) 740 ncsi_set_error_flag( eng, NCSI_Flag_Get_Version_ID ); 741 else { 742 #ifdef Print_Version_ID 743 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 ]); 744 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 ]); 745 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 ]); 746 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 ]); 747 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 ]); 748 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 ]); 749 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 ]); 750 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 ]); 751 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 ]); 752 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 ]); 753 #endif 754 eng->ncsi_cap.PCI_DID_VID = (eng->ncsi_rsp.Payload_Data[ 24 ]<<24) 755 | (eng->ncsi_rsp.Payload_Data[ 25 ]<<16) 756 | (eng->ncsi_rsp.Payload_Data[ 26 ]<< 8) 757 | (eng->ncsi_rsp.Payload_Data[ 27 ] ); 758 eng->ncsi_cap.manufacturer_id = (eng->ncsi_rsp.Payload_Data[ 32 ]<<24) 759 | (eng->ncsi_rsp.Payload_Data[ 33 ]<<16) 760 | (eng->ncsi_rsp.Payload_Data[ 34 ]<< 8) 761 | (eng->ncsi_rsp.Payload_Data[ 35 ] ); 762 } 763 } // End void Get_Version_ID_SLT (MAC_ENGINE *eng) 764 765 //------------------------------------------------------------ 766 void Get_Capabilities_SLT (MAC_ENGINE *eng) {//Command:0x16 767 if ( NCSI_SentWaitPacket( eng, GET_CAPABILITIES, eng->ncsi_cap.All_ID, 0 ) ) 768 ncsi_set_error_flag( eng, NCSI_Flag_Get_Capabilities ); 769 else { 770 // eng->ncsi_cap.Capabilities_Flags = (eng->ncsi_rsp.Payload_Data[ 0 ]<<24) 771 // | (eng->ncsi_rsp.Payload_Data[ 1 ]<<16) 772 // | (eng->ncsi_rsp.Payload_Data[ 2 ]<< 8) 773 // | (eng->ncsi_rsp.Payload_Data[ 3 ] ); 774 // eng->ncsi_cap.Broadcast_Packet_Filter_Capabilities = (eng->ncsi_rsp.Payload_Data[ 4 ]<<24) 775 // | (eng->ncsi_rsp.Payload_Data[ 5 ]<<16) 776 // | (eng->ncsi_rsp.Payload_Data[ 6 ]<< 8) 777 // | (eng->ncsi_rsp.Payload_Data[ 7 ] ); 778 // eng->ncsi_cap.Multicast_Packet_Filter_Capabilities = (eng->ncsi_rsp.Payload_Data[ 8 ]<<24) 779 // | (eng->ncsi_rsp.Payload_Data[ 9 ]<<16) 780 // | (eng->ncsi_rsp.Payload_Data[ 10 ]<< 8) 781 // | (eng->ncsi_rsp.Payload_Data[ 11 ] ); 782 // eng->ncsi_cap.Buffering_Capabilities = (eng->ncsi_rsp.Payload_Data[ 12 ]<<24) 783 // | (eng->ncsi_rsp.Payload_Data[ 13 ]<<16) 784 // | (eng->ncsi_rsp.Payload_Data[ 14 ]<< 8) 785 // | (eng->ncsi_rsp.Payload_Data[ 15 ] ); 786 // eng->ncsi_cap.AEN_Control_Support = (eng->ncsi_rsp.Payload_Data[ 16 ]<<24) 787 // | (eng->ncsi_rsp.Payload_Data[ 17 ]<<16) 788 // | (eng->ncsi_rsp.Payload_Data[ 18 ]<< 8) 789 // | (eng->ncsi_rsp.Payload_Data[ 19 ] ); 790 // eng->ncsi_cap.VLAN_Filter_Count = eng->ncsi_rsp.Payload_Data[ 20 ]; 791 eng->ncsi_cap.Mixed_Filter_Count = eng->ncsi_rsp.Payload_Data[ 21 ]; 792 // eng->ncsi_cap.Multicast_Filter_Count = eng->ncsi_rsp.Payload_Data[ 22 ]; 793 eng->ncsi_cap.Unicast_Filter_Count = eng->ncsi_rsp.Payload_Data[ 23 ]; 794 // eng->ncsi_cap.VLAN_Mode_Support = eng->ncsi_rsp.Payload_Data[ 26 ] 795 eng->ncsi_cap.Channel_Count = eng->ncsi_rsp.Payload_Data[ 27 ]; 796 } 797 } 798 799 //------------------------------------------------------------ 800 void Get_Controller_Packet_Statistics_SLT (MAC_ENGINE *eng) {//Command:0x18 801 if ( NCSI_SentWaitPacket( eng, GET_CONTROLLER_PACKET_STATISTICS, eng->ncsi_cap.All_ID, 0 ) ) 802 ncsi_set_error_flag( eng, NCSI_Flag_Get_Controller_Packet_Statistics ); 803 } 804 805 //------------------------------------------------------------ 806 char phy_ncsi (MAC_ENGINE *eng) 807 { 808 uint32_t pkg_idx; 809 uint32_t chl_idx; 810 uint32_t select_flag[MAX_PACKAGE_NUM]; 811 uint32_t Re_Send; 812 uint32_t Link_Status; 813 814 eng->dat.NCSI_RxEr = 0; 815 eng->dat.number_chl = 0; 816 eng->dat.number_pak = 0; 817 eng->ncsi_cap.Package_ID = 0; 818 eng->ncsi_cap.Channel_ID = 0x1F; 819 eng->ncsi_cap.All_ID = 0x1F; 820 PRINTF(FP_LOG, "\n\n======> Start:\n"); 821 822 NCSI_Struct_Initialize_SLT(eng); 823 824 #ifdef NCSI_Skip_Phase1_DeSelectPackage 825 #else 826 //NCSI Start 827 //Disable Channel then DeSelect Package 828 for (pkg_idx = 0; pkg_idx < MAX_PACKAGE_NUM; pkg_idx++) { 829 eng->ncsi_cap.Package_ID = pkg_idx; 830 eng->ncsi_cap.Channel_ID = 0x1F; 831 eng->ncsi_cap.All_ID = ( eng->ncsi_cap.Package_ID << 5) + eng->ncsi_cap.Channel_ID; 832 833 select_flag[ pkg_idx ] = Select_Package_SLT ( eng, 1 ); //skipflag// Command:0x01 834 835 if ( select_flag[ pkg_idx ] == 0 ) { 836 if ( !eng->run.IO_MrgChk ) { 837 printf("----Find Package ID: %d\n", eng->ncsi_cap.Package_ID); 838 PRINTF(FP_LOG, "----Find Package ID: %d\n", eng->ncsi_cap.Package_ID ); 839 } 840 for ( chl_idx = 0; chl_idx < MAX_CHANNEL_NUM; chl_idx++ ) { 841 eng->ncsi_cap.Channel_ID = chl_idx; 842 eng->ncsi_cap.All_ID = ( eng->ncsi_cap.Package_ID << 5) + eng->ncsi_cap.Channel_ID; 843 844 Disable_Channel_SLT( eng, 1 );//skipflag // Command: 0x04 845 } 846 #ifdef NCSI_Skip_DeSelectPackage 847 #else 848 DeSelect_Package_SLT ( eng ); // Command:0x02 849 #endif 850 } else { 851 if ( !eng->run.IO_MrgChk ) { 852 printf("----Absence of Package ID: %d\n", pkg_idx); 853 PRINTF( FP_LOG, "----Absence of Package ID: %d\n", pkg_idx ); 854 } 855 } // End if ( select_flag[ pkg_idx ] == 0 ) 856 } // End for (pkg_idx = 0; pkg_idx < MAX_PACKAGE_NUM; pkg_idx++) 857 #endif 858 859 //Select Package 860 for ( pkg_idx = 0; pkg_idx < MAX_PACKAGE_NUM; pkg_idx++ ) { 861 eng->ncsi_cap.Package_ID = pkg_idx; 862 eng->ncsi_cap.Channel_ID = 0x1F; 863 eng->ncsi_cap.All_ID = ( eng->ncsi_cap.Package_ID << 5) + eng->ncsi_cap.Channel_ID; 864 865 #ifdef NCSI_Skip_Phase1_DeSelectPackage 866 select_flag[ pkg_idx ] = Select_Package_SLT ( eng, 1 ); //skipflag//Command:0x01 867 #endif 868 869 if ( select_flag[ pkg_idx ] == 0 ) { 870 //eng->run.NCSI_RxTimeOutScale = 1000; 871 eng->run.NCSI_RxTimeOutScale = 10; 872 873 #ifdef NCSI_Skip_Phase1_DeSelectPackage 874 #else 875 Select_Package_SLT ( eng, 0 );//Command:0x01 876 #endif 877 eng->dat.number_pak++; 878 if ( !eng->run.IO_MrgChk ) { 879 printf("====Find Package ID: %d\n", eng->ncsi_cap.Package_ID); 880 PRINTF(FP_LOG, "====Find Package ID: %d\n", eng->ncsi_cap.Package_ID ); 881 } 882 883 // Scan all channel in the package 884 for ( chl_idx = 0; chl_idx < MAX_CHANNEL_NUM; chl_idx++ ) { 885 eng->ncsi_cap.Channel_ID = chl_idx; 886 eng->ncsi_cap.All_ID = ( eng->ncsi_cap.Package_ID << 5) + eng->ncsi_cap.Channel_ID; 887 888 if ( Clear_Initial_State_SLT( eng ) == 0 ) { //Command:0x00 889 eng->dat.number_chl++; 890 if ( !eng->run.IO_MrgChk ) { 891 printf("--------Find Channel ID: %d\n", eng->ncsi_cap.Channel_ID); 892 PRINTF( FP_LOG, "--------Find Channel ID: %d\n", eng->ncsi_cap.Channel_ID ); 893 } 894 895 // Get Version and Capabilities 896 Get_Version_ID_SLT( eng ); //Command:0x15 897 Get_Capabilities_SLT( eng ); //Command:0x16 898 Select_Active_Package_SLT( eng ); //Command:0x01 899 Enable_Set_MAC_Address_SLT( eng ); //Command:0x0e 900 Enable_Broadcast_Filter_SLT( eng ); //Command:0x10 901 902 // Enable TX 903 Enable_Network_TX_SLT( eng ); //Command:0x06 904 905 // Enable Channel 906 Enable_Channel_SLT( eng ); //Command:0x03 907 908 // Get Link Status 909 Re_Send = 0; 910 do { 911 #ifdef NCSI_EnableDelay_GetLinkStatus 912 if ( Re_Send ) 913 DELAY( Delay_GetLinkStatus ); 914 #endif 915 916 Link_Status = Get_Link_Status_SLT( eng );//Command:0x0a 917 if ( Link_Status == LINK_UP ) { 918 if ( eng->arg.GARPNumCnt ) 919 NCSI_ARP ( eng ); 920 break; 921 } // End if ( Link_Status == LINK_UP ) 922 } while ( Re_Send++ <= 2 ); 923 924 if ( !eng->run.IO_MrgChk ) { 925 if ( Link_Status == LINK_UP ) { 926 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); 927 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); 928 } 929 else { 930 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); 931 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); 932 } 933 } 934 935 #ifdef NCSI_Skip_DiSChannel 936 #else 937 if ( eng->run.TM_NCSI_DiSChannel ) { 938 // Disable TX 939 Disable_Network_TX_SLT( eng ); //Command:0x07 940 // Disable Channel 941 Disable_Channel_SLT( eng, 0 ); //Command:0x04 942 } 943 #endif 944 } // End if ( Clear_Initial_State_SLT( eng, chl_idx ) == 0 ) 945 } // End for ( chl_idx = 0; chl_idx < MAX_CHANNEL_NUM; chl_idx++ ) 946 947 #ifdef NCSI_Skip_DeSelectPackage 948 #else 949 DeSelect_Package_SLT ( eng );//Command:0x02 950 #endif 951 eng->run.NCSI_RxTimeOutScale = 1; 952 } 953 else { 954 if ( !eng->run.IO_MrgChk ) { 955 printf("====Absence of Package ID: %d\n", pkg_idx); 956 PRINTF( FP_LOG, "====Absence of Package ID: %d\n", pkg_idx ); 957 } 958 } // End if ( select_flag[pkg_idx] == 0 ) 959 } // End for ( pkg_idx = 0; pkg_idx < MAX_PACKAGE_NUM; pkg_idx++ ) 960 961 if ( eng->dat.number_pak == 0 ) FindErr( eng, Err_Flag_NCSI_No_PHY ); 962 if ( eng->dat.number_pak != eng->arg.GPackageTolNum ) FindErr( eng, Err_Flag_NCSI_Package_Num ); 963 if ( eng->dat.number_chl != eng->arg.GChannelTolNum ) FindErr( eng, Err_Flag_NCSI_Channel_Num ); 964 // if ( eng->dat.number_chl == 0 ) FindErr( eng ); 965 966 if ( eng->flg.error ) { 967 if ( eng->dat.NCSI_RxEr ) 968 FindErr_Des( eng, Des_Flag_RxErr ); 969 return(1); 970 } 971 else { 972 if ( eng->dat.NCSI_RxEr ) { 973 eng->flg.warn = eng->flg.warn | Wrn_Flag_RxErFloatting; 974 if ( eng->arg.ctrl.b.skip_rx_err ) { 975 eng->flg.all_fail = 0; 976 return(0); 977 } 978 else { 979 FindErr_Des( eng, Des_Flag_RxErr ); 980 return(1); 981 } 982 } 983 else { 984 eng->flg.all_fail = 0; 985 return(0); 986 } 987 } 988 } 989