/[dynamips]/upstream/dynamips-0.2.8-RC1/dev_c3745.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 /upstream/dynamips-0.2.8-RC1/dev_c3745.c

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

upstream/dynamips-0.2.7/dev_c3745.c revision 10 by dpavlin, Sat Oct 6 16:29:14 2007 UTC upstream/dynamips-0.2.8-RC1/dev_c3745.c revision 11 by dpavlin, Sat Oct 6 16:33:40 2007 UTC
# Line 88  struct cisco_eeprom eeprom_c3745_midplan Line 88  struct cisco_eeprom eeprom_c3745_midplan
88  /* ======================================================================== */  /* ======================================================================== */
89  /* Network Module Drivers                                                   */  /* Network Module Drivers                                                   */
90  /* ======================================================================== */  /* ======================================================================== */
91  static struct c3745_nm_driver *nm_drivers[] = {  static struct cisco_card_driver *nm_drivers[] = {
92     &dev_c3745_nm_1fe_tx_driver,     &dev_c3745_nm_1fe_tx_driver,
93     &dev_c3745_nm_16esw_driver,     &dev_c3745_nm_16esw_driver,
94     &dev_c3745_gt96100_fe_driver,     &dev_c3745_gt96100_fe_driver,
95     &dev_c3745_nm_4t_driver,     &dev_c3745_nm_4t_driver,
96       &dev_c3745_nm_nam_driver,
97       &dev_c3745_nm_cids_driver,
98     NULL,     NULL,
99  };  };
100    
# Line 100  static struct c3745_nm_driver *nm_driver Line 102  static struct c3745_nm_driver *nm_driver
102  /* Cisco 3745 router instances                                              */  /* Cisco 3745 router instances                                              */
103  /* ======================================================================== */  /* ======================================================================== */
104    
105    /* Initialize default parameters for a C3745 */
106    static void c3745_init_defaults(c3745_t *router);
107    
108  /* Directly extract the configuration from the NVRAM device */  /* Directly extract the configuration from the NVRAM device */
109  ssize_t c3745_nvram_extract_config(vm_instance_t *vm,char **buffer)  static ssize_t c3745_nvram_extract_config(vm_instance_t *vm,u_char **buffer)
110  {    {  
111     u_char *base_ptr,*ios_ptr,*cfg_ptr,*end_ptr;     u_char *base_ptr,*ios_ptr,*cfg_ptr,*end_ptr;
112     m_uint32_t start,nvlen;     m_uint32_t start,nvlen;
# Line 156  ssize_t c3745_nvram_extract_config(vm_in Line 161  ssize_t c3745_nvram_extract_config(vm_in
161  }  }
162    
163  static int c3745_nvram_push_config_part(vm_instance_t *vm,  static int c3745_nvram_push_config_part(vm_instance_t *vm,
164                                          char *buffer,size_t len,                                          u_char *buffer,size_t len,
165                                          u_char *ios_ptr)                                          u_char *ios_ptr)
166  {  {
167     m_uint32_t cfg_offset,cklen,tmp;     m_uint32_t cfg_offset,cklen,tmp;
# Line 191  static int c3745_nvram_push_config_part( Line 196  static int c3745_nvram_push_config_part(
196  }  }
197    
198  /* Directly push the IOS configuration to the NVRAM device */  /* Directly push the IOS configuration to the NVRAM device */
199  int c3745_nvram_push_config(vm_instance_t *vm,char *buffer,size_t len)  static int c3745_nvram_push_config(vm_instance_t *vm,u_char *buffer,size_t len)
200  {  {
201     u_char *base_ptr,*ios_ptr;     u_char *base_ptr,*ios_ptr;
202     int fd;     int fd;
# Line 214  int c3745_nvram_push_config(vm_instance_ Line 219  int c3745_nvram_push_config(vm_instance_
219  }  }
220    
221  /* Check for empty config */  /* Check for empty config */
222  int c3745_nvram_check_empty_config(vm_instance_t *vm)  static int c3745_nvram_check_empty_config(vm_instance_t *vm)
223  {  {
224     struct vdevice *rom_dev;     struct vdevice *rom_dev;
225     m_uint64_t addr;     m_uint64_t addr;
# Line 241  int c3745_nvram_check_empty_config(vm_in Line 246  int c3745_nvram_check_empty_config(vm_in
246  }  }
247    
248  /* Create a new router instance */  /* Create a new router instance */
249  c3745_t *c3745_create_instance(char *name,int instance_id)  static int c3745_create_instance(vm_instance_t *vm)
250  {  {
251     c3745_t *router;     c3745_t *router;
252    
253     if (!(router = malloc(sizeof(*router)))) {     if (!(router = malloc(sizeof(*router)))) {
254        fprintf(stderr,"C3745 '%s': Unable to create new instance!\n",name);        fprintf(stderr,"C3745 '%s': Unable to create new instance!\n",vm->name);
255        return NULL;        return(-1);
256     }     }
257    
258     memset(router,0,sizeof(*router));     memset(router,0,sizeof(*router));
259       router->vm = vm;
260     if (!(router->vm = vm_create(name,instance_id,VM_TYPE_C3745))) {     vm->hw_data = router;
       fprintf(stderr,"C3745 '%s': unable to create VM instance!\n",name);  
       goto err_vm;  
    }  
261    
262     c3745_init_defaults(router);     c3745_init_defaults(router);
263     router->vm->hw_data = router;     return(0);
    return router;  
   
  err_vm:  
    free(router);  
    return NULL;  
264  }  }
265    
266  /* Free resources used by a router instance */  /* Free resources used by a router instance */
267  static int c3745_free_instance(void *data,void *arg)  static int c3745_delete_instance(vm_instance_t *vm)
268  {  {
269     vm_instance_t *vm = data;     c3745_t *router = VM_C3745(vm);
    c3745_t *router;  
270     int i;     int i;
271    
272     if (vm->type == VM_TYPE_C3745) {     /* Stop all CPUs */
273        router = VM_C3745(vm);     if (vm->cpu_group != NULL) {
274          vm_stop(vm);
       /* Stop all CPUs */  
       if (vm->cpu_group != NULL) {  
          vm_stop(vm);  
275                
276           if (cpu_group_sync_state(vm->cpu_group) == -1) {        if (cpu_group_sync_state(vm->cpu_group) == -1) {
277              vm_error(vm,"unable to sync with system CPUs.\n");           vm_error(vm,"unable to sync with system CPUs.\n");
278              return(FALSE);           return(FALSE);
          }  
279        }        }
   
       /* Remove NIO bindings */  
       for(i=0;i<C3745_MAX_NM_BAYS;i++)  
          c3745_nm_remove_all_nio_bindings(router,i);  
   
       /* Shutdown all Network Modules */  
       c3745_nm_shutdown_all(router);  
   
       /* Free mainboard EEPROM */  
       for(i=0;i<3;i++)  
          cisco_eeprom_free(&router->sys_eeprom[i]);  
   
       /* Free all resources used by VM */  
       vm_free(vm);  
   
       /* Free the router structure */  
       free(router);  
       return(TRUE);  
280     }     }
281    
282     return(FALSE);     /* Remove NIO bindings */
283  }     for(i=0;i<vm->nr_slots;i++)
284          vm_slot_remove_all_nio_bindings(vm,i);
285  /* Delete a router instance */    
286  int c3745_delete_instance(char *name)     /* Shutdown all Network Modules */
287  {     vm_slot_shutdown_all(vm);
288     return(registry_delete_if_unused(name,OBJ_TYPE_VM,    
289                                      c3745_free_instance,NULL));     /* Free mainboard EEPROM */
290  }     for(i=0;i<3;i++)
291          cisco_eeprom_free(&router->sys_eeprom[i]);
292      
293       /* Free all resources used by VM */
294       vm_free(vm);
295    
296  /* Delete all router instances */     /* Free the router structure */
297  int c3745_delete_all_instances(void)     free(router);
298  {     return(TRUE);
    return(registry_delete_type(OBJ_TYPE_VM,c3745_free_instance,NULL));  
299  }  }
300    
301  /* Save configuration of a C3745 instance */  /* Get WIC device address for the specified onboard port */
302  void c3745_save_config(c3745_t *router,FILE *fd)  int c3745_get_onboard_wic_addr(u_int slot,m_uint64_t *phys_addr)
303  {  {
304     vm_instance_t *vm = router->vm;     if (slot >= C3745_MAX_WIC_BAYS)
305     struct c3745_nio_binding *nb;        return(-1);
    struct c3745_nm_bay *bay;  
    int i;  
   
    /* General settings */  
    fprintf(fd,"c3745 create %s %u\n",vm->name,vm->instance_id);  
   
    /* VM configuration */  
    vm_save_config(vm,fd);  
   
    /* Network Module settings */  
    for(i=0;i<C3745_MAX_NM_BAYS;i++) {  
       if (!(bay = c3745_nm_get_info(router,i)))  
          continue;  
   
       if (bay->dev_type) {  
          fprintf(fd,"c3745 add_nm_binding %s %u %s\n",  
                  vm->name,i,bay->dev_type);  
       }  
   
       for(nb=bay->nio_list;nb;nb=nb->next) {  
          fprintf(fd,"c3745 add_nio_binding %s %u %u %s\n",  
                  vm->name,i,nb->port_id,nb->nio->name);  
       }  
    }  
306    
307     fprintf(fd,"\n");     *phys_addr = C3745_WIC_ADDR + (slot * C3745_WIC_SIZE);
308       return(0);
309  }  }
310    
311  /* Save configurations of all C3745 instances */  /* Set EEPROM for the specified slot */
312  static void c3745_reg_save_config(registry_entry_t *entry,void *opt,int *err)  int c3745_set_slot_eeprom(c3745_t *router,u_int slot,
313                              struct cisco_eeprom *eeprom)
314  {  {
315     vm_instance_t *vm = entry->data;     if ((slot < 1) || (slot >= C3745_MAX_NM_BAYS))
316     c3745_t *router = VM_C3745(vm);        return(-1);
   
    if (vm->type == VM_TYPE_C3745)  
       c3745_save_config(router,(FILE *)opt);  
 }  
317    
318  void c3745_save_config_all(FILE *fd)     router->nm_eeprom_group[slot-1].eeprom[0] = eeprom;
319  {     return(0);
    registry_foreach_type(OBJ_TYPE_VM,c3745_reg_save_config,fd,NULL);  
320  }  }
321    
322  /* Get slot/port corresponding to specified network IRQ */  /* Get slot/port corresponding to specified network IRQ */
# Line 389  u_int c3745_net_irq_for_slot_port(u_int Line 339  u_int c3745_net_irq_for_slot_port(u_int
339     return(irq);     return(irq);
340  }  }
341    
 /* Set NM EEPROM definition */  
 int c3745_nm_set_eeprom(c3745_t *router,u_int nm_bay,  
                         const struct cisco_eeprom *eeprom)  
 {  
    if (!nm_bay || (nm_bay >= C3745_MAX_NM_BAYS)) {  
       vm_error(router->vm,"c3745_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,"c3745_nm_set_eeprom: no memory.\n");  
       return(-1);  
    }  
     
    return(0);  
 }  
   
 /* Unset NM EEPROM definition (empty bay) */  
 int c3745_nm_unset_eeprom(c3745_t *router,u_int nm_bay)  
 {  
    if (!nm_bay || (nm_bay >= C3745_MAX_NM_BAYS)) {  
       vm_error(router->vm,"c3745_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 c3745_nm_check_eeprom(c3745_t *router,u_int nm_bay)  
 {  
    if (!nm_bay || (nm_bay >= C3745_MAX_NM_BAYS))  
       return(FALSE);  
   
    return(cisco_eeprom_valid(&router->nm_bay[nm_bay].eeprom));  
 }  
   
 /* Get bay info */  
 struct c3745_nm_bay *c3745_nm_get_info(c3745_t *router,u_int nm_bay)  
 {  
    if (nm_bay >= C3745_MAX_NM_BAYS)  
       return NULL;  
   
    return(&router->nm_bay[nm_bay]);  
 }  
   
 /* Get NM type */  
 char *c3745_nm_get_type(c3745_t *router,u_int nm_bay)  
 {  
    struct c3745_nm_bay *bay;  
   
    bay = c3745_nm_get_info(router,nm_bay);  
    return((bay != NULL) ? bay->dev_type : NULL);  
 }  
   
 /* Get driver info about the specified slot */  
 void *c3745_nm_get_drvinfo(c3745_t *router,u_int nm_bay)  
 {  
    struct c3745_nm_bay *bay;  
   
    bay = c3745_nm_get_info(router,nm_bay);  
    return((bay != NULL) ? bay->drv_info : NULL);  
 }  
   
 /* Set driver info for the specified slot */  
 int c3745_nm_set_drvinfo(c3745_t *router,u_int nm_bay,void *drv_info)  
 {  
    struct c3745_nm_bay *bay;  
   
    if (!(bay = c3745_nm_get_info(router,nm_bay)))  
       return(-1);  
   
    bay->drv_info = drv_info;  
    return(0);  
 }  
   
 /* Get a NM driver */  
 static struct c3745_nm_driver *c3745_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 c3745_nm_add_binding(c3745_t *router,char *dev_type,u_int nm_bay)  
 {    
    struct c3745_nm_driver *nm_driver;  
    struct c3745_nm_bay *bay;  
   
    if (!(bay = c3745_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 = c3745_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 c3745_nm_remove_binding(c3745_t *router,u_int nm_bay)  
 {    
    struct c3745_nm_bay *bay;  
   
    if (!(bay = c3745_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 */  
    c3745_nm_remove_all_nio_bindings(router,nm_bay);  
   
    bay->dev_type  = NULL;  
    bay->nm_driver = NULL;  
    return(0);  
 }  
   
 /* Find a NIO binding */  
 struct c3745_nio_binding *  
 c3745_nm_find_nio_binding(c3745_t *router,u_int nm_bay,u_int port_id)  
 {    
    struct c3745_nio_binding *nb;  
    struct c3745_nm_bay *bay;  
   
    if (!(bay = c3745_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 c3745_nm_add_nio_binding(c3745_t *router,u_int nm_bay,u_int port_id,  
                              char *nio_name)  
 {  
    struct c3745_nio_binding *nb;  
    struct c3745_nm_bay *bay;  
    netio_desc_t *nio;  
   
    if (!(bay = c3745_nm_get_info(router,nm_bay)))  
       return(-1);  
   
    /* check that a NIO is not already bound to this port */  
    if (c3745_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 c3745_nm_remove_nio_binding(c3745_t *router,u_int nm_bay,u_int port_id)  
 {  
    struct c3745_nio_binding *nb;  
    struct c3745_nm_bay *bay;  
     
    if (!(bay = c3745_nm_get_info(router,nm_bay)))  
       return(-1);  
   
    if (!(nb = c3745_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 c3745_nm_remove_all_nio_bindings(c3745_t *router,u_int nm_bay)  
 {    
    struct c3745_nio_binding *nb,*next;  
    struct c3745_nm_bay *bay;  
   
    if (!(bay = c3745_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 c3745_nm_enable_nio(c3745_t *router,u_int nm_bay,u_int port_id)  
 {  
    struct c3745_nio_binding *nb;  
    struct c3745_nm_bay *bay;  
   
    if (!(bay = c3745_nm_get_info(router,nm_bay)))  
       return(-1);  
   
    /* check that we have an NIO binding for this interface */  
    if (!(nb = c3745_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 c3745_nm_disable_nio(c3745_t *router,u_int nm_bay,u_int port_id)  
 {  
    struct c3745_nm_bay *bay;  
   
    if (!(bay = c3745_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 c3745_nm_enable_all_nio(c3745_t *router,u_int nm_bay)  
 {  
    struct c3745_nio_binding *nb;  
    struct c3745_nm_bay *bay;  
   
    if (!(bay = c3745_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 c3745_nm_disable_all_nio(c3745_t *router,u_int nm_bay)  
 {  
    struct c3745_nio_binding *nb;  
    struct c3745_nm_bay *bay;  
   
    if (!(bay = c3745_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 c3745_nm_init(c3745_t *router,u_int nm_bay)  
 {    
    struct c3745_nm_bay *bay;  
    size_t len;  
   
    if (!(bay = c3745_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 */  
    c3745_nm_enable_all_nio(router,nm_bay);  
    return(0);  
 }  
   
 /* Shutdown a Network Module */  
 int c3745_nm_shutdown(c3745_t *router,u_int nm_bay)  
 {  
    struct c3745_nm_bay *bay;  
   
    if (!(bay = c3745_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 */  
    c3745_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 c3745_nm_shutdown_all(c3745_t *router)  
 {  
    int i;  
   
    for(i=0;i<C3745_MAX_NM_BAYS;i++) {  
       if (!router->nm_bay[i].dev_type)  
          continue;  
   
       c3745_nm_shutdown(router,i);  
    }  
   
    return(0);  
 }  
   
 /* Show info about all NMs */  
 int c3745_nm_show_all_info(c3745_t *router)  
 {  
    struct c3745_nm_bay *bay;  
    int i;  
   
    for(i=0;i<C3745_MAX_NM_BAYS;i++) {  
       if (!(bay = c3745_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 c3745_cmd_nm_create(c3745_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 = c3745_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 c3745_cmd_add_nio(c3745_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),"c3745-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 (c3745_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 c3745_nm_show_drivers(void)  
 {  
    int i;  
   
    printf("Available C3745 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");  
 }  
   
342  /* Set the base MAC address of the chassis */  /* Set the base MAC address of the chassis */
343  static int c3745_burn_mac_addr(c3745_t *router,n_eth_addr_t *addr)  static int c3745_burn_mac_addr(c3745_t *router,n_eth_addr_t *addr)
344  {  {
# Line 1060  int c3745_chassis_set_mac_addr(c3745_t * Line 388  int c3745_chassis_set_mac_addr(c3745_t *
388  static int c3745_init_gt96100(c3745_t *router)  static int c3745_init_gt96100(c3745_t *router)
389  {  {
390     vm_instance_t *vm = router->vm;     vm_instance_t *vm = router->vm;
391       vm_obj_t *obj;
392    
393     vm->pci_bus[0] = pci_bus_create("PCI bus #0",0);     vm->pci_bus[0] = pci_bus_create("PCI bus #0",0);
394     vm->pci_bus[1] = pci_bus_create("PCI bus #1",0);     vm->pci_bus[1] = pci_bus_create("PCI bus #1",0);
# Line 1069  static int c3745_init_gt96100(c3745_t *r Line 398  static int c3745_init_gt96100(c3745_t *r
398        return(-1);        return(-1);
399     }     }
400        
401     return(dev_gt96100_init(vm,"gt96100",C3745_GT96K_ADDR,0x200000,     if (dev_gt96100_init(vm,"gt96100",C3745_GT96K_ADDR,0x200000,
402                             C3745_GT96K_IRQ,c3745_net_irq_for_slot_port(0,0)));                          C3745_GT96K_IRQ,
403                            C3745_EXT_IRQ,
404                            c3745_net_irq_for_slot_port(0,0),
405                            255) == -1)
406          return(-1);
407    
408       if (!(obj = vm_object_find(router->vm,"gt96100")))
409          return(-1);
410    
411       router->gt_data = obj->data;
412       return(0);
413  }  }
414    
415  /* Initialize a Cisco 3745 */  /* Initialize a Cisco 3745 */
# Line 1093  static int c3745_init(c3745_t *router) Line 432  static int c3745_init(c3745_t *router)
432        vm->pci_bus_pool[i] = pci_bus_create(bus_name,-1);        vm->pci_bus_pool[i] = pci_bus_create(bus_name,-1);
433    
434        /* Map the NM PCI bus */        /* Map the NM PCI bus */
435        router->nm_bay[i].pci_map = vm->pci_bus_pool[i];        vm->slots_pci_bus[i] = vm->pci_bus_pool[i];
436    
437        /* Create the PCI bridge */        /* Create the PCI bridge */
438        dev_ti2050b_init(vm->pci_bus[1],i,router->nm_bay[i].pci_map);        dev_ti2050b_init(vm->pci_bus[1],i,vm->slots_pci_bus[i]);
439     }     }
440    
441     vm->elf_machine_id = C3745_ELF_MACHINE_ID;     vm->elf_machine_id = C3745_ELF_MACHINE_ID;
# Line 1124  void c3745_show_hardware(c3745_t *router Line 463  void c3745_show_hardware(c3745_t *router
463  }  }
464    
465  /* Initialize default parameters for a C3745 */  /* Initialize default parameters for a C3745 */
466  void c3745_init_defaults(c3745_t *router)  static void c3745_init_defaults(c3745_t *router)
467  {    {  
468     vm_instance_t *vm = router->vm;       vm_instance_t *vm = router->vm;  
469     n_eth_addr_t *m;     n_eth_addr_t *m;
470     m_uint16_t pid;     m_uint16_t pid;
471    
472       /* Set platform slots characteristics */
473       vm->nr_slots   = C3745_MAX_NM_BAYS;
474       vm->slots_type = CISCO_CARD_TYPE_NM;
475       vm->slots_drivers = nm_drivers;
476    
477     pid = (m_uint16_t)getpid();     pid = (m_uint16_t)getpid();
478    
479     /* Generate a chassis MAC address based on the instance ID */     /* Generate a chassis MAC address based on the instance ID */
# Line 1145  void c3745_init_defaults(c3745_t *router Line 489  void c3745_init_defaults(c3745_t *router
489     cisco_eeprom_copy(&router->sys_eeprom[0],&eeprom_c3745_motherboard);     cisco_eeprom_copy(&router->sys_eeprom[0],&eeprom_c3745_motherboard);
490     cisco_eeprom_copy(&router->sys_eeprom[1],&eeprom_c3745_ioboard);     cisco_eeprom_copy(&router->sys_eeprom[1],&eeprom_c3745_ioboard);
491     cisco_eeprom_copy(&router->sys_eeprom[2],&eeprom_c3745_midplane);     cisco_eeprom_copy(&router->sys_eeprom[2],&eeprom_c3745_midplane);
   
492     c3745_burn_mac_addr(router,&router->mac_addr);     c3745_burn_mac_addr(router,&router->mac_addr);
493    
494       /* The GT96100 system controller has 2 integrated FastEthernet ports */
495       vm_slot_add_binding(vm,"GT96100-FE",0,0);
496    
497     vm->ram_mmap          = C3745_DEFAULT_RAM_MMAP;     vm->ram_mmap          = C3745_DEFAULT_RAM_MMAP;
498     vm->ram_size          = C3745_DEFAULT_RAM_SIZE;     vm->ram_size          = C3745_DEFAULT_RAM_SIZE;
499     vm->rom_size          = C3745_DEFAULT_ROM_SIZE;     vm->rom_size          = C3745_DEFAULT_ROM_SIZE;
# Line 1155  void c3745_init_defaults(c3745_t *router Line 501  void c3745_init_defaults(c3745_t *router
501     vm->conf_reg_setup    = C3745_DEFAULT_CONF_REG;     vm->conf_reg_setup    = C3745_DEFAULT_CONF_REG;
502     vm->clock_divisor     = C3745_DEFAULT_CLOCK_DIV;     vm->clock_divisor     = C3745_DEFAULT_CLOCK_DIV;
503     vm->nvram_rom_space   = C3745_NVRAM_ROM_RES_SIZE;     vm->nvram_rom_space   = C3745_NVRAM_ROM_RES_SIZE;
504     router->nm_iomem_size = C3745_DEFAULT_IOMEM_SIZE;     vm->nm_iomem_size     = C3745_DEFAULT_IOMEM_SIZE;
505    
506     vm->pcmcia_disk_size[0] = C3745_DEFAULT_DISK0_SIZE;     vm->pcmcia_disk_size[0] = C3745_DEFAULT_DISK0_SIZE;
507     vm->pcmcia_disk_size[1] = C3745_DEFAULT_DISK1_SIZE;     vm->pcmcia_disk_size[1] = C3745_DEFAULT_DISK1_SIZE;
   
    /* Enable NVRAM operations to load/store configs */  
    vm->nvram_extract_config = c3745_nvram_extract_config;  
    vm->nvram_push_config = c3745_nvram_push_config;  
508  }  }
509    
510  /* Initialize the C3745 Platform */  /* Initialize the C3745 Platform */
511  int c3745_init_platform(c3745_t *router)  static int c3745_init_platform(c3745_t *router)
512  {  {
513     vm_instance_t *vm = router->vm;     vm_instance_t *vm = router->vm;
    struct c3745_nm_bay *nm_bay;  
514     cpu_mips_t *cpu;     cpu_mips_t *cpu;
515     cpu_gen_t *gen;     cpu_gen_t *gen;
516     vm_obj_t *obj;     vm_obj_t *obj;
    int i;  
517    
518     /* Copy config register setup into "active" config register */     /* Copy config register setup into "active" config register */
519     vm->conf_reg = vm->conf_reg_setup;     vm->conf_reg = vm->conf_reg_setup;
# Line 1246  int c3745_init_platform(c3745_t *router) Line 586  int c3745_init_platform(c3745_t *router)
586     dev_flash_copy_data(obj,0,mips64_microcode,mips64_microcode_len);     dev_flash_copy_data(obj,0,mips64_microcode,mips64_microcode_len);
587     c3745_nvram_check_empty_config(vm);     c3745_nvram_check_empty_config(vm);
588    
589       /* Byte swapping */
590       dev_bswap_init(vm,"mem_bswap",C3745_BSWAP_ADDR,1024*1048576,0x00000000ULL);
591    
592     /* Initialize the NS16552 DUART */     /* Initialize the NS16552 DUART */
593     dev_ns16552_init(vm,C3745_DUART_ADDR,0x1000,3,C3745_DUART_IRQ,     dev_ns16552_init(vm,C3745_DUART_ADDR,0x1000,3,C3745_DUART_IRQ,
594                      vm->vtty_con,vm->vtty_aux);                      vm->vtty_con,vm->vtty_aux);
# Line 1258  int c3745_init_platform(c3745_t *router) Line 601  int c3745_init_platform(c3745_t *router)
601     dev_pcmcia_disk_init(vm,"slot1",C3745_SLOT1_ADDR,0x200000,     dev_pcmcia_disk_init(vm,"slot1",C3745_SLOT1_ADDR,0x200000,
602                          vm->pcmcia_disk_size[1],1);                          vm->pcmcia_disk_size[1],1);
603    
    /* The GT96100 system controller has 2 integrated FastEthernet ports */  
    c3745_nm_add_binding(router,"GT96100-FE",0);  
   
604     /* Initialize Network Modules */     /* Initialize Network Modules */
605     for(i=0;i<C3745_MAX_NM_BAYS;i++) {     if (vm_slot_init_all(vm) == -1)
606        nm_bay = &router->nm_bay[i];        return(-1);
   
       if (!nm_bay->dev_type)  
          continue;  
   
       if (c3745_nm_init(router,i) == -1) {  
          vm_error(vm,"unable to create Network Module \"%s\"\n",  
                   nm_bay->dev_type);  
          return(-1);  
       }  
    }  
607    
608     /* Show device list */     /* Show device list */
609     c3745_show_hardware(router);     c3745_show_hardware(router);
# Line 1281  int c3745_init_platform(c3745_t *router) Line 611  int c3745_init_platform(c3745_t *router)
611  }  }
612    
613  /* Boot the IOS image */  /* Boot the IOS image */
614  int c3745_boot_ios(c3745_t *router)  static int c3745_boot_ios(c3745_t *router)
615  {    {  
616     vm_instance_t *vm = router->vm;     vm_instance_t *vm = router->vm;
617     cpu_mips_t *cpu;     cpu_mips_t *cpu;
# Line 1372  static void c3745_clear_irq(vm_instance_ Line 702  static void c3745_clear_irq(vm_instance_
702  }  }
703    
704  /* Initialize a Cisco 3745 instance */  /* Initialize a Cisco 3745 instance */
705  int c3745_init_instance(c3745_t *router)  static int c3745_init_instance(vm_instance_t *vm)
706  {    {  
707     vm_instance_t *vm = router->vm;     c3745_t *router = VM_C3745(vm);
708     m_uint32_t rom_entry_point;     m_uint32_t rom_entry_point;
709     cpu_mips_t *cpu0;     cpu_mips_t *cpu0;
710    
# Line 1421  int c3745_init_instance(c3745_t *router) Line 751  int c3745_init_instance(c3745_t *router)
751  }  }
752    
753  /* Stop a Cisco 3745 instance */  /* Stop a Cisco 3745 instance */
754  int c3745_stop_instance(c3745_t *router)  static int c3745_stop_instance(vm_instance_t *vm)
755  {  {
    vm_instance_t *vm = router->vm;  
   
756     printf("\nC3745 '%s': stopping simulation.\n",vm->name);     printf("\nC3745 '%s': stopping simulation.\n",vm->name);
757     vm_log(vm,"C3745_STOP","stopping simulation.\n");     vm_log(vm,"C3745_STOP","stopping simulation.\n");
758    
# Line 1439  int c3745_stop_instance(c3745_t *router) Line 767  int c3745_stop_instance(c3745_t *router)
767     }     }
768    
769     /* Free resources that were used during execution to emulate hardware */     /* Free resources that were used during execution to emulate hardware */
770     c3745_nm_shutdown_all(router);     vm_slot_shutdown_all(vm);
771     vm_hardware_shutdown(vm);     vm_hardware_shutdown(vm);
772     return(0);     return(0);
773  }  }
774    
775    /* Get MAC address MSB */
776    static u_int c3745_get_mac_addr_msb(void)
777    {
778       return(0xC4);
779    }
780    
781    /* Parse specific options for the Cisco 1700 platform */
782    static int c3745_cli_parse_options(vm_instance_t *vm,int option)
783    {
784       switch(option) {
785          /* IO memory reserved for NMs (in percents!) */
786          case OPT_IOMEM_SIZE:
787             vm->nm_iomem_size = 0x8000 | atoi(optarg);
788             break;
789    
790          /* Unknown option */
791          default:
792             return(-1);
793       }
794    
795       return(0);
796    }
797    
798    /* Show specific CLI options */
799    static void c3745_cli_show_options(vm_instance_t *vm)
800    {
801       printf("  --iomem-size <val> : IO memory (in percents, default: %u)\n"
802              "  -p <nm_desc>       : Define a Network Module\n"
803              "  -s <nm_nio>        : Bind a Network IO interface to a "
804              "Network Module\n",
805              vm->nm_iomem_size);
806    }
807    
808    /* Platform definition */
809    static vm_platform_t c3745_platform = {
810       "c3745", "C3745", "3745",
811       c3745_create_instance,
812       c3745_delete_instance,
813       c3745_init_instance,
814       c3745_stop_instance,
815       c3745_nvram_extract_config,
816       c3745_nvram_push_config,
817       c3745_get_mac_addr_msb,
818       NULL,
819       c3745_cli_parse_options,
820       c3745_cli_show_options,
821       NULL,
822    };
823    
824    /* Register the c3745 platform */
825    int c3745_platform_register(void)
826    {
827       if (vm_platform_register(&c3745_platform) == -1)
828          return(-1);
829      
830       return(hypervisor_c3745_init(&c3745_platform));
831    }

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

  ViewVC Help
Powered by ViewVC 1.1.26