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

Contents of /trunk/dev_c3600_eth.c

Parent Directory Parent Directory | Revision Log Revision Log


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

1 /*
2 * Cisco C3600 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_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 static int dev_c3600_nm_eth_init(vm_instance_t *vm,struct cisco_card *card,
38 int nr_port,int interface_type,
39 const struct cisco_eeprom *eeprom)
40 {
41 struct nm_bay_info *bay_info;
42 struct nm_eth_data *data;
43 u_int slot = card->slot_id;
44 u_int chassis_id;
45 int i;
46
47 /* Allocate the private data structure */
48 if (!(data = malloc(sizeof(*data)))) {
49 vm_error(vm,"%s: out of memory.\n",card->dev_name);
50 return(-1);
51 }
52
53 memset(data,0,sizeof(*data));
54 data->nr_port = nr_port;
55
56 /* Set the PCI bus */
57 card->pci_bus = vm->slots_pci_bus[slot];
58
59 /* Set the EEPROM */
60 cisco_card_set_eeprom(vm,card,eeprom);
61 c3600_set_slot_eeprom(VM_C3600(vm),slot,&card->eeprom);
62
63 /* Get PCI bus info about this bay */
64 chassis_id = c3600_chassis_get_id(VM_C3600(vm));
65 bay_info = c3600_nm_get_bay_info(chassis_id,slot);
66
67 if (!bay_info) {
68 vm_error(vm,"unable to get info for NM bay %u\n",slot);
69 return(-1);
70 }
71
72 /* Create the AMD Am971c971 chip(s) */
73 for(i=0;i<data->nr_port;i++) {
74 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 }
78
79 /* Store device info into the router structure */
80 card->drv_info = data;
81 return(0);
82 }
83
84 /* Remove an Ethernet NM from the specified slot */
85 static int dev_c3600_nm_eth_shutdown(vm_instance_t *vm,struct cisco_card *card)
86 {
87 struct nm_eth_data *data = card->drv_info;
88 int i;
89
90 /* Remove the NM EEPROM */
91 cisco_card_unset_eeprom(card);
92 c3600_set_slot_eeprom(VM_C3600(vm),card->slot_id,NULL);
93
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 static int dev_c3600_nm_eth_set_nio(vm_instance_t *vm,struct cisco_card *card,
104 u_int port_id,netio_desc_t *nio)
105 {
106 struct nm_eth_data *d = card->drv_info;
107
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 static int dev_c3600_nm_eth_unset_nio(vm_instance_t *vm,
117 struct cisco_card *card,
118 u_int port_id)
119 {
120 struct nm_eth_data *d = card->drv_info;
121
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 static int dev_c3600_nm_1e_init(vm_instance_t *vm,struct cisco_card *card)
139 {
140 return(dev_c3600_nm_eth_init(vm,card,1,AM79C971_TYPE_10BASE_T,
141 cisco_eeprom_find_nm("NM-1E")));
142 }
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 static int dev_c3600_nm_4e_init(vm_instance_t *vm,struct cisco_card *card)
154 {
155 return(dev_c3600_nm_eth_init(vm,card,4,AM79C971_TYPE_10BASE_T,
156 cisco_eeprom_find_nm("NM-4E")));
157 }
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 static int dev_c3600_nm_1fe_tx_init(vm_instance_t *vm,struct cisco_card *card)
169 {
170 return(dev_c3600_nm_eth_init(vm,card,1,AM79C971_TYPE_100BASE_TX,
171 cisco_eeprom_find_nm("NM-1FE-TX")));
172 }
173
174 /* ====================================================================== */
175 /* NM-16ESW */
176 /* ====================================================================== */
177
178 /* Add a NM-16ESW */
179 static int dev_c3600_nm_16esw_init(vm_instance_t *vm,struct cisco_card *card)
180 {
181 struct nm_bay_info *bay_info;
182 struct nm_16esw_data *data;
183 u_int slot = card->slot_id;
184 u_int chassis_id;
185
186 /* Set the PCI bus */
187 card->pci_bus = vm->slots_pci_bus[slot];
188
189 /* Set the EEPROM */
190 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
194 /* Get PCI bus info about this bay */
195 chassis_id = c3600_chassis_get_id(VM_C3600(vm));
196 bay_info = c3600_nm_get_bay_info(chassis_id,slot);
197
198 if (!bay_info) {
199 vm_error(vm,"unable to get info for NM bay %u\n",slot);
200 return(-1);
201 }
202
203 /* Create the device */
204 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
208 /* Store device info into the router structure */
209 card->drv_info = data;
210 return(0);
211 }
212
213 /* Remove a NM-16ESW from the specified slot */
214 static int
215 dev_c3600_nm_16esw_shutdown(vm_instance_t *vm,struct cisco_card *card)
216 {
217 struct nm_16esw_data *data = card->drv_info;
218
219 /* Remove the NM EEPROM */
220 cisco_card_unset_eeprom(card);
221 c3600_set_slot_eeprom(VM_C3600(vm),card->slot_id,NULL);
222
223 /* Remove the BCM5600 chip */
224 dev_nm_16esw_remove(data);
225 return(0);
226 }
227
228 /* Bind a Network IO descriptor */
229 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 {
233 struct nm_16esw_data *d = card->drv_info;
234 dev_nm_16esw_set_nio(d,port_id,nio);
235 return(0);
236 }
237
238 /* Unbind a Network IO descriptor */
239 static int dev_c3600_nm_16esw_unset_nio(vm_instance_t *vm,
240 struct cisco_card *card,
241 u_int port_id)
242 {
243 struct nm_16esw_data *d = card->drv_info;
244 dev_nm_16esw_unset_nio(d,port_id);
245 return(0);
246 }
247
248 /* Show debug info */
249 static int
250 dev_c3600_nm_16esw_show_info(vm_instance_t *vm,struct cisco_card *card)
251 {
252 struct nm_16esw_data *d = card->drv_info;
253 dev_nm_16esw_show_info(d);
254 return(0);
255 }
256
257 /* ====================================================================== */
258 /* 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 static const struct cisco_eeprom eeprom_c3600_leopard_2fe = {
278 "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 static int
288 dev_c3600_leopard_2fe_init(vm_instance_t *vm,struct cisco_card *card)
289 {
290 if (card->slot_id != 0) {
291 vm_error(vm,"dev_c3600_leopard_2fe_init: bad slot %u specified.\n",
292 card->slot_id);
293 return(-1);
294 }
295
296 return(dev_c3600_nm_eth_init(vm,card,2,AM79C971_TYPE_100BASE_TX,
297 &eeprom_c3600_leopard_2fe));
298 }
299
300 /* ====================================================================== */
301
302 /* NM-1FE-TX driver */
303 struct cisco_card_driver dev_c3600_nm_1fe_tx_driver = {
304 "NM-1FE-TX", 1, 0,
305 dev_c3600_nm_1fe_tx_init,
306 dev_c3600_nm_eth_shutdown,
307 NULL,
308 dev_c3600_nm_eth_set_nio,
309 dev_c3600_nm_eth_unset_nio,
310 NULL,
311 };
312
313 /* NM-1E driver */
314 struct cisco_card_driver dev_c3600_nm_1e_driver = {
315 "NM-1E", 1, 0,
316 dev_c3600_nm_1e_init,
317 dev_c3600_nm_eth_shutdown,
318 NULL,
319 dev_c3600_nm_eth_set_nio,
320 dev_c3600_nm_eth_unset_nio,
321 NULL,
322 };
323
324 /* NM-4E driver */
325 struct cisco_card_driver dev_c3600_nm_4e_driver = {
326 "NM-4E", 1, 0,
327 dev_c3600_nm_4e_init,
328 dev_c3600_nm_eth_shutdown,
329 NULL,
330 dev_c3600_nm_eth_set_nio,
331 dev_c3600_nm_eth_unset_nio,
332 NULL,
333 };
334
335 /* NM-16ESW driver */
336 struct cisco_card_driver dev_c3600_nm_16esw_driver = {
337 "NM-16ESW", 1, 0,
338 dev_c3600_nm_16esw_init,
339 dev_c3600_nm_16esw_shutdown,
340 NULL,
341 dev_c3600_nm_16esw_set_nio,
342 dev_c3600_nm_16esw_unset_nio,
343 dev_c3600_nm_16esw_show_info,
344 };
345
346 /* Leopard-2FE driver */
347 struct cisco_card_driver dev_c3600_leopard_2fe_driver = {
348 "Leopard-2FE", 1, 0,
349 dev_c3600_leopard_2fe_init,
350 dev_c3600_nm_eth_shutdown,
351 NULL,
352 dev_c3600_nm_eth_set_nio,
353 dev_c3600_nm_eth_unset_nio,
354 NULL,
355 };

  ViewVC Help
Powered by ViewVC 1.1.26