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 | /** |
| 33 | * @file bal_dpp_qos_map.c |
| 34 | * @brief BAL Switch Util QoS map management API |
| 35 | * |
| 36 | * This file contains the data structures and functions for |
| 37 | * configuring and managing the pcp bits translation services for |
| 38 | * DUNE Pack Processor (DPP). |
| 39 | * |
| 40 | * The pcp translation service is accomplished using ING ingress vlan translation API |
| 41 | * The API required a Qos map table for pcp translatin on a LIF. |
| 42 | * This file defines 15 pre-map tables for all known use cases. |
| 43 | * |
| 44 | * A set of utilities API are included for callers to determine which table to use |
| 45 | * |
| 46 | * ******************************************************************************** |
| 47 | * |
| 48 | */ |
| 49 | |
| 50 | /*@{*/ |
| 51 | #ifndef TEST_SW_UTIL_LOOPBACK |
| 52 | |
| 53 | #include <stdint.h> |
| 54 | |
| 55 | #include "bcm_dev_log.h" |
| 56 | #include "bcmos_errno.h" |
| 57 | #include "bal_dpp_qos_map.h" |
| 58 | |
| 59 | #include "bal_switch_util.h" /* for definition of log_id_sw_util */ |
| 60 | |
| 61 | #include "bcm/error.h" |
| 62 | #include "bcm/qos.h" |
| 63 | |
| 64 | #define BAL_BCM_PCP_MAP_NUM 15 |
| 65 | #define BAL_BCM_PCP_MAP_ENTRIES 8 |
| 66 | #define BAL_BCM_MAX_PCP_VALUE 7 |
| 67 | #define BAL_BCM_FIXED_PCP_MAP_NUM 8 |
| 68 | |
| 69 | |
| 70 | const int g_bal_bcm_qos_pcp_map[BAL_BCM_PCP_MAP_NUM][BAL_BCM_PCP_MAP_ENTRIES] = |
| 71 | { |
| 72 | {0, 0, 0, 0, 0, 0, 0, 0}, /* 0-7 --> 0 */ |
| 73 | {1, 1, 1, 1, 1, 1, 1, 1}, /* 0-7 --> 1 */ |
| 74 | {2, 2, 2, 2, 2, 2, 2, 2}, /* 0-7 --> 2 */ |
| 75 | {3, 3, 3, 3, 3, 3, 3, 3}, /* 0-7 --> 3 */ |
| 76 | {4, 4, 4, 4, 4, 4, 4, 4}, /* 0-7 --> 4 */ |
| 77 | {5, 5, 5, 5, 5, 5, 5, 5}, /* 0-7 --> 5 */ |
| 78 | {6, 6, 6, 6, 6, 6, 6, 6}, /* 0-7 --> 6 */ |
| 79 | {7, 7, 7, 7, 7, 7, 7, 7}, /* 0-7 --> 7 */ |
| 80 | {1, 2, 3, 4, 5, 6, 7, 0}, /* 0-6 --> 1-7, 7 ->0 offset = 1 or -7 */ |
| 81 | {2, 3, 4, 5, 6, 7, 0, 1}, /* 0-5 --> 2-7, 6-7->0-1 offset = 2 or -6 */ |
| 82 | {3, 4, 5, 6, 7, 0, 1, 2}, /* 0-4 --> 3-7, 5-7->0-2 offset = 3 or -5 */ |
| 83 | {4, 5, 6, 7, 0, 1, 2, 3}, /* 0-3 --> 4-7, 4-7->0-3 offset = 4 or -4 */ |
| 84 | {5, 6, 7, 0, 1, 2, 3, 4}, /* 0-2 --> 5-7, 3-7->0-4 offset = 5 or -3 */ |
| 85 | {6, 7, 0, 1, 2, 3, 4, 5}, /* 0-1 --> 6-7, 2-7->0-5 offset = 6 or -2 */ |
| 86 | {7, 0, 1, 2, 3, 4, 5, 6}, /* 0 --> 7, 1-7->0-6 offset = 7 or -1 */ |
| 87 | }; |
| 88 | |
| 89 | static int g_bal_bcm_pcp_remark_map_id[BAL_BCM_PCP_MAP_NUM]; |
| 90 | |
| 91 | /**************************************************************************/ |
| 92 | /** |
| 93 | * @brief Create the PCP remark mapping tables |
| 94 | * |
| 95 | * This function creates the mapping from PCP bits in the |
| 96 | * frames received by DPP to the internal priority in |
| 97 | * DPP. The created map id are used in the ingress vlan translation API |
| 98 | * to perform PCP bits replacement. |
| 99 | * |
| 100 | * |
| 101 | * @param unit SDK unit number |
| 102 | * |
| 103 | * @return bcmos_errno |
| 104 | * |
| 105 | **************************************************************************/ |
| 106 | bcmos_errno bal_sw_dpp_pcp_remark_maps_init(int unit) |
| 107 | { |
| 108 | bcm_error_t sdk_rc = BCM_E_NONE; |
| 109 | bcm_qos_map_t l2_in_map; |
| 110 | int map_id, pcp; |
| 111 | int32_t qos_map_id; |
| 112 | |
| 113 | |
| 114 | for(map_id=0; map_id < BAL_BCM_PCP_MAP_NUM; map_id++) |
| 115 | { |
| 116 | /* in case anything goes wrong */ |
| 117 | g_bal_bcm_pcp_remark_map_id[map_id] = BAL_BCM_INVALID_PCP_MAP_ID; |
| 118 | |
| 119 | /* Create a map object */ |
| 120 | sdk_rc = bcm_qos_map_create(unit, BCM_QOS_MAP_INGRESS| BCM_QOS_MAP_L2_VLAN_PCP, &qos_map_id); |
| 121 | if (sdk_rc != BCM_E_NONE) |
| 122 | { |
| 123 | /* Error */ |
| 124 | BCM_LOG(ERROR, log_id_sw_util, |
| 125 | "bcm_qos_map_create failed with %s\n", |
| 126 | bcm_errmsg(sdk_rc)); |
| 127 | |
| 128 | return BCM_ERR_INTERNAL; |
| 129 | } |
| 130 | |
| 131 | /* Create a mapping for each PCP bits value. */ |
| 132 | for (pcp = 0; pcp < BAL_BCM_PCP_MAP_ENTRIES; pcp++) |
| 133 | { |
| 134 | bcm_qos_map_t_init(&l2_in_map); |
| 135 | |
| 136 | /* Ingress PCP/CoS value */ |
| 137 | l2_in_map.pkt_pri = g_bal_bcm_qos_pcp_map[map_id][pcp]; |
| 138 | |
| 139 | /* Set internal priority for this ingress pri */ |
| 140 | l2_in_map.int_pri = pcp; |
| 141 | |
| 142 | /* Set color for this ingress Priority */ |
| 143 | l2_in_map.color = bcmColorGreen; |
| 144 | |
| 145 | sdk_rc = bcm_qos_map_add(unit, BCM_QOS_MAP_L2_OUTER_TAG|BCM_QOS_MAP_L2|BCM_QOS_MAP_L2_VLAN_PCP, &l2_in_map, qos_map_id); |
| 146 | if (sdk_rc != BCM_E_NONE) |
| 147 | { |
| 148 | /* Error */ |
| 149 | BCM_LOG(ERROR, log_id_sw_util, |
| 150 | "bcm_qos_map_add failed with %s, for pcp %d\n", |
| 151 | bcm_errmsg(sdk_rc), pcp); |
| 152 | |
| 153 | return BCM_ERR_INTERNAL; |
| 154 | } |
| 155 | |
| 156 | } |
| 157 | |
| 158 | g_bal_bcm_pcp_remark_map_id[map_id] = qos_map_id; |
| 159 | } |
| 160 | return BCM_ERR_OK; |
| 161 | } |
| 162 | |
| 163 | /**************************************************************************/ |
| 164 | /** |
| 165 | * @brief Retrieve PCP remark mapping table ID according to the translation |
| 166 | * |
| 167 | * This function retrieve the pre-created mapping table id associate with |
| 168 | * the translation. |
| 169 | * The created map id can be used in the ingress vlan translation API |
| 170 | * to perform PCP bits replacement. |
| 171 | * |
| 172 | * @param src_pcp the pcp value that need to be translated, or -1 for DONTCARE |
| 173 | * @param dst_pcp the translated pcp value |
| 174 | * @param p_map_id pointer for the retrieved id |
| 175 | * |
| 176 | * @return bcmos_errno |
| 177 | * |
| 178 | **************************************************************************/ |
| 179 | bcmos_errno bal_sw_dpp_pcp_remark_map_get(int src_pcp, int dst_pcp, int *p_map_id) |
| 180 | { |
| 181 | int offset; |
| 182 | unsigned int indx; |
| 183 | |
| 184 | if(dst_pcp < 0 || dst_pcp > BAL_BCM_MAX_PCP_VALUE) |
| 185 | { |
| 186 | BCM_LOG(ERROR, log_id_sw_util, |
| 187 | "%s(): invalid destination pcp = %d\n", __FUNCTION__, dst_pcp); |
| 188 | return BCM_ERR_PARM; |
| 189 | } |
| 190 | /* if source is DONTCARE, i.e map to a fixed PCP, use the first 8 map tables */ |
| 191 | if(src_pcp == -1) |
| 192 | { |
| 193 | *p_map_id = g_bal_bcm_pcp_remark_map_id[dst_pcp]; |
| 194 | } |
| 195 | else |
| 196 | { |
| 197 | if(src_pcp < 0 || src_pcp > BAL_BCM_MAX_PCP_VALUE) |
| 198 | { |
| 199 | BCM_LOG(ERROR, log_id_sw_util, |
| 200 | "%s(): invalid source pcp = %d\n", __FUNCTION__, src_pcp); |
| 201 | return BCM_ERR_PARM; |
| 202 | } |
| 203 | /* find out the offset between the src_pcp and dst_pcp */ |
| 204 | offset = dst_pcp - src_pcp; |
| 205 | if (offset == 0) |
| 206 | { |
| 207 | BCM_LOG(ERROR, log_id_sw_util, |
| 208 | "%s(): source pcp %d == destination pcp %d\n", __FUNCTION__, src_pcp, dst_pcp); |
| 209 | return BCM_ERR_NOT_SUPPORTED; |
| 210 | } |
| 211 | if (offset < 0) |
| 212 | { |
| 213 | /* see comments in the above map tables */ |
| 214 | offset += BAL_BCM_PCP_MAP_ENTRIES; |
| 215 | } |
| 216 | |
| 217 | indx = offset + BAL_BCM_FIXED_PCP_MAP_NUM - 1; |
| 218 | if(indx >= BAL_BCM_PCP_MAP_NUM) |
| 219 | { |
| 220 | BCM_LOG(ERROR, log_id_sw_util, |
| 221 | "%s(): something is wrong, invalid map index = %d\n", __FUNCTION__, indx); |
| 222 | return BCM_ERR_INTERNAL; |
| 223 | } |
| 224 | /* index is 0 based */ |
| 225 | *p_map_id = g_bal_bcm_pcp_remark_map_id[indx]; |
| 226 | |
| 227 | } |
| 228 | |
| 229 | BCM_LOG(INFO, log_id_sw_util, |
| 230 | "%s(): pbits translate %d -> %d using bal qos map table %d, id 0x%x\n", __FUNCTION__, src_pcp, dst_pcp, indx, *p_map_id); |
| 231 | return BCM_ERR_OK; |
| 232 | } |
| 233 | |
| 234 | #endif /* TEST_SW_UTIL_LOOPBACK */ |
| 235 | |
| 236 | /*@}*/ |