chassis.c (7263B)
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 * Chassis support 8 */ 9 10 11 #include <appl/diag/shell.h> 12 #include <appl/diag/system.h> 13 #include <shared/bsl.h> 14 #if defined(MBZ) 15 extern int sysIsLM(); 16 /* Chassis failover related stuff */ 17 18 #include <soc/cm.h> 19 #include <soc/mem.h> 20 #include <soc/debug.h> 21 22 #include <bcm/link.h> 23 24 #define CFM1_PORT_LM 6 25 #define CFM2_PORT_LM 3 26 #define DRACO_UNIT1_PORT 8 27 #define DRACO_UNIT2_PORT 1 28 #define CFM1_PORT_CX4 5 29 #define CFM2_PORT_CX4 4 30 #define LYNX_UNIT1_PORT 6 31 #define LYNX_UNIT6_PORT 3 32 #define CFM1_PORT ((cx4_flag) ? CFM1_PORT_CX4 : CFM1_PORT_LM) 33 #define CFM2_PORT ((cx4_flag) ? CFM2_PORT_CX4 : CFM2_PORT_LM) 34 int cfm_hattached = 0; 35 int cx4_flag = 0; 36 37 38 void 39 bcm_cx4_fabric_setup(int unit, bcm_port_t port) 40 { 41 if (port == CFM1_PORT_CX4) { 42 /* CFM in slot 1 */ 43 LOG_ERROR(BSL_LS_APPL_CHASSIS, 44 (BSL_META_U(unit, 45 "bcm_cx4_fabric_setup: port=%d CFM slot-1\n"), 46 port)); 47 /* soc_icm_egress_mask_set(int unit, int port, pbmp_t pbmp)*/ 48 WRITE_ING_EGRMSKBMAPr(unit, LYNX_UNIT6_PORT, 0x020); 49 WRITE_ING_EGRMSKBMAPr(unit, LYNX_UNIT1_PORT, 0x020); 50 WRITE_ING_EGRMSKBMAPr(unit, CFM2_PORT_CX4, 0x048); 51 WRITE_ING_EGRMSKBMAPr(unit, CFM1_PORT_CX4, 0x048); 52 } else if (port == CFM2_PORT_CX4) { 53 /* CFM in slot 2 */ 54 LOG_ERROR(BSL_LS_APPL_CHASSIS, 55 (BSL_META_U(unit, 56 "bcm_cx4_fabric_setup: unit=%d port=%d CFM slot-2\n"), 57 unit, port)); 58 WRITE_ING_EGRMSKBMAPr(unit, LYNX_UNIT6_PORT, 0x010); 59 WRITE_ING_EGRMSKBMAPr(unit, LYNX_UNIT1_PORT, 0x010); 60 WRITE_ING_EGRMSKBMAPr(unit, CFM2_PORT_CX4, 0x048); 61 WRITE_ING_EGRMSKBMAPr(unit, CFM1_PORT_CX4, 0x048); 62 } else { 63 /* Both CFMs active */ 64 LOG_ERROR(BSL_LS_APPL_CHASSIS, 65 (BSL_META_U(unit, 66 "bcm_cx4_fabric_setup: unit=%d port=%d CFM slot-1&2\n"), 67 unit, port)); 68 WRITE_ING_EGRMSKBMAPr(unit, LYNX_UNIT6_PORT, 0x010); 69 WRITE_ING_EGRMSKBMAPr(unit, LYNX_UNIT1_PORT, 0x020); 70 WRITE_ING_EGRMSKBMAPr(unit, CFM2_PORT_CX4, 0x008); 71 WRITE_ING_EGRMSKBMAPr(unit, CFM1_PORT_CX4, 0x040); 72 } 73 } 74 75 void 76 bcm_fabric_setup(int unit, bcm_port_t port) 77 { 78 if (port == CFM1_PORT_LM) { 79 /* CFM in slot 1 */ 80 LOG_ERROR(BSL_LS_APPL_CHASSIS, 81 (BSL_META_U(unit, 82 "bcm_fabric_setup: unit=%d port=%d CFM slot-1\n"), 83 unit, port)); 84 /* soc_icm_egress_mask_set(int unit, int port, pbmp_t pbmp)*/ 85 WRITE_ING_EGRMSKBMAPr(unit, DRACO_UNIT2_PORT, 0x142); 86 WRITE_ING_EGRMSKBMAPr(unit, DRACO_UNIT1_PORT, 0x142); 87 } else if (port == CFM2_PORT_LM) { 88 /* CFM in slot 2 */ 89 LOG_ERROR(BSL_LS_APPL_CHASSIS, 90 (BSL_META_U(unit, 91 "bcm_fabric_setup: unit=%d port=%d CFM slot-2\n"), 92 unit, port)); 93 WRITE_ING_EGRMSKBMAPr(unit, DRACO_UNIT2_PORT, 0x10a); 94 WRITE_ING_EGRMSKBMAPr(unit, DRACO_UNIT1_PORT, 0x10a); 95 } else { 96 /* Both CFMs active */ 97 LOG_ERROR(BSL_LS_APPL_CHASSIS, 98 (BSL_META_U(unit, 99 "bcm_fabric_setup: unit=%d port=%d CFM slot-1&2\n"), 100 unit, port)); 101 WRITE_ING_EGRMSKBMAPr(unit, DRACO_UNIT2_PORT, 0x10a); 102 WRITE_ING_EGRMSKBMAPr(unit, DRACO_UNIT1_PORT, 0x142); 103 } 104 } 105 106 void 107 bcm_cfm_fail_over(int unit, bcm_port_t port, bcm_port_info_t *info) 108 { 109 int link_status; 110 bcm_port_t cfm_port; 111 char *ll_status[] = {"down", "up", "failed", "fault"}; 112 113 cfm_port = port; 114 115 LOG_ERROR(BSL_LS_APPL_CHASSIS, 116 (BSL_META_U(unit, 117 "bcm_cfm_fail_over: unit = %d port = %d Link = %s\n"), 118 unit, port, 119 ((info->linkstatus >= BCM_PORT_LINK_STATUS_DOWN && 120 info->linkstatus <= BCM_PORT_LINK_STATUS_REMOTE_FAULT) ? 121 ll_status[info->linkstatus] : "Invalid"))); 122 if ((port != CFM1_PORT) && (port != CFM2_PORT)) { 123 return; 124 } 125 126 if (info->linkstatus == BCM_PORT_LINK_STATUS_UP) { 127 /* Link Up */ 128 if (bcm_port_link_status_get(unit, (port == CFM1_PORT) ? CFM2_PORT : 129 CFM1_PORT, &link_status) >= 0) { 130 if (link_status) { 131 cfm_port = -1; /* Both CFMs active */ 132 } 133 } 134 } else { 135 /* Link down */ 136 cfm_port = (port == CFM1_PORT) ? CFM2_PORT : CFM1_PORT; 137 } 138 139 if (cx4_flag) { 140 bcm_cx4_fabric_setup(unit, cfm_port); 141 } else { 142 bcm_fabric_setup(unit, cfm_port); 143 } 144 } 145 146 147 void bcm_cfm_failover_attach(int unit) 148 { 149 int link_status; 150 bcm_port_t cfm_port; 151 152 if (unit != 0) return; 153 154 cfm_port = CFM1_PORT; 155 156 if (sysIsLM()) { 157 if (bcm_port_link_status_get(unit, CFM1_PORT, &link_status) >= 0) { 158 if (link_status) { 159 cfm_port = CFM1_PORT; 160 if (bcm_port_link_status_get( 161 unit, CFM2_PORT, &link_status) >= 0) { 162 if (link_status) { 163 cfm_port = -1; /* Both CFMs active */ 164 } 165 } 166 } 167 else { 168 cfm_port = CFM2_PORT; 169 } 170 } 171 172 if (cx4_flag) { 173 bcm_cx4_fabric_setup(unit, cfm_port); 174 } else { 175 bcm_fabric_setup(unit, cfm_port); 176 } 177 178 LOG_ERROR(BSL_LS_APPL_CHASSIS, 179 (BSL_META_U(unit, 180 "bcm_cfm_failover_attach: unit = %d %s\n"), 181 unit, "Registered Handler for CFM failover")); 182 bcm_linkscan_register(unit, bcm_cfm_fail_over); 183 } 184 cfm_hattached = 1; 185 } 186 187 void bcm_cfm_failover_detach(int unit) 188 { 189 bcm_linkscan_unregister(unit, bcm_cfm_fail_over); 190 cfm_hattached = 0; 191 } 192 193 /* 194 * Function: 195 * if_cfm_failover 196 * Purpose: 197 * Activate/Deactivate CFM failover 198 * Parameters: 199 * unit - SOC unit # 200 * a - pointer to args 201 * Returns: 202 * CMD_OK/CMD_FAIL 203 */ 204 205 char if_cfm_failover_usage[] = 206 "Activate CFM failover.\n"; 207 208 cmd_result_t 209 if_cfm_failover(int unit, args_t *a) 210 { 211 char *c; 212 213 if (!sh_check_attached(ARG_CMD(a), unit)) { 214 return CMD_FAIL; 215 } 216 217 if ((c = ARG_GET(a)) != NULL) { 218 if (!sal_strcmp(c, "cx4")) { 219 cx4_flag = 1; 220 c = ARG_GET(a); 221 } 222 } 223 224 if (c != NULL) { 225 if (!sal_strcmp(c, "enable")) { 226 if (cfm_hattached) bcm_cfm_failover_detach(unit); 227 bcm_cfm_failover_attach(unit); 228 } else if (!sal_strcmp(c, "disable")) { 229 bcm_cfm_failover_detach(unit); 230 } else { 231 cli_out("cfmfailover [enable/disable] \n"); 232 } 233 } else { 234 cli_out("cfmfailover [enable/disable] \n"); 235 } 236 237 return CMD_OK; 238 } 239 240 #endif 241 242 int _bcm_diag_chassis_not_empty;