rdp.c 12.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419
/*
 * rdp.c - rdp diagnostics
 */
#include <sys/types.h>
#ifdef __sgi__
#include <sys/sbd.h>
#endif
#include <sys/stat.h>
#include <sys/mman.h>
#ifdef __sgi__
#include <sys/sema.h>
#endif
#include <netinet/in.h>

#include <errno.h>
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <getopt.h>
#include <rcp.h>

/*
 * From $ROOT/usr/include/ide, which is installed from $ROOT/PR/diags/include
 */
#include "diag.h"
#include "dbg_comm.h"

/*
 * Constants
 */
#define RDP_TEST_BASE	10

/* cmd registers test */
#define STATUS_REG_MSK  	0x000007ff
#define BUFBUSY_REG_MSK 	0x00ffffff
#define TMEM_REG_MSK    	0x00ffffff
#define START_REG_MSK   	0x00ffffff
#define END_REG_MSK     	0x00ffffff
#define CURRENT_REG_MSK 	0x00ffffff

/* spanbuf test */
#define SPANBUF_DEPTH 		16
#define BUFTEST_ADDR_MSK 	0x0000007f
#define BUFTEST_DATA_MSK 	0x000000ff
#define TEST_MODE_REG_MSK 	0x00000001

/* tmembist test */
#define TBIST_REG_MSK	 	0x000007ff

/*
 * Local function prototypes
 */
static int rdpInit(void);
static int rdpDo(TEST_REF *test_ref);

static int rdp_cmdreg(void);

static int rdp_spanbuf(void);
static int spanbufWriteWord(unsigned pattern, unsigned adrs, unsigned bank);
static int spanbufTestWord(unsigned pattern, unsigned adrs, unsigned bank);

static int rdp_tmembist(void);


/*
 * Global Variables
 */

/*
 * Create an array of tests, each of which corresponds to a separate menu
 * item callable from the master ide menu.
 */
static TEST_REF TestRefs[] = {
    {"RDP CMD Registers test", RDP_TEST_BASE+0, rdp_cmdreg},
    {"RDP SPANBUF test", RDP_TEST_BASE+10, rdp_spanbuf},
    {"RDP TMEMBIST test", RDP_TEST_BASE+20, rdp_tmembist},
    {"END OF TESTS",0,0}
};

static int NumFailures = 0;


/*
 * diagnostic entry point:
 *
 * Each separately invokable ide diagnostic command corresponds to an
 * independent ".c" module; the entry point herein must match
 * the test name as specified in the rdpcmd.awk script.  These command
 * names correspond to the names you see from the ide menu.  For this
 * module, there will be an ide command "rdp".
 */
int rdpEntry()
{
    int c;
    int testNum;

    /*
     * parse command line args received from ide
     */
    while ((c = getopt(pGlobalComm->argc, pGlobalComm->argv, "ht:")) != EOF) 
    {
	switch(c) 
     	{
	    case 'h':
		/*
		 * Print out the available subtests, then return without
		 * invoking any subtests.
		 */
		dgListSubTests(TestRefs);
		return(0);
		break;
	    case 't':
		testNum = atoi(optarg);
		pGlobalComm->entryNum = -(testNum);
		break;
	    default:
		printf("weird option character %c = 0x%x\n", c, c);
		break;
        }
    }

    /*
     * IDE will call our one-time initialization function rdpInit(),
     * then invoke rdpDo() for as many tests as we've put into the
     * global test array "TestRefs", declared at the top of this module.
     */
    diaginit(TestRefs, rdpInit, rdpDo);

    if (NumFailures) {
        errlog(INFO_END, "... test %s FAILED, %d failures.",
            ideTestName, NumFailures);
    } else {
	errlog(INFO_END, "... test %s PASSED", ideTestName);
    }
}

static int rdpInit()
{

    errlog(INFO_START, "Starting test %s ... ", ideTestName);
    NumFailures = 0;

    /*
     * Setup the diagnostic communication link to the target system.
     *
     * (this uses the global ide variable "commtype", which by default
     * is set to DG_VERILOG.)
     */
    dgInitComm();

    return(0);
}

static int rdpDo(TEST_REF *test_ref)
{
    int rc;

    errlog(INFO_START, 
      "%s: starting subtest %s (%d) ...",
      ideTestName, test_ref->name, test_ref->num);

    /*
     * Invoke the actual test from the "TEST_REF" array statically declared
     * as a global within this test module.
     */
    if (rc = test_ref->fnc()) NumFailures++;

    if (rc == 0) {
	errlog(INFO_END, "... PASSED");
    } else { 
	errlog(INFO_END, "... FAILED");
    }
    return(NumFailures);
}

int rdp_cmdreg(void)
{
   int errcount = 0;

   /* status register: read/check */
   errcount += dgRdTestWordMsk(DPC_STATUS_REG, 0x000000a8, STATUS_REG_MSK);

   /* status register: set xbus, dmem, freeze; clear start_gclk */
   errcount += dgWriteWord(DPC_STATUS_REG, 0x0000002a);
   errcount += dgRdTestWordMsk(DPC_STATUS_REG, 0x000000a7, STATUS_REG_MSK);

   /* status register: clear xbus, dmem, freeze; set start_gclk */
   errcount += dgWriteWord(DPC_STATUS_REG, 0x00000015);
   errcount += dgRdTestWordMsk(DPC_STATUS_REG, 0x000000a8, STATUS_REG_MSK);

   /* status register: clear counters */
   errcount += dgWriteWord(DPC_STATUS_REG, 0x000003c0);

   /* read buffer-busy counter and tmem-load counter */
   errcount += dgRdTestWordMsk(DPC_BUFBUSY_REG, 0x00000000, BUFBUSY_REG_MSK);
   errcount += dgRdTestWordMsk(DPC_TMEM_REG, 0x00000000, TMEM_REG_MSK);

   /* DMA start/end/current registers. also check start_valid status bit. */
   errcount += dgTestRegMsk(DPC_START_REG, 0x00aaaaaa, 0x00aaaaa8, START_REG_MSK);
   errcount += dgRdTestWordMsk(DPC_STATUS_REG, 0x000004a8, STATUS_REG_MSK);
   errcount += dgTestRegMsk(DPC_END_REG, 0x00aaaaaa, 0x00aaaaa8, END_REG_MSK);
   errcount += dgRdTestWordMsk(DPC_STATUS_REG, 0x000000a8, STATUS_REG_MSK);
   errcount += dgRdTestWordMsk(DPC_CURRENT_REG, 0x00aaaaa8, CURRENT_REG_MSK);

   errcount += dgTestRegMsk(DPC_START_REG, 0x00555555, 0x00555550, START_REG_MSK);
   errcount += dgTestRegMsk(DPC_END_REG, 0x00555555, 0x00555550, END_REG_MSK);
   errcount += dgRdTestWordMsk(DPC_CURRENT_REG, 0x00555550, CURRENT_REG_MSK);

   errcount += dgTestRegMsk(DPC_START_REG, 0x00000000, 0x00000000, START_REG_MSK);
   errcount += dgTestRegMsk(DPC_END_REG, 0x00000000, 0x00000000, END_REG_MSK);
   errcount += dgRdTestWordMsk(DPC_CURRENT_REG, 0x00000000, CURRENT_REG_MSK);

   if (errcount)
      errlog(ERR_SEVERE, "errcount = %d", errcount);

   return(errcount);
}

static int spanbufWriteWord(unsigned pattern, unsigned adrs, unsigned bank)
{
   unsigned full_word;
   unsigned short_word;
   int errcount = 0;

   full_word = pattern | (pattern << 4) | (pattern << 8) | (pattern << 12) | 
              (pattern << 16) | (pattern << 20) | (pattern << 24) | (pattern << 28);

   short_word = pattern | (pattern << 4);

   errcount += dgTestRegMsk(DPS_BUFTEST_ADDR_REG, (adrs << 3) | 0x0 | (bank * 4), (adrs << 3) | 0x0 | (bank * 4), BUFTEST_ADDR_MSK);
   errcount += dgWriteWord(DPS_BUFTEST_DATA_REG, full_word);

   errcount += dgTestRegMsk(DPS_BUFTEST_ADDR_REG, (adrs << 3) | 0x1 | (bank * 4), (adrs << 3) | 0x1 | (bank * 4), BUFTEST_ADDR_MSK);
   errcount += dgWriteWord(DPS_BUFTEST_DATA_REG, full_word);

   errcount += dgTestRegMsk(DPS_BUFTEST_ADDR_REG, (adrs << 3) | 0x2 | (bank * 4), (adrs << 3) | 0x2 | (bank * 4), BUFTEST_ADDR_MSK);
   errcount += dgWriteWord(DPS_BUFTEST_DATA_REG, short_word);

   errcount += dgTestRegMsk(DPS_BUFTEST_ADDR_REG, (adrs << 3) | 0x3 | (bank * 4), (adrs << 3) | 0x3 | (bank * 4), BUFTEST_ADDR_MSK);
   errcount += dgWriteWord(DPS_BUFTEST_DATA_REG, 0x00000000);

   return(errcount);
}

static int spanbufTestWord(unsigned pattern, unsigned adrs, unsigned bank)
{
   unsigned full_word;
   unsigned short_word;
   unsigned read_data;
   int errcount = 0;

   full_word = pattern | (pattern << 4) | (pattern << 8) | (pattern << 12) |
              (pattern << 16) | (pattern << 20) | (pattern << 24) | (pattern << 28);

   short_word = pattern | (pattern << 4);

   errcount += dgTestRegMsk(DPS_BUFTEST_ADDR_REG, (adrs << 3) | 0x0 | (bank * 4), (adrs << 3) | 0x0 | (bank * 4), BUFTEST_ADDR_MSK);
   errcount += dgReadWord(DPS_BUFTEST_DATA_REG, &read_data);
   errlog(DEBUG, "reading - bk = %x, ad = %01x, rd = %08x", bank, adrs, read_data);
   if (read_data != full_word)
   {
     errlog(ERR_SEVERE,
            "data miscompare - ad = %08x, wr = %08x, rd = %08x",
            DPS_BUFTEST_DATA_REG, full_word, read_data);
     errcount++;
   }


   errcount += dgTestRegMsk(DPS_BUFTEST_ADDR_REG, (adrs << 3) | 0x1 | (bank * 4), (adrs << 3) | 0x1 | (bank * 4), BUFTEST_ADDR_MSK);
   errcount += dgReadWord(DPS_BUFTEST_DATA_REG, &read_data);
   errlog(DEBUG, "reading - bk = %x, ad = %01x, rd = %08x", bank, adrs, read_data);
   if (read_data != full_word)
   {
     errlog(ERR_SEVERE,
            "data miscompare - ad = %08x, wr = %08x, rd = %08x",
            DPS_BUFTEST_DATA_REG, full_word, read_data);
     errcount++;
   }

   errcount += dgTestRegMsk(DPS_BUFTEST_ADDR_REG, (adrs << 3) | 0x2 | (bank * 4), (adrs << 3) | 0x2 | (bank * 4), BUFTEST_ADDR_MSK);
   errcount += dgReadWord(DPS_BUFTEST_DATA_REG, &read_data);
   errlog(DEBUG, "reading - bk = %x, ad = %01x, rd = %08x", bank, adrs, read_data);
   if ((read_data & BUFTEST_DATA_MSK) != short_word)
   {
     errlog(ERR_SEVERE,
            "data miscompare - ad = %08x, wr = %08x, rd = %08x",
            DPS_BUFTEST_DATA_REG, short_word, (read_data & BUFTEST_DATA_MSK));
     errcount++;
   }

   return(errcount);
}

int rdp_spanbuf(void)
{

   unsigned adrs;
   unsigned bank;
   int errcount = 0;

   /* put spanbuf in test mode */
   errcount += dgTestRegMsk(DPS_TEST_MODE_REG, 0x00000001, 0x00000001, TEST_MODE_REG_MSK);

   for (bank = 0; bank <= 1; bank++)
   {
      /* write A's and 5's */
      for (adrs = 0; adrs < SPANBUF_DEPTH; adrs+=1)
      {
         errcount += spanbufWriteWord(0xa, adrs, bank);
         adrs += 1;
         errcount += spanbufWriteWord(0x5, adrs, bank);
      }

      /* read back and compare */
      for (adrs = 0; adrs < SPANBUF_DEPTH; adrs+=1)
      {
         errcount += spanbufTestWord(0xa, adrs, bank);
         adrs += 1;
         errcount += spanbufTestWord(0x5, adrs, bank);
      }

      /* write 5's and A's */
      for (adrs = 0; adrs < SPANBUF_DEPTH; adrs+=1)
      {
         errcount += spanbufWriteWord(0x5, adrs, bank);
         adrs += 1;
         errcount += spanbufWriteWord(0xa, adrs, bank);
      }

      /* read back and compare */
      for (adrs = 0; adrs < SPANBUF_DEPTH; adrs+=1)
      {
         errcount += spanbufTestWord(0x5, adrs, bank);
         adrs += 1;
         errcount += spanbufTestWord(0xa, adrs, bank);
      }

      /* write adrs to adrs */
      for (adrs = 0; adrs < SPANBUF_DEPTH; adrs+=1)
      {
         errcount += spanbufWriteWord(adrs, adrs, bank);
      }

      /* read back and compare */
      for (adrs = 0; adrs < SPANBUF_DEPTH; adrs+=1)
      {
         errcount += spanbufTestWord(adrs, adrs, bank);
      }

      /* write ~adrs to adrs */
      for (adrs = 0; adrs < SPANBUF_DEPTH; adrs+=1)
      {
         errcount += spanbufWriteWord((~adrs & 0xf), adrs, bank);
      }

      /* read back and compare */
      for (adrs = 0; adrs < SPANBUF_DEPTH; adrs+=1)
      {
         errcount += spanbufTestWord((~adrs & 0xf), adrs, bank);
      }
   }

   /* take spanbuf out of test mode */
   errcount += dgTestRegMsk(DPS_TEST_MODE_REG, 0x00000000, 0x00000000, TEST_MODE_REG_MSK);

   if (errcount)
      errlog(ERR_SEVERE, "errcount = %d", errcount);

   return(errcount);
}

int rdp_tmembist(void)
{
   int errcount = 0;
   unsigned read_data;

   /* clear bist status */
   errcount += dgWriteWord(DPS_TBIST_REG, DPS_TBIST_CLEAR);
   errcount += dgRdTestWordMsk(DPS_TBIST_REG, 0x00000000, TBIST_REG_MSK);

   /* bist_check 1 */
   errcount += dgWriteWord(DPS_TBIST_REG, DPS_TBIST_CHECK);
   while (!(errcount += dgReadWord(DPS_TBIST_REG, &read_data)))
   {
     if (read_data & DPS_TBIST_DONE) break;
   }
   errcount += dgRdTestWordMsk(DPS_TBIST_REG, (DPS_TBIST_FAILED | DPS_TBIST_DONE | DPS_TBIST_CHECK), 
			       TBIST_REG_MSK);

   /* clear bist, bist_check 0 */
   errcount += dgWriteWord(DPS_TBIST_REG, DPS_TBIST_CLEAR);
   while (!(errcount += dgReadWord(DPS_TBIST_REG, &read_data)))
   {
     if (read_data & DPS_TBIST_DONE) break;
   }
   errcount += dgRdTestWordMsk(DPS_TBIST_REG, (DPS_TBIST_FAILED | DPS_TBIST_DONE), TBIST_REG_MSK);

   /* clear bist status */
   errcount += dgWriteWord(DPS_TBIST_REG, DPS_TBIST_CLEAR);
   errcount += dgRdTestWordMsk(DPS_TBIST_REG, 0x00000000, TBIST_REG_MSK);

   /* bist_go */
   errcount += dgWriteWord(DPS_TBIST_REG, DPS_TBIST_GO);
   while (!(errcount += dgReadWord(DPS_TBIST_REG, &read_data)))
   {
     if (read_data & DPS_TBIST_DONE) break;
   }
   errcount += dgRdTestWordMsk(DPS_TBIST_REG, (DPS_TBIST_DONE | DPS_TBIST_GO), TBIST_REG_MSK);

   /* clear bist status */
   errcount += dgWriteWord(DPS_TBIST_REG, DPS_TBIST_CLEAR);
   errcount += dgRdTestWordMsk(DPS_TBIST_REG, 0x00000000, TBIST_REG_MSK);

   if (errcount)
      errlog(ERR_SEVERE, "errcount = %d", errcount);

   return(errcount);
}