Lines Matching refs:devlink

19 static struct devlink *devlinks_xa_get(unsigned long index)  in devlinks_xa_get()
21 struct devlink *devlink; in devlinks_xa_get() local
24 devlink = xa_find(&devlinks, &index, index, DEVLINK_REGISTERED); in devlinks_xa_get()
25 if (!devlink || !devlink_try_get(devlink)) in devlinks_xa_get()
26 devlink = NULL; in devlinks_xa_get()
28 return devlink; in devlinks_xa_get()
74 struct devlink *devlink; in devlink_rel_nested_in_notify_work() local
76 devlink = devlinks_xa_get(rel->nested_in.devlink_index); in devlink_rel_nested_in_notify_work()
77 if (!devlink) in devlink_rel_nested_in_notify_work()
79 if (!devl_trylock(devlink)) { in devlink_rel_nested_in_notify_work()
80 devlink_put(devlink); in devlink_rel_nested_in_notify_work()
83 if (!devl_is_registered(devlink)) { in devlink_rel_nested_in_notify_work()
84 devl_unlock(devlink); in devlink_rel_nested_in_notify_work()
85 devlink_put(devlink); in devlink_rel_nested_in_notify_work()
89 rel->nested_in.cleanup_cb(devlink, rel->nested_in.obj_index, rel->index); in devlink_rel_nested_in_notify_work()
90 rel->nested_in.notify_cb(devlink, rel->nested_in.obj_index); in devlink_rel_nested_in_notify_work()
91 devl_unlock(devlink); in devlink_rel_nested_in_notify_work()
92 devlink_put(devlink); in devlink_rel_nested_in_notify_work()
131 static void devlink_rel_put(struct devlink *devlink) in devlink_rel_put() argument
133 struct devlink_rel *rel = devlink->rel; in devlink_rel_put()
140 devlink->rel = NULL; in devlink_rel_put()
151 struct devlink *devlink) in devlink_rel_nested_in_add() argument
155 ASSERT_DEVLINK_NOT_REGISTERED(devlink); in devlink_rel_nested_in_add()
160 rel->devlink_index = devlink->index; in devlink_rel_nested_in_add()
167 devlink->rel = rel; in devlink_rel_nested_in_add()
185 void devlink_rel_nested_in_notify(struct devlink *devlink) in devlink_rel_nested_in_notify() argument
187 struct devlink_rel *rel = devlink->rel; in devlink_rel_nested_in_notify()
200 static struct devlink *devlink_rel_devlink_get(u32 rel_index) in devlink_rel_devlink_get()
217 int devlink_rel_devlink_handle_put(struct sk_buff *msg, struct devlink *devlink, in devlink_rel_devlink_handle_put() argument
221 struct net *net = devlink_net(devlink); in devlink_rel_devlink_handle_put()
222 struct devlink *rel_devlink; in devlink_rel_devlink_handle_put()
235 void *devlink_priv(struct devlink *devlink) in devlink_priv() argument
237 return &devlink->priv; in devlink_priv()
241 struct devlink *priv_to_devlink(void *priv) in priv_to_devlink()
243 return container_of(priv, struct devlink, priv); in priv_to_devlink()
247 struct device *devlink_to_dev(const struct devlink *devlink) in devlink_to_dev() argument
249 return devlink->dev; in devlink_to_dev()
253 struct net *devlink_net(const struct devlink *devlink) in devlink_net() argument
255 return read_pnet(&devlink->_net); in devlink_net()
259 void devl_assert_locked(struct devlink *devlink) in devl_assert_locked() argument
261 lockdep_assert_held(&devlink->lock); in devl_assert_locked()
267 bool devl_lock_is_held(struct devlink *devlink) in devl_lock_is_held() argument
269 return lockdep_is_held(&devlink->lock); in devl_lock_is_held()
274 void devl_lock(struct devlink *devlink) in devl_lock() argument
276 mutex_lock(&devlink->lock); in devl_lock()
280 int devl_trylock(struct devlink *devlink) in devl_trylock() argument
282 return mutex_trylock(&devlink->lock); in devl_trylock()
286 void devl_unlock(struct devlink *devlink) in devl_unlock() argument
288 mutex_unlock(&devlink->lock); in devl_unlock()
301 struct devlink *__must_check devlink_try_get(struct devlink *devlink) in devlink_try_get() argument
303 if (refcount_inc_not_zero(&devlink->refcount)) in devlink_try_get()
304 return devlink; in devlink_try_get()
310 struct devlink *devlink; in devlink_release() local
312 devlink = container_of(to_rcu_work(work), struct devlink, rwork); in devlink_release()
314 mutex_destroy(&devlink->lock); in devlink_release()
315 lockdep_unregister_key(&devlink->lock_key); in devlink_release()
316 put_device(devlink->dev); in devlink_release()
317 kvfree(devlink); in devlink_release()
320 void devlink_put(struct devlink *devlink) in devlink_put() argument
322 if (refcount_dec_and_test(&devlink->refcount)) in devlink_put()
323 queue_rcu_work(system_wq, &devlink->rwork); in devlink_put()
326 struct devlink *devlinks_xa_find_get(struct net *net, unsigned long *indexp) in devlinks_xa_find_get()
328 struct devlink *devlink = NULL; in devlinks_xa_find_get() local
332 devlink = xa_find(&devlinks, indexp, ULONG_MAX, DEVLINK_REGISTERED); in devlinks_xa_find_get()
333 if (!devlink) in devlinks_xa_find_get()
336 if (!devlink_try_get(devlink)) in devlinks_xa_find_get()
338 if (!net_eq(devlink_net(devlink), net)) { in devlinks_xa_find_get()
339 devlink_put(devlink); in devlinks_xa_find_get()
344 return devlink; in devlinks_xa_find_get()
355 int devl_register(struct devlink *devlink) in devl_register() argument
357 ASSERT_DEVLINK_NOT_REGISTERED(devlink); in devl_register()
358 devl_assert_locked(devlink); in devl_register()
360 xa_set_mark(&devlinks, devlink->index, DEVLINK_REGISTERED); in devl_register()
361 devlink_notify_register(devlink); in devl_register()
362 devlink_rel_nested_in_notify(devlink); in devl_register()
368 void devlink_register(struct devlink *devlink) in devlink_register() argument
370 devl_lock(devlink); in devlink_register()
371 devl_register(devlink); in devlink_register()
372 devl_unlock(devlink); in devlink_register()
380 void devl_unregister(struct devlink *devlink) in devl_unregister() argument
382 ASSERT_DEVLINK_REGISTERED(devlink); in devl_unregister()
383 devl_assert_locked(devlink); in devl_unregister()
385 devlink_notify_unregister(devlink); in devl_unregister()
386 xa_clear_mark(&devlinks, devlink->index, DEVLINK_REGISTERED); in devl_unregister()
387 devlink_rel_put(devlink); in devl_unregister()
391 void devlink_unregister(struct devlink *devlink) in devlink_unregister() argument
393 devl_lock(devlink); in devlink_unregister()
394 devl_unregister(devlink); in devlink_unregister()
395 devl_unlock(devlink); in devlink_unregister()
411 struct devlink *devlink_alloc_ns(const struct devlink_ops *ops, in devlink_alloc_ns()
415 struct devlink *devlink; in devlink_alloc_ns() local
423 devlink = kvzalloc(struct_size(devlink, priv, priv_size), GFP_KERNEL); in devlink_alloc_ns()
424 if (!devlink) in devlink_alloc_ns()
427 ret = xa_alloc_cyclic(&devlinks, &devlink->index, devlink, xa_limit_31b, in devlink_alloc_ns()
432 devlink->dev = get_device(dev); in devlink_alloc_ns()
433 devlink->ops = ops; in devlink_alloc_ns()
434 xa_init_flags(&devlink->ports, XA_FLAGS_ALLOC); in devlink_alloc_ns()
435 xa_init_flags(&devlink->params, XA_FLAGS_ALLOC); in devlink_alloc_ns()
436 xa_init_flags(&devlink->snapshot_ids, XA_FLAGS_ALLOC); in devlink_alloc_ns()
437 xa_init_flags(&devlink->nested_rels, XA_FLAGS_ALLOC); in devlink_alloc_ns()
438 write_pnet(&devlink->_net, net); in devlink_alloc_ns()
439 INIT_LIST_HEAD(&devlink->rate_list); in devlink_alloc_ns()
440 INIT_LIST_HEAD(&devlink->linecard_list); in devlink_alloc_ns()
441 INIT_LIST_HEAD(&devlink->sb_list); in devlink_alloc_ns()
442 INIT_LIST_HEAD_RCU(&devlink->dpipe_table_list); in devlink_alloc_ns()
443 INIT_LIST_HEAD(&devlink->resource_list); in devlink_alloc_ns()
444 INIT_LIST_HEAD(&devlink->region_list); in devlink_alloc_ns()
445 INIT_LIST_HEAD(&devlink->reporter_list); in devlink_alloc_ns()
446 INIT_LIST_HEAD(&devlink->trap_list); in devlink_alloc_ns()
447 INIT_LIST_HEAD(&devlink->trap_group_list); in devlink_alloc_ns()
448 INIT_LIST_HEAD(&devlink->trap_policer_list); in devlink_alloc_ns()
449 INIT_RCU_WORK(&devlink->rwork, devlink_release); in devlink_alloc_ns()
450 lockdep_register_key(&devlink->lock_key); in devlink_alloc_ns()
451 mutex_init(&devlink->lock); in devlink_alloc_ns()
452 lockdep_set_class(&devlink->lock, &devlink->lock_key); in devlink_alloc_ns()
453 refcount_set(&devlink->refcount, 1); in devlink_alloc_ns()
455 return devlink; in devlink_alloc_ns()
458 kvfree(devlink); in devlink_alloc_ns()
468 void devlink_free(struct devlink *devlink) in devlink_free() argument
470 ASSERT_DEVLINK_NOT_REGISTERED(devlink); in devlink_free()
472 WARN_ON(!list_empty(&devlink->trap_policer_list)); in devlink_free()
473 WARN_ON(!list_empty(&devlink->trap_group_list)); in devlink_free()
474 WARN_ON(!list_empty(&devlink->trap_list)); in devlink_free()
475 WARN_ON(!list_empty(&devlink->reporter_list)); in devlink_free()
476 WARN_ON(!list_empty(&devlink->region_list)); in devlink_free()
477 WARN_ON(!list_empty(&devlink->resource_list)); in devlink_free()
478 WARN_ON(!list_empty(&devlink->dpipe_table_list)); in devlink_free()
479 WARN_ON(!list_empty(&devlink->sb_list)); in devlink_free()
480 WARN_ON(!list_empty(&devlink->rate_list)); in devlink_free()
481 WARN_ON(!list_empty(&devlink->linecard_list)); in devlink_free()
482 WARN_ON(!xa_empty(&devlink->ports)); in devlink_free()
484 xa_destroy(&devlink->nested_rels); in devlink_free()
485 xa_destroy(&devlink->snapshot_ids); in devlink_free()
486 xa_destroy(&devlink->params); in devlink_free()
487 xa_destroy(&devlink->ports); in devlink_free()
489 xa_erase(&devlinks, devlink->index); in devlink_free()
491 devlink_put(devlink); in devlink_free()
497 struct devlink *devlink; in devlink_pernet_pre_exit() local
505 devlinks_xa_for_each_registered_get(net, index, devlink) { in devlink_pernet_pre_exit()
506 devl_dev_lock(devlink, true); in devlink_pernet_pre_exit()
508 if (devl_is_registered(devlink)) in devlink_pernet_pre_exit()
509 err = devlink_reload(devlink, &init_net, in devlink_pernet_pre_exit()
513 devl_dev_unlock(devlink, true); in devlink_pernet_pre_exit()
514 devlink_put(devlink); in devlink_pernet_pre_exit()