/[dynamips]/upstream/dynamips-0.2.6-RC2/dev_c7200.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.6-RC2/dev_c7200.c

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

upstream/dynamips-0.2.5/dev_c7200.c revision 1 by dpavlin, Sat Oct 6 16:01:44 2007 UTC upstream/dynamips-0.2.6-RC2/dev_c7200.c revision 3 by dpavlin, Sat Oct 6 16:05:34 2007 UTC
# Line 90  static m_uint16_t eeprom_cpu_npeg1_data[ Line 90  static m_uint16_t eeprom_cpu_npeg1_data[
90  /*  /*
91   * CPU EEPROM array.   * CPU EEPROM array.
92   */   */
93  static struct c7200_eeprom c7200_cpu_eeprom[] = {  static struct cisco_eeprom c7200_cpu_eeprom[] = {
94     { "npe-100", eeprom_cpu_npe100_data, sizeof(eeprom_cpu_npe100_data)/2 },     { "npe-100", eeprom_cpu_npe100_data, sizeof(eeprom_cpu_npe100_data)/2 },
95     { "npe-150", eeprom_cpu_npe150_data, sizeof(eeprom_cpu_npe150_data)/2 },     { "npe-150", eeprom_cpu_npe150_data, sizeof(eeprom_cpu_npe150_data)/2 },
96     { "npe-175", eeprom_cpu_npe175_data, sizeof(eeprom_cpu_npe175_data)/2 },     { "npe-175", eeprom_cpu_npe175_data, sizeof(eeprom_cpu_npe175_data)/2 },
# Line 125  static m_uint16_t eeprom_vxr_midplane_da Line 125  static m_uint16_t eeprom_vxr_midplane_da
125  /*  /*
126   * Midplane EEPROM array.   * Midplane EEPROM array.
127   */   */
128  static struct c7200_eeprom c7200_midplane_eeprom[] = {  static struct cisco_eeprom c7200_midplane_eeprom[] = {
129     { "std", eeprom_midplane_data, sizeof(eeprom_midplane_data)/2 },     { "std", eeprom_midplane_data, sizeof(eeprom_midplane_data)/2 },
130     { "vxr", eeprom_vxr_midplane_data, sizeof(eeprom_vxr_midplane_data)/2 },     { "vxr", eeprom_vxr_midplane_data, sizeof(eeprom_vxr_midplane_data)/2 },
131     { NULL, NULL, 0 },     { NULL, NULL, 0 },
# Line 150  static m_uint16_t eeprom_pem_npe225_data Line 150  static m_uint16_t eeprom_pem_npe225_data
150  /*  /*
151   * PEM EEPROM array.   * PEM EEPROM array.
152   */   */
153  static struct c7200_eeprom c7200_pem_eeprom[] = {  static struct cisco_eeprom c7200_pem_eeprom[] = {
154     { "npe-175", eeprom_pem_npe175_data, sizeof(eeprom_pem_npe175_data)/2 },     { "npe-175", eeprom_pem_npe175_data, sizeof(eeprom_pem_npe175_data)/2 },
155     { "npe-225", eeprom_pem_npe225_data, sizeof(eeprom_pem_npe225_data)/2 },     { "npe-225", eeprom_pem_npe225_data, sizeof(eeprom_pem_npe225_data)/2 },
156     { NULL, NULL, 0 },     { NULL, NULL, 0 },
# Line 201  static struct c7200_npe_driver npe_drive Line 201  static struct c7200_npe_driver npe_drive
201  };  };
202    
203  /* ======================================================================== */  /* ======================================================================== */
 /* Empty EEPROM for PAs                                                     */  
 /* ======================================================================== */  
 static const m_uint16_t eeprom_pa_empty[64] = {  
    0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,  
    0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,  
    0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,  
    0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,  
 };  
   
 /* ======================================================================== */  
204  /* Cisco 7200 router instances                                              */  /* Cisco 7200 router instances                                              */
205  /* ======================================================================== */  /* ======================================================================== */
206    
# Line 267  ssize_t c7200_nvram_extract_config(vm_in Line 257  ssize_t c7200_nvram_extract_config(vm_in
257  int c7200_nvram_push_config(vm_instance_t *vm,char *buffer,size_t len)  int c7200_nvram_push_config(vm_instance_t *vm,char *buffer,size_t len)
258  {  {
259     struct vdevice *nvram_dev;     struct vdevice *nvram_dev;
260     m_uint64_t addr,cfg_addr,cfg_start_addr;     m_uint64_t addr,cfg_addr;
261       m_uint32_t cklen;
262       m_uint16_t cksum;
263    
264     if (!(nvram_dev = dev_get_by_name(vm,"nvram")))     if (!(nvram_dev = dev_get_by_name(vm,"nvram")))
265        return(-1);        return(-1);
266    
267     addr = nvram_dev->phys_addr + vm->nvram_rom_space;     addr = nvram_dev->phys_addr + vm->nvram_rom_space;
268     cfg_start_addr = cfg_addr = addr + 0x40;     cfg_addr = addr + 0x2c;
269    
270     /* Write IOS tag, uncompressed config... */     /* Write IOS tag, uncompressed config... */
271     physmem_copy_u16_to_vm(vm,addr+0x06,0xF0A5);     physmem_copy_u16_to_vm(vm,addr+0x06,0xF0A5);
272     physmem_copy_u16_to_vm(vm,addr+0x08,0xABCD);      /* Magic number */     physmem_copy_u16_to_vm(vm,addr+0x08,0xABCD);      /* Magic number */
273     physmem_copy_u16_to_vm(vm,addr+0x0a,0x0001);      /* ??? */     physmem_copy_u16_to_vm(vm,addr+0x0a,0x0001);      /* ??? */
274     physmem_copy_u16_to_vm(vm,addr+0x0c,0x0000);      /* zero */     physmem_copy_u16_to_vm(vm,addr+0x0c,0x0000);      /* zero */
275     physmem_copy_u16_to_vm(vm,addr+0x0e,0x0c04);      /* IOS version */     physmem_copy_u16_to_vm(vm,addr+0x0e,0x0000);      /* IOS version */
276    
277     /* Store file contents to NVRAM */     /* Store file contents to NVRAM */
278     physmem_copy_to_vm(vm,buffer,cfg_addr,len);     physmem_copy_to_vm(vm,buffer,cfg_addr,len);
279    
280     /* Write config addresses + size */     /* Write config addresses + size */
281     physmem_copy_u32_to_vm(vm,addr+0x10,cfg_start_addr);     physmem_copy_u32_to_vm(vm,addr+0x10,cfg_addr);
282     physmem_copy_u32_to_vm(vm,addr+0x14,cfg_addr);     physmem_copy_u32_to_vm(vm,addr+0x14,cfg_addr + len);
283     physmem_copy_u32_to_vm(vm,addr+0x18,cfg_addr - cfg_start_addr);     physmem_copy_u32_to_vm(vm,addr+0x18,len);
284    
285       /* Compute the checksum */
286       cklen = nvram_dev->phys_len - (vm->nvram_rom_space + 0x08);
287       cksum = nvram_cksum(vm,addr+0x08,cklen);
288       physmem_copy_u16_to_vm(vm,addr+0x0c,cksum);
289     return(0);     return(0);
290  }  }
291    
 /* Find an EEPROM in the specified array */  
 struct c7200_eeprom *c7200_get_eeprom(struct c7200_eeprom *eeproms,char *name)  
 {  
    int i;  
   
    for(i=0;eeproms[i].name;i++)  
       if (!strcmp(eeproms[i].name,name))  
          return(&eeproms[i]);  
   
    return NULL;  
 }  
   
292  /* Get an EEPROM for a given NPE model */  /* Get an EEPROM for a given NPE model */
293  struct c7200_eeprom *c7200_get_cpu_eeprom(char *npe_name)  static const struct cisco_eeprom *c7200_get_cpu_eeprom(char *npe_name)
294  {  {
295     return(c7200_get_eeprom(c7200_cpu_eeprom,npe_name));     return(cisco_eeprom_find(c7200_cpu_eeprom,npe_name));
296  }  }
297    
298  /* Get an EEPROM for a given midplane model */  /* Get an EEPROM for a given midplane model */
299  struct c7200_eeprom *c7200_get_midplane_eeprom(char *midplane_name)  static const struct cisco_eeprom *
300    c7200_get_midplane_eeprom(char *midplane_name)
301  {  {
302     return(c7200_get_eeprom(c7200_midplane_eeprom,midplane_name));     return(cisco_eeprom_find(c7200_midplane_eeprom,midplane_name));
303  }  }
304    
305  /* Get a PEM EEPROM for a given NPE model */  /* Get a PEM EEPROM for a given NPE model */
306  struct c7200_eeprom *c7200_get_pem_eeprom(char *npe_name)  static const struct cisco_eeprom *c7200_get_pem_eeprom(char *npe_name)
307  {  {
308     return(c7200_get_eeprom(c7200_pem_eeprom,npe_name));     return(cisco_eeprom_find(c7200_pem_eeprom,npe_name));
309  }  }
310    
311  /* Set the base MAC address of the chassis */  /* Set the base MAC address of the chassis */
312  static int c7200_burn_mac_addr(m_uint16_t *data,size_t data_len,  static int c7200_burn_mac_addr(c7200_t *router,n_eth_addr_t *addr)
                                n_eth_addr_t *addr)  
313  {  {
314     m_uint8_t eeprom_ver;     m_uint8_t eeprom_ver;
315    
316     /* Read EEPROM format version */     /* Read EEPROM format version */
317     cisco_eeprom_get_byte(data,data_len,0,&eeprom_ver);     cisco_eeprom_get_byte(&router->mp_eeprom,0,&eeprom_ver);
318    
319     if (eeprom_ver != 1) {     if (eeprom_ver != 1) {
320        fprintf(stderr,"c7200_burn_mac_addr: unable to handle "        vm_error(router->vm,"c7200_burn_mac_addr: unable to handle "
321                "EEPROM version %u\n",eeprom_ver);                "EEPROM version %u\n",eeprom_ver);
322        return(-1);        return(-1);
323     }     }
324    
325     cisco_eeprom_set_region(data,data_len,12,addr->eth_addr_byte,6);     cisco_eeprom_set_region(&router->mp_eeprom,12,addr->eth_addr_byte,6);
326     return(0);     return(0);
327  }  }
328    
# Line 411  static int c7200_free_instance(void *dat Line 396  static int c7200_free_instance(void *dat
396        /* Free specific HW resources */        /* Free specific HW resources */
397        c7200_free_hw_ressources(router);        c7200_free_hw_ressources(router);
398    
399          /* Free EEPROMs */
400          cisco_eeprom_free(&router->cpu_eeprom);
401          cisco_eeprom_free(&router->mp_eeprom);
402          cisco_eeprom_free(&router->pem_eeprom);
403    
404        /* Free all resources used by VM */        /* Free all resources used by VM */
405        vm_free(vm);        vm_free(vm);
406    
# Line 489  void c7200_save_config_all(FILE *fd) Line 479  void c7200_save_config_all(FILE *fd)
479  /* Set NPE eeprom definition */  /* Set NPE eeprom definition */
480  static int c7200_npe_set_eeprom(c7200_t *router)  static int c7200_npe_set_eeprom(c7200_t *router)
481  {  {
482     struct c7200_eeprom *eeprom;     const struct cisco_eeprom *eeprom;
483    
484     if (!(eeprom = c7200_get_cpu_eeprom(router->npe_driver->npe_type))) {     if (!(eeprom = c7200_get_cpu_eeprom(router->npe_driver->npe_type))) {
485        vm_error(router->vm,"unknown NPE \"%s\" (internal error)!\n",        vm_error(router->vm,"unknown NPE \"%s\" (internal error)!\n",
# Line 497  static int c7200_npe_set_eeprom(c7200_t Line 487  static int c7200_npe_set_eeprom(c7200_t
487        return(-1);        return(-1);
488     }     }
489    
490     router->cpu_eeprom.data = eeprom->data;     if (cisco_eeprom_copy(&router->cpu_eeprom,eeprom) == -1) {
491     router->cpu_eeprom.data_len = eeprom->len;        vm_error(router->vm,"unable to set NPE EEPROM.\n");
492          return(-1);
493       }
494    
495     return(0);     return(0);
496  }  }
497    
498  /* Set PEM eeprom definition */  /* Set PEM eeprom definition */
499  static int c7200_pem_set_eeprom(c7200_t *router)  static int c7200_pem_set_eeprom(c7200_t *router)
500  {  {
501     struct c7200_eeprom *eeprom;     const struct cisco_eeprom *eeprom;
502    
503     if (!(eeprom = c7200_get_pem_eeprom(router->npe_driver->npe_type))) {     if (!(eeprom = c7200_get_pem_eeprom(router->npe_driver->npe_type))) {
504        vm_error(router->vm,"no PEM EEPROM found for NPE type \"%s\"!\n",        vm_error(router->vm,"no PEM EEPROM found for NPE type \"%s\"!\n",
# Line 513  static int c7200_pem_set_eeprom(c7200_t Line 506  static int c7200_pem_set_eeprom(c7200_t
506        return(-1);        return(-1);
507     }     }
508    
509     router->pem_eeprom.data = eeprom->data;     if (cisco_eeprom_copy(&router->pem_eeprom,eeprom) == -1) {
510     router->pem_eeprom.data_len = eeprom->len;        vm_error(router->vm,"unable to set PEM EEPROM.\n");
511          return(-1);
512       }
513    
514     return(0);     return(0);
515  }  }
516    
517  /* Set PA EEPROM definition */  /* Set PA EEPROM definition */
518  int c7200_pa_set_eeprom(c7200_t *router,u_int pa_bay,  int c7200_pa_set_eeprom(c7200_t *router,u_int pa_bay,
519                          const struct c7200_eeprom *eeprom)                          const struct cisco_eeprom *eeprom)
520  {  {
521     if (pa_bay >= C7200_MAX_PA_BAYS) {     if (pa_bay >= C7200_MAX_PA_BAYS) {
522        vm_error(router->vm,"c7200_pa_set_eeprom: invalid PA Bay %u.\n",pa_bay);        vm_error(router->vm,"c7200_pa_set_eeprom: invalid PA Bay %u.\n",pa_bay);
523        return(-1);        return(-1);
524     }     }
525      
526     router->pa_bay[pa_bay].eeprom.data = eeprom->data;     if (cisco_eeprom_copy(&router->pa_bay[pa_bay].eeprom,eeprom) == -1) {
527     router->pa_bay[pa_bay].eeprom.data_len = eeprom->len;        vm_error(router->vm,"c7200_pa_set_eeprom: no memory.\n");
528          return(-1);
529       }
530    
531     return(0);     return(0);
532  }  }
533    
# Line 540  int c7200_pa_unset_eeprom(c7200_t *route Line 539  int c7200_pa_unset_eeprom(c7200_t *route
539        return(-1);        return(-1);
540     }     }
541        
542     router->pa_bay[pa_bay].eeprom.data = (m_uint16_t *)eeprom_pa_empty;     cisco_eeprom_free(&router->pa_bay[pa_bay].eeprom);
    router->pa_bay[pa_bay].eeprom.data_len = sizeof(eeprom_pa_empty)/2;  
543     return(0);     return(0);
544  }  }
545    
546  /* Check if a bay has a port adapter */  /* Check if a bay has a port adapter */
547  int c7200_pa_check_eeprom(c7200_t *router,u_int pa_bay)  int c7200_pa_check_eeprom(c7200_t *router,u_int pa_bay)
548  {  {
    struct nmc93c46_eeprom_def *def;  
   
549     if (!pa_bay || (pa_bay >= C7200_MAX_PA_BAYS))     if (!pa_bay || (pa_bay >= C7200_MAX_PA_BAYS))
550        return(0);        return(FALSE);
   
    def = &router->pa_bay[pa_bay].eeprom;  
     
    if (def->data == eeprom_pa_empty)  
       return(0);  
551    
552     return(1);     return(cisco_eeprom_valid(&router->pa_bay[pa_bay].eeprom));
553  }  }
554    
555  /* Get bay info */  /* Get bay info */
# Line 933  int c7200_pa_shutdown_all(c7200_t *route Line 924  int c7200_pa_shutdown_all(c7200_t *route
924     return(0);     return(0);
925  }  }
926    
927    /* Show info about all NMs */
928    int c7200_pa_show_all_info(c7200_t *router)
929    {
930       struct c7200_pa_bay *bay;
931       int i;
932    
933       for(i=0;i<C7200_MAX_PA_BAYS;i++) {
934          if (!(bay = c7200_pa_get_info(router,i)) || !bay->pa_driver)
935             continue;
936    
937          if (bay->pa_driver->pa_show_info != NULL)
938             bay->pa_driver->pa_show_info(router,i);
939       }
940    
941       return(0);
942    }
943    
944  /* Maximum number of tokens in a PA description */  /* Maximum number of tokens in a PA description */
945  #define PA_DESC_MAX_TOKENS  8  #define PA_DESC_MAX_TOKENS  8
946    
# Line 1184  void c7200_npe_show_drivers(void) Line 1192  void c7200_npe_show_drivers(void)
1192  /* Set Midplane type */  /* Set Midplane type */
1193  int c7200_midplane_set_type(c7200_t *router,char *midplane_type)  int c7200_midplane_set_type(c7200_t *router,char *midplane_type)
1194  {  {
1195     struct c7200_eeprom *eeprom;     const struct cisco_eeprom *eeprom;
1196     m_uint8_t version;     m_uint8_t version;
1197    
1198     if (router->vm->status == VM_STATUS_RUNNING) {     if (router->vm->status == VM_STATUS_RUNNING) {
# Line 1198  int c7200_midplane_set_type(c7200_t *rou Line 1206  int c7200_midplane_set_type(c7200_t *rou
1206        return(-1);        return(-1);
1207     }     }
1208    
1209     memcpy(router->mp_eeprom_data,eeprom->data,eeprom->len << 1);     /* Copy the midplane EEPROM */
1210       if (cisco_eeprom_copy(&router->mp_eeprom,eeprom) == -1) {
1211          vm_error(router->vm,"unable to set midplane EEPROM.\n");
1212          return(-1);
1213       }
1214    
1215     /* Set the chassis base MAC address */     /* Set the chassis base MAC address */
1216     c7200_burn_mac_addr(router->mp_eeprom_data,sizeof(router->mp_eeprom_data),     c7200_burn_mac_addr(router,&router->mac_addr);
                        &router->mac_addr);  
   
    router->mp_eeprom.data = router->mp_eeprom_data;  
    router->mp_eeprom.data_len = eeprom->len;  
    router->midplane_type = eeprom->name;  
1217    
1218     /* Get the midplane version */     /* Get the midplane version */
1219     cisco_eeprom_get_byte(router->mp_eeprom.data,router->mp_eeprom.data_len*2,     cisco_eeprom_get_byte(&router->mp_eeprom,2,&version);
1220                           2,&version);     router->midplane_version = version;  
1221     router->midplane_version = version;     router->midplane_type = eeprom->name;
1222     return(0);     return(0);
1223  }  }
1224    
# Line 1224  int c7200_midplane_set_mac_addr(c7200_t Line 1231  int c7200_midplane_set_mac_addr(c7200_t
1231     }     }
1232    
1233     /* Set the chassis base MAC address */     /* Set the chassis base MAC address */
1234     c7200_burn_mac_addr(router->mp_eeprom_data,sizeof(router->mp_eeprom_data),     c7200_burn_mac_addr(router,&router->mac_addr);
                        &router->mac_addr);  
1235     return(0);     return(0);
1236  }  }
1237    

Legend:
Removed from v.1  
changed lines
  Added in v.3

  ViewVC Help
Powered by ViewVC 1.1.26