/[dynamips]/trunk/dev_c2691.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

Diff of /trunk/dev_c2691.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

upstream/dynamips-0.2.7/dev_c2691.c revision 10 by dpavlin, Sat Oct 6 16:29:14 2007 UTC upstream/dynamips-0.2.8-RC1/dev_c2691.c revision 11 by dpavlin, Sat Oct 6 16:33:40 2007 UTC
# Line 51  struct cisco_eeprom eeprom_c2691_mainboa Line 51  struct cisco_eeprom eeprom_c2691_mainboa
51  /* ======================================================================== */  /* ======================================================================== */
52  /* Network Module Drivers                                                   */  /* Network Module Drivers                                                   */
53  /* ======================================================================== */  /* ======================================================================== */
54  static struct c2691_nm_driver *nm_drivers[] = {  static struct cisco_card_driver *nm_drivers[] = {
55     &dev_c2691_nm_1fe_tx_driver,     &dev_c2691_nm_1fe_tx_driver,
56     &dev_c2691_nm_16esw_driver,     &dev_c2691_nm_16esw_driver,
57     &dev_c2691_gt96100_fe_driver,     &dev_c2691_gt96100_fe_driver,
58     &dev_c2691_nm_4t_driver,     &dev_c2691_nm_4t_driver,
59       &dev_c2691_nm_nam_driver,
60       &dev_c2691_nm_cids_driver,
61     NULL,     NULL,
62  };  };
63    
# Line 63  static struct c2691_nm_driver *nm_driver Line 65  static struct c2691_nm_driver *nm_driver
65  /* Cisco 2691 router instances                                              */  /* Cisco 2691 router instances                                              */
66  /* ======================================================================== */  /* ======================================================================== */
67    
68    /* Initialize default parameters for a C2691 */
69    static void c2691_init_defaults(c2691_t *router);
70    
71  /* Directly extract the configuration from the NVRAM device */  /* Directly extract the configuration from the NVRAM device */
72  ssize_t c2691_nvram_extract_config(vm_instance_t *vm,char **buffer)  ssize_t c2691_nvram_extract_config(vm_instance_t *vm,u_char **buffer)
73  {    {  
74     u_char *base_ptr,*ios_ptr,*cfg_ptr,*end_ptr;     u_char *base_ptr,*ios_ptr,*cfg_ptr,*end_ptr;
75     m_uint32_t start,nvlen;     m_uint32_t start,nvlen;
# Line 119  ssize_t c2691_nvram_extract_config(vm_in Line 124  ssize_t c2691_nvram_extract_config(vm_in
124  }  }
125    
126  static int c2691_nvram_push_config_part(vm_instance_t *vm,  static int c2691_nvram_push_config_part(vm_instance_t *vm,
127                                          char *buffer,size_t len,                                          u_char *buffer,size_t len,
128                                          u_char *ios_ptr)                                          u_char *ios_ptr)
129  {      {    
130     m_uint32_t cfg_offset,cklen,tmp;     m_uint32_t cfg_offset,cklen,tmp;
# Line 154  static int c2691_nvram_push_config_part( Line 159  static int c2691_nvram_push_config_part(
159  }  }
160    
161  /* Directly push the IOS configuration to the NVRAM device */  /* Directly push the IOS configuration to the NVRAM device */
162  int c2691_nvram_push_config(vm_instance_t *vm,char *buffer,size_t len)  int c2691_nvram_push_config(vm_instance_t *vm,u_char *buffer,size_t len)
163  {  {
164     u_char *base_ptr,*ios_ptr;     u_char *base_ptr,*ios_ptr;
165     int fd;     int fd;
# Line 204  int c2691_nvram_check_empty_config(vm_in Line 209  int c2691_nvram_check_empty_config(vm_in
209  }  }
210    
211  /* Create a new router instance */  /* Create a new router instance */
212  c2691_t *c2691_create_instance(char *name,int instance_id)  static int c2691_create_instance(vm_instance_t *vm)
213  {  {
214     c2691_t *router;     c2691_t *router;
215    
216     if (!(router = malloc(sizeof(*router)))) {     if (!(router = malloc(sizeof(*router)))) {
217        fprintf(stderr,"C2691 '%s': Unable to create new instance!\n",name);        fprintf(stderr,"C2691 '%s': Unable to create new instance!\n",vm->name);
218        return NULL;        return(-1);
219     }     }
220    
221     memset(router,0,sizeof(*router));     memset(router,0,sizeof(*router));
222       router->vm = vm;
223     if (!(router->vm = vm_create(name,instance_id,VM_TYPE_C2691))) {     vm->hw_data = router;
       fprintf(stderr,"C2691 '%s': unable to create VM instance!\n",name);  
       goto err_vm;  
    }  
224    
225     c2691_init_defaults(router);     c2691_init_defaults(router);
226     router->vm->hw_data = router;     return(0);
    return router;  
   
  err_vm:  
    free(router);  
    return NULL;  
227  }  }
228    
229  /* Free resources used by a router instance */  /* Free resources used by a router instance */
230  static int c2691_free_instance(void *data,void *arg)  static int c2691_delete_instance(vm_instance_t *vm)
231  {  {
232     vm_instance_t *vm = data;     c2691_t *router = VM_C2691(vm);
    c2691_t *router;  
233     int i;     int i;
234    
235     if (vm->type == VM_TYPE_C2691) {     /* Stop all CPUs */
236        router = VM_C2691(vm);     if (vm->cpu_group != NULL) {
237          vm_stop(vm);
       /* Stop all CPUs */  
       if (vm->cpu_group != NULL) {  
          vm_stop(vm);  
238                
239           if (cpu_group_sync_state(vm->cpu_group) == -1) {        if (cpu_group_sync_state(vm->cpu_group) == -1) {
240              vm_error(vm,"unable to sync with system CPUs.\n");           vm_error(vm,"unable to sync with system CPUs.\n");
241              return(FALSE);           return(FALSE);
          }  
242        }        }
   
       /* Remove NIO bindings */  
       for(i=0;i<C2691_MAX_NM_BAYS;i++)  
          c2691_nm_remove_all_nio_bindings(router,i);  
   
       /* Shutdown all Network Modules */  
       c2691_nm_shutdown_all(router);  
   
       /* Free mainboard EEPROM */  
       cisco_eeprom_free(&router->mb_eeprom);  
   
       /* Free all resources used by VM */  
       vm_free(vm);  
   
       /* Free the router structure */  
       free(router);  
       return(TRUE);  
243     }     }
244    
245     return(FALSE);     /* Remove NIO bindings */
246  }     for(i=0;i<vm->nr_slots;i++)
247          vm_slot_remove_all_nio_bindings(vm,i);
 /* Delete a router instance */  
 int c2691_delete_instance(char *name)  
 {  
    return(registry_delete_if_unused(name,OBJ_TYPE_VM,  
                                     c2691_free_instance,NULL));  
 }  
   
 /* Delete all router instances */  
 int c2691_delete_all_instances(void)  
 {  
    return(registry_delete_type(OBJ_TYPE_VM,c2691_free_instance,NULL));  
 }  
   
 /* Save configuration of a C2691 instance */  
 void c2691_save_config(c2691_t *router,FILE *fd)  
 {  
    vm_instance_t *vm = router->vm;  
    struct c2691_nio_binding *nb;  
    struct c2691_nm_bay *bay;  
    int i;  
248    
249     /* General settings */     /* Shutdown all Network Modules */
250     fprintf(fd,"c2691 create %s %u\n",vm->name,vm->instance_id);     vm_slot_shutdown_all(vm);
251    
252     /* VM configuration */     /* Free mainboard EEPROM */
253     vm_save_config(vm,fd);     cisco_eeprom_free(&router->mb_eeprom);
254    
255     /* Network Module settings */     /* Free all resources used by VM */
256     for(i=0;i<C2691_MAX_NM_BAYS;i++) {     vm_free(vm);
       if (!(bay = c2691_nm_get_info(router,i)))  
          continue;  
   
       if (bay->dev_type) {  
          fprintf(fd,"c2691 add_nm_binding %s %u %s\n",  
                  vm->name,i,bay->dev_type);  
       }  
257    
258        for(nb=bay->nio_list;nb;nb=nb->next) {     /* Free the router structure */
259           fprintf(fd,"c2691 add_nio_binding %s %u %u %s\n",     free(router);
260                   vm->name,i,nb->port_id,nb->nio->name);     return(TRUE);
       }  
    }  
   
    fprintf(fd,"\n");  
261  }  }
262    
263  /* Save configurations of all C2691 instances */  /* Get WIC device address for the specified onboard port */
264  static void c2691_reg_save_config(registry_entry_t *entry,void *opt,int *err)  int c2691_get_onboard_wic_addr(u_int slot,m_uint64_t *phys_addr)
265  {  {
266     vm_instance_t *vm = entry->data;     if (slot >= C2691_MAX_WIC_BAYS)
267     c2691_t *router = VM_C2691(vm);        return(-1);
268    
269     if (vm->type == VM_TYPE_C2691)     *phys_addr = C2691_WIC_ADDR + (slot * C2691_WIC_SIZE);
270        c2691_save_config(router,(FILE *)opt);     return(0);
271  }  }
272    
273  void c2691_save_config_all(FILE *fd)  /* Set EEPROM for the specified slot */
274    int c2691_set_slot_eeprom(c2691_t *router,u_int slot,
275                              struct cisco_eeprom *eeprom)
276  {  {
277     registry_foreach_type(OBJ_TYPE_VM,c2691_reg_save_config,fd,NULL);     if (slot != 1)
278          return(-1);
279    
280       router->nm_eeprom_group.eeprom[0] = eeprom;
281       return(0);
282  }  }
283    
284  /* Get slot/port corresponding to specified network IRQ */  /* Get slot/port corresponding to specified network IRQ */
# Line 351  u_int c2691_net_irq_for_slot_port(u_int Line 301  u_int c2691_net_irq_for_slot_port(u_int
301     return(irq);     return(irq);
302  }  }
303    
 /* Set NM EEPROM definition */  
 int c2691_nm_set_eeprom(c2691_t *router,u_int nm_bay,  
                         const struct cisco_eeprom *eeprom)  
 {  
    if (nm_bay != 1) {  
       vm_error(router->vm,"c2691_nm_set_eeprom: invalid NM Bay %u.\n",nm_bay);  
       return(-1);  
    }  
     
    if (cisco_eeprom_copy(&router->nm_bay[nm_bay].eeprom,eeprom) == -1) {  
       vm_error(router->vm,"c2691_nm_set_eeprom: no memory.\n");  
       return(-1);  
    }  
     
    return(0);  
 }  
   
 /* Unset NM EEPROM definition (empty bay) */  
 int c2691_nm_unset_eeprom(c2691_t *router,u_int nm_bay)  
 {  
    if (nm_bay != 1) {  
       vm_error(router->vm,"c2691_nm_set_eeprom: invalid NM Bay %u.\n",nm_bay);  
       return(-1);  
    }  
     
    cisco_eeprom_free(&router->nm_bay[nm_bay].eeprom);  
    return(0);  
 }  
   
 /* Check if a bay has a port adapter */  
 int c2691_nm_check_eeprom(c2691_t *router,u_int nm_bay)  
 {  
    if (nm_bay != 1)  
       return(FALSE);  
   
    return(cisco_eeprom_valid(&router->nm_bay[nm_bay].eeprom));  
 }  
   
 /* Get bay info */  
 struct c2691_nm_bay *c2691_nm_get_info(c2691_t *router,u_int nm_bay)  
 {  
    if (nm_bay >= C2691_MAX_NM_BAYS)  
       return NULL;  
   
    return(&router->nm_bay[nm_bay]);  
 }  
   
 /* Get NM type */  
 char *c2691_nm_get_type(c2691_t *router,u_int nm_bay)  
 {  
    struct c2691_nm_bay *bay;  
   
    bay = c2691_nm_get_info(router,nm_bay);  
    return((bay != NULL) ? bay->dev_type : NULL);  
 }  
   
 /* Get driver info about the specified slot */  
 void *c2691_nm_get_drvinfo(c2691_t *router,u_int nm_bay)  
 {  
    struct c2691_nm_bay *bay;  
   
    bay = c2691_nm_get_info(router,nm_bay);  
    return((bay != NULL) ? bay->drv_info : NULL);  
 }  
   
 /* Set driver info for the specified slot */  
 int c2691_nm_set_drvinfo(c2691_t *router,u_int nm_bay,void *drv_info)  
 {  
    struct c2691_nm_bay *bay;  
   
    if (!(bay = c2691_nm_get_info(router,nm_bay)))  
       return(-1);  
   
    bay->drv_info = drv_info;  
    return(0);  
 }  
   
 /* Get a NM driver */  
 static struct c2691_nm_driver *c2691_nm_get_driver(char *dev_type)  
 {  
    int i;  
   
    for(i=0;nm_drivers[i];i++)  
       if (!strcmp(nm_drivers[i]->dev_type,dev_type))  
          return nm_drivers[i];  
   
    return NULL;  
 }  
   
 /* Add a NM binding */  
 int c2691_nm_add_binding(c2691_t *router,char *dev_type,u_int nm_bay)  
 {    
    struct c2691_nm_driver *nm_driver;  
    struct c2691_nm_bay *bay;  
   
    if (!(bay = c2691_nm_get_info(router,nm_bay)))  
       return(-1);  
   
    /* check that this bay is empty */  
    if (bay->dev_type != NULL) {  
       vm_error(router->vm,"a NM already exists in slot %u.\n",nm_bay);  
       return(-1);  
    }  
   
    /* find the NM driver */  
    if (!(nm_driver = c2691_nm_get_driver(dev_type))) {  
       vm_error(router->vm,"unknown NM type '%s'.\n",dev_type);  
       return(-1);  
    }  
   
    bay->dev_type = nm_driver->dev_type;  
    bay->nm_driver = nm_driver;  
    return(0);    
 }  
   
 /* Remove a NM binding */  
 int c2691_nm_remove_binding(c2691_t *router,u_int nm_bay)  
 {    
    struct c2691_nm_bay *bay;  
   
    if (!(bay = c2691_nm_get_info(router,nm_bay)))  
       return(-1);  
   
    /* stop if this bay is still active */  
    if (bay->drv_info != NULL) {  
       vm_error(router->vm,"slot %u still active.\n",nm_bay);  
       return(-1);  
    }  
   
    /* check that this bay is not empty */  
    if (bay->dev_type == NULL) {  
       vm_error(router->vm,"slot %u is empty.\n",nm_bay);  
       return(-1);  
    }  
     
    /* remove all NIOs bindings */  
    c2691_nm_remove_all_nio_bindings(router,nm_bay);  
   
    bay->dev_type  = NULL;  
    bay->nm_driver = NULL;  
    return(0);  
 }  
   
 /* Find a NIO binding */  
 struct c2691_nio_binding *  
 c2691_nm_find_nio_binding(c2691_t *router,u_int nm_bay,u_int port_id)  
 {    
    struct c2691_nio_binding *nb;  
    struct c2691_nm_bay *bay;  
   
    if (!(bay = c2691_nm_get_info(router,nm_bay)))  
       return NULL;  
   
    for(nb=bay->nio_list;nb;nb=nb->next)  
       if (nb->port_id == port_id)  
          return nb;  
   
    return NULL;  
 }  
   
 /* Add a network IO binding */  
 int c2691_nm_add_nio_binding(c2691_t *router,u_int nm_bay,u_int port_id,  
                              char *nio_name)  
 {  
    struct c2691_nio_binding *nb;  
    struct c2691_nm_bay *bay;  
    netio_desc_t *nio;  
   
    if (!(bay = c2691_nm_get_info(router,nm_bay)))  
       return(-1);  
   
    /* check that a NIO is not already bound to this port */  
    if (c2691_nm_find_nio_binding(router,nm_bay,port_id) != NULL) {  
       vm_error(router->vm,"a NIO already exists for interface %u/%u.\n",  
                nm_bay,port_id);  
       return(-1);  
    }  
   
    /* acquire a reference on the NIO object */  
    if (!(nio = netio_acquire(nio_name))) {  
       vm_error(router->vm,"unable to find NIO '%s'.\n",nio_name);  
       return(-1);  
    }  
   
    /* create a new binding */  
    if (!(nb = malloc(sizeof(*nb)))) {  
       vm_error(router->vm,"unable to create NIO binding "  
                "for interface %u/%u.\n",nm_bay,port_id);  
       netio_release(nio_name);  
       return(-1);  
    }  
   
    memset(nb,0,sizeof(*nb));  
    nb->nio       = nio;  
    nb->port_id   = port_id;  
    nb->next      = bay->nio_list;  
    if (nb->next) nb->next->prev = nb;  
    bay->nio_list = nb;  
    return(0);  
 }  
   
 /* Remove a NIO binding */  
 int c2691_nm_remove_nio_binding(c2691_t *router,u_int nm_bay,u_int port_id)  
 {  
    struct c2691_nio_binding *nb;  
    struct c2691_nm_bay *bay;  
     
    if (!(bay = c2691_nm_get_info(router,nm_bay)))  
       return(-1);  
   
    if (!(nb = c2691_nm_find_nio_binding(router,nm_bay,port_id)))  
       return(-1);   /* no nio binding for this slot/port */  
   
    /* tell the NM driver to stop using this NIO */  
    if (bay->nm_driver)  
       bay->nm_driver->nm_unset_nio(router,nm_bay,port_id);  
   
    /* remove this entry from the double linked list */  
    if (nb->next)  
       nb->next->prev = nb->prev;  
   
    if (nb->prev) {  
       nb->prev->next = nb->next;  
    } else {  
       bay->nio_list = nb->next;  
    }  
   
    /* unreference NIO object */  
    netio_release(nb->nio->name);  
    free(nb);  
    return(0);  
 }  
   
 /* Remove all NIO bindings for the specified NM */  
 int c2691_nm_remove_all_nio_bindings(c2691_t *router,u_int nm_bay)  
 {    
    struct c2691_nio_binding *nb,*next;  
    struct c2691_nm_bay *bay;  
   
    if (!(bay = c2691_nm_get_info(router,nm_bay)))  
       return(-1);  
   
    for(nb=bay->nio_list;nb;nb=next) {  
       next = nb->next;  
   
       /* tell the NM driver to stop using this NIO */  
       if (bay->nm_driver)  
          bay->nm_driver->nm_unset_nio(router,nm_bay,nb->port_id);  
   
       /* unreference NIO object */  
       netio_release(nb->nio->name);  
       free(nb);  
    }  
   
    bay->nio_list = NULL;  
    return(0);  
 }  
   
 /* Enable a Network IO descriptor for a Network Module */  
 int c2691_nm_enable_nio(c2691_t *router,u_int nm_bay,u_int port_id)  
 {  
    struct c2691_nio_binding *nb;  
    struct c2691_nm_bay *bay;  
   
    if (!(bay = c2691_nm_get_info(router,nm_bay)))  
       return(-1);  
   
    /* check that we have an NIO binding for this interface */  
    if (!(nb = c2691_nm_find_nio_binding(router,nm_bay,port_id)))  
       return(-1);  
   
    /* check that the driver is defined and successfully initialized */  
    if (!bay->nm_driver || !bay->drv_info)  
       return(-1);  
   
    return(bay->nm_driver->nm_set_nio(router,nm_bay,port_id,nb->nio));  
 }  
   
 /* Disable Network IO descriptor of a Network Module */  
 int c2691_nm_disable_nio(c2691_t *router,u_int nm_bay,u_int port_id)  
 {  
    struct c2691_nm_bay *bay;  
   
    if (!(bay = c2691_nm_get_info(router,nm_bay)))  
       return(-1);  
   
    /* check that the driver is defined and successfully initialized */  
    if (!bay->nm_driver || !bay->drv_info)  
       return(-1);  
   
    return(bay->nm_driver->nm_unset_nio(router,nm_bay,port_id));  
 }  
   
 /* Enable all NIO of the specified NM */  
 int c2691_nm_enable_all_nio(c2691_t *router,u_int nm_bay)  
 {  
    struct c2691_nio_binding *nb;  
    struct c2691_nm_bay *bay;  
   
    if (!(bay = c2691_nm_get_info(router,nm_bay)))  
       return(-1);  
   
    /* check that the driver is defined and successfully initialized */  
    if (!bay->nm_driver || !bay->drv_info)  
       return(-1);  
   
    for(nb=bay->nio_list;nb;nb=nb->next)  
       bay->nm_driver->nm_set_nio(router,nm_bay,nb->port_id,nb->nio);  
   
    return(0);  
 }  
   
 /* Disable all NIO of the specified NM */  
 int c2691_nm_disable_all_nio(c2691_t *router,u_int nm_bay)  
 {  
    struct c2691_nio_binding *nb;  
    struct c2691_nm_bay *bay;  
   
    if (!(bay = c2691_nm_get_info(router,nm_bay)))  
       return(-1);  
   
    /* check that the driver is defined and successfully initialized */  
    if (!bay->nm_driver || !bay->drv_info)  
       return(-1);  
   
    for(nb=bay->nio_list;nb;nb=nb->next)  
       bay->nm_driver->nm_unset_nio(router,nm_bay,nb->port_id);  
   
    return(0);  
 }  
   
 /* Initialize a Network Module */  
 int c2691_nm_init(c2691_t *router,u_int nm_bay)  
 {    
    struct c2691_nm_bay *bay;  
    size_t len;  
   
    if (!(bay = c2691_nm_get_info(router,nm_bay)))  
       return(-1);  
   
    /* Check that a device type is defined for this bay */  
    if (!bay->dev_type || !bay->nm_driver) {  
       vm_error(router->vm,"trying to init empty slot %u.\n",nm_bay);  
       return(-1);  
    }  
   
    /* Allocate device name */  
    len = strlen(bay->dev_type) + 10;  
    if (!(bay->dev_name = malloc(len))) {  
       vm_error(router->vm,"unable to allocate device name.\n");  
       return(-1);  
    }  
   
    snprintf(bay->dev_name,len,"%s(%u)",bay->dev_type,nm_bay);  
   
    /* Initialize NM driver */  
    if (bay->nm_driver->nm_init(router,bay->dev_name,nm_bay) == -1) {  
       vm_error(router->vm,"unable to initialize NM %u.\n",nm_bay);  
       return(-1);  
    }  
   
    /* Enable all NIO */  
    c2691_nm_enable_all_nio(router,nm_bay);  
    return(0);  
 }  
   
 /* Shutdown a Network Module */  
 int c2691_nm_shutdown(c2691_t *router,u_int nm_bay)  
 {  
    struct c2691_nm_bay *bay;  
   
    if (!(bay = c2691_nm_get_info(router,nm_bay)))  
       return(-1);  
   
    /* Check that a device type is defined for this bay */    
    if (!bay->dev_type || !bay->nm_driver) {  
       vm_error(router->vm,"trying to shut down empty slot %u.\n",nm_bay);  
       return(-1);  
    }  
   
    /* Disable all NIO */  
    c2691_nm_disable_all_nio(router,nm_bay);  
   
    /* Shutdown the NM driver */  
    if (bay->drv_info && (bay->nm_driver->nm_shutdown(router,nm_bay) == -1)) {  
       vm_error(router->vm,"unable to shutdown NM %u.\n",nm_bay);  
       return(-1);  
    }  
   
    free(bay->dev_name);  
    bay->dev_name = NULL;  
    bay->drv_info = NULL;  
    return(0);  
 }  
   
 /* Shutdown all NM of a router */  
 int c2691_nm_shutdown_all(c2691_t *router)  
 {  
    int i;  
   
    for(i=0;i<C2691_MAX_NM_BAYS;i++) {  
       if (!router->nm_bay[i].dev_type)  
          continue;  
   
       c2691_nm_shutdown(router,i);  
    }  
   
    return(0);  
 }  
   
 /* Show info about all NMs */  
 int c2691_nm_show_all_info(c2691_t *router)  
 {  
    struct c2691_nm_bay *bay;  
    int i;  
   
    for(i=0;i<C2691_MAX_NM_BAYS;i++) {  
       if (!(bay = c2691_nm_get_info(router,i)) || !bay->nm_driver)  
          continue;  
   
       if (bay->nm_driver->nm_show_info != NULL)  
          bay->nm_driver->nm_show_info(router,i);  
    }  
   
    return(0);  
 }  
   
 /* Maximum number of tokens in a NM description */  
 #define NM_DESC_MAX_TOKENS  8  
   
 /* Create a Network Module (command line) */  
 int c2691_cmd_nm_create(c2691_t *router,char *str)  
 {  
    char *tokens[NM_DESC_MAX_TOKENS];  
    int i,count,res;  
    u_int nm_bay;  
   
    /* A port adapter description is like "1:NM-1FE" */  
    if ((count = m_strsplit(str,':',tokens,NM_DESC_MAX_TOKENS)) != 2) {  
       vm_error(router->vm,"unable to parse NM description '%s'.\n",str);  
       return(-1);  
    }  
   
    /* Parse the NM bay id */  
    nm_bay = atoi(tokens[0]);  
   
    /* Add this new NM to the current NM list */  
    res = c2691_nm_add_binding(router,tokens[1],nm_bay);  
   
    /* The complete array was cleaned by strsplit */  
    for(i=0;i<NM_DESC_MAX_TOKENS;i++)  
       free(tokens[i]);  
   
    return(res);  
 }  
   
 /* Add a Network IO descriptor binding (command line) */  
 int c2691_cmd_add_nio(c2691_t *router,char *str)  
 {  
    char *tokens[NM_DESC_MAX_TOKENS];  
    int i,count,nio_type,res=-1;  
    u_int nm_bay,port_id;  
    netio_desc_t *nio;  
    char nio_name[128];  
   
    /* A port adapter description is like "1:3:tap:tap0" */  
    if ((count = m_strsplit(str,':',tokens,NM_DESC_MAX_TOKENS)) < 3) {  
       vm_error(router->vm,"unable to parse NIO description '%s'.\n",str);  
       return(-1);  
    }  
   
    /* Parse the NM bay */  
    nm_bay = atoi(tokens[0]);  
   
    /* Parse the NM port id */  
    port_id = atoi(tokens[1]);  
   
    /* Autogenerate a NIO name */  
    snprintf(nio_name,sizeof(nio_name),"c2691-i%u/%u/%u",  
             router->vm->instance_id,nm_bay,port_id);  
   
    /* Create the Network IO descriptor */  
    nio = NULL;  
    nio_type = netio_get_type(tokens[2]);  
   
    switch(nio_type) {  
       case NETIO_TYPE_UNIX:  
          if (count != 5) {  
             vm_error(router->vm,  
                      "invalid number of arguments for UNIX NIO '%s'\n",str);  
             goto done;  
          }  
   
          nio = netio_desc_create_unix(nio_name,tokens[3],tokens[4]);  
          break;  
   
       case NETIO_TYPE_VDE:  
          if (count != 5) {  
             vm_error(router->vm,  
                      "invalid number of arguments for VDE NIO '%s'\n",str);  
             goto done;  
          }  
   
          nio = netio_desc_create_vde(nio_name,tokens[3],tokens[4]);  
          break;  
   
       case NETIO_TYPE_TAP:  
          if (count != 4) {  
             vm_error(router->vm,  
                      "invalid number of arguments for TAP NIO '%s'\n",str);  
             goto done;  
          }  
   
          nio = netio_desc_create_tap(nio_name,tokens[3]);  
          break;  
   
       case NETIO_TYPE_UDP:  
          if (count != 6) {  
             vm_error(router->vm,  
                      "invalid number of arguments for UDP NIO '%s'\n",str);  
             goto done;  
          }  
   
          nio = netio_desc_create_udp(nio_name,atoi(tokens[3]),  
                                      tokens[4],atoi(tokens[5]));  
          break;  
   
       case NETIO_TYPE_TCP_CLI:  
          if (count != 5) {  
             vm_error(router->vm,  
                      "invalid number of arguments for TCP CLI NIO '%s'\n",str);  
             goto done;  
          }  
   
          nio = netio_desc_create_tcp_cli(nio_name,tokens[3],tokens[4]);  
          break;  
   
       case NETIO_TYPE_TCP_SER:  
          if (count != 4) {  
             vm_error(router->vm,  
                      "invalid number of arguments for TCP SER NIO '%s'\n",str);  
             goto done;  
          }  
   
          nio = netio_desc_create_tcp_ser(nio_name,tokens[3]);  
          break;  
   
       case NETIO_TYPE_NULL:  
          nio = netio_desc_create_null(nio_name);  
          break;  
   
 #ifdef LINUX_ETH  
       case NETIO_TYPE_LINUX_ETH:  
          if (count != 4) {  
             vm_error(router->vm,  
                      "invalid number of arguments for Linux Eth NIO '%s'\n",  
                      str);  
             goto done;  
          }  
           
          nio = netio_desc_create_lnxeth(nio_name,tokens[3]);  
          break;  
 #endif  
   
 #ifdef GEN_ETH  
       case NETIO_TYPE_GEN_ETH:  
          if (count != 4) {  
             vm_error(router->vm,  
                      "invalid number of arguments for Generic Eth NIO '%s'\n",  
                      str);  
             goto done;  
          }  
           
          nio = netio_desc_create_geneth(nio_name,tokens[3]);  
          break;  
 #endif  
   
       default:  
          vm_error(router->vm,"unknown NETIO type '%s'\n",tokens[2]);  
          goto done;  
    }  
   
    if (!nio) {  
       vm_error(router->vm,"unable to create NETIO "  
               "descriptor for NM slot %u\n",nm_bay);  
       goto done;  
    }  
   
    if (c2691_nm_add_nio_binding(router,nm_bay,port_id,nio_name) == -1) {  
       vm_error(router->vm,"unable to add NETIO binding for slot %u\n",nm_bay);  
       netio_release(nio_name);  
       netio_delete(nio_name);  
       goto done;  
    }  
     
    netio_release(nio_name);  
    res = 0;  
   
  done:  
    /* The complete array was cleaned by strsplit */  
    for(i=0;i<NM_DESC_MAX_TOKENS;i++)  
       free(tokens[i]);  
   
    return(res);  
 }  
   
 /* Show the list of available NM drivers */  
 void c2691_nm_show_drivers(void)  
 {  
    int i;  
   
    printf("Available C2691 Network Module drivers:\n");  
   
    for(i=0;nm_drivers[i];i++) {  
       printf("  * %s %s\n",  
              nm_drivers[i]->dev_type,  
              !nm_drivers[i]->supported ? "(NOT WORKING)" : "");  
    }  
     
    printf("\n");  
 }  
   
304  /* Set the base MAC address of the chassis */  /* Set the base MAC address of the chassis */
305  static int c2691_burn_mac_addr(c2691_t *router,n_eth_addr_t *addr)  static int c2691_burn_mac_addr(c2691_t *router,n_eth_addr_t *addr)
306  {  {
# Line 1020  int c2691_chassis_set_mac_addr(c2691_t * Line 348  int c2691_chassis_set_mac_addr(c2691_t *
348  static int c2691_init_gt96100(c2691_t *router)  static int c2691_init_gt96100(c2691_t *router)
349  {  {
350     vm_instance_t *vm = router->vm;     vm_instance_t *vm = router->vm;
351       vm_obj_t *obj;
352    
353     vm->pci_bus[0] = pci_bus_create("PCI bus #0",0);     vm->pci_bus[0] = pci_bus_create("PCI bus #0",0);
354     vm->pci_bus[1] = pci_bus_create("PCI bus #1",0);     vm->pci_bus[1] = pci_bus_create("PCI bus #1",0);
# Line 1029  static int c2691_init_gt96100(c2691_t *r Line 358  static int c2691_init_gt96100(c2691_t *r
358        return(-1);        return(-1);
359     }     }
360        
361     return(dev_gt96100_init(vm,"gt96100",C2691_GT96K_ADDR,0x200000,     if (dev_gt96100_init(vm,"gt96100",C2691_GT96K_ADDR,0x200000,
362                             C2691_GT96K_IRQ,c2691_net_irq_for_slot_port(0,0)));                          C2691_GT96K_IRQ,
363                            C2691_EXT_IRQ,
364                            c2691_net_irq_for_slot_port(0,0),
365                            255) == -1)
366          return(-1);
367    
368       if (!(obj = vm_object_find(router->vm,"gt96100")))
369          return(-1);
370    
371       router->gt_data = obj->data;
372       return(0);
373  }  }
374    
375  /* Initialize a Cisco 2691 */  /* Initialize a Cisco 2691 */
# Line 1046  static int c2691_init(c2691_t *router) Line 385  static int c2691_init(c2691_t *router)
385        return(-1);        return(-1);
386    
387     /* Initialize PCI map (NM slot 1) */     /* Initialize PCI map (NM slot 1) */
388     router->nm_bay[1].pci_map = vm->pci_bus[1];     vm->slots_pci_bus[1] = vm->pci_bus[1];
389    
390     vm->elf_machine_id = C2691_ELF_MACHINE_ID;     vm->elf_machine_id = C2691_ELF_MACHINE_ID;
391     return(0);     return(0);
# Line 1073  void c2691_show_hardware(c2691_t *router Line 412  void c2691_show_hardware(c2691_t *router
412  }  }
413    
414  /* Initialize default parameters for a C2691 */  /* Initialize default parameters for a C2691 */
415  void c2691_init_defaults(c2691_t *router)  static void c2691_init_defaults(c2691_t *router)
416  {    {  
417     vm_instance_t *vm = router->vm;       vm_instance_t *vm = router->vm;  
418     n_eth_addr_t *m;     n_eth_addr_t *m;
419     m_uint16_t pid;     m_uint16_t pid;
420    
421       /* Set platform slots characteristics */
422       vm->nr_slots   = C2691_MAX_NM_BAYS;
423       vm->slots_type = CISCO_CARD_TYPE_NM;
424       vm->slots_drivers = nm_drivers;
425    
426     pid = (m_uint16_t)getpid();     pid = (m_uint16_t)getpid();
427    
428     /* Generate a chassis MAC address based on the instance ID */     /* Generate a chassis MAC address based on the instance ID */
# Line 1094  void c2691_init_defaults(c2691_t *router Line 438  void c2691_init_defaults(c2691_t *router
438     cisco_eeprom_copy(&router->mb_eeprom,&eeprom_c2691_mainboard);     cisco_eeprom_copy(&router->mb_eeprom,&eeprom_c2691_mainboard);
439     c2691_burn_mac_addr(router,&router->mac_addr);     c2691_burn_mac_addr(router,&router->mac_addr);
440    
441       /* The GT96100 system controller has 2 integrated FastEthernet ports */
442       vm_slot_add_binding(vm,"GT96100-FE",0,0);
443    
444     vm->ram_mmap          = C2691_DEFAULT_RAM_MMAP;     vm->ram_mmap          = C2691_DEFAULT_RAM_MMAP;
445     vm->ram_size          = C2691_DEFAULT_RAM_SIZE;     vm->ram_size          = C2691_DEFAULT_RAM_SIZE;
446     vm->rom_size          = C2691_DEFAULT_ROM_SIZE;     vm->rom_size          = C2691_DEFAULT_ROM_SIZE;
# Line 1101  void c2691_init_defaults(c2691_t *router Line 448  void c2691_init_defaults(c2691_t *router
448     vm->conf_reg_setup    = C2691_DEFAULT_CONF_REG;     vm->conf_reg_setup    = C2691_DEFAULT_CONF_REG;
449     vm->clock_divisor     = C2691_DEFAULT_CLOCK_DIV;     vm->clock_divisor     = C2691_DEFAULT_CLOCK_DIV;
450     vm->nvram_rom_space   = C2691_NVRAM_ROM_RES_SIZE;     vm->nvram_rom_space   = C2691_NVRAM_ROM_RES_SIZE;
451     router->nm_iomem_size = C2691_DEFAULT_IOMEM_SIZE;     vm->nm_iomem_size     = C2691_DEFAULT_IOMEM_SIZE;
452    
453     vm->pcmcia_disk_size[0] = C2691_DEFAULT_DISK0_SIZE;     vm->pcmcia_disk_size[0] = C2691_DEFAULT_DISK0_SIZE;
454     vm->pcmcia_disk_size[1] = C2691_DEFAULT_DISK1_SIZE;     vm->pcmcia_disk_size[1] = C2691_DEFAULT_DISK1_SIZE;
   
    /* Enable NVRAM operations to load/store configs */  
    vm->nvram_extract_config = c2691_nvram_extract_config;  
    vm->nvram_push_config = c2691_nvram_push_config;  
455  }  }
456    
457  /* Initialize the C2691 Platform */  /* Initialize the C2691 Platform */
458  int c2691_init_platform(c2691_t *router)  static int c2691_init_platform(c2691_t *router)
459  {  {
460     vm_instance_t *vm = router->vm;     vm_instance_t *vm = router->vm;
    struct c2691_nm_bay *nm_bay;  
461     cpu_mips_t *cpu;     cpu_mips_t *cpu;
462     cpu_gen_t *gen;     cpu_gen_t *gen;
463     vm_obj_t *obj;     vm_obj_t *obj;
    int i;  
464    
465     /* Copy config register setup into "active" config register */     /* Copy config register setup into "active" config register */
466     vm->conf_reg = vm->conf_reg_setup;     vm->conf_reg = vm->conf_reg_setup;
# Line 1192  int c2691_init_platform(c2691_t *router) Line 533  int c2691_init_platform(c2691_t *router)
533     dev_flash_copy_data(obj,0,mips64_microcode,mips64_microcode_len);     dev_flash_copy_data(obj,0,mips64_microcode,mips64_microcode_len);
534     c2691_nvram_check_empty_config(vm);     c2691_nvram_check_empty_config(vm);
535    
536       /* Byte swapping */
537       dev_bswap_init(vm,"mem_bswap",C2691_BSWAP_ADDR,1024*1048576,0x00000000ULL);
538    
539     /* Initialize the NS16552 DUART */     /* Initialize the NS16552 DUART */
540     dev_ns16552_init(vm,C2691_DUART_ADDR,0x1000,3,C2691_DUART_IRQ,     dev_ns16552_init(vm,C2691_DUART_ADDR,0x1000,3,C2691_DUART_IRQ,
541                      vm->vtty_con,vm->vtty_aux);                      vm->vtty_con,vm->vtty_aux);
# Line 1204  int c2691_init_platform(c2691_t *router) Line 548  int c2691_init_platform(c2691_t *router)
548     dev_pcmcia_disk_init(vm,"slot1",C2691_SLOT1_ADDR,0x200000,     dev_pcmcia_disk_init(vm,"slot1",C2691_SLOT1_ADDR,0x200000,
549                          vm->pcmcia_disk_size[1],1);                          vm->pcmcia_disk_size[1],1);
550    
    /* The GT96100 system controller has 2 integrated FastEthernet ports */  
    c2691_nm_add_binding(router,"GT96100-FE",0);  
   
551     /* Initialize Network Modules */     /* Initialize Network Modules */
552     for(i=0;i<C2691_MAX_NM_BAYS;i++) {     if (vm_slot_init_all(vm) == -1)
553        nm_bay = &router->nm_bay[i];        return(-1);
   
       if (!nm_bay->dev_type)  
          continue;  
   
       if (c2691_nm_init(router,i) == -1) {  
          vm_error(vm,"unable to create Network Module \"%s\"\n",  
                   nm_bay->dev_type);  
          return(-1);  
       }  
    }  
554    
555     /* Show device list */     /* Show device list */
556     c2691_show_hardware(router);     c2691_show_hardware(router);
# Line 1227  int c2691_init_platform(c2691_t *router) Line 558  int c2691_init_platform(c2691_t *router)
558  }  }
559    
560  /* Boot the IOS image */  /* Boot the IOS image */
561  int c2691_boot_ios(c2691_t *router)  static int c2691_boot_ios(c2691_t *router)
562  {    {  
563     vm_instance_t *vm = router->vm;     vm_instance_t *vm = router->vm;
564     cpu_mips_t *cpu;     cpu_mips_t *cpu;
# Line 1318  static void c2691_clear_irq(vm_instance_ Line 649  static void c2691_clear_irq(vm_instance_
649  }  }
650    
651  /* Initialize a Cisco 2691 instance */  /* Initialize a Cisco 2691 instance */
652  int c2691_init_instance(c2691_t *router)  static int c2691_init_instance(vm_instance_t *vm)
653  {    {
654     vm_instance_t *vm = router->vm;     c2691_t *router = VM_C2691(vm);
655     m_uint32_t rom_entry_point;     m_uint32_t rom_entry_point;
656     cpu_mips_t *cpu0;     cpu_mips_t *cpu0;
657    
# Line 1367  int c2691_init_instance(c2691_t *router) Line 698  int c2691_init_instance(c2691_t *router)
698  }  }
699    
700  /* Stop a Cisco 2691 instance */  /* Stop a Cisco 2691 instance */
701  int c2691_stop_instance(c2691_t *router)  static int c2691_stop_instance(vm_instance_t *vm)
702  {  {
    vm_instance_t *vm = router->vm;  
   
703     printf("\nC2691 '%s': stopping simulation.\n",vm->name);     printf("\nC2691 '%s': stopping simulation.\n",vm->name);
704     vm_log(vm,"C2691_STOP","stopping simulation.\n");     vm_log(vm,"C2691_STOP","stopping simulation.\n");
705    
# Line 1385  int c2691_stop_instance(c2691_t *router) Line 714  int c2691_stop_instance(c2691_t *router)
714     }     }
715    
716     /* Free resources that were used during execution to emulate hardware */     /* Free resources that were used during execution to emulate hardware */
717     c2691_nm_shutdown_all(router);     vm_slot_shutdown_all(vm);
718     vm_hardware_shutdown(vm);     vm_hardware_shutdown(vm);
719     return(0);     return(0);
720  }  }
721    
722    /* Get MAC address MSB */
723    static u_int c2691_get_mac_addr_msb(void)
724    {
725       return(0xC0);
726    }
727    
728    /* Parse specific options for the Cisco 1700 platform */
729    static int c2691_cli_parse_options(vm_instance_t *vm,int option)
730    {
731       switch(option) {
732          /* IO memory reserved for NMs (in percents!) */
733          case OPT_IOMEM_SIZE:
734             vm->nm_iomem_size = 0x8000 | atoi(optarg);
735             break;
736    
737          /* Unknown option */
738          default:
739             return(-1);
740       }
741    
742       return(0);
743    }
744    
745    /* Show specific CLI options */
746    static void c2691_cli_show_options(vm_instance_t *vm)
747    {
748       printf("  --iomem-size <val> : IO memory (in percents, default: %u)\n"
749              "  -p <nm_desc>       : Define a Network Module\n"
750              "  -s <nm_nio>        : Bind a Network IO interface to a "
751              "Network Module\n",
752              vm->nm_iomem_size);
753    }
754    
755    /* Platform definition */
756    static vm_platform_t c2691_platform = {
757       "c2691", "C2691", "2691",
758       c2691_create_instance,
759       c2691_delete_instance,
760       c2691_init_instance,
761       c2691_stop_instance,
762       c2691_nvram_extract_config,
763       c2691_nvram_push_config,
764       c2691_get_mac_addr_msb,
765       NULL,
766       c2691_cli_parse_options,
767       c2691_cli_show_options,
768       NULL,
769    };
770    
771    /* Register the c2691 platform */
772    int c2691_platform_register(void)
773    {
774       if (vm_platform_register(&c2691_platform) == -1)
775          return(-1);
776    
777       return(hypervisor_c2691_init(&c2691_platform));
778    }

Legend:
Removed from v.10  
changed lines
  Added in v.11

  ViewVC Help
Powered by ViewVC 1.1.26