Blame view
net/core/hwbm.c
1.88 KB
2874c5fd2
|
1 |
// SPDX-License-Identifier: GPL-2.0-or-later |
8cb2d8bf5
|
2 3 4 5 6 |
/* Support for hardware buffer manager. * * Copyright (C) 2016 Marvell * * Gregory CLEMENT <gregory.clement@free-electrons.com> |
8cb2d8bf5
|
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
*/ #include <linux/kernel.h> #include <linux/printk.h> #include <linux/skbuff.h> #include <net/hwbm.h> void hwbm_buf_free(struct hwbm_pool *bm_pool, void *buf) { if (likely(bm_pool->frag_size <= PAGE_SIZE)) skb_free_frag(buf); else kfree(buf); } EXPORT_SYMBOL_GPL(hwbm_buf_free); /* Refill processing for HW buffer management */ int hwbm_pool_refill(struct hwbm_pool *bm_pool, gfp_t gfp) { int frag_size = bm_pool->frag_size; void *buf; if (likely(frag_size <= PAGE_SIZE)) buf = netdev_alloc_frag(frag_size); else buf = kmalloc(frag_size, gfp); if (!buf) return -ENOMEM; if (bm_pool->construct) if (bm_pool->construct(bm_pool, buf)) { hwbm_buf_free(bm_pool, buf); return -ENOMEM; } return 0; } EXPORT_SYMBOL_GPL(hwbm_pool_refill); |
6dcdd884e
|
45 |
int hwbm_pool_add(struct hwbm_pool *bm_pool, unsigned int buf_num) |
8cb2d8bf5
|
46 47 |
{ int err, i; |
8cb2d8bf5
|
48 |
|
6dcdd884e
|
49 |
mutex_lock(&bm_pool->buf_lock); |
8cb2d8bf5
|
50 51 52 |
if (bm_pool->buf_num == bm_pool->size) { pr_warn("pool already filled "); |
6dcdd884e
|
53 |
mutex_unlock(&bm_pool->buf_lock); |
8cb2d8bf5
|
54 55 56 57 58 59 60 |
return bm_pool->buf_num; } if (buf_num + bm_pool->buf_num > bm_pool->size) { pr_warn("cannot allocate %d buffers for pool ", buf_num); |
6dcdd884e
|
61 |
mutex_unlock(&bm_pool->buf_lock); |
8cb2d8bf5
|
62 63 64 65 66 67 68 |
return 0; } if ((buf_num + bm_pool->buf_num) < bm_pool->buf_num) { pr_warn("Adding %d buffers to the %d current buffers will overflow ", buf_num, bm_pool->buf_num); |
6dcdd884e
|
69 |
mutex_unlock(&bm_pool->buf_lock); |
8cb2d8bf5
|
70 71 72 73 |
return 0; } for (i = 0; i < buf_num; i++) { |
6dcdd884e
|
74 |
err = hwbm_pool_refill(bm_pool, GFP_KERNEL); |
8cb2d8bf5
|
75 76 77 78 79 80 81 82 83 |
if (err < 0) break; } /* Update BM driver with number of buffers added to pool */ bm_pool->buf_num += i; pr_debug("hwpm pool: %d of %d buffers added ", i, buf_num); |
6dcdd884e
|
84 |
mutex_unlock(&bm_pool->buf_lock); |
8cb2d8bf5
|
85 86 87 88 |
return i; } EXPORT_SYMBOL_GPL(hwbm_pool_add); |