alpm_cmn.c (3623B)
1 /* 2 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 3 * 4 * Copyright 2007-2019 Broadcom Inc. All rights reserved. 5 * 6 * File: alpm_common.c 7 * Purpose: ALPM common code. 8 * Requires: 9 */ 10 11 /* Implementation notes: 12 */ 13 #include <shared/bsl.h> 14 15 #include <soc/mem.h> 16 #include <soc/drv.h> 17 #include <soc/debug.h> 18 #include <soc/error.h> 19 #include <soc/lpm.h> 20 #include <soc/trident2.h> 21 #include <soc/tomahawk.h> 22 #include <soc/trident3.h> 23 #include <soc/apache.h> 24 #include <soc/monterey.h> 25 #include <shared/bsl.h> 26 27 #ifdef ALPM_ENABLE 28 #if defined(BCM_TOMAHAWK_SUPPORT) || defined(BCM_APACHE_SUPPORT) 29 30 #include <shared/util.h> 31 #include <shared/l3.h> 32 #include <soc/alpm.h> 33 #include <soc/esw/alpm_int.h> 34 #include <soc/esw/trie.h> 35 36 /* returns 0 for Combined Search mode and 1 for Parallel Search mode, 37 * 2 for TCAM/ALPM mode, equals to L3_DEFIP_RPF_CONTROLr.LOOKUP_MODEf value 38 */ 39 int 40 soc_alpm_cmn_mode_get(int unit) 41 { 42 int mode = 0; 43 44 /* 'mode' here equals to l3_alpm_enable config property value */ 45 #if defined(BCM_APACHE_SUPPORT) 46 if (SOC_IS_APACHE(unit)) { 47 mode = soc_apache_alpm_mode_get(unit); 48 } 49 #endif 50 #if defined(BCM_TOMAHAWK_SUPPORT) 51 if (SOC_IS_TOMAHAWKX(unit)) { 52 mode = soc_tomahawk_alpm_mode_get(unit); 53 } 54 #endif 55 #if defined(BCM_TRIDENT3_SUPPORT) 56 if (SOC_IS_TRIDENT3X(unit)) { 57 mode = soc_trident3_alpm_mode_get(unit); 58 } 59 #endif 60 switch (mode) { 61 case 1: /* Parallel mode */ 62 return SOC_ALPM_MODE_PARALLEL; 63 case 3: /* TCAM/ALPM mode */ 64 return SOC_ALPM_MODE_TCAM_ALPM; 65 case 2: 66 default: /* Combined mode */ 67 return SOC_ALPM_MODE_COMBINED; 68 } 69 70 return SOC_ALPM_MODE_COMBINED; 71 } 72 73 int soc_alpm_cmn_banks_get(int unit) 74 { 75 int banks = 0; 76 #if defined(BCM_APACHE_SUPPORT) 77 if (SOC_IS_APACHE(unit)) { 78 banks = soc_apache_get_alpm_banks(unit); 79 } 80 #endif 81 #if defined(BCM_TOMAHAWK_SUPPORT) 82 if (SOC_IS_TOMAHAWKX(unit)) { 83 banks = soc_th_get_alpm_banks(unit); 84 } 85 #endif 86 #if defined(BCM_TRIDENT3_SUPPORT) 87 if (SOC_IS_TRIDENT3X(unit)) { 88 banks = soc_trident3_get_alpm_banks(unit); 89 } 90 #endif 91 92 return banks; 93 } 94 95 #endif /* TOMAHAWK APACHE */ 96 #endif /* ALPM_ENABLE */ 97 98 void soc_alpm_cmn_bkt_view_set(int unit, int index, soc_mem_t view) 99 { 100 #if defined(BCM_APACHE_SUPPORT) 101 if (SOC_IS_APACHE(unit)) { 102 _soc_apache_alpm_bkt_view_set(unit, index, view); 103 } 104 #endif 105 #if defined(BCM_TOMAHAWK_SUPPORT) 106 if (SOC_IS_TOMAHAWKX(unit)) { 107 _soc_tomahawk_alpm_bkt_view_set(unit, index, view); 108 } 109 #endif 110 #if defined(BCM_TRIDENT3_SUPPORT) 111 if (SOC_IS_TRIDENT3X(unit) && !SOC_IS_HELIX5(unit)) { 112 _soc_trident3_alpm_bkt_view_set(unit, index, view); 113 } 114 #endif 115 } 116 117 soc_mem_t soc_alpm_cmn_bkt_view_get(int unit, int index) 118 { 119 soc_mem_t mem = INVALIDm; 120 #if defined(BCM_APACHE_SUPPORT) 121 if (SOC_IS_APACHE(unit)) { 122 mem = _soc_apache_alpm_bkt_view_get(unit, index); 123 } 124 #endif 125 #if defined(BCM_TOMAHAWK_SUPPORT) 126 if (SOC_IS_TOMAHAWKX(unit)) { 127 mem = _soc_tomahawk_alpm_bkt_view_get(unit, index); 128 } 129 #endif 130 #if defined(BCM_TRIDENT3_SUPPORT) 131 if (SOC_IS_TRIDENT3X(unit) && !SOC_IS_HELIX5(unit)) { 132 mem = _soc_trident3_alpm_bkt_view_get(unit, index); 133 } 134 #endif 135 136 return mem; 137 } 138 139 int 140 soc_alpm_l3_defip_index_map(int unit, soc_mem_t mem, int index) 141 { 142 return soc_trident2_l3_defip_index_map(unit, mem, index); 143 } 144 145 int 146 soc_alpm_l3_defip_index_remap(int unit, soc_mem_t mem, int index) 147 { 148 return soc_trident2_l3_defip_index_remap(unit, mem, index); 149 } 150