/[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 12 - (hide annotations)
Sat Oct 6 16:45:40 2007 UTC (16 years, 6 months ago) by dpavlin
File MIME type: text/plain
File size: 10276 byte(s)
make working copy

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 dpavlin 11 static int dev_c3600_nm_eth_init(vm_instance_t *vm,struct cisco_card *card,
38 dpavlin 1 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 dpavlin 11 u_int slot = card->slot_id;
44     u_int chassis_id;
45 dpavlin 1 int i;
46    
47     /* Allocate the private data structure */
48     if (!(data = malloc(sizeof(*data)))) {
49 dpavlin 11 vm_error(vm,"%s: out of memory.\n",card->dev_name);
50 dpavlin 1 return(-1);
51     }
52    
53     memset(data,0,sizeof(*data));
54     data->nr_port = nr_port;
55    
56 dpavlin 11 /* Set the PCI bus */
57     card->pci_bus = vm->slots_pci_bus[slot];
58    
59 dpavlin 1 /* Set the EEPROM */
60 dpavlin 11 cisco_card_set_eeprom(vm,card,eeprom);
61     c3600_set_slot_eeprom(VM_C3600(vm),slot,&card->eeprom);
62 dpavlin 1
63     /* Get PCI bus info about this bay */
64 dpavlin 11 chassis_id = c3600_chassis_get_id(VM_C3600(vm));
65     bay_info = c3600_nm_get_bay_info(chassis_id,slot);
66 dpavlin 1
67     if (!bay_info) {
68 dpavlin 11 vm_error(vm,"unable to get info for NM bay %u\n",slot);
69 dpavlin 1 return(-1);
70     }
71    
72     /* Create the AMD Am971c971 chip(s) */
73     for(i=0;i<data->nr_port;i++) {
74 dpavlin 11 data->port[i] = dev_am79c971_init(vm,card->dev_name,interface_type,
75     card->pci_bus,bay_info->pci_device+i,
76     c3600_net_irq_for_slot_port(slot,i));
77 dpavlin 1 }
78    
79     /* Store device info into the router structure */
80 dpavlin 11 card->drv_info = data;
81     return(0);
82 dpavlin 1 }
83    
84     /* Remove an Ethernet NM from the specified slot */
85 dpavlin 11 static int dev_c3600_nm_eth_shutdown(vm_instance_t *vm,struct cisco_card *card)
86 dpavlin 1 {
87 dpavlin 11 struct nm_eth_data *data = card->drv_info;
88 dpavlin 1 int i;
89    
90     /* Remove the NM EEPROM */
91 dpavlin 11 cisco_card_unset_eeprom(card);
92     c3600_set_slot_eeprom(VM_C3600(vm),card->slot_id,NULL);
93 dpavlin 1
94     /* Remove the AMD Am79c971 chips */
95     for(i=0;i<data->nr_port;i++)
96     dev_am79c971_remove(data->port[i]);
97    
98     free(data);
99     return(0);
100     }
101    
102     /* Bind a Network IO descriptor */
103 dpavlin 11 static int dev_c3600_nm_eth_set_nio(vm_instance_t *vm,struct cisco_card *card,
104 dpavlin 1 u_int port_id,netio_desc_t *nio)
105     {
106 dpavlin 11 struct nm_eth_data *d = card->drv_info;
107 dpavlin 1
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 dpavlin 11 static int dev_c3600_nm_eth_unset_nio(vm_instance_t *vm,
117     struct cisco_card *card,
118 dpavlin 1 u_int port_id)
119     {
120 dpavlin 11 struct nm_eth_data *d = card->drv_info;
121 dpavlin 1
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 dpavlin 11 static int dev_c3600_nm_1e_init(vm_instance_t *vm,struct cisco_card *card)
139 dpavlin 1 {
140 dpavlin 11 return(dev_c3600_nm_eth_init(vm,card,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 dpavlin 11 static int dev_c3600_nm_4e_init(vm_instance_t *vm,struct cisco_card *card)
154 dpavlin 1 {
155 dpavlin 11 return(dev_c3600_nm_eth_init(vm,card,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 dpavlin 11 static int dev_c3600_nm_1fe_tx_init(vm_instance_t *vm,struct cisco_card *card)
169 dpavlin 1 {
170 dpavlin 11 return(dev_c3600_nm_eth_init(vm,card,1,AM79C971_TYPE_100BASE_TX,
171 dpavlin 3 cisco_eeprom_find_nm("NM-1FE-TX")));
172 dpavlin 1 }
173    
174     /* ====================================================================== */
175 dpavlin 4 /* NM-16ESW */
176     /* ====================================================================== */
177    
178     /* Add a NM-16ESW */
179 dpavlin 11 static int dev_c3600_nm_16esw_init(vm_instance_t *vm,struct cisco_card *card)
180 dpavlin 4 {
181     struct nm_bay_info *bay_info;
182     struct nm_16esw_data *data;
183 dpavlin 11 u_int slot = card->slot_id;
184     u_int chassis_id;
185 dpavlin 4
186 dpavlin 11 /* Set the PCI bus */
187     card->pci_bus = vm->slots_pci_bus[slot];
188    
189 dpavlin 4 /* Set the EEPROM */
190 dpavlin 11 cisco_card_set_eeprom(vm,card,cisco_eeprom_find_nm("NM-16ESW"));
191     dev_nm_16esw_burn_mac_addr(vm,slot,&card->eeprom);
192     c3600_set_slot_eeprom(VM_C3600(vm),slot,&card->eeprom);
193 dpavlin 4
194     /* Get PCI bus info about this bay */
195 dpavlin 11 chassis_id = c3600_chassis_get_id(VM_C3600(vm));
196     bay_info = c3600_nm_get_bay_info(chassis_id,slot);
197 dpavlin 4
198     if (!bay_info) {
199 dpavlin 11 vm_error(vm,"unable to get info for NM bay %u\n",slot);
200 dpavlin 4 return(-1);
201     }
202    
203     /* Create the device */
204 dpavlin 11 data = dev_nm_16esw_init(vm,card->dev_name,slot,
205     card->pci_bus,bay_info->pci_device,
206     c3600_net_irq_for_slot_port(slot,0));
207 dpavlin 4
208     /* Store device info into the router structure */
209 dpavlin 11 card->drv_info = data;
210     return(0);
211 dpavlin 4 }
212    
213     /* Remove a NM-16ESW from the specified slot */
214 dpavlin 11 static int
215     dev_c3600_nm_16esw_shutdown(vm_instance_t *vm,struct cisco_card *card)
216 dpavlin 4 {
217 dpavlin 11 struct nm_16esw_data *data = card->drv_info;
218 dpavlin 4
219     /* Remove the NM EEPROM */
220 dpavlin 11 cisco_card_unset_eeprom(card);
221     c3600_set_slot_eeprom(VM_C3600(vm),card->slot_id,NULL);
222 dpavlin 4
223     /* Remove the BCM5600 chip */
224     dev_nm_16esw_remove(data);
225     return(0);
226     }
227    
228     /* Bind a Network IO descriptor */
229 dpavlin 11 static int
230     dev_c3600_nm_16esw_set_nio(vm_instance_t *vm,struct cisco_card *card,
231     u_int port_id,netio_desc_t *nio)
232 dpavlin 4 {
233 dpavlin 11 struct nm_16esw_data *d = card->drv_info;
234 dpavlin 4 dev_nm_16esw_set_nio(d,port_id,nio);
235     return(0);
236     }
237    
238     /* Unbind a Network IO descriptor */
239 dpavlin 11 static int dev_c3600_nm_16esw_unset_nio(vm_instance_t *vm,
240     struct cisco_card *card,
241 dpavlin 4 u_int port_id)
242     {
243 dpavlin 11 struct nm_16esw_data *d = card->drv_info;
244 dpavlin 4 dev_nm_16esw_unset_nio(d,port_id);
245     return(0);
246     }
247    
248     /* Show debug info */
249 dpavlin 11 static int
250     dev_c3600_nm_16esw_show_info(vm_instance_t *vm,struct cisco_card *card)
251 dpavlin 4 {
252 dpavlin 11 struct nm_16esw_data *d = card->drv_info;
253 dpavlin 4 dev_nm_16esw_show_info(d);
254     return(0);
255     }
256    
257     /* ====================================================================== */
258 dpavlin 1 /* Leopard-2FE */
259     /* ====================================================================== */
260    
261     /*
262     * Leopard-2FE: 2 FastEthernet ports on C3660 motherboard.
263     *
264     * Leopard-2FE is the FRU/Product Number displayed by "show diag".
265     */
266     static m_uint16_t eeprom_c3600_leopard_2fe_data[] = {
267     0x04FF, 0xC18B, 0x4A41, 0x4230, 0x3530, 0x3330, 0x3454, 0x3809,
268     0x3440, 0x00B3, 0xC046, 0x0320, 0x0012, 0x8104, 0x4241, 0x3085,
269     0x1C0C, 0xA202, 0x80FF, 0xFFFF, 0xFFC4, 0x08FF, 0xFFFF, 0xFFFF,
270     0xFFFF, 0xFFA1, 0xFFFF, 0xFFFF, 0x03FF, 0x04FF, 0xC508, 0xFFFF,
271     0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 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, 0xFF00,
275     };
276    
277 dpavlin 3 static const struct cisco_eeprom eeprom_c3600_leopard_2fe = {
278 dpavlin 1 "Leopard-2FE", (m_uint16_t *)eeprom_c3600_leopard_2fe_data,
279     sizeof(eeprom_c3600_leopard_2fe_data)/2,
280     };
281    
282     /*
283     * dev_c3600_leopard_2fe_init()
284     *
285     * Add Leopard-2FE (only Cisco 3660, in slot 0).
286     */
287 dpavlin 11 static int
288     dev_c3600_leopard_2fe_init(vm_instance_t *vm,struct cisco_card *card)
289 dpavlin 1 {
290 dpavlin 11 if (card->slot_id != 0) {
291     vm_error(vm,"dev_c3600_leopard_2fe_init: bad slot %u specified.\n",
292     card->slot_id);
293 dpavlin 1 return(-1);
294     }
295    
296 dpavlin 11 return(dev_c3600_nm_eth_init(vm,card,2,AM79C971_TYPE_100BASE_TX,
297 dpavlin 1 &eeprom_c3600_leopard_2fe));
298     }
299    
300     /* ====================================================================== */
301    
302     /* NM-1FE-TX driver */
303 dpavlin 11 struct cisco_card_driver dev_c3600_nm_1fe_tx_driver = {
304 dpavlin 1 "NM-1FE-TX", 1, 0,
305     dev_c3600_nm_1fe_tx_init,
306     dev_c3600_nm_eth_shutdown,
307 dpavlin 11 NULL,
308 dpavlin 1 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 dpavlin 11 struct cisco_card_driver dev_c3600_nm_1e_driver = {
315 dpavlin 1 "NM-1E", 1, 0,
316     dev_c3600_nm_1e_init,
317     dev_c3600_nm_eth_shutdown,
318 dpavlin 11 NULL,
319 dpavlin 1 dev_c3600_nm_eth_set_nio,
320     dev_c3600_nm_eth_unset_nio,
321 dpavlin 2 NULL,
322 dpavlin 1 };
323    
324     /* NM-4E driver */
325 dpavlin 11 struct cisco_card_driver dev_c3600_nm_4e_driver = {
326 dpavlin 1 "NM-4E", 1, 0,
327     dev_c3600_nm_4e_init,
328     dev_c3600_nm_eth_shutdown,
329 dpavlin 11 NULL,
330 dpavlin 1 dev_c3600_nm_eth_set_nio,
331     dev_c3600_nm_eth_unset_nio,
332 dpavlin 2 NULL,
333 dpavlin 1 };
334    
335 dpavlin 4 /* NM-16ESW driver */
336 dpavlin 11 struct cisco_card_driver dev_c3600_nm_16esw_driver = {
337 dpavlin 4 "NM-16ESW", 1, 0,
338     dev_c3600_nm_16esw_init,
339     dev_c3600_nm_16esw_shutdown,
340 dpavlin 11 NULL,
341 dpavlin 4 dev_c3600_nm_16esw_set_nio,
342     dev_c3600_nm_16esw_unset_nio,
343     dev_c3600_nm_16esw_show_info,
344     };
345    
346 dpavlin 1 /* Leopard-2FE driver */
347 dpavlin 11 struct cisco_card_driver dev_c3600_leopard_2fe_driver = {
348 dpavlin 1 "Leopard-2FE", 1, 0,
349     dev_c3600_leopard_2fe_init,
350     dev_c3600_nm_eth_shutdown,
351 dpavlin 11 NULL,
352 dpavlin 1 dev_c3600_nm_eth_set_nio,
353     dev_c3600_nm_eth_unset_nio,
354 dpavlin 2 NULL,
355 dpavlin 1 };

  ViewVC Help
Powered by ViewVC 1.1.26