/[dynamips]/upstream/dynamips-0.2.6-RC3/dev_c3725_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.6-RC3/dev_c3725_eth.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4 - (hide annotations)
Sat Oct 6 16:06:49 2007 UTC (12 years, 2 months ago) by dpavlin
File MIME type: text/plain
File size: 8057 byte(s)
dynamips-0.2.6-RC3

1 dpavlin 4 /*
2     * Cisco C3725 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_gt.h"
24     #include "dev_c3725.h"
25    
26     /* Multi-Ethernet NM with Am79c971 chips */
27     struct nm_eth_data {
28     u_int nr_port;
29     struct am79c971_data *port[8];
30     };
31    
32     /*
33     * dev_c3725_nm_eth_init()
34     *
35     * Add an Ethernet Network Module into specified slot.
36     */
37     static int dev_c3725_nm_eth_init(c3725_t *router,char *name,u_int nm_bay,
38     int nr_port,int interface_type,
39     const struct cisco_eeprom *eeprom)
40     {
41     struct nm_eth_data *data;
42     int i;
43    
44     /* Allocate the private data structure */
45     if (!(data = malloc(sizeof(*data)))) {
46     fprintf(stderr,"%s: out of memory\n",name);
47     return(-1);
48     }
49    
50     memset(data,0,sizeof(*data));
51     data->nr_port = nr_port;
52    
53     /* Set the EEPROM */
54     c3725_nm_set_eeprom(router,nm_bay,eeprom);
55    
56     /* Create the AMD Am971c971 chip(s) */
57     for(i=0;i<data->nr_port;i++) {
58     data->port[i] = dev_am79c971_init(router->vm,name,interface_type,
59     router->nm_bay[nm_bay].pci_map,
60     c3725_nm_get_pci_device(nm_bay),
61     C3725_NETIO_IRQ);
62     }
63    
64     /* Store device info into the router structure */
65     return(c3725_nm_set_drvinfo(router,nm_bay,data));
66     }
67    
68     /* Remove an Ethernet NM from the specified slot */
69     static int dev_c3725_nm_eth_shutdown(c3725_t *router,u_int nm_bay)
70     {
71     struct c3725_nm_bay *bay;
72     struct nm_eth_data *data;
73     int i;
74    
75     if (!(bay = c3725_nm_get_info(router,nm_bay)))
76     return(-1);
77    
78     data = bay->drv_info;
79    
80     /* Remove the NM EEPROM */
81     c3725_nm_unset_eeprom(router,nm_bay);
82    
83     /* Remove the AMD Am79c971 chips */
84     for(i=0;i<data->nr_port;i++)
85     dev_am79c971_remove(data->port[i]);
86    
87     free(data);
88     return(0);
89     }
90    
91     /* Bind a Network IO descriptor */
92     static int dev_c3725_nm_eth_set_nio(c3725_t *router,u_int nm_bay,
93     u_int port_id,netio_desc_t *nio)
94     {
95     struct nm_eth_data *d;
96    
97     d = c3725_nm_get_drvinfo(router,nm_bay);
98    
99     if (!d || (port_id >= d->nr_port))
100     return(-1);
101    
102     dev_am79c971_set_nio(d->port[port_id],nio);
103     return(0);
104     }
105    
106     /* Unbind a Network IO descriptor */
107     static int dev_c3725_nm_eth_unset_nio(c3725_t *router,u_int nm_bay,
108     u_int port_id)
109     {
110     struct nm_eth_data *d;
111    
112     d = c3725_nm_get_drvinfo(router,nm_bay);
113    
114     if (!d || (port_id >= d->nr_port))
115     return(-1);
116    
117     dev_am79c971_unset_nio(d->port[port_id]);
118     return(0);
119     }
120    
121     /* ====================================================================== */
122     /* NM-1FE-TX */
123     /* ====================================================================== */
124    
125     /*
126     * dev_c3725_nm_1fe_tx_init()
127     *
128     * Add a NM-1FE-TX Network Module into specified slot.
129     */
130     static int dev_c3725_nm_1fe_tx_init(c3725_t *router,char *name,u_int nm_bay)
131     {
132     return(dev_c3725_nm_eth_init(router,name,nm_bay,1,AM79C971_TYPE_100BASE_TX,
133     cisco_eeprom_find_nm("NM-1FE-TX")));
134     }
135    
136     /* ====================================================================== */
137     /* NM-16ESW */
138     /* ====================================================================== */
139    
140     /* Add a NM-16ESW */
141     static int dev_c3725_nm_16esw_init(c3725_t *router,char *name,u_int nm_bay)
142     {
143     struct nm_16esw_data *data;
144    
145     /* Set the EEPROM */
146     c3725_nm_set_eeprom(router,nm_bay,cisco_eeprom_find_nm("NM-16ESW"));
147     dev_nm_16esw_burn_mac_addr(router->vm,nm_bay,
148     &router->nm_bay[nm_bay].eeprom);
149    
150     /* Create the device */
151     data = dev_nm_16esw_init(router->vm,name,nm_bay,
152     router->nm_bay[nm_bay].pci_map,
153     c3725_nm_get_pci_device(nm_bay),
154     C3725_NETIO_IRQ);
155    
156     /* Store device info into the router structure */
157     return(c3725_nm_set_drvinfo(router,nm_bay,data));
158     }
159    
160     /* Remove a NM-16ESW from the specified slot */
161     static int dev_c3725_nm_16esw_shutdown(c3725_t *router,u_int nm_bay)
162     {
163     struct c3725_nm_bay *bay;
164     struct nm_16esw_data *data;
165    
166     if (!(bay = c3725_nm_get_info(router,nm_bay)))
167     return(-1);
168    
169     data = bay->drv_info;
170    
171     /* Remove the NM EEPROM */
172     c3725_nm_unset_eeprom(router,nm_bay);
173    
174     /* Remove the BCM5600 chip */
175     dev_nm_16esw_remove(data);
176     return(0);
177     }
178    
179     /* Bind a Network IO descriptor */
180     static int dev_c3725_nm_16esw_set_nio(c3725_t *router,u_int nm_bay,
181     u_int port_id,netio_desc_t *nio)
182     {
183     struct nm_16esw_data *d;
184    
185     d = c3725_nm_get_drvinfo(router,nm_bay);
186     dev_nm_16esw_set_nio(d,port_id,nio);
187     return(0);
188     }
189    
190     /* Unbind a Network IO descriptor */
191     static int dev_c3725_nm_16esw_unset_nio(c3725_t *router,u_int nm_bay,
192     u_int port_id)
193     {
194     struct nm_16esw_data *d;
195    
196     d = c3725_nm_get_drvinfo(router,nm_bay);
197     dev_nm_16esw_unset_nio(d,port_id);
198     return(0);
199     }
200    
201     /* Show debug info */
202     static int dev_c3725_nm_16esw_show_info(c3725_t *router,u_int nm_bay)
203     {
204     struct nm_16esw_data *d;
205    
206     d = c3725_nm_get_drvinfo(router,nm_bay);
207     dev_nm_16esw_show_info(d);
208     return(0);
209     }
210    
211     /* ====================================================================== */
212     /* GT96100 - Integrated Ethernet ports */
213     /* ====================================================================== */
214    
215     /* Initialize Ethernet part of the GT96100 controller */
216     static int dev_c3725_gt96100_fe_init(c3725_t *router,char *name,u_int nm_bay)
217     {
218     vm_obj_t *obj;
219    
220     if (nm_bay != 0) {
221     fprintf(stderr,"dev_c3725_gt96100_fe_init: bad slot specified.\n");
222     return(-1);
223     }
224    
225     if (!(obj = vm_object_find(router->vm,"gt96100"))) {
226     fprintf(stderr,"dev_c3725_gt96100_fe_init: unable to find "
227     "system controller!\n");
228     return(-1);
229     }
230    
231     /* Store device info into the router structure */
232     return(c3725_nm_set_drvinfo(router,0,obj->data));
233     }
234    
235     /* Nothing to do, we never remove the system controller */
236     static int dev_c3725_gt96100_fe_shutdown(c3725_t *router,u_int nm_bay)
237     {
238     return(0);
239     }
240    
241     /* Bind a Network IO descriptor */
242     static int dev_c3725_gt96100_fe_set_nio(c3725_t *router,u_int nm_bay,
243     u_int port_id,netio_desc_t *nio)
244     {
245     struct gt_data *d;
246    
247     if (!(d = c3725_nm_get_drvinfo(router,nm_bay)))
248     return(-1);
249    
250     dev_gt96100_set_nio(d,port_id,nio);
251     return(0);
252     }
253    
254     /* Unbind a Network IO descriptor */
255     static int dev_c3725_gt96100_fe_unset_nio(c3725_t *router,u_int nm_bay,
256     u_int port_id)
257     {
258     struct gt_data *d;
259    
260     if (!(d = c3725_nm_get_drvinfo(router,nm_bay)))
261     return(-1);
262    
263     dev_gt96100_unset_nio(d,port_id);
264     return(0);
265     }
266    
267     /* ====================================================================== */
268    
269     /* NM-1FE-TX driver */
270     struct c3725_nm_driver dev_c3725_nm_1fe_tx_driver = {
271     "NM-1FE-TX", 1, 0,
272     dev_c3725_nm_1fe_tx_init,
273     dev_c3725_nm_eth_shutdown,
274     dev_c3725_nm_eth_set_nio,
275     dev_c3725_nm_eth_unset_nio,
276     NULL,
277     };
278    
279     /* NM-16ESW driver */
280     struct c3725_nm_driver dev_c3725_nm_16esw_driver = {
281     "NM-16ESW", 1, 0,
282     dev_c3725_nm_16esw_init,
283     dev_c3725_nm_16esw_shutdown,
284     dev_c3725_nm_16esw_set_nio,
285     dev_c3725_nm_16esw_unset_nio,
286     dev_c3725_nm_16esw_show_info,
287     };
288    
289     /* GT96100 FastEthernet integrated ports */
290     struct c3725_nm_driver dev_c3725_gt96100_fe_driver = {
291     "GT96100-FE", 1, 0,
292     dev_c3725_gt96100_fe_init,
293     dev_c3725_gt96100_fe_shutdown,
294     dev_c3725_gt96100_fe_set_nio,
295     dev_c3725_gt96100_fe_unset_nio,
296     NULL,
297     };

  ViewVC Help
Powered by ViewVC 1.1.26