~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/net/core/hwbm.c

Version: ~ [ linux-5.13-rc5 ] ~ [ linux-5.12.9 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.42 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.124 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.193 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.235 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.271 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.271 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp