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

flexport_common.c (3766B)


      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:  flexport_common.c
      8 */
      9 
     10 
     11 #include <shared/bsl.h>
     12 #include <soc/drv.h>
     13 #include <soc/defs.h>
     14 #include <soc/mem.h>
     15 #include <soc/esw/port.h>
     16 #include <soc/tdm/core/tdm_top.h>
     17 
     18 
     19 #include <soc/flexport/flexport_common.h>
     20 
     21 /*! @file flexport_common.c
     22  *   @brief FlexPort common (across chips) functions and structures.
     23  *   Details are shown below.
     24  */
     25 
     26 
     27 /*! @fn int soc_detach_flex_phase(int unit, phase_callback_type *flex_phases,
     28  *                phase_callback_type phase, int *phase_pos)
     29  *   @param unit Chip unit number.
     30  *   @param flex_phases Pointer to the array holding the callbacks implementing
     31  *          FlexPort phases.
     32  *   @param phase The callback implementing the phase to be detached.
     33  *   @param phase_pos Position of the detached callback in the array is
     34  *          returned
     35  *          in this variable.
     36  *   @brief Detaches a phase from the FlexPort operations implemented with a
     37  *          callback function. Detaches the first instance of the callback.
     38  */
     39 int
     40 soc_detach_flex_phase (
     41     int                  unit,
     42     phase_callback_type *flex_phases,
     43     phase_callback_type  phase,
     44     int                 *phase_pos
     45     )
     46 {
     47     int i;
     48 
     49     *phase_pos = -1;
     50     for (i = 0; i < MAX_FLEX_PHASES; i++) {
     51         if (flex_phases[i] == phase) {
     52             flex_phases[i] = NULL;
     53             *phase_pos = i;
     54             break;
     55         }
     56     }
     57 
     58     if (*phase_pos < 0) {
     59         LOG_ERROR(BSL_LS_SOC_PORT, (BSL_META_U(unit, "Phase not found, noting detached!\n")));
     60         return SOC_E_NONE;
     61     }
     62 
     63     return SOC_E_NONE;
     64 }
     65 
     66 
     67 /*! @fn int soc_attach_flex_phase(int unit, phase_callback_type *flex_phases,
     68  *               phase_callback_type phase, int phase_pos)
     69  *   @param unit Chip unit number.
     70  *   @param flex_phases Pointer to the array holding the callbacks implementing
     71  *          FlexPort phases.
     72  *   @param phase The callback implementing the phase to be attached.
     73  *   @param phase_pos Position where the callback be attached in the array.
     74  *   @brief Attaches a phase in the FlexPort operations implemented with a
     75  *          callback function.
     76  */
     77 int
     78 soc_attach_flex_phase (
     79     int                  unit,
     80     phase_callback_type *flex_phases,
     81     phase_callback_type  phase,
     82     int                  phase_pos
     83     )
     84 {
     85     if (phase_pos < 0 || phase_pos >= MAX_FLEX_PHASES) {
     86         LOG_ERROR(BSL_LS_SOC_COMMON,
     87                   (BSL_META_U(unit,
     88                        "Illegal phase position; "
     89                        "must be in the 0 .. %0d range!\n"),
     90                    MAX_FLEX_PHASES-1));
     91         return SOC_E_FAIL;
     92     }
     93 
     94     flex_phases[phase_pos] = phase;
     95 
     96     return SOC_E_NONE;
     97 }
     98 
     99 
    100 /*! @fn int soc_check_flex_phase(int unit, phase_callback_type *flex_phases,
    101  *               phase_callback_type phase, int *present)
    102  *   @param unit Chip unit number.
    103  *   @param flex_phases Pointer to the array holding the callbacks implementing
    104  *          FlexPort phases.
    105  *   @param phase The presence of callback phase to be checked.
    106  *   @param present Set to 1 if the callback exists, 0 otherwise.
    107  *   @brief Checks whether a phase callback function exists in the phase array.
    108  */
    109 int
    110 soc_check_flex_phase (
    111     int                  unit,
    112     phase_callback_type *flex_phases,
    113     phase_callback_type  phase,
    114     int                 *present
    115     )
    116 {
    117     int i;
    118 
    119     *present = -1;
    120     for (i = 0; i < MAX_FLEX_PHASES; i++) {
    121         if (flex_phases[i] == phase) {
    122             *present = 1;
    123             break;
    124         }
    125     }
    126 
    127     if (*present < 0) {
    128         *present = 0;
    129     }
    130 
    131     return SOC_E_NONE;
    132 }