Annotation of cf/dev_c7200_eth.c, revision 1.1.1.4

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

unix.superglobalmegacorp.com

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