/[dynamips]/upstream/dynamips-0.2.6-RC2/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 /upstream/dynamips-0.2.6-RC2/dev_c3600_eth.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3 - (hide annotations)
Sat Oct 6 16:05:34 2007 UTC (16 years, 6 months ago) by dpavlin
File MIME type: text/plain
File size: 7365 byte(s)
dynamips-0.2.6-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     #include "dev_c3600.h"
23     #include "dev_c3600_bay.h"
24    
25     /* Multi-Ethernet NM with Am79c971 chips */
26     struct nm_eth_data {
27     u_int nr_port;
28     struct am79c971_data *port[8];
29     };
30    
31     /*
32     * dev_c3600_nm_eth_init()
33     *
34     * Add an Ethernet Network Module into specified slot.
35     */
36     static int dev_c3600_nm_eth_init(c3600_t *router,char *name,u_int nm_bay,
37     int nr_port,int interface_type,
38 dpavlin 3 const struct cisco_eeprom *eeprom)
39 dpavlin 1 {
40     struct nm_bay_info *bay_info;
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     c3600_nm_set_eeprom(router,nm_bay,eeprom);
55    
56     /* Get PCI bus info about this bay */
57     bay_info = c3600_nm_get_bay_info(c3600_chassis_get_id(router),nm_bay);
58    
59     if (!bay_info) {
60     fprintf(stderr,"%s: unable to get info for NM bay %u\n",name,nm_bay);
61     return(-1);
62     }
63    
64     /* Create the AMD Am971c971 chip(s) */
65     for(i=0;i<data->nr_port;i++) {
66     data->port[i] = dev_am79c971_init(router->vm,name,interface_type,
67     router->nm_bay[nm_bay].pci_map,
68     bay_info->pci_device + i,
69     C3600_NETIO_IRQ);
70     }
71    
72     /* Store device info into the router structure */
73     return(c3600_nm_set_drvinfo(router,nm_bay,data));
74     }
75    
76     /* Remove an Ethernet NM from the specified slot */
77     static int dev_c3600_nm_eth_shutdown(c3600_t *router,u_int nm_bay)
78     {
79     struct c3600_nm_bay *bay;
80     struct nm_eth_data *data;
81     int i;
82    
83     if (!(bay = c3600_nm_get_info(router,nm_bay)))
84     return(-1);
85    
86     data = bay->drv_info;
87    
88     /* Remove the NM EEPROM */
89     c3600_nm_unset_eeprom(router,nm_bay);
90    
91     /* Remove the AMD Am79c971 chips */
92     for(i=0;i<data->nr_port;i++)
93     dev_am79c971_remove(data->port[i]);
94    
95     free(data);
96     return(0);
97     }
98    
99     /* Bind a Network IO descriptor */
100     static int dev_c3600_nm_eth_set_nio(c3600_t *router,u_int nm_bay,
101     u_int port_id,netio_desc_t *nio)
102     {
103     struct nm_eth_data *d;
104    
105     d = c3600_nm_get_drvinfo(router,nm_bay);
106    
107     if (!d || (port_id >= d->nr_port))
108     return(-1);
109    
110     dev_am79c971_set_nio(d->port[port_id],nio);
111     return(0);
112     }
113    
114     /* Unbind a Network IO descriptor */
115     static int dev_c3600_nm_eth_unset_nio(c3600_t *router,u_int nm_bay,
116     u_int port_id)
117     {
118     struct nm_eth_data *d;
119    
120     d = c3600_nm_get_drvinfo(router,nm_bay);
121    
122     if (!d || (port_id >= d->nr_port))
123     return(-1);
124    
125     dev_am79c971_unset_nio(d->port[port_id]);
126     return(0);
127     }
128    
129     /* ====================================================================== */
130     /* NM-1E */
131     /* ====================================================================== */
132    
133     /*
134     * dev_c3600_nm_1e_init()
135     *
136     * Add a NM-1E Network Module into specified slot.
137     */
138     static int dev_c3600_nm_1e_init(c3600_t *router,char *name,u_int nm_bay)
139     {
140     return(dev_c3600_nm_eth_init(router,name,nm_bay,1,AM79C971_TYPE_10BASE_T,
141 dpavlin 3 cisco_eeprom_find_nm("NM-1E")));
142 dpavlin 1 }
143    
144     /* ====================================================================== */
145     /* NM-4E */
146     /* ====================================================================== */
147    
148     /*
149     * dev_c3600_nm_4e_init()
150     *
151     * Add a NM-4E Network Module into specified slot.
152     */
153     static int dev_c3600_nm_4e_init(c3600_t *router,char *name,u_int nm_bay)
154     {
155     return(dev_c3600_nm_eth_init(router,name,nm_bay,4,AM79C971_TYPE_10BASE_T,
156 dpavlin 3 cisco_eeprom_find_nm("NM-4E")));
157 dpavlin 1 }
158    
159     /* ====================================================================== */
160     /* NM-1FE-TX */
161     /* ====================================================================== */
162    
163     /*
164     * dev_c3600_nm_1fe_tx_init()
165     *
166     * Add a NM-1FE-TX Network Module into specified slot.
167     */
168     static int dev_c3600_nm_1fe_tx_init(c3600_t *router,char *name,u_int nm_bay)
169     {
170     return(dev_c3600_nm_eth_init(router,name,nm_bay,1,AM79C971_TYPE_100BASE_TX,
171 dpavlin 3 cisco_eeprom_find_nm("NM-1FE-TX")));
172 dpavlin 1 }
173    
174     /* ====================================================================== */
175     /* Leopard-2FE */
176     /* ====================================================================== */
177    
178     /*
179     * Leopard-2FE: 2 FastEthernet ports on C3660 motherboard.
180     *
181     * Leopard-2FE is the FRU/Product Number displayed by "show diag".
182     */
183     static m_uint16_t eeprom_c3600_leopard_2fe_data[] = {
184     0x04FF, 0xC18B, 0x4A41, 0x4230, 0x3530, 0x3330, 0x3454, 0x3809,
185     0x3440, 0x00B3, 0xC046, 0x0320, 0x0012, 0x8104, 0x4241, 0x3085,
186     0x1C0C, 0xA202, 0x80FF, 0xFFFF, 0xFFC4, 0x08FF, 0xFFFF, 0xFFFF,
187     0xFFFF, 0xFFA1, 0xFFFF, 0xFFFF, 0x03FF, 0x04FF, 0xC508, 0xFFFF,
188     0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
189     0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
190     0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
191     0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFF00,
192     };
193    
194 dpavlin 3 static const struct cisco_eeprom eeprom_c3600_leopard_2fe = {
195 dpavlin 1 "Leopard-2FE", (m_uint16_t *)eeprom_c3600_leopard_2fe_data,
196     sizeof(eeprom_c3600_leopard_2fe_data)/2,
197     };
198    
199     /*
200     * dev_c3600_leopard_2fe_init()
201     *
202     * Add Leopard-2FE (only Cisco 3660, in slot 0).
203     */
204     static int dev_c3600_leopard_2fe_init(c3600_t *router,char *name,u_int nm_bay)
205     {
206     if (nm_bay != 0) {
207     fprintf(stderr,"C3600 %s: Leopard-2FE can only be put in slot 0\n",
208     router->vm->name);
209     return(-1);
210     }
211    
212     return(dev_c3600_nm_eth_init(router,name,0,2,AM79C971_TYPE_100BASE_TX,
213     &eeprom_c3600_leopard_2fe));
214     }
215    
216     /* ====================================================================== */
217    
218     /* NM-1FE-TX driver */
219     struct c3600_nm_driver dev_c3600_nm_1fe_tx_driver = {
220     "NM-1FE-TX", 1, 0,
221     dev_c3600_nm_1fe_tx_init,
222     dev_c3600_nm_eth_shutdown,
223     dev_c3600_nm_eth_set_nio,
224     dev_c3600_nm_eth_unset_nio,
225 dpavlin 2 NULL,
226 dpavlin 1 };
227    
228     /* NM-1E driver */
229     struct c3600_nm_driver dev_c3600_nm_1e_driver = {
230     "NM-1E", 1, 0,
231     dev_c3600_nm_1e_init,
232     dev_c3600_nm_eth_shutdown,
233     dev_c3600_nm_eth_set_nio,
234     dev_c3600_nm_eth_unset_nio,
235 dpavlin 2 NULL,
236 dpavlin 1 };
237    
238     /* NM-4E driver */
239     struct c3600_nm_driver dev_c3600_nm_4e_driver = {
240     "NM-4E", 1, 0,
241     dev_c3600_nm_4e_init,
242     dev_c3600_nm_eth_shutdown,
243     dev_c3600_nm_eth_set_nio,
244     dev_c3600_nm_eth_unset_nio,
245 dpavlin 2 NULL,
246 dpavlin 1 };
247    
248     /* Leopard-2FE driver */
249     struct c3600_nm_driver dev_c3600_leopard_2fe_driver = {
250     "Leopard-2FE", 1, 0,
251     dev_c3600_leopard_2fe_init,
252     dev_c3600_nm_eth_shutdown,
253     dev_c3600_nm_eth_set_nio,
254     dev_c3600_nm_eth_unset_nio,
255 dpavlin 2 NULL,
256 dpavlin 1 };

  ViewVC Help
Powered by ViewVC 1.1.26