/[dynamips]/trunk/dev_c2691_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_c2691_eth.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 11 - (hide annotations)
Sat Oct 6 16:33:40 2007 UTC (16 years, 6 months ago) by dpavlin
Original Path: upstream/dynamips-0.2.8-RC1/dev_c2691_eth.c
File MIME type: text/plain
File size: 8463 byte(s)
dynamips-0.2.8-RC1

1 dpavlin 4 /*
2     * Cisco C2691 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_gt.h"
24     #include "dev_c2691.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_c2691_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     /* 3 integrated WIC slots */
39     if ((port_id & 0x0F) >= 3)
40     return(-1);
41    
42     *drv_array = dev_c2691_mb_wic_drivers;
43     *subcard_type = CISCO_CARD_TYPE_WIC;
44     return(0);
45     }
46    
47 dpavlin 4 /*
48     * dev_c2691_nm_eth_init()
49     *
50     * Add an Ethernet Network Module into specified slot.
51     */
52 dpavlin 11 static int dev_c2691_nm_eth_init(vm_instance_t *vm,struct cisco_card *card,
53 dpavlin 4 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 4 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 4 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 4 /* Set the EEPROM */
73 dpavlin 11 cisco_card_set_eeprom(vm,card,eeprom);
74     c2691_set_slot_eeprom(VM_C2691(vm),slot,&card->eeprom);
75 dpavlin 4
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,6+i,
80     c2691_net_irq_for_slot_port(slot,i));
81 dpavlin 4 }
82    
83     /* Store device info into the router structure */
84 dpavlin 11 card->drv_info = data;
85     return(0);
86 dpavlin 4 }
87    
88     /* Remove an Ethernet NM from the specified slot */
89 dpavlin 11 static int dev_c2691_nm_eth_shutdown(vm_instance_t *vm,struct cisco_card *card)
90 dpavlin 4 {
91 dpavlin 11 struct nm_eth_data *data = card->drv_info;
92 dpavlin 4 int i;
93    
94     /* Remove the NM EEPROM */
95 dpavlin 11 cisco_card_unset_eeprom(card);
96     c2691_set_slot_eeprom(VM_C2691(vm),card->slot_id,NULL);
97 dpavlin 4
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_c2691_nm_eth_set_nio(vm_instance_t *vm,struct cisco_card *card,
108 dpavlin 4 u_int port_id,netio_desc_t *nio)
109     {
110 dpavlin 11 struct nm_eth_data *d = card->drv_info;
111 dpavlin 4
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_c2691_nm_eth_unset_nio(vm_instance_t *vm,
121     struct cisco_card *card,
122 dpavlin 4 u_int port_id)
123     {
124 dpavlin 11 struct nm_eth_data *d = card->drv_info;
125 dpavlin 4
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 dpavlin 11
134 dpavlin 4 /* ====================================================================== */
135     /* NM-1FE-TX */
136     /* ====================================================================== */
137    
138     /*
139     * dev_c2691_nm_1fe_tx_init()
140     *
141     * Add a NM-1FE-TX Network Module into specified slot.
142     */
143 dpavlin 11 static int dev_c2691_nm_1fe_tx_init(vm_instance_t *vm,struct cisco_card *card)
144 dpavlin 4 {
145 dpavlin 11 return(dev_c2691_nm_eth_init(vm,card,1,AM79C971_TYPE_100BASE_TX,
146 dpavlin 4 cisco_eeprom_find_nm("NM-1FE-TX")));
147     }
148    
149     /* ====================================================================== */
150     /* NM-16ESW */
151     /* ====================================================================== */
152    
153     /* Add a NM-16ESW */
154 dpavlin 11 static int dev_c2691_nm_16esw_init(vm_instance_t *vm,struct cisco_card *card)
155 dpavlin 4 {
156     struct nm_16esw_data *data;
157 dpavlin 11 u_int slot = card->slot_id;
158 dpavlin 4
159 dpavlin 11 /* Set the PCI bus */
160     card->pci_bus = vm->slots_pci_bus[slot];
161    
162 dpavlin 4 /* Set the EEPROM */
163 dpavlin 11 cisco_card_set_eeprom(vm,card,cisco_eeprom_find_nm("NM-16ESW"));
164     dev_nm_16esw_burn_mac_addr(vm,slot,&card->eeprom);
165     c2691_set_slot_eeprom(VM_C2691(vm),slot,&card->eeprom);
166 dpavlin 4
167     /* Create the device */
168 dpavlin 11 data = dev_nm_16esw_init(vm,card->dev_name,slot,
169     card->pci_bus,6,
170     c2691_net_irq_for_slot_port(slot,0));
171 dpavlin 4
172     /* Store device info into the router structure */
173 dpavlin 11 card->drv_info = data;
174     return(0);
175 dpavlin 4 }
176    
177     /* Remove a NM-16ESW from the specified slot */
178 dpavlin 11 static int
179     dev_c2691_nm_16esw_shutdown(vm_instance_t *vm,struct cisco_card *card)
180 dpavlin 4 {
181 dpavlin 11 struct nm_16esw_data *data = card->drv_info;
182 dpavlin 4
183     /* Remove the NM EEPROM */
184 dpavlin 11 cisco_card_unset_eeprom(card);
185     c2691_set_slot_eeprom(VM_C2691(vm),card->slot_id,NULL);
186 dpavlin 4
187     /* Remove the BCM5600 chip */
188     dev_nm_16esw_remove(data);
189     return(0);
190     }
191    
192     /* Bind a Network IO descriptor */
193 dpavlin 11 static int
194     dev_c2691_nm_16esw_set_nio(vm_instance_t *vm,struct cisco_card *card,
195     u_int port_id,netio_desc_t *nio)
196 dpavlin 4 {
197 dpavlin 11 struct nm_16esw_data *d = card->drv_info;
198 dpavlin 4 dev_nm_16esw_set_nio(d,port_id,nio);
199     return(0);
200     }
201    
202     /* Unbind a Network IO descriptor */
203 dpavlin 11 static int dev_c2691_nm_16esw_unset_nio(vm_instance_t *vm,
204     struct cisco_card *card,
205 dpavlin 4 u_int port_id)
206     {
207 dpavlin 11 struct nm_16esw_data *d = card->drv_info;
208 dpavlin 4 dev_nm_16esw_unset_nio(d,port_id);
209     return(0);
210     }
211    
212     /* Show debug info */
213 dpavlin 11 static int
214     dev_c2691_nm_16esw_show_info(vm_instance_t *vm,struct cisco_card *card)
215 dpavlin 4 {
216 dpavlin 11 struct nm_16esw_data *d = card->drv_info;
217 dpavlin 4 dev_nm_16esw_show_info(d);
218     return(0);
219     }
220    
221     /* ====================================================================== */
222     /* GT96100 - Integrated Ethernet ports */
223     /* ====================================================================== */
224    
225     /* Initialize Ethernet part of the GT96100 controller */
226 dpavlin 11 static int dev_c2691_gt96100_fe_init(vm_instance_t *vm,struct cisco_card *card)
227 dpavlin 4 {
228 dpavlin 11 if (card->slot_id != 0) {
229     vm_error(vm,"dev_c2691_gt96100_fe_init: bad slot %u specified.\n",
230     card->slot_id);
231 dpavlin 4 return(-1);
232     }
233    
234     /* Store device info into the router structure */
235 dpavlin 11 card->drv_info = VM_C2691(vm)->gt_data;
236     return(0);
237 dpavlin 4 }
238    
239     /* Nothing to do, we never remove the system controller */
240 dpavlin 11 static int
241     dev_c2691_gt96100_fe_shutdown(vm_instance_t *vm,struct cisco_card *card)
242 dpavlin 4 {
243     return(0);
244     }
245    
246     /* Bind a Network IO descriptor */
247 dpavlin 11 static int
248     dev_c2691_gt96100_fe_set_nio(vm_instance_t *vm,struct cisco_card *card,
249     u_int port_id,netio_desc_t *nio)
250 dpavlin 4 {
251 dpavlin 11 struct gt_data *d = card->drv_info;
252     dev_gt96100_eth_set_nio(d,port_id,nio);
253 dpavlin 4 return(0);
254     }
255    
256     /* Unbind a Network IO descriptor */
257 dpavlin 11 static int dev_c2691_gt96100_fe_unset_nio(vm_instance_t *vm,
258     struct cisco_card *card,
259     u_int port_id)
260 dpavlin 4 {
261 dpavlin 11 struct gt_data *d = card->drv_info;
262     dev_gt96100_eth_unset_nio(d,port_id);
263 dpavlin 4 return(0);
264     }
265    
266     /* ====================================================================== */
267    
268     /* NM-1FE-TX driver */
269 dpavlin 11 struct cisco_card_driver dev_c2691_nm_1fe_tx_driver = {
270 dpavlin 4 "NM-1FE-TX", 1, 0,
271     dev_c2691_nm_1fe_tx_init,
272     dev_c2691_nm_eth_shutdown,
273 dpavlin 11 NULL,
274 dpavlin 4 dev_c2691_nm_eth_set_nio,
275     dev_c2691_nm_eth_unset_nio,
276     NULL,
277     };
278    
279     /* NM-16ESW driver */
280 dpavlin 11 struct cisco_card_driver dev_c2691_nm_16esw_driver = {
281 dpavlin 4 "NM-16ESW", 1, 0,
282     dev_c2691_nm_16esw_init,
283     dev_c2691_nm_16esw_shutdown,
284 dpavlin 11 NULL,
285 dpavlin 4 dev_c2691_nm_16esw_set_nio,
286     dev_c2691_nm_16esw_unset_nio,
287     dev_c2691_nm_16esw_show_info,
288     };
289    
290     /* GT96100 FastEthernet integrated ports */
291 dpavlin 11 struct cisco_card_driver dev_c2691_gt96100_fe_driver = {
292 dpavlin 4 "GT96100-FE", 1, 0,
293     dev_c2691_gt96100_fe_init,
294     dev_c2691_gt96100_fe_shutdown,
295 dpavlin 11 dev_c2691_mb_get_sub_info,
296 dpavlin 4 dev_c2691_gt96100_fe_set_nio,
297     dev_c2691_gt96100_fe_unset_nio,
298     NULL,
299     };

  ViewVC Help
Powered by ViewVC 1.1.26