--- upstream/dynamips-0.2.6-RC1/dev_c7200_eth.c 2007/10/06 16:03:58 2 +++ upstream/dynamips-0.2.7-RC1/dev_c7200_eth.c 2007/10/06 16:23:47 7 @@ -1,5 +1,5 @@ /* - * Cisco C7200 (Predator) simulation platform. + * Cisco router simulation platform. * Copyright (c) 2005,2006 Christophe Fillot (cf@utc.fr) * * Ethernet Port Adapters. @@ -20,30 +20,20 @@ #include "ptask.h" #include "dev_am79c971.h" #include "dev_dec21140.h" +#include "dev_i8254x.h" #include "dev_c7200.h" /* ====================================================================== */ -/* PA-FE-TX / C7200-IO-FE */ +/* C7200-IO-FE EEPROM */ /* ====================================================================== */ -/* PA-FE-TX: FastEthernet Port Adapter EEPROM */ -static const m_uint16_t eeprom_c7200_pa_fe_tx_data[16] = { - 0x0111, 0x0102, 0xffff, 0xffff, 0x4906, 0x9804, 0x0000, 0x0000, - 0x6000, 0x0000, 0x9812, 0x1700, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, -}; - -static const struct c7200_eeprom eeprom_c7200_pa_fe_tx = { - "PA-FE-TX", (m_uint16_t *)eeprom_c7200_pa_fe_tx_data, - sizeof(eeprom_c7200_pa_fe_tx_data)/2, -}; - /* C7200-IO-FE: C7200 IOCard with one FastEthernet port EEPROM */ static const m_uint16_t eeprom_c7200_io_fe_data[16] = { 0x0183, 0x010E, 0xffff, 0xffff, 0x490B, 0x8C02, 0x0000, 0x0000, 0x5000, 0x0000, 0x9812, 0x2800, 0x00FF, 0xFFFF, 0xFFFF, 0xFFFF, }; -static const struct c7200_eeprom eeprom_c7200_io_fe = { +static const struct cisco_eeprom eeprom_c7200_io_fe = { "C7200-IO-FE", (m_uint16_t *)eeprom_c7200_io_fe_data, sizeof(eeprom_c7200_io_fe_data)/2, }; @@ -69,7 +59,6 @@ /* Create the DEC21140 chip */ data = dev_dec21140_init(router->vm,name, router->pa_bay[pa_bay].pci_map, - /*router->npe_driver->dec21140_pci_bus,*/ //PCI router->npe_driver->dec21140_pci_dev, C7200_NETIO_IRQ); if (!data) return(-1); @@ -126,7 +115,7 @@ struct dec21140_data *data; /* Set the EEPROM */ - c7200_pa_set_eeprom(router,pa_bay,&eeprom_c7200_pa_fe_tx); + c7200_pa_set_eeprom(router,pa_bay,cisco_eeprom_find_pa("PA-FE-TX")); /* Create the DEC21140 chip */ data = dev_dec21140_init(router->vm,name,router->pa_bay[pa_bay].pci_map,0, @@ -176,7 +165,7 @@ } /* C7200-IO-FE driver */ -struct c7200_pa_driver dev_c7200_io_fe_driver = { +struct c7200_pa_driver dev_c7200_iocard_fe_driver = { "C7200-IO-FE", 1, dev_c7200_iocard_init, dev_c7200_iocard_shutdown, @@ -196,35 +185,305 @@ }; /* ====================================================================== */ -/* PA-4E / PA-8E */ +/* PA based on Intel i8254x chips */ /* ====================================================================== */ -/* PA-4E/PA-8E data */ -struct pa_4e8e_data { +struct pa_i8254x_data { u_int nr_port; - struct am79c971_data *port[8]; + struct i8254x_data *port[2]; +}; + +/* Remove a PA-2FE-TX from the specified slot */ +static int dev_c7200_pa_i8254x_shutdown(c7200_t *router,u_int pa_bay) +{ + struct c7200_pa_bay *bay; + struct pa_i8254x_data *data; + int i; + + if (!(bay = c7200_pa_get_info(router,pa_bay))) + return(-1); + + data = bay->drv_info; + + /* Remove the PA EEPROM */ + c7200_pa_unset_eeprom(router,pa_bay); + + /* Remove the AMD Am79c971 chips */ + for(i=0;inr_port;i++) + dev_i8254x_remove(data->port[i]); + + free(data); + return(0); +} + +/* Bind a Network IO descriptor */ +static int dev_c7200_pa_i8254x_set_nio(c7200_t *router,u_int pa_bay, + u_int port_id,netio_desc_t *nio) +{ + struct pa_i8254x_data *d; + + d = c7200_pa_get_drvinfo(router,pa_bay); + + if (!d || (port_id >= d->nr_port)) + return(-1); + + dev_i8254x_set_nio(d->port[port_id],nio); + return(0); +} + +/* Unbind a Network IO descriptor */ +static int dev_c7200_pa_i8254x_unset_nio(c7200_t *router,u_int pa_bay, + u_int port_id) +{ + struct pa_i8254x_data *d; + + d = c7200_pa_get_drvinfo(router,pa_bay); + + if (!d || (port_id >= d->nr_port)) + return(-1); + + dev_i8254x_unset_nio(d->port[port_id]); + return(0); +} + +/* ====================================================================== */ +/* PA-2FE-TX */ +/* ====================================================================== */ + +/* + * dev_c7200_pa_2fe_tx_init() + * + * Add a PA-2FE-TX port adapter into specified slot. + */ +static int dev_c7200_pa_2fe_tx_init(c7200_t *router,char *name,u_int pa_bay) +{ + struct pa_i8254x_data *data; + int i; + + /* Allocate the private data structure for the PA-2FE-TX */ + if (!(data = malloc(sizeof(*data)))) { + fprintf(stderr,"%s (PA-2FE-TX): out of memory\n",name); + return(-1); + } + + /* 2 Ethernet ports */ + memset(data,0,sizeof(*data)); + data->nr_port = 2; + + /* Set the EEPROM */ + c7200_pa_set_eeprom(router,pa_bay,cisco_eeprom_find_pa("PA-2FE-TX")); + + /* Create the Intel i8254x chips */ + for(i=0;inr_port;i++) { + data->port[i] = dev_i8254x_init(router->vm,name,0, + router->pa_bay[pa_bay].pci_map,i, + C7200_NETIO_IRQ); + } + + /* Store device info into the router structure */ + return(c7200_pa_set_drvinfo(router,pa_bay,data)); +} + +/* PA-2FE-TX driver */ +struct c7200_pa_driver dev_c7200_pa_2fe_tx_driver = { + "PA-2FE-TX", 0, + dev_c7200_pa_2fe_tx_init, + dev_c7200_pa_i8254x_shutdown, + dev_c7200_pa_i8254x_set_nio, + dev_c7200_pa_i8254x_unset_nio, + NULL, +}; + +/* ====================================================================== */ +/* PA-GE */ +/* ====================================================================== */ + +/* + * dev_c7200_pa_ge_init() + * + * Add a PA-GE port adapter into specified slot. + */ +static int dev_c7200_pa_ge_init(c7200_t *router,char *name,u_int pa_bay) +{ + struct pa_i8254x_data *data; + + /* Allocate the private data structure for the PA-2FE-TX */ + if (!(data = malloc(sizeof(*data)))) { + fprintf(stderr,"%s (PA-GE): out of memory\n",name); + return(-1); + } + + /* 2 Ethernet ports */ + memset(data,0,sizeof(*data)); + data->nr_port = 1; + + /* Set the EEPROM */ + c7200_pa_set_eeprom(router,pa_bay,cisco_eeprom_find_pa("PA-GE")); + + /* Create the Intel i8254x chip */ + data->port[0] = dev_i8254x_init(router->vm,name,0, + router->pa_bay[pa_bay].pci_map,0, + C7200_NETIO_IRQ); + + /* Store device info into the router structure */ + return(c7200_pa_set_drvinfo(router,pa_bay,data)); +} + +/* PA-GE driver */ +struct c7200_pa_driver dev_c7200_pa_ge_driver = { + "PA-GE", 0, + dev_c7200_pa_ge_init, + dev_c7200_pa_i8254x_shutdown, + dev_c7200_pa_i8254x_set_nio, + dev_c7200_pa_i8254x_unset_nio, + NULL, }; -/* PA-4E: 4 Ethernet Port Adapter EEPROM */ -static const m_uint16_t eeprom_c7200_pa_4e_data[16] = { - 0x0102, 0x010E, 0xFFFF, 0xFFFF, 0x4906, 0x1404, 0x0000, 0x0000, - 0x5000, 0x0000, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, +/* ====================================================================== */ +/* C7200-IO-2FE */ +/* ====================================================================== */ + +/* C7200-IO-2FE/E: C7200 IOCard with two FastEthernet ports EEPROM */ +static const m_uint16_t eeprom_c7200_io_2fe_data[] = { + 0x04FF, 0x4002, 0x1541, 0x0201, 0xC046, 0x0320, 0x001B, 0xCA06, + 0x8249, 0x138B, 0x0642, 0x4230, 0xC18B, 0x3030, 0x3030, 0x3030, + 0x3030, 0x0000, 0x0004, 0x0002, 0x0385, 0x1C0D, 0x7F03, 0xCB8F, + 0x4337, 0x3230, 0x302D, 0x492F, 0x4F2D, 0x3246, 0x452F, 0x4580, + 0x0000, 0x0000, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, }; -static const struct c7200_eeprom eeprom_c7200_pa_4e = { - "PA-4E", (m_uint16_t *)eeprom_c7200_pa_4e_data, - sizeof(eeprom_c7200_pa_4e_data)/2, +static const struct cisco_eeprom eeprom_c7200_io_2fe = { + "C7200-IO-2FE", (m_uint16_t *)eeprom_c7200_io_2fe_data, + sizeof(eeprom_c7200_io_2fe_data)/2, }; -/* PA-8E: 8 Ethernet Port Adapter EEPROM */ -static const m_uint16_t eeprom_c7200_pa_8e_data[16] = { - 0x0101, 0x010E, 0xFFFF, 0xFFFF, 0x4906, 0x1404, 0x0000, 0x0000, - 0x5000, 0x0000, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, +/* + * dev_c7200_pa_2fe_tx_init() + * + * Add a C7200-IO-2FE/E port adapter into specified slot. + */ +static int dev_c7200_iocard_2fe_init(c7200_t *router,char *name,u_int pa_bay) +{ + struct pa_i8254x_data *data; + + /* Allocate the private data structure for the iocard */ + if (!(data = malloc(sizeof(*data)))) { + fprintf(stderr,"%s (C7200-IO-2FE): out of memory\n",name); + return(-1); + } + + /* 2 Ethernet ports */ + memset(data,0,sizeof(*data)); + data->nr_port = 2; + + /* Set the EEPROM */ + c7200_pa_set_eeprom(router,pa_bay,&eeprom_c7200_io_2fe); + + /* Port Fa0/0 is on PCI Device 1 */ + data->port[0] = dev_i8254x_init(router->vm,name,0, + router->pa_bay[pa_bay].pci_map,1, + C7200_NETIO_IRQ); + + /* Port Fa0/1 is on PCI Device 0 */ + data->port[1] = dev_i8254x_init(router->vm,name,0, + router->pa_bay[pa_bay].pci_map,0, + C7200_NETIO_IRQ); + + /* Store device info into the router structure */ + return(c7200_pa_set_drvinfo(router,pa_bay,data)); +} + +/* C7200-IO-2FE driver */ +struct c7200_pa_driver dev_c7200_iocard_2fe_driver = { + "C7200-IO-2FE", 0, + dev_c7200_iocard_2fe_init, + dev_c7200_pa_i8254x_shutdown, + dev_c7200_pa_i8254x_set_nio, + dev_c7200_pa_i8254x_unset_nio, + NULL, }; -static const struct c7200_eeprom eeprom_c7200_pa_8e = { - "PA-8E", (m_uint16_t *)eeprom_c7200_pa_8e_data, - sizeof(eeprom_c7200_pa_8e_data)/2, +/* ====================================================================== */ +/* C7200-IO-GE-E */ +/* ====================================================================== */ + +/* + * C7200-IO-GE+E: C7200 IOCard with 1 GigatEthernet ports + * and 1 Ethernet port EEPROM. + */ +static const m_uint16_t eeprom_c7200_io_ge_e_data[] = { + 0x04FF, 0x4002, 0x1641, 0x0201, 0xC046, 0x0320, 0x001B, 0xCA06, + 0x8249, 0x138B, 0x0642, 0x4230, 0xC18B, 0x3030, 0x3030, 0x3030, + 0x3030, 0x0000, 0x0004, 0x0002, 0x0385, 0x1C0D, 0x7F03, 0xCB8F, + 0x4337, 0x3230, 0x302D, 0x492F, 0x4F2D, 0x3246, 0x452F, 0x4580, + 0x0000, 0x0000, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, +}; + +static const struct cisco_eeprom eeprom_c7200_io_ge_e = { + "C7200-IO-GE-E", (m_uint16_t *)eeprom_c7200_io_ge_e_data, + sizeof(eeprom_c7200_io_ge_e_data)/2, +}; + +/* + * dev_c7200_pa_ge_e_tx_init() + * + * Add a C7200-I/O-GE+E port adapter into specified slot. + */ +static int dev_c7200_iocard_ge_e_init(c7200_t *router,char *name,u_int pa_bay) +{ + struct pa_i8254x_data *data; + + /* Allocate the private data structure for the iocard */ + if (!(data = malloc(sizeof(*data)))) { + fprintf(stderr,"%s (C7200-IO-GE+E): out of memory\n",name); + return(-1); + } + + /* 2 Ethernet ports */ + memset(data,0,sizeof(*data)); + data->nr_port = 2; + + /* Set the EEPROM */ + c7200_pa_set_eeprom(router,pa_bay,&eeprom_c7200_io_ge_e); + + /* Port Gi0/0 is on PCI Device 1 */ + data->port[0] = dev_i8254x_init(router->vm,name,0, + router->pa_bay[pa_bay].pci_map,1, + C7200_NETIO_IRQ); + + /* Port e0/0 is on PCI Device 0 */ + data->port[1] = dev_i8254x_init(router->vm,name,0, + router->pa_bay[pa_bay].pci_map,0, + C7200_NETIO_IRQ); + + /* Store device info into the router structure */ + return(c7200_pa_set_drvinfo(router,pa_bay,data)); +} + +/* C7200-IO-GE-E driver */ +struct c7200_pa_driver dev_c7200_iocard_ge_e_driver = { + "C7200-IO-GE-E", 0, + dev_c7200_iocard_ge_e_init, + dev_c7200_pa_i8254x_shutdown, + dev_c7200_pa_i8254x_set_nio, + dev_c7200_pa_i8254x_unset_nio, + NULL, +}; + +/* ====================================================================== */ +/* PA-4E / PA-8E */ +/* ====================================================================== */ + +/* PA-4E/PA-8E data */ +struct pa_4e8e_data { + u_int nr_port; + struct am79c971_data *port[8]; }; /* @@ -248,7 +507,7 @@ data->nr_port = 4; /* Set the EEPROM */ - c7200_pa_set_eeprom(router,pa_bay,&eeprom_c7200_pa_4e); + c7200_pa_set_eeprom(router,pa_bay,cisco_eeprom_find_pa("PA-4E")); /* Create the AMD Am79c971 chips */ for(i=0;inr_port;i++) { @@ -282,7 +541,7 @@ data->nr_port = 8; /* Set the EEPROM */ - c7200_pa_set_eeprom(router,pa_bay,&eeprom_c7200_pa_8e); + c7200_pa_set_eeprom(router,pa_bay,cisco_eeprom_find_pa("PA-8E")); /* Create the AMD Am79c971 chips */ for(i=0;inr_port;i++) {