/[dynamips]/upstream/dynamips-0.2.6-RC1/dev_c7200_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.6-RC1/dev_c7200_eth.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (show annotations)
Sat Oct 6 16:03:58 2007 UTC (12 years, 1 month ago) by dpavlin
File MIME type: text/plain
File size: 10042 byte(s)
import dynamips-0.2.6-RC1

1 /*
2 * Cisco C7200 (Predator) simulation platform.
3 * Copyright (c) 2005,2006 Christophe Fillot (cf@utc.fr)
4 *
5 * Ethernet Port Adapters.
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_dec21140.h"
23 #include "dev_c7200.h"
24
25 /* ====================================================================== */
26 /* PA-FE-TX / C7200-IO-FE */
27 /* ====================================================================== */
28
29 /* PA-FE-TX: FastEthernet Port Adapter EEPROM */
30 static const m_uint16_t eeprom_c7200_pa_fe_tx_data[16] = {
31 0x0111, 0x0102, 0xffff, 0xffff, 0x4906, 0x9804, 0x0000, 0x0000,
32 0x6000, 0x0000, 0x9812, 0x1700, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
33 };
34
35 static const struct c7200_eeprom eeprom_c7200_pa_fe_tx = {
36 "PA-FE-TX", (m_uint16_t *)eeprom_c7200_pa_fe_tx_data,
37 sizeof(eeprom_c7200_pa_fe_tx_data)/2,
38 };
39
40 /* C7200-IO-FE: C7200 IOCard with one FastEthernet port EEPROM */
41 static const m_uint16_t eeprom_c7200_io_fe_data[16] = {
42 0x0183, 0x010E, 0xffff, 0xffff, 0x490B, 0x8C02, 0x0000, 0x0000,
43 0x5000, 0x0000, 0x9812, 0x2800, 0x00FF, 0xFFFF, 0xFFFF, 0xFFFF,
44 };
45
46 static const struct c7200_eeprom eeprom_c7200_io_fe = {
47 "C7200-IO-FE", (m_uint16_t *)eeprom_c7200_io_fe_data,
48 sizeof(eeprom_c7200_io_fe_data)/2,
49 };
50
51 /*
52 * dev_c7200_iocard_init()
53 *
54 * Add an IOcard into slot 0.
55 */
56 static int dev_c7200_iocard_init(c7200_t *router,char *name,u_int pa_bay)
57 {
58 struct dec21140_data *data;
59
60 if (pa_bay != 0) {
61 fprintf(stderr,"C7200 '%s': cannot put IOCARD in PA bay %u!\n",
62 router->vm->name,pa_bay);
63 return(-1);
64 }
65
66 /* Set the EEPROM */
67 c7200_pa_set_eeprom(router,pa_bay,&eeprom_c7200_io_fe);
68
69 /* Create the DEC21140 chip */
70 data = dev_dec21140_init(router->vm,name,
71 router->pa_bay[pa_bay].pci_map,
72 /*router->npe_driver->dec21140_pci_bus,*/ //PCI
73 router->npe_driver->dec21140_pci_dev,
74 C7200_NETIO_IRQ);
75 if (!data) return(-1);
76
77 /* Store device info into the router structure */
78 return(c7200_pa_set_drvinfo(router,pa_bay,data));
79 }
80
81 /* Remove an IOcard from slot 0 */
82 static int dev_c7200_iocard_shutdown(c7200_t *router,u_int pa_bay)
83 {
84 struct c7200_pa_bay *bay;
85
86 if (!(bay = c7200_pa_get_info(router,pa_bay)))
87 return(-1);
88
89 c7200_pa_unset_eeprom(router,pa_bay);
90 dev_dec21140_remove(bay->drv_info);
91 return(0);
92 }
93
94 /* Bind a Network IO descriptor */
95 static int dev_c7200_iocard_set_nio(c7200_t *router,u_int pa_bay,u_int port_id,
96 netio_desc_t *nio)
97 {
98 struct dec21140_data *d;
99
100 if ((port_id > 0) || !(d = c7200_pa_get_drvinfo(router,pa_bay)))
101 return(-1);
102
103 return(dev_dec21140_set_nio(d,nio));
104 }
105
106 /* Unbind a Network IO descriptor */
107 static int dev_c7200_iocard_unset_nio(c7200_t *router,u_int pa_bay,
108 u_int port_id)
109 {
110 struct dec21140_data *d;
111
112 if ((port_id > 0) || !(d = c7200_pa_get_drvinfo(router,pa_bay)))
113 return(-1);
114
115 dev_dec21140_unset_nio(d);
116 return(0);
117 }
118
119 /*
120 * dev_c7200_pa_fe_tx_init()
121 *
122 * Add a PA-FE-TX port adapter into specified slot.
123 */
124 static int dev_c7200_pa_fe_tx_init(c7200_t *router,char *name,u_int pa_bay)
125 {
126 struct dec21140_data *data;
127
128 /* Set the EEPROM */
129 c7200_pa_set_eeprom(router,pa_bay,&eeprom_c7200_pa_fe_tx);
130
131 /* Create the DEC21140 chip */
132 data = dev_dec21140_init(router->vm,name,router->pa_bay[pa_bay].pci_map,0,
133 C7200_NETIO_IRQ);
134 if (!data) return(-1);
135
136 /* Store device info into the router structure */
137 return(c7200_pa_set_drvinfo(router,pa_bay,data));
138 }
139
140 /* Remove a PA-FE-TX from the specified slot */
141 static int dev_c7200_pa_fe_tx_shutdown(c7200_t *router,u_int pa_bay)
142 {
143 struct c7200_pa_bay *bay;
144
145 if (!(bay = c7200_pa_get_info(router,pa_bay)))
146 return(-1);
147
148 c7200_pa_unset_eeprom(router,pa_bay);
149 dev_dec21140_remove(bay->drv_info);
150 return(0);
151 }
152
153 /* Bind a Network IO descriptor */
154 static int dev_c7200_pa_fe_tx_set_nio(c7200_t *router,u_int pa_bay,
155 u_int port_id,netio_desc_t *nio)
156 {
157 struct dec21140_data *d;
158
159 if ((port_id > 0) || !(d = c7200_pa_get_drvinfo(router,pa_bay)))
160 return(-1);
161
162 return(dev_dec21140_set_nio(d,nio));
163 }
164
165 /* Unbind a Network IO descriptor */
166 static int dev_c7200_pa_fe_tx_unset_nio(c7200_t *router,u_int pa_bay,
167 u_int port_id)
168 {
169 struct dec21140_data *d;
170
171 if ((port_id > 0) || !(d = c7200_pa_get_drvinfo(router,pa_bay)))
172 return(-1);
173
174 dev_dec21140_unset_nio(d);
175 return(0);
176 }
177
178 /* C7200-IO-FE driver */
179 struct c7200_pa_driver dev_c7200_io_fe_driver = {
180 "C7200-IO-FE", 1,
181 dev_c7200_iocard_init,
182 dev_c7200_iocard_shutdown,
183 dev_c7200_iocard_set_nio,
184 dev_c7200_iocard_unset_nio,
185 NULL,
186 };
187
188 /* PA-FE-TX driver */
189 struct c7200_pa_driver dev_c7200_pa_fe_tx_driver = {
190 "PA-FE-TX", 1,
191 dev_c7200_pa_fe_tx_init,
192 dev_c7200_pa_fe_tx_shutdown,
193 dev_c7200_pa_fe_tx_set_nio,
194 dev_c7200_pa_fe_tx_unset_nio,
195 NULL,
196 };
197
198 /* ====================================================================== */
199 /* PA-4E / PA-8E */
200 /* ====================================================================== */
201
202 /* PA-4E/PA-8E data */
203 struct pa_4e8e_data {
204 u_int nr_port;
205 struct am79c971_data *port[8];
206 };
207
208 /* PA-4E: 4 Ethernet Port Adapter EEPROM */
209 static const m_uint16_t eeprom_c7200_pa_4e_data[16] = {
210 0x0102, 0x010E, 0xFFFF, 0xFFFF, 0x4906, 0x1404, 0x0000, 0x0000,
211 0x5000, 0x0000, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
212 };
213
214 static const struct c7200_eeprom eeprom_c7200_pa_4e = {
215 "PA-4E", (m_uint16_t *)eeprom_c7200_pa_4e_data,
216 sizeof(eeprom_c7200_pa_4e_data)/2,
217 };
218
219 /* PA-8E: 8 Ethernet Port Adapter EEPROM */
220 static const m_uint16_t eeprom_c7200_pa_8e_data[16] = {
221 0x0101, 0x010E, 0xFFFF, 0xFFFF, 0x4906, 0x1404, 0x0000, 0x0000,
222 0x5000, 0x0000, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
223 };
224
225 static const struct c7200_eeprom eeprom_c7200_pa_8e = {
226 "PA-8E", (m_uint16_t *)eeprom_c7200_pa_8e_data,
227 sizeof(eeprom_c7200_pa_8e_data)/2,
228 };
229
230 /*
231 * dev_c7200_pa_4e_init()
232 *
233 * Add a PA-4E port adapter into specified slot.
234 */
235 static int dev_c7200_pa_4e_init(c7200_t *router,char *name,u_int pa_bay)
236 {
237 struct pa_4e8e_data *data;
238 int i;
239
240 /* Allocate the private data structure for the PA-4E */
241 if (!(data = malloc(sizeof(*data)))) {
242 fprintf(stderr,"%s (PA-4E): out of memory\n",name);
243 return(-1);
244 }
245
246 /* 4 Ethernet ports */
247 memset(data,0,sizeof(*data));
248 data->nr_port = 4;
249
250 /* Set the EEPROM */
251 c7200_pa_set_eeprom(router,pa_bay,&eeprom_c7200_pa_4e);
252
253 /* Create the AMD Am79c971 chips */
254 for(i=0;i<data->nr_port;i++) {
255 data->port[i] = dev_am79c971_init(router->vm,name,AM79C971_TYPE_10BASE_T,
256 router->pa_bay[pa_bay].pci_map,i,
257 C7200_NETIO_IRQ);
258 }
259
260 /* Store device info into the router structure */
261 return(c7200_pa_set_drvinfo(router,pa_bay,data));
262 }
263
264 /*
265 * dev_c7200_pa_8e_init()
266 *
267 * Add a PA-8E port adapter into specified slot.
268 */
269 static int dev_c7200_pa_8e_init(c7200_t *router,char *name,u_int pa_bay)
270 {
271 struct pa_4e8e_data *data;
272 int i;
273
274 /* Allocate the private data structure for the PA-8E */
275 if (!(data = malloc(sizeof(*data)))) {
276 fprintf(stderr,"%s (PA-8E): out of memory\n",name);
277 return(-1);
278 }
279
280 /* 4 Ethernet ports */
281 memset(data,0,sizeof(*data));
282 data->nr_port = 8;
283
284 /* Set the EEPROM */
285 c7200_pa_set_eeprom(router,pa_bay,&eeprom_c7200_pa_8e);
286
287 /* Create the AMD Am79c971 chips */
288 for(i=0;i<data->nr_port;i++) {
289 data->port[i] = dev_am79c971_init(router->vm,name,AM79C971_TYPE_10BASE_T,
290 router->pa_bay[pa_bay].pci_map,i,
291 C7200_NETIO_IRQ);
292 }
293
294 /* Store device info into the router structure */
295 return(c7200_pa_set_drvinfo(router,pa_bay,data));
296 }
297
298 /* Remove a PA-4E/PA-8E from the specified slot */
299 static int dev_c7200_pa_4e8e_shutdown(c7200_t *router,u_int pa_bay)
300 {
301 struct c7200_pa_bay *bay;
302 struct pa_4e8e_data *data;
303 int i;
304
305 if (!(bay = c7200_pa_get_info(router,pa_bay)))
306 return(-1);
307
308 data = bay->drv_info;
309
310 /* Remove the PA EEPROM */
311 c7200_pa_unset_eeprom(router,pa_bay);
312
313 /* Remove the AMD Am79c971 chips */
314 for(i=0;i<data->nr_port;i++)
315 dev_am79c971_remove(data->port[i]);
316
317 free(data);
318 return(0);
319 }
320
321 /* Bind a Network IO descriptor */
322 static int dev_c7200_pa_4e8e_set_nio(c7200_t *router,u_int pa_bay,
323 u_int port_id,netio_desc_t *nio)
324 {
325 struct pa_4e8e_data *d;
326
327 d = c7200_pa_get_drvinfo(router,pa_bay);
328
329 if (!d || (port_id >= d->nr_port))
330 return(-1);
331
332 dev_am79c971_set_nio(d->port[port_id],nio);
333 return(0);
334 }
335
336 /* Unbind a Network IO descriptor */
337 static int dev_c7200_pa_4e8e_unset_nio(c7200_t *router,u_int pa_bay,
338 u_int port_id)
339 {
340 struct pa_4e8e_data *d;
341
342 d = c7200_pa_get_drvinfo(router,pa_bay);
343
344 if (!d || (port_id >= d->nr_port))
345 return(-1);
346
347 dev_am79c971_unset_nio(d->port[port_id]);
348 return(0);
349 }
350
351 /* PA-4E driver */
352 struct c7200_pa_driver dev_c7200_pa_4e_driver = {
353 "PA-4E", 1,
354 dev_c7200_pa_4e_init,
355 dev_c7200_pa_4e8e_shutdown,
356 dev_c7200_pa_4e8e_set_nio,
357 dev_c7200_pa_4e8e_unset_nio,
358 NULL,
359 };
360
361 /* PA-8E driver */
362 struct c7200_pa_driver dev_c7200_pa_8e_driver = {
363 "PA-8E", 1,
364 dev_c7200_pa_8e_init,
365 dev_c7200_pa_4e8e_shutdown,
366 dev_c7200_pa_4e8e_set_nio,
367 dev_c7200_pa_4e8e_unset_nio,
368 NULL,
369 };

  ViewVC Help
Powered by ViewVC 1.1.26