int crash_dump_msr()

in meta-facebook/meta-fbttn/recipes-fbttn/me-util/files/me-util.c [61:245]


int crash_dump_msr(void) {
  FILE *fp = NULL;
  int processorid = 0, retry = 0, response = 0, comp = 1,
  mc_index = 0, msr_offset = 0;
  uint16_t param, param0, param1, cmdout;
  uint8_t slot_id = 1;
  uint8_t tbuf[256] = {0x00};
  uint8_t rbuf[256] = {0x00};
  uint8_t tlen = 0;
  uint8_t rlen = 0;
  uint8_t check; //for check 4th response data
  int i = 0;

  fp = fopen(CRASHDUMP_FILE, "a+");
  if (!fp) {
      printf("File open Fail\n");
      return -1;
    }
  fprintf(fp, "\n");
  fprintf(fp, "%s\n", "MSR DUMP:");
  fprintf(fp, "%s\n", "=========");
  fprintf(fp, "\n");

  while( mc_index <= MAX_MC_IDX ) {
    fprintf(fp, "********************************************************\n");
    fprintf(fp, "*                    MC index %02d                       *\n", mc_index);
    fprintf(fp, "********************************************************\n");

//////////////////////////////////////////////////////////////////////////////////////////////////////////
    fprintf(fp, "   <<< IA32_MC%d_CTL, ProcessorID from 0 to %d >>> \n", mc_index, MAX_PROC_ID);
    processorid = 0;
    retry = 0;
    while( processorid <= MAX_PROC_ID ) {
      param = IA32_MC_CTL_base + msr_offset;
      param0 = ( param & 0xFF );
      param1 = ( param >> 8 );

      tbuf[0] = 0xB8;
      tbuf[1] = 0x40;
      tbuf[2] = 0x57;
      tbuf[3] = 0x01;
      tbuf[4] = 0x00;
      tbuf[5] = 0x30;
      tbuf[6] = 0x05;
      tbuf[7] = 0x09;
      tbuf[8] = 0xb1;
      tbuf[9] = 0x00;
      tbuf[10] = processorid;
      tbuf[11] = param0;
      tbuf[12] = param1;
      tlen = 13;
      comp = bic_me_xmit(slot_id, tbuf, tlen, rbuf, &rlen);
      check = rbuf[3];
      if( (( check == 0x80 ) || ( check = 0x81 ) || ( check == 0x81 ) || ( comp != 0 )) &&  ( retry < MAX_RETRY ) ) {
        retry++;
        sleep(1);
      }
      else {
        for ( i = 0 ; i < rlen ; i ++ )
          fprintf(fp, "%02X ", rbuf[i]);
        fprintf(fp, "\n");
        processorid++;
        retry = 0;
      }
    }

//////////////////////////////////////////////////////////////////////////////////////////////////////////
    fprintf(fp, "   <<< IA32_MC%d_CTL2, ProcessorID from 0 to %d >>> \n", mc_index, MAX_PROC_ID);
    processorid = 0;
    retry = 0;
    while( processorid <= MAX_PROC_ID ) {
      param = IA32_MC_CTL2_base + mc_index;
      param0 = ( param & 0xFF );
      param1 = ( param >> 8 );

      tbuf[10] = processorid;
      tbuf[11] = param0;
      tbuf[12] = param1;

      comp = bic_me_xmit(slot_id, tbuf, tlen, rbuf, &rlen);
      check = rbuf[3];
      if( (( check == 0x80 ) || ( check = 0x81 ) || ( check == 0x81 ) || ( comp != 0 )) &&  ( retry < MAX_RETRY ) ) {
        retry++;
        sleep(1);
      }
      else {
        for ( i = 0 ; i < rlen ; i ++ )
          fprintf(fp, "%02X ", rbuf[i]);
        fprintf(fp, "\n");
        processorid++;
        retry = 0;
      }
    }

//////////////////////////////////////////////////////////////////////////////////////////////////////////
    fprintf(fp, "   <<< IA32_MC%d_STATUS, ProcessorID from 0 to %d >>> \n", mc_index, MAX_PROC_ID);
    processorid = 0;
    retry = 0;
    while( processorid <= MAX_PROC_ID ) {
      param = IA32_MC_STATUS_base + msr_offset;
      param0 = ( param & 0xFF );
      param1 = ( param >> 8 );

      tbuf[10] = processorid;
      tbuf[11] = param0;
      tbuf[12] = param1;

      comp = bic_me_xmit(slot_id, tbuf, tlen, rbuf, &rlen);
      check = rbuf[3];
      if( (( check == 0x80 ) || ( check = 0x81 ) || ( check == 0x81 ) || ( comp != 0 )) &&  ( retry < MAX_RETRY ) ) {
        retry++;
        sleep(1);
      }
      else {
        for ( i = 0 ; i < rlen ; i ++ )
          fprintf(fp, "%02X ", rbuf[i]);
        fprintf(fp, "\n");
        processorid++;
        retry = 0;
      }
    }

//////////////////////////////////////////////////////////////////////////////////////////////////////////
    fprintf(fp, "   <<< IA32_MC%d_ADDR, ProcessorID from 0 to %d >>> \n", mc_index, MAX_PROC_ID);
    processorid = 0;
    retry = 0;
    while( processorid <= MAX_PROC_ID ) {
      param = IA32_MC_ADDR_base + msr_offset;
      param0 = ( param & 0xFF );
      param1 = ( param >> 8 );

      tbuf[10] = processorid;
      tbuf[11] = param0;
      tbuf[12] = param1;

      comp = bic_me_xmit(slot_id, tbuf, tlen, rbuf, &rlen);
      check = rbuf[3];
      if( (( check == 0x80 ) || ( check = 0x81 ) || ( check == 0x81 ) || ( comp != 0 )) &&  ( retry < MAX_RETRY ) ) {
        retry++;
        sleep(1);
      }
      else {
        for ( i = 0 ; i < rlen ; i ++ )
          fprintf(fp, "%02X ", rbuf[i]);
        fprintf(fp, "\n");
        processorid++;
        retry = 0;
      }
    }

//////////////////////////////////////////////////////////////////////////////////////////////////////////
    fprintf(fp, "   <<< IA32_MC%d_MISC, ProcessorID from 0 to %d >>> \n", mc_index, MAX_PROC_ID);
    processorid = 0;
    retry = 0;
    while( processorid <= MAX_PROC_ID ) {
      param = IA32_MC_MISC_base + msr_offset;
      param0 = ( param & 0xFF );
      param1 = ( param >> 8 );

      tbuf[10] = processorid;
      tbuf[11] = param0;
      tbuf[12] = param1;

      comp = bic_me_xmit(slot_id, tbuf, tlen, rbuf, &rlen);
      check = rbuf[3];
      if( (( check == 0x80 ) || ( check = 0x81 ) || ( check == 0x81 ) || ( comp != 0 )) &&  ( retry < MAX_RETRY ) ) {
        retry++;
        sleep(1);
      }
      else {
        for ( i = 0 ; i < rlen ; i ++ )
          fprintf(fp, "%02X ", rbuf[i]);
        fprintf(fp, "\n");
        processorid++;
        retry = 0;
      }
    }

    mc_index++;
    msr_offset+4;
  }

  fclose(fp);
  return 0;
}