1 /**
2 * @file pcap_singlecore.c
3 *
4 * @brief
5 * Example to illustrate the usage of EMAC CPSW3G switch using CPPI, QMSS
6 * low level drivers and CSL.
7 *
8 * This example application does the following:
9 * (1) Initializes:
10 * (a) Queue Manager (QM) Subsystem
11 * (b) Packet Accelerator (PA) CPPI DMA
12 * (c) Ethernet Subsystem (Ethernet switch + SGMII + MDIO) - (Note: Applicable only for NO_BOOT mode)
13 * (d) PA Subsystem + PDSP - (Note: PDSP is initialized only during NO_BOOT mode)
14 *
15 * (2) Sets up the CPPI descriptors and Queues required for sending and
16 * receiving data using Ethernet.
17 * (a) Uses Host descriptors
18 * (b) Uses High Priority Accumulation interrupts
19 *
20 * (3) Sets up the example application's configuration (MAC address
21 * it uses to send/recv data; IP address and port number it's listening
22 * on) in PA Subsystem so as to enable the PASS to forward all packets
23 * matching this configuration onto the application for processing.
24 * (a) Switch MAC address configured = 0x10:0x11:0x12:0x13:0x14:0x15
25 * (b) Example's IP address = 192.168.1.10
26 * (c) Example App's listening port = 0x5678
27 *
28 * (4) Sends packets onto wire
29 * (constructed manually in code here with following settings):
30 * (a) Source MAC = 0x00:0x01:0x02:0x03:0x04:0x05
31 * Destination MAC = 0x10:0x11:0x12:0x13:0x14:0x15
32 * (b) Source IP = 192.168.1.1
33 * Destination IP = 192.168.1.10
34 * (c) Source Port = 0x1234
35 * Destination Port= 0x5678
36 * (d) Payload Data (80 bytes)
37 *
38 * The packets sent by the application are sent onto wire and
39 * since the destination MAC on the packet is the Ethernet Switch
40 * MAC address, the packets are received by simulator and passed
41 * back up to the example application for processing.
42 *
43 * (5) Application receives all packets using QM High priority interrupt
44 * registered; Validates received packet against data sent.
45 *
46 * Example application Setup:
47 *
48 * PC Running Simulator using CCS connected to a
49 * Switch/Hub. You could put another PC on the Hub to observe packets
50 * being sent onto wire.
51 *
52 * Please consult the Readme.txt packaged with the example to
53 * setup the CCS simulator configuration required to run this example
54 * succesfully.
55 *
56 * \par
57 * ============================================================================
58 * @n (C) Copyright 2009, Texas Instruments, Inc.
59 *
60 * Redistribution and use in source and binary forms, with or without
61 * modification, are permitted provided that the following conditions
62 * are met:
63 *
64 * Redistributions of source code must retain the above copyright
65 * notice, this list of conditions and the following disclaimer.
66 *
67 * Redistributions in binary form must reproduce the above copyright
68 * notice, this list of conditions and the following disclaimer in the
69 * documentation and/or other materials provided with the
70 * distribution.
71 *
72 * Neither the name of Texas Instruments Incorporated nor the names of
73 * its contributors may be used to endorse or promote products derived
74 * from this software without specific prior written permission.
75 *
76 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
77 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
78 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
79 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
80 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
81 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
82 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
83 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
84 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
85 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
86 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
87 *
88 */
89 #include <pcap_singlecore.h>
90 #include <stdio.h>
92 /**************************************************************
93 ************************** DEFINITIONS ************************
94 ***************************************************************/
96 /* Counters to track number of packets sent/received by this application */
97 pktStats_t expected, actual;
99 /*
100 * Default test configuration for the silicon
101 *
102 * To run test at the CCS simulator
103 * cpswSimTest = 1
104 * cpswLpbkMode = CPSW_LOOPBACK_INTERNAL
105 */
106 #ifdef SIMULATOR_SUPPORT
107 int cpswSimTest = 1;
108 int cpswLpbkMode = CPSW_LOOPBACK_INTERNAL;
109 #else
110 int cpswSimTest = 0;
111 int cpswLpbkMode = CPSW_LOOPBACK_INTERNAL;
112 #endif
114 extern void mdebugHaltPdsp (int pdspNum);
115 volatile int mdebugWait = 1;
116 uint32_t no_bootMode = TRUE;
118 /**************************************************************
119 **************** EXAMPLE APP FUNCTIONS ************************
120 ***************************************************************/
122 /** ============================================================================
123 * @n@b pCap_SingleCoreApp
124 *
125 * @b Description
126 * @n Example application that sets up the application, sends, receives
127 * data.
128 *
129 * @param[in]
130 * @n None
131 *
132 * @return
133 * @n None
134 *
135 * =============================================================================
136 */
137 void pCap_SingleCoreApp (void)
138 {
139 System_printf ("**************************************************\n");
140 System_printf ("******* Single Core Packet Capture Unit Test Start *******\n");
141 System_printf ("**************************************************\n");
142 System_flush();
143 int anyTestFailCnt = 0;
145 if (setupFramework() != 0) {
146 System_printf ("Failed to setup test framework \n");
147 System_flush();
148 }
150 System_printf ("-------------------------------------------------------------------------------------------------------------------\n");
151 System_printf ("|Test Name\t\t\t|Port ID\t|Pkts Sent\t|Pkts Received\t|Pkts Captured/Mirrored\t|Test Status\n");
152 System_printf ("-------------------------------------------------------------------------------------------------------------------\n");
153 System_flush();
154 /* Run some data through and verify transfer worked */
155 for (dest_emac_port_id = 0; dest_emac_port_id < (NUM_MAC_PORTS); dest_emac_port_id ++)
156 {
157 /* If the port is not available for test, proceed for next port test */
158 if (ports[dest_emac_port_id].pState == NOT_AVAILABLE_FOR_PCAP_TEST)
159 continue;
161 /* 1. Ingress Packet Capture test */
162 if (pkt_capture_test(TRUE, dest_emac_port_id))
163 {
164 System_flush();
165 anyTestFailCnt ++;
166 }
168 /* 2. Ingress Port Mirror test */
169 if (port_mirror_test(TRUE, dest_emac_port_id))
170 {
171 System_flush();
172 anyTestFailCnt ++;
173 }
175 /* 3. Egress Packet Capture Test */
176 if (pkt_capture_test(FALSE, dest_emac_port_id))
177 {
178 System_flush();
179 anyTestFailCnt ++;
180 }
181 /* 4. Egress port Mirror Test */
182 if (port_mirror_test(FALSE, dest_emac_port_id))
183 {
184 System_flush();
185 anyTestFailCnt ++;
186 }
187 }
189 /* 5. Egress Packet Capture Test for CPPI PORT (PORT 0)*/
190 dest_emac_port_id = -1;
191 if (pkt_capture_test(FALSE, dest_emac_port_id))
192 {
193 System_printf ("Egress Packet Capture test failed for port # %d", dest_emac_port_id + pa_EMAC_PORT_0);
194 System_flush();
195 anyTestFailCnt ++;
196 }
198 System_printf ("-------------------------------------------------------------------------------------------------------------------\n");
200 System_printf (" \nExample Done! \nPA Stats After Packet Transmission BEGIN ********* ... \n");
201 if (getPaStats ()) {
202 System_printf ("Function getPaStats failed\n");
203 System_flush();
204 }
206 System_printf ("**************************************************\n");
207 System_printf ("******** Packet Capture Single Core Example End ********\n");
208 System_printf ("**************************************************\n");
209 System_flush();
211 /* Clear framework */
212 if (clearFramework() < 0)
213 {
214 System_printf ("Failed to Clean the example application \n");
215 System_flush();
216 }
218 #if (RM) && !defined(__LINUX_USER_SPACE)
219 {
220 int32_t rmResult;
222 if ((rmResult = Rm_resourceStatus(rmHandle, FALSE)) != 0)
223 {
224 System_printf ("Error : Number of unfreed resources : %d\n", rmResult);
225 System_flush();
226 }
227 else
228 {
229 System_printf ("All resources freed successfully\n");
230 System_flush();
231 }
232 }
233 #endif
234 /* Print all tests passed */
235 if (anyTestFailCnt == 0)
236 System_printf ("All tests passed \n");
237 else
238 System_printf ("Few tests failed \n");
239 /* Example application done. Return success */
240 APP_exit (0);
242 }
244 /* Nothing past this point */