/* Set mainboard type */ int c1700_mainboard_set_type(c1700_t *router,char *mainboard_type) { struct c1700_mb_id *mb_info; if (router->vm->status == VM_STATUS_RUNNING) { vm_error(router->vm,"unable to change mainboard type when online.\n"); return(-1); } if (!(mb_info = c1700_get_mb_info(mainboard_type))) { vm_error(router->vm,"unknown mainboard '%s'\n",mainboard_type); return(-1); } router->mainboard_type = mainboard_type; /* Set the cookie */ memcpy(router->vm->chassis_cookie, eeprom_c1700_mb_data,sizeof(eeprom_c1700_mb_data)); router->vm->chassis_cookie[6] = mb_info->id; /* Set the chassis base MAC address */ c1700_burn_mac_addr(router,&router->mac_addr); /* Set the mainboard driver */ if (vm_slot_active(router->vm,0,0)) vm_slot_remove_binding(router->vm,0,0); vm_slot_add_binding(router->vm,mb_info->mb_driver,0,0); c1700_refresh_systemid(router); return(0); }
/* Remove a slot binding */ static int cmd_slot_remove_binding(hypervisor_conn_t *conn, int argc,char *argv[]) { vm_instance_t *vm; u_int slot,port; if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) return(-1); slot = atoi(argv[1]); port = atoi(argv[2]); if (vm_slot_remove_binding(vm,slot,port) == -1) { vm_release(vm); hypervisor_send_reply(conn,HSC_ERR_BINDING,1, "VM %s: unable to remove binding for slot %u/%u", argv[0],slot,port); return(-1); } vm_release(vm); hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); return(0); }
/* Add a slot binding */ int vm_slot_add_binding(vm_instance_t *vm,char *dev_type, u_int slot_id,u_int port_id) { struct cisco_card_driver *driver,**drv_array; struct cisco_card **rc,*card,*nc,*parent; u_int real_port_id,card_type,card_id; if (vm_slot_get_info(vm,slot_id,port_id,&rc,&real_port_id) == -1) return(-1); /* check that this bay is empty */ if (*rc != NULL) { if ((*rc)->card_flags & CISCO_CARD_FLAG_OVERRIDE) { vm_slot_remove_binding(vm,slot_id,port_id); } else { vm_error(vm,"a card already exists in slot %u/%u (%s)\n", slot_id,port_id,(*rc)->dev_type); return(-1); } } card = vm->slots[slot_id]; if (!card || (card == *rc)) { /* Main slot */ drv_array = vm->slots_drivers; card_type = vm->slots_type; card_id = slot_id; parent = NULL; } else { /* Subslot */ if (!card->driver->card_get_sub_info) { vm_error(vm,"no sub-slot possible for slot %u/%u.\n",slot_id,port_id); return(-1); } if (card->driver->card_get_sub_info(vm,card,port_id, &drv_array,&card_type) == -1) { vm_error(vm,"no sub-slot info for slot %u/%u.\n",slot_id,port_id); return(-1); } card_id = port_id; parent = card; } assert(drv_array != NULL); /* Find the card driver */ if (!(driver = cisco_card_find_driver(drv_array,dev_type))) { vm_error(vm,"unknown card type '%s' for slot %u/%u.\n", dev_type,slot_id,port_id); return(-1); } /* Allocate new card info */ if (!(nc = cisco_card_create(card_type))) return(-1); nc->slot_id = slot_id; nc->subslot_id = port_id; nc->card_id = card_id; nc->dev_type = driver->dev_type; nc->driver = driver; nc->parent = parent; *rc = nc; return(0); }