/[dynamips]/upstream/dynamips-0.2.5/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

Annotation of /upstream/dynamips-0.2.5/dev_c7200_eth.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (hide annotations)
Sat Oct 6 16:01:44 2007 UTC (16 years, 5 months ago) by dpavlin
File MIME type: text/plain
File size: 10006 byte(s)
import 0.2.5 from upstream

1 dpavlin 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     };
186    
187     /* PA-FE-TX driver */
188     struct c7200_pa_driver dev_c7200_pa_fe_tx_driver = {
189     "PA-FE-TX", 1,
190     dev_c7200_pa_fe_tx_init,
191     dev_c7200_pa_fe_tx_shutdown,
192     dev_c7200_pa_fe_tx_set_nio,
193     dev_c7200_pa_fe_tx_unset_nio,
194     };
195    
196     /* ====================================================================== */
197     /* PA-4E / PA-8E */
198     /* ====================================================================== */
199    
200     /* PA-4E/PA-8E data */
201     struct pa_4e8e_data {
202     u_int nr_port;
203     struct am79c971_data *port[8];
204     };
205    
206     /* PA-4E: 4 Ethernet Port Adapter EEPROM */
207     static const m_uint16_t eeprom_c7200_pa_4e_data[16] = {
208     0x0102, 0x010E, 0xFFFF, 0xFFFF, 0x4906, 0x1404, 0x0000, 0x0000,
209     0x5000, 0x0000, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
210     };
211    
212     static const struct c7200_eeprom eeprom_c7200_pa_4e = {
213     "PA-4E", (m_uint16_t *)eeprom_c7200_pa_4e_data,
214     sizeof(eeprom_c7200_pa_4e_data)/2,
215     };
216    
217     /* PA-8E: 8 Ethernet Port Adapter EEPROM */
218     static const m_uint16_t eeprom_c7200_pa_8e_data[16] = {
219     0x0101, 0x010E, 0xFFFF, 0xFFFF, 0x4906, 0x1404, 0x0000, 0x0000,
220     0x5000, 0x0000, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
221     };
222    
223     static const struct c7200_eeprom eeprom_c7200_pa_8e = {
224     "PA-8E", (m_uint16_t *)eeprom_c7200_pa_8e_data,
225     sizeof(eeprom_c7200_pa_8e_data)/2,
226     };
227    
228     /*
229     * dev_c7200_pa_4e_init()
230     *
231     * Add a PA-4E port adapter into specified slot.
232     */
233     static int dev_c7200_pa_4e_init(c7200_t *router,char *name,u_int pa_bay)
234     {
235     struct pa_4e8e_data *data;
236     int i;
237    
238     /* Allocate the private data structure for the PA-4E */
239     if (!(data = malloc(sizeof(*data)))) {
240     fprintf(stderr,"%s (PA-4E): out of memory\n",name);
241     return(-1);
242     }
243    
244     /* 4 Ethernet ports */
245     memset(data,0,sizeof(*data));
246     data->nr_port = 4;
247    
248     /* Set the EEPROM */
249     c7200_pa_set_eeprom(router,pa_bay,&eeprom_c7200_pa_4e);
250    
251     /* Create the AMD Am79c971 chips */
252     for(i=0;i<data->nr_port;i++) {
253     data->port[i] = dev_am79c971_init(router->vm,name,AM79C971_TYPE_10BASE_T,
254     router->pa_bay[pa_bay].pci_map,i,
255     C7200_NETIO_IRQ);
256     }
257    
258     /* Store device info into the router structure */
259     return(c7200_pa_set_drvinfo(router,pa_bay,data));
260     }
261    
262     /*
263     * dev_c7200_pa_8e_init()
264     *
265     * Add a PA-8E port adapter into specified slot.
266     */
267     static int dev_c7200_pa_8e_init(c7200_t *router,char *name,u_int pa_bay)
268     {
269     struct pa_4e8e_data *data;
270     int i;
271    
272     /* Allocate the private data structure for the PA-8E */
273     if (!(data = malloc(sizeof(*data)))) {
274     fprintf(stderr,"%s (PA-8E): out of memory\n",name);
275     return(-1);
276     }
277    
278     /* 4 Ethernet ports */
279     memset(data,0,sizeof(*data));
280     data->nr_port = 8;
281    
282     /* Set the EEPROM */
283     c7200_pa_set_eeprom(router,pa_bay,&eeprom_c7200_pa_8e);
284    
285     /* Create the AMD Am79c971 chips */
286     for(i=0;i<data->nr_port;i++) {
287     data->port[i] = dev_am79c971_init(router->vm,name,AM79C971_TYPE_10BASE_T,
288     router->pa_bay[pa_bay].pci_map,i,
289     C7200_NETIO_IRQ);
290     }
291    
292     /* Store device info into the router structure */
293     return(c7200_pa_set_drvinfo(router,pa_bay,data));
294     }
295    
296     /* Remove a PA-4E/PA-8E from the specified slot */
297     static int dev_c7200_pa_4e8e_shutdown(c7200_t *router,u_int pa_bay)
298     {
299     struct c7200_pa_bay *bay;
300     struct pa_4e8e_data *data;
301     int i;
302    
303     if (!(bay = c7200_pa_get_info(router,pa_bay)))
304     return(-1);
305    
306     data = bay->drv_info;
307    
308     /* Remove the PA EEPROM */
309     c7200_pa_unset_eeprom(router,pa_bay);
310    
311     /* Remove the AMD Am79c971 chips */
312     for(i=0;i<data->nr_port;i++)
313     dev_am79c971_remove(data->port[i]);
314    
315     free(data);
316     return(0);
317     }
318    
319     /* Bind a Network IO descriptor */
320     static int dev_c7200_pa_4e8e_set_nio(c7200_t *router,u_int pa_bay,
321     u_int port_id,netio_desc_t *nio)
322     {
323     struct pa_4e8e_data *d;
324    
325     d = c7200_pa_get_drvinfo(router,pa_bay);
326    
327     if (!d || (port_id >= d->nr_port))
328     return(-1);
329    
330     dev_am79c971_set_nio(d->port[port_id],nio);
331     return(0);
332     }
333    
334     /* Unbind a Network IO descriptor */
335     static int dev_c7200_pa_4e8e_unset_nio(c7200_t *router,u_int pa_bay,
336     u_int port_id)
337     {
338     struct pa_4e8e_data *d;
339    
340     d = c7200_pa_get_drvinfo(router,pa_bay);
341    
342     if (!d || (port_id >= d->nr_port))
343     return(-1);
344    
345     dev_am79c971_unset_nio(d->port[port_id]);
346     return(0);
347     }
348    
349     /* PA-4E driver */
350     struct c7200_pa_driver dev_c7200_pa_4e_driver = {
351     "PA-4E", 1,
352     dev_c7200_pa_4e_init,
353     dev_c7200_pa_4e8e_shutdown,
354     dev_c7200_pa_4e8e_set_nio,
355     dev_c7200_pa_4e8e_unset_nio,
356     };
357    
358     /* PA-8E driver */
359     struct c7200_pa_driver dev_c7200_pa_8e_driver = {
360     "PA-8E", 1,
361     dev_c7200_pa_8e_init,
362     dev_c7200_pa_4e8e_shutdown,
363     dev_c7200_pa_4e8e_set_nio,
364     dev_c7200_pa_4e8e_unset_nio,
365     };

  ViewVC Help
Powered by ViewVC 1.1.26