Annotation of cf/dev_c7200_eth.c, revision 1.1.1.3

1.1       root        1: /*  
                      2:  * Cisco C7200 (Predator) simulation platform.
                      3:  * Copyright (c) 2005,2006 Christophe Fillot ([email protected])
                      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: #include "dev_c7200.h"
                     24: 
                     25: /* ====================================================================== */
1.1.1.3 ! root       26: /* C7200-IO-FE EEPROM                                                     */
1.1       root       27: /* ====================================================================== */
                     28: 
                     29: /* C7200-IO-FE: C7200 IOCard with one FastEthernet port EEPROM */
                     30: static const m_uint16_t eeprom_c7200_io_fe_data[16] = {
                     31:    0x0183, 0x010E, 0xffff, 0xffff, 0x490B, 0x8C02, 0x0000, 0x0000,
                     32:    0x5000, 0x0000, 0x9812, 0x2800, 0x00FF, 0xFFFF, 0xFFFF, 0xFFFF,
                     33: };
                     34: 
1.1.1.3 ! root       35: static const struct cisco_eeprom eeprom_c7200_io_fe = {
1.1       root       36:    "C7200-IO-FE", (m_uint16_t *)eeprom_c7200_io_fe_data,
                     37:    sizeof(eeprom_c7200_io_fe_data)/2,
                     38: };
                     39: 
                     40: /*
                     41:  * dev_c7200_iocard_init()
                     42:  *
                     43:  * Add an IOcard into slot 0.
                     44:  */
                     45: static int dev_c7200_iocard_init(c7200_t *router,char *name,u_int pa_bay)
                     46: {
                     47:    struct dec21140_data *data;
                     48:    
                     49:    if (pa_bay != 0) {
                     50:       fprintf(stderr,"C7200 '%s': cannot put IOCARD in PA bay %u!\n",
                     51:               router->vm->name,pa_bay);
                     52:       return(-1);
                     53:    }
                     54: 
                     55:    /* Set the EEPROM */
                     56:    c7200_pa_set_eeprom(router,pa_bay,&eeprom_c7200_io_fe);
                     57: 
                     58:    /* Create the DEC21140 chip */
                     59:    data = dev_dec21140_init(router->vm,name,
                     60:                             router->pa_bay[pa_bay].pci_map,
                     61:                             router->npe_driver->dec21140_pci_dev,
                     62:                             C7200_NETIO_IRQ);
                     63:    if (!data) return(-1);
                     64: 
                     65:    /* Store device info into the router structure */
                     66:    return(c7200_pa_set_drvinfo(router,pa_bay,data));
                     67: }
                     68: 
                     69: /* Remove an IOcard from slot 0 */
                     70: static int dev_c7200_iocard_shutdown(c7200_t *router,u_int pa_bay) 
                     71: {
                     72:    struct c7200_pa_bay *bay;
                     73: 
                     74:    if (!(bay = c7200_pa_get_info(router,pa_bay)))
                     75:       return(-1);
                     76: 
                     77:    c7200_pa_unset_eeprom(router,pa_bay);
                     78:    dev_dec21140_remove(bay->drv_info);
                     79:    return(0);
                     80: }
                     81: 
                     82: /* Bind a Network IO descriptor */
                     83: static int dev_c7200_iocard_set_nio(c7200_t *router,u_int pa_bay,u_int port_id,
                     84:                                     netio_desc_t *nio)
                     85: {
                     86:    struct dec21140_data *d;
                     87: 
                     88:    if ((port_id > 0) || !(d = c7200_pa_get_drvinfo(router,pa_bay)))
                     89:       return(-1);
                     90: 
                     91:    return(dev_dec21140_set_nio(d,nio));
                     92: }
                     93: 
                     94: /* Unbind a Network IO descriptor */
                     95: static int dev_c7200_iocard_unset_nio(c7200_t *router,u_int pa_bay,
                     96:                                       u_int port_id)
                     97: {
                     98:    struct dec21140_data *d;
                     99: 
                    100:    if ((port_id > 0) || !(d = c7200_pa_get_drvinfo(router,pa_bay)))
                    101:       return(-1);
                    102:    
                    103:    dev_dec21140_unset_nio(d);
                    104:    return(0);
                    105: }
                    106: 
                    107: /*
                    108:  * dev_c7200_pa_fe_tx_init()
                    109:  *
                    110:  * Add a PA-FE-TX port adapter into specified slot.
                    111:  */
                    112: static int dev_c7200_pa_fe_tx_init(c7200_t *router,char *name,u_int pa_bay)
                    113: {
                    114:    struct dec21140_data *data;
                    115: 
                    116:    /* Set the EEPROM */
1.1.1.3 ! root      117:    c7200_pa_set_eeprom(router,pa_bay,cisco_eeprom_find_pa("PA-FE-TX"));
1.1       root      118: 
                    119:    /* Create the DEC21140 chip */
                    120:    data = dev_dec21140_init(router->vm,name,router->pa_bay[pa_bay].pci_map,0,
                    121:                             C7200_NETIO_IRQ);
                    122:    if (!data) return(-1);
                    123: 
                    124:    /* Store device info into the router structure */
                    125:    return(c7200_pa_set_drvinfo(router,pa_bay,data));
                    126: }
                    127: 
                    128: /* Remove a PA-FE-TX from the specified slot */
                    129: static int dev_c7200_pa_fe_tx_shutdown(c7200_t *router,u_int pa_bay) 
                    130: {
                    131:    struct c7200_pa_bay *bay;
                    132: 
                    133:    if (!(bay = c7200_pa_get_info(router,pa_bay)))
                    134:       return(-1);
                    135: 
                    136:    c7200_pa_unset_eeprom(router,pa_bay);
                    137:    dev_dec21140_remove(bay->drv_info);
                    138:    return(0);
                    139: }
                    140: 
                    141: /* Bind a Network IO descriptor */
                    142: static int dev_c7200_pa_fe_tx_set_nio(c7200_t *router,u_int pa_bay,
                    143:                                       u_int port_id,netio_desc_t *nio)
                    144: {
                    145:    struct dec21140_data *d;
                    146: 
                    147:    if ((port_id > 0) || !(d = c7200_pa_get_drvinfo(router,pa_bay)))
                    148:       return(-1);
                    149:    
                    150:    return(dev_dec21140_set_nio(d,nio));
                    151: }
                    152: 
                    153: /* Unbind a Network IO descriptor */
                    154: static int dev_c7200_pa_fe_tx_unset_nio(c7200_t *router,u_int pa_bay,
                    155:                                         u_int port_id)
                    156: {
                    157:    struct dec21140_data *d;
                    158: 
                    159:    if ((port_id > 0) || !(d = c7200_pa_get_drvinfo(router,pa_bay)))
                    160:       return(-1);
                    161:    
                    162:    dev_dec21140_unset_nio(d);
                    163:    return(0);
                    164: }
                    165: 
                    166: /* C7200-IO-FE driver */
                    167: struct c7200_pa_driver dev_c7200_io_fe_driver = {
                    168:    "C7200-IO-FE", 1, 
                    169:    dev_c7200_iocard_init, 
                    170:    dev_c7200_iocard_shutdown,
                    171:    dev_c7200_iocard_set_nio,
                    172:    dev_c7200_iocard_unset_nio,
1.1.1.2   root      173:    NULL,
1.1       root      174: };
                    175: 
                    176: /* PA-FE-TX driver */
                    177: struct c7200_pa_driver dev_c7200_pa_fe_tx_driver = {
                    178:    "PA-FE-TX", 1, 
                    179:    dev_c7200_pa_fe_tx_init, 
                    180:    dev_c7200_pa_fe_tx_shutdown,
                    181:    dev_c7200_pa_fe_tx_set_nio,
                    182:    dev_c7200_pa_fe_tx_unset_nio,
1.1.1.2   root      183:    NULL,
1.1       root      184: };
                    185: 
                    186: /* ====================================================================== */
                    187: /* PA-4E / PA-8E                                                          */
                    188: /* ====================================================================== */
                    189: 
                    190: /* PA-4E/PA-8E data */
                    191: struct pa_4e8e_data {
                    192:    u_int nr_port;
                    193:    struct am79c971_data *port[8];
                    194: };
                    195: 
                    196: /*
                    197:  * dev_c7200_pa_4e_init()
                    198:  *
                    199:  * Add a PA-4E port adapter into specified slot.
                    200:  */
                    201: static int dev_c7200_pa_4e_init(c7200_t *router,char *name,u_int pa_bay)
                    202: {
                    203:    struct pa_4e8e_data *data;
                    204:    int i;
                    205: 
                    206:    /* Allocate the private data structure for the PA-4E */
                    207:    if (!(data = malloc(sizeof(*data)))) {
                    208:       fprintf(stderr,"%s (PA-4E): out of memory\n",name);
                    209:       return(-1);
                    210:    }
                    211: 
                    212:    /* 4 Ethernet ports */
                    213:    memset(data,0,sizeof(*data));
                    214:    data->nr_port = 4;
                    215: 
                    216:    /* Set the EEPROM */
1.1.1.3 ! root      217:    c7200_pa_set_eeprom(router,pa_bay,cisco_eeprom_find_pa("PA-4E"));
1.1       root      218: 
                    219:    /* Create the AMD Am79c971 chips */
                    220:    for(i=0;i<data->nr_port;i++) {
                    221:       data->port[i] = dev_am79c971_init(router->vm,name,AM79C971_TYPE_10BASE_T,
                    222:                                         router->pa_bay[pa_bay].pci_map,i,
                    223:                                         C7200_NETIO_IRQ);
                    224:    }
                    225: 
                    226:    /* Store device info into the router structure */
                    227:    return(c7200_pa_set_drvinfo(router,pa_bay,data));
                    228: }
                    229: 
                    230: /*
                    231:  * dev_c7200_pa_8e_init()
                    232:  *
                    233:  * Add a PA-8E port adapter into specified slot.
                    234:  */
                    235: static int dev_c7200_pa_8e_init(c7200_t *router,char *name,u_int pa_bay)
                    236: {
                    237:    struct pa_4e8e_data *data;
                    238:    int i;
                    239: 
                    240:    /* Allocate the private data structure for the PA-8E */
                    241:    if (!(data = malloc(sizeof(*data)))) {
                    242:       fprintf(stderr,"%s (PA-8E): out of memory\n",name);
                    243:       return(-1);
                    244:    }
                    245: 
                    246:    /* 4 Ethernet ports */
                    247:    memset(data,0,sizeof(*data));
                    248:    data->nr_port = 8;
                    249: 
                    250:    /* Set the EEPROM */
1.1.1.3 ! root      251:    c7200_pa_set_eeprom(router,pa_bay,cisco_eeprom_find_pa("PA-8E"));
1.1       root      252: 
                    253:    /* Create the AMD Am79c971 chips */
                    254:    for(i=0;i<data->nr_port;i++) {
                    255:       data->port[i] = dev_am79c971_init(router->vm,name,AM79C971_TYPE_10BASE_T,
                    256:                                         router->pa_bay[pa_bay].pci_map,i,
                    257:                                         C7200_NETIO_IRQ);
                    258:    }
                    259: 
                    260:    /* Store device info into the router structure */
                    261:    return(c7200_pa_set_drvinfo(router,pa_bay,data));
                    262: }
                    263: 
                    264: /* Remove a PA-4E/PA-8E from the specified slot */
                    265: static int dev_c7200_pa_4e8e_shutdown(c7200_t *router,u_int pa_bay) 
                    266: {
                    267:    struct c7200_pa_bay *bay;
                    268:    struct pa_4e8e_data *data;
                    269:    int i;
                    270: 
                    271:    if (!(bay = c7200_pa_get_info(router,pa_bay)))
                    272:       return(-1);
                    273: 
                    274:    data = bay->drv_info;
                    275: 
                    276:    /* Remove the PA EEPROM */
                    277:    c7200_pa_unset_eeprom(router,pa_bay);
                    278: 
                    279:    /* Remove the AMD Am79c971 chips */
                    280:    for(i=0;i<data->nr_port;i++)
                    281:       dev_am79c971_remove(data->port[i]);
                    282: 
                    283:    free(data);
                    284:    return(0);
                    285: }
                    286: 
                    287: /* Bind a Network IO descriptor */
                    288: static int dev_c7200_pa_4e8e_set_nio(c7200_t *router,u_int pa_bay,
                    289:                                      u_int port_id,netio_desc_t *nio)
                    290: {
                    291:    struct pa_4e8e_data *d;
                    292: 
                    293:    d = c7200_pa_get_drvinfo(router,pa_bay);
                    294: 
                    295:    if (!d || (port_id >= d->nr_port))
                    296:       return(-1);
                    297: 
                    298:    dev_am79c971_set_nio(d->port[port_id],nio);
                    299:    return(0);
                    300: }
                    301: 
                    302: /* Unbind a Network IO descriptor */
                    303: static int dev_c7200_pa_4e8e_unset_nio(c7200_t *router,u_int pa_bay,
                    304:                                        u_int port_id)
                    305: {
                    306:    struct pa_4e8e_data *d;
                    307: 
                    308:    d = c7200_pa_get_drvinfo(router,pa_bay);
                    309: 
                    310:    if (!d || (port_id >= d->nr_port))
                    311:       return(-1);
                    312: 
                    313:    dev_am79c971_unset_nio(d->port[port_id]);
                    314:    return(0);
                    315: }
                    316: 
                    317: /* PA-4E driver */
                    318: struct c7200_pa_driver dev_c7200_pa_4e_driver = {
                    319:    "PA-4E", 1, 
                    320:    dev_c7200_pa_4e_init, 
                    321:    dev_c7200_pa_4e8e_shutdown, 
                    322:    dev_c7200_pa_4e8e_set_nio,
                    323:    dev_c7200_pa_4e8e_unset_nio,
1.1.1.2   root      324:    NULL,
1.1       root      325: };
                    326: 
                    327: /* PA-8E driver */
                    328: struct c7200_pa_driver dev_c7200_pa_8e_driver = {
                    329:    "PA-8E", 1, 
                    330:    dev_c7200_pa_8e_init, 
                    331:    dev_c7200_pa_4e8e_shutdown, 
                    332:    dev_c7200_pa_4e8e_set_nio,
                    333:    dev_c7200_pa_4e8e_unset_nio,
1.1.1.2   root      334:    NULL,
1.1       root      335: };

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.