Lines Matching refs:nsim_dev

65 	struct nsim_dev *nsim_dev = file->private_data;  in nsim_dev_take_snapshot_write()  local
71 devlink = priv_to_devlink(nsim_dev); in nsim_dev_take_snapshot_write()
83 err = devlink_region_snapshot_create(nsim_dev->dummy_region, in nsim_dev_take_snapshot_write()
106 struct nsim_dev *nsim_dev = file->private_data; in nsim_dev_trap_fa_cookie_read() local
112 spin_lock(&nsim_dev->fa_cookie_lock); in nsim_dev_trap_fa_cookie_read()
113 fa_cookie = nsim_dev->fa_cookie; in nsim_dev_trap_fa_cookie_read()
125 spin_unlock(&nsim_dev->fa_cookie_lock); in nsim_dev_trap_fa_cookie_read()
133 spin_unlock(&nsim_dev->fa_cookie_lock); in nsim_dev_trap_fa_cookie_read()
141 struct nsim_dev *nsim_dev = file->private_data; in nsim_dev_trap_fa_cookie_write() local
173 spin_lock(&nsim_dev->fa_cookie_lock); in nsim_dev_trap_fa_cookie_write()
174 kfree(nsim_dev->fa_cookie); in nsim_dev_trap_fa_cookie_write()
175 nsim_dev->fa_cookie = fa_cookie; in nsim_dev_trap_fa_cookie_write()
176 spin_unlock(&nsim_dev->fa_cookie_lock); in nsim_dev_trap_fa_cookie_write()
195 static int nsim_dev_debugfs_init(struct nsim_dev *nsim_dev) in nsim_dev_debugfs_init() argument
199 sprintf(dev_ddir_name, DRV_NAME "%u", nsim_dev->nsim_bus_dev->dev.id); in nsim_dev_debugfs_init()
200 nsim_dev->ddir = debugfs_create_dir(dev_ddir_name, nsim_dev_ddir); in nsim_dev_debugfs_init()
201 if (IS_ERR(nsim_dev->ddir)) in nsim_dev_debugfs_init()
202 return PTR_ERR(nsim_dev->ddir); in nsim_dev_debugfs_init()
203 nsim_dev->ports_ddir = debugfs_create_dir("ports", nsim_dev->ddir); in nsim_dev_debugfs_init()
204 if (IS_ERR(nsim_dev->ports_ddir)) in nsim_dev_debugfs_init()
205 return PTR_ERR(nsim_dev->ports_ddir); in nsim_dev_debugfs_init()
206 debugfs_create_bool("fw_update_status", 0600, nsim_dev->ddir, in nsim_dev_debugfs_init()
207 &nsim_dev->fw_update_status); in nsim_dev_debugfs_init()
208 debugfs_create_u32("fw_update_overwrite_mask", 0600, nsim_dev->ddir, in nsim_dev_debugfs_init()
209 &nsim_dev->fw_update_overwrite_mask); in nsim_dev_debugfs_init()
210 debugfs_create_u32("max_macs", 0600, nsim_dev->ddir, in nsim_dev_debugfs_init()
211 &nsim_dev->max_macs); in nsim_dev_debugfs_init()
212 debugfs_create_bool("test1", 0600, nsim_dev->ddir, in nsim_dev_debugfs_init()
213 &nsim_dev->test1); in nsim_dev_debugfs_init()
214 nsim_dev->take_snapshot = debugfs_create_file("take_snapshot", in nsim_dev_debugfs_init()
216 nsim_dev->ddir, in nsim_dev_debugfs_init()
217 nsim_dev, in nsim_dev_debugfs_init()
219 debugfs_create_bool("dont_allow_reload", 0600, nsim_dev->ddir, in nsim_dev_debugfs_init()
220 &nsim_dev->dont_allow_reload); in nsim_dev_debugfs_init()
221 debugfs_create_bool("fail_reload", 0600, nsim_dev->ddir, in nsim_dev_debugfs_init()
222 &nsim_dev->fail_reload); in nsim_dev_debugfs_init()
223 debugfs_create_file("trap_flow_action_cookie", 0600, nsim_dev->ddir, in nsim_dev_debugfs_init()
224 nsim_dev, &nsim_dev_trap_fa_cookie_fops); in nsim_dev_debugfs_init()
226 nsim_dev->ddir, in nsim_dev_debugfs_init()
227 &nsim_dev->fail_trap_group_set); in nsim_dev_debugfs_init()
229 nsim_dev->ddir, in nsim_dev_debugfs_init()
230 &nsim_dev->fail_trap_policer_set); in nsim_dev_debugfs_init()
232 nsim_dev->ddir, in nsim_dev_debugfs_init()
233 &nsim_dev->fail_trap_policer_counter_get); in nsim_dev_debugfs_init()
234 nsim_udp_tunnels_debugfs_create(nsim_dev); in nsim_dev_debugfs_init()
238 static void nsim_dev_debugfs_exit(struct nsim_dev *nsim_dev) in nsim_dev_debugfs_exit() argument
240 debugfs_remove_recursive(nsim_dev->ports_ddir); in nsim_dev_debugfs_exit()
241 debugfs_remove_recursive(nsim_dev->ddir); in nsim_dev_debugfs_exit()
244 static int nsim_dev_port_debugfs_init(struct nsim_dev *nsim_dev, in nsim_dev_port_debugfs_init() argument
252 nsim_dev->ports_ddir); in nsim_dev_port_debugfs_init()
257 nsim_dev->nsim_bus_dev->dev.id); in nsim_dev_port_debugfs_init()
348 static void nsim_devlink_set_params_init_values(struct nsim_dev *nsim_dev, in nsim_devlink_set_params_init_values() argument
353 value.vu32 = nsim_dev->max_macs; in nsim_devlink_set_params_init_values()
357 value.vbool = nsim_dev->test1; in nsim_devlink_set_params_init_values()
365 struct nsim_dev *nsim_dev = devlink_priv(devlink); in nsim_devlink_param_load_driverinit_values() local
373 nsim_dev->max_macs = saved_value.vu32; in nsim_devlink_param_load_driverinit_values()
378 nsim_dev->test1 = saved_value.vbool; in nsim_devlink_param_load_driverinit_values()
389 static int nsim_dev_dummy_region_init(struct nsim_dev *nsim_dev, in nsim_dev_dummy_region_init() argument
392 nsim_dev->dummy_region = in nsim_dev_dummy_region_init()
396 return PTR_ERR_OR_ZERO(nsim_dev->dummy_region); in nsim_dev_dummy_region_init()
399 static void nsim_dev_dummy_region_exit(struct nsim_dev *nsim_dev) in nsim_dev_dummy_region_exit() argument
401 devlink_region_destroy(nsim_dev->dummy_region); in nsim_dev_dummy_region_exit()
413 struct nsim_dev *nsim_dev; member
543 struct nsim_dev *nsim_dev = nsim_dev_port->ns->nsim_dev; in nsim_dev_trap_report() local
544 struct devlink *devlink = priv_to_devlink(nsim_dev); in nsim_dev_trap_report()
548 nsim_trap_data = nsim_dev->trap_data; in nsim_dev_trap_report()
575 spin_lock_bh(&nsim_dev->fa_cookie_lock); in nsim_dev_trap_report()
576 fa_cookie = has_fa_cookie ? nsim_dev->fa_cookie : NULL; in nsim_dev_trap_report()
579 spin_unlock_bh(&nsim_dev->fa_cookie_lock); in nsim_dev_trap_report()
591 struct nsim_dev *nsim_dev; in nsim_dev_trap_report_work() local
595 nsim_dev = nsim_trap_data->nsim_dev; in nsim_dev_trap_report_work()
600 mutex_lock(&nsim_dev->port_list_lock); in nsim_dev_trap_report_work()
601 list_for_each_entry(nsim_dev_port, &nsim_dev->port_list, list) { in nsim_dev_trap_report_work()
607 mutex_unlock(&nsim_dev->port_list_lock); in nsim_dev_trap_report_work()
609 schedule_delayed_work(&nsim_dev->trap_data->trap_report_dw, in nsim_dev_trap_report_work()
616 struct nsim_dev *nsim_dev = devlink_priv(devlink); in nsim_dev_traps_init() local
645 nsim_trap_data->nsim_dev = nsim_dev; in nsim_dev_traps_init()
646 nsim_dev->trap_data = nsim_trap_data; in nsim_dev_traps_init()
663 INIT_DELAYED_WORK(&nsim_dev->trap_data->trap_report_dw, in nsim_dev_traps_init()
665 schedule_delayed_work(&nsim_dev->trap_data->trap_report_dw, in nsim_dev_traps_init()
687 struct nsim_dev *nsim_dev = devlink_priv(devlink); in nsim_dev_traps_exit() local
689 cancel_delayed_work_sync(&nsim_dev->trap_data->trap_report_dw); in nsim_dev_traps_exit()
696 kfree(nsim_dev->trap_data->trap_policers_cnt_arr); in nsim_dev_traps_exit()
697 kfree(nsim_dev->trap_data->trap_items_arr); in nsim_dev_traps_exit()
698 kfree(nsim_dev->trap_data); in nsim_dev_traps_exit()
701 static int nsim_dev_reload_create(struct nsim_dev *nsim_dev,
703 static void nsim_dev_reload_destroy(struct nsim_dev *nsim_dev);
709 struct nsim_dev *nsim_dev = devlink_priv(devlink); in nsim_dev_reload_down() local
711 if (nsim_dev->dont_allow_reload) { in nsim_dev_reload_down()
719 nsim_dev_reload_destroy(nsim_dev); in nsim_dev_reload_down()
727 struct nsim_dev *nsim_dev = devlink_priv(devlink); in nsim_dev_reload_up() local
729 if (nsim_dev->fail_reload) { in nsim_dev_reload_up()
738 return nsim_dev_reload_create(nsim_dev, extack); in nsim_dev_reload_up()
756 struct nsim_dev *nsim_dev = devlink_priv(devlink); in nsim_dev_flash_update() local
759 if ((params->overwrite_mask & ~nsim_dev->fw_update_overwrite_mask) != 0) in nsim_dev_flash_update()
762 if (nsim_dev->fw_update_status) { in nsim_dev_flash_update()
770 if (nsim_dev->fw_update_status) in nsim_dev_flash_update()
778 if (nsim_dev->fw_update_status) { in nsim_dev_flash_update()
794 nsim_dev_trap_item_lookup(struct nsim_dev *nsim_dev, u16 trap_id) in nsim_dev_trap_item_lookup() argument
796 struct nsim_trap_data *nsim_trap_data = nsim_dev->trap_data; in nsim_dev_trap_item_lookup()
811 struct nsim_dev *nsim_dev = devlink_priv(devlink); in nsim_dev_devlink_trap_init() local
814 nsim_trap_item = nsim_dev_trap_item_lookup(nsim_dev, trap->id); in nsim_dev_devlink_trap_init()
830 struct nsim_dev *nsim_dev = devlink_priv(devlink); in nsim_dev_devlink_trap_action_set() local
833 nsim_trap_item = nsim_dev_trap_item_lookup(nsim_dev, trap->id); in nsim_dev_devlink_trap_action_set()
837 spin_lock(&nsim_dev->trap_data->trap_lock); in nsim_dev_devlink_trap_action_set()
839 spin_unlock(&nsim_dev->trap_data->trap_lock); in nsim_dev_devlink_trap_action_set()
850 struct nsim_dev *nsim_dev = devlink_priv(devlink); in nsim_dev_devlink_trap_group_set() local
852 if (nsim_dev->fail_trap_group_set) in nsim_dev_devlink_trap_group_set()
864 struct nsim_dev *nsim_dev = devlink_priv(devlink); in nsim_dev_devlink_trap_policer_set() local
866 if (nsim_dev->fail_trap_policer_set) { in nsim_dev_devlink_trap_policer_set()
879 struct nsim_dev *nsim_dev = devlink_priv(devlink); in nsim_dev_devlink_trap_policer_counter_get() local
882 if (nsim_dev->fail_trap_policer_counter_get) in nsim_dev_devlink_trap_policer_counter_get()
885 cnt = &nsim_dev->trap_data->trap_policers_cnt_arr[policer->id - 1]; in nsim_dev_devlink_trap_policer_counter_get()
909 static int __nsim_dev_port_add(struct nsim_dev *nsim_dev, in __nsim_dev_port_add() argument
925 memcpy(attrs.switch_id.id, nsim_dev->switch_id.id, nsim_dev->switch_id.id_len); in __nsim_dev_port_add()
926 attrs.switch_id.id_len = nsim_dev->switch_id.id_len; in __nsim_dev_port_add()
928 err = devlink_port_register(priv_to_devlink(nsim_dev), devlink_port, in __nsim_dev_port_add()
933 err = nsim_dev_port_debugfs_init(nsim_dev, nsim_dev_port); in __nsim_dev_port_add()
937 nsim_dev_port->ns = nsim_create(nsim_dev, nsim_dev_port); in __nsim_dev_port_add()
944 list_add(&nsim_dev_port->list, &nsim_dev->port_list); in __nsim_dev_port_add()
969 static void nsim_dev_port_del_all(struct nsim_dev *nsim_dev) in nsim_dev_port_del_all() argument
973 mutex_lock(&nsim_dev->port_list_lock); in nsim_dev_port_del_all()
975 &nsim_dev->port_list, list) in nsim_dev_port_del_all()
977 mutex_unlock(&nsim_dev->port_list_lock); in nsim_dev_port_del_all()
980 static int nsim_dev_port_add_all(struct nsim_dev *nsim_dev, in nsim_dev_port_add_all() argument
986 err = __nsim_dev_port_add(nsim_dev, i); in nsim_dev_port_add_all()
993 nsim_dev_port_del_all(nsim_dev); in nsim_dev_port_add_all()
997 static int nsim_dev_reload_create(struct nsim_dev *nsim_dev, in nsim_dev_reload_create() argument
1000 struct nsim_bus_dev *nsim_bus_dev = nsim_dev->nsim_bus_dev; in nsim_dev_reload_create()
1004 devlink = priv_to_devlink(nsim_dev); in nsim_dev_reload_create()
1005 nsim_dev = devlink_priv(devlink); in nsim_dev_reload_create()
1006 INIT_LIST_HEAD(&nsim_dev->port_list); in nsim_dev_reload_create()
1007 mutex_init(&nsim_dev->port_list_lock); in nsim_dev_reload_create()
1008 nsim_dev->fw_update_status = true; in nsim_dev_reload_create()
1009 nsim_dev->fw_update_overwrite_mask = 0; in nsim_dev_reload_create()
1013 err = nsim_dev_dummy_region_init(nsim_dev, devlink); in nsim_dev_reload_create()
1021 nsim_dev->fib_data = nsim_fib_create(devlink, extack); in nsim_dev_reload_create()
1022 if (IS_ERR(nsim_dev->fib_data)) { in nsim_dev_reload_create()
1023 err = PTR_ERR(nsim_dev->fib_data); in nsim_dev_reload_create()
1027 err = nsim_dev_health_init(nsim_dev, devlink); in nsim_dev_reload_create()
1031 err = nsim_dev_port_add_all(nsim_dev, nsim_bus_dev->port_count); in nsim_dev_reload_create()
1035 nsim_dev->take_snapshot = debugfs_create_file("take_snapshot", in nsim_dev_reload_create()
1037 nsim_dev->ddir, in nsim_dev_reload_create()
1038 nsim_dev, in nsim_dev_reload_create()
1043 nsim_dev_health_exit(nsim_dev); in nsim_dev_reload_create()
1045 nsim_fib_destroy(devlink, nsim_dev->fib_data); in nsim_dev_reload_create()
1049 nsim_dev_dummy_region_exit(nsim_dev); in nsim_dev_reload_create()
1055 struct nsim_dev *nsim_dev; in nsim_dev_probe() local
1059 devlink = devlink_alloc(&nsim_dev_devlink_ops, sizeof(*nsim_dev)); in nsim_dev_probe()
1063 nsim_dev = devlink_priv(devlink); in nsim_dev_probe()
1064 nsim_dev->nsim_bus_dev = nsim_bus_dev; in nsim_dev_probe()
1065 nsim_dev->switch_id.id_len = sizeof(nsim_dev->switch_id.id); in nsim_dev_probe()
1066 get_random_bytes(nsim_dev->switch_id.id, nsim_dev->switch_id.id_len); in nsim_dev_probe()
1067 INIT_LIST_HEAD(&nsim_dev->port_list); in nsim_dev_probe()
1068 mutex_init(&nsim_dev->port_list_lock); in nsim_dev_probe()
1069 nsim_dev->fw_update_status = true; in nsim_dev_probe()
1070 nsim_dev->fw_update_overwrite_mask = 0; in nsim_dev_probe()
1071 nsim_dev->max_macs = NSIM_DEV_MAX_MACS_DEFAULT; in nsim_dev_probe()
1072 nsim_dev->test1 = NSIM_DEV_TEST1_DEFAULT; in nsim_dev_probe()
1073 spin_lock_init(&nsim_dev->fa_cookie_lock); in nsim_dev_probe()
1075 dev_set_drvdata(&nsim_bus_dev->dev, nsim_dev); in nsim_dev_probe()
1089 nsim_devlink_set_params_init_values(nsim_dev, devlink); in nsim_dev_probe()
1091 err = nsim_dev_dummy_region_init(nsim_dev, devlink); in nsim_dev_probe()
1099 err = nsim_dev_debugfs_init(nsim_dev); in nsim_dev_probe()
1103 nsim_dev->fib_data = nsim_fib_create(devlink, NULL); in nsim_dev_probe()
1104 if (IS_ERR(nsim_dev->fib_data)) { in nsim_dev_probe()
1105 err = PTR_ERR(nsim_dev->fib_data); in nsim_dev_probe()
1109 err = nsim_dev_health_init(nsim_dev, devlink); in nsim_dev_probe()
1113 err = nsim_bpf_dev_init(nsim_dev); in nsim_dev_probe()
1117 err = nsim_dev_port_add_all(nsim_dev, nsim_bus_dev->port_count); in nsim_dev_probe()
1126 nsim_bpf_dev_exit(nsim_dev); in nsim_dev_probe()
1128 nsim_dev_health_exit(nsim_dev); in nsim_dev_probe()
1130 nsim_fib_destroy(devlink, nsim_dev->fib_data); in nsim_dev_probe()
1132 nsim_dev_debugfs_exit(nsim_dev); in nsim_dev_probe()
1136 nsim_dev_dummy_region_exit(nsim_dev); in nsim_dev_probe()
1149 static void nsim_dev_reload_destroy(struct nsim_dev *nsim_dev) in nsim_dev_reload_destroy() argument
1151 struct devlink *devlink = priv_to_devlink(nsim_dev); in nsim_dev_reload_destroy()
1155 debugfs_remove(nsim_dev->take_snapshot); in nsim_dev_reload_destroy()
1156 nsim_dev_port_del_all(nsim_dev); in nsim_dev_reload_destroy()
1157 nsim_dev_health_exit(nsim_dev); in nsim_dev_reload_destroy()
1158 nsim_fib_destroy(devlink, nsim_dev->fib_data); in nsim_dev_reload_destroy()
1160 nsim_dev_dummy_region_exit(nsim_dev); in nsim_dev_reload_destroy()
1161 mutex_destroy(&nsim_dev->port_list_lock); in nsim_dev_reload_destroy()
1166 struct nsim_dev *nsim_dev = dev_get_drvdata(&nsim_bus_dev->dev); in nsim_dev_remove() local
1167 struct devlink *devlink = priv_to_devlink(nsim_dev); in nsim_dev_remove()
1171 nsim_dev_reload_destroy(nsim_dev); in nsim_dev_remove()
1173 nsim_bpf_dev_exit(nsim_dev); in nsim_dev_remove()
1174 nsim_dev_debugfs_exit(nsim_dev); in nsim_dev_remove()
1183 __nsim_dev_port_lookup(struct nsim_dev *nsim_dev, unsigned int port_index) in __nsim_dev_port_lookup() argument
1187 list_for_each_entry(nsim_dev_port, &nsim_dev->port_list, list) in __nsim_dev_port_lookup()
1196 struct nsim_dev *nsim_dev = dev_get_drvdata(&nsim_bus_dev->dev); in nsim_dev_port_add() local
1199 mutex_lock(&nsim_dev->port_list_lock); in nsim_dev_port_add()
1200 if (__nsim_dev_port_lookup(nsim_dev, port_index)) in nsim_dev_port_add()
1203 err = __nsim_dev_port_add(nsim_dev, port_index); in nsim_dev_port_add()
1204 mutex_unlock(&nsim_dev->port_list_lock); in nsim_dev_port_add()
1211 struct nsim_dev *nsim_dev = dev_get_drvdata(&nsim_bus_dev->dev); in nsim_dev_port_del() local
1215 mutex_lock(&nsim_dev->port_list_lock); in nsim_dev_port_del()
1216 nsim_dev_port = __nsim_dev_port_lookup(nsim_dev, port_index); in nsim_dev_port_del()
1221 mutex_unlock(&nsim_dev->port_list_lock); in nsim_dev_port_del()