source: umon/ports/template/etherdev.c @ ddf6706

Last change on this file since ddf6706 was 87db514, checked in by Amar Takhar <amar@…>, on 04/16/15 at 19:26:21

Initial commit of the umon repository.

Prior to this three changes were made:

  • Remove umon_ prefix from parent directories.
  • Collapse main/target/ into main/
  • Remove ports/template/flashtest.scr.ucon script.
  • Property mode set to 100644
File size: 5.8 KB
Line 
1/* template_etherdev.c:
2 * This is a "starter" file for the ethernet driver interface used by
3 * the monitor.  The functions are described, but empty.
4 * At a minimum, code must be added in all places marked ADD_CODE_HERE.
5 * Additional OPT_ADD_CODE_HERE tags indicate locations that can be
6 * omitted, but would be nice to have additional facilities.
7 *
8 * General notice:
9 * This code is part of a boot-monitor package developed as a generic base
10 * platform for embedded system designs.  As such, it is likely to be
11 * distributed to various projects beyond the control of the original
12 * author.  Please notify the author of any enhancements made or bugs found
13 * so that all may benefit from the changes.  In addition, notification back
14 * to the author will allow the new user to pick up changes that may have
15 * been made by other users after this version of the code was distributed.
16 *
17 * Author:      Ed Sutter
18 * email:       esutter@lucent.com
19 * phone:       908-582-2351
20 */
21
22#include "config.h"
23#include "genlib.h"
24#include "stddefs.h"
25#include "ether.h"
26
27#if INCLUDE_ETHERNET
28
29ulong tx_buff[400];
30
31/*
32 * enreset():
33 *      Reset the PHY and MAC.
34 */
35void
36enreset(void)
37{
38        /* ADD_CODE_HERE */
39}
40
41/*
42 * eninit():
43 * Initialize the PHY and MAC.
44 * This would include establishing buffer descriptor tables and
45 * all the support code that will be used by the ethernet device.
46 *
47 * It can be assumed at this point that the array uchar BinEnetAddr[6]
48 * contains the 6-byte MAC address.
49 *
50 * Return 0 if successful; else -1.
51 */
52int
53eninit(void)
54{
55        /* Initialize the Phy */
56        /* ADD_CODE_HERE */
57
58        /* Query the PHY to determine if the link is up.
59         * If not just default to a 10Base-T, half-duplex interface config.
60         * If link is up, then attempt auto-negotiation.
61         */
62        /* ADD_CODE_HERE */
63
64        /* Initialize the MAC */
65        /* ADD_CODE_HERE */
66
67        return (0);
68}
69
70int
71EtherdevStartup(int verbose)
72{
73        /* Initialize local device error counts (if any) here. */
74        /* OPT_ADD_CODE_HERE */
75
76        /* Put ethernet controller in reset: */
77        enreset();
78
79        /* Initialize controller and return the value returned by
80         * eninit().
81         */
82        return(eninit());
83}
84
85/* disablePromiscuousReception():
86 * Provide the code that disables promiscuous reception.
87 */
88void
89disablePromiscuousReception(void)
90{
91        /* OPT_ADD_CODE_HERE */
92}
93
94/* enablePromiscuousReception():
95 * Provide the code that enables promiscuous reception.
96 */
97void
98enablePromiscuousReception(void)
99{
100        /* OPT_ADD_CODE_HERE */
101}
102
103/* disableBroadcastReception():
104 * Provide the code that disables broadcast reception.
105 */
106void
107disableBroadcastReception(void)
108{
109        /* ADD_CODE_HERE */
110}
111
112/* enableBroadcastReception():
113 * Provide the code that enables broadcast reception.
114 */
115void
116enableBroadcastReception(void)
117{
118        /* ADD_CODE_HERE */
119}
120
121/*
122 * enselftest():
123 *      Run a self test of the ethernet device(s).  This can be stubbed
124 *      with a return(1).
125 *      Return 1 if success; else -1 if failure.
126 */
127int
128enselftest(int verbose)
129{
130        return(1);
131}
132
133/* ShowEtherdevStats():
134 * This function is used to display device-specific stats (error counts
135 * usually).
136 */
137void
138ShowEtherdevStats(void)
139{
140        /* OPT_ADD_CODE_HERE */
141}
142
143/* getXmitBuffer():
144 * Return a pointer to the buffer that is to be used for transmission of
145 * the next packet.  Since the monitor's driver is EXTREMELY basic,
146 * there will only be one packet ever being transmitted.  No need to queue
147 * up transmit packets.
148 */
149uchar *
150getXmitBuffer(void)
151{
152        /* ADD_CODE_HERE */
153        return((uchar *)tx_buff);
154}
155
156/* sendBuffer():
157 * Send out the packet assumed to be built in the buffer returned by the
158 * previous call to getXmitBuffer() above.
159 */
160int
161sendBuffer(int length)
162{
163#if INCLUDE_ETHERVERBOSE
164        if (EtherVerbose &  SHOW_OUTGOING)
165                printPkt((struct ether_header *)tx_buff,length,ETHER_OUTGOING);
166#endif
167
168        /* Bump up the packet length to a minimum of 64 bytes.
169         */
170        if (length < 64)
171                length = 64;
172
173        /* Add the code that will tickle the device into sending out the
174         * buffer that was previously returned by getXmitBuffer() above...
175         */
176        /* ADD_CODE_HERE */
177
178        EtherXFRAMECnt++;
179        return(0);
180}
181
182/* DisableEtherdev():
183 * Fine as it is...
184 */
185void
186DisableEtherdev(void)
187{
188        enreset();
189}
190
191/* extGetIpAdd():
192 * If there was some external mechanism (other than just using the
193 * IPADD shell variable established in the monrc file) for retrieval of
194 * the board's IP address, then do it here...
195 */
196char *
197extGetIpAdd(void)
198{
199        return((char *)0);
200}
201
202/* extGetEtherAdd():
203 * If there was some external mechanism (other than just using the
204 * ETHERADD shell variable established in the monrc file) for retrieval of
205 * the board's MAC address, then do it here...
206 */
207char *
208extGetEtherAdd(void)
209{
210        return((char *)0);
211}
212
213/*
214 * polletherdev():
215 * Called continuously by the monitor (ethernet.c) to determine if there
216 * is any incoming ethernet packets.
217 *
218 * NOTES:
219 * 1. This function must be reentrant, because there are a few cases in
220 *    processPACKET() where pollethernet() may be called.
221 * 2. It should only process one packet per call.  This is important
222 *    because if allowed to stay here to flush all available packets,
223 *    it may starve the rest of the system (especially in cases of heavy
224 *    network traffic).
225 * 3. There are cases in the monitor's execution that may cause the
226 *    polling polletherdev() to cease for several seconds.  Depending on
227 *    network traffic, this may cause the input buffering mechanism on
228 *    the ethernet device to overflow.  A robust polletherdev() function
229 *    should support this gracefully (i.e. when the error is detected,
230 *    attempt to pass all queued packets to processPACKET(), then do what
231 *    is necessary to clear the error).
232 */
233int
234polletherdev(void)
235{
236        uchar *pktbuf = (char *)0;
237        int     pktlen = 0, pktcnt = 0;
238
239        if (PACKET_AVAILABLE()) {
240                GET_PACKET_FROM_DEVICE();
241                processPACKET((struct ether_header *)pktbuf, pktlen);
242                pktcnt++;
243        }
244        return(pktcnt);
245}
246
247#endif
Note: See TracBrowser for help on using the repository browser.