openbcm

Git mirror of https://github.com/Broadcom-Network-Switching-Software/OpenBCM
git clone git://git.finwo.net/mirror/broadcom/openbcm
Log | Files | Refs | README

phymod_symbol_show_fields.c (3250B)


      1 /*
      2  * 
      3  * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
      4  * 
      5  * Copyright 2007-2019 Broadcom Inc. All rights reserved.
      6  */
      7 
      8 #include <phymod/phymod_system.h>
      9 #include <phymod/phymod_symbols.h>
     10 
     11 #if PHYMOD_CONFIG_INCLUDE_FIELD_INFO == 1
     12 
     13 static int
     14 phymod_util_bit_range(char *buf, int size, int minbit, int maxbit)
     15 {
     16     if (minbit == maxbit) {
     17         PHYMOD_SNPRINTF(buf, size, "<%d>", minbit);
     18     } else {
     19         PHYMOD_SNPRINTF(buf, size, "<%d:%d>", maxbit, minbit);
     20     }
     21     return 0;
     22 }
     23 
     24 /*
     25  * Function:
     26  *	phymod_symbol_show_fields
     27  * Purpose:
     28  *	Display all fields of a register/memory
     29  * Parameters:
     30  *	symbol - symbol information
     31  *	fnames - list of all field names
     32  *	data - symbol data (one or more 32-bit words)
     33  *	nz - skip fields with value of zero
     34  *	fcb - filter call-back function
     35  *	cookie - filter call-back context
     36  * Returns:
     37  *      Always 0
     38  */
     39 int 
     40 phymod_symbol_show_fields(const phymod_symbol_t *symbol,
     41                           const char **fnames, uint32_t *data, int nz,
     42                           int (*print_str)(const char *str),
     43                           phymod_symbol_filter_cb_t fcb, void *cookie)
     44 {
     45     int mval; 
     46     phymod_field_info_t finfo; 
     47     char *ptr;
     48     char vstr[8 * PHYMOD_MAX_REG_WSIZE + 32];
     49     char fname_str[16];
     50     const char *fname;
     51     uint32_t val[PHYMOD_MAX_REG_WSIZE];
     52     int idx = 0;
     53 
     54     PHYMOD_SYMBOL_FIELDS_ITER_BEGIN(symbol->fields, finfo, fnames) {
     55 
     56         /* Create default field name */
     57         PHYMOD_SPRINTF(fname_str, "field%d", idx++);
     58         fname = fname_str;
     59 
     60 #if PHYMOD_CONFIG_INCLUDE_FIELD_NAMES == 1
     61         /* Use real field name when available */
     62         if (finfo.name) {
     63             if (fcb && fcb(symbol, fnames, finfo.name, cookie) != 0) {
     64                 continue;
     65             }
     66             /* Skip encoding part of field name if present */
     67             if ((fname = PHYMOD_STRCHR(finfo.name, '}')) != NULL) {
     68                 fname++;
     69             } else {
     70                 fname = finfo.name;
     71             }
     72         }
     73 #endif
     74 
     75         /* Create bit range string */
     76         phymod_util_bit_range(vstr, sizeof(vstr),
     77                               finfo.minbit, 
     78                               finfo.maxbit);
     79 
     80         if (data) {
     81             /* Get normalized field value */
     82             PHYMOD_MEMSET(val, 0, sizeof(val));
     83             phymod_field_get(data, finfo.minbit, finfo.maxbit, val);
     84 
     85             /* Create field value string */
     86             mval = COUNTOF(val) - 1;
     87             while (mval && val[mval] == 0) {
     88                 mval--;
     89             }
     90 
     91             /* Optionally skip fields with all zeros */
     92             if (nz && mval == 0 && val[mval] == 0) {
     93                 continue;
     94             }
     95 
     96             ptr = vstr + PHYMOD_STRLEN(vstr);
     97             PHYMOD_SPRINTF(ptr, "=0x%"PRIx32"", val[mval]);
     98             while (mval--) {
     99                 ptr += PHYMOD_STRLEN(ptr);
    100                 PHYMOD_SPRINTF(ptr, "%08"PRIx32"", val[mval]);
    101             }
    102         }
    103 
    104         print_str("\t");
    105         print_str(fname);
    106         print_str(vstr);
    107         print_str("\n");
    108 
    109     } PHYMOD_SYMBOL_FIELDS_ITER_END(); 
    110 
    111     return 0; 
    112 }
    113 
    114 #endif /* PHYMOD_CONFIG_INCLUDE_FIELD_INFO */