Shad Ansari | 2f7f9be | 2017-06-07 13:34:53 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * <:copyright-BRCM:2016:DUAL/GPL:standard |
| 4 | * |
| 5 | * Copyright (c) 2016 Broadcom |
| 6 | * All Rights Reserved |
| 7 | * |
| 8 | * Unless you and Broadcom execute a separate written software license |
| 9 | * agreement governing use of this software, this software is licensed |
| 10 | * to you under the terms of the GNU General Public License version 2 |
| 11 | * (the "GPL"), available at http://www.broadcom.com/licenses/GPLv2.php, |
| 12 | * with the following added to such license: |
| 13 | * |
| 14 | * As a special exception, the copyright holders of this software give |
| 15 | * you permission to link this software with independent modules, and |
| 16 | * to copy and distribute the resulting executable under terms of your |
| 17 | * choice, provided that you also meet, for each linked independent |
| 18 | * module, the terms and conditions of the license of that module. |
| 19 | * An independent module is a module which is not derived from this |
| 20 | * software. The special exception does not apply to any modifications |
| 21 | * of the software. |
| 22 | * |
| 23 | * Not withstanding the above, under no circumstances may you combine |
| 24 | * this software in any way with any other Broadcom software provided |
| 25 | * under a license other than the GPL, without Broadcom's express prior |
| 26 | * written consent. |
| 27 | * |
| 28 | * :> |
| 29 | * |
| 30 | *****************************************************************************/ |
| 31 | |
| 32 | #ifndef _BCM_TOPO_H_ |
| 33 | #define _BCM_TOPO_H_ |
| 34 | |
| 35 | #include <bcmolt_conv.h> |
| 36 | #include <bcmos_system.h> |
| 37 | #include <bcmolt_model_types.h> |
| 38 | #include <bal_model_types.h> |
| 39 | |
| 40 | #define BCM_TOPO_DEV_INVALID UINT8_MAX |
| 41 | #define BCM_TOPO_PON_INVALID UINT32_MAX |
| 42 | #define BCM_TOPO_ERR_INVALID UINT32_MAX |
| 43 | #define BCM_TOPO_MAX_NUM_OF_DEVS 8 /* Maxmimum of 8 devices per vOLT. */ |
| 44 | #define BCM_TOPO_MAX_NUM_OF_PONS_PER_DEV 16 |
| 45 | #define BCM_TOPO_MAX_NUM_OF_LOGICAL_PONS (BCM_TOPO_MAX_NUM_OF_DEVS * BCM_TOPO_MAX_NUM_OF_PONS_PER_DEV) |
| 46 | |
| 47 | #define BCM_TOPO_FOR_EACH_DEV(device_id) \ |
| 48 | for (device_id = bcm_topo_dev_get_next(BCM_TOPO_DEV_INVALID); device_id != BCM_TOPO_DEV_INVALID; device_id = bcm_topo_dev_get_next(device_id)) |
| 49 | |
| 50 | #define BCM_TOPO_DEV_FOR_EACH_PON(device_id, pon) \ |
| 51 | for (pon = bcm_topo_pon_get_next(device_id, BCM_TOPO_PON_INVALID); pon != BCM_TOPO_PON_INVALID; pon = bcm_topo_pon_get_next(device_id, pon)) |
| 52 | |
| 53 | #define BCM_TOPO_FOR_EACH_PON(device_id, pon) \ |
| 54 | for (device_id = bcm_topo_dev_get_next(BCM_TOPO_DEV_INVALID); device_id != BCM_TOPO_DEV_INVALID; device_id = bcm_topo_dev_get_next(device_id)) \ |
| 55 | BCM_TOPO_DEV_FOR_EACH_PON(device_id, pon) |
| 56 | |
| 57 | #define BCM_TOPO_FOR_EACH_ONU(pon, onu) \ |
| 58 | for (onu = 0; onu < bcm_topo_pon_get_max_num_of_onus(pon); onu++) |
| 59 | |
| 60 | typedef enum |
| 61 | { |
| 62 | BCM_TOPO_PON_MODE_GPON, |
| 63 | BCM_TOPO_PON_MODE_XGPON, |
| 64 | BCM_TOPO_PON_MODE_XGS, |
| 65 | BCM_TOPO_PON_MODE_EPON_TDMA, |
| 66 | BCM_TOPO_PON_MODE_EPON_1G, |
| 67 | BCM_TOPO_PON_MODE_EPON_10G, |
| 68 | BCM_TOPO_PON_MODE_INVALID, |
| 69 | BCM_TOPO_PON_MODE__NUM_OF, |
| 70 | } bcm_topo_pon_mode; |
| 71 | |
| 72 | typedef enum |
| 73 | { |
| 74 | BCM_TOPO_PON_FAMILY_GPON, /* GPON, XGPON, XGS, NGPON2 */ |
| 75 | BCM_TOPO_PON_FAMILY_EPON, |
| 76 | BCM_TOPO_PON_FAMILY_INVALID, |
| 77 | BCM_TOPO_PON_FAMILY__NUM_OF, |
| 78 | } bcm_topo_pon_family; |
| 79 | |
| 80 | typedef enum |
| 81 | { |
| 82 | BCM_TOPO_PON_SUB_FAMILY_GPON, /* GPON only */ |
| 83 | BCM_TOPO_PON_SUB_FAMILY_XGPON, /* XGPON, XGS, NGPON2 */ |
| 84 | BCM_TOPO_PON_SUB_FAMILY_EPON, |
| 85 | BCM_TOPO_PON_SUB_FAMILY_INVALID, |
| 86 | BCM_TOPO_PON_SUB_FAMILY__NUM_OF, |
| 87 | } bcm_topo_pon_sub_family; |
| 88 | |
| 89 | /* User context identifier - can be extended if more modules in the system use the bcm_topo.context. */ |
| 90 | typedef enum |
| 91 | { |
| 92 | BCM_TOPO_PON_CONTEXT_ID_MAC_UTIL, |
| 93 | BCM_TOPO_PON_CONTEXT_ID_OMCI_SVC, |
| 94 | BCM_TOPO_PON_CONTEXT_ID_RSC_MGR, |
| 95 | BCM_TOPO_PON_CONTEXT_ID__NUM_OF, |
| 96 | } bcm_topo_pon_context_id; |
| 97 | |
| 98 | typedef struct |
| 99 | { |
| 100 | uint32_t num_of_devs; |
| 101 | uint32_t num_of_pons_per_dev; |
| 102 | bcm_topo_pon_mode pon_mode; |
| 103 | } bcm_topo_params; |
| 104 | |
| 105 | /** |
| 106 | * @brief Get the PON mode of a given device ID. |
| 107 | * @param device_id device ID |
| 108 | * |
| 109 | * @returns PON mode or Null on error |
| 110 | */ |
| 111 | const char *bcm_topo_dev_get_pon_mode_str(bcmolt_devid device_id); |
| 112 | |
| 113 | |
| 114 | /** |
| 115 | * @brief Get the max number of pons of a given device ID. |
| 116 | * @param device_id device ID |
| 117 | * |
| 118 | * @returns the max number of pons or -1 on error |
| 119 | */ |
| 120 | int bcm_topo_dev_get_max_pon(bcmolt_devid device_id); |
| 121 | |
| 122 | /** |
| 123 | * @brief Get the PON mode of a given logical PON ID. |
| 124 | * @param pon Logical PON ID |
| 125 | * |
| 126 | * @returns PON mode or BCM_TOPO_PON_MODE_INVALID on error |
| 127 | */ |
| 128 | bcm_topo_pon_mode bcm_topo_pon_get_pon_mode(uint32_t pon); |
| 129 | |
| 130 | /** |
| 131 | * @brief Get the PON family of a given logical PON ID. |
| 132 | * @param pon Logical PON ID |
| 133 | * |
| 134 | * @returns PON mode or BCM_TOPO_PON_FAMILY_INVALID on error |
| 135 | */ |
| 136 | bcm_topo_pon_family bcm_topo_pon_get_pon_family(uint32_t pon); |
| 137 | |
| 138 | /** |
| 139 | * @brief Get the PON sub-family of a given logical PON ID. |
| 140 | * @param pon Logical PON ID |
| 141 | * |
| 142 | * @returns PON mode or BCM_TOPO_PON_SUB_FAMILY_INVALID on error |
| 143 | */ |
| 144 | bcm_topo_pon_sub_family bcm_topo_pon_get_pon_sub_family(uint32_t pon); |
| 145 | |
| 146 | /** |
| 147 | * @brief Get the number of ONUs of a given logical PON ID. |
| 148 | * @param pon Logical PON ID |
| 149 | * |
| 150 | * @returns Number of ONUs or BCM_TOPO_ERR_INVALID on error |
| 151 | */ |
| 152 | uint32_t bcm_topo_pon_get_max_num_of_onus(uint32_t pon); |
| 153 | |
| 154 | /** |
| 155 | * @brief Return whether a given logical PON is in the valid range. |
| 156 | * |
| 157 | * @returns BCMOS_TRUE is the given logical PON is in the valid range, BCMOS_FALSE otherwise |
| 158 | */ |
| 159 | bcmos_bool bcm_topo_pon_is_valid(uint32_t pon); |
| 160 | |
| 161 | /** |
| 162 | * @brief Traverse devices |
| 163 | * @param device_id Device iterator. Should be BCM_TOPO_DEV_INVALID at the beginning. |
| 164 | * |
| 165 | * @returns Next device, or BCM_TOPO_DEV_INVALID to mark that no more devices are available. |
| 166 | */ |
| 167 | bcmolt_devid bcm_topo_dev_get_next(bcmolt_devid device_id); |
| 168 | |
| 169 | /** |
| 170 | * @brief Traverse logical PONs within a given device. |
| 171 | * @param device_id Device id |
| 172 | * @param pon Logical PON iterator. Should be BCM_TOPO_PON_INVALID at the beginning. |
| 173 | * |
| 174 | * @returns Next logical PON on this device, or BCM_TOPO_PON_INVALID to mark that no more PONs are available. |
| 175 | */ |
| 176 | uint32_t bcm_topo_pon_get_next(bcmolt_devid device_id, uint32_t pon); |
| 177 | |
| 178 | /** |
| 179 | * @brief Get device ID and physical PON ID from logical PON ID. |
| 180 | * @param logical_pon logical PON ID |
| 181 | * @param *device_id Pointer to device id |
| 182 | * @param *physical_pon Pointer to physical PON ID |
| 183 | * |
| 184 | * @returns bcmos_errno |
| 185 | * @note In general, the physical PON ID is used in the hardware directed function calls. |
| 186 | */ |
| 187 | bcmos_errno bcm_topo_pon_get_logical2physical(uint32_t logical_pon, bcmolt_devid *device_id, uint32_t *physical_pon); |
| 188 | |
| 189 | /** |
| 190 | * @brief Get logical PON ID from device ID and physical PON ID. |
| 191 | * @param device_id Device id |
| 192 | * @param physical_pon Physical PON ID |
| 193 | * @param *logical_pon Pointer to logical PON ID |
| 194 | * |
| 195 | * @returns bcmos_errno |
| 196 | * @note In general, the logical PON ID is used in the BAL core directed function calls. |
| 197 | */ |
| 198 | bcmos_errno bcm_topo_pon_get_physical2logical(bcmolt_devid device_id, uint32_t physical_pon, uint32_t *logical_pon); |
| 199 | |
| 200 | /** |
| 201 | * @brief Set user context for a given logical PON ID. |
| 202 | * @param pon Logical PON ID |
| 203 | * @param pon_context_id The identity of the module using the context |
| 204 | * @param context Pointer to user context |
| 205 | * |
| 206 | * @returns bcmos_errno |
| 207 | */ |
| 208 | bcmos_errno bcm_topo_pon_set_context(uint32_t pon, bcm_topo_pon_context_id pon_context_id, void *context); |
| 209 | |
| 210 | /** |
| 211 | * @brief Get user context for a given logical PON ID. |
| 212 | * @param pon Logical PON ID |
| 213 | * @param pon_context_id The identity of the module using the context |
| 214 | * |
| 215 | * @returns User context or NULL if there's an error |
| 216 | */ |
| 217 | void *bcm_topo_pon_get_context(uint32_t pon, bcm_topo_pon_context_id pon_context_id); |
| 218 | |
| 219 | /** |
| 220 | * @brief Initialize topology module, either by arguments (probably received from CLI) or by a topology file. The rule is at least one of them must be specified and exist. If both are |
| 221 | * specified and exist, then we rely on topology file. |
| 222 | * Pay attention that when not using a file, the user have less freedom. For example: |
| 223 | * - The user won't be able to have devices with different PON modes. |
| 224 | * - The user won't be able to have devices with different number of PONs. |
| 225 | * - The user won't be able to map logical PON to (device, physical PON). We assume that logical_pon = (device * num_of_pons_per_dev) + physical_pon. |
| 226 | * @param params Topology parameters. If NULL, we rely on topology file. |
| 227 | * @param topo_filename File containing bcm_topo.configuration in a .csv format |
| 228 | * The columns are: |
| 229 | * Logical PON ID, PON Mode, Physical Device ID, Physical PON ID |
| 230 | * |
| 231 | * @returns bcmos_errno |
| 232 | */ |
| 233 | bcmos_errno bcm_topo_init(bcm_topo_params *params, const char *topo_filename); |
| 234 | |
| 235 | /** |
| 236 | * @brief Returns whether the topology module has been initialized. |
| 237 | * |
| 238 | * @returns BCMOS_TRUE if topology module has been initialized |
| 239 | */ |
| 240 | bcmos_bool bcm_topo_is_initialized(void); |
| 241 | |
| 242 | #define BCM_TOPO_MAX_NNI_PORTS 16 |
| 243 | |
| 244 | /** |
| 245 | * @brief Set the max number of nnis of a given device ID. |
| 246 | * @param device_id device ID |
| 247 | * @param num_nni_ports nni ports on the device |
| 248 | * |
| 249 | * @returns BCMOS_TRUE |
| 250 | */ |
| 251 | bcmos_bool bcm_topo_dev_set_max_nni(bcmolt_devid device_id, uint32_t num_nni_ports); |
| 252 | |
| 253 | /** |
| 254 | * @brief Get the max number of nnis of a given device ID. |
| 255 | * @param device_id device ID |
| 256 | * @param p_num_nni_ports pointer for the retrieved nni ports on the device |
| 257 | * |
| 258 | * @returns BCMOS_TRUE |
| 259 | */ |
| 260 | bcmos_bool bcm_topo_dev_get_max_nni(bcmolt_devid device_id, uint32_t *p_num_nni_ports); |
| 261 | |
| 262 | /** |
| 263 | * @brief Return whether a given logical NNI is in the valid range. |
| 264 | * |
| 265 | * @returns BCMOS_TRUE is the given logical NNI is in the valid range, BCMOS_FALSE otherwise |
| 266 | */ |
| 267 | bcmos_bool bcm_topo_nni_is_valid(uint32_t nni); |
| 268 | |
| 269 | #endif |
| 270 | |