1 /* *********************************************************************
2 * Broadcom Common Firmware Environment (CFE)
4 * Test commands for c3 board File: c3_tests.c
7 * Author: Binh Vo (binh@broadcom.com)
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 ********************************************************************* */
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"
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"
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",
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"
78 "-8;8-bit mode (default)|"
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"
94 static int ui_cmd_fifotest(ui_cmdline_t
*cmd
, int argc
, char *argv
[])
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
;
104 uint8_t tx_packet
[1024];
105 uint8_t rx_packet
[1024];
108 int interactive
= FALSE
;
123 /* obtain and open device(mac) */
124 dev
= cmd_getarg(cmd
,0);
125 if (!dev
) return ui_showusage(cmd
);
128 xprintf("Could not open device: %s\n",cfe_errortext(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");
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 */
164 cmd_sw_value(cmd
,"-pktsize",&tmp
);
169 cmd_sw_value(cmd
,"-pktnum",&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);
180 xprintf("Transmit %d packet(s):\n",pktnum
);
181 xprintf("%d ",pktsize
);
182 pktsize_disp
= pktsize
;
183 if(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
) {
196 for (idx
=0; idx
< pktnum
; idx
++) {
197 res
= cfe_write(fh
,tx_packet
,pktsize
);
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
);
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("...");
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");
223 /*Receive pre-defined test data*/
224 while (!console_status()) {
225 res
= cfe_read(fh
,rx_packet
,pktsize
);
226 if (res
== 0) continue;
228 xprintf("Read error: %s\n",cfe_errortext(res
));
231 xprintf("RX[%d] %d ",rx_count
,res
);
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("...");
244 if(rx_count
>= tx_count
) break;
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");
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') {
264 for(idx
= 0; idx
< tx_count
+5; idx
++) {
265 res
= cfe_read(fh
,rx_packet
,sizeof(rx_packet
));
267 xprintf("Read error: %s\n",cfe_errortext(res
));
270 if (res
== 0) continue;
271 xprintf("RX[%d] %d ",rx_count
,res
);
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("...");
286 else if (line
[0] == 't') {
289 xprintf("Transmit %d packet(s):\n",pktnum
);
290 xprintf("%d ",pktsize
);
291 pktsize_disp
= pktsize
;
292 if(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
) {
305 for(idx
= 0; idx
< pktnum
; idx
++) {
306 res
= cfe_write(fh
,tx_packet
,pktsize
);
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
);
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("...");
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");
331 memset(tx_packet
,0xEE,sizeof(tx_packet
));
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
);
340 tmp_char
= line
[idx2
+ 1];
341 lo
= xtoi(&tmp_char
);
350 /* Closing the device will reset the MAC # registers */