1/* ********************************************************************* 2 * Broadcom Common Firmware Environment (CFE) 3 * 4 * Test commands for c3 board File: c3_tests.c 5 * 6 * 7 * Author: Binh Vo (binh@broadcom.com) 8 * 9 ********************************************************************* 10 * 11 * Copyright 2000,2001,2002,2003 12 * Broadcom Corporation. All rights reserved. 13 * 14 * This software is furnished under license and may be used and 15 * copied only in accordance with the following terms and 16 * conditions. Subject to these conditions, you may download, 17 * copy, install, use, modify and distribute modified or unmodified 18 * copies of this software in source and/or binary form. No title 19 * or ownership is transferred hereby. 20 * 21 * 1) Any source code used, modified or distributed must reproduce 22 * and retain this copyright notice and list of conditions 23 * as they appear in the source file. 24 * 25 * 2) No right is granted to use any trade name, trademark, or 26 * logo of Broadcom Corporation. The "Broadcom Corporation" 27 * name may not be used to endorse or promote products derived 28 * from this software without the prior written permission of 29 * Broadcom Corporation. 30 * 31 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR 32 * IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED 33 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 34 * PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT 35 * SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN 36 * PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT, 37 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 38 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 39 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 40 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 41 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 42 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF 43 * THE POSSIBILITY OF SUCH DAMAGE. 44 ********************************************************************* */ 45 46 47#include "sbmips.h" 48#include "sb1250_regs.h" 49 50#include "lib_types.h" 51#include "lib_string.h" 52#include "lib_queue.h" 53#include "lib_malloc.h" 54#include "lib_printf.h" 55 56#include "cfe_iocb.h" 57#include "cfe_devfuncs.h" 58#include "ui_command.h" 59#include "cfe_console.h" 60#include "cfe_error.h" 61#include "cfe_ioctl.h" 62#include "cfe.h" 63 64int ui_init_bcm91125e_testcmds(void); 65static int ui_cmd_fifotest(ui_cmdline_t *cmd, int argc, char *argv[]); 66 67int ui_init_bcm91125e_testcmds(void) 68{ 69 70 cmd_addcmd("test fifo", 71 ui_cmd_fifotest, 72 NULL, 73 "Do a packet fifo mode test in 8 or 16-bit mode and various other options.", 74 "test fifo {eth0|eth1|eth2} [-8|-16] [-encoded|-gmii|-sop|-eop] [options..]\n\n" 75 "This command converts the MAC(s) into packet FIFO mode. In 8-bit mode, f0, f1,\n" 76 "and f2 correspond to eth0, eth1, and eth2. In 16-bit mode, f0 and f1 correspond\n" 77 "to eth0 and eth2.", 78 "-8;8-bit mode (default)|" 79 "-16;16-bit mode|" 80 "-encoded;Encoded signal mode (default)|" 81 "-gmii;GMII style signal mode|" 82 "-sop;SOP flagged signal mode (8-bit mode only)|" 83 "-eop;EOP flagged signal mode (8-bit mode only)|" 84 "-loopback;Internal loopback (8-bit mode only)|" 85 "-pktsize=*;Packet size (default=32 bytes)|" 86 "-pktnum=*;Number of packets to send (default=1)|" 87 "-i;Interactive mode for user-defined data" 88 ); 89 90 return 0; 91} 92 93 94static int ui_cmd_fifotest(ui_cmdline_t *cmd, int argc, char *argv[]) 95{ 96 char *dev = "eth0"; 97 int fh; 98 int fifo_mode = ETHER_FIFO_8; 99 int strobe = ETHER_STROBE_ENCODED; 100 int loopback = ETHER_LOOPBACK_OFF; /* only in 8-bit mode */ 101 102 int idx,idx2,idx3,idx4; 103 int res=0; 104 uint8_t tx_packet[1024]; 105 uint8_t rx_packet[1024]; 106 int pktsize=32; 107 int pktnum=1; 108 int interactive = FALSE; 109 char *tmp; 110 int pktsize_disp; 111 112 char prompt[12]; 113 char line[256]; 114 int num_read=0; 115 116 int rx_count=0; 117 int tx_count=0; 118 119 char tmp_char; 120 int hi; 121 int lo; 122 123 /* obtain and open device(mac) */ 124 dev = cmd_getarg(cmd,0); 125 if (!dev) return ui_showusage(cmd); 126 fh = cfe_open(dev); 127 if (fh < 0) { 128 xprintf("Could not open device: %s\n",cfe_errortext(fh)); 129 return fh; 130 } 131 132 if (cmd_sw_isset(cmd,"-i")) interactive = TRUE; 133 134 /* 8(default) or 16 bit fifo mode */ 135 if (cmd_sw_isset(cmd,"-16")) { 136 if( (strcmp(dev,"eth1")==0) ) { 137 xprintf("16-bit mode not available on eth1.\n"); 138 return -1; 139 } 140 fifo_mode = ETHER_FIFO_16; 141 } 142 cfe_ioctl(fh,IOCTL_ETHER_SETPACKETFIFO, (uint8_t *) &fifo_mode, sizeof(fifo_mode),NULL,0); 143 144 /* signal type: encoded(default),gmii,sop(16-bit only),and eop(16-bit only) */ 145 if (cmd_sw_isset(cmd,"-gmii")) { 146 strobe = ETHER_STROBE_GMII; 147 } 148 else if (cmd_sw_isset(cmd,"-sop")) { 149 strobe = ETHER_STROBE_SOP; 150 } 151 else if (cmd_sw_isset(cmd,"-eop")) { 152 strobe = ETHER_STROBE_EOP; 153 } 154 cfe_ioctl(fh,IOCTL_ETHER_SETSTROBESIG, (uint8_t *)&strobe,sizeof(strobe),NULL,0); 155 156 /* internal loopback (only for 8-bit fifo) */ 157 if ( (cmd_sw_isset(cmd,"-loopback")) && (fifo_mode == ETHER_FIFO_8) ) { 158 loopback = ETHER_LOOPBACK_INT; 159 } 160 cfe_ioctl(fh,IOCTL_ETHER_SETLOOPBACK, (uint8_t *) &loopback, sizeof(loopback),NULL,0); 161 162 /* packet size and number of packets to send */ 163 tmp = NULL; 164 cmd_sw_value(cmd,"-pktsize",&tmp); 165 if (tmp != NULL) { 166 pktsize = atoi(tmp); 167 } 168 tmp = NULL; 169 cmd_sw_value(cmd,"-pktnum",&tmp); 170 if (tmp != NULL) { 171 pktnum = atoi(tmp); 172 } 173 174 memset(tx_packet,0xEE,sizeof(tx_packet)); 175 memset(rx_packet,0xFF,sizeof(rx_packet)); 176 memcpy(tx_packet,"\xAA\xBB\xCC\xDD\x00\x01\x02\x03\x04\x05\x06\x07\x08\x11",14); 177 178 xprintf("\n"); 179 180 xprintf("Transmit %d packet(s):\n",pktnum); 181 xprintf("%d ",pktsize); 182 pktsize_disp = pktsize; 183 if(pktsize_disp > 32) { 184 pktsize_disp = 32; 185 } 186 for (idx2 = 0,idx = 1; idx2 < pktsize_disp; idx2++,idx++) { 187 xprintf("%02X",tx_packet[idx2]); 188 if ( (idx % 4) == 0 ) xprintf(" "); 189 } 190 191 if(pktsize > pktsize_disp) { 192 xprintf("..."); 193 } 194 xprintf("\n\n"); 195 196 for (idx=0; idx < pktnum; idx++) { 197 res = cfe_write(fh,tx_packet,pktsize); 198 199 if (res < 0) { 200 /* If transmit fails, descriptor ring probably full, try to read sent packets*/ 201 for(idx2=0; idx2 < idx; idx2++) { 202 res = cfe_read(fh,rx_packet,pktsize); 203 if (res == 0) continue; 204 205 xprintf("RX[%d] %d ",rx_count,res); 206 rx_count++; 207 if (res > 32) res = 32; 208 for (idx3 = 0,idx4 = 1; idx3 < res; idx3++,idx4++) { 209 xprintf("%02X",rx_packet[idx3]); 210 if ( (idx4 % 4) == 0 ) xprintf(" "); 211 } 212 if(pktsize > pktsize_disp) xprintf("..."); 213 xprintf("\n"); 214 } 215 216 /*Retransmit the packet that failed*/ 217 res = cfe_write(fh,tx_packet,pktsize); 218 if (res < 0) ui_showerror(res,"ERROR Could not transmit packet"); 219 } 220 tx_count++; 221 } 222 223 /*Receive pre-defined test data*/ 224 while (!console_status()) { 225 res = cfe_read(fh,rx_packet,pktsize); 226 if (res == 0) continue; 227 if (res < 0) { 228 xprintf("Read error: %s\n",cfe_errortext(res)); 229 break; 230 } 231 xprintf("RX[%d] %d ",rx_count,res); 232 rx_count++; 233 if (res > 32) res = 32; 234 235 for (idx = 0,idx2 = 1; idx < res; idx++,idx2++) { 236 xprintf("%02X",rx_packet[idx]); 237 if ( (idx2 % 4) == 0 ) xprintf(" "); 238 } 239 240 if(pktsize > pktsize_disp) xprintf("..."); 241 242 xprintf("\n"); 243 244 if(rx_count >= tx_count) break; 245 } 246 247 if (interactive) { 248 249 tx_count=0; 250 rx_count=0; 251 memset(tx_packet,0xEE,sizeof(tx_packet)); 252 253 xprintf("\nEnter hex value without '0x'. 't' to transmit. 'r' to receive. 'e' to end\n"); 254 for(;;) { 255 256 xsprintf(prompt,"TX[%d] :",tx_count); 257 num_read = console_readline(prompt,line,sizeof(line)); 258 259 if (line[0] == 'e') break; 260 261 if (line[0] == 'r') { 262 263 /*Receive data*/ 264 for(idx = 0; idx < tx_count+5; idx++) { 265 res = cfe_read(fh,rx_packet,sizeof(rx_packet)); 266 if (res < 0) { 267 xprintf("Read error: %s\n",cfe_errortext(res)); 268 break; 269 } 270 if (res == 0) continue; 271 xprintf("RX[%d] %d ",rx_count,res); 272 rx_count++; 273 if (res > 32) res = 32; 274 275 for (idx3 = 0,idx4 = 1; idx3 < res; idx3++,idx4++) { 276 xprintf("%02X",rx_packet[idx3]); 277 if ( (idx4 % 4) == 0 ) xprintf(" "); 278 } 279 280 if(pktsize > pktsize_disp) xprintf("..."); 281 282 xprintf("\n"); 283 } 284 xprintf("\n"); 285 } 286 else if (line[0] == 't') { 287 288 /*Transmit data*/ 289 xprintf("Transmit %d packet(s):\n",pktnum); 290 xprintf("%d ",pktsize); 291 pktsize_disp = pktsize; 292 if(pktsize_disp > 32) { 293 pktsize_disp = 32; 294 } 295 for (idx2 = 0,idx = 1; idx2 < pktsize_disp; idx2++,idx++) { 296 xprintf("%02X",tx_packet[idx2]); 297 if ( (idx % 4) == 0 ) xprintf(" "); 298 } 299 300 if(pktsize > pktsize_disp) { 301 xprintf("..."); 302 } 303 xprintf("\n\n"); 304 305 for(idx = 0; idx < pktnum; idx++) { 306 res = cfe_write(fh,tx_packet,pktsize); 307 if (res < 0) { 308 309 /* If transmit fails, descriptor ring probably full, try to read sent packets*/ 310 for(idx2=0; idx2 < idx; idx2++) { 311 res = cfe_read(fh,rx_packet,pktsize); 312 if (res == 0) continue; 313 314 xprintf("RX[%d] %d ",rx_count,res); 315 rx_count++; 316 if (res > 32) res = 32; 317 for (idx3 = 0,idx4 = 1; idx3 < res; idx3++,idx4++) { 318 xprintf("%02X",rx_packet[idx3]); 319 if ( (idx4 % 4) == 0 ) xprintf(" "); 320 } 321 if(pktsize > pktsize_disp) xprintf("..."); 322 xprintf("\n"); 323 } 324 325 /*Retransmit the packet that failed*/ 326 res = cfe_write(fh,tx_packet,pktsize); 327 if (res < 0) ui_showerror(res,"ERROR Could not transmit packet"); 328 } 329 } 330 tx_count++; 331 memset(tx_packet,0xEE,sizeof(tx_packet)); 332 333 } 334 else { 335 /* Pack the packet */ 336 for (idx = 0,idx2=0; idx < (num_read+1)/2; idx++,idx2+=2) { 337 tmp_char = line[idx2 + 0]; 338 hi = xtoi(&tmp_char); 339 hi = hi << 4; 340 tmp_char = line[idx2 + 1]; 341 lo = xtoi(&tmp_char); 342 lo = lo | hi; 343 tx_packet[idx] = lo; 344 } 345 } 346 347 } /* for(;;) */ 348 } 349 350 /* Closing the device will reset the MAC # registers */ 351 cfe_close(fh); 352 353 return 0; 354} 355