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_sentosa_testcmds(void);
65 static int ui_cmd_fifotest(ui_cmdline_t
*cmd
, int argc
, char *argv
[]);
66 static int ui_cmd_download(ui_cmdline_t
*cmd
, int argc
, char *argv
[]);
68 int ui_init_sentosa_testcmds(void)
73 "Wait for a PCI download from the host",
77 cmd_addcmd("test fifo",
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"
85 "-8;8-bit mode (default)|"
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"
100 extern int cfe_device_download(int boot
, char *options
);
102 static int ui_cmd_download(ui_cmdline_t
*cmd
, int argc
, char *argv
[])
104 cfe_device_download(1, "");
109 static int ui_cmd_fifotest(ui_cmdline_t
*cmd
, int argc
, char *argv
[])
113 int fifo_mode
= ETHER_FIFO_8
;
114 int strobe
= ETHER_STROBE_ENCODED
;
115 int loopback
= ETHER_LOOPBACK_OFF
; /* only in 8-bit mode */
117 int idx
,idx2
,idx3
,idx4
;
119 uint8_t tx_packet
[1024];
120 uint8_t rx_packet
[1024];
123 int interactive
= FALSE
;
138 /* obtain and open device(mac) */
139 dev
= cmd_getarg(cmd
,0);
140 if (!dev
) return ui_showusage(cmd
);
143 xprintf("Could not open device: %s\n",cfe_errortext(fh
));
147 if (cmd_sw_isset(cmd
,"-i")) interactive
= TRUE
;
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");
155 fifo_mode
= ETHER_FIFO_16
;
157 cfe_ioctl(fh
,IOCTL_ETHER_SETPACKETFIFO
, (uint8_t *) &fifo_mode
, sizeof(fifo_mode
),NULL
,0);
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
;
163 else if (cmd_sw_isset(cmd
,"-sop")) {
164 strobe
= ETHER_STROBE_SOP
;
166 else if (cmd_sw_isset(cmd
,"-eop")) {
167 strobe
= ETHER_STROBE_EOP
;
169 cfe_ioctl(fh
,IOCTL_ETHER_SETSTROBESIG
, (uint8_t *)&strobe
,sizeof(strobe
),NULL
,0);
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
;
175 cfe_ioctl(fh
,IOCTL_ETHER_SETLOOPBACK
, (uint8_t *) &loopback
, sizeof(loopback
),NULL
,0);
177 /* packet size and number of packets to send */
179 cmd_sw_value(cmd
,"-pktsize",&tmp
);
184 cmd_sw_value(cmd
,"-pktnum",&tmp
);
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);
195 xprintf("Transmit %d packet(s):\n",pktnum
);
196 xprintf("%d ",pktsize
);
197 pktsize_disp
= pktsize
;
198 if(pktsize_disp
> 32) {
201 for (idx2
= 0,idx
= 1; idx2
< pktsize_disp
; idx2
++,idx
++) {
202 xprintf("%02X",tx_packet
[idx2
]);
203 if ( (idx
% 4) == 0 ) xprintf(" ");
206 if(pktsize
> pktsize_disp
) {
211 for (idx
=0; idx
< pktnum
; idx
++) {
212 res
= cfe_write(fh
,tx_packet
,pktsize
);
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;
220 xprintf("RX[%d] %d ",rx_count
,res
);
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(" ");
227 if(pktsize
> pktsize_disp
) xprintf("...");
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");
238 /*Receive pre-defined test data*/
239 while (!console_status()) {
240 res
= cfe_read(fh
,rx_packet
,pktsize
);
241 if (res
== 0) continue;
243 xprintf("Read error: %s\n",cfe_errortext(res
));
246 xprintf("RX[%d] %d ",rx_count
,res
);
248 if (res
> 32) res
= 32;
250 for (idx
= 0,idx2
= 1; idx
< res
; idx
++,idx2
++) {
251 xprintf("%02X",rx_packet
[idx
]);
252 if ( (idx2
% 4) == 0 ) xprintf(" ");
255 if(pktsize
> pktsize_disp
) xprintf("...");
259 if(rx_count
>= tx_count
) break;
266 memset(tx_packet
,0xEE,sizeof(tx_packet
));
268 xprintf("\nEnter hex value without '0x'. 't' to transmit. 'r' to receive. 'e' to end\n");
271 xsprintf(prompt
,"TX[%d] :",tx_count
);
272 num_read
= console_readline(prompt
,line
,sizeof(line
));
274 if (line
[0] == 'e') break;
276 if (line
[0] == 'r') {
279 for(idx
= 0; idx
< tx_count
+5; idx
++) {
280 res
= cfe_read(fh
,rx_packet
,sizeof(rx_packet
));
282 xprintf("Read error: %s\n",cfe_errortext(res
));
285 if (res
== 0) continue;
286 xprintf("RX[%d] %d ",rx_count
,res
);
288 if (res
> 32) res
= 32;
290 for (idx3
= 0,idx4
= 1; idx3
< res
; idx3
++,idx4
++) {
291 xprintf("%02X",rx_packet
[idx3
]);
292 if ( (idx4
% 4) == 0 ) xprintf(" ");
295 if(pktsize
> pktsize_disp
) xprintf("...");
301 else if (line
[0] == 't') {
304 xprintf("Transmit %d packet(s):\n",pktnum
);
305 xprintf("%d ",pktsize
);
306 pktsize_disp
= pktsize
;
307 if(pktsize_disp
> 32) {
310 for (idx2
= 0,idx
= 1; idx2
< pktsize_disp
; idx2
++,idx
++) {
311 xprintf("%02X",tx_packet
[idx2
]);
312 if ( (idx
% 4) == 0 ) xprintf(" ");
315 if(pktsize
> pktsize_disp
) {
320 for(idx
= 0; idx
< pktnum
; idx
++) {
321 res
= cfe_write(fh
,tx_packet
,pktsize
);
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;
329 xprintf("RX[%d] %d ",rx_count
,res
);
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(" ");
336 if(pktsize
> pktsize_disp
) xprintf("...");
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");
346 memset(tx_packet
,0xEE,sizeof(tx_packet
));
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
);
355 tmp_char
= line
[idx2
+ 1];
356 lo
= xtoi(&tmp_char
);
365 /* Closing the device will reset the MAC # registers */