fhci-mem.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Freescale QUICC Engine USB Host Controller Driver
  3. *
  4. * Copyright (c) Freescale Semicondutor, Inc. 2006.
  5. * Shlomi Gridish <gridish@freescale.com>
  6. * Jerry Huang <Chang-Ming.Huang@freescale.com>
  7. * Copyright (c) Logic Product Development, Inc. 2007
  8. * Peter Barada <peterb@logicpd.com>
  9. * Copyright (c) MontaVista Software, Inc. 2008.
  10. * Anton Vorontsov <avorontsov@ru.mvista.com>
  11. *
  12. * This program is free software; you can redistribute it and/or modify it
  13. * under the terms of the GNU General Public License as published by the
  14. * Free Software Foundation; either version 2 of the License, or (at your
  15. * option) any later version.
  16. */
  17. #include <linux/kernel.h>
  18. #include <linux/types.h>
  19. #include <linux/delay.h>
  20. #include <linux/slab.h>
  21. #include <linux/list.h>
  22. #include <linux/usb.h>
  23. #include <linux/usb/hcd.h>
  24. #include "fhci.h"
  25. static void init_td(struct td *td)
  26. {
  27. memset(td, 0, sizeof(*td));
  28. INIT_LIST_HEAD(&td->node);
  29. INIT_LIST_HEAD(&td->frame_lh);
  30. }
  31. static void init_ed(struct ed *ed)
  32. {
  33. memset(ed, 0, sizeof(*ed));
  34. INIT_LIST_HEAD(&ed->td_list);
  35. INIT_LIST_HEAD(&ed->node);
  36. }
  37. static struct td *get_empty_td(struct fhci_hcd *fhci)
  38. {
  39. struct td *td;
  40. if (!list_empty(&fhci->empty_tds)) {
  41. td = list_entry(fhci->empty_tds.next, struct td, node);
  42. list_del(fhci->empty_tds.next);
  43. } else {
  44. td = kmalloc(sizeof(*td), GFP_ATOMIC);
  45. if (!td)
  46. fhci_err(fhci, "No memory to allocate to TD\n");
  47. else
  48. init_td(td);
  49. }
  50. return td;
  51. }
  52. void fhci_recycle_empty_td(struct fhci_hcd *fhci, struct td *td)
  53. {
  54. init_td(td);
  55. list_add(&td->node, &fhci->empty_tds);
  56. }
  57. struct ed *fhci_get_empty_ed(struct fhci_hcd *fhci)
  58. {
  59. struct ed *ed;
  60. if (!list_empty(&fhci->empty_eds)) {
  61. ed = list_entry(fhci->empty_eds.next, struct ed, node);
  62. list_del(fhci->empty_eds.next);
  63. } else {
  64. ed = kmalloc(sizeof(*ed), GFP_ATOMIC);
  65. if (!ed)
  66. fhci_err(fhci, "No memory to allocate to ED\n");
  67. else
  68. init_ed(ed);
  69. }
  70. return ed;
  71. }
  72. void fhci_recycle_empty_ed(struct fhci_hcd *fhci, struct ed *ed)
  73. {
  74. init_ed(ed);
  75. list_add(&ed->node, &fhci->empty_eds);
  76. }
  77. struct td *fhci_td_fill(struct fhci_hcd *fhci, struct urb *urb,
  78. struct urb_priv *urb_priv, struct ed *ed, u16 index,
  79. enum fhci_ta_type type, int toggle, u8 *data, u32 len,
  80. u16 interval, u16 start_frame, bool ioc)
  81. {
  82. struct td *td = get_empty_td(fhci);
  83. if (!td)
  84. return NULL;
  85. td->urb = urb;
  86. td->ed = ed;
  87. td->type = type;
  88. td->toggle = toggle;
  89. td->data = data;
  90. td->len = len;
  91. td->iso_index = index;
  92. td->interval = interval;
  93. td->start_frame = start_frame;
  94. td->ioc = ioc;
  95. td->status = USB_TD_OK;
  96. urb_priv->tds[index] = td;
  97. return td;
  98. }