topo.c (2955B)
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: topo.c 8 * Purpose: Topology mapping, when so programmed. 9 * Requires: 10 */ 11 12 13 #include <soc/drv.h> 14 15 #include <bcm/topo.h> 16 #include <bcm/error.h> 17 #include <bcm/stack.h> 18 19 static bcm_topo_map_f _topo_map; 20 21 22 /* 23 * Function: 24 * bcm_topo_map_set/get 25 * Purpose: 26 * Set/get the map used by topo_port_resolve 27 * Parameters: 28 * _map - (OUT for get) The function pointer to use 29 * Returns: 30 * BCM_E_NONE 31 * Notes: 32 * These functions are not dispatchable. The board type 33 * and topology information determine the map to use. 34 */ 35 36 int 37 bcm_topo_map_set(bcm_topo_map_f _map) 38 { 39 _topo_map = _map; 40 41 return BCM_E_NONE; 42 } 43 44 int 45 bcm_topo_map_get(bcm_topo_map_f *_map) 46 { 47 *_map = _topo_map; 48 49 return BCM_E_NONE; 50 } 51 52 53 /* 54 * Default topology mapping function. 55 * This routine is used when no board specific mapping function 56 * has been programmed. It knows about common single board configurations. 57 */ 58 59 STATIC int 60 _bcm_topo_default_map(int unit, int dest_modid, bcm_port_t *exit_port) 61 { 62 int rv, local_mod, local_mod_count; 63 bcm_port_t port; 64 bcm_pbmp_t pbmp; 65 66 /* is the destination local? */ 67 rv = bcm_stk_my_modid_get(unit, &local_mod); 68 if (BCM_E_NONE != rv) { 69 return rv; 70 } 71 rv = bcm_stk_modid_count(unit, &local_mod_count); 72 if (BCM_E_NONE != rv) { 73 return rv; 74 } 75 76 if (dest_modid >= local_mod && dest_modid < local_mod + local_mod_count) { 77 *exit_port = -1; 78 return BCM_E_NONE; 79 } 80 81 /* handles xgs switches */ 82 rv = bcm_stk_modport_get(unit, dest_modid, exit_port); 83 if (rv != BCM_E_UNAVAIL) { 84 return rv; 85 } 86 87 /* handles xgs fabrics */ 88 rv = bcm_stk_ucbitmap_get(unit, -1, dest_modid, &pbmp); 89 if (rv != BCM_E_UNAVAIL) { 90 if (rv >= 0) { 91 BCM_PBMP_ITER(pbmp, port) { 92 *exit_port = port; 93 break; 94 } 95 } 96 return rv; 97 } 98 99 /* handles strata back to back boards */ 100 101 SOC_PBMP_STACK_ACTIVE_GET(unit, pbmp); 102 if (BCM_PBMP_NOT_NULL(pbmp)) { 103 BCM_PBMP_ITER(pbmp, port) { 104 *exit_port = port; /* just grab the first stack port */ 105 break; 106 } 107 return BCM_E_NONE; 108 } 109 110 /* out of ideas */ 111 return BCM_E_UNAVAIL; 112 } 113 114 /* 115 * Function: 116 * _bcm_topo_port_get 117 * Purpose: 118 * Helper function to bcm_topo_port_get API 119 * Parameters: 120 * unit - The source unit 121 * dest_modid - Destination to reach 122 * exit_port - (OUT) Port to exit device on 123 * Returns: 124 * BCM_E_XXX 125 * Notes: 126 * The code for the local board is programmed by 127 */ 128 129 int 130 _bcm_topo_port_get(int unit, int dest_modid, bcm_port_t *exit_port) 131 { 132 if (_topo_map == NULL) { 133 return _bcm_topo_default_map(unit, dest_modid, exit_port); 134 } 135 136 return _topo_map(unit, dest_modid, exit_port); 137 } 138