📄 cisco_card.c
字号:
real_port_id = vm_slot_translate_port_id(vm,slot_id,port_id,&rc); if (rc == NULL) return(-1); /* no nio binding for this slot/port ? */ if (!(nb = cisco_card_find_nio_binding(rc,real_port_id))) return(-1); /* tell the NM driver to stop using this NIO */ if (rc->driver) rc->driver->card_unset_nio(vm,rc,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 { rc->nio_list = nb->next; } /* unreference NIO object */ netio_release(nb->nio->name); free(nb); return(0);}/* Remove all NIO bindings for the specified slot (sub-slots included) */int vm_slot_remove_all_nio_bindings(vm_instance_t *vm,u_int slot_id){ struct cisco_card *card,*sc; int i; if (!(card = vm_slot_get_card_ptr(vm,slot_id))) return(-1); /* Remove NIO bindings for the main slot */ cisco_card_remove_all_nio_bindings(vm,card); /* Remove NIO bindings for all sub-slots */ for(i=0;i<CISCO_CARD_MAX_SUBSLOTS;i++) { if ((sc = card->sub_slots[i]) != NULL) cisco_card_remove_all_nio_bindings(vm,sc); } return(0);}/* Enable a Network IO descriptor for the specified slot */int vm_slot_enable_nio(vm_instance_t *vm,u_int slot_id,u_int port_id){ struct cisco_nio_binding *nb; struct cisco_card *card,*rc; u_int real_port_id; if (!(card = vm_slot_get_card_ptr(vm,slot_id))) return(-1); /* Get the real card (in case this is a sub-slot) */ real_port_id = vm_slot_translate_port_id(vm,slot_id,port_id,&rc); if (rc == NULL) return(-1); /* no nio binding for this slot/port ? */ if (!(nb = cisco_card_find_nio_binding(rc,real_port_id))) return(-1); /* check that the driver is defined and successfully initialized */ if (!rc->driver || !rc->drv_info) return(-1); return(rc->driver->card_set_nio(vm,rc,port_id,nb->nio));}/* Disable Network IO descriptor for the specified slot */int vm_slot_disable_nio(vm_instance_t *vm,u_int slot_id,u_int port_id){ struct cisco_nio_binding *nb; struct cisco_card *card,*rc; u_int real_port_id; if (!(card = vm_slot_get_card_ptr(vm,slot_id))) return(-1); /* Get the real card (in case this is a sub-slot) */ real_port_id = vm_slot_translate_port_id(vm,slot_id,port_id,&rc); if (rc == NULL) return(-1); /* no nio binding for this slot/port ? */ if (!(nb = cisco_card_find_nio_binding(rc,real_port_id))) return(-1); /* check that the driver is defined and successfully initialized */ if (!rc->driver || !rc->drv_info) return(-1); return(rc->driver->card_unset_nio(vm,rc,port_id));}/* Enable all NIO for the specified slot (sub-slots included) */int vm_slot_enable_all_nio(vm_instance_t *vm,u_int slot_id){ struct cisco_card *card; int i; if (!(card = vm_slot_get_card_ptr(vm,slot_id))) return(-1); /* Enable slot NIOs */ cisco_card_enable_all_nio(vm,card); /* Enable NIO of sub-slots */ for(i=0;i<CISCO_CARD_MAX_SUBSLOTS;i++) cisco_card_enable_all_nio(vm,card->sub_slots[i]); return(0);}/* Disable all NIO for the specified slot (sub-slots included) */int vm_slot_disable_all_nio(vm_instance_t *vm,u_int slot_id){ struct cisco_card *card; int i; if (!(card = vm_slot_get_card_ptr(vm,slot_id))) return(-1); /* Disable slot NIOs */ cisco_card_disable_all_nio(vm,card); /* Disable NIO of sub-slots */ for(i=0;i<CISCO_CARD_MAX_SUBSLOTS;i++) cisco_card_disable_all_nio(vm,card->sub_slots[i]); return(0);}/* Initialize the specified slot (sub-slots included) */int vm_slot_init(vm_instance_t *vm,u_int slot_id){ struct cisco_card *card; int i; if (!(card = vm_slot_get_card_ptr(vm,slot_id))) return(0); /* Initialize card main module */ cisco_card_init(vm,card,slot_id); /* Initialize sub-slots */ for(i=0;i<CISCO_CARD_MAX_SUBSLOTS;i++) cisco_card_init(vm,card->sub_slots[i],slot_id); /* Enable all NIO */ vm_slot_enable_all_nio(vm,slot_id); return(0);}/* Initialize all slots of a VM */int vm_slot_init_all(vm_instance_t *vm){ int i; for(i=0;i<vm->nr_slots;i++) { if (vm_slot_init(vm,i) == -1) { vm_error(vm,"unable to initialize slot %u\n",i); return(-1); } } return(0);}/* Shutdown the specified slot (sub-slots included) */int vm_slot_shutdown(vm_instance_t *vm,u_int slot_id){ struct cisco_card *card; int i; if (!(card = vm_slot_get_card_ptr(vm,slot_id))) return(-1); /* Disable all NIO */ vm_slot_disable_all_nio(vm,slot_id); /* Shutdown sub-slots */ for(i=0;i<CISCO_CARD_MAX_SUBSLOTS;i++) cisco_card_shutdown(vm,card->sub_slots[i]); /* Shutdown card main module */ cisco_card_shutdown(vm,card); return(0);}/* Shutdown all slots of a VM */int vm_slot_shutdown_all(vm_instance_t *vm){ int i; for(i=0;i<vm->nr_slots;i++) vm_slot_shutdown(vm,i); return(0);}/* Show info about the specified slot (sub-slots included) */int vm_slot_show_info(vm_instance_t *vm,u_int slot_id){ struct cisco_card *card; if (!(card = vm_slot_get_card_ptr(vm,slot_id))) return(-1); cisco_card_show_info(vm,card); return(0);}/* Show info about all slots */int vm_slot_show_all_info(vm_instance_t *vm){ int i; for(i=0;i<vm->nr_slots;i++) vm_slot_show_info(vm,i); return(0);}/* Check if the specified slot has a valid EEPROM defined */int vm_slot_check_eeprom(vm_instance_t *vm,u_int slot_id,u_int port_id){ struct cisco_card *card,*rc; if (!(card = vm_slot_get_card_ptr(vm,slot_id))) return(FALSE); /* Get the real card (in case this is a sub-slot) */ vm_slot_translate_port_id(vm,slot_id,port_id,&rc); if (rc == NULL) return(FALSE); return(cisco_card_check_eeprom(rc));}/* Returns the EEPROM data of the specified slot */struct cisco_eeprom *vm_slot_get_eeprom(vm_instance_t *vm,u_int slot_id,u_int port_id){ struct cisco_card *card,*rc; if (!(card = vm_slot_get_card_ptr(vm,slot_id))) return NULL; /* Get the real card (in case this is a sub-slot) */ vm_slot_translate_port_id(vm,slot_id,port_id,&rc); if (rc == NULL) return NULL; return(&rc->eeprom);}/* Save config for the specified slot (sub-slots included) */int vm_slot_save_config(vm_instance_t *vm,u_int slot_id,FILE *fd){ struct cisco_card *card; int i; if (!(card = vm_slot_get_card_ptr(vm,slot_id))) return(-1); /* Main slot info */ cisco_card_save_config(vm,card,fd); /* Shutdown sub-slots */ for(i=0;i<CISCO_CARD_MAX_SUBSLOTS;i++) cisco_card_save_config(vm,card->sub_slots[i],fd); return(0);}/* Save config for all slots */int vm_slot_save_all_config(vm_instance_t *vm,FILE *fd){ int i; for(i=0;i<vm->nr_slots;i++) vm_slot_save_config(vm,i,fd); return(0);}/* Show slot drivers */int vm_slot_show_drivers(vm_instance_t *vm){ char *slot_type; int i; if (!vm->slots_drivers) return(-1); slot_type = cisco_card_get_type_desc(vm->slots_type); printf("Available %s %s drivers:\n",vm->platform->log_name,slot_type); for(i=0;vm->slots_drivers[i];i++) { printf(" * %s %s\n", vm->slots_drivers[i]->dev_type, !vm->slots_drivers[i]->supported ? "(NOT WORKING)" : ""); } printf("\n"); return(0);}/* Maximum number of tokens in a slot description */#define SLOT_DESC_MAX_TOKENS 8/* Create a Network Module (command line) */int vm_slot_cmd_create(vm_instance_t *vm,char *str){ char *tokens[SLOT_DESC_MAX_TOKENS]; int i,count,res; u_int slot_id,port_id; /* A port adapter description is like "1:0:NM-1FE" */ count = m_strsplit(str,':',tokens,SLOT_DESC_MAX_TOKENS); if ((count < 2) || (count > 3)) { vm_error(vm,"unable to parse slot description '%s'.\n",str); return(-1); } /* Parse the slot id */ slot_id = atoi(tokens[0]); /* Parse the sub-slot id */ if (count == 3) port_id = atoi(tokens[1]); else port_id = 0; /* Add this new slot to the current slot list */ res = vm_slot_add_binding(vm,tokens[count-1],slot_id,port_id); /* The complete array was cleaned by strsplit */ for(i=0;i<SLOT_DESC_MAX_TOKENS;i++) free(tokens[i]); return(res);}/* Add a Network IO descriptor binding (command line) */int vm_slot_cmd_add_nio(vm_instance_t *vm,char *str){ char *tokens[SLOT_DESC_MAX_TOKENS]; int i,count,nio_type,res=-1; u_int slot_id,port_id; netio_desc_t *nio; char nio_name[128]; /* A NIO binding description is like "1:3:tap:tap0" */ if ((count = m_strsplit(str,':',tokens,SLOT_DESC_MAX_TOKENS)) < 3) { vm_error(vm,"unable to parse NIO description '%s'.\n",str); return(-1); } /* Parse the slot id */ slot_id = atoi(tokens[0]); /* Parse the port id */ port_id = atoi(tokens[1]); /* Autogenerate a NIO name */ snprintf(nio_name,sizeof(nio_name),"%s-i%u/%u/%u", vm_get_type(vm),vm->instance_id,slot_id,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(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(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(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(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(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(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(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(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(vm,"unknown NETIO type '%s'\n",tokens[2]); goto done; } if (!nio) { vm_error(vm,"unable to create NETIO descriptor for slot %u\n",slot_id); goto done; } if (vm_slot_add_nio_binding(vm,slot_id,port_id,nio_name) == -1) { vm_error(vm,"unable to add NETIO binding for slot %u\n",slot_id); 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<SLOT_DESC_MAX_TOKENS;i++) free(tokens[i]); return(res);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -