/drivers/scsi/fnic/vnic_wq.h

http://github.com/mirrors/linux · C Header · 183 lines · 131 code · 22 blank · 30 comment · 4 complexity · 0e43fab2c30285b8b4b18f4cc4ddd122 MD5 · raw file

  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_H_
  19. #define _VNIC_WQ_H_
  20. #include <linux/pci.h>
  21. #include "vnic_dev.h"
  22. #include "vnic_cq.h"
  23. /*
  24. * These defines avoid symbol clash between fnic and enic (Cisco 10G Eth
  25. * Driver) when both are built with CONFIG options =y
  26. */
  27. #define vnic_wq_desc_avail fnic_wq_desc_avail
  28. #define vnic_wq_desc_used fnic_wq_desc_used
  29. #define vnic_wq_next_desc fni_cwq_next_desc
  30. #define vnic_wq_post fnic_wq_post
  31. #define vnic_wq_service fnic_wq_service
  32. #define vnic_wq_free fnic_wq_free
  33. #define vnic_wq_alloc fnic_wq_alloc
  34. #define vnic_wq_devcmd2_alloc fnic_wq_devcmd2_alloc
  35. #define vnic_wq_init_start fnic_wq_init_start
  36. #define vnic_wq_init fnic_wq_init
  37. #define vnic_wq_error_status fnic_wq_error_status
  38. #define vnic_wq_enable fnic_wq_enable
  39. #define vnic_wq_disable fnic_wq_disable
  40. #define vnic_wq_clean fnic_wq_clean
  41. /* Work queue control */
  42. struct vnic_wq_ctrl {
  43. u64 ring_base; /* 0x00 */
  44. u32 ring_size; /* 0x08 */
  45. u32 pad0;
  46. u32 posted_index; /* 0x10 */
  47. u32 pad1;
  48. u32 cq_index; /* 0x18 */
  49. u32 pad2;
  50. u32 enable; /* 0x20 */
  51. u32 pad3;
  52. u32 running; /* 0x28 */
  53. u32 pad4;
  54. u32 fetch_index; /* 0x30 */
  55. u32 pad5;
  56. u32 dca_value; /* 0x38 */
  57. u32 pad6;
  58. u32 error_interrupt_enable; /* 0x40 */
  59. u32 pad7;
  60. u32 error_interrupt_offset; /* 0x48 */
  61. u32 pad8;
  62. u32 error_status; /* 0x50 */
  63. u32 pad9;
  64. };
  65. struct vnic_wq_buf {
  66. struct vnic_wq_buf *next;
  67. dma_addr_t dma_addr;
  68. void *os_buf;
  69. unsigned int len;
  70. unsigned int index;
  71. int sop;
  72. void *desc;
  73. };
  74. /* Break the vnic_wq_buf allocations into blocks of 64 entries */
  75. #define VNIC_WQ_BUF_BLK_ENTRIES 64
  76. #define VNIC_WQ_BUF_BLK_SZ \
  77. (VNIC_WQ_BUF_BLK_ENTRIES * sizeof(struct vnic_wq_buf))
  78. #define VNIC_WQ_BUF_BLKS_NEEDED(entries) \
  79. DIV_ROUND_UP(entries, VNIC_WQ_BUF_BLK_ENTRIES)
  80. #define VNIC_WQ_BUF_BLKS_MAX VNIC_WQ_BUF_BLKS_NEEDED(4096)
  81. struct vnic_wq {
  82. unsigned int index;
  83. struct vnic_dev *vdev;
  84. struct vnic_wq_ctrl __iomem *ctrl; /* memory-mapped */
  85. struct vnic_dev_ring ring;
  86. struct vnic_wq_buf *bufs[VNIC_WQ_BUF_BLKS_MAX];
  87. struct vnic_wq_buf *to_use;
  88. struct vnic_wq_buf *to_clean;
  89. unsigned int pkts_outstanding;
  90. };
  91. static inline unsigned int vnic_wq_desc_avail(struct vnic_wq *wq)
  92. {
  93. /* how many does SW own? */
  94. return wq->ring.desc_avail;
  95. }
  96. static inline unsigned int vnic_wq_desc_used(struct vnic_wq *wq)
  97. {
  98. /* how many does HW own? */
  99. return wq->ring.desc_count - wq->ring.desc_avail - 1;
  100. }
  101. static inline void *vnic_wq_next_desc(struct vnic_wq *wq)
  102. {
  103. return wq->to_use->desc;
  104. }
  105. static inline void vnic_wq_post(struct vnic_wq *wq,
  106. void *os_buf, dma_addr_t dma_addr,
  107. unsigned int len, int sop, int eop)
  108. {
  109. struct vnic_wq_buf *buf = wq->to_use;
  110. buf->sop = sop;
  111. buf->os_buf = eop ? os_buf : NULL;
  112. buf->dma_addr = dma_addr;
  113. buf->len = len;
  114. buf = buf->next;
  115. if (eop) {
  116. /* Adding write memory barrier prevents compiler and/or CPU
  117. * reordering, thus avoiding descriptor posting before
  118. * descriptor is initialized. Otherwise, hardware can read
  119. * stale descriptor fields.
  120. */
  121. wmb();
  122. iowrite32(buf->index, &wq->ctrl->posted_index);
  123. }
  124. wq->to_use = buf;
  125. wq->ring.desc_avail--;
  126. }
  127. static inline void vnic_wq_service(struct vnic_wq *wq,
  128. struct cq_desc *cq_desc, u16 completed_index,
  129. void (*buf_service)(struct vnic_wq *wq,
  130. struct cq_desc *cq_desc, struct vnic_wq_buf *buf, void *opaque),
  131. void *opaque)
  132. {
  133. struct vnic_wq_buf *buf;
  134. buf = wq->to_clean;
  135. while (1) {
  136. (*buf_service)(wq, cq_desc, buf, opaque);
  137. wq->ring.desc_avail++;
  138. wq->to_clean = buf->next;
  139. if (buf->index == completed_index)
  140. break;
  141. buf = wq->to_clean;
  142. }
  143. }
  144. void vnic_wq_free(struct vnic_wq *wq);
  145. int vnic_wq_alloc(struct vnic_dev *vdev, struct vnic_wq *wq, unsigned int index,
  146. unsigned int desc_count, unsigned int desc_size);
  147. int vnic_wq_devcmd2_alloc(struct vnic_dev *vdev, struct vnic_wq *wq,
  148. unsigned int desc_count, unsigned int desc_size);
  149. void vnic_wq_init_start(struct vnic_wq *wq, unsigned int cq_index,
  150. unsigned int fetch_index, unsigned int posted_index,
  151. unsigned int error_interrupt_enable,
  152. unsigned int error_interrupt_offset);
  153. void vnic_wq_init(struct vnic_wq *wq, unsigned int cq_index,
  154. unsigned int error_interrupt_enable,
  155. unsigned int error_interrupt_offset);
  156. unsigned int vnic_wq_error_status(struct vnic_wq *wq);
  157. void vnic_wq_enable(struct vnic_wq *wq);
  158. int vnic_wq_disable(struct vnic_wq *wq);
  159. void vnic_wq_clean(struct vnic_wq *wq,
  160. void (*buf_clean)(struct vnic_wq *wq, struct vnic_wq_buf *buf));
  161. #endif /* _VNIC_WQ_H_ */