uboot_skb.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Definitions for the 'struct sk_buff' memory handlers in U-Boot.
  3. *
  4. * (C) Copyright 2003
  5. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. */
  25. #include <config.h>
  26. #include <common.h>
  27. #include "u-boot_compat.h"
  28. #define MAX_SKB 50
  29. static struct sk_buff *sk_table[MAX_SKB];
  30. struct sk_buff * alloc_skb(u32 size, int dummy)
  31. {
  32. int i;
  33. struct sk_buff * ret = NULL;
  34. for (i = 0; i < MAX_SKB; i++)
  35. {
  36. if (sk_table[i])
  37. {
  38. /* Already allocated.
  39. */
  40. continue;
  41. }
  42. sk_table[i] = malloc(sizeof(struct sk_buff));
  43. if (! sk_table[i])
  44. {
  45. printf("alloc_skb: malloc failed\n");
  46. break;
  47. }
  48. memset(sk_table[i], 0, sizeof(struct sk_buff));
  49. sk_table[i]->data = sk_table[i]->data_unaligned =
  50. malloc(size + 16);
  51. if (! sk_table[i]->data)
  52. {
  53. printf("alloc_skb: malloc failed\n");
  54. free(sk_table[i]);
  55. sk_table[i] = NULL;
  56. break;
  57. }
  58. sk_table[i]->data += 16 - ((u32)sk_table[i]->data & 15);
  59. sk_table[i]->len = size;
  60. break;
  61. }
  62. if (i < MAX_SKB)
  63. {
  64. ret = sk_table[i];
  65. }
  66. if (! ret)
  67. {
  68. printf("Unable to allocate skb!\n");
  69. }
  70. return ret;
  71. }
  72. void dev_kfree_skb_any(struct sk_buff *skb)
  73. {
  74. int i;
  75. for (i = 0; i < MAX_SKB; i++)
  76. {
  77. if (sk_table[i] != skb)
  78. {
  79. continue;
  80. }
  81. free(skb->data_unaligned);
  82. free(skb);
  83. sk_table[i] = NULL;
  84. break;
  85. }
  86. if (i == MAX_SKB)
  87. {
  88. printf("SKB allocation error!\n");
  89. }
  90. }
  91. void skb_reserve(struct sk_buff *skb, unsigned int len)
  92. {
  93. skb->data+=len;
  94. }
  95. void skb_put(struct sk_buff *skb, unsigned int len)
  96. {
  97. skb->len+=len;
  98. }