/[dynamips]/trunk/dev_c3745_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_c3745_eth.c

Parent Directory Parent Directory | Revision Log Revision Log


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

1 dpavlin 4 /*
2     * Cisco C3745 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_c3745.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_c3745_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_c3745_mb_wic_drivers;
43     *subcard_type = CISCO_CARD_TYPE_WIC;
44     return(0);
45     }
46    
47 dpavlin 4 /*
48     * dev_c3745_nm_eth_init()
49     *
50     * Add an Ethernet Network Module into specified slot.
51     */
52 dpavlin 11 static int dev_c3745_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     c3745_set_slot_eeprom(VM_C3745(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,0,
80     c3745_net_irq_for_slot_port(slot,0));
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_c3745_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     c3745_set_slot_eeprom(VM_C3745(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_c3745_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_c3745_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     /* ====================================================================== */
134     /* NM-1FE-TX */
135     /* ====================================================================== */
136    
137     /*
138     * dev_c3745_nm_1fe_tx_init()
139     *
140     * Add a NM-1FE-TX Network Module into specified slot.
141     */
142 dpavlin 11 static int dev_c3745_nm_1fe_tx_init(vm_instance_t *vm,struct cisco_card *card)
143 dpavlin 4 {
144 dpavlin 11 return(dev_c3745_nm_eth_init(vm,card,1,AM79C971_TYPE_100BASE_TX,
145 dpavlin 4 cisco_eeprom_find_nm("NM-1FE-TX")));
146     }
147    
148     /* ====================================================================== */
149     /* NM-16ESW */
150     /* ====================================================================== */
151    
152     /* Add a NM-16ESW */
153 dpavlin 11 static int dev_c3745_nm_16esw_init(vm_instance_t *vm,struct cisco_card *card)
154 dpavlin 4 {
155     struct nm_16esw_data *data;
156 dpavlin 11 u_int slot = card->slot_id;
157 dpavlin 4
158 dpavlin 11 /* Set the PCI bus */
159     card->pci_bus = vm->slots_pci_bus[slot];
160    
161 dpavlin 4 /* Set the EEPROM */
162 dpavlin 11 cisco_card_set_eeprom(vm,card,cisco_eeprom_find_nm("NM-16ESW"));
163     dev_nm_16esw_burn_mac_addr(vm,slot,&card->eeprom);
164     c3745_set_slot_eeprom(VM_C3745(vm),slot,&card->eeprom);
165 dpavlin 4
166     /* Create the device */
167 dpavlin 11 data = dev_nm_16esw_init(vm,card->dev_name,slot,card->pci_bus,0,
168     c3745_net_irq_for_slot_port(slot,0));
169 dpavlin 4
170     /* Store device info into the router structure */
171 dpavlin 11 card->drv_info = data;
172     return(0);
173 dpavlin 4 }
174    
175     /* Remove a NM-16ESW from the specified slot */
176 dpavlin 11 static int
177     dev_c3745_nm_16esw_shutdown(vm_instance_t *vm,struct cisco_card *card)
178 dpavlin 4 {
179 dpavlin 11 struct nm_16esw_data *data = card->drv_info;
180 dpavlin 4
181     /* Remove the NM EEPROM */
182 dpavlin 11 cisco_card_unset_eeprom(card);
183     c3745_set_slot_eeprom(VM_C3745(vm),card->slot_id,NULL);
184 dpavlin 4
185     /* Remove the BCM5600 chip */
186     dev_nm_16esw_remove(data);
187     return(0);
188     }
189    
190     /* Bind a Network IO descriptor */
191 dpavlin 11 static int
192     dev_c3745_nm_16esw_set_nio(vm_instance_t *vm,struct cisco_card *card,
193     u_int port_id,netio_desc_t *nio)
194 dpavlin 4 {
195 dpavlin 11 struct nm_16esw_data *d = card->drv_info;
196 dpavlin 4 dev_nm_16esw_set_nio(d,port_id,nio);
197     return(0);
198     }
199    
200     /* Unbind a Network IO descriptor */
201 dpavlin 11 static int dev_c3745_nm_16esw_unset_nio(vm_instance_t *vm,
202     struct cisco_card *card,
203 dpavlin 4 u_int port_id)
204     {
205 dpavlin 11 struct nm_16esw_data *d = card->drv_info;
206 dpavlin 4 dev_nm_16esw_unset_nio(d,port_id);
207     return(0);
208     }
209    
210     /* Show debug info */
211 dpavlin 11 static int
212     dev_c3745_nm_16esw_show_info(vm_instance_t *vm,struct cisco_card *card)
213 dpavlin 4 {
214 dpavlin 11 struct nm_16esw_data *d = card->drv_info;
215 dpavlin 4 dev_nm_16esw_show_info(d);
216     return(0);
217     }
218    
219     /* ====================================================================== */
220     /* GT96100 - Integrated Ethernet ports */
221     /* ====================================================================== */
222    
223     /* Initialize Ethernet part of the GT96100 controller */
224 dpavlin 11 static int dev_c3745_gt96100_fe_init(vm_instance_t *vm,struct cisco_card *card)
225 dpavlin 4 {
226 dpavlin 11 if (card->slot_id != 0) {
227     vm_error(vm,"dev_c3745_gt96100_fe_init: bad slot %u specified.\n",
228     card->slot_id);
229 dpavlin 4 return(-1);
230     }
231    
232     /* Store device info into the router structure */
233 dpavlin 11 card->drv_info = VM_C3745(vm)->gt_data;
234     return(0);
235 dpavlin 4 }
236    
237     /* Nothing to do, we never remove the system controller */
238 dpavlin 11 static int
239     dev_c3745_gt96100_fe_shutdown(vm_instance_t *vm,struct cisco_card *card)
240 dpavlin 4 {
241     return(0);
242     }
243    
244     /* Bind a Network IO descriptor */
245 dpavlin 11 static int
246     dev_c3745_gt96100_fe_set_nio(vm_instance_t *vm,struct cisco_card *card,
247     u_int port_id,netio_desc_t *nio)
248 dpavlin 4 {
249 dpavlin 11 struct gt_data *d = card->drv_info;
250     dev_gt96100_eth_set_nio(d,port_id,nio);
251 dpavlin 4 return(0);
252     }
253    
254     /* Unbind a Network IO descriptor */
255 dpavlin 11 static int dev_c3745_gt96100_fe_unset_nio(vm_instance_t *vm,
256     struct cisco_card *card,
257     u_int port_id)
258 dpavlin 4 {
259 dpavlin 11 struct gt_data *d = card->drv_info;
260     dev_gt96100_eth_unset_nio(d,port_id);
261 dpavlin 4 return(0);
262     }
263    
264     /* ====================================================================== */
265    
266     /* NM-1FE-TX driver */
267 dpavlin 11 struct cisco_card_driver dev_c3745_nm_1fe_tx_driver = {
268 dpavlin 4 "NM-1FE-TX", 1, 0,
269     dev_c3745_nm_1fe_tx_init,
270     dev_c3745_nm_eth_shutdown,
271 dpavlin 11 NULL,
272 dpavlin 4 dev_c3745_nm_eth_set_nio,
273     dev_c3745_nm_eth_unset_nio,
274     NULL,
275     };
276    
277     /* NM-16ESW driver */
278 dpavlin 11 struct cisco_card_driver dev_c3745_nm_16esw_driver = {
279 dpavlin 4 "NM-16ESW", 1, 0,
280     dev_c3745_nm_16esw_init,
281     dev_c3745_nm_16esw_shutdown,
282 dpavlin 11 NULL,
283 dpavlin 4 dev_c3745_nm_16esw_set_nio,
284     dev_c3745_nm_16esw_unset_nio,
285     dev_c3745_nm_16esw_show_info,
286     };
287    
288     /* GT96100 FastEthernet integrated ports */
289 dpavlin 11 struct cisco_card_driver dev_c3745_gt96100_fe_driver = {
290 dpavlin 4 "GT96100-FE", 1, 0,
291     dev_c3745_gt96100_fe_init,
292     dev_c3745_gt96100_fe_shutdown,
293 dpavlin 11 dev_c3745_mb_get_sub_info,
294 dpavlin 4 dev_c3745_gt96100_fe_set_nio,
295     dev_c3745_gt96100_fe_unset_nio,
296     NULL,
297     };

  ViewVC Help
Powered by ViewVC 1.1.26