uboot_skb.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. #ifdef CONFIG_SK98
  27. #include <common.h>
  28. #include "u-boot_compat.h"
  29. #define MAX_SKB 50
  30. static struct sk_buff *sk_table[MAX_SKB];
  31. struct sk_buff * alloc_skb(u32 size, int dummy)
  32. {
  33. int i;
  34. struct sk_buff * ret = NULL;
  35. for (i = 0; i < MAX_SKB; i++)
  36. {
  37. if (sk_table[i])
  38. {
  39. /* Already allocated.
  40. */
  41. continue;
  42. }
  43. sk_table[i] = malloc(sizeof(struct sk_buff));
  44. if (! sk_table[i])
  45. {
  46. printf("alloc_skb: malloc failed\n");
  47. break;
  48. }
  49. memset(sk_table[i], 0, sizeof(struct sk_buff));
  50. sk_table[i]->data = sk_table[i]->data_unaligned =
  51. malloc(size + 16);
  52. if (! sk_table[i]->data)
  53. {
  54. printf("alloc_skb: malloc failed\n");
  55. free(sk_table[i]);
  56. sk_table[i] = NULL;
  57. break;
  58. }
  59. sk_table[i]->data += 16 - ((u32)sk_table[i]->data & 15);
  60. sk_table[i]->len = size;
  61. break;
  62. }
  63. if (i < MAX_SKB)
  64. {
  65. ret = sk_table[i];
  66. }
  67. if (! ret)
  68. {
  69. printf("Unable to allocate skb!\n");
  70. }
  71. return ret;
  72. }
  73. void dev_kfree_skb_any(struct sk_buff *skb)
  74. {
  75. int i;
  76. for (i = 0; i < MAX_SKB; i++)
  77. {
  78. if (sk_table[i] != skb)
  79. {
  80. continue;
  81. }
  82. free(skb->data_unaligned);
  83. free(skb);
  84. sk_table[i] = NULL;
  85. break;
  86. }
  87. if (i == MAX_SKB)
  88. {
  89. printf("SKB allocation error!\n");
  90. }
  91. }
  92. void skb_reserve(struct sk_buff *skb, unsigned int len)
  93. {
  94. skb->data+=len;
  95. }
  96. void skb_put(struct sk_buff *skb, unsigned int len)
  97. {
  98. skb->len+=len;
  99. }
  100. #endif /* CONFIG_SK98 */