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_c3_testcmds(void); 65static int ui_cmd_fifotest(ui_cmdline_t *cmd, int argc, char *argv[]); 66static int ui_cmd_download(ui_cmdline_t *cmd, int argc, char *argv[]); 67 68int ui_init_c3_testcmds(void) 69{ 70 cmd_addcmd("dl", 71 ui_cmd_download, 72 NULL, 73 "Wait for a PCI download from the host", 74 "dl", 75 "" 76 ); 77 cmd_addcmd("test fifo", 78 ui_cmd_fifotest, 79 NULL, 80 "Do a packet fifo mode test in 8 or 16-bit mode and various other options.", 81 "test fifo {eth0|eth1|eth2} [-8|-16] [-encoded|-gmii|-sop|-eop] [options..]\n\n" 82 "This command converts the MAC(s) into packet FIFO mode. In 8-bit mode, f0, f1,\n" 83 "and f2 correspond to eth0, eth1, and eth2. In 16-bit mode, f0 and f1 correspond\n" 84 "to eth0 and eth2.", 85 "-8;8-bit mode (default)|" 86 "-16;16-bit mode|" 87 "-encoded;Encoded signal mode (default)|" 88 "-gmii;GMII style signal mode|" 89 "-sop;SOP flagged signal mode (8-bit mode only)|" 90 "-eop;EOP flagged signal mode (8-bit mode only)|" 91 "-loopback;Internal loopback (8-bit mode only)|" 92 "-pktsize=*;Packet size (default=32 bytes)|" 93 "-pktnum=*;Number of packets to send (default=1)|" 94 "-i;Interactive mode for user-defined data" 95 ); 96 97 return 0; 98} 99 100extern int cfe_device_download(int boot, char *options); 101 102static int ui_cmd_download(ui_cmdline_t *cmd, int argc, char *argv[]) 103{ 104 cfe_device_download(1, ""); 105 106 return 0; 107} 108 109static int ui_cmd_fifotest(ui_cmdline_t *cmd, int argc, char *argv[]) 110{ 111 char *dev = "eth0"; 112 int fh; 113 int fifo_mode = ETHER_FIFO_8; 114 int strobe = ETHER_STROBE_ENCODED; 115 int loopback = ETHER_LOOPBACK_OFF; /* only in 8-bit mode */ 116 117 int idx,idx2,idx3,idx4; 118 int res=0; 119 uint8_t tx_packet[1024]; 120 uint8_t rx_packet[1024]; 121 int pktsize=32; 122 int pktnum=1; 123 int interactive = FALSE; 124 char *tmp; 125 int pktsize_disp; 126 127 char prompt[12]; 128 char line[256]; 129 int num_read=0; 130 131 int rx_count=0; 132 int tx_count=0; 133 134 char tmp_char; 135 int hi; 136 int lo; 137 138 /* obtain and open device(mac) */ 139 dev = cmd_getarg(cmd,0); 140 if (!dev) return ui_showusage(cmd); 141 fh = cfe_open(dev); 142 if (fh < 0) { 143 xprintf("Could not open device: %s\n",cfe_errortext(fh)); 144 return fh; 145 } 146 147 if (cmd_sw_isset(cmd,"-i")) interactive = TRUE; 148 149 /* 8(default) or 16 bit fifo mode */ 150 if (cmd_sw_isset(cmd,"-16")) { 151 if( (strcmp(dev,"eth1")==0) ) { 152 xprintf("16-bit mode not available on eth1.\n"); 153 return -1; 154 } 155 fifo_mode = ETHER_FIFO_16; 156 } 157 cfe_ioctl(fh,IOCTL_ETHER_SETPACKETFIFO, (uint8_t *) &fifo_mode, sizeof(fifo_mode),NULL,0); 158 159 /* signal type: encoded(default),gmii,sop(16-bit only),and eop(16-bit only) */ 160 if (cmd_sw_isset(cmd,"-gmii")) { 161 strobe = ETHER_STROBE_GMII; 162 } 163 else if (cmd_sw_isset(cmd,"-sop")) { 164 strobe = ETHER_STROBE_SOP; 165 } 166 else if (cmd_sw_isset(cmd,"-eop")) { 167 strobe = ETHER_STROBE_EOP; 168 } 169 cfe_ioctl(fh,IOCTL_ETHER_SETSTROBESIG, (uint8_t *)&strobe,sizeof(strobe),NULL,0); 170 171 /* internal loopback (only for 8-bit fifo) */ 172 if ( (cmd_sw_isset(cmd,"-loopback")) && (fifo_mode == ETHER_FIFO_8) ) { 173 loopback = ETHER_LOOPBACK_INT; 174 } 175 cfe_ioctl(fh,IOCTL_ETHER_SETLOOPBACK, (uint8_t *) &loopback, sizeof(loopback),NULL,0); 176 177 /* packet size and number of packets to send */ 178 tmp = NULL; 179 cmd_sw_value(cmd,"-pktsize",&tmp); 180 if (tmp != NULL) { 181 pktsize = atoi(tmp); 182 } 183 tmp = NULL; 184 cmd_sw_value(cmd,"-pktnum",&tmp); 185 if (tmp != NULL) { 186 pktnum = atoi(tmp); 187 } 188 189 memset(tx_packet,0xEE,sizeof(tx_packet)); 190 memset(rx_packet,0xFF,sizeof(rx_packet)); 191 memcpy(tx_packet,"\xAA\xBB\xCC\xDD\x00\x01\x02\x03\x04\x05\x06\x07\x08\x11",14); 192 193 xprintf("\n"); 194 195 xprintf("Transmit %d packet(s):\n",pktnum); 196 xprintf("%d ",pktsize); 197 pktsize_disp = pktsize; 198 if(pktsize_disp > 32) { 199 pktsize_disp = 32; 200 } 201 for (idx2 = 0,idx = 1; idx2 < pktsize_disp; idx2++,idx++) { 202 xprintf("%02X",tx_packet[idx2]); 203 if ( (idx % 4) == 0 ) xprintf(" "); 204 } 205 206 if(pktsize > pktsize_disp) { 207 xprintf("..."); 208 } 209 xprintf("\n\n"); 210 211 for (idx=0; idx < pktnum; idx++) { 212 res = cfe_write(fh,tx_packet,pktsize); 213 214 if (res < 0) { 215 /* If transmit fails, descriptor ring probably full, try to read sent packets*/ 216 for(idx2=0; idx2 < idx; idx2++) { 217 res = cfe_read(fh,rx_packet,pktsize); 218 if (res == 0) continue; 219 220 xprintf("RX[%d] %d ",rx_count,res); 221 rx_count++; 222 if (res > 32) res = 32; 223 for (idx3 = 0,idx4 = 1; idx3 < res; idx3++,idx4++) { 224 xprintf("%02X",rx_packet[idx3]); 225 if ( (idx4 % 4) == 0 ) xprintf(" "); 226 } 227 if(pktsize > pktsize_disp) xprintf("..."); 228 xprintf("\n"); 229 } 230 231 /*Retransmit the packet that failed*/ 232 res = cfe_write(fh,tx_packet,pktsize); 233 if (res < 0) ui_showerror(res,"ERROR Could not transmit packet"); 234 } 235 tx_count++; 236 } 237 238 /*Receive pre-defined test data*/ 239 while (!console_status()) { 240 res = cfe_read(fh,rx_packet,pktsize); 241 if (res == 0) continue; 242 if (res < 0) { 243 xprintf("Read error: %s\n",cfe_errortext(res)); 244 break; 245 } 246 xprintf("RX[%d] %d ",rx_count,res); 247 rx_count++; 248 if (res > 32) res = 32; 249 250 for (idx = 0,idx2 = 1; idx < res; idx++,idx2++) { 251 xprintf("%02X",rx_packet[idx]); 252 if ( (idx2 % 4) == 0 ) xprintf(" "); 253 } 254 255 if(pktsize > pktsize_disp) xprintf("..."); 256 257 xprintf("\n"); 258 259 if(rx_count >= tx_count) break; 260 } 261 262 if (interactive) { 263 264 tx_count=0; 265 rx_count=0; 266 memset(tx_packet,0xEE,sizeof(tx_packet)); 267 268 xprintf("\nEnter hex value without '0x'. 't' to transmit. 'r' to receive. 'e' to end\n"); 269 for(;;) { 270 271 xsprintf(prompt,"TX[%d] :",tx_count); 272 num_read = console_readline(prompt,line,sizeof(line)); 273 274 if (line[0] == 'e') break; 275 276 if (line[0] == 'r') { 277 278 /*Receive data*/ 279 for(idx = 0; idx < tx_count+5; idx++) { 280 res = cfe_read(fh,rx_packet,sizeof(rx_packet)); 281 if (res < 0) { 282 xprintf("Read error: %s\n",cfe_errortext(res)); 283 break; 284 } 285 if (res == 0) continue; 286 xprintf("RX[%d] %d ",rx_count,res); 287 rx_count++; 288 if (res > 32) res = 32; 289 290 for (idx3 = 0,idx4 = 1; idx3 < res; idx3++,idx4++) { 291 xprintf("%02X",rx_packet[idx3]); 292 if ( (idx4 % 4) == 0 ) xprintf(" "); 293 } 294 295 if(pktsize > pktsize_disp) xprintf("..."); 296 297 xprintf("\n"); 298 } 299 xprintf("\n"); 300 } 301 else if (line[0] == 't') { 302 303 /*Transmit data*/ 304 xprintf("Transmit %d packet(s):\n",pktnum); 305 xprintf("%d ",pktsize); 306 pktsize_disp = pktsize; 307 if(pktsize_disp > 32) { 308 pktsize_disp = 32; 309 } 310 for (idx2 = 0,idx = 1; idx2 < pktsize_disp; idx2++,idx++) { 311 xprintf("%02X",tx_packet[idx2]); 312 if ( (idx % 4) == 0 ) xprintf(" "); 313 } 314 315 if(pktsize > pktsize_disp) { 316 xprintf("..."); 317 } 318 xprintf("\n\n"); 319 320 for(idx = 0; idx < pktnum; idx++) { 321 res = cfe_write(fh,tx_packet,pktsize); 322 if (res < 0) { 323 324 /* If transmit fails, descriptor ring probably full, try to read sent packets*/ 325 for(idx2=0; idx2 < idx; idx2++) { 326 res = cfe_read(fh,rx_packet,pktsize); 327 if (res == 0) continue; 328 329 xprintf("RX[%d] %d ",rx_count,res); 330 rx_count++; 331 if (res > 32) res = 32; 332 for (idx3 = 0,idx4 = 1; idx3 < res; idx3++,idx4++) { 333 xprintf("%02X",rx_packet[idx3]); 334 if ( (idx4 % 4) == 0 ) xprintf(" "); 335 } 336 if(pktsize > pktsize_disp) xprintf("..."); 337 xprintf("\n"); 338 } 339 340 /*Retransmit the packet that failed*/ 341 res = cfe_write(fh,tx_packet,pktsize); 342 if (res < 0) ui_showerror(res,"ERROR Could not transmit packet"); 343 } 344 } 345 tx_count++; 346 memset(tx_packet,0xEE,sizeof(tx_packet)); 347 348 } 349 else { 350 /* Pack the packet */ 351 for (idx = 0,idx2=0; idx < (num_read+1)/2; idx++,idx2+=2) { 352 tmp_char = line[idx2 + 0]; 353 hi = xtoi(&tmp_char); 354 hi = hi << 4; 355 tmp_char = line[idx2 + 1]; 356 lo = xtoi(&tmp_char); 357 lo = lo | hi; 358 tx_packet[idx] = lo; 359 } 360 } 361 362 } /* for(;;) */ 363 } 364 365 /* Closing the device will reset the MAC # registers */ 366 cfe_close(fh); 367 368 return 0; 369} 370