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

Annotation of /trunk/dev_c2600_eth.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 12 - (hide 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 dpavlin 7 /*
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 dpavlin 11 #include "vm.h"
22 dpavlin 7 #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 dpavlin 11 /* 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 dpavlin 7 /*
48     * dev_c2600_nm_eth_init()
49     *
50     * Add an Ethernet Network Module into specified slot.
51     */
52 dpavlin 11 static int dev_c2600_nm_eth_init(vm_instance_t *vm,struct cisco_card *card,
53 dpavlin 7 int nr_port,int interface_type,
54     const struct cisco_eeprom *eeprom)
55     {
56     struct nm_eth_data *data;
57 dpavlin 11 u_int slot = card->slot_id;
58 dpavlin 7 int i;
59    
60     /* Allocate the private data structure */
61     if (!(data = malloc(sizeof(*data)))) {
62 dpavlin 11 vm_error(vm,"%s: out of memory.\n",card->dev_name);
63 dpavlin 7 return(-1);
64     }
65    
66     memset(data,0,sizeof(*data));
67     data->nr_port = nr_port;
68    
69 dpavlin 11 /* Set the PCI bus */
70     card->pci_bus = vm->slots_pci_bus[slot];
71    
72 dpavlin 7 /* Set the EEPROM */
73 dpavlin 11 cisco_card_set_eeprom(vm,card,eeprom);
74     c2600_set_slot_eeprom(VM_C2600(vm),slot,&card->eeprom);
75 dpavlin 7
76     /* Create the AMD Am971c971 chip(s) */
77     for(i=0;i<data->nr_port;i++) {
78 dpavlin 11 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 dpavlin 7 }
82    
83     /* Store device info into the router structure */
84 dpavlin 11 card->drv_info = data;
85     return(0);
86 dpavlin 7 }
87    
88     /* Remove an Ethernet NM from the specified slot */
89 dpavlin 11 static int dev_c2600_nm_eth_shutdown(vm_instance_t *vm,struct cisco_card *card)
90 dpavlin 7 {
91 dpavlin 11 struct nm_eth_data *data = card->drv_info;
92 dpavlin 7 int i;
93    
94     /* Remove the NM EEPROM */
95 dpavlin 11 cisco_card_unset_eeprom(card);
96     c2600_set_slot_eeprom(VM_C2600(vm),card->slot_id,NULL);
97 dpavlin 7
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 dpavlin 11 static int dev_c2600_nm_eth_set_nio(vm_instance_t *vm,struct cisco_card *card,
108 dpavlin 7 u_int port_id,netio_desc_t *nio)
109     {
110 dpavlin 11 struct nm_eth_data *d = card->drv_info;
111 dpavlin 7
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 dpavlin 11 static int dev_c2600_nm_eth_unset_nio(vm_instance_t *vm,
121     struct cisco_card *card,
122 dpavlin 7 u_int port_id)
123     {
124 dpavlin 11 struct nm_eth_data *d = card->drv_info;
125 dpavlin 7
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 dpavlin 11 static int dev_c2600_mb1e_eth_init(vm_instance_t *vm,struct cisco_card *card)
138 dpavlin 7 {
139 dpavlin 11 return(dev_c2600_nm_eth_init(vm,card,1,AM79C971_TYPE_10BASE_T,NULL));
140 dpavlin 7 }
141    
142     /* ====================================================================== */
143     /* Cisco 2600 mainboard with 1 Ethernet port */
144     /* ====================================================================== */
145 dpavlin 11 static int dev_c2600_mb2e_eth_init(vm_instance_t *vm,struct cisco_card *card)
146 dpavlin 7 {
147 dpavlin 11 return(dev_c2600_nm_eth_init(vm,card,2,AM79C971_TYPE_10BASE_T,NULL));
148 dpavlin 7 }
149    
150     /* ====================================================================== */
151     /* Cisco 2600 mainboard with 1 FastEthernet port */
152     /* ====================================================================== */
153 dpavlin 11 static int dev_c2600_mb1fe_eth_init(vm_instance_t *vm,struct cisco_card *card)
154 dpavlin 7 {
155 dpavlin 11 return(dev_c2600_nm_eth_init(vm,card,1,AM79C971_TYPE_100BASE_TX,NULL));
156 dpavlin 7 }
157    
158     /* ====================================================================== */
159     /* Cisco 2600 mainboard with 2 FastEthernet ports */
160     /* ====================================================================== */
161 dpavlin 11 static int dev_c2600_mb2fe_eth_init(vm_instance_t *vm,struct cisco_card *card)
162 dpavlin 7 {
163 dpavlin 11 return(dev_c2600_nm_eth_init(vm,card,2,AM79C971_TYPE_100BASE_TX,NULL));
164 dpavlin 7 }
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 dpavlin 11 static int dev_c2600_nm_1e_init(vm_instance_t *vm,struct cisco_card *card)
176 dpavlin 7 {
177 dpavlin 11 return(dev_c2600_nm_eth_init(vm,card,1,AM79C971_TYPE_10BASE_T,
178 dpavlin 7 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 dpavlin 11 static int dev_c2600_nm_4e_init(vm_instance_t *vm,struct cisco_card *card)
191 dpavlin 7 {
192 dpavlin 11 return(dev_c2600_nm_eth_init(vm,card,4,AM79C971_TYPE_10BASE_T,
193 dpavlin 7 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 dpavlin 11 static int dev_c2600_nm_1fe_tx_init(vm_instance_t *vm,struct cisco_card *card)
206 dpavlin 7 {
207 dpavlin 11 return(dev_c2600_nm_eth_init(vm,card,1,AM79C971_TYPE_100BASE_TX,
208 dpavlin 7 cisco_eeprom_find_nm("NM-1FE-TX")));
209     }
210    
211     /* ====================================================================== */
212     /* NM-16ESW */
213     /* ====================================================================== */
214    
215     /* Add a NM-16ESW */
216 dpavlin 11 static int dev_c2600_nm_16esw_init(vm_instance_t *vm,struct cisco_card *card)
217 dpavlin 7 {
218     struct nm_16esw_data *data;
219 dpavlin 11 u_int slot = card->slot_id;
220 dpavlin 7
221 dpavlin 11 /* Set the PCI bus */
222     card->pci_bus = vm->slots_pci_bus[slot];
223    
224 dpavlin 7 /* Set the EEPROM */
225 dpavlin 11 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 dpavlin 7
229     /* Create the device */
230 dpavlin 11 data = dev_nm_16esw_init(vm,card->dev_name,slot,card->pci_bus,4,
231     c2600_net_irq_for_slot_port(slot,0));
232 dpavlin 7
233     /* Store device info into the router structure */
234 dpavlin 11 card->drv_info = data;
235     return(0);
236 dpavlin 7 }
237    
238     /* Remove a NM-16ESW from the specified slot */
239 dpavlin 11 static int
240     dev_c2600_nm_16esw_shutdown(vm_instance_t *vm,struct cisco_card *card)
241 dpavlin 7 {
242 dpavlin 11 struct nm_16esw_data *data = card->drv_info;
243 dpavlin 7
244     /* Remove the NM EEPROM */
245 dpavlin 11 cisco_card_unset_eeprom(card);
246     c2600_set_slot_eeprom(VM_C2600(vm),card->slot_id,NULL);
247 dpavlin 7
248     /* Remove the BCM5600 chip */
249     dev_nm_16esw_remove(data);
250     return(0);
251     }
252    
253     /* Bind a Network IO descriptor */
254 dpavlin 11 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 dpavlin 7 {
258 dpavlin 11 struct nm_16esw_data *d = card->drv_info;
259 dpavlin 7 dev_nm_16esw_set_nio(d,port_id,nio);
260     return(0);
261     }
262    
263     /* Unbind a Network IO descriptor */
264 dpavlin 11 static int
265     dev_c2600_nm_16esw_unset_nio(vm_instance_t *vm,struct cisco_card *card,
266     u_int port_id)
267 dpavlin 7 {
268 dpavlin 11 struct nm_16esw_data *d = card->drv_info;
269 dpavlin 7 dev_nm_16esw_unset_nio(d,port_id);
270     return(0);
271     }
272    
273     /* Show debug info */
274 dpavlin 11 static int
275     dev_c2600_nm_16esw_show_info(vm_instance_t *vm,struct cisco_card *card)
276 dpavlin 7 {
277 dpavlin 11 struct nm_16esw_data *d = card->drv_info;
278 dpavlin 7 dev_nm_16esw_show_info(d);
279     return(0);
280     }
281    
282     /* ====================================================================== */
283    
284     /* Cisco 2600 mainboard 1 Ethernet port driver */
285 dpavlin 11 struct cisco_card_driver dev_c2600_mb1e_eth_driver = {
286     "CISCO2600-MB-1E", 1, 2,
287 dpavlin 7 dev_c2600_mb1e_eth_init,
288     dev_c2600_nm_eth_shutdown,
289 dpavlin 11 dev_c2600_mb_get_sub_info,
290 dpavlin 7 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 dpavlin 11 struct cisco_card_driver dev_c2600_mb2e_eth_driver = {
297     "CISCO2600-MB-2E", 1, 2,
298 dpavlin 7 dev_c2600_mb2e_eth_init,
299     dev_c2600_nm_eth_shutdown,
300 dpavlin 11 dev_c2600_mb_get_sub_info,
301 dpavlin 7 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 dpavlin 11 struct cisco_card_driver dev_c2600_mb1fe_eth_driver = {
308     "CISCO2600-MB-1FE", 1, 2,
309 dpavlin 7 dev_c2600_mb1fe_eth_init,
310     dev_c2600_nm_eth_shutdown,
311 dpavlin 11 dev_c2600_mb_get_sub_info,
312 dpavlin 7 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 dpavlin 11 struct cisco_card_driver dev_c2600_mb2fe_eth_driver = {
319     "CISCO2600-MB-2FE", 1, 2,
320 dpavlin 7 dev_c2600_mb2fe_eth_init,
321     dev_c2600_nm_eth_shutdown,
322 dpavlin 11 dev_c2600_mb_get_sub_info,
323 dpavlin 7 dev_c2600_nm_eth_set_nio,
324     dev_c2600_nm_eth_unset_nio,
325     NULL,
326     };
327    
328     /* NM-1FE-TX driver */
329 dpavlin 11 struct cisco_card_driver dev_c2600_nm_1fe_tx_driver = {
330 dpavlin 7 "NM-1FE-TX", 1, 0,
331     dev_c2600_nm_1fe_tx_init,
332     dev_c2600_nm_eth_shutdown,
333 dpavlin 11 NULL,
334 dpavlin 7 dev_c2600_nm_eth_set_nio,
335     dev_c2600_nm_eth_unset_nio,
336     NULL,
337     };
338    
339     /* NM-1E driver */
340 dpavlin 11 struct cisco_card_driver dev_c2600_nm_1e_driver = {
341 dpavlin 7 "NM-1E", 1, 0,
342     dev_c2600_nm_1e_init,
343     dev_c2600_nm_eth_shutdown,
344 dpavlin 11 NULL,
345 dpavlin 7 dev_c2600_nm_eth_set_nio,
346     dev_c2600_nm_eth_unset_nio,
347     NULL,
348     };
349    
350     /* NM-4E driver */
351 dpavlin 11 struct cisco_card_driver dev_c2600_nm_4e_driver = {
352 dpavlin 7 "NM-4E", 1, 0,
353     dev_c2600_nm_4e_init,
354     dev_c2600_nm_eth_shutdown,
355 dpavlin 11 NULL,
356 dpavlin 7 dev_c2600_nm_eth_set_nio,
357     dev_c2600_nm_eth_unset_nio,
358     NULL,
359     };
360    
361     /* NM-16ESW driver */
362 dpavlin 11 struct cisco_card_driver dev_c2600_nm_16esw_driver = {
363 dpavlin 7 "NM-16ESW", 1, 0,
364     dev_c2600_nm_16esw_init,
365     dev_c2600_nm_16esw_shutdown,
366 dpavlin 11 NULL,
367 dpavlin 7 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