response_manager.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /**********************************************************************
  2. * Author: Cavium, Inc.
  3. *
  4. * Contact: support@cavium.com
  5. * Please include "LiquidIO" in the subject.
  6. *
  7. * Copyright (c) 2003-2016 Cavium, Inc.
  8. *
  9. * This file is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License, Version 2, as
  11. * published by the Free Software Foundation.
  12. *
  13. * This file is distributed in the hope that it will be useful, but
  14. * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
  15. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
  16. * NONINFRINGEMENT. See the GNU General Public License for more
  17. * details.
  18. **********************************************************************/
  19. #include <linux/pci.h>
  20. #include <linux/netdevice.h>
  21. #include "liquidio_common.h"
  22. #include "octeon_droq.h"
  23. #include "octeon_iq.h"
  24. #include "response_manager.h"
  25. #include "octeon_device.h"
  26. #include "octeon_main.h"
  27. static void oct_poll_req_completion(struct work_struct *work);
  28. int octeon_setup_response_list(struct octeon_device *oct)
  29. {
  30. int i, ret = 0;
  31. struct cavium_wq *cwq;
  32. for (i = 0; i < MAX_RESPONSE_LISTS; i++) {
  33. INIT_LIST_HEAD(&oct->response_list[i].head);
  34. spin_lock_init(&oct->response_list[i].lock);
  35. atomic_set(&oct->response_list[i].pending_req_count, 0);
  36. }
  37. spin_lock_init(&oct->cmd_resp_wqlock);
  38. oct->dma_comp_wq.wq = alloc_workqueue("dma-comp", WQ_MEM_RECLAIM, 0);
  39. if (!oct->dma_comp_wq.wq) {
  40. dev_err(&oct->pci_dev->dev, "failed to create wq thread\n");
  41. return -ENOMEM;
  42. }
  43. cwq = &oct->dma_comp_wq;
  44. INIT_DELAYED_WORK(&cwq->wk.work, oct_poll_req_completion);
  45. cwq->wk.ctxptr = oct;
  46. oct->cmd_resp_state = OCT_DRV_ONLINE;
  47. queue_delayed_work(cwq->wq, &cwq->wk.work, msecs_to_jiffies(50));
  48. return ret;
  49. }
  50. void octeon_delete_response_list(struct octeon_device *oct)
  51. {
  52. cancel_delayed_work_sync(&oct->dma_comp_wq.wk.work);
  53. destroy_workqueue(oct->dma_comp_wq.wq);
  54. }
  55. int lio_process_ordered_list(struct octeon_device *octeon_dev,
  56. u32 force_quit)
  57. {
  58. struct octeon_response_list *ordered_sc_list;
  59. struct octeon_soft_command *sc;
  60. int request_complete = 0;
  61. int resp_to_process = MAX_ORD_REQS_TO_PROCESS;
  62. u32 status;
  63. u64 status64;
  64. struct octeon_instr_rdp *rdp;
  65. u64 rptr;
  66. ordered_sc_list = &octeon_dev->response_list[OCTEON_ORDERED_SC_LIST];
  67. do {
  68. spin_lock_bh(&ordered_sc_list->lock);
  69. if (ordered_sc_list->head.next == &ordered_sc_list->head) {
  70. spin_unlock_bh(&ordered_sc_list->lock);
  71. return 1;
  72. }
  73. sc = (struct octeon_soft_command *)ordered_sc_list->
  74. head.next;
  75. if (OCTEON_CN23XX_PF(octeon_dev) ||
  76. OCTEON_CN23XX_VF(octeon_dev)) {
  77. rdp = (struct octeon_instr_rdp *)&sc->cmd.cmd3.rdp;
  78. rptr = sc->cmd.cmd3.rptr;
  79. } else {
  80. rdp = (struct octeon_instr_rdp *)&sc->cmd.cmd2.rdp;
  81. rptr = sc->cmd.cmd2.rptr;
  82. }
  83. status = OCTEON_REQUEST_PENDING;
  84. /* check if octeon has finished DMA'ing a response
  85. * to where rptr is pointing to
  86. */
  87. dma_sync_single_for_cpu(&octeon_dev->pci_dev->dev,
  88. rptr, rdp->rlen,
  89. DMA_FROM_DEVICE);
  90. status64 = *sc->status_word;
  91. if (status64 != COMPLETION_WORD_INIT) {
  92. if ((status64 & 0xff) != 0xff) {
  93. octeon_swap_8B_data(&status64, 1);
  94. if (((status64 & 0xff) != 0xff)) {
  95. status = (u32)(status64 &
  96. 0xffffffffULL);
  97. }
  98. }
  99. } else if (force_quit || (sc->timeout &&
  100. time_after(jiffies, (unsigned long)sc->timeout))) {
  101. status = OCTEON_REQUEST_TIMEOUT;
  102. }
  103. if (status != OCTEON_REQUEST_PENDING) {
  104. /* we have received a response or we have timed out */
  105. /* remove node from linked list */
  106. list_del(&sc->node);
  107. atomic_dec(&octeon_dev->response_list
  108. [OCTEON_ORDERED_SC_LIST].
  109. pending_req_count);
  110. spin_unlock_bh
  111. (&ordered_sc_list->lock);
  112. if (sc->callback)
  113. sc->callback(octeon_dev, status,
  114. sc->callback_arg);
  115. request_complete++;
  116. } else {
  117. /* no response yet */
  118. request_complete = 0;
  119. spin_unlock_bh
  120. (&ordered_sc_list->lock);
  121. }
  122. /* If we hit the Max Ordered requests to process every loop,
  123. * we quit
  124. * and let this function be invoked the next time the poll
  125. * thread runs
  126. * to process the remaining requests. This function can take up
  127. * the entire CPU if there is no upper limit to the requests
  128. * processed.
  129. */
  130. if (request_complete >= resp_to_process)
  131. break;
  132. } while (request_complete);
  133. return 0;
  134. }
  135. static void oct_poll_req_completion(struct work_struct *work)
  136. {
  137. struct cavium_wk *wk = (struct cavium_wk *)work;
  138. struct octeon_device *oct = (struct octeon_device *)wk->ctxptr;
  139. struct cavium_wq *cwq = &oct->dma_comp_wq;
  140. lio_process_ordered_list(oct, 0);
  141. queue_delayed_work(cwq->wq, &cwq->wk.work, msecs_to_jiffies(50));
  142. }