/[dynamips]/upstream/dynamips-0.2.6-RC3/dev_c2691_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_c2691_eth.c

Parent Directory Parent Directory | Revision Log Revision Log


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

1 dpavlin 4 /*
2     * Cisco C2691 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_c2691.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_c2691_nm_eth_init()
34     *
35     * Add an Ethernet Network Module into specified slot.
36     */
37     static int dev_c2691_nm_eth_init(c2691_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     c2691_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     6,C2691_NETIO_IRQ);
61     }
62    
63     /* Store device info into the router structure */
64     return(c2691_nm_set_drvinfo(router,nm_bay,data));
65     }
66    
67     /* Remove an Ethernet NM from the specified slot */
68     static int dev_c2691_nm_eth_shutdown(c2691_t *router,u_int nm_bay)
69     {
70     struct c2691_nm_bay *bay;
71     struct nm_eth_data *data;
72     int i;
73    
74     if (!(bay = c2691_nm_get_info(router,nm_bay)))
75     return(-1);
76    
77     data = bay->drv_info;
78    
79     /* Remove the NM EEPROM */
80     c2691_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_c2691_nm_eth_set_nio(c2691_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 = c2691_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_c2691_nm_eth_unset_nio(c2691_t *router,u_int nm_bay,
107     u_int port_id)
108     {
109     struct nm_eth_data *d;
110    
111     d = c2691_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     /* NM-1FE-TX */
122     /* ====================================================================== */
123    
124     /*
125     * dev_c2691_nm_1fe_tx_init()
126     *
127     * Add a NM-1FE-TX Network Module into specified slot.
128     */
129     static int dev_c2691_nm_1fe_tx_init(c2691_t *router,char *name,u_int nm_bay)
130     {
131     return(dev_c2691_nm_eth_init(router,name,nm_bay,1,AM79C971_TYPE_100BASE_TX,
132     cisco_eeprom_find_nm("NM-1FE-TX")));
133     }
134    
135     /* ====================================================================== */
136     /* NM-16ESW */
137     /* ====================================================================== */
138    
139     /* Add a NM-16ESW */
140     static int dev_c2691_nm_16esw_init(c2691_t *router,char *name,u_int nm_bay)
141     {
142     struct nm_16esw_data *data;
143    
144     /* Set the EEPROM */
145     c2691_nm_set_eeprom(router,nm_bay,cisco_eeprom_find_nm("NM-16ESW"));
146     dev_nm_16esw_burn_mac_addr(router->vm,nm_bay,
147     &router->nm_bay[nm_bay].eeprom);
148    
149     /* Create the device */
150     data = dev_nm_16esw_init(router->vm,name,nm_bay,
151     router->nm_bay[nm_bay].pci_map,
152     6,C2691_NETIO_IRQ);
153    
154     /* Store device info into the router structure */
155     return(c2691_nm_set_drvinfo(router,nm_bay,data));
156     }
157    
158     /* Remove a NM-16ESW from the specified slot */
159     static int dev_c2691_nm_16esw_shutdown(c2691_t *router,u_int nm_bay)
160     {
161     struct c2691_nm_bay *bay;
162     struct nm_16esw_data *data;
163    
164     if (!(bay = c2691_nm_get_info(router,nm_bay)))
165     return(-1);
166    
167     data = bay->drv_info;
168    
169     /* Remove the NM EEPROM */
170     c2691_nm_unset_eeprom(router,nm_bay);
171    
172     /* Remove the BCM5600 chip */
173     dev_nm_16esw_remove(data);
174     return(0);
175     }
176    
177     /* Bind a Network IO descriptor */
178     static int dev_c2691_nm_16esw_set_nio(c2691_t *router,u_int nm_bay,
179     u_int port_id,netio_desc_t *nio)
180     {
181     struct nm_16esw_data *d;
182    
183     d = c2691_nm_get_drvinfo(router,nm_bay);
184     dev_nm_16esw_set_nio(d,port_id,nio);
185     return(0);
186     }
187    
188     /* Unbind a Network IO descriptor */
189     static int dev_c2691_nm_16esw_unset_nio(c2691_t *router,u_int nm_bay,
190     u_int port_id)
191     {
192     struct nm_16esw_data *d;
193    
194     d = c2691_nm_get_drvinfo(router,nm_bay);
195     dev_nm_16esw_unset_nio(d,port_id);
196     return(0);
197     }
198    
199     /* Show debug info */
200     static int dev_c2691_nm_16esw_show_info(c2691_t *router,u_int nm_bay)
201     {
202     struct nm_16esw_data *d;
203    
204     d = c2691_nm_get_drvinfo(router,nm_bay);
205     dev_nm_16esw_show_info(d);
206     return(0);
207     }
208    
209     /* ====================================================================== */
210     /* GT96100 - Integrated Ethernet ports */
211     /* ====================================================================== */
212    
213     /* Initialize Ethernet part of the GT96100 controller */
214     static int dev_c2691_gt96100_fe_init(c2691_t *router,char *name,u_int nm_bay)
215     {
216     vm_obj_t *obj;
217    
218     if (nm_bay != 0) {
219     fprintf(stderr,"dev_c2691_gt96100_fe_init: bad slot specified.\n");
220     return(-1);
221     }
222    
223     if (!(obj = vm_object_find(router->vm,"gt96100"))) {
224     fprintf(stderr,"dev_c2691_gt96100_fe_init: unable to find "
225     "system controller!\n");
226     return(-1);
227     }
228    
229     /* Store device info into the router structure */
230     return(c2691_nm_set_drvinfo(router,0,obj->data));
231     }
232    
233     /* Nothing to do, we never remove the system controller */
234     static int dev_c2691_gt96100_fe_shutdown(c2691_t *router,u_int nm_bay)
235     {
236     return(0);
237     }
238    
239     /* Bind a Network IO descriptor */
240     static int dev_c2691_gt96100_fe_set_nio(c2691_t *router,u_int nm_bay,
241     u_int port_id,netio_desc_t *nio)
242     {
243     struct gt_data *d;
244    
245     if (!(d = c2691_nm_get_drvinfo(router,nm_bay)))
246     return(-1);
247    
248     dev_gt96100_set_nio(d,port_id,nio);
249     return(0);
250     }
251    
252     /* Unbind a Network IO descriptor */
253     static int dev_c2691_gt96100_fe_unset_nio(c2691_t *router,u_int nm_bay,
254     u_int port_id)
255     {
256     struct gt_data *d;
257    
258     if (!(d = c2691_nm_get_drvinfo(router,nm_bay)))
259     return(-1);
260    
261     dev_gt96100_unset_nio(d,port_id);
262     return(0);
263     }
264    
265     /* ====================================================================== */
266    
267     /* NM-1FE-TX driver */
268     struct c2691_nm_driver dev_c2691_nm_1fe_tx_driver = {
269     "NM-1FE-TX", 1, 0,
270     dev_c2691_nm_1fe_tx_init,
271     dev_c2691_nm_eth_shutdown,
272     dev_c2691_nm_eth_set_nio,
273     dev_c2691_nm_eth_unset_nio,
274     NULL,
275     };
276    
277     /* NM-16ESW driver */
278     struct c2691_nm_driver dev_c2691_nm_16esw_driver = {
279     "NM-16ESW", 1, 0,
280     dev_c2691_nm_16esw_init,
281     dev_c2691_nm_16esw_shutdown,
282     dev_c2691_nm_16esw_set_nio,
283     dev_c2691_nm_16esw_unset_nio,
284     dev_c2691_nm_16esw_show_info,
285     };
286    
287     /* GT96100 FastEthernet integrated ports */
288     struct c2691_nm_driver dev_c2691_gt96100_fe_driver = {
289     "GT96100-FE", 1, 0,
290     dev_c2691_gt96100_fe_init,
291     dev_c2691_gt96100_fe_shutdown,
292     dev_c2691_gt96100_fe_set_nio,
293     dev_c2691_gt96100_fe_unset_nio,
294     NULL,
295     };

  ViewVC Help
Powered by ViewVC 1.1.26