--- upstream/dynamips-0.2.7/dev_c3725_eth.c 2007/10/06 16:29:14 10 +++ upstream/dynamips-0.2.8-RC1/dev_c3725_eth.c 2007/10/06 16:33:40 11 @@ -29,56 +29,72 @@ struct am79c971_data *port[8]; }; +/* Return sub-slot info for integrated WIC slots (on motherboard) */ +static int dev_c3725_mb_get_sub_info(vm_instance_t *vm,struct cisco_card *card, + u_int port_id, + struct cisco_card_driver ***drv_array, + u_int *subcard_type) +{ + /* 3 integrated WIC slots */ + if ((port_id & 0x0F) >= 3) + return(-1); + + *drv_array = dev_c3725_mb_wic_drivers; + *subcard_type = CISCO_CARD_TYPE_WIC; + return(0); +} + /* * dev_c3725_nm_eth_init() * * Add an Ethernet Network Module into specified slot. */ -static int dev_c3725_nm_eth_init(c3725_t *router,char *name,u_int nm_bay, +static int dev_c3725_nm_eth_init(vm_instance_t *vm,struct cisco_card *card, int nr_port,int interface_type, const struct cisco_eeprom *eeprom) { struct nm_eth_data *data; + u_int slot = card->slot_id; int i; /* Allocate the private data structure */ if (!(data = malloc(sizeof(*data)))) { - fprintf(stderr,"%s: out of memory\n",name); + vm_error(vm,"%s: out of memory.\n",card->dev_name); return(-1); } memset(data,0,sizeof(*data)); data->nr_port = nr_port; + /* Set the PCI bus */ + card->pci_bus = vm->slots_pci_bus[slot]; + /* Set the EEPROM */ - c3725_nm_set_eeprom(router,nm_bay,eeprom); + cisco_card_set_eeprom(vm,card,eeprom); + c3725_set_slot_eeprom(VM_C3725(vm),slot,&card->eeprom); /* Create the AMD Am971c971 chip(s) */ for(i=0;inr_port;i++) { - data->port[i] = dev_am79c971_init(router->vm,name,interface_type, - router->nm_bay[nm_bay].pci_map, - c3725_nm_get_pci_device(nm_bay), - c3725_net_irq_for_slot_port(nm_bay,i)); + data->port[i] = dev_am79c971_init(vm,card->dev_name,interface_type, + card->pci_bus, + c3725_nm_get_pci_device(slot), + c3725_net_irq_for_slot_port(slot,i)); } /* Store device info into the router structure */ - return(c3725_nm_set_drvinfo(router,nm_bay,data)); + card->drv_info = data; + return(0); } /* Remove an Ethernet NM from the specified slot */ -static int dev_c3725_nm_eth_shutdown(c3725_t *router,u_int nm_bay) +static int dev_c3725_nm_eth_shutdown(vm_instance_t *vm,struct cisco_card *card) { - struct c3725_nm_bay *bay; - struct nm_eth_data *data; + struct nm_eth_data *data = card->drv_info; int i; - if (!(bay = c3725_nm_get_info(router,nm_bay))) - return(-1); - - data = bay->drv_info; - /* Remove the NM EEPROM */ - c3725_nm_unset_eeprom(router,nm_bay); + cisco_card_unset_eeprom(card); + c3725_set_slot_eeprom(VM_C3725(vm),card->slot_id,NULL); /* Remove the AMD Am79c971 chips */ for(i=0;inr_port;i++) @@ -88,13 +104,10 @@ return(0); } -/* Bind a Network IO descriptor */ -static int dev_c3725_nm_eth_set_nio(c3725_t *router,u_int nm_bay, +static int dev_c3725_nm_eth_set_nio(vm_instance_t *vm,struct cisco_card *card, u_int port_id,netio_desc_t *nio) { - struct nm_eth_data *d; - - d = c3725_nm_get_drvinfo(router,nm_bay); + struct nm_eth_data *d = card->drv_info; if (!d || (port_id >= d->nr_port)) return(-1); @@ -104,12 +117,11 @@ } /* Unbind a Network IO descriptor */ -static int dev_c3725_nm_eth_unset_nio(c3725_t *router,u_int nm_bay, +static int dev_c3725_nm_eth_unset_nio(vm_instance_t *vm, + struct cisco_card *card, u_int port_id) { - struct nm_eth_data *d; - - d = c3725_nm_get_drvinfo(router,nm_bay); + struct nm_eth_data *d = card->drv_info; if (!d || (port_id >= d->nr_port)) return(-1); @@ -127,9 +139,9 @@ * * Add a NM-1FE-TX Network Module into specified slot. */ -static int dev_c3725_nm_1fe_tx_init(c3725_t *router,char *name,u_int nm_bay) +static int dev_c3725_nm_1fe_tx_init(vm_instance_t *vm,struct cisco_card *card) { - return(dev_c3725_nm_eth_init(router,name,nm_bay,1,AM79C971_TYPE_100BASE_TX, + return(dev_c3725_nm_eth_init(vm,card,1,AM79C971_TYPE_100BASE_TX, cisco_eeprom_find_nm("NM-1FE-TX"))); } @@ -138,38 +150,38 @@ /* ====================================================================== */ /* Add a NM-16ESW */ -static int dev_c3725_nm_16esw_init(c3725_t *router,char *name,u_int nm_bay) +static int dev_c3725_nm_16esw_init(vm_instance_t *vm,struct cisco_card *card) { struct nm_16esw_data *data; + u_int slot = card->slot_id; + + /* Set the PCI bus */ + card->pci_bus = vm->slots_pci_bus[slot]; /* Set the EEPROM */ - c3725_nm_set_eeprom(router,nm_bay,cisco_eeprom_find_nm("NM-16ESW")); - dev_nm_16esw_burn_mac_addr(router->vm,nm_bay, - &router->nm_bay[nm_bay].eeprom); + cisco_card_set_eeprom(vm,card,cisco_eeprom_find_nm("NM-16ESW")); + dev_nm_16esw_burn_mac_addr(vm,slot,&card->eeprom); + c3725_set_slot_eeprom(VM_C3725(vm),slot,&card->eeprom); /* Create the device */ - data = dev_nm_16esw_init(router->vm,name,nm_bay, - router->nm_bay[nm_bay].pci_map, - c3725_nm_get_pci_device(nm_bay), - c3725_net_irq_for_slot_port(nm_bay,0)); + data = dev_nm_16esw_init(vm,card->dev_name,slot, + card->pci_bus,c3725_nm_get_pci_device(slot), + c3725_net_irq_for_slot_port(slot,0)); /* Store device info into the router structure */ - return(c3725_nm_set_drvinfo(router,nm_bay,data)); + card->drv_info = data; + return(0); } /* Remove a NM-16ESW from the specified slot */ -static int dev_c3725_nm_16esw_shutdown(c3725_t *router,u_int nm_bay) +static int +dev_c3725_nm_16esw_shutdown(vm_instance_t *vm,struct cisco_card *card) { - struct c3725_nm_bay *bay; - struct nm_16esw_data *data; - - if (!(bay = c3725_nm_get_info(router,nm_bay))) - return(-1); - - data = bay->drv_info; + struct nm_16esw_data *data = card->drv_info; /* Remove the NM EEPROM */ - c3725_nm_unset_eeprom(router,nm_bay); + cisco_card_unset_eeprom(card); + c3725_set_slot_eeprom(VM_C3725(vm),card->slot_id,NULL); /* Remove the BCM5600 chip */ dev_nm_16esw_remove(data); @@ -177,121 +189,120 @@ } /* Bind a Network IO descriptor */ -static int dev_c3725_nm_16esw_set_nio(c3725_t *router,u_int nm_bay, - u_int port_id,netio_desc_t *nio) +static int +dev_c3725_nm_16esw_set_nio(vm_instance_t *vm,struct cisco_card *card, + u_int port_id,netio_desc_t *nio) { - struct nm_16esw_data *d; - - d = c3725_nm_get_drvinfo(router,nm_bay); + struct nm_16esw_data *d = card->drv_info; dev_nm_16esw_set_nio(d,port_id,nio); return(0); } /* Unbind a Network IO descriptor */ -static int dev_c3725_nm_16esw_unset_nio(c3725_t *router,u_int nm_bay, +static int dev_c3725_nm_16esw_unset_nio(vm_instance_t *vm, + struct cisco_card *card, u_int port_id) { - struct nm_16esw_data *d; - - d = c3725_nm_get_drvinfo(router,nm_bay); + struct nm_16esw_data *d = card->drv_info; dev_nm_16esw_unset_nio(d,port_id); return(0); } /* Show debug info */ -static int dev_c3725_nm_16esw_show_info(c3725_t *router,u_int nm_bay) +static int +dev_c3725_nm_16esw_show_info(vm_instance_t *vm,struct cisco_card *card) { - struct nm_16esw_data *d; - - d = c3725_nm_get_drvinfo(router,nm_bay); + struct nm_16esw_data *d = card->drv_info; dev_nm_16esw_show_info(d); return(0); } + /* ====================================================================== */ /* GT96100 - Integrated Ethernet ports */ /* ====================================================================== */ /* Initialize Ethernet part of the GT96100 controller */ -static int dev_c3725_gt96100_fe_init(c3725_t *router,char *name,u_int nm_bay) +static int dev_c3725_gt96100_fe_init(vm_instance_t *vm,struct cisco_card *card) { - vm_obj_t *obj; - - if (nm_bay != 0) { - fprintf(stderr,"dev_c3725_gt96100_fe_init: bad slot specified.\n"); - return(-1); - } - - if (!(obj = vm_object_find(router->vm,"gt96100"))) { - fprintf(stderr,"dev_c3725_gt96100_fe_init: unable to find " - "system controller!\n"); + if (card->slot_id != 0) { + vm_error(vm,"dev_c3725_gt96100_fe_init: bad slot %u specified.\n", + card->slot_id); return(-1); } /* Store device info into the router structure */ - return(c3725_nm_set_drvinfo(router,0,obj->data)); + card->drv_info = VM_C3725(vm)->gt_data; + return(0); } /* Nothing to do, we never remove the system controller */ -static int dev_c3725_gt96100_fe_shutdown(c3725_t *router,u_int nm_bay) +static int +dev_c3725_gt96100_fe_shutdown(vm_instance_t *vm,struct cisco_card *card) { return(0); } /* Bind a Network IO descriptor */ -static int dev_c3725_gt96100_fe_set_nio(c3725_t *router,u_int nm_bay, - u_int port_id,netio_desc_t *nio) +static int +dev_c3725_gt96100_fe_set_nio(vm_instance_t *vm,struct cisco_card *card, + u_int port_id,netio_desc_t *nio) { - struct gt_data *d; - - if (!(d = c3725_nm_get_drvinfo(router,nm_bay))) - return(-1); - - dev_gt96100_set_nio(d,port_id,nio); + struct gt_data *d = card->drv_info; + dev_gt96100_eth_set_nio(d,port_id,nio); return(0); } /* Unbind a Network IO descriptor */ -static int dev_c3725_gt96100_fe_unset_nio(c3725_t *router,u_int nm_bay, - u_int port_id) +static int dev_c3725_gt96100_fe_unset_nio(vm_instance_t *vm, + struct cisco_card *card, + u_int port_id) { - struct gt_data *d; - - if (!(d = c3725_nm_get_drvinfo(router,nm_bay))) - return(-1); + struct gt_data *d = card->drv_info; + dev_gt96100_eth_unset_nio(d,port_id); + return(0); +} - dev_gt96100_unset_nio(d,port_id); +/* Show debug info */ +static int +dev_c3725_gt96100_show_info(vm_instance_t *vm,struct cisco_card *card) +{ + struct gt_data *d = card->drv_info; + dev_gt96100_show_info(d); return(0); } /* ====================================================================== */ /* NM-1FE-TX driver */ -struct c3725_nm_driver dev_c3725_nm_1fe_tx_driver = { +struct cisco_card_driver dev_c3725_nm_1fe_tx_driver = { "NM-1FE-TX", 1, 0, dev_c3725_nm_1fe_tx_init, dev_c3725_nm_eth_shutdown, + NULL, dev_c3725_nm_eth_set_nio, dev_c3725_nm_eth_unset_nio, NULL, }; /* NM-16ESW driver */ -struct c3725_nm_driver dev_c3725_nm_16esw_driver = { +struct cisco_card_driver dev_c3725_nm_16esw_driver = { "NM-16ESW", 1, 0, dev_c3725_nm_16esw_init, dev_c3725_nm_16esw_shutdown, + NULL, dev_c3725_nm_16esw_set_nio, dev_c3725_nm_16esw_unset_nio, dev_c3725_nm_16esw_show_info, }; /* GT96100 FastEthernet integrated ports */ -struct c3725_nm_driver dev_c3725_gt96100_fe_driver = { +struct cisco_card_driver dev_c3725_gt96100_fe_driver = { "GT96100-FE", 1, 0, dev_c3725_gt96100_fe_init, dev_c3725_gt96100_fe_shutdown, + dev_c3725_mb_get_sub_info, dev_c3725_gt96100_fe_set_nio, dev_c3725_gt96100_fe_unset_nio, - NULL, + dev_c3725_gt96100_show_info, };