/[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

Contents of /trunk/dev_c3600_eth.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4 - (show annotations)
Sat Oct 6 16:06:49 2007 UTC (16 years, 6 months ago) by dpavlin
Original Path: upstream/dynamips-0.2.6-RC3/dev_c3600_eth.c
File MIME type: text/plain
File size: 10052 byte(s)
dynamips-0.2.6-RC3

1 /*
2 * Cisco C3600 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_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 const struct cisco_eeprom *eeprom)
40 {
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 C3600_NETIO_IRQ);
71 }
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 cisco_eeprom_find_nm("NM-1E")));
143 }
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 cisco_eeprom_find_nm("NM-4E")));
158 }
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 cisco_eeprom_find_nm("NM-1FE-TX")));
173 }
174
175 /* ====================================================================== */
176 /* 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 bay_info->pci_device,C3600_NETIO_IRQ);
202
203 /* Store device info into the router structure */
204 return(c3600_nm_set_drvinfo(router,nm_bay,data));
205 }
206
207 /* Remove a NM-16ESW from the specified slot */
208 static int dev_c3600_nm_16esw_shutdown(c3600_t *router,u_int nm_bay)
209 {
210 struct c3600_nm_bay *bay;
211 struct nm_16esw_data *data;
212
213 if (!(bay = c3600_nm_get_info(router,nm_bay)))
214 return(-1);
215
216 data = bay->drv_info;
217
218 /* Remove the NM EEPROM */
219 c3600_nm_unset_eeprom(router,nm_bay);
220
221 /* Remove the BCM5600 chip */
222 dev_nm_16esw_remove(data);
223 return(0);
224 }
225
226 /* Bind a Network IO descriptor */
227 static int dev_c3600_nm_16esw_set_nio(c3600_t *router,u_int nm_bay,
228 u_int port_id,netio_desc_t *nio)
229 {
230 struct nm_16esw_data *d;
231
232 d = c3600_nm_get_drvinfo(router,nm_bay);
233 dev_nm_16esw_set_nio(d,port_id,nio);
234 return(0);
235 }
236
237 /* Unbind a Network IO descriptor */
238 static int dev_c3600_nm_16esw_unset_nio(c3600_t *router,u_int nm_bay,
239 u_int port_id)
240 {
241 struct nm_16esw_data *d;
242
243 d = c3600_nm_get_drvinfo(router,nm_bay);
244 dev_nm_16esw_unset_nio(d,port_id);
245 return(0);
246 }
247
248 /* Show debug info */
249 static int dev_c3600_nm_16esw_show_info(c3600_t *router,u_int nm_bay)
250 {
251 struct nm_16esw_data *d;
252
253 d = c3600_nm_get_drvinfo(router,nm_bay);
254 dev_nm_16esw_show_info(d);
255 return(0);
256 }
257
258 /* ====================================================================== */
259 /* Leopard-2FE */
260 /* ====================================================================== */
261
262 /*
263 * Leopard-2FE: 2 FastEthernet ports on C3660 motherboard.
264 *
265 * Leopard-2FE is the FRU/Product Number displayed by "show diag".
266 */
267 static m_uint16_t eeprom_c3600_leopard_2fe_data[] = {
268 0x04FF, 0xC18B, 0x4A41, 0x4230, 0x3530, 0x3330, 0x3454, 0x3809,
269 0x3440, 0x00B3, 0xC046, 0x0320, 0x0012, 0x8104, 0x4241, 0x3085,
270 0x1C0C, 0xA202, 0x80FF, 0xFFFF, 0xFFC4, 0x08FF, 0xFFFF, 0xFFFF,
271 0xFFFF, 0xFFA1, 0xFFFF, 0xFFFF, 0x03FF, 0x04FF, 0xC508, 0xFFFF,
272 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 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, 0xFF00,
276 };
277
278 static const struct cisco_eeprom eeprom_c3600_leopard_2fe = {
279 "Leopard-2FE", (m_uint16_t *)eeprom_c3600_leopard_2fe_data,
280 sizeof(eeprom_c3600_leopard_2fe_data)/2,
281 };
282
283 /*
284 * dev_c3600_leopard_2fe_init()
285 *
286 * Add Leopard-2FE (only Cisco 3660, in slot 0).
287 */
288 static int dev_c3600_leopard_2fe_init(c3600_t *router,char *name,u_int nm_bay)
289 {
290 if (nm_bay != 0) {
291 fprintf(stderr,"C3600 %s: Leopard-2FE can only be put in slot 0\n",
292 router->vm->name);
293 return(-1);
294 }
295
296 return(dev_c3600_nm_eth_init(router,name,0,2,AM79C971_TYPE_100BASE_TX,
297 &eeprom_c3600_leopard_2fe));
298 }
299
300 /* ====================================================================== */
301
302 /* NM-1FE-TX driver */
303 struct c3600_nm_driver dev_c3600_nm_1fe_tx_driver = {
304 "NM-1FE-TX", 1, 0,
305 dev_c3600_nm_1fe_tx_init,
306 dev_c3600_nm_eth_shutdown,
307 dev_c3600_nm_eth_set_nio,
308 dev_c3600_nm_eth_unset_nio,
309 NULL,
310 };
311
312 /* NM-1E driver */
313 struct c3600_nm_driver dev_c3600_nm_1e_driver = {
314 "NM-1E", 1, 0,
315 dev_c3600_nm_1e_init,
316 dev_c3600_nm_eth_shutdown,
317 dev_c3600_nm_eth_set_nio,
318 dev_c3600_nm_eth_unset_nio,
319 NULL,
320 };
321
322 /* NM-4E driver */
323 struct c3600_nm_driver dev_c3600_nm_4e_driver = {
324 "NM-4E", 1, 0,
325 dev_c3600_nm_4e_init,
326 dev_c3600_nm_eth_shutdown,
327 dev_c3600_nm_eth_set_nio,
328 dev_c3600_nm_eth_unset_nio,
329 NULL,
330 };
331
332 /* NM-16ESW driver */
333 struct c3600_nm_driver dev_c3600_nm_16esw_driver = {
334 "NM-16ESW", 1, 0,
335 dev_c3600_nm_16esw_init,
336 dev_c3600_nm_16esw_shutdown,
337 dev_c3600_nm_16esw_set_nio,
338 dev_c3600_nm_16esw_unset_nio,
339 dev_c3600_nm_16esw_show_info,
340 };
341
342 /* Leopard-2FE driver */
343 struct c3600_nm_driver dev_c3600_leopard_2fe_driver = {
344 "Leopard-2FE", 1, 0,
345 dev_c3600_leopard_2fe_init,
346 dev_c3600_nm_eth_shutdown,
347 dev_c3600_nm_eth_set_nio,
348 dev_c3600_nm_eth_unset_nio,
349 NULL,
350 };

  ViewVC Help
Powered by ViewVC 1.1.26