1 | //============================================================================= |
---|
2 | // |
---|
3 | // etherdev.c |
---|
4 | // |
---|
5 | // Ethernet Abstraction Layer for Micro Monitor |
---|
6 | // |
---|
7 | // Author(s): Michael Kelly, Cogent Computer Systems, Inc. |
---|
8 | // Contributors: Luis Torrico, Cogent Computer Systems, Inc. |
---|
9 | // Date: 05-26-2002 |
---|
10 | // Modified: 06-26-2007 |
---|
11 | // Description: This file contains the interface layer between Micro Monitor |
---|
12 | // and the Ethernet driver for the LAN921x on the CSB733. |
---|
13 | // |
---|
14 | //============================================================================= |
---|
15 | |
---|
16 | #include "config.h" |
---|
17 | #include "cpuio.h" |
---|
18 | #include "genlib.h" |
---|
19 | #include "stddefs.h" |
---|
20 | #include "ether.h" |
---|
21 | |
---|
22 | extern void smsc911x_reset(void); |
---|
23 | extern ushort smsc911x_rx(uchar *pktbuf); |
---|
24 | extern int smsc911x_init(void); |
---|
25 | extern ulong smsc911x_tx(ulong txbuf, ulong length); |
---|
26 | extern void smsc911x_enable_promiscuous_reception(void); |
---|
27 | extern void smsc911x_disable_promiscuous_reception(void); |
---|
28 | extern void smsc911x_enable_multicast_reception(void); |
---|
29 | extern void smsc911x_disable_multicast_reception(void); |
---|
30 | extern void smsc911x_enable_broadcast_reception(void); |
---|
31 | extern void smsc911x_disable_broadcast_reception(void); |
---|
32 | |
---|
33 | ulong tx_buf[400]; |
---|
34 | |
---|
35 | #if INCLUDE_ETHERNET |
---|
36 | |
---|
37 | /* |
---|
38 | * enreset(): |
---|
39 | * Reset the PHY and MAC. |
---|
40 | */ |
---|
41 | void |
---|
42 | enreset(void) |
---|
43 | { |
---|
44 | smsc911x_reset(); |
---|
45 | } |
---|
46 | |
---|
47 | /* |
---|
48 | * eninit(): |
---|
49 | * This would include establishing buffer descriptor tables and |
---|
50 | * all the support code that will be used by the ethernet device. |
---|
51 | * |
---|
52 | * It can be assumed at this point that the array uchar BinEnetAddr[6] |
---|
53 | * contains the 6-byte MAC address. |
---|
54 | * |
---|
55 | * Return 0 if successful; else -1. |
---|
56 | */ |
---|
57 | int |
---|
58 | eninit(void) |
---|
59 | { |
---|
60 | return smsc911x_init(); |
---|
61 | |
---|
62 | } |
---|
63 | |
---|
64 | int |
---|
65 | EtherdevStartup(int verbose) |
---|
66 | { |
---|
67 | /* Initialize local device error counts (if any) here. */ |
---|
68 | /* OPT_ADD_CODE_HERE */ |
---|
69 | |
---|
70 | /* Put ethernet controller in reset: */ |
---|
71 | enreset(); |
---|
72 | |
---|
73 | /* Initialize controller: */ |
---|
74 | eninit(); |
---|
75 | |
---|
76 | return(0); |
---|
77 | } |
---|
78 | |
---|
79 | /* disablePromiscuousReception(): |
---|
80 | * Provide the code that disables promiscuous reception. |
---|
81 | */ |
---|
82 | void |
---|
83 | disablePromiscuousReception(void) |
---|
84 | { |
---|
85 | smsc911x_disable_promiscuous_reception(); |
---|
86 | } |
---|
87 | |
---|
88 | /* enablePromiscuousReception(): |
---|
89 | * Provide the code that enables promiscuous reception. |
---|
90 | */ |
---|
91 | void |
---|
92 | enablePromiscuousReception(void) |
---|
93 | { |
---|
94 | smsc911x_enable_promiscuous_reception(); |
---|
95 | } |
---|
96 | |
---|
97 | /* disableBroadcastReception(): |
---|
98 | * Provide the code that disables broadcast reception. |
---|
99 | */ |
---|
100 | void |
---|
101 | disableBroadcastReception(void) |
---|
102 | { |
---|
103 | smsc911x_disable_broadcast_reception(); |
---|
104 | } |
---|
105 | |
---|
106 | /* enableBroadcastReception(): |
---|
107 | * Provide the code that enables broadcast reception. |
---|
108 | */ |
---|
109 | void |
---|
110 | enableBroadcastReception(void) |
---|
111 | { |
---|
112 | smsc911x_enable_broadcast_reception(); |
---|
113 | } |
---|
114 | |
---|
115 | void |
---|
116 | disableMulticastReception(void) |
---|
117 | { |
---|
118 | smsc911x_disable_multicast_reception(); |
---|
119 | } |
---|
120 | |
---|
121 | void |
---|
122 | enableMulticastReception(void) |
---|
123 | { |
---|
124 | smsc911x_enable_multicast_reception(); |
---|
125 | } |
---|
126 | |
---|
127 | |
---|
128 | /* |
---|
129 | * enselftest(): |
---|
130 | * Run a self test of the ethernet device(s). This can be stubbed |
---|
131 | * with a return(1). |
---|
132 | * Return 1 if success; else -1 if failure. |
---|
133 | */ |
---|
134 | int |
---|
135 | enselftest(int verbose) |
---|
136 | { |
---|
137 | return(1); |
---|
138 | } |
---|
139 | |
---|
140 | /* ShowEtherdevStats(): |
---|
141 | * This function is used to display device-specific stats (error counts |
---|
142 | * usually). |
---|
143 | */ |
---|
144 | void |
---|
145 | ShowEtherdevStats(void) |
---|
146 | { |
---|
147 | /* OPT_ADD_CODE_HERE */ |
---|
148 | } |
---|
149 | |
---|
150 | /* getXmitBuffer(): |
---|
151 | * Return a pointer to the buffer that is to be used for transmission of |
---|
152 | * the next packet. Since the monitor's driver is EXTREMELY basic, |
---|
153 | * there will only be one packet ever being transmitted. No need to queue |
---|
154 | * up transmit packets. |
---|
155 | */ |
---|
156 | uchar * |
---|
157 | getXmitBuffer(void) |
---|
158 | { |
---|
159 | return((uchar *) tx_buf); |
---|
160 | } |
---|
161 | |
---|
162 | /* sendBuffer(): |
---|
163 | * Send out the packet assumed to be built in the buffer returned by the |
---|
164 | * previous call to getXmitBuffer() above. |
---|
165 | */ |
---|
166 | int |
---|
167 | sendBuffer(int length) |
---|
168 | { |
---|
169 | ulong temp32; |
---|
170 | |
---|
171 | if (length < 64) |
---|
172 | length = 64; |
---|
173 | |
---|
174 | if (EtherVerbose & SHOW_OUTGOING) |
---|
175 | printPkt((struct ether_header *)tx_buf,length,ETHER_OUTGOING); |
---|
176 | |
---|
177 | // tell the cs8900a to send the tx buffer pointed to by tx_buf |
---|
178 | temp32 = smsc911x_tx((ulong)tx_buf, (ulong)length); |
---|
179 | |
---|
180 | EtherXFRAMECnt++; |
---|
181 | if (temp32) { |
---|
182 | return -1; |
---|
183 | } |
---|
184 | else { |
---|
185 | return 0; |
---|
186 | } |
---|
187 | } |
---|
188 | |
---|
189 | /* DisableEtherdev(): |
---|
190 | * Fine as it is... |
---|
191 | */ |
---|
192 | void |
---|
193 | DisableEtherdev(void) |
---|
194 | { |
---|
195 | enreset(); |
---|
196 | } |
---|
197 | |
---|
198 | /* extGetIpAdd(): |
---|
199 | * If there was some external mechanism (other than just using the |
---|
200 | * IPADD shell variable established in the monrc file) for retrieval of |
---|
201 | * the board's IP address, then do it here... |
---|
202 | */ |
---|
203 | char * |
---|
204 | extGetIpAdd(void) |
---|
205 | { |
---|
206 | return((char *)0); |
---|
207 | } |
---|
208 | |
---|
209 | /* extGetEtherAdd(): |
---|
210 | * If there was some external mechanism (other than just using the |
---|
211 | * ETHERADD shell variable established in the monrc file) for retrieval of |
---|
212 | * the board's MAC address, then do it here... |
---|
213 | */ |
---|
214 | char * |
---|
215 | extGetEtherAdd(void) |
---|
216 | { |
---|
217 | return((char *)0); |
---|
218 | } |
---|
219 | |
---|
220 | /* |
---|
221 | * polletherdev(): |
---|
222 | * Called continuously by the monitor (ethernet.c) to determine if there |
---|
223 | * is any incoming ethernet packets. |
---|
224 | */ |
---|
225 | int |
---|
226 | polletherdev(void) |
---|
227 | { |
---|
228 | ulong pktbuf[RBUFSIZE/4]; |
---|
229 | int pktlen, pktcnt = 0; |
---|
230 | |
---|
231 | pktlen = smsc911x_rx((uchar *)pktbuf); |
---|
232 | |
---|
233 | if(pktlen) { |
---|
234 | pktcnt = 1; |
---|
235 | EtherRFRAMECnt++; |
---|
236 | processPACKET((struct ether_header *)pktbuf, pktlen); |
---|
237 | } |
---|
238 | return(pktcnt); |
---|
239 | } |
---|
240 | |
---|
241 | #endif |
---|