GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / cfe / cfe / arch / mips / board / bcm91125e / src / bcm91125e_tests.c
blob022914d2011d7ae4ec95ebceb925a3c4f5cecaff
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 *********************************************************************
11 * Copyright 2000,2001,2002,2003
12 * Broadcom Corporation. All rights reserved.
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.
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.
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.
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 ********************************************************************* */
47 #include "sbmips.h"
48 #include "sb1250_regs.h"
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"
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"
64 int ui_init_bcm91125e_testcmds(void);
65 static int ui_cmd_fifotest(ui_cmdline_t *cmd, int argc, char *argv[]);
67 int ui_init_bcm91125e_testcmds(void)
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"
90 return 0;
94 static int ui_cmd_fifotest(ui_cmdline_t *cmd, int argc, char *argv[])
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 */
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;
112 char prompt[12];
113 char line[256];
114 int num_read=0;
116 int rx_count=0;
117 int tx_count=0;
119 char tmp_char;
120 int hi;
121 int lo;
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;
132 if (cmd_sw_isset(cmd,"-i")) interactive = TRUE;
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;
140 fifo_mode = ETHER_FIFO_16;
142 cfe_ioctl(fh,IOCTL_ETHER_SETPACKETFIFO, (uint8_t *) &fifo_mode, sizeof(fifo_mode),NULL,0);
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;
148 else if (cmd_sw_isset(cmd,"-sop")) {
149 strobe = ETHER_STROBE_SOP;
151 else if (cmd_sw_isset(cmd,"-eop")) {
152 strobe = ETHER_STROBE_EOP;
154 cfe_ioctl(fh,IOCTL_ETHER_SETSTROBESIG, (uint8_t *)&strobe,sizeof(strobe),NULL,0);
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;
160 cfe_ioctl(fh,IOCTL_ETHER_SETLOOPBACK, (uint8_t *) &loopback, sizeof(loopback),NULL,0);
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);
168 tmp = NULL;
169 cmd_sw_value(cmd,"-pktnum",&tmp);
170 if (tmp != NULL) {
171 pktnum = atoi(tmp);
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);
178 xprintf("\n");
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;
186 for (idx2 = 0,idx = 1; idx2 < pktsize_disp; idx2++,idx++) {
187 xprintf("%02X",tx_packet[idx2]);
188 if ( (idx % 4) == 0 ) xprintf(" ");
191 if(pktsize > pktsize_disp) {
192 xprintf("...");
194 xprintf("\n\n");
196 for (idx=0; idx < pktnum; idx++) {
197 res = cfe_write(fh,tx_packet,pktsize);
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;
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(" ");
212 if(pktsize > pktsize_disp) xprintf("...");
213 xprintf("\n");
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");
220 tx_count++;
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;
231 xprintf("RX[%d] %d ",rx_count,res);
232 rx_count++;
233 if (res > 32) res = 32;
235 for (idx = 0,idx2 = 1; idx < res; idx++,idx2++) {
236 xprintf("%02X",rx_packet[idx]);
237 if ( (idx2 % 4) == 0 ) xprintf(" ");
240 if(pktsize > pktsize_disp) xprintf("...");
242 xprintf("\n");
244 if(rx_count >= tx_count) break;
247 if (interactive) {
249 tx_count=0;
250 rx_count=0;
251 memset(tx_packet,0xEE,sizeof(tx_packet));
253 xprintf("\nEnter hex value without '0x'. 't' to transmit. 'r' to receive. 'e' to end\n");
254 for(;;) {
256 xsprintf(prompt,"TX[%d] :",tx_count);
257 num_read = console_readline(prompt,line,sizeof(line));
259 if (line[0] == 'e') break;
261 if (line[0] == 'r') {
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;
270 if (res == 0) continue;
271 xprintf("RX[%d] %d ",rx_count,res);
272 rx_count++;
273 if (res > 32) res = 32;
275 for (idx3 = 0,idx4 = 1; idx3 < res; idx3++,idx4++) {
276 xprintf("%02X",rx_packet[idx3]);
277 if ( (idx4 % 4) == 0 ) xprintf(" ");
280 if(pktsize > pktsize_disp) xprintf("...");
282 xprintf("\n");
284 xprintf("\n");
286 else if (line[0] == 't') {
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;
295 for (idx2 = 0,idx = 1; idx2 < pktsize_disp; idx2++,idx++) {
296 xprintf("%02X",tx_packet[idx2]);
297 if ( (idx % 4) == 0 ) xprintf(" ");
300 if(pktsize > pktsize_disp) {
301 xprintf("...");
303 xprintf("\n\n");
305 for(idx = 0; idx < pktnum; idx++) {
306 res = cfe_write(fh,tx_packet,pktsize);
307 if (res < 0) {
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;
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(" ");
321 if(pktsize > pktsize_disp) xprintf("...");
322 xprintf("\n");
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");
330 tx_count++;
331 memset(tx_packet,0xEE,sizeof(tx_packet));
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;
347 } /* for(;;) */
350 /* Closing the device will reset the MAC # registers */
351 cfe_close(fh);
353 return 0;