sdio-tx.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. * Intel Wireless WiMAX Connection 2400m
  3. * SDIO TX transaction backends
  4. *
  5. *
  6. * Copyright (C) 2007-2008 Intel Corporation. All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * * Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * * Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in
  16. * the documentation and/or other materials provided with the
  17. * distribution.
  18. * * Neither the name of Intel Corporation nor the names of its
  19. * contributors may be used to endorse or promote products derived
  20. * from this software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  25. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  26. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  27. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  28. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  29. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  30. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  32. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. *
  35. * Intel Corporation <linux-wimax@intel.com>
  36. * Dirk Brandewie <dirk.j.brandewie@intel.com>
  37. * - Initial implementation
  38. *
  39. *
  40. * Takes the TX messages in the i2400m's driver TX FIFO and sends them
  41. * to the device until there are no more.
  42. *
  43. * If we fail sending the message, we just drop it. There isn't much
  44. * we can do at this point. Most of the traffic is network, which has
  45. * recovery methods for dropped packets.
  46. *
  47. * The SDIO functions are not atomic, so we can't run from the context
  48. * where i2400m->bus_tx_kick() [i2400ms_bus_tx_kick()] is being called
  49. * (some times atomic). Thus, the actual TX work is deferred to a
  50. * workqueue.
  51. *
  52. * ROADMAP
  53. *
  54. * i2400ms_bus_tx_kick()
  55. * i2400ms_tx_submit() [through workqueue]
  56. *
  57. * i2400m_tx_setup()
  58. *
  59. * i2400m_tx_release()
  60. */
  61. #include <linux/mmc/sdio_func.h>
  62. #include "i2400m-sdio.h"
  63. #define D_SUBMODULE tx
  64. #include "sdio-debug-levels.h"
  65. /*
  66. * Pull TX transations from the TX FIFO and send them to the device
  67. * until there are no more.
  68. */
  69. static
  70. void i2400ms_tx_submit(struct work_struct *ws)
  71. {
  72. int result;
  73. struct i2400ms *i2400ms = container_of(ws, struct i2400ms, tx_worker);
  74. struct i2400m *i2400m = &i2400ms->i2400m;
  75. struct sdio_func *func = i2400ms->func;
  76. struct device *dev = &func->dev;
  77. struct i2400m_msg_hdr *tx_msg;
  78. size_t tx_msg_size;
  79. d_fnstart(4, dev, "(i2400ms %p, i2400m %p)\n", i2400ms, i2400ms);
  80. while (NULL != (tx_msg = i2400m_tx_msg_get(i2400m, &tx_msg_size))) {
  81. d_printf(2, dev, "TX: submitting %zu bytes\n", tx_msg_size);
  82. d_dump(5, dev, tx_msg, tx_msg_size);
  83. sdio_claim_host(func);
  84. result = sdio_memcpy_toio(func, 0, tx_msg, tx_msg_size);
  85. sdio_release_host(func);
  86. i2400m_tx_msg_sent(i2400m);
  87. if (result < 0) {
  88. dev_err(dev, "TX: cannot submit TX; tx_msg @%zu %zu B:"
  89. " %d\n", (void *) tx_msg - i2400m->tx_buf,
  90. tx_msg_size, result);
  91. }
  92. if (result == -ETIMEDOUT) {
  93. i2400m_error_recovery(i2400m);
  94. break;
  95. }
  96. d_printf(2, dev, "TX: %zub submitted\n", tx_msg_size);
  97. }
  98. d_fnend(4, dev, "(i2400ms %p) = void\n", i2400ms);
  99. }
  100. /*
  101. * The generic driver notifies us that there is data ready for TX
  102. *
  103. * Schedule a run of i2400ms_tx_submit() to handle it.
  104. */
  105. void i2400ms_bus_tx_kick(struct i2400m *i2400m)
  106. {
  107. struct i2400ms *i2400ms = container_of(i2400m, struct i2400ms, i2400m);
  108. struct device *dev = &i2400ms->func->dev;
  109. unsigned long flags;
  110. d_fnstart(3, dev, "(i2400m %p) = void\n", i2400m);
  111. /* schedule tx work, this is because tx may block, therefore
  112. * it has to run in a thread context.
  113. */
  114. spin_lock_irqsave(&i2400m->tx_lock, flags);
  115. if (i2400ms->tx_workqueue != NULL)
  116. queue_work(i2400ms->tx_workqueue, &i2400ms->tx_worker);
  117. spin_unlock_irqrestore(&i2400m->tx_lock, flags);
  118. d_fnend(3, dev, "(i2400m %p) = void\n", i2400m);
  119. }
  120. int i2400ms_tx_setup(struct i2400ms *i2400ms)
  121. {
  122. int result;
  123. struct device *dev = &i2400ms->func->dev;
  124. struct i2400m *i2400m = &i2400ms->i2400m;
  125. struct workqueue_struct *tx_workqueue;
  126. unsigned long flags;
  127. d_fnstart(5, dev, "(i2400ms %p)\n", i2400ms);
  128. INIT_WORK(&i2400ms->tx_worker, i2400ms_tx_submit);
  129. snprintf(i2400ms->tx_wq_name, sizeof(i2400ms->tx_wq_name),
  130. "%s-tx", i2400m->wimax_dev.name);
  131. tx_workqueue =
  132. create_singlethread_workqueue(i2400ms->tx_wq_name);
  133. if (tx_workqueue == NULL) {
  134. dev_err(dev, "TX: failed to create workqueue\n");
  135. result = -ENOMEM;
  136. } else
  137. result = 0;
  138. spin_lock_irqsave(&i2400m->tx_lock, flags);
  139. i2400ms->tx_workqueue = tx_workqueue;
  140. spin_unlock_irqrestore(&i2400m->tx_lock, flags);
  141. d_fnend(5, dev, "(i2400ms %p) = %d\n", i2400ms, result);
  142. return result;
  143. }
  144. void i2400ms_tx_release(struct i2400ms *i2400ms)
  145. {
  146. struct i2400m *i2400m = &i2400ms->i2400m;
  147. struct workqueue_struct *tx_workqueue;
  148. unsigned long flags;
  149. tx_workqueue = i2400ms->tx_workqueue;
  150. spin_lock_irqsave(&i2400m->tx_lock, flags);
  151. i2400ms->tx_workqueue = NULL;
  152. spin_unlock_irqrestore(&i2400m->tx_lock, flags);
  153. if (tx_workqueue)
  154. destroy_workqueue(tx_workqueue);
  155. }