vnic_wq_copy.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Copyright 2008 Cisco Systems, Inc. All rights reserved.
  3. * Copyright 2007 Nuova Systems, Inc. All rights reserved.
  4. *
  5. * This program is free software; you may redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; version 2 of the License.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  10. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  11. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  12. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  13. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  14. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  15. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  16. * SOFTWARE.
  17. */
  18. #ifndef _VNIC_WQ_COPY_H_
  19. #define _VNIC_WQ_COPY_H_
  20. #include <linux/pci.h>
  21. #include "vnic_wq.h"
  22. #include "fcpio.h"
  23. #define VNIC_WQ_COPY_MAX 1
  24. struct vnic_wq_copy {
  25. unsigned int index;
  26. struct vnic_dev *vdev;
  27. struct vnic_wq_ctrl __iomem *ctrl; /* memory-mapped */
  28. struct vnic_dev_ring ring;
  29. unsigned to_use_index;
  30. unsigned to_clean_index;
  31. };
  32. static inline unsigned int vnic_wq_copy_desc_avail(struct vnic_wq_copy *wq)
  33. {
  34. return wq->ring.desc_avail;
  35. }
  36. static inline unsigned int vnic_wq_copy_desc_in_use(struct vnic_wq_copy *wq)
  37. {
  38. return wq->ring.desc_count - 1 - wq->ring.desc_avail;
  39. }
  40. static inline void *vnic_wq_copy_next_desc(struct vnic_wq_copy *wq)
  41. {
  42. struct fcpio_host_req *desc = wq->ring.descs;
  43. return &desc[wq->to_use_index];
  44. }
  45. static inline void vnic_wq_copy_post(struct vnic_wq_copy *wq)
  46. {
  47. ((wq->to_use_index + 1) == wq->ring.desc_count) ?
  48. (wq->to_use_index = 0) : (wq->to_use_index++);
  49. wq->ring.desc_avail--;
  50. /* Adding write memory barrier prevents compiler and/or CPU
  51. * reordering, thus avoiding descriptor posting before
  52. * descriptor is initialized. Otherwise, hardware can read
  53. * stale descriptor fields.
  54. */
  55. wmb();
  56. iowrite32(wq->to_use_index, &wq->ctrl->posted_index);
  57. }
  58. static inline void vnic_wq_copy_desc_process(struct vnic_wq_copy *wq, u16 index)
  59. {
  60. unsigned int cnt;
  61. if (wq->to_clean_index <= index)
  62. cnt = (index - wq->to_clean_index) + 1;
  63. else
  64. cnt = wq->ring.desc_count - wq->to_clean_index + index + 1;
  65. wq->to_clean_index = ((index + 1) % wq->ring.desc_count);
  66. wq->ring.desc_avail += cnt;
  67. }
  68. static inline void vnic_wq_copy_service(struct vnic_wq_copy *wq,
  69. u16 completed_index,
  70. void (*q_service)(struct vnic_wq_copy *wq,
  71. struct fcpio_host_req *wq_desc))
  72. {
  73. struct fcpio_host_req *wq_desc = wq->ring.descs;
  74. unsigned int curr_index;
  75. while (1) {
  76. if (q_service)
  77. (*q_service)(wq, &wq_desc[wq->to_clean_index]);
  78. wq->ring.desc_avail++;
  79. curr_index = wq->to_clean_index;
  80. /* increment the to-clean index so that we start
  81. * with an unprocessed index next time we enter the loop
  82. */
  83. ((wq->to_clean_index + 1) == wq->ring.desc_count) ?
  84. (wq->to_clean_index = 0) : (wq->to_clean_index++);
  85. if (curr_index == completed_index)
  86. break;
  87. /* we have cleaned all the entries */
  88. if ((completed_index == (u16)-1) &&
  89. (wq->to_clean_index == wq->to_use_index))
  90. break;
  91. }
  92. }
  93. void vnic_wq_copy_enable(struct vnic_wq_copy *wq);
  94. int vnic_wq_copy_disable(struct vnic_wq_copy *wq);
  95. void vnic_wq_copy_free(struct vnic_wq_copy *wq);
  96. int vnic_wq_copy_alloc(struct vnic_dev *vdev, struct vnic_wq_copy *wq,
  97. unsigned int index, unsigned int desc_count, unsigned int desc_size);
  98. void vnic_wq_copy_init(struct vnic_wq_copy *wq, unsigned int cq_index,
  99. unsigned int error_interrupt_enable,
  100. unsigned int error_interrupt_offset);
  101. void vnic_wq_copy_clean(struct vnic_wq_copy *wq,
  102. void (*q_clean)(struct vnic_wq_copy *wq,
  103. struct fcpio_host_req *wq_desc));
  104. #endif /* _VNIC_WQ_COPY_H_ */