/[dynamips]/trunk/dev_c2600_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_c2600_eth.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 12 - (show annotations)
Sat Oct 6 16:45:40 2007 UTC (16 years, 5 months ago) by dpavlin
File MIME type: text/plain
File size: 10934 byte(s)
make working copy

1 /*
2 * Cisco router 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 "vm.h"
22 #include "dev_am79c971.h"
23 #include "dev_nm_16esw.h"
24 #include "dev_c2600.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 /* Return sub-slot info for integrated WIC slots (on motherboard) */
33 static int dev_c2600_mb_get_sub_info(vm_instance_t *vm,struct cisco_card *card,
34 u_int port_id,
35 struct cisco_card_driver ***drv_array,
36 u_int *subcard_type)
37 {
38 /* 2 integrated WIC slots */
39 if ((port_id & 0x0F) >= 2)
40 return(-1);
41
42 *drv_array = dev_c2600_mb_wic_drivers;
43 *subcard_type = CISCO_CARD_TYPE_WIC;
44 return(0);
45 }
46
47 /*
48 * dev_c2600_nm_eth_init()
49 *
50 * Add an Ethernet Network Module into specified slot.
51 */
52 static int dev_c2600_nm_eth_init(vm_instance_t *vm,struct cisco_card *card,
53 int nr_port,int interface_type,
54 const struct cisco_eeprom *eeprom)
55 {
56 struct nm_eth_data *data;
57 u_int slot = card->slot_id;
58 int i;
59
60 /* Allocate the private data structure */
61 if (!(data = malloc(sizeof(*data)))) {
62 vm_error(vm,"%s: out of memory.\n",card->dev_name);
63 return(-1);
64 }
65
66 memset(data,0,sizeof(*data));
67 data->nr_port = nr_port;
68
69 /* Set the PCI bus */
70 card->pci_bus = vm->slots_pci_bus[slot];
71
72 /* Set the EEPROM */
73 cisco_card_set_eeprom(vm,card,eeprom);
74 c2600_set_slot_eeprom(VM_C2600(vm),slot,&card->eeprom);
75
76 /* Create the AMD Am971c971 chip(s) */
77 for(i=0;i<data->nr_port;i++) {
78 data->port[i] = dev_am79c971_init(vm,card->dev_name,interface_type,
79 card->pci_bus,i+(slot * 4),
80 c2600_net_irq_for_slot_port(slot,i));
81 }
82
83 /* Store device info into the router structure */
84 card->drv_info = data;
85 return(0);
86 }
87
88 /* Remove an Ethernet NM from the specified slot */
89 static int dev_c2600_nm_eth_shutdown(vm_instance_t *vm,struct cisco_card *card)
90 {
91 struct nm_eth_data *data = card->drv_info;
92 int i;
93
94 /* Remove the NM EEPROM */
95 cisco_card_unset_eeprom(card);
96 c2600_set_slot_eeprom(VM_C2600(vm),card->slot_id,NULL);
97
98 /* Remove the AMD Am79c971 chips */
99 for(i=0;i<data->nr_port;i++)
100 dev_am79c971_remove(data->port[i]);
101
102 free(data);
103 return(0);
104 }
105
106 /* Bind a Network IO descriptor */
107 static int dev_c2600_nm_eth_set_nio(vm_instance_t *vm,struct cisco_card *card,
108 u_int port_id,netio_desc_t *nio)
109 {
110 struct nm_eth_data *d = card->drv_info;
111
112 if (!d || (port_id >= d->nr_port))
113 return(-1);
114
115 dev_am79c971_set_nio(d->port[port_id],nio);
116 return(0);
117 }
118
119 /* Unbind a Network IO descriptor */
120 static int dev_c2600_nm_eth_unset_nio(vm_instance_t *vm,
121 struct cisco_card *card,
122 u_int port_id)
123 {
124 struct nm_eth_data *d = card->drv_info;
125
126 if (!d || (port_id >= d->nr_port))
127 return(-1);
128
129 dev_am79c971_unset_nio(d->port[port_id]);
130 return(0);
131 }
132
133 /* ====================================================================== */
134 /* Cisco 2600 mainboard with 1 Ethernet port */
135 /* ====================================================================== */
136
137 static int dev_c2600_mb1e_eth_init(vm_instance_t *vm,struct cisco_card *card)
138 {
139 return(dev_c2600_nm_eth_init(vm,card,1,AM79C971_TYPE_10BASE_T,NULL));
140 }
141
142 /* ====================================================================== */
143 /* Cisco 2600 mainboard with 1 Ethernet port */
144 /* ====================================================================== */
145 static int dev_c2600_mb2e_eth_init(vm_instance_t *vm,struct cisco_card *card)
146 {
147 return(dev_c2600_nm_eth_init(vm,card,2,AM79C971_TYPE_10BASE_T,NULL));
148 }
149
150 /* ====================================================================== */
151 /* Cisco 2600 mainboard with 1 FastEthernet port */
152 /* ====================================================================== */
153 static int dev_c2600_mb1fe_eth_init(vm_instance_t *vm,struct cisco_card *card)
154 {
155 return(dev_c2600_nm_eth_init(vm,card,1,AM79C971_TYPE_100BASE_TX,NULL));
156 }
157
158 /* ====================================================================== */
159 /* Cisco 2600 mainboard with 2 FastEthernet ports */
160 /* ====================================================================== */
161 static int dev_c2600_mb2fe_eth_init(vm_instance_t *vm,struct cisco_card *card)
162 {
163 return(dev_c2600_nm_eth_init(vm,card,2,AM79C971_TYPE_100BASE_TX,NULL));
164 }
165
166 /* ====================================================================== */
167 /* NM-1E */
168 /* ====================================================================== */
169
170 /*
171 * dev_c2600_nm_1e_init()
172 *
173 * Add a NM-1E Network Module into specified slot.
174 */
175 static int dev_c2600_nm_1e_init(vm_instance_t *vm,struct cisco_card *card)
176 {
177 return(dev_c2600_nm_eth_init(vm,card,1,AM79C971_TYPE_10BASE_T,
178 cisco_eeprom_find_nm("NM-1E")));
179 }
180
181 /* ====================================================================== */
182 /* NM-4E */
183 /* ====================================================================== */
184
185 /*
186 * dev_c2600_nm_4e_init()
187 *
188 * Add a NM-4E Network Module into specified slot.
189 */
190 static int dev_c2600_nm_4e_init(vm_instance_t *vm,struct cisco_card *card)
191 {
192 return(dev_c2600_nm_eth_init(vm,card,4,AM79C971_TYPE_10BASE_T,
193 cisco_eeprom_find_nm("NM-4E")));
194 }
195
196 /* ====================================================================== */
197 /* NM-1FE-TX */
198 /* ====================================================================== */
199
200 /*
201 * dev_c2600_nm_1fe_tx_init()
202 *
203 * Add a NM-1FE-TX Network Module into specified slot.
204 */
205 static int dev_c2600_nm_1fe_tx_init(vm_instance_t *vm,struct cisco_card *card)
206 {
207 return(dev_c2600_nm_eth_init(vm,card,1,AM79C971_TYPE_100BASE_TX,
208 cisco_eeprom_find_nm("NM-1FE-TX")));
209 }
210
211 /* ====================================================================== */
212 /* NM-16ESW */
213 /* ====================================================================== */
214
215 /* Add a NM-16ESW */
216 static int dev_c2600_nm_16esw_init(vm_instance_t *vm,struct cisco_card *card)
217 {
218 struct nm_16esw_data *data;
219 u_int slot = card->slot_id;
220
221 /* Set the PCI bus */
222 card->pci_bus = vm->slots_pci_bus[slot];
223
224 /* Set the EEPROM */
225 cisco_card_set_eeprom(vm,card,cisco_eeprom_find_nm("NM-16ESW"));
226 dev_nm_16esw_burn_mac_addr(vm,slot,&card->eeprom);
227 c2600_set_slot_eeprom(VM_C2600(vm),slot,&card->eeprom);
228
229 /* Create the device */
230 data = dev_nm_16esw_init(vm,card->dev_name,slot,card->pci_bus,4,
231 c2600_net_irq_for_slot_port(slot,0));
232
233 /* Store device info into the router structure */
234 card->drv_info = data;
235 return(0);
236 }
237
238 /* Remove a NM-16ESW from the specified slot */
239 static int
240 dev_c2600_nm_16esw_shutdown(vm_instance_t *vm,struct cisco_card *card)
241 {
242 struct nm_16esw_data *data = card->drv_info;
243
244 /* Remove the NM EEPROM */
245 cisco_card_unset_eeprom(card);
246 c2600_set_slot_eeprom(VM_C2600(vm),card->slot_id,NULL);
247
248 /* Remove the BCM5600 chip */
249 dev_nm_16esw_remove(data);
250 return(0);
251 }
252
253 /* Bind a Network IO descriptor */
254 static int
255 dev_c2600_nm_16esw_set_nio(vm_instance_t *vm,struct cisco_card *card,
256 u_int port_id,netio_desc_t *nio)
257 {
258 struct nm_16esw_data *d = card->drv_info;
259 dev_nm_16esw_set_nio(d,port_id,nio);
260 return(0);
261 }
262
263 /* Unbind a Network IO descriptor */
264 static int
265 dev_c2600_nm_16esw_unset_nio(vm_instance_t *vm,struct cisco_card *card,
266 u_int port_id)
267 {
268 struct nm_16esw_data *d = card->drv_info;
269 dev_nm_16esw_unset_nio(d,port_id);
270 return(0);
271 }
272
273 /* Show debug info */
274 static int
275 dev_c2600_nm_16esw_show_info(vm_instance_t *vm,struct cisco_card *card)
276 {
277 struct nm_16esw_data *d = card->drv_info;
278 dev_nm_16esw_show_info(d);
279 return(0);
280 }
281
282 /* ====================================================================== */
283
284 /* Cisco 2600 mainboard 1 Ethernet port driver */
285 struct cisco_card_driver dev_c2600_mb1e_eth_driver = {
286 "CISCO2600-MB-1E", 1, 2,
287 dev_c2600_mb1e_eth_init,
288 dev_c2600_nm_eth_shutdown,
289 dev_c2600_mb_get_sub_info,
290 dev_c2600_nm_eth_set_nio,
291 dev_c2600_nm_eth_unset_nio,
292 NULL,
293 };
294
295 /* Cisco 2600 mainboard 2 Ethernet port driver */
296 struct cisco_card_driver dev_c2600_mb2e_eth_driver = {
297 "CISCO2600-MB-2E", 1, 2,
298 dev_c2600_mb2e_eth_init,
299 dev_c2600_nm_eth_shutdown,
300 dev_c2600_mb_get_sub_info,
301 dev_c2600_nm_eth_set_nio,
302 dev_c2600_nm_eth_unset_nio,
303 NULL,
304 };
305
306 /* Cisco 2600 mainboard 1 FastEthernet port driver */
307 struct cisco_card_driver dev_c2600_mb1fe_eth_driver = {
308 "CISCO2600-MB-1FE", 1, 2,
309 dev_c2600_mb1fe_eth_init,
310 dev_c2600_nm_eth_shutdown,
311 dev_c2600_mb_get_sub_info,
312 dev_c2600_nm_eth_set_nio,
313 dev_c2600_nm_eth_unset_nio,
314 NULL,
315 };
316
317 /* Cisco 2600 mainboard 2 Ethernet port driver */
318 struct cisco_card_driver dev_c2600_mb2fe_eth_driver = {
319 "CISCO2600-MB-2FE", 1, 2,
320 dev_c2600_mb2fe_eth_init,
321 dev_c2600_nm_eth_shutdown,
322 dev_c2600_mb_get_sub_info,
323 dev_c2600_nm_eth_set_nio,
324 dev_c2600_nm_eth_unset_nio,
325 NULL,
326 };
327
328 /* NM-1FE-TX driver */
329 struct cisco_card_driver dev_c2600_nm_1fe_tx_driver = {
330 "NM-1FE-TX", 1, 0,
331 dev_c2600_nm_1fe_tx_init,
332 dev_c2600_nm_eth_shutdown,
333 NULL,
334 dev_c2600_nm_eth_set_nio,
335 dev_c2600_nm_eth_unset_nio,
336 NULL,
337 };
338
339 /* NM-1E driver */
340 struct cisco_card_driver dev_c2600_nm_1e_driver = {
341 "NM-1E", 1, 0,
342 dev_c2600_nm_1e_init,
343 dev_c2600_nm_eth_shutdown,
344 NULL,
345 dev_c2600_nm_eth_set_nio,
346 dev_c2600_nm_eth_unset_nio,
347 NULL,
348 };
349
350 /* NM-4E driver */
351 struct cisco_card_driver dev_c2600_nm_4e_driver = {
352 "NM-4E", 1, 0,
353 dev_c2600_nm_4e_init,
354 dev_c2600_nm_eth_shutdown,
355 NULL,
356 dev_c2600_nm_eth_set_nio,
357 dev_c2600_nm_eth_unset_nio,
358 NULL,
359 };
360
361 /* NM-16ESW driver */
362 struct cisco_card_driver dev_c2600_nm_16esw_driver = {
363 "NM-16ESW", 1, 0,
364 dev_c2600_nm_16esw_init,
365 dev_c2600_nm_16esw_shutdown,
366 NULL,
367 dev_c2600_nm_16esw_set_nio,
368 dev_c2600_nm_16esw_unset_nio,
369 dev_c2600_nm_16esw_show_info,
370 };

  ViewVC Help
Powered by ViewVC 1.1.26