fhci-mem.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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/list.h>
  21. #include <linux/usb.h>
  22. #include "../core/hcd.h"
  23. #include "fhci.h"
  24. static void init_td(struct td *td)
  25. {
  26. memset(td, 0, sizeof(*td));
  27. INIT_LIST_HEAD(&td->node);
  28. INIT_LIST_HEAD(&td->frame_lh);
  29. }
  30. static void init_ed(struct ed *ed)
  31. {
  32. memset(ed, 0, sizeof(*ed));
  33. INIT_LIST_HEAD(&ed->td_list);
  34. INIT_LIST_HEAD(&ed->node);
  35. }
  36. static struct td *get_empty_td(struct fhci_hcd *fhci)
  37. {
  38. struct td *td;
  39. if (!list_empty(&fhci->empty_tds)) {
  40. td = list_entry(fhci->empty_tds.next, struct td, node);
  41. list_del(fhci->empty_tds.next);
  42. } else {
  43. td = kmalloc(sizeof(*td), GFP_ATOMIC);
  44. if (!td)
  45. fhci_err(fhci, "No memory to allocate to TD\n");
  46. else
  47. init_td(td);
  48. }
  49. return td;
  50. }
  51. void fhci_recycle_empty_td(struct fhci_hcd *fhci, struct td *td)
  52. {
  53. init_td(td);
  54. list_add(&td->node, &fhci->empty_tds);
  55. }
  56. struct ed *fhci_get_empty_ed(struct fhci_hcd *fhci)
  57. {
  58. struct ed *ed;
  59. if (!list_empty(&fhci->empty_eds)) {
  60. ed = list_entry(fhci->empty_eds.next, struct ed, node);
  61. list_del(fhci->empty_eds.next);
  62. } else {
  63. ed = kmalloc(sizeof(*ed), GFP_ATOMIC);
  64. if (!ed)
  65. fhci_err(fhci, "No memory to allocate to ED\n");
  66. else
  67. init_ed(ed);
  68. }
  69. return ed;
  70. }
  71. void fhci_recycle_empty_ed(struct fhci_hcd *fhci, struct ed *ed)
  72. {
  73. init_ed(ed);
  74. list_add(&ed->node, &fhci->empty_eds);
  75. }
  76. struct td *fhci_td_fill(struct fhci_hcd *fhci, struct urb *urb,
  77. struct urb_priv *urb_priv, struct ed *ed, u16 index,
  78. enum fhci_ta_type type, int toggle, u8 *data, u32 len,
  79. u16 interval, u16 start_frame, bool ioc)
  80. {
  81. struct td *td = get_empty_td(fhci);
  82. if (!td)
  83. return NULL;
  84. td->urb = urb;
  85. td->ed = ed;
  86. td->type = type;
  87. td->toggle = toggle;
  88. td->data = data;
  89. td->len = len;
  90. td->iso_index = index;
  91. td->interval = interval;
  92. td->start_frame = start_frame;
  93. td->ioc = ioc;
  94. td->status = USB_TD_OK;
  95. urb_priv->tds[index] = td;
  96. return td;
  97. }