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

tdm_mv2_proc.c (6311B)


      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  * $All Rights Reserved.$
      7  *
      8  * TDM chip operations
      9  */
     10 #ifdef _TDM_STANDALONE
     11 	#include <tdm_top.h>
     12 #else
     13 	#include <soc/tdm/core/tdm_top.h>
     14 #endif
     15 
     16 
     17 /**
     18 @name: tdm_mv2_proc_cal_ancl
     19 @param:
     20 
     21 Allocate ancillary slots with matched speed rates accordingly
     22  */
     23 int
     24 tdm_mv2_proc_cal_ancl(tdm_mod_t *_tdm)
     25 {
     26     int i, j, k, k_prev, k_idx, idx_up, idx_dn, result=PASS;
     27     int param_lr_limit, param_ancl_num, param_cal_len, 
     28         param_token_empty, param_token_ancl,
     29         param_lr_en;
     30     int *param_cal_main;
     31     
     32     param_lr_limit    = _tdm->_chip_data.soc_pkg.lr_idx_limit;
     33     param_ancl_num    = _tdm->_chip_data.soc_pkg.tvec_size;
     34     param_cal_len     = param_lr_limit + param_ancl_num;
     35     param_token_empty = _tdm->_chip_data.soc_pkg.num_ext_ports;
     36     param_token_ancl  = _tdm->_chip_data.soc_pkg.soc_vars.ancl_token;
     37     param_lr_en       = _tdm->_core_data.vars_pkg.lr_enable;
     38     
     39     /* allocate ANCL slots */
     40     TDM_SEL_CAL(_tdm->_core_data.vars_pkg.cal_id,param_cal_main);
     41     if (param_ancl_num>0){
     42         TDM_PRINT1("TDM: Allocate %d ANCL slots\n\n", param_ancl_num);
     43         if (param_lr_en==BOOL_TRUE){
     44             k = 0;
     45             for (j=0; j<param_ancl_num; j++){
     46                 idx_up = 0;
     47                 idx_dn = 0;
     48                 k_idx  = 0;
     49                 k_prev = k;
     50                 if (j==(param_ancl_num-1)){
     51                     k = param_cal_len - 1;
     52                 } else {
     53                     k = k_prev + ((param_cal_len-k_prev)/(param_ancl_num-j)) -1;
     54                 }
     55                 for (i=k; i>0 && i<param_cal_len; i--){
     56                     if (param_cal_main[i]==param_token_empty){
     57                         idx_up = i;
     58                         break;
     59                     }
     60                 }
     61                 for (i=k; i<param_cal_len; i++){
     62                     if (param_cal_main[i]==param_token_empty){
     63                         idx_dn = i;
     64                         break;
     65                     }
     66                 }
     67                 if (idx_up>0 || idx_dn>0){
     68                     if (idx_up>0 && idx_dn>0){
     69                         k_idx = ((k-idx_up)<(idx_dn-k))?(idx_up):(idx_dn);
     70                     } else if (idx_up>0){
     71                         k_idx = idx_up;
     72                     } else if (idx_dn>0){
     73                         k_idx = idx_dn;
     74                     }
     75                 }
     76                 if (k_idx==0){
     77                     for (i=(param_cal_len-1); i>0; i--){
     78                         if (param_cal_main[i]==param_token_empty){
     79                             k_idx = i;
     80                             break;
     81                         }
     82                     }
     83                 }
     84                 if (k_idx>0 && k_idx<param_cal_len){
     85                     param_cal_main[k_idx] = param_token_ancl;
     86                     TDM_PRINT2("TDM: Allocate %d-th ANCL slot at index #%03d\n",
     87                                 j+1, k_idx);
     88                 } else {
     89                     TDM_WARN1("TDM: Failed in %d-th ANCL slot allocation\n",j);
     90                     result = FAIL;
     91                 }
     92             }
     93         } else {
     94             k_prev = 0;
     95             for (j=0; j<param_ancl_num; j++){
     96                 k_idx = k_prev + ((param_cal_len-k_prev)/(param_ancl_num-j)) - 1;
     97                 param_cal_main[k_idx] = param_token_ancl;
     98                 k_prev= k_idx+1;
     99                 TDM_PRINT1("TDM: Allocate ANCL slot at index #%03d\n",
    100                             k_idx);
    101             }
    102         }
    103         TDM_SML_BAR
    104     }
    105     return result;
    106 }
    107 
    108 
    109 /**
    110 @name: tdm_mv2_proc_cal_idle
    111 @param:
    112 
    113 Allocate idle slots with matched speed rates accordingly
    114  */
    115 int
    116 tdm_mv2_proc_cal_idle( tdm_mod_t *_tdm )
    117 {
    118     int i, result=PASS;
    119     int param_lr_limit, param_ancl_num, param_cal_len, 
    120         param_token_empty, param_token_ovsb,
    121         param_token_idl1, param_token_idl2,
    122         param_os_en;
    123     int *param_cal_main;
    124     
    125     param_lr_limit    = _tdm->_chip_data.soc_pkg.lr_idx_limit;
    126     param_ancl_num    = _tdm->_chip_data.soc_pkg.tvec_size;
    127     param_cal_len     = param_lr_limit + param_ancl_num;
    128     param_token_empty = _tdm->_chip_data.soc_pkg.num_ext_ports;
    129     param_token_ovsb  = _tdm->_chip_data.soc_pkg.soc_vars.ovsb_token;
    130     param_token_idl1  = _tdm->_chip_data.soc_pkg.soc_vars.idl1_token;
    131     param_token_idl2  = _tdm->_chip_data.soc_pkg.soc_vars.idl2_token;
    132     param_os_en       = _tdm->_core_data.vars_pkg.os_enable;
    133     
    134     TDM_SEL_CAL(_tdm->_core_data.vars_pkg.cal_id,param_cal_main);
    135     
    136     if (param_os_en==BOOL_TRUE){
    137         for (i=0; i<param_cal_len; i++){
    138             if (param_cal_main[i]==param_token_empty){
    139                 param_cal_main[i] = param_token_ovsb;
    140             }
    141         }
    142     }
    143     else {
    144         for (i=0; i<param_cal_len; i++){
    145             if (param_cal_main[i]==param_token_empty){
    146                 if ((i%2)==0){
    147                     param_cal_main[i] = param_token_idl1;
    148                 }
    149                 else {
    150                     param_cal_main[i] = param_token_idl2;
    151                 }
    152             }
    153         }
    154     }
    155 
    156     return result;
    157 }
    158 
    159 
    160 /**
    161 @name: tdm_mv2_proc_cal_lr
    162 @param:
    163 
    164 Allocate linerate slots with matched speed rates accordingly
    165  */
    166 int
    167 tdm_mv2_proc_cal_lr( tdm_mod_t *_tdm )
    168 {
    169     int result=PASS;
    170     
    171     /* pre-allocation */
    172     if(_tdm->_core_exec[TDM_CORE_EXEC__VMAP_PREALLOC](_tdm)!=PASS){
    173         result = FAIL;
    174     }
    175     /* allocation */
    176     if (result == PASS) {
    177         if(_tdm->_core_exec[TDM_CORE_EXEC__VMAP_ALLOC](_tdm)!=PASS){
    178             result = FAIL;
    179         }
    180     }
    181     
    182     return result;
    183 }
    184 
    185 
    186 /**
    187 @name: tdm_mv2_proc_cal
    188 @param:
    189 
    190 Allocate slots for linerate/oversub/ancl ports with matched speed rates accordingly
    191  */
    192 int
    193 tdm_mv2_proc_cal(tdm_mod_t *_tdm)
    194 {
    195     /* allocate LINERATE slots */
    196     if(tdm_mv2_proc_cal_lr(_tdm)!=PASS){
    197         return (TDM_EXEC_CORE_SIZE+1);
    198     }
    199     /* allocate ANCILLARY slots */
    200     if(tdm_mv2_proc_cal_ancl(_tdm)!=PASS){
    201         return (TDM_EXEC_CORE_SIZE+1);
    202     }
    203     /* allocate IDLE/OVSB slots */
    204     if(tdm_mv2_proc_cal_idle(_tdm)!=PASS){
    205         return (TDM_EXEC_CORE_SIZE+1);
    206     }
    207     
    208     return ( _tdm->_core_exec[TDM_CORE_EXEC__SCHEDULER](_tdm) );
    209 }