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