/[dynamips]/trunk/dev_c3600_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 /trunk/dev_c3600_eth.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 8 - (hide annotations)
Sat Oct 6 16:24:54 2007 UTC (16 years, 6 months ago) by dpavlin
Original Path: upstream/dynamips-0.2.7-RC2/dev_c3600_eth.c
File MIME type: text/plain
File size: 10125 byte(s)
dynamips-0.2.7-RC2

1 dpavlin 1 /*
2 dpavlin 2 * Cisco C3600 simulation platform.
3 dpavlin 1 * 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 dpavlin 4 #include "dev_nm_16esw.h"
23 dpavlin 1 #include "dev_c3600.h"
24     #include "dev_c3600_bay.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_c3600_nm_eth_init()
34     *
35     * Add an Ethernet Network Module into specified slot.
36     */
37     static int dev_c3600_nm_eth_init(c3600_t *router,char *name,u_int nm_bay,
38     int nr_port,int interface_type,
39 dpavlin 3 const struct cisco_eeprom *eeprom)
40 dpavlin 1 {
41     struct nm_bay_info *bay_info;
42     struct nm_eth_data *data;
43     int i;
44    
45     /* Allocate the private data structure */
46     if (!(data = malloc(sizeof(*data)))) {
47     fprintf(stderr,"%s: out of memory\n",name);
48     return(-1);
49     }
50    
51     memset(data,0,sizeof(*data));
52     data->nr_port = nr_port;
53    
54     /* Set the EEPROM */
55     c3600_nm_set_eeprom(router,nm_bay,eeprom);
56    
57     /* Get PCI bus info about this bay */
58     bay_info = c3600_nm_get_bay_info(c3600_chassis_get_id(router),nm_bay);
59    
60     if (!bay_info) {
61     fprintf(stderr,"%s: unable to get info for NM bay %u\n",name,nm_bay);
62     return(-1);
63     }
64    
65     /* Create the AMD Am971c971 chip(s) */
66     for(i=0;i<data->nr_port;i++) {
67     data->port[i] = dev_am79c971_init(router->vm,name,interface_type,
68     router->nm_bay[nm_bay].pci_map,
69     bay_info->pci_device + i,
70 dpavlin 8 c3600_net_irq_for_slot_port(nm_bay,i));
71 dpavlin 1 }
72    
73     /* Store device info into the router structure */
74     return(c3600_nm_set_drvinfo(router,nm_bay,data));
75     }
76    
77     /* Remove an Ethernet NM from the specified slot */
78     static int dev_c3600_nm_eth_shutdown(c3600_t *router,u_int nm_bay)
79     {
80     struct c3600_nm_bay *bay;
81     struct nm_eth_data *data;
82     int i;
83    
84     if (!(bay = c3600_nm_get_info(router,nm_bay)))
85     return(-1);
86    
87     data = bay->drv_info;
88    
89     /* Remove the NM EEPROM */
90     c3600_nm_unset_eeprom(router,nm_bay);
91    
92     /* Remove the AMD Am79c971 chips */
93     for(i=0;i<data->nr_port;i++)
94     dev_am79c971_remove(data->port[i]);
95    
96     free(data);
97     return(0);
98     }
99    
100     /* Bind a Network IO descriptor */
101     static int dev_c3600_nm_eth_set_nio(c3600_t *router,u_int nm_bay,
102     u_int port_id,netio_desc_t *nio)
103     {
104     struct nm_eth_data *d;
105    
106     d = c3600_nm_get_drvinfo(router,nm_bay);
107    
108     if (!d || (port_id >= d->nr_port))
109     return(-1);
110    
111     dev_am79c971_set_nio(d->port[port_id],nio);
112     return(0);
113     }
114    
115     /* Unbind a Network IO descriptor */
116     static int dev_c3600_nm_eth_unset_nio(c3600_t *router,u_int nm_bay,
117     u_int port_id)
118     {
119     struct nm_eth_data *d;
120    
121     d = c3600_nm_get_drvinfo(router,nm_bay);
122    
123     if (!d || (port_id >= d->nr_port))
124     return(-1);
125    
126     dev_am79c971_unset_nio(d->port[port_id]);
127     return(0);
128     }
129    
130     /* ====================================================================== */
131     /* NM-1E */
132     /* ====================================================================== */
133    
134     /*
135     * dev_c3600_nm_1e_init()
136     *
137     * Add a NM-1E Network Module into specified slot.
138     */
139     static int dev_c3600_nm_1e_init(c3600_t *router,char *name,u_int nm_bay)
140     {
141     return(dev_c3600_nm_eth_init(router,name,nm_bay,1,AM79C971_TYPE_10BASE_T,
142 dpavlin 3 cisco_eeprom_find_nm("NM-1E")));
143 dpavlin 1 }
144    
145     /* ====================================================================== */
146     /* NM-4E */
147     /* ====================================================================== */
148    
149     /*
150     * dev_c3600_nm_4e_init()
151     *
152     * Add a NM-4E Network Module into specified slot.
153     */
154     static int dev_c3600_nm_4e_init(c3600_t *router,char *name,u_int nm_bay)
155     {
156     return(dev_c3600_nm_eth_init(router,name,nm_bay,4,AM79C971_TYPE_10BASE_T,
157 dpavlin 3 cisco_eeprom_find_nm("NM-4E")));
158 dpavlin 1 }
159    
160     /* ====================================================================== */
161     /* NM-1FE-TX */
162     /* ====================================================================== */
163    
164     /*
165     * dev_c3600_nm_1fe_tx_init()
166     *
167     * Add a NM-1FE-TX Network Module into specified slot.
168     */
169     static int dev_c3600_nm_1fe_tx_init(c3600_t *router,char *name,u_int nm_bay)
170     {
171     return(dev_c3600_nm_eth_init(router,name,nm_bay,1,AM79C971_TYPE_100BASE_TX,
172 dpavlin 3 cisco_eeprom_find_nm("NM-1FE-TX")));
173 dpavlin 1 }
174    
175     /* ====================================================================== */
176 dpavlin 4 /* NM-16ESW */
177     /* ====================================================================== */
178    
179     /* Add a NM-16ESW */
180     static int dev_c3600_nm_16esw_init(c3600_t *router,char *name,u_int nm_bay)
181     {
182     struct nm_bay_info *bay_info;
183     struct nm_16esw_data *data;
184    
185     /* Set the EEPROM */
186     c3600_nm_set_eeprom(router,nm_bay,cisco_eeprom_find_nm("NM-16ESW"));
187     dev_nm_16esw_burn_mac_addr(router->vm,nm_bay,
188     &router->nm_bay[nm_bay].eeprom);
189    
190     /* Get PCI bus info about this bay */
191     bay_info = c3600_nm_get_bay_info(c3600_chassis_get_id(router),nm_bay);
192    
193     if (!bay_info) {
194     fprintf(stderr,"%s: unable to get info for NM bay %u\n",name,nm_bay);
195     return(-1);
196     }
197    
198     /* Create the device */
199     data = dev_nm_16esw_init(router->vm,name,nm_bay,
200     router->nm_bay[nm_bay].pci_map,
201 dpavlin 8 bay_info->pci_device,
202     c3600_net_irq_for_slot_port(nm_bay,0));
203 dpavlin 4
204     /* Store device info into the router structure */
205     return(c3600_nm_set_drvinfo(router,nm_bay,data));
206     }
207    
208     /* Remove a NM-16ESW from the specified slot */
209     static int dev_c3600_nm_16esw_shutdown(c3600_t *router,u_int nm_bay)
210     {
211     struct c3600_nm_bay *bay;
212     struct nm_16esw_data *data;
213    
214     if (!(bay = c3600_nm_get_info(router,nm_bay)))
215     return(-1);
216    
217     data = bay->drv_info;
218    
219     /* Remove the NM EEPROM */
220     c3600_nm_unset_eeprom(router,nm_bay);
221    
222     /* Remove the BCM5600 chip */
223     dev_nm_16esw_remove(data);
224     return(0);
225     }
226    
227     /* Bind a Network IO descriptor */
228     static int dev_c3600_nm_16esw_set_nio(c3600_t *router,u_int nm_bay,
229     u_int port_id,netio_desc_t *nio)
230     {
231     struct nm_16esw_data *d;
232    
233     d = c3600_nm_get_drvinfo(router,nm_bay);
234     dev_nm_16esw_set_nio(d,port_id,nio);
235     return(0);
236     }
237    
238     /* Unbind a Network IO descriptor */
239     static int dev_c3600_nm_16esw_unset_nio(c3600_t *router,u_int nm_bay,
240     u_int port_id)
241     {
242     struct nm_16esw_data *d;
243    
244     d = c3600_nm_get_drvinfo(router,nm_bay);
245     dev_nm_16esw_unset_nio(d,port_id);
246     return(0);
247     }
248    
249     /* Show debug info */
250     static int dev_c3600_nm_16esw_show_info(c3600_t *router,u_int nm_bay)
251     {
252     struct nm_16esw_data *d;
253    
254     d = c3600_nm_get_drvinfo(router,nm_bay);
255     dev_nm_16esw_show_info(d);
256     return(0);
257     }
258    
259     /* ====================================================================== */
260 dpavlin 1 /* Leopard-2FE */
261     /* ====================================================================== */
262    
263     /*
264     * Leopard-2FE: 2 FastEthernet ports on C3660 motherboard.
265     *
266     * Leopard-2FE is the FRU/Product Number displayed by "show diag".
267     */
268     static m_uint16_t eeprom_c3600_leopard_2fe_data[] = {
269     0x04FF, 0xC18B, 0x4A41, 0x4230, 0x3530, 0x3330, 0x3454, 0x3809,
270     0x3440, 0x00B3, 0xC046, 0x0320, 0x0012, 0x8104, 0x4241, 0x3085,
271     0x1C0C, 0xA202, 0x80FF, 0xFFFF, 0xFFC4, 0x08FF, 0xFFFF, 0xFFFF,
272     0xFFFF, 0xFFA1, 0xFFFF, 0xFFFF, 0x03FF, 0x04FF, 0xC508, 0xFFFF,
273     0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
274     0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
275     0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
276     0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFF00,
277     };
278    
279 dpavlin 3 static const struct cisco_eeprom eeprom_c3600_leopard_2fe = {
280 dpavlin 1 "Leopard-2FE", (m_uint16_t *)eeprom_c3600_leopard_2fe_data,
281     sizeof(eeprom_c3600_leopard_2fe_data)/2,
282     };
283    
284     /*
285     * dev_c3600_leopard_2fe_init()
286     *
287     * Add Leopard-2FE (only Cisco 3660, in slot 0).
288     */
289     static int dev_c3600_leopard_2fe_init(c3600_t *router,char *name,u_int nm_bay)
290     {
291     if (nm_bay != 0) {
292     fprintf(stderr,"C3600 %s: Leopard-2FE can only be put in slot 0\n",
293     router->vm->name);
294     return(-1);
295     }
296    
297     return(dev_c3600_nm_eth_init(router,name,0,2,AM79C971_TYPE_100BASE_TX,
298     &eeprom_c3600_leopard_2fe));
299     }
300    
301     /* ====================================================================== */
302    
303     /* NM-1FE-TX driver */
304     struct c3600_nm_driver dev_c3600_nm_1fe_tx_driver = {
305     "NM-1FE-TX", 1, 0,
306     dev_c3600_nm_1fe_tx_init,
307     dev_c3600_nm_eth_shutdown,
308     dev_c3600_nm_eth_set_nio,
309     dev_c3600_nm_eth_unset_nio,
310 dpavlin 2 NULL,
311 dpavlin 1 };
312    
313     /* NM-1E driver */
314     struct c3600_nm_driver dev_c3600_nm_1e_driver = {
315     "NM-1E", 1, 0,
316     dev_c3600_nm_1e_init,
317     dev_c3600_nm_eth_shutdown,
318     dev_c3600_nm_eth_set_nio,
319     dev_c3600_nm_eth_unset_nio,
320 dpavlin 2 NULL,
321 dpavlin 1 };
322    
323     /* NM-4E driver */
324     struct c3600_nm_driver dev_c3600_nm_4e_driver = {
325     "NM-4E", 1, 0,
326     dev_c3600_nm_4e_init,
327     dev_c3600_nm_eth_shutdown,
328     dev_c3600_nm_eth_set_nio,
329     dev_c3600_nm_eth_unset_nio,
330 dpavlin 2 NULL,
331 dpavlin 1 };
332    
333 dpavlin 4 /* NM-16ESW driver */
334     struct c3600_nm_driver dev_c3600_nm_16esw_driver = {
335     "NM-16ESW", 1, 0,
336     dev_c3600_nm_16esw_init,
337     dev_c3600_nm_16esw_shutdown,
338     dev_c3600_nm_16esw_set_nio,
339     dev_c3600_nm_16esw_unset_nio,
340     dev_c3600_nm_16esw_show_info,
341     };
342    
343 dpavlin 1 /* Leopard-2FE driver */
344     struct c3600_nm_driver dev_c3600_leopard_2fe_driver = {
345     "Leopard-2FE", 1, 0,
346     dev_c3600_leopard_2fe_init,
347     dev_c3600_nm_eth_shutdown,
348     dev_c3600_nm_eth_set_nio,
349     dev_c3600_nm_eth_unset_nio,
350 dpavlin 2 NULL,
351 dpavlin 1 };

  ViewVC Help
Powered by ViewVC 1.1.26