Lines Matching refs:pool

19 #define MLX5_CRYPTO_DEK_POOL_CALC_FREED(pool) MLX5_CRYPTO_DEK_CALC_FREED(pool)  argument
288 mlx5_crypto_dek_bulk_create(struct mlx5_crypto_dek_pool *pool) in mlx5_crypto_dek_bulk_create() argument
290 struct mlx5_crypto_dek_priv *dek_priv = pool->mdev->mlx5e_res.dek_priv; in mlx5_crypto_dek_bulk_create()
291 struct mlx5_core_dev *mdev = pool->mdev; in mlx5_crypto_dek_bulk_create()
313 err = mlx5_crypto_create_dek_bulk(mdev, pool->key_purpose, in mlx5_crypto_dek_bulk_create()
334 mlx5_crypto_dek_pool_add_bulk(struct mlx5_crypto_dek_pool *pool) in mlx5_crypto_dek_pool_add_bulk() argument
338 bulk = mlx5_crypto_dek_bulk_create(pool); in mlx5_crypto_dek_pool_add_bulk()
342 pool->avail_deks += bulk->num_deks; in mlx5_crypto_dek_pool_add_bulk()
343 pool->num_deks += bulk->num_deks; in mlx5_crypto_dek_pool_add_bulk()
344 list_add(&bulk->entry, &pool->partial_list); in mlx5_crypto_dek_pool_add_bulk()
357 static void mlx5_crypto_dek_pool_remove_bulk(struct mlx5_crypto_dek_pool *pool, in mlx5_crypto_dek_pool_remove_bulk() argument
361 pool->num_deks -= bulk->num_deks; in mlx5_crypto_dek_pool_remove_bulk()
362 pool->avail_deks -= bulk->avail_deks; in mlx5_crypto_dek_pool_remove_bulk()
363 pool->in_use_deks -= bulk->in_use_deks; in mlx5_crypto_dek_pool_remove_bulk()
370 mlx5_crypto_dek_pool_pop(struct mlx5_crypto_dek_pool *pool, u32 *obj_offset) in mlx5_crypto_dek_pool_pop() argument
375 mutex_lock(&pool->lock); in mlx5_crypto_dek_pool_pop()
376 bulk = list_first_entry_or_null(&pool->partial_list, in mlx5_crypto_dek_pool_pop()
383 mlx5_core_err(pool->mdev, "Wrong DEK bulk avail_start.\n"); in mlx5_crypto_dek_pool_pop()
388 bulk = list_first_entry_or_null(&pool->avail_list, in mlx5_crypto_dek_pool_pop()
392 list_move(&bulk->entry, &pool->partial_list); in mlx5_crypto_dek_pool_pop()
394 bulk = mlx5_crypto_dek_pool_add_bulk(pool); in mlx5_crypto_dek_pool_pop()
407 list_move(&bulk->entry, &pool->full_list); in mlx5_crypto_dek_pool_pop()
412 pool->avail_deks--; in mlx5_crypto_dek_pool_pop()
413 pool->in_use_deks++; in mlx5_crypto_dek_pool_pop()
416 mutex_unlock(&pool->lock); in mlx5_crypto_dek_pool_pop()
420 static bool mlx5_crypto_dek_need_sync(struct mlx5_crypto_dek_pool *pool) in mlx5_crypto_dek_need_sync() argument
422 return !pool->syncing && in mlx5_crypto_dek_need_sync()
423 MLX5_CRYPTO_DEK_POOL_CALC_FREED(pool) > MLX5_CRYPTO_DEK_POOL_SYNC_THRESH; in mlx5_crypto_dek_need_sync()
426 static int mlx5_crypto_dek_free_locked(struct mlx5_crypto_dek_pool *pool, in mlx5_crypto_dek_free_locked() argument
441 pool->in_use_deks--; in mlx5_crypto_dek_free_locked()
444 list_move(&bulk->entry, &pool->sync_list); in mlx5_crypto_dek_free_locked()
446 if (mlx5_crypto_dek_need_sync(pool) && schedule_work(&pool->sync_work)) in mlx5_crypto_dek_free_locked()
447 pool->syncing = true; in mlx5_crypto_dek_free_locked()
454 static int mlx5_crypto_dek_pool_push(struct mlx5_crypto_dek_pool *pool, in mlx5_crypto_dek_pool_push() argument
459 mutex_lock(&pool->lock); in mlx5_crypto_dek_pool_push()
460 if (pool->syncing) in mlx5_crypto_dek_pool_push()
461 list_add(&dek->entry, &pool->wait_for_free); in mlx5_crypto_dek_pool_push()
463 err = mlx5_crypto_dek_free_locked(pool, dek); in mlx5_crypto_dek_pool_push()
464 mutex_unlock(&pool->lock); in mlx5_crypto_dek_pool_push()
479 static void mlx5_crypto_dek_bulk_reset_synced(struct mlx5_crypto_dek_pool *pool, in mlx5_crypto_dek_bulk_reset_synced() argument
496 pool->avail_deks += reused; in mlx5_crypto_dek_bulk_reset_synced()
510 static bool mlx5_crypto_dek_bulk_handle_avail(struct mlx5_crypto_dek_pool *pool, in mlx5_crypto_dek_bulk_handle_avail() argument
514 if (list_empty(&pool->avail_list)) { in mlx5_crypto_dek_bulk_handle_avail()
515 list_move(&bulk->entry, &pool->avail_list); in mlx5_crypto_dek_bulk_handle_avail()
519 mlx5_crypto_dek_pool_remove_bulk(pool, bulk, true); in mlx5_crypto_dek_bulk_handle_avail()
524 static void mlx5_crypto_dek_pool_splice_destroy_list(struct mlx5_crypto_dek_pool *pool, in mlx5_crypto_dek_pool_splice_destroy_list() argument
528 spin_lock(&pool->destroy_lock); in mlx5_crypto_dek_pool_splice_destroy_list()
530 spin_unlock(&pool->destroy_lock); in mlx5_crypto_dek_pool_splice_destroy_list()
533 static void mlx5_crypto_dek_pool_free_wait_keys(struct mlx5_crypto_dek_pool *pool) in mlx5_crypto_dek_pool_free_wait_keys() argument
537 list_for_each_entry_safe(dek, next, &pool->wait_for_free, entry) { in mlx5_crypto_dek_pool_free_wait_keys()
539 mlx5_crypto_dek_free_locked(pool, dek); in mlx5_crypto_dek_pool_free_wait_keys()
548 static void mlx5_crypto_dek_pool_reset_synced(struct mlx5_crypto_dek_pool *pool) in mlx5_crypto_dek_pool_reset_synced() argument
553 list_for_each_entry_safe(bulk, tmp, &pool->partial_list, entry) { in mlx5_crypto_dek_pool_reset_synced()
554 mlx5_crypto_dek_bulk_reset_synced(pool, bulk); in mlx5_crypto_dek_pool_reset_synced()
556 mlx5_crypto_dek_bulk_handle_avail(pool, bulk, &destroy_list); in mlx5_crypto_dek_pool_reset_synced()
559 list_for_each_entry_safe(bulk, tmp, &pool->full_list, entry) { in mlx5_crypto_dek_pool_reset_synced()
560 mlx5_crypto_dek_bulk_reset_synced(pool, bulk); in mlx5_crypto_dek_pool_reset_synced()
566 mlx5_crypto_dek_bulk_handle_avail(pool, bulk, &destroy_list); in mlx5_crypto_dek_pool_reset_synced()
568 list_move(&bulk->entry, &pool->partial_list); in mlx5_crypto_dek_pool_reset_synced()
571 list_for_each_entry_safe(bulk, tmp, &pool->sync_list, entry) { in mlx5_crypto_dek_pool_reset_synced()
573 pool->avail_deks += bulk->num_deks; in mlx5_crypto_dek_pool_reset_synced()
574 if (mlx5_crypto_dek_bulk_handle_avail(pool, bulk, &destroy_list)) { in mlx5_crypto_dek_pool_reset_synced()
580 mlx5_crypto_dek_pool_free_wait_keys(pool); in mlx5_crypto_dek_pool_reset_synced()
583 mlx5_crypto_dek_pool_splice_destroy_list(pool, &destroy_list, in mlx5_crypto_dek_pool_reset_synced()
584 &pool->destroy_list); in mlx5_crypto_dek_pool_reset_synced()
585 schedule_work(&pool->destroy_work); in mlx5_crypto_dek_pool_reset_synced()
591 struct mlx5_crypto_dek_pool *pool = in mlx5_crypto_dek_sync_work_fn() local
595 err = mlx5_crypto_cmd_sync_crypto(pool->mdev, BIT(pool->key_purpose)); in mlx5_crypto_dek_sync_work_fn()
596 mutex_lock(&pool->lock); in mlx5_crypto_dek_sync_work_fn()
598 mlx5_crypto_dek_pool_reset_synced(pool); in mlx5_crypto_dek_sync_work_fn()
599 pool->syncing = false; in mlx5_crypto_dek_sync_work_fn()
600 mutex_unlock(&pool->lock); in mlx5_crypto_dek_sync_work_fn()
672 struct mlx5_crypto_dek_pool *pool = in mlx5_crypto_dek_destroy_work_fn() local
676 mlx5_crypto_dek_pool_splice_destroy_list(pool, &pool->destroy_list, in mlx5_crypto_dek_destroy_work_fn()
684 struct mlx5_crypto_dek_pool *pool; in mlx5_crypto_dek_pool_create() local
686 pool = kzalloc(sizeof(*pool), GFP_KERNEL); in mlx5_crypto_dek_pool_create()
687 if (!pool) in mlx5_crypto_dek_pool_create()
690 pool->mdev = mdev; in mlx5_crypto_dek_pool_create()
691 pool->key_purpose = key_purpose; in mlx5_crypto_dek_pool_create()
693 mutex_init(&pool->lock); in mlx5_crypto_dek_pool_create()
694 INIT_LIST_HEAD(&pool->avail_list); in mlx5_crypto_dek_pool_create()
695 INIT_LIST_HEAD(&pool->partial_list); in mlx5_crypto_dek_pool_create()
696 INIT_LIST_HEAD(&pool->full_list); in mlx5_crypto_dek_pool_create()
697 INIT_LIST_HEAD(&pool->sync_list); in mlx5_crypto_dek_pool_create()
698 INIT_LIST_HEAD(&pool->wait_for_free); in mlx5_crypto_dek_pool_create()
699 INIT_WORK(&pool->sync_work, mlx5_crypto_dek_sync_work_fn); in mlx5_crypto_dek_pool_create()
700 spin_lock_init(&pool->destroy_lock); in mlx5_crypto_dek_pool_create()
701 INIT_LIST_HEAD(&pool->destroy_list); in mlx5_crypto_dek_pool_create()
702 INIT_WORK(&pool->destroy_work, mlx5_crypto_dek_destroy_work_fn); in mlx5_crypto_dek_pool_create()
704 return pool; in mlx5_crypto_dek_pool_create()
707 void mlx5_crypto_dek_pool_destroy(struct mlx5_crypto_dek_pool *pool) in mlx5_crypto_dek_pool_destroy() argument
711 cancel_work_sync(&pool->sync_work); in mlx5_crypto_dek_pool_destroy()
712 cancel_work_sync(&pool->destroy_work); in mlx5_crypto_dek_pool_destroy()
714 mlx5_crypto_dek_pool_free_wait_keys(pool); in mlx5_crypto_dek_pool_destroy()
716 list_for_each_entry_safe(bulk, tmp, &pool->avail_list, entry) in mlx5_crypto_dek_pool_destroy()
717 mlx5_crypto_dek_pool_remove_bulk(pool, bulk, false); in mlx5_crypto_dek_pool_destroy()
719 list_for_each_entry_safe(bulk, tmp, &pool->full_list, entry) in mlx5_crypto_dek_pool_destroy()
720 mlx5_crypto_dek_pool_remove_bulk(pool, bulk, false); in mlx5_crypto_dek_pool_destroy()
722 list_for_each_entry_safe(bulk, tmp, &pool->sync_list, entry) in mlx5_crypto_dek_pool_destroy()
723 mlx5_crypto_dek_pool_remove_bulk(pool, bulk, false); in mlx5_crypto_dek_pool_destroy()
725 list_for_each_entry_safe(bulk, tmp, &pool->partial_list, entry) in mlx5_crypto_dek_pool_destroy()
726 mlx5_crypto_dek_pool_remove_bulk(pool, bulk, false); in mlx5_crypto_dek_pool_destroy()
728 mlx5_crypto_dek_free_destroy_list(&pool->destroy_list); in mlx5_crypto_dek_pool_destroy()
730 mutex_destroy(&pool->lock); in mlx5_crypto_dek_pool_destroy()
732 kfree(pool); in mlx5_crypto_dek_pool_destroy()