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

ft_diag.c (31602B)


      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  * File:        ft_diag.c
      8  * Purpose:     The purpose of this file is to set flow tracker group methods.
      9  * Requires:
     10  */
     11 
     12 
     13 #include <bcm_int/esw/flowtracker/ft_group.h>
     14 
     15 #if defined(BCM_FLOWTRACKER_SUPPORT)
     16 
     17 
     18 /* Group Sw state. */
     19 extern
     20 bcmi_ft_group_sw_info_t **bcmi_ft_group_sw_state[BCM_MAX_NUM_UNITS];
     21 
     22 int bcmi_alu_opr_conversion[8] =
     23         {5, 6, 1, 2, 3, 4, 7, 8};
     24 
     25 int bcmi_alu_action_conversion[9] =
     26         {0, 1, 7, 2, 3, 4, 5, 6, -1};
     27 
     28 char trackingelements[bcmFlowtrackerTrackingParamTypeCount] [100] =
     29    {"None",
     30     "SrcIPv4",
     31     "DstIPv4",
     32     "SrcIPv6",
     33     "DstIPv6",
     34     "L4SrcPort",
     35     "L4DstPort",
     36     "IPProtocol",
     37     "PktCount",
     38     "ByteCount",
     39     "VRF",
     40     "TTL",
     41     "IPLength",
     42     "TcpWindowSize",
     43     "DosAttack",
     44     "VxlanNetworkId",
     45     "NextHeader",
     46     "HopLimit",
     47     "InnerSrcIPv4",
     48     "InnerDstIPv4",
     49     "InnerSrcIPv6 ",
     50     "InnerDstIPv6",
     51     "InnerIPProtocol",
     52     "InnerTTL ",
     53     "InnerNextHeader",
     54     "InnerHopLimit",
     55     "InnerL4SrcPort",
     56     "InnerL4DstPort",
     57     "TcpFlags",
     58     "OuterVlanTag",
     59     "IP6Length",
     60     "InnerIPLength",
     61     "InnerIP6Length"};
     62 
     63 
     64 char elementType[3][100] =
     65    {"Flowchecker",
     66     "Tracking Param",
     67     "TimeStamp"};
     68 
     69 /*
     70  * Function:
     71  *     bcmi_ft_table_lookup
     72  * Purpose:
     73  *     Looks up ft entry at 5 tuple.
     74  * Parameters:
     75  *     unit - (IN) BCM device id
     76  *     id   - (IN) FT group id.
     77  *     v4-5tuple.- (IN) 5 tuple values, DIP,sip,srcport,dstport, protocol
     78  *     index - (OUT) memory index.
     79  *
     80  * Returns:
     81  *     BCM_E_XXX
     82  */
     83 int
     84 bcmi_ft_table_lookup(
     85     int unit,
     86     bcm_flowtracker_group_t id,
     87     bcm_ip_t dip,
     88     bcm_ip_t sip,
     89     uint16 l4destport,
     90     uint16 l4srcport,
     91     uint8 proto,
     92     int *index)
     93 {
     94     uint32 ft_key[50], ft_ret[50];
     95     uint8 data[40];
     96     uint8 *p;
     97     int rv = 0;
     98     int i;
     99     uint8 mode = 0;
    100     soc_mem_t mem;
    101     int b1=0, b2=0, k1=0, k2=0;
    102     int p_val = 0;
    103 
    104     if (!index) {
    105         return BCM_E_FAIL;
    106     }
    107 
    108     if (!BCMI_FT_GROUP_IS_VALIDATED(unit, id)) {
    109         LOG_ERROR(BSL_LS_BCM_FLOWTRACKER, (BSL_META_U(unit,
    110             "Group index (%d) is not created or validated yet.\n "), id));
    111 
    112         return BCM_E_CONFIG;
    113     }
    114 
    115     sal_memset(data, 0, sizeof(data));
    116     sal_memset(ft_key, 0, sizeof(ft_key));
    117     sal_memset(ft_ret, 0, sizeof(ft_ret));
    118 
    119     mode = (BCMI_FT_GROUP_FTFP_DATA(unit, id).session_key_mode ==
    120                bcmiFtGroupModeDouble) ? 1 :0;
    121 
    122     if (mode) {
    123         mem = FT_KEY_DOUBLEm;
    124         b1 = BASE_VALID_0f;
    125         b2 = BASE_VALID_1f;
    126         k1 = KEY_0f;
    127         k2 = KEY_1f;
    128     } else {
    129         mem = FT_KEY_SINGLEm;
    130         b1 = b2 = BASE_VALIDf;
    131         k1 = k2 = KEYf;
    132     }
    133 
    134     soc_mem_field_set(unit, mem, ft_key, k2, (uint32 *)data);
    135     /* Key Type. */
    136     data[0] = mode;
    137     p_val = 0;
    138     p = (uint8 *)&dip;
    139     p_val++;
    140     for (i=0; i<4; i++) {
    141         data[p_val+i] = p[i];
    142     }
    143     p_val += 4;
    144 
    145     p = (uint8 *)&sip;
    146     for (i=0; i<4; i++) {
    147         data[p_val+i] = p[i];
    148     }
    149     p_val += 4;
    150 
    151     if (l4srcport) {
    152         p = (uint8 *)&l4srcport;
    153         for (i=0; i<2; i++) {
    154             data[p_val+i] = p[i];
    155         }
    156         p_val += 2;
    157     }
    158 
    159     if (l4destport) {
    160 
    161         p = (uint8 *)&l4destport;
    162         for (i=0; i<2; i++) {
    163             data[p_val+i] = p[i];
    164         }
    165         p_val += 2;
    166     }
    167 
    168     if (proto) {
    169         data[p_val] = proto;
    170     }
    171 
    172     LOG_ERROR(BSL_LS_BCM_FLOWTRACKER,
    173         (BSL_META_U(unit, "soc_mem_insert : KEY : DIP=0x%x, SIP=0x%x, l4destport = %d, l4srcport=%d, proto = %d \n"),
    174          dip, sip, l4destport, l4srcport, proto));
    175 
    176     LOG_CLI((BSL_META_U(unit, "Printing Key")));
    177 
    178     for (i=15; i>=0; i--) {
    179         LOG_CLI((BSL_META_U(unit, "%x"), data[i]));
    180     }
    181 
    182     LOG_CLI((BSL_META_U(unit, "\n")));
    183     soc_mem_field32_set(unit, mem, ft_key, b1, 1);
    184     soc_mem_field32_set(unit, mem, ft_key, b2, 1);
    185 
    186     soc_mem_field_set(unit, mem, ft_key, k1, (uint32 *)data);
    187 
    188     rv = soc_mem_search(unit, mem, MEM_BLOCK_ANY, index,
    189                        &ft_key, &ft_ret, 0);
    190 
    191     LOG_ERROR(BSL_LS_BCM_FLOWTRACKER,
    192         (BSL_META_U(unit, "soc_mem_search : rv = %d, index = %d \n"),
    193         rv, *index));
    194 
    195     return BCM_E_NONE;
    196 }
    197 
    198 
    199 /*
    200  * Function:
    201  *     bcmi_ft_table_insert
    202  * Purpose:
    203  *     Insert entry into ft table.
    204  * Parameters:
    205  *     unit - (IN) BCM device id
    206  *     v4-5tuple.- (IN) 5 tuple values, DIP,sip,srcport,dstport, protocol
    207  *
    208  * Returns:
    209  *     BCM_E_XXX
    210  */
    211 int
    212 bcmi_ft_table_insert(
    213     int unit,
    214     bcm_ip_t dip,
    215     bcm_ip_t sip,
    216     uint16 l4destport,
    217     uint16 l4srcport,
    218     uint8 proto)
    219 {
    220     ft_key_single_entry_t ft_key;
    221     uint8 data[40];
    222     uint8 *p;
    223     int rv = 0;
    224     int i;
    225 
    226     sal_memset(&data, 0, 40);
    227 
    228     /* Key Type. */
    229     data[0] = 0;
    230 
    231     p = (uint8 *)&dip;
    232 
    233     for (i=0; i<4; i++) {
    234         data[1+i] = p[i];
    235     }
    236 
    237     p = (uint8 *)&sip;
    238     for (i=0; i<4; i++) {
    239         data[5+i] = p[i];
    240     }
    241 
    242     p = (uint8 *)&l4srcport;
    243     for (i=0; i<2; i++) {
    244         data[9+i] = p[i];
    245     }
    246 
    247     p = (uint8 *)&l4destport;
    248     for (i=0; i<2; i++) {
    249         data[11+i] = p[i];
    250     }
    251 
    252     data[13] = proto;
    253 
    254     sal_memset(&ft_key, 0, sizeof(ft_key_single_entry_t));
    255 
    256     LOG_ERROR(BSL_LS_BCM_FLOWTRACKER,
    257         (BSL_META_U(unit, "soc_mem_insert : KEY : DIP=0x%x, SIP=0x%x, l4destport = %d, l4srcport=%d, proto = %d \n"),
    258         dip, sip, l4destport, l4srcport, proto));
    259 
    260 
    261     soc_mem_field32_set(unit, FT_KEY_SINGLEm, &ft_key, BASE_VALIDf, 1);
    262     soc_mem_field_set(unit, FT_KEY_SINGLEm, (uint32*)&ft_key, KEYf, (uint32*)data);
    263 
    264     rv = soc_mem_insert(unit, FT_KEY_SINGLEm, MEM_BLOCK_ANY, &ft_key);
    265 
    266     return rv;
    267 }
    268 
    269 void
    270 bcmi_ft_print_alu_load_type_str(int unit, int type)
    271 {
    272         LOG_CLI((BSL_META_U(unit, "Type = ")));
    273         if (type == bcmiFtAluLoadTypeLoad16) {
    274 
    275             LOG_CLI((BSL_META_U(unit, "bcmiFtAluLoadTypeLoad16")));
    276         } else if (type == bcmiFtAluLoadTypeLoad8) {
    277 
    278             LOG_CLI((BSL_META_U(unit, "bcmiFtAluLoadTypeLoad8")));
    279         } else if (type == bcmiFtAluLoadTypeAlu32) {
    280 
    281             LOG_CLI((BSL_META_U(unit, "bcmiFtAluLoadTypeAlu32")));
    282         } else if (type == bcmiFtAluLoadTypeAlu16) {
    283             LOG_CLI((BSL_META_U(unit, "bcmiFtAluLoadTypeAlu16")));
    284         } else {
    285             LOG_CLI((BSL_META_U(unit, "bcmiFtAluLoadTypeNone")));
    286         }
    287 }
    288 
    289 /*
    290  * Function:
    291  *     bcmi_ft_group_state_dump
    292  * Purpose:
    293  *     Insert entry into ft table.
    294  * Parameters:
    295  *     unit - (IN) BCM device id
    296  *       id - (IN) Group index to dump.
    297  *
    298  * Returns:
    299  *     BCM_E_XXX
    300  */
    301 int
    302 bcmi_ft_group_state_dump(
    303     int unit,
    304     bcm_flowtracker_group_t id)
    305 {
    306     int rv =  BCM_E_NONE;
    307     int num_alus_loads = 0, i=0;
    308     bcmi_ft_group_alu_info_t *temp = NULL;
    309     bcmi_ft_alu_load_type_t type = bcmiFtAluLoadTypeNone;
    310     bcmi_ft_group_pdd_bus_info_t *pdd_info = NULL;
    311     bcm_collector_t cmn_coll_id;
    312     bcm_flowtracker_collector_t hw_coll_id;
    313     int total_mems = 0;
    314     int mem_idx = 0;
    315     bcm_flowtracker_tracking_param_info_t *t_param;
    316     bcmi_flowtracker_flowchecker_info_t fc_info;
    317     const char *plist[] = BCM_FT_TRACKING_PARAM_STRINGS;
    318     char direction_str[20] = {'\0'};
    319 
    320     if (bcmi_ft_group_is_invalid(unit, id)) {
    321         LOG_ERROR(BSL_LS_BCM_FLOWTRACKER, (BSL_META_U(unit,
    322             "Group index (%d) is yet not created.\n "), id));
    323 
    324         return BCM_E_NONE;
    325     }
    326 
    327     LOG_CLI((BSL_META_U(unit, " ************************************** \n\r")));
    328 
    329     /* Print Group Management Status */
    330     if (BCMI_FT_GROUP(unit, id)->flags &
    331             BCM_FLOWTRACKER_GROUP_USER_ENTRIES_ONLY) {
    332         LOG_CLI((BSL_META_U(unit, "--Software Managed Group--\n\r")));
    333     } else {
    334         LOG_CLI((BSL_META_U(unit, "--Hardware Managed Group--\n\r")));
    335     }
    336 
    337     /* Flowtracker Group Class Id */
    338     LOG_CLI((BSL_META_U(unit, "Class Identifier              :\t%5d\n\r"),
    339                 BCMI_FT_GROUP_CONFIG(unit, id).class_id));
    340 
    341     /* Flowtracker Group Controls */
    342     if (BCMI_FT_GROUP_FTFP_DATA(unit, id).direction ==
    343             bcmFlowtrackerFlowDirectionNone) {
    344         sal_snprintf(direction_str, 20, "%s", "None");
    345     } else if (BCMI_FT_GROUP_FTFP_DATA(unit, id).direction ==
    346             bcmFlowtrackerFlowDirectionForward) {
    347         sal_snprintf(direction_str, 20, "%s", "Forward");
    348     } else if (BCMI_FT_GROUP_FTFP_DATA(unit, id).direction ==
    349             bcmFlowtrackerFlowDirectionReverse) {
    350         sal_snprintf(direction_str, 20, "%s", "Reverse");
    351     } else if (BCMI_FT_GROUP_FTFP_DATA(unit, id).direction ==
    352             bcmFlowtrackerFlowDirectionBidirectional) {
    353         sal_snprintf(direction_str, 20, "%s", "Bidirectional");
    354     }
    355 
    356     LOG_CLI((BSL_META_U(unit, "Flowtracker Status            :\t%5d\n\r"),
    357                 BCMI_FT_GROUP_FTFP_DATA(unit, id).flowtrack));
    358     LOG_CLI((BSL_META_U(unit, "New Learn Status              :\t%5d\n\r"),
    359             BCMI_FT_GROUP_FTFP_DATA(unit, id).new_learn));
    360     LOG_CLI((BSL_META_U(unit, "Direction                     :\t%5s\n\r"),
    361                 direction_str));
    362 
    363    /* Print associated Collector */
    364     if (BCMI_FT_COLLECTOR_ID_INVALID !=
    365             BCMI_FT_GROUP(unit, id)->collector_id) {
    366         hw_coll_id = BCMI_FT_GROUP(unit, id)->collector_id;
    367         cmn_coll_id = (BCMI_FT_COLLECTOR_INFO(unit, hw_coll_id))->cmn_coll_id;
    368         LOG_CLI((BSL_META_U(unit, "Associated Collector(s/w Id)  :\t%5d\n\r"),
    369                     cmn_coll_id));
    370         LOG_CLI((BSL_META_U(unit, "Associated Collector(h/w Id)  :\t%5d\n\r"),
    371                     hw_coll_id));
    372     } else {
    373         LOG_CLI((BSL_META_U(unit, "Associated Collector          :\t%5s\n\r"),
    374                 "(NA)"));
    375     }
    376 
    377     /* Print associated Template */
    378     if (BCMI_FT_TEMPLATE_ID_INVALID !=
    379             BCMI_FT_GROUP(unit, id)->template_id) {
    380         LOG_CLI((BSL_META_U(unit, "Associated Template           :\t%5d\n\r"),
    381                 BCMI_FT_GROUP(unit, id)->template_id));
    382     } else {
    383         LOG_CLI((BSL_META_U(unit, "Associated Template           :\t%5s\n\r"),
    384                 "(NA)"));
    385     }
    386 
    387     /* Association with FTFP Entries */
    388     LOG_CLI((BSL_META_U(unit, "Associated with Field Entries :\t%5d\n\r"),
    389                 BCMI_FT_GROUP(unit, id)->num_ftfp_entries));
    390 
    391     if (!BCMI_FT_GROUP_IS_VALIDATED(unit, id)) {
    392         LOG_ERROR(BSL_LS_BCM_FLOWTRACKER, (BSL_META_U(unit,
    393             "Group index (%d) is not validated yet.\n "), id));
    394 
    395         return BCM_E_NONE;
    396     }
    397 
    398     /* Metering info */
    399     LOG_CLI((BSL_META_U(unit, "Meter Rate (Kbps/pps)         :\t%5d\n\r"),
    400                 BCMI_FT_GROUP_METER_INFO(unit, id).sw_ckbits_sec));
    401     LOG_CLI((BSL_META_U(unit, "Meter burst (Kbits/Kpkts)     :\t%5d\n\r"),
    402                 BCMI_FT_GROUP_METER_INFO(unit, id).sw_ckbits_burst));
    403 
    404     LOG_CLI((BSL_META_U(unit, "\n===== Dumping Tracking Parameters =====\n")));
    405 
    406     t_param = BCMI_FT_GROUP_TRACK_PARAM(unit, id);
    407     for (i=0; i<(BCMI_FT_GROUP_TRACK_PARAM_NUM(unit, id)); i++) {
    408 
    409         LOG_CLI((BSL_META_U(unit, "%d. "), i));
    410         LOG_CLI((BSL_META_U(unit, "flags = %-5d | "), t_param->flags));
    411         LOG_CLI((BSL_META_U(unit, "Parameter type -")));
    412         LOG_CLI((BSL_META_U(unit, " %20s"), plist[t_param->param]));
    413 
    414         t_param++;
    415         LOG_CLI((BSL_META_U(unit, "\n")));
    416     }
    417 
    418     LOG_CLI((BSL_META_U(unit, "\n ===== Dumping extractor Data ====\n")));
    419 
    420     /* assign the ALU memory chunk to local pointer. */
    421     temp = BCMI_FT_GROUP_EXT_DATA_INFO(unit, id);
    422 
    423     /* Get total number of alus in this chunk. */
    424     num_alus_loads = (BCMI_FT_GROUP_EXT_INFO(unit, id)).num_data_info;
    425 
    426     LOG_CLI((BSL_META_U(unit, "Total elements  = %d\n"), num_alus_loads));
    427     /* allocate the bitmap based on the type, length */
    428     for (i=0; i<num_alus_loads; i++) {
    429 
    430          /* Now get the type of the memory and take action. */
    431          LOG_CLI((BSL_META_U
    432              (unit, " ************ Session Data - Element %d    ************"),
    433              i+1));
    434 
    435          LOG_CLI((BSL_META_U(unit, "\n")));
    436 
    437          if (temp->flowchecker_id) {
    438             sal_memset(&fc_info, 0, sizeof(bcmi_flowtracker_flowchecker_info_t));
    439             LOG_CLI((BSL_META_U(unit, "FlowCheck Id = 0x%x\n"), temp->flowchecker_id));
    440             BCM_IF_ERROR_RETURN(bcmi_ft_flowchecker_get
    441                 (unit, temp->flowchecker_id, &fc_info));
    442 
    443             LOG_CLI((BSL_META_U(unit,
    444                 "Element1 -")));
    445             LOG_CLI((BSL_META_U(unit, " %20s, "), plist[fc_info.check1.param]));
    446 
    447             if (fc_info.check2.param) {
    448                 LOG_CLI((BSL_META_U(unit,
    449                     "Element2 -")));
    450                 LOG_CLI((BSL_META_U(unit, " %20s"), plist[fc_info.check2.param]));
    451             }
    452         } else {
    453             LOG_CLI((BSL_META_U(unit,
    454                  "Element -")));
    455             LOG_CLI((BSL_META_U(unit, " %20s"), plist[temp->element_type1]));
    456          }
    457 
    458         LOG_CLI((BSL_META_U(unit, "\n")));
    459 
    460         type = temp->alu_load_type;
    461         bcmi_ft_print_alu_load_type_str(unit, type);
    462 
    463         LOG_CLI((BSL_META_U(unit, "\n Element1 - Length = %d, IS_ALU = %d,"
    464             " location = %d"),
    465             temp->key1.length, temp->key1.is_alu, temp->key1.location));
    466 
    467         if (temp->flowchecker_id) {
    468             LOG_CLI((BSL_META_U(unit, "\n Element2 - Length = %d, IS_ALU = %d,"
    469                 " location = %d"),
    470                 temp->key2.length, temp->key2.is_alu, temp->key2.location));
    471         }
    472 
    473         if (type == bcmiFtAluLoadTypeAlu16) {
    474             bcmi_ft_alu16_dump(unit, temp->alu_load_index);
    475         } else if (type == bcmiFtAluLoadTypeAlu32) {
    476             bcmi_ft_alu32_dump(unit, temp->alu_load_index);
    477         } else {
    478             LOG_CLI((BSL_META_U(unit, "\n This element belongs to Load memory\n")));
    479         }
    480 
    481         LOG_CLI((BSL_META_U(unit, "\n")));
    482         temp++;
    483     }
    484 
    485     LOG_CLI((BSL_META_U(unit, "Dump PDD profile entry.\n")));
    486     /* For all the types of memory types. */
    487     for (type=0; type<4; type++) {
    488 
    489         total_mems = alu_load_index_info[unit][type].total_mem_count;
    490 
    491         /* Set sub memories for Load memories. */
    492          if (type == bcmiFtAluLoadTypeLoad8) {
    493              total_mems = 8;
    494          } else if (type == bcmiFtAluLoadTypeLoad16) {
    495              total_mems = 16;
    496          }
    497 
    498         /* For all the alu/load types, check what memories are set in pdd. */
    499         for (mem_idx=0; mem_idx<total_mems; mem_idx++) {
    500             /* Now get if this particular field is set in pdd. */
    501             pdd_info = alu_load_index_info[unit][type].pdd_bus_info;
    502             if (!pdd_info) {
    503                 return BCM_E_INTERNAL;
    504             }
    505             if (soc_mem_field32_get(unit, BSD_POLICY_ACTION_PROFILEm,
    506                     (uint32 *)(&(BCMI_FT_GROUP(unit, id)->pdd_entry)),
    507                     pdd_info[mem_idx].param_id)) {
    508                 LOG_CLI((BSL_META_U(unit, "Index=%d of "),
    509                     mem_idx));
    510                 bcmi_ft_print_alu_load_type_str(unit, type);
    511                 LOG_CLI((BSL_META_U(unit, " is set.\n")));
    512 
    513             }
    514         }
    515     }
    516 
    517     LOG_CLI((BSL_META_U(unit, "Group Dump Completed.\n")));
    518     return rv;
    519 }
    520 
    521 /*
    522  * Function:
    523  *     bcmi_ft_group_session_data_dump
    524  * Purpose:
    525  *     Dump the session data.
    526  * Parameters:
    527  *     unit - (IN) BCM device id
    528  *       id - (IN) Group index to dump.
    529  *     index - (IN) FT index to dump.
    530  *
    531  * Returns:
    532  *     BCM_E_XXX
    533  */
    534 int
    535 bcmi_ft_group_session_data_dump(
    536     int unit,
    537     bcm_flowtracker_group_t id,
    538     int index)
    539 {
    540     int rv = BCM_E_NONE;
    541     int data_bytes;
    542     bcmi_ft_group_template_list_t *temp;
    543     uint8 *data = NULL;
    544     uint32 *buffer = NULL;
    545     int length = 0, start=32, i;
    546     uint32 value = 0;
    547     bcmi_flowtracker_flowchecker_info_t fc_info;
    548     bcm_flowtracker_tracking_param_type_t element;
    549     uint8 mode = 0;
    550     soc_mem_t mem;
    551     int etype = 0;
    552     const char *plist[] = BCM_FT_TRACKING_PARAM_STRINGS;
    553     int sub_len=0, first_value=0;
    554 
    555     if (!BCMI_FT_GROUP_IS_VALIDATED(unit, id)) {
    556 
    557         LOG_CLI((BSL_META_U(unit, "Group index (%d) is NOT validated \n "), id));
    558 
    559         return BCM_E_CONFIG;
    560     } else {
    561         LOG_CLI((BSL_META_U(unit, "Group index (%d) is validated \n "), id));
    562     }
    563     if (BCMI_FT_GROUP_IS_BUSY(unit, id)) {
    564         LOG_CLI((BSL_META_U(unit, "Group index (%d) is associated with FTFP Entry \n "), id));
    565     }
    566 
    567     /* Get the head of the templs info plist. */
    568     temp = ((BCMI_FT_GROUP(unit, id))->template_head);
    569 
    570     mode = (BCMI_FT_GROUP_FTFP_DATA(unit, id).session_key_mode ==
    571                bcmiFtGroupModeDouble) ? 1 :0;
    572 
    573     if (mode) {
    574         start = (start << mode);
    575         mem = BSC_DT_FLEX_SESSION_DATA_DOUBLEm;
    576     } else {
    577         mem = BSC_DT_FLEX_SESSION_DATA_SINGLEm;
    578     }
    579 
    580     data_bytes = soc_mem_field_length(unit, mem, OPAQUE_DATAf);
    581     data_bytes = BITS2BYTES(data_bytes);
    582     data = (uint8 *) sal_alloc(data_bytes * sizeof(uint8), "session data");
    583     if (data == NULL) {
    584         return BCM_E_MEMORY;
    585     }
    586     buffer = (uint32 *) sal_alloc(sizeof(uint32) * SOC_MAX_MEM_WORDS, "data buffer");
    587     if (buffer == NULL) {
    588         sal_free(data);
    589         return BCM_E_MEMORY;
    590     }
    591 
    592     sal_memset(data, 0, data_bytes * sizeof(uint8));
    593     sal_memset(buffer, 0, SOC_MAX_MEM_WORDS * sizeof(uint32));
    594 
    595     /* Read the entry also. */
    596     rv = soc_mem_read(unit, mem,
    597         MEM_BLOCK_ANY, index, (uint32 *)buffer);
    598     if (BCM_FAILURE(rv)) {
    599         sal_free(data);
    600         sal_free(buffer);
    601         return rv;
    602     }
    603 
    604     soc_mem_field_get(unit, mem, (uint32 *) buffer,
    605             OPAQUE_DATAf, (uint32 *) data);
    606 
    607     start = start -1;
    608 
    609     LOG_CLI((BSL_META_U(unit, "\n ***********************************************\n")));
    610     LOG_CLI((BSL_META_U(unit, "\n *****      Session Data Dump Follows      *****\n")));
    611     LOG_CLI((BSL_META_U(unit, "\n ***********************************************\n")));
    612 
    613 
    614     LOG_CLI((BSL_META_U(unit, "\n")));
    615     while (temp) {
    616 
    617         value = 0;
    618         sub_len = 0;
    619         length = temp->info.cont_width / 8;
    620 
    621         if ((temp->info.param_type == bcmiFtGroupParamTypeTsNewLearn) ||
    622             (temp->info.param_type == bcmiFtGroupParamTypeTsFlowStart) ||
    623             (temp->info.param_type == bcmiFtGroupParamTypeTsFlowEnd) ||
    624             (temp->info.param_type == bcmiFtGroupParamTypeTsCheckEvent1) ||
    625             (temp->info.param_type == bcmiFtGroupParamTypeTsCheckEvent2)) {
    626 
    627             etype = 2;
    628             element = bcmi_ft_group_get_tracking_param
    629                           (unit, temp->info.param_type);
    630             sub_len = 2;
    631 
    632         } else if (temp->info.check_id) {
    633             rv = bcmi_ft_flowchecker_get
    634                 (unit, temp->info.check_id, &fc_info);
    635             if (BCM_FAILURE(rv)) {
    636                 sal_free(data);
    637                 sal_free(buffer);
    638                 return rv;
    639             }
    640 
    641             element = fc_info.check1.param;
    642             etype = 0;
    643 
    644         } else if (temp->info.param_type == bcmiFtGroupParamTypeTracking) {
    645             etype = 1;
    646             element = temp->info.param;
    647 
    648         } else {
    649             start -=  length;
    650             temp = temp->next;
    651             continue;
    652         }
    653         first_value = 0;
    654         for (i=0; i<length; i++) {
    655 
    656             if (sub_len && (length > sub_len)) {
    657                 while (i < sub_len) {
    658                     first_value =
    659                        ((first_value) |
    660                            ((data[start-i]) << (((sub_len-1)-i) * 8)));
    661                     i++;
    662                     continue;
    663                 }
    664             }
    665 
    666             value = ((value) | ((data[start-i]) << (((length-1)-i) *8)));
    667         }
    668         start -= length;
    669 
    670         LOG_CLI((BSL_META_U(unit,
    671             "Element -")));
    672         LOG_CLI((BSL_META_U(unit, " %25s "), plist[element]));
    673         LOG_CLI((BSL_META_U(unit, "( %-15s)  | "), elementType[etype] ));
    674 
    675         /*bcmi_ft_group_element_print(unit, element);*/
    676         if ((element == bcmFlowtrackerTrackingParamTypePktCount) ||
    677             (element == bcmFlowtrackerTrackingParamTypeByteCount)) {
    678             LOG_CLI((BSL_META_U(unit,
    679                 " Value -  %-15u"), value));
    680         } else {
    681             if (sub_len) {
    682                 /* Currently first value is only for timestamping. */
    683                 LOG_CLI((BSL_META_U(unit,
    684                     " Value -  %dsec, %dnsec  "), first_value, value));
    685             } else {
    686 
    687                 LOG_CLI((BSL_META_U(unit,
    688                    " Value -  0x%-15x"), value));
    689             }
    690         }
    691 
    692         LOG_CLI((BSL_META_U(unit, "\n")));
    693 
    694         temp = temp->next;
    695 
    696         /* We still need to add data for flowchecker. */
    697     }
    698 
    699     if (data != NULL) {
    700         sal_free(data);
    701     }
    702     if (buffer != NULL) {
    703         sal_free(buffer);
    704     }
    705 
    706     return rv;
    707 }
    708 
    709 /*
    710  * Function:
    711  *     bcmi_ft_alu32_dump
    712  * Purpose:
    713  *     Dump the alu32 data.
    714  * Parameters:
    715  *     unit - (IN) BCM device id
    716  *       id - (IN) Group index to dump.
    717  *     index - (IN) index to dump.
    718  *
    719  * Returns:
    720  *     BCM_E_XXX
    721  */
    722 int
    723 bcmi_ft_alu32_dump(
    724     int unit,
    725     int global_index)
    726 {
    727 
    728     int rv = BCM_E_NONE;
    729     int new_index = -1;
    730     soc_mem_t mem = -1;
    731     int a_idx = -1; /* Array index of field/memory array. */
    732     uint32 alu_fmt[3];
    733     uint32 alu32_specific_ctrlfmt[4];
    734     uint32 alu32_ctrlfmt[6];
    735     bsc_dg_group_alu32_profile_0_entry_t alu32_entry;
    736     uint32 val0, val1, opr0, opr1, check0_attr, check1_attr, update_opr;
    737     uint32 gran0, gran1, update_opr_param, export_mode, clear_on_export;
    738     uint32 export_opr, export_threshold;
    739     bcmi_ft_alu_load_type_t alu_load_type = bcmiFtAluLoadTypeAlu32;
    740     uint32 load_trigger = 0, update_attr = 0;
    741     const char *olist[] = BCM_FT_CHECK_OPERATION_STRINGS;
    742     const char *alist[] = BCM_FT_CHECK_ACTION_STRINGS;
    743 
    744 
    745     sal_memset(alu_fmt, 0, 3 * sizeof(uint32));
    746     sal_memset(alu32_specific_ctrlfmt, 0, 4*sizeof(uint32));
    747     sal_memset(alu32_ctrlfmt, 0, 6*sizeof(uint32));
    748 
    749 
    750     bcmi_ft_alu_load_mem_index_get
    751         (unit, global_index, alu_load_type, &new_index, &mem, &a_idx);
    752 
    753 
    754     /* The profile is set. Write into the index of group. */
    755     rv  = soc_mem_read(unit, mem, MEM_BLOCK_ALL, new_index, &alu32_entry);
    756 
    757     if (BCM_FAILURE(rv)) {
    758         return rv;
    759     }
    760 
    761 
    762     soc_mem_field_get(unit, mem, (uint32 *)&alu32_entry, DATAf,
    763         alu32_ctrlfmt);
    764 
    765 
    766     soc_format_field_get(unit, BSC_TL_DG_TO_DT_ALU32_CONTROL_BUSfmt,
    767         alu32_ctrlfmt, ALU32_SPECIFIC_CONTROL_BUSf, alu32_specific_ctrlfmt);
    768 
    769 
    770     val0 = soc_format_field32_get(unit,
    771                 BSC_TL_DG_TO_DT_ALU32_SPECIFIC_CONTROL_BUSfmt,
    772                 alu32_specific_ctrlfmt, CHECK_0_THRESHOLDf);
    773     val1 = soc_format_field32_get(unit,
    774                 BSC_TL_DG_TO_DT_ALU32_SPECIFIC_CONTROL_BUSfmt,
    775                 alu32_specific_ctrlfmt, CHECK_1_THRESHOLDf);
    776 
    777     gran0 = soc_format_field32_get(unit,
    778                 BSC_TL_DG_TO_DT_ALU32_SPECIFIC_CONTROL_BUSfmt,
    779                 alu32_specific_ctrlfmt, CHECK_0_ATTR_SELECT_GRANf);
    780     gran1 = soc_format_field32_get(unit,
    781                 BSC_TL_DG_TO_DT_ALU32_SPECIFIC_CONTROL_BUSfmt,
    782                 alu32_specific_ctrlfmt, CHECK_1_ATTR_SELECT_GRANf);
    783 
    784     export_threshold = soc_format_field32_get(unit,
    785                 BSC_TL_DG_TO_DT_ALU32_SPECIFIC_CONTROL_BUSfmt,
    786                 alu32_specific_ctrlfmt, EXPORT_THRESHOLDf);
    787 
    788     soc_format_field_get(unit, BSC_TL_DG_TO_DT_ALU32_CONTROL_BUSfmt,
    789         alu32_ctrlfmt, ALU_BASE_CONTROL_BUSf, alu_fmt);
    790 
    791     check0_attr = soc_format_field32_get(unit,
    792                 BSC_TL_DG_TO_DT_ALU_BASE_CONTROL_BUSfmt,
    793                 alu_fmt, CHECK_0_ATTR_SELECTf);
    794 
    795     check1_attr = soc_format_field32_get(unit,
    796                 BSC_TL_DG_TO_DT_ALU_BASE_CONTROL_BUSfmt,
    797                 alu_fmt, CHECK_1_ATTR_SELECTf);
    798 
    799 
    800     opr0 = soc_format_field32_get(unit,
    801                 BSC_TL_DG_TO_DT_ALU_BASE_CONTROL_BUSfmt,
    802                 alu_fmt, CHECK_0_OPERATIONf);
    803 
    804     opr1 = soc_format_field32_get(unit,
    805                 BSC_TL_DG_TO_DT_ALU_BASE_CONTROL_BUSfmt,
    806                 alu_fmt, CHECK_1_OPERATIONf);
    807 
    808 
    809     update_attr = soc_format_field32_get(unit,
    810                   BSC_TL_DG_TO_DT_ALU_BASE_CONTROL_BUSfmt,
    811                   alu_fmt, UPDATE_ATTR_SELECTf);
    812 
    813     update_opr = soc_format_field32_get(unit,
    814                 BSC_TL_DG_TO_DT_ALU_BASE_CONTROL_BUSfmt,
    815                 alu_fmt, UPDATE_OPERATIONf);
    816 
    817     update_opr_param = soc_format_field32_get(unit,
    818                 BSC_TL_DG_TO_DT_ALU_BASE_CONTROL_BUSfmt,
    819                 alu_fmt, UPDATE_OP_PARAMf);
    820 
    821     load_trigger = soc_format_field32_get(unit,
    822                 BSC_TL_DG_TO_DT_ALU_BASE_CONTROL_BUSfmt,
    823                 alu_fmt, LOAD_TRIGGERf);
    824 
    825     export_opr =  soc_format_field32_get(unit,
    826                     BSC_TL_DG_TO_DT_ALU_BASE_CONTROL_BUSfmt,
    827                     alu_fmt, EXPORT_OPERATIONf);
    828 
    829     export_mode =  soc_format_field32_get(unit,
    830                     BSC_TL_DG_TO_DT_ALU_BASE_CONTROL_BUSfmt,
    831                     alu_fmt, EXPORT_CHECK_MODEf);
    832 
    833     clear_on_export =  soc_format_field32_get(unit,
    834                     BSC_TL_DG_TO_DT_ALU_BASE_CONTROL_BUSfmt,
    835                     alu_fmt, CLEAR_ON_EXPORT_ENABLEf);
    836 
    837     LOG_CLI((BSL_META_U(unit, "\n******* ALu32 Global index = %d ******\n "), global_index));
    838 
    839     LOG_CLI((BSL_META_U(unit, "val0 = 0x%x\n "), val0));
    840     opr0 = bcmi_alu_opr_conversion[opr0];
    841     LOG_CLI((BSL_META_U(unit, "opr0 = %s\n "), olist[opr0]));
    842     LOG_CLI((BSL_META_U(unit, "check0_attr = %d\n "), check0_attr));
    843     LOG_CLI((BSL_META_U(unit, "check0_gran = %d\n "), gran0));
    844 
    845     LOG_CLI((BSL_META_U(unit, "val1 = 0x%x\n "), val1));
    846     opr1 = bcmi_alu_opr_conversion[opr1];
    847     LOG_CLI((BSL_META_U(unit, "opr1 = %s\n "), olist[opr1]));
    848     LOG_CLI((BSL_META_U(unit, "check1_attr = %d\n "), check1_attr));
    849     LOG_CLI((BSL_META_U(unit, "check1_gran = %d\n "), gran1));
    850 
    851     LOG_CLI((BSL_META_U(unit, "Update_attr = %d\n "), update_attr));
    852     update_opr = bcmi_alu_action_conversion[update_opr];
    853     if (update_opr == -1) {
    854         LOG_CLI((BSL_META_U(unit, "update_opr = bitwise_or\n ")));
    855     } else {
    856         LOG_CLI((BSL_META_U(unit, "update_opr = %s\n "), alist[update_opr]));
    857     }
    858     LOG_CLI((BSL_META_U(unit, "update_opr_param = %d\n "), update_opr_param));
    859     LOG_CLI((BSL_META_U(unit, "load_trigger = %d\n "), load_trigger));
    860 
    861     export_opr = bcmi_alu_opr_conversion[export_opr];
    862     LOG_CLI((BSL_META_U(unit, "export_opr = %s\n "), olist[export_opr]));
    863     LOG_CLI((BSL_META_U(unit, "export_threshold = %d\n "), export_threshold));
    864     LOG_CLI((BSL_META_U(unit, "export data = %d, %d\n "), export_mode, clear_on_export));
    865 
    866     LOG_CLI((BSL_META_U(unit, "************************************************\n ")));
    867 
    868     return BCM_E_NONE;
    869 }
    870 
    871 /*
    872  * Function:
    873  *     bcmi_ft_alu16_dump
    874  * Purpose:
    875  *     Dump the alu16 data.
    876  * Parameters:
    877  *     unit - (IN) BCM device id
    878  *       id - (IN) Group index to dump.
    879  *     index - (IN) index to dump.
    880  *
    881  * Returns:
    882  *     BCM_E_XXX
    883  */
    884 int
    885 bcmi_ft_alu16_dump(
    886     int unit,
    887     int global_index)
    888 {
    889 
    890     int rv = BCM_E_NONE;
    891     int new_index = -1;
    892     soc_mem_t mem = -1;
    893     int a_idx = -1; /* Array index of field/memory array. */
    894     int load_trigger = 0;
    895     uint32 alu_fmt[3];
    896     uint32 alu16_specific_ctrlfmt[4];
    897     uint32 alu16_ctrlfmt[6];
    898     bsc_dg_group_alu16_profile_0_entry_t alu16_entry;
    899     uint32 val0, val1, opr0, opr1, check0_attr, check1_attr, update_opr;
    900     uint32 export_opr = 0, export_threshold = 0, update_attr = 0;
    901     bcmi_ft_alu_load_type_t alu_load_type = bcmiFtAluLoadTypeAlu16;
    902     const char *olist[] = BCM_FT_CHECK_OPERATION_STRINGS;
    903     const char *alist[] = BCM_FT_CHECK_ACTION_STRINGS;
    904 
    905     sal_memset(alu_fmt, 0, 3 * sizeof(uint32));
    906     sal_memset(alu16_specific_ctrlfmt, 0, 4*sizeof(uint32));
    907     sal_memset(alu16_ctrlfmt, 0, 6*sizeof(uint32));
    908 
    909     bcmi_ft_alu_load_mem_index_get
    910         (unit, global_index, alu_load_type, &new_index, &mem, &a_idx);
    911 
    912 
    913     /* The profile is set. Write into the index of group. */
    914     rv  = soc_mem_read(unit, mem, MEM_BLOCK_ALL, new_index, &alu16_entry);
    915 
    916     if (BCM_FAILURE(rv)) {
    917         return rv;
    918     }
    919 
    920 
    921     soc_mem_field_get(unit, mem, (uint32 *)&alu16_entry, DATAf,
    922         alu16_ctrlfmt);
    923 
    924 
    925     soc_format_field_get(unit, BSC_TL_DG_TO_DT_ALU16_CONTROL_BUSfmt,
    926         alu16_ctrlfmt, ALU16_SPECIFIC_CONTROL_BUSf, alu16_specific_ctrlfmt);
    927 
    928 
    929     val0 = soc_format_field32_get(unit,
    930                 BSC_TL_DG_TO_DT_ALU16_SPECIFIC_CONTROL_BUSfmt,
    931                 alu16_specific_ctrlfmt, CHECK_0_THRESHOLDf);
    932     val1 = soc_format_field32_get(unit,
    933                 BSC_TL_DG_TO_DT_ALU16_SPECIFIC_CONTROL_BUSfmt,
    934                 alu16_specific_ctrlfmt, CHECK_1_THRESHOLDf);
    935 
    936 
    937     export_threshold = soc_format_field32_get(unit,
    938                     BSC_TL_DG_TO_DT_ALU16_SPECIFIC_CONTROL_BUSfmt,
    939                     alu16_specific_ctrlfmt, EXPORT_THRESHOLDf);
    940 
    941 
    942     soc_format_field_get(unit, BSC_TL_DG_TO_DT_ALU16_CONTROL_BUSfmt,
    943         alu16_ctrlfmt, ALU_BASE_CONTROL_BUSf, alu_fmt);
    944 
    945     check0_attr = soc_format_field32_get(unit,
    946                 BSC_TL_DG_TO_DT_ALU_BASE_CONTROL_BUSfmt,
    947                 alu_fmt, CHECK_0_ATTR_SELECTf);
    948 
    949     check1_attr = soc_format_field32_get(unit,
    950                 BSC_TL_DG_TO_DT_ALU_BASE_CONTROL_BUSfmt,
    951                 alu_fmt, CHECK_1_ATTR_SELECTf);
    952 
    953 
    954     opr0 = soc_format_field32_get(unit,
    955                 BSC_TL_DG_TO_DT_ALU_BASE_CONTROL_BUSfmt,
    956                 alu_fmt, CHECK_0_OPERATIONf);
    957 
    958     opr1 = soc_format_field32_get(unit,
    959                 BSC_TL_DG_TO_DT_ALU_BASE_CONTROL_BUSfmt,
    960                 alu_fmt, CHECK_1_OPERATIONf);
    961 
    962     update_attr = soc_format_field32_get(unit,
    963                   BSC_TL_DG_TO_DT_ALU_BASE_CONTROL_BUSfmt,
    964                   alu_fmt, UPDATE_ATTR_SELECTf);
    965 
    966     update_opr = soc_format_field32_get(unit,
    967                 BSC_TL_DG_TO_DT_ALU_BASE_CONTROL_BUSfmt,
    968                 alu_fmt, UPDATE_OPERATIONf);
    969 
    970     load_trigger = soc_format_field32_get(unit,
    971                 BSC_TL_DG_TO_DT_ALU_BASE_CONTROL_BUSfmt,
    972                 alu_fmt, LOAD_TRIGGERf);
    973 
    974     export_opr =  soc_format_field32_get(unit,
    975                     BSC_TL_DG_TO_DT_ALU_BASE_CONTROL_BUSfmt,
    976                     alu_fmt, EXPORT_OPERATIONf);
    977 
    978     LOG_CLI((BSL_META_U(unit, "\n******* ALU16 Global index = %d ******\n "), global_index));
    979 
    980 
    981     LOG_CLI((BSL_META_U(unit, "val0 = %d\n "), val0));
    982     opr0 = bcmi_alu_opr_conversion[opr0];
    983     LOG_CLI((BSL_META_U(unit, "opr0 = %s\n "), olist[opr0]));
    984     LOG_CLI((BSL_META_U(unit, "check0_attr = %d\n "), check0_attr));
    985 
    986     LOG_CLI((BSL_META_U(unit, "val1 = %d\n "), val1));
    987     opr1 = bcmi_alu_opr_conversion[opr1];
    988     LOG_CLI((BSL_META_U(unit, "opr1 = %s\n "), olist[opr1]));
    989     LOG_CLI((BSL_META_U(unit, "check1_attr = %d\n "), check1_attr));
    990 
    991     LOG_CLI((BSL_META_U(unit, "Update_attr = %d\n "), update_attr));
    992     update_opr = bcmi_alu_action_conversion[update_opr];
    993     if (update_opr == -1) {
    994         LOG_CLI((BSL_META_U(unit, "update_opr = bitwise_or\n ")));
    995     } else {
    996         LOG_CLI((BSL_META_U(unit, "update_opr = %s\n "), alist[update_opr]));
    997     }
    998     LOG_CLI((BSL_META_U(unit, "load_trigger = %d\n "), load_trigger));
    999 
   1000     export_opr = bcmi_alu_opr_conversion[export_opr];
   1001     LOG_CLI((BSL_META_U(unit, "export_opr = %s\n "), olist[export_opr]));
   1002     LOG_CLI((BSL_META_U(unit, "export_threshold = %d\n "), export_threshold));
   1003 
   1004     LOG_CLI((BSL_META_U(unit, "**********************************************\n ")));
   1005 
   1006     return BCM_E_NONE;
   1007 }
   1008 
   1009 
   1010 #else /* BCM_FLOWTRCAKER_SUPPORT*/
   1011 int bcmi_ft_group_not_empty;
   1012 #endif /* BCM_FLOWTRCAKER_SUPPORT */
   1013