/[dynamips]/trunk/dev_c7200_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_c7200_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: 19350 byte(s)
make working copy

1 dpavlin 1 /*
2 dpavlin 7 * Cisco router simulation platform.
3 dpavlin 1 * Copyright (c) 2005,2006 Christophe Fillot (cf@utc.fr)
4     *
5     * Ethernet Port Adapters.
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_dec21140.h"
23 dpavlin 7 #include "dev_i8254x.h"
24 dpavlin 1 #include "dev_c7200.h"
25    
26     /* ====================================================================== */
27 dpavlin 3 /* C7200-IO-FE EEPROM */
28 dpavlin 1 /* ====================================================================== */
29    
30     /* C7200-IO-FE: C7200 IOCard with one FastEthernet port EEPROM */
31     static const m_uint16_t eeprom_c7200_io_fe_data[16] = {
32     0x0183, 0x010E, 0xffff, 0xffff, 0x490B, 0x8C02, 0x0000, 0x0000,
33     0x5000, 0x0000, 0x9812, 0x2800, 0x00FF, 0xFFFF, 0xFFFF, 0xFFFF,
34     };
35    
36 dpavlin 3 static const struct cisco_eeprom eeprom_c7200_io_fe = {
37 dpavlin 1 "C7200-IO-FE", (m_uint16_t *)eeprom_c7200_io_fe_data,
38     sizeof(eeprom_c7200_io_fe_data)/2,
39     };
40    
41     /*
42     * dev_c7200_iocard_init()
43     *
44     * Add an IOcard into slot 0.
45     */
46 dpavlin 11 static int dev_c7200_iocard_init(vm_instance_t *vm,struct cisco_card *card)
47 dpavlin 1 {
48     struct dec21140_data *data;
49 dpavlin 11 u_int slot = card->slot_id;
50    
51     if (slot != 0) {
52     vm_error(vm,"cannot put IOCARD in PA bay %u!\n",slot);
53 dpavlin 1 return(-1);
54     }
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_c7200_io_fe);
61     c7200_set_slot_eeprom(VM_C7200(vm),slot,&card->eeprom);
62 dpavlin 1
63     /* Create the DEC21140 chip */
64 dpavlin 11 data = dev_dec21140_init(vm,card->dev_name,
65     card->pci_bus,
66     VM_C7200(vm)->npe_driver->dec21140_pci_dev,
67     c7200_net_irq_for_slot_port(slot,0));
68 dpavlin 1 if (!data) return(-1);
69    
70     /* Store device info into the router structure */
71 dpavlin 11 card->drv_info = data;
72     return(0);
73 dpavlin 1 }
74    
75     /* Remove an IOcard from slot 0 */
76 dpavlin 11 static int dev_c7200_iocard_shutdown(vm_instance_t *vm,struct cisco_card *card)
77 dpavlin 1 {
78 dpavlin 11 /* Remove the PA EEPROM */
79     cisco_card_unset_eeprom(card);
80     c7200_set_slot_eeprom(VM_C7200(vm),card->slot_id,NULL);
81 dpavlin 1
82 dpavlin 11 /* Shutdown the DEC21140 */
83     dev_dec21140_remove(card->drv_info);
84 dpavlin 1 return(0);
85     }
86    
87     /* Bind a Network IO descriptor */
88 dpavlin 11 static int dev_c7200_iocard_set_nio(vm_instance_t *vm,struct cisco_card *card,
89     u_int port_id,netio_desc_t *nio)
90 dpavlin 1 {
91 dpavlin 11 struct dec21140_data *d = card->drv_info;
92 dpavlin 1
93 dpavlin 11 if (!d || (port_id > 0))
94 dpavlin 1 return(-1);
95    
96     return(dev_dec21140_set_nio(d,nio));
97     }
98    
99     /* Unbind a Network IO descriptor */
100 dpavlin 11 static int dev_c7200_iocard_unset_nio(vm_instance_t *vm,
101     struct cisco_card *card,
102 dpavlin 1 u_int port_id)
103     {
104 dpavlin 11 struct dec21140_data *d = card->drv_info;
105 dpavlin 1
106 dpavlin 11 if (!d || (port_id > 0))
107 dpavlin 1 return(-1);
108    
109     dev_dec21140_unset_nio(d);
110     return(0);
111     }
112    
113     /*
114     * dev_c7200_pa_fe_tx_init()
115     *
116     * Add a PA-FE-TX port adapter into specified slot.
117     */
118 dpavlin 11 static int dev_c7200_pa_fe_tx_init(vm_instance_t *vm,struct cisco_card *card)
119 dpavlin 1 {
120     struct dec21140_data *data;
121 dpavlin 11 u_int slot = card->slot_id;
122 dpavlin 1
123 dpavlin 11 /* Set the PCI bus */
124     card->pci_bus = vm->slots_pci_bus[slot];
125    
126 dpavlin 1 /* Set the EEPROM */
127 dpavlin 11 cisco_card_set_eeprom(vm,card,cisco_eeprom_find_pa("PA-FE-TX"));
128     c7200_set_slot_eeprom(VM_C7200(vm),slot,&card->eeprom);
129 dpavlin 1
130     /* Create the DEC21140 chip */
131 dpavlin 11 data = dev_dec21140_init(vm,card->dev_name,card->pci_bus,0,
132     c7200_net_irq_for_slot_port(slot,0));
133 dpavlin 1 if (!data) return(-1);
134    
135     /* Store device info into the router structure */
136 dpavlin 11 card->drv_info = data;
137     return(0);
138 dpavlin 1 }
139    
140     /* Remove a PA-FE-TX from the specified slot */
141 dpavlin 11 static int
142     dev_c7200_pa_fe_tx_shutdown(vm_instance_t *vm,struct cisco_card *card)
143 dpavlin 1 {
144 dpavlin 11 /* Remove the PA EEPROM */
145     cisco_card_unset_eeprom(card);
146     c7200_set_slot_eeprom(VM_C7200(vm),card->slot_id,NULL);
147 dpavlin 1
148 dpavlin 11 /* Shutdown the DEC21140 */
149     dev_dec21140_remove(card->drv_info);
150 dpavlin 1 return(0);
151     }
152    
153     /* Bind a Network IO descriptor */
154 dpavlin 11 static int
155     dev_c7200_pa_fe_tx_set_nio(vm_instance_t *vm,struct cisco_card *card,
156     u_int port_id,netio_desc_t *nio)
157 dpavlin 1 {
158 dpavlin 11 struct dec21140_data *d = card->drv_info;
159 dpavlin 1
160 dpavlin 11 if (!d || (port_id > 0))
161 dpavlin 1 return(-1);
162 dpavlin 11
163 dpavlin 1 return(dev_dec21140_set_nio(d,nio));
164     }
165    
166     /* Unbind a Network IO descriptor */
167 dpavlin 11 static int
168     dev_c7200_pa_fe_tx_unset_nio(vm_instance_t *vm,struct cisco_card *card,
169     u_int port_id)
170 dpavlin 1 {
171 dpavlin 11 struct dec21140_data *d = card->drv_info;
172 dpavlin 1
173 dpavlin 11 if (!d || (port_id > 0))
174 dpavlin 1 return(-1);
175    
176     dev_dec21140_unset_nio(d);
177     return(0);
178     }
179    
180     /* C7200-IO-FE driver */
181 dpavlin 11 struct cisco_card_driver dev_c7200_iocard_fe_driver = {
182     "C7200-IO-FE", 1, 0,
183 dpavlin 1 dev_c7200_iocard_init,
184     dev_c7200_iocard_shutdown,
185 dpavlin 11 NULL,
186 dpavlin 1 dev_c7200_iocard_set_nio,
187     dev_c7200_iocard_unset_nio,
188 dpavlin 2 NULL,
189 dpavlin 1 };
190    
191     /* PA-FE-TX driver */
192 dpavlin 11 struct cisco_card_driver dev_c7200_pa_fe_tx_driver = {
193     "PA-FE-TX", 1, 0,
194 dpavlin 1 dev_c7200_pa_fe_tx_init,
195     dev_c7200_pa_fe_tx_shutdown,
196 dpavlin 11 NULL,
197 dpavlin 1 dev_c7200_pa_fe_tx_set_nio,
198     dev_c7200_pa_fe_tx_unset_nio,
199 dpavlin 2 NULL,
200 dpavlin 1 };
201    
202     /* ====================================================================== */
203 dpavlin 7 /* PA based on Intel i8254x chips */
204     /* ====================================================================== */
205    
206     struct pa_i8254x_data {
207     u_int nr_port;
208     struct i8254x_data *port[2];
209     };
210    
211     /* Remove a PA-2FE-TX from the specified slot */
212 dpavlin 11 static int
213     dev_c7200_pa_i8254x_shutdown(vm_instance_t *vm,struct cisco_card *card)
214 dpavlin 7 {
215 dpavlin 11 struct pa_i8254x_data *data = card->drv_info;
216 dpavlin 7 int i;
217    
218     /* Remove the PA EEPROM */
219 dpavlin 11 cisco_card_unset_eeprom(card);
220     c7200_set_slot_eeprom(VM_C7200(vm),card->slot_id,NULL);
221 dpavlin 7
222 dpavlin 11 /* Remove the Intel i2854x chips */
223 dpavlin 7 for(i=0;i<data->nr_port;i++)
224     dev_i8254x_remove(data->port[i]);
225    
226     free(data);
227     return(0);
228     }
229    
230     /* Bind a Network IO descriptor */
231 dpavlin 11 static int
232     dev_c7200_pa_i8254x_set_nio(vm_instance_t *vm,struct cisco_card *card,
233     u_int port_id,netio_desc_t *nio)
234 dpavlin 7 {
235 dpavlin 11 struct pa_i8254x_data *d = card->drv_info;
236 dpavlin 7
237     if (!d || (port_id >= d->nr_port))
238     return(-1);
239    
240     dev_i8254x_set_nio(d->port[port_id],nio);
241     return(0);
242     }
243    
244     /* Unbind a Network IO descriptor */
245 dpavlin 11 static int
246     dev_c7200_pa_i8254x_unset_nio(vm_instance_t *vm,struct cisco_card *card,
247     u_int port_id)
248 dpavlin 7 {
249 dpavlin 11 struct pa_i8254x_data *d = card->drv_info;
250 dpavlin 7
251     if (!d || (port_id >= d->nr_port))
252     return(-1);
253    
254     dev_i8254x_unset_nio(d->port[port_id]);
255     return(0);
256     }
257    
258     /* ====================================================================== */
259     /* PA-2FE-TX */
260     /* ====================================================================== */
261    
262     /*
263     * dev_c7200_pa_2fe_tx_init()
264     *
265     * Add a PA-2FE-TX port adapter into specified slot.
266     */
267 dpavlin 11 static int dev_c7200_pa_2fe_tx_init(vm_instance_t *vm,struct cisco_card *card)
268 dpavlin 7 {
269     struct pa_i8254x_data *data;
270 dpavlin 11 u_int slot = card->slot_id;
271 dpavlin 7 int i;
272    
273     /* Allocate the private data structure for the PA-2FE-TX */
274     if (!(data = malloc(sizeof(*data)))) {
275 dpavlin 11 vm_error(vm,"%s: out of memory\n",card->dev_name);
276 dpavlin 7 return(-1);
277     }
278    
279     /* 2 Ethernet ports */
280     memset(data,0,sizeof(*data));
281     data->nr_port = 2;
282    
283 dpavlin 11 /* Set the PCI bus */
284     card->pci_bus = vm->slots_pci_bus[slot];
285    
286 dpavlin 7 /* Set the EEPROM */
287 dpavlin 11 cisco_card_set_eeprom(vm,card,cisco_eeprom_find_pa("PA-2FE-TX"));
288     c7200_set_slot_eeprom(VM_C7200(vm),slot,&card->eeprom);
289 dpavlin 7
290     /* Create the Intel i8254x chips */
291     for(i=0;i<data->nr_port;i++) {
292 dpavlin 11 data->port[i] = dev_i8254x_init(vm,card->dev_name,0,
293     card->pci_bus,i,
294     c7200_net_irq_for_slot_port(slot,i));
295 dpavlin 7 }
296    
297     /* Store device info into the router structure */
298 dpavlin 11 card->drv_info = data;
299     return(0);
300 dpavlin 7 }
301    
302     /* PA-2FE-TX driver */
303 dpavlin 11 struct cisco_card_driver dev_c7200_pa_2fe_tx_driver = {
304     "PA-2FE-TX", 0, 0,
305 dpavlin 7 dev_c7200_pa_2fe_tx_init,
306     dev_c7200_pa_i8254x_shutdown,
307 dpavlin 11 NULL,
308 dpavlin 7 dev_c7200_pa_i8254x_set_nio,
309     dev_c7200_pa_i8254x_unset_nio,
310     NULL,
311     };
312    
313     /* ====================================================================== */
314     /* PA-GE */
315     /* ====================================================================== */
316    
317     /*
318     * dev_c7200_pa_ge_init()
319     *
320     * Add a PA-GE port adapter into specified slot.
321     */
322 dpavlin 11 static int dev_c7200_pa_ge_init(vm_instance_t *vm,struct cisco_card *card)
323 dpavlin 7 {
324     struct pa_i8254x_data *data;
325 dpavlin 11 u_int slot = card->slot_id;
326 dpavlin 7
327     /* Allocate the private data structure for the PA-2FE-TX */
328     if (!(data = malloc(sizeof(*data)))) {
329 dpavlin 11 vm_error(vm,"%s: out of memory\n",card->dev_name);
330 dpavlin 7 return(-1);
331     }
332    
333     /* 2 Ethernet ports */
334     memset(data,0,sizeof(*data));
335     data->nr_port = 1;
336    
337 dpavlin 11 /* Set the PCI bus */
338     card->pci_bus = vm->slots_pci_bus[slot];
339    
340 dpavlin 7 /* Set the EEPROM */
341 dpavlin 11 cisco_card_set_eeprom(vm,card,cisco_eeprom_find_pa("PA-GE"));
342     c7200_set_slot_eeprom(VM_C7200(vm),slot,&card->eeprom);
343 dpavlin 7
344     /* Create the Intel i8254x chip */
345 dpavlin 11 data->port[0] = dev_i8254x_init(vm,card->dev_name,0,
346     card->pci_bus,0,
347     c7200_net_irq_for_slot_port(slot,0));
348 dpavlin 7
349     /* Store device info into the router structure */
350 dpavlin 11 card->drv_info = data;
351     return(0);
352 dpavlin 7 }
353    
354     /* PA-GE driver */
355 dpavlin 11 struct cisco_card_driver dev_c7200_pa_ge_driver = {
356     "PA-GE", 0, 0,
357 dpavlin 7 dev_c7200_pa_ge_init,
358     dev_c7200_pa_i8254x_shutdown,
359 dpavlin 11 NULL,
360 dpavlin 7 dev_c7200_pa_i8254x_set_nio,
361     dev_c7200_pa_i8254x_unset_nio,
362     NULL,
363     };
364    
365     /* ====================================================================== */
366     /* C7200-IO-2FE */
367     /* ====================================================================== */
368    
369     /* C7200-IO-2FE/E: C7200 IOCard with two FastEthernet ports EEPROM */
370     static const m_uint16_t eeprom_c7200_io_2fe_data[] = {
371     0x04FF, 0x4002, 0x1541, 0x0201, 0xC046, 0x0320, 0x001B, 0xCA06,
372     0x8249, 0x138B, 0x0642, 0x4230, 0xC18B, 0x3030, 0x3030, 0x3030,
373     0x3030, 0x0000, 0x0004, 0x0002, 0x0385, 0x1C0D, 0x7F03, 0xCB8F,
374     0x4337, 0x3230, 0x302D, 0x492F, 0x4F2D, 0x3246, 0x452F, 0x4580,
375     0x0000, 0x0000, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
376     0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
377     0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
378     0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
379     };
380    
381     static const struct cisco_eeprom eeprom_c7200_io_2fe = {
382     "C7200-IO-2FE", (m_uint16_t *)eeprom_c7200_io_2fe_data,
383     sizeof(eeprom_c7200_io_2fe_data)/2,
384     };
385    
386     /*
387     * dev_c7200_pa_2fe_tx_init()
388     *
389     * Add a C7200-IO-2FE/E port adapter into specified slot.
390     */
391 dpavlin 11 static int dev_c7200_iocard_2fe_init(vm_instance_t *vm,struct cisco_card *card)
392 dpavlin 7 {
393     struct pa_i8254x_data *data;
394 dpavlin 11 u_int slot = card->slot_id;
395 dpavlin 7
396     /* Allocate the private data structure for the iocard */
397     if (!(data = malloc(sizeof(*data)))) {
398 dpavlin 11 vm_error(vm,"%s: out of memory\n",card->dev_name);
399 dpavlin 7 return(-1);
400     }
401    
402     /* 2 Ethernet ports */
403     memset(data,0,sizeof(*data));
404     data->nr_port = 2;
405    
406 dpavlin 11 /* Set the PCI bus */
407     card->pci_bus = vm->slots_pci_bus[slot];
408    
409 dpavlin 7 /* Set the EEPROM */
410 dpavlin 11 cisco_card_set_eeprom(vm,card,&eeprom_c7200_io_2fe);
411     c7200_set_slot_eeprom(VM_C7200(vm),slot,&card->eeprom);
412 dpavlin 7
413     /* Port Fa0/0 is on PCI Device 1 */
414 dpavlin 11 data->port[0] = dev_i8254x_init(vm,card->dev_name,0,
415     card->pci_bus,1,
416     c7200_net_irq_for_slot_port(slot,1));
417 dpavlin 7
418     /* Port Fa0/1 is on PCI Device 0 */
419 dpavlin 11 data->port[1] = dev_i8254x_init(vm,card->dev_name,0,
420     card->pci_bus,0,
421     c7200_net_irq_for_slot_port(slot,0));
422 dpavlin 7
423 dpavlin 8 if (!data->port[0] || !data->port[1]) {
424     dev_i8254x_remove(data->port[0]);
425     dev_i8254x_remove(data->port[1]);
426     free(data);
427     return(-1);
428     }
429    
430 dpavlin 7 /* Store device info into the router structure */
431 dpavlin 11 card->drv_info = data;
432     return(0);
433 dpavlin 7 }
434    
435     /* C7200-IO-2FE driver */
436 dpavlin 11 struct cisco_card_driver dev_c7200_iocard_2fe_driver = {
437     "C7200-IO-2FE", 0, 0,
438 dpavlin 7 dev_c7200_iocard_2fe_init,
439     dev_c7200_pa_i8254x_shutdown,
440 dpavlin 11 NULL,
441 dpavlin 7 dev_c7200_pa_i8254x_set_nio,
442     dev_c7200_pa_i8254x_unset_nio,
443     NULL,
444     };
445    
446     /* ====================================================================== */
447     /* C7200-IO-GE-E */
448     /* ====================================================================== */
449    
450     /*
451     * C7200-IO-GE+E: C7200 IOCard with 1 GigatEthernet ports
452     * and 1 Ethernet port EEPROM.
453     */
454     static const m_uint16_t eeprom_c7200_io_ge_e_data[] = {
455     0x04FF, 0x4002, 0x1641, 0x0201, 0xC046, 0x0320, 0x001B, 0xCA06,
456     0x8249, 0x138B, 0x0642, 0x4230, 0xC18B, 0x3030, 0x3030, 0x3030,
457     0x3030, 0x0000, 0x0004, 0x0002, 0x0385, 0x1C0D, 0x7F03, 0xCB8F,
458     0x4337, 0x3230, 0x302D, 0x492F, 0x4F2D, 0x3246, 0x452F, 0x4580,
459     0x0000, 0x0000, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
460     0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
461     0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
462     0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
463     };
464    
465     static const struct cisco_eeprom eeprom_c7200_io_ge_e = {
466     "C7200-IO-GE-E", (m_uint16_t *)eeprom_c7200_io_ge_e_data,
467     sizeof(eeprom_c7200_io_ge_e_data)/2,
468     };
469    
470     /*
471     * dev_c7200_pa_ge_e_tx_init()
472     *
473     * Add a C7200-I/O-GE+E port adapter into specified slot.
474     */
475 dpavlin 11 static int
476     dev_c7200_iocard_ge_e_init(vm_instance_t *vm,struct cisco_card *card)
477 dpavlin 7 {
478     struct pa_i8254x_data *data;
479 dpavlin 11 u_int slot = card->slot_id;
480 dpavlin 7
481     /* Allocate the private data structure for the iocard */
482     if (!(data = malloc(sizeof(*data)))) {
483 dpavlin 11 vm_error(vm,"%s: out of memory\n",card->dev_name);
484 dpavlin 7 return(-1);
485     }
486    
487     /* 2 Ethernet ports */
488     memset(data,0,sizeof(*data));
489     data->nr_port = 2;
490    
491 dpavlin 11 /* Set the PCI bus */
492     card->pci_bus = vm->slots_pci_bus[slot];
493    
494 dpavlin 7 /* Set the EEPROM */
495 dpavlin 11 cisco_card_set_eeprom(vm,card,&eeprom_c7200_io_ge_e);
496     c7200_set_slot_eeprom(VM_C7200(vm),slot,&card->eeprom);
497 dpavlin 7
498     /* Port Gi0/0 is on PCI Device 1 */
499 dpavlin 11 data->port[0] = dev_i8254x_init(vm,card->dev_name,0,
500     card->pci_bus,1,
501     c7200_net_irq_for_slot_port(slot,1));
502 dpavlin 7
503     /* Port e0/0 is on PCI Device 0 */
504 dpavlin 11 data->port[1] = dev_i8254x_init(vm,card->dev_name,0,
505     card->pci_bus,0,
506     c7200_net_irq_for_slot_port(slot,0));
507 dpavlin 7
508     /* Store device info into the router structure */
509 dpavlin 11 card->drv_info = data;
510     return(0);
511 dpavlin 7 }
512    
513     /* C7200-IO-GE-E driver */
514 dpavlin 11 struct cisco_card_driver dev_c7200_iocard_ge_e_driver = {
515     "C7200-IO-GE-E", 0, 0,
516 dpavlin 7 dev_c7200_iocard_ge_e_init,
517     dev_c7200_pa_i8254x_shutdown,
518 dpavlin 11 NULL,
519 dpavlin 7 dev_c7200_pa_i8254x_set_nio,
520     dev_c7200_pa_i8254x_unset_nio,
521     NULL,
522     };
523    
524     /* ====================================================================== */
525 dpavlin 1 /* PA-4E / PA-8E */
526     /* ====================================================================== */
527    
528     /* PA-4E/PA-8E data */
529     struct pa_4e8e_data {
530     u_int nr_port;
531     struct am79c971_data *port[8];
532     };
533    
534     /*
535     * dev_c7200_pa_4e_init()
536     *
537     * Add a PA-4E port adapter into specified slot.
538     */
539 dpavlin 11 static int dev_c7200_pa_4e_init(vm_instance_t *vm,struct cisco_card *card)
540 dpavlin 1 {
541     struct pa_4e8e_data *data;
542 dpavlin 11 u_int slot = card->slot_id;
543 dpavlin 1 int i;
544    
545     /* Allocate the private data structure for the PA-4E */
546     if (!(data = malloc(sizeof(*data)))) {
547 dpavlin 11 vm_error(vm,"%s: out of memory\n",card->dev_name);
548 dpavlin 1 return(-1);
549     }
550    
551     /* 4 Ethernet ports */
552     memset(data,0,sizeof(*data));
553     data->nr_port = 4;
554    
555 dpavlin 11 /* Set the PCI bus */
556     card->pci_bus = vm->slots_pci_bus[slot];
557    
558 dpavlin 1 /* Set the EEPROM */
559 dpavlin 11 cisco_card_set_eeprom(vm,card,cisco_eeprom_find_pa("PA-4E"));
560     c7200_set_slot_eeprom(VM_C7200(vm),slot,&card->eeprom);
561 dpavlin 1
562     /* Create the AMD Am79c971 chips */
563     for(i=0;i<data->nr_port;i++) {
564 dpavlin 11 data->port[i] = dev_am79c971_init(vm,card->dev_name,
565     AM79C971_TYPE_10BASE_T,
566     card->pci_bus,i,
567     c7200_net_irq_for_slot_port(slot,i));
568 dpavlin 1 }
569    
570     /* Store device info into the router structure */
571 dpavlin 11 card->drv_info = data;
572     return(0);
573 dpavlin 1 }
574    
575     /*
576     * dev_c7200_pa_8e_init()
577     *
578     * Add a PA-8E port adapter into specified slot.
579     */
580 dpavlin 11 static int dev_c7200_pa_8e_init(vm_instance_t *vm,struct cisco_card *card)
581 dpavlin 1 {
582     struct pa_4e8e_data *data;
583 dpavlin 11 u_int slot = card->slot_id;
584 dpavlin 1 int i;
585    
586     /* Allocate the private data structure for the PA-8E */
587     if (!(data = malloc(sizeof(*data)))) {
588 dpavlin 11 vm_error(vm,"%s: out of memory\n",card->dev_name);
589 dpavlin 1 return(-1);
590     }
591    
592     /* 4 Ethernet ports */
593     memset(data,0,sizeof(*data));
594     data->nr_port = 8;
595    
596 dpavlin 11 /* Set the PCI bus */
597     card->pci_bus = vm->slots_pci_bus[slot];
598    
599 dpavlin 1 /* Set the EEPROM */
600 dpavlin 11 cisco_card_set_eeprom(vm,card,cisco_eeprom_find_pa("PA-8E"));
601     c7200_set_slot_eeprom(VM_C7200(vm),slot,&card->eeprom);
602 dpavlin 1
603     /* Create the AMD Am79c971 chips */
604     for(i=0;i<data->nr_port;i++) {
605 dpavlin 11 data->port[i] = dev_am79c971_init(vm,card->dev_name,
606     AM79C971_TYPE_10BASE_T,
607     card->pci_bus,i,
608     c7200_net_irq_for_slot_port(slot,i));
609 dpavlin 1 }
610    
611     /* Store device info into the router structure */
612 dpavlin 11 card->drv_info = data;
613     return(0);
614 dpavlin 1 }
615    
616     /* Remove a PA-4E/PA-8E from the specified slot */
617 dpavlin 11 static int
618     dev_c7200_pa_4e8e_shutdown(vm_instance_t *vm,struct cisco_card *card)
619 dpavlin 1 {
620 dpavlin 11 struct pa_4e8e_data *data = card->drv_info;
621 dpavlin 1 int i;
622    
623     /* Remove the PA EEPROM */
624 dpavlin 11 cisco_card_unset_eeprom(card);
625     c7200_set_slot_eeprom(VM_C7200(vm),card->slot_id,NULL);
626 dpavlin 1
627     /* Remove the AMD Am79c971 chips */
628     for(i=0;i<data->nr_port;i++)
629     dev_am79c971_remove(data->port[i]);
630    
631     free(data);
632     return(0);
633     }
634    
635     /* Bind a Network IO descriptor */
636 dpavlin 11 static int
637     dev_c7200_pa_4e8e_set_nio(vm_instance_t *vm,struct cisco_card *card,
638     u_int port_id,netio_desc_t *nio)
639 dpavlin 1 {
640 dpavlin 11 struct pa_4e8e_data *d = card->drv_info;
641 dpavlin 1
642     if (!d || (port_id >= d->nr_port))
643     return(-1);
644    
645     dev_am79c971_set_nio(d->port[port_id],nio);
646     return(0);
647     }
648    
649     /* Unbind a Network IO descriptor */
650 dpavlin 11 static int
651     dev_c7200_pa_4e8e_unset_nio(vm_instance_t *vm,struct cisco_card *card,
652     u_int port_id)
653 dpavlin 1 {
654 dpavlin 11 struct pa_4e8e_data *d = card->drv_info;
655 dpavlin 1
656     if (!d || (port_id >= d->nr_port))
657     return(-1);
658    
659     dev_am79c971_unset_nio(d->port[port_id]);
660     return(0);
661     }
662    
663     /* PA-4E driver */
664 dpavlin 11 struct cisco_card_driver dev_c7200_pa_4e_driver = {
665     "PA-4E", 1, 0,
666 dpavlin 1 dev_c7200_pa_4e_init,
667     dev_c7200_pa_4e8e_shutdown,
668 dpavlin 11 NULL,
669 dpavlin 1 dev_c7200_pa_4e8e_set_nio,
670     dev_c7200_pa_4e8e_unset_nio,
671 dpavlin 2 NULL,
672 dpavlin 1 };
673    
674     /* PA-8E driver */
675 dpavlin 11 struct cisco_card_driver dev_c7200_pa_8e_driver = {
676     "PA-8E", 1, 0,
677 dpavlin 1 dev_c7200_pa_8e_init,
678     dev_c7200_pa_4e8e_shutdown,
679 dpavlin 11 NULL,
680 dpavlin 1 dev_c7200_pa_4e8e_set_nio,
681     dev_c7200_pa_4e8e_unset_nio,
682 dpavlin 2 NULL,
683 dpavlin 1 };

  ViewVC Help
Powered by ViewVC 1.1.26