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

~ [ 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