loopback2.h (12507B)
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-2020 Broadcom Inc. All rights reserved. 6 * 7 * Loopback Test definitions. 8 */ 9 10 #ifndef __LOOPBACK2TEST__H 11 #define __LOOPBACK2TEST__H 12 13 #include <sal/types.h> 14 #include <sal/compiler.h> 15 16 #include <soc/mem.h> 17 #include <soc/dma.h> 18 #include <soc/enet.h> 19 #include <soc/counter.h> 20 #include <soc/register.h> 21 #include <soc/memory.h> 22 23 #include <bcm/port.h> 24 #include <bcm/l2.h> 25 #include <bcm/rx.h> 26 #include <bcm/pkt.h> 27 28 #include <appl/diag/parse.h> 29 30 #define LB2_VLAN_ID 1 31 #define LB2_LINKSCAN_PERIOD 100000 32 #define LB2_LINK_TIMEOUT 10000000 /* Microseconds */ 33 34 #define LB2_PACKET_TIMEOUT 5 /* Seconds */ 35 #define LB2_PACKET_TIMEOUT_QT 60 /* Seconds */ 36 #define LB2_PACKET_TIMEOUT_PLI (3*60) /* Seconds */ 37 #define LB2_FFP_PARAM_BYTES 6 38 39 #define LB2_TH_ASCEND_PORT_MODE 0 /* ports begin with firt port in ascending order */ 40 #define LB2_TH_DSCEND_PORT_MODE 1 /*ports begin with last port in descending order */ 41 #define LB2_TH_MAX_PORTS_WITH_PROFILE 127 /* maximum ports supported for TH/TH+ due to profile management limitation */ 42 43 enum lb2_test_type_e { 44 LB2_TT_MAC = 0, 45 LB2_TT_PHY, 46 LB2_TT_EXT, 47 LB2_TT_SNAKE, 48 LB2_TT_NUM 49 }; 50 51 /* Matching parse arrays are in lb_util.c */ 52 53 /* MUST MATCH LB2_SPEED_INIT_STR ordering below used in lb_util.c */ 54 enum lb2_speed_e { 55 LB_SPEED_MAX = 0, 56 LB_SPEED_10FD, 57 LB_SPEED_100FD, 58 LB_SPEED_1000FD, 59 LB_SPEED_2500FD, 60 LB_SPEED_3000FD, 61 LB_SPEED_5000FD, 62 LB_SPEED_10G_FD, 63 LB_SPEED_11G_FD, 64 LB_SPEED_12G_FD, 65 LB_SPEED_13G_FD, 66 LB_SPEED_15G_FD, 67 LB_SPEED_16G_FD, 68 LB_SPEED_20G_FD, 69 LB_SPEED_21G_FD, 70 LB_SPEED_23G_FD, 71 LB_SPEED_24G_FD, 72 LB_SPEED_25G_FD, 73 LB_SPEED_30G_FD, 74 LB_SPEED_32G_FD, 75 LB_SPEED_40G_FD, 76 LB_SPEED_42G_FD, 77 LB_SPEED_50G_FD, 78 LB_SPEED_100G_FD, 79 LB_SPEED_106G_FD, 80 LB_SPEED_120G_FD, 81 LB_SPEED_127G_FD, 82 LB_SPEED_200G_FD, 83 LB_SPEED_400G_FD 84 }; 85 86 #define LB2_SPEED_INIT_STR \ 87 "MAXimum", \ 88 "10fullduplex", \ 89 "100fullduplex", \ 90 "1000fullduplex", \ 91 "2500fullduplex", \ 92 "3000fullduplex", \ 93 "5000fullduplex", \ 94 "10Gfullduplex", \ 95 "11Gfullduplex", \ 96 "12Gfullduplex", \ 97 "13Gfullduplex", \ 98 "15Gfullduplex", \ 99 "16Gfullduplex", \ 100 "20Gfullduplex", \ 101 "21Gfullduplex", \ 102 "23Gfullduplex", \ 103 "24Gfullduplex", \ 104 "25Gfullduplex", \ 105 "30Gfullduplex", \ 106 "32Gfullduplex", \ 107 "40Gfullduplex", \ 108 "42Gfullduplex", \ 109 "50Gfullduplex", \ 110 "100Gfullduplex", \ 111 "106Gfullduplex", \ 112 "120Gfullduplex", \ 113 "127Gfullduplex", \ 114 "200Gfullduplex", \ 115 "400Gfullduplex" 116 117 /* MUST MATCH lb2_crc_mode ordering */ 118 enum lb2_crc_mode_e { 119 LB2_CRC_MODE_CPU_NONE = 0, 120 LB2_CRC_MODE_CPU_APPEND, 121 LB2_CRC_MODE_MAC_REGEN 122 }; 123 124 /* MUST MATCH lb2_parse_snake ordering */ 125 enum lb2_snake_path_e { 126 LB2_SNAKE_INCR = 0, 127 LB2_SNAKE_DECR, 128 LB2_SNAKE_BOTH 129 }; 130 131 /* MUST MATCH lb2_parse_lbmode ordering */ 132 enum lb2_mode_e { 133 LB2_MODE_MAC = 0, 134 LB2_MODE_PHY, 135 LB2_MODE_EXT 136 }; 137 138 /* Loopback test data, attributes of a given loopback test */ 139 typedef struct loopback2_testdata_s { 140 int test_type; /* Parameters for which test? */ 141 pbmp_t pbm; /* Ports under test */ 142 pbmp_t pbm_tx; /* Ports under test, TX only */ 143 soc_port_t dst_inc; /* Destination increment */ 144 pbmp_t ubm; /* Untag bit mask */ 145 uint32 pattern; /* Data Pattern */ 146 uint32 pattern_inc; /* Data Pattern increment */ 147 uint32 vlan; /* Vlan tag */ 148 int d_mod; /* Destination module, HiGig hdr */ 149 int d_mod_inc; /* HiGig modid increment */ 150 uint32 d_port; /* Destination port, HiGig hdr */ 151 uint32 opcode; /* Opcode, HiGig hdr */ 152 int len_start; /* Start length */ 153 int len_end; /* End length */ 154 int len_inc; /* Length increment */ 155 int ppt_start; /* Packets/trial, start */ 156 int ppt_end; /* Packets/trial, end */ 157 int ppt_inc; /* Packets/trial, increment */ 158 int send_mech; /* Sending mechanism per chain: */ 159 #define LBD_SEND_SINGLE 0 /* Single step packets */ 160 #define LBD_SEND_ARRAY 1 /* Send as array */ 161 #define LBD_SEND_LLIST 2 /* Note Yet Supported */ 162 int iterations; /* Number of times to iterate test */ 163 int cos_start; /* Starting COS value */ 164 int cos_end; /* Ending COS value */ 165 int crc_mode; /* CRC generation mode */ 166 int check_data; /* Check data integrity on receive */ 167 int check_crc; /* CRC data integrity on receive */ 168 int speed; /* Speed to configure ports */ 169 int autoneg; /* Enable autoneg (ext lb only) */ 170 sal_mac_addr_t mac_src; /* SRC Mac address under test */ 171 uint32 mac_src_inc; /* Source mac increment */ 172 sal_mac_addr_t mac_dst; /* SRC Mac address under test */ 173 uint32 mac_dst_inc; /* Destination mac increment */ 174 int duration; /* Duration time for Snake Test */ 175 int interval; /* Check frequency for iSnake Test */ 176 int two_way; /* Both directions of snake path */ 177 int snake_way; /* Direction(s) of snake path */ 178 int loopback; /* Select loopback mode */ 179 int inject; /* Setup ISnake and TX only */ 180 int port_select_mode; /* Only valid for TH/TH+ of 128 ports 181 0(default):use 127 ports begin with firt port in ascending order; 182 1: use 127 ports begin with last port in descending order */ 183 pbmp_t saved_pbm; /* Saved ports under test */ 184 #ifdef BCM_TOMAHAWK_SUPPORT 185 int line_rate; /* line_rate snake test*/ 186 int line_rate_count; /* packet number in line rate mode */ 187 #endif 188 } loopback2_testdata_t; 189 190 /* Info for forwarding a packet from one port to the next in snake */ 191 typedef struct lb2s_port_connect_s { 192 bcm_port_t this_port; 193 bcm_port_t to_port; 194 bcm_vlan_t added_vlan; 195 sal_mac_addr_t dst_mac; 196 sal_mac_addr_t src_mac; 197 int dst_modid; 198 int src_modid; 199 ip_addr_t dst_ip; 200 ip_addr_t src_ip; 201 int valid_info; 202 } lb2s_port_connect_t; 203 204 205 typedef struct loopback2_test_s { 206 int current_test_type; /* Which test is active */ 207 int set_up; /* TRUE if lb_setup() done */ 208 loopback2_testdata_t params[LB2_TT_NUM]; /* Loopback Parameters */ 209 loopback2_testdata_t *cur_params; /* Current lp parameters */ 210 int unit; /* Unit # */ 211 bcm_port_info_t save_port[SOC_MAX_NUM_PORTS]; /* Port information */ 212 #ifdef BCM_TOMAHAWK3_SUPPORT 213 bcm_port_resource_t port_info[SOC_MAX_NUM_PORTS]; /* Original FEC, 214 * phy lane, link 215 * training info to be 216 * saved and restored 217 */ 218 #endif /* BCM_TOMAHAWK3_SUPPORT */ 219 int save_linkscan_period; 220 int stats_init; /* TRUE if stats initialized */ 221 bcm_port_t tx_port; /* Current TX port */ 222 bcm_port_t rx_port; /* Current RX port */ 223 int tx_seq; /* Seq # in sent packet */ 224 int tx_total; /* Total # to send (multiplied out)*/ 225 int tx_count; /* Total packets sent so far */ 226 sal_time_t tx_stime; /* Transmit start time */ 227 sal_time_t tx_rtime; /* Time of next report */ 228 uint32 tx_bytes; /* Total bytes sent so far */ 229 int rx_count; /* Total packets received so far */ 230 uint32 rx_bytes; /* Total bytes received so far */ 231 232 sal_mac_addr_t base_mac_src; /* Source MAC address base for loop */ 233 sal_mac_addr_t base_mac_dst; /* Dest MAC address base for loop */ 234 bcm_l2_addr_t l2_addr_scratch; /* Working L2 entry */ 235 236 sal_sem_t sema; /* Sleep semaphore */ 237 volatile int sema_woke; /* Used to prevent excess semGives */ 238 uint32 timeout_usec; /* Timeout for packet operations */ 239 int tx_len; /* Current TX packet length */ 240 int tx_cos; /* Current TX COS */ 241 int tx_ppt; /* Current TX packets/chain */ 242 243 bcm_pkt_t **tx_pkts; /* Array of pointers to TX packets */ 244 bcm_pkt_t *rx_pkts; /* Array of RX packets */ 245 bcm_pkt_t *rx_pkt_head; /* Queue of rcvd packets */ 246 bcm_pkt_t *rx_pkt_tail; 247 248 volatile int expect_pkts; /* TRUE --> Expecting packets */ 249 volatile int rx_pkt_cnt; /* Number of packets received */ 250 251 /* Snake test */ 252 int *tx_pkt_match; /* TRUE --> Already matched tx pkt */ 253 254 lb2s_port_connect_t *port_cnct_f; /* Port interlink records, forward */ 255 lb2s_port_connect_t *port_cnct_r; /* Port interlink records, reverse */ 256 int port_count; /* Number of ports under test */ 257 } loopback2_test_t; 258 259 #define LB2_RX_PKT(lw, idx) (&(lw)->rx_pkts[idx]) 260 #define LB2_RX_CUR_PKT(lw) (&(lw)->rx_pkts[(lw)->rx_pkt_cnt]) 261 #define LB2_PKT_NONE 0 262 #define LB2_PKT_EXPECTED 1 263 #define LB2_PKT_UNEXPECTED 2 264 265 #define LB2_ID_POS 24 /* L3 may need this larger */ 266 #define LB2_SNAKE_TOLERANCE 50 267 268 /* 269 * Port stats we monitor on a per-port basis while the test is running. 270 * (Lifted from traffic.h) 271 */ 272 typedef struct { 273 int initialized; 274 int error; 275 uint64 rbyt; 276 uint64 rpkt; 277 uint64 raln; 278 uint64 rdisc; 279 uint64 tbyt; 280 uint64 tpkt; 281 uint64 dropped; 282 #ifdef BCM_TOMAHAWK_SUPPORT 283 uint64 rate; 284 #endif 285 } lb2_port_stat_t; 286 287 extern void lbu_pkt_param_add(int unit, parse_table_t *pt, 288 loopback2_testdata_t *lp); 289 extern void lbu_port_param_add(int unit, parse_table_t *pt, 290 loopback2_testdata_t *lp); 291 extern void lbu_other_param_add(int unit, parse_table_t *pt, 292 loopback2_testdata_t *lp); 293 294 extern void lbu_setup(int unit, loopback2_test_t *lw); 295 extern int lbu_setup_arl_cmic(loopback2_test_t *lw); 296 extern void lbu_cleanup_arl(loopback2_test_t *lw); 297 extern int lbu_check_parms(loopback2_test_t *lw, loopback2_testdata_t *lp); 298 extern int lbu_init(loopback2_test_t *lw, loopback2_testdata_t *lp); 299 extern int lbu_snake_init(loopback2_test_t *lw, loopback2_testdata_t *lp); 300 301 extern void lbu_stats_init(loopback2_test_t *lw); 302 extern void lbu_stats_done(loopback2_test_t *lw); 303 304 extern int lbu_serial_txrx(loopback2_test_t *lw); 305 extern int lbu_snake_tx(loopback2_test_t *lw); 306 extern int lbu_snake_txrx(loopback2_test_t *lw, lb2_port_stat_t *stats); 307 308 extern int lbu_done(loopback2_test_t *lw); 309 extern int lbu_snake_done(loopback2_test_t *lw); 310 311 extern int lbu_connect_ports(int unit, lb2s_port_connect_t *pc_info, int connect); 312 extern int lbu_port_monitor_task(int unit, bcm_rx_cb_f callback, void *cookie); 313 extern bcm_rx_t lbu_rx_callback(int unit, bcm_pkt_t *info, void *cookie); 314 extern int lbu_snake_stats(int unit, bcm_pbmp_t sel_pbm, int mac_lb, 315 lb2_port_stat_t *stats); 316 extern void lbu_snake_dump_stats(int unit, bcm_pbmp_t sel_pbm, 317 lb2_port_stat_t *stats); 318 extern int lbu_snake_analysis(loopback2_test_t *lw); 319 #endif /*!__LOOPBACK2TEST__H */