/[dynamips]/upstream/dynamips-0.2.7-RC2/dev_c2600_eth.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /upstream/dynamips-0.2.7-RC2/dev_c2600_eth.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 8 - (show annotations)
Sat Oct 6 16:24:54 2007 UTC (12 years, 1 month ago) by dpavlin
File MIME type: text/plain
File size: 10432 byte(s)
dynamips-0.2.7-RC2

1 /*
2 * Cisco router simulation platform.
3 * Copyright (c) 2006 Christophe Fillot (cf@utc.fr)
4 *
5 * Ethernet Network Modules.
6 */
7
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <stdarg.h>
12 #include <unistd.h>
13 #include <time.h>
14 #include <errno.h>
15 #include <assert.h>
16
17 #include "utils.h"
18 #include "net.h"
19 #include "net_io.h"
20 #include "ptask.h"
21 #include "dev_am79c971.h"
22 #include "dev_nm_16esw.h"
23 #include "dev_c2600.h"
24
25 /* Multi-Ethernet NM with Am79c971 chips */
26 struct nm_eth_data {
27 u_int nr_port;
28 struct am79c971_data *port[8];
29 };
30
31 /*
32 * dev_c2600_nm_eth_init()
33 *
34 * Add an Ethernet Network Module into specified slot.
35 */
36 static int dev_c2600_nm_eth_init(c2600_t *router,char *name,u_int nm_bay,
37 int nr_port,int interface_type,
38 const struct cisco_eeprom *eeprom)
39 {
40 struct nm_eth_data *data;
41 int i;
42
43 /* Allocate the private data structure */
44 if (!(data = malloc(sizeof(*data)))) {
45 fprintf(stderr,"%s: out of memory\n",name);
46 return(-1);
47 }
48
49 memset(data,0,sizeof(*data));
50 data->nr_port = nr_port;
51
52 /* Set the EEPROM */
53 c2600_nm_set_eeprom(router,nm_bay,eeprom);
54
55 /* Create the AMD Am971c971 chip(s) */
56 for(i=0;i<data->nr_port;i++) {
57 data->port[i] = dev_am79c971_init(router->vm,name,interface_type,
58 router->nm_bay[nm_bay].pci_map,
59 i+(nm_bay * 4),
60 c2600_net_irq_for_slot_port(nm_bay,i));
61 }
62
63 /* Store device info into the router structure */
64 return(c2600_nm_set_drvinfo(router,nm_bay,data));
65 }
66
67 /* Remove an Ethernet NM from the specified slot */
68 static int dev_c2600_nm_eth_shutdown(c2600_t *router,u_int nm_bay)
69 {
70 struct c2600_nm_bay *bay;
71 struct nm_eth_data *data;
72 int i;
73
74 if (!(bay = c2600_nm_get_info(router,nm_bay)))
75 return(-1);
76
77 data = bay->drv_info;
78
79 /* Remove the NM EEPROM */
80 c2600_nm_unset_eeprom(router,nm_bay);
81
82 /* Remove the AMD Am79c971 chips */
83 for(i=0;i<data->nr_port;i++)
84 dev_am79c971_remove(data->port[i]);
85
86 free(data);
87 return(0);
88 }
89
90 /* Bind a Network IO descriptor */
91 static int dev_c2600_nm_eth_set_nio(c2600_t *router,u_int nm_bay,
92 u_int port_id,netio_desc_t *nio)
93 {
94 struct nm_eth_data *d;
95
96 d = c2600_nm_get_drvinfo(router,nm_bay);
97
98 if (!d || (port_id >= d->nr_port))
99 return(-1);
100
101 dev_am79c971_set_nio(d->port[port_id],nio);
102 return(0);
103 }
104
105 /* Unbind a Network IO descriptor */
106 static int dev_c2600_nm_eth_unset_nio(c2600_t *router,u_int nm_bay,
107 u_int port_id)
108 {
109 struct nm_eth_data *d;
110
111 d = c2600_nm_get_drvinfo(router,nm_bay);
112
113 if (!d || (port_id >= d->nr_port))
114 return(-1);
115
116 dev_am79c971_unset_nio(d->port[port_id]);
117 return(0);
118 }
119
120 /* ====================================================================== */
121 /* Cisco 2600 mainboard with 1 Ethernet port */
122 /* ====================================================================== */
123
124 static int dev_c2600_mb1e_eth_init(c2600_t *router,char *name,u_int nm_bay)
125 {
126 return(dev_c2600_nm_eth_init(router,name,nm_bay,1,AM79C971_TYPE_10BASE_T,
127 NULL));
128 }
129
130 /* ====================================================================== */
131 /* Cisco 2600 mainboard with 1 Ethernet port */
132 /* ====================================================================== */
133 static int dev_c2600_mb2e_eth_init(c2600_t *router,char *name,u_int nm_bay)
134 {
135 return(dev_c2600_nm_eth_init(router,name,nm_bay,2,AM79C971_TYPE_10BASE_T,
136 NULL));
137 }
138
139 /* ====================================================================== */
140 /* Cisco 2600 mainboard with 1 FastEthernet port */
141 /* ====================================================================== */
142 static int dev_c2600_mb1fe_eth_init(c2600_t *router,char *name,u_int nm_bay)
143 {
144 return(dev_c2600_nm_eth_init(router,name,nm_bay,1,AM79C971_TYPE_100BASE_TX,
145 NULL));
146 }
147
148 /* ====================================================================== */
149 /* Cisco 2600 mainboard with 2 FastEthernet ports */
150 /* ====================================================================== */
151 static int dev_c2600_mb2fe_eth_init(c2600_t *router,char *name,u_int nm_bay)
152 {
153 return(dev_c2600_nm_eth_init(router,name,nm_bay,2,AM79C971_TYPE_100BASE_TX,
154 NULL));
155 }
156
157 /* ====================================================================== */
158 /* NM-1E */
159 /* ====================================================================== */
160
161 /*
162 * dev_c2600_nm_1e_init()
163 *
164 * Add a NM-1E Network Module into specified slot.
165 */
166 static int dev_c2600_nm_1e_init(c2600_t *router,char *name,u_int nm_bay)
167 {
168 return(dev_c2600_nm_eth_init(router,name,nm_bay,1,AM79C971_TYPE_10BASE_T,
169 cisco_eeprom_find_nm("NM-1E")));
170 }
171
172 /* ====================================================================== */
173 /* NM-4E */
174 /* ====================================================================== */
175
176 /*
177 * dev_c2600_nm_4e_init()
178 *
179 * Add a NM-4E Network Module into specified slot.
180 */
181 static int dev_c2600_nm_4e_init(c2600_t *router,char *name,u_int nm_bay)
182 {
183 return(dev_c2600_nm_eth_init(router,name,nm_bay,4,AM79C971_TYPE_10BASE_T,
184 cisco_eeprom_find_nm("NM-4E")));
185 }
186
187 /* ====================================================================== */
188 /* NM-1FE-TX */
189 /* ====================================================================== */
190
191 /*
192 * dev_c2600_nm_1fe_tx_init()
193 *
194 * Add a NM-1FE-TX Network Module into specified slot.
195 */
196 static int dev_c2600_nm_1fe_tx_init(c2600_t *router,char *name,u_int nm_bay)
197 {
198 return(dev_c2600_nm_eth_init(router,name,nm_bay,1,AM79C971_TYPE_100BASE_TX,
199 cisco_eeprom_find_nm("NM-1FE-TX")));
200 }
201
202 /* ====================================================================== */
203 /* NM-16ESW */
204 /* ====================================================================== */
205
206 /* Add a NM-16ESW */
207 static int dev_c2600_nm_16esw_init(c2600_t *router,char *name,u_int nm_bay)
208 {
209 struct nm_16esw_data *data;
210
211 /* Set the EEPROM */
212 c2600_nm_set_eeprom(router,nm_bay,cisco_eeprom_find_nm("NM-16ESW"));
213 dev_nm_16esw_burn_mac_addr(router->vm,nm_bay,
214 &router->nm_bay[nm_bay].eeprom);
215
216 /* Create the device */
217 data = dev_nm_16esw_init(router->vm,name,nm_bay,
218 router->nm_bay[nm_bay].pci_map,4,
219 c2600_net_irq_for_slot_port(nm_bay,0));
220
221 /* Store device info into the router structure */
222 return(c2600_nm_set_drvinfo(router,nm_bay,data));
223 }
224
225 /* Remove a NM-16ESW from the specified slot */
226 static int dev_c2600_nm_16esw_shutdown(c2600_t *router,u_int nm_bay)
227 {
228 struct c2600_nm_bay *bay;
229 struct nm_16esw_data *data;
230
231 if (!(bay = c2600_nm_get_info(router,nm_bay)))
232 return(-1);
233
234 data = bay->drv_info;
235
236 /* Remove the NM EEPROM */
237 c2600_nm_unset_eeprom(router,nm_bay);
238
239 /* Remove the BCM5600 chip */
240 dev_nm_16esw_remove(data);
241 return(0);
242 }
243
244 /* Bind a Network IO descriptor */
245 static int dev_c2600_nm_16esw_set_nio(c2600_t *router,u_int nm_bay,
246 u_int port_id,netio_desc_t *nio)
247 {
248 struct nm_16esw_data *d;
249
250 d = c2600_nm_get_drvinfo(router,nm_bay);
251 dev_nm_16esw_set_nio(d,port_id,nio);
252 return(0);
253 }
254
255 /* Unbind a Network IO descriptor */
256 static int dev_c2600_nm_16esw_unset_nio(c2600_t *router,u_int nm_bay,
257 u_int port_id)
258 {
259 struct nm_16esw_data *d;
260
261 d = c2600_nm_get_drvinfo(router,nm_bay);
262 dev_nm_16esw_unset_nio(d,port_id);
263 return(0);
264 }
265
266 /* Show debug info */
267 static int dev_c2600_nm_16esw_show_info(c2600_t *router,u_int nm_bay)
268 {
269 struct nm_16esw_data *d;
270
271 d = c2600_nm_get_drvinfo(router,nm_bay);
272 dev_nm_16esw_show_info(d);
273 return(0);
274 }
275
276 /* ====================================================================== */
277
278 /* Cisco 2600 mainboard 1 Ethernet port driver */
279 struct c2600_nm_driver dev_c2600_mb1e_eth_driver = {
280 "CISCO2600-MB-1E", 1, 0,
281 dev_c2600_mb1e_eth_init,
282 dev_c2600_nm_eth_shutdown,
283 dev_c2600_nm_eth_set_nio,
284 dev_c2600_nm_eth_unset_nio,
285 NULL,
286 };
287
288 /* Cisco 2600 mainboard 2 Ethernet port driver */
289 struct c2600_nm_driver dev_c2600_mb2e_eth_driver = {
290 "CISCO2600-MB-2E", 1, 0,
291 dev_c2600_mb2e_eth_init,
292 dev_c2600_nm_eth_shutdown,
293 dev_c2600_nm_eth_set_nio,
294 dev_c2600_nm_eth_unset_nio,
295 NULL,
296 };
297
298 /* Cisco 2600 mainboard 1 FastEthernet port driver */
299 struct c2600_nm_driver dev_c2600_mb1fe_eth_driver = {
300 "CISCO2600-MB-1FE", 1, 0,
301 dev_c2600_mb1fe_eth_init,
302 dev_c2600_nm_eth_shutdown,
303 dev_c2600_nm_eth_set_nio,
304 dev_c2600_nm_eth_unset_nio,
305 NULL,
306 };
307
308 /* Cisco 2600 mainboard 2 Ethernet port driver */
309 struct c2600_nm_driver dev_c2600_mb2fe_eth_driver = {
310 "CISCO2600-MB-2FE", 1, 0,
311 dev_c2600_mb2fe_eth_init,
312 dev_c2600_nm_eth_shutdown,
313 dev_c2600_nm_eth_set_nio,
314 dev_c2600_nm_eth_unset_nio,
315 NULL,
316 };
317
318 /* NM-1FE-TX driver */
319 struct c2600_nm_driver dev_c2600_nm_1fe_tx_driver = {
320 "NM-1FE-TX", 1, 0,
321 dev_c2600_nm_1fe_tx_init,
322 dev_c2600_nm_eth_shutdown,
323 dev_c2600_nm_eth_set_nio,
324 dev_c2600_nm_eth_unset_nio,
325 NULL,
326 };
327
328 /* NM-1E driver */
329 struct c2600_nm_driver dev_c2600_nm_1e_driver = {
330 "NM-1E", 1, 0,
331 dev_c2600_nm_1e_init,
332 dev_c2600_nm_eth_shutdown,
333 dev_c2600_nm_eth_set_nio,
334 dev_c2600_nm_eth_unset_nio,
335 NULL,
336 };
337
338 /* NM-4E driver */
339 struct c2600_nm_driver dev_c2600_nm_4e_driver = {
340 "NM-4E", 1, 0,
341 dev_c2600_nm_4e_init,
342 dev_c2600_nm_eth_shutdown,
343 dev_c2600_nm_eth_set_nio,
344 dev_c2600_nm_eth_unset_nio,
345 NULL,
346 };
347
348 /* NM-16ESW driver */
349 struct c2600_nm_driver dev_c2600_nm_16esw_driver = {
350 "NM-16ESW", 1, 0,
351 dev_c2600_nm_16esw_init,
352 dev_c2600_nm_16esw_shutdown,
353 dev_c2600_nm_16esw_set_nio,
354 dev_c2600_nm_16esw_unset_nio,
355 dev_c2600_nm_16esw_show_info,
356 };

  ViewVC Help
Powered by ViewVC 1.1.26