1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
8 struct multicore_worker __percpu
*
9 wg_packet_percpu_multicore_worker_alloc(work_func_t function
, void *ptr
)
12 struct multicore_worker __percpu
*worker
=
13 alloc_percpu(struct multicore_worker
);
18 for_each_possible_cpu(cpu
) {
19 per_cpu_ptr(worker
, cpu
)->ptr
= ptr
;
20 INIT_WORK(&per_cpu_ptr(worker
, cpu
)->work
, function
);
25 int wg_packet_queue_init(struct crypt_queue
*queue
, work_func_t function
,
26 bool multicore
, unsigned int len
)
30 memset(queue
, 0, sizeof(*queue
));
31 ret
= ptr_ring_init(&queue
->ring
, len
, GFP_KERNEL
);
36 queue
->worker
= wg_packet_percpu_multicore_worker_alloc(
39 ptr_ring_cleanup(&queue
->ring
, NULL
);
43 INIT_WORK(&queue
->work
, function
);
49 void wg_packet_queue_free(struct crypt_queue
*queue
, bool multicore
)
52 free_percpu(queue
->worker
);
53 WARN_ON(!__ptr_ring_empty(&queue
->ring
));
54 ptr_ring_cleanup(&queue
->ring
, NULL
);