vnic_wq.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. * Copyright 2008-2010 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. */
  19. #ifndef _VNIC_WQ_H_
  20. #define _VNIC_WQ_H_
  21. #include <linux/pci.h>
  22. #include "vnic_dev.h"
  23. #include "vnic_cq.h"
  24. /* Work queue control */
  25. struct vnic_wq_ctrl {
  26. u64 ring_base; /* 0x00 */
  27. u32 ring_size; /* 0x08 */
  28. u32 pad0;
  29. u32 posted_index; /* 0x10 */
  30. u32 pad1;
  31. u32 cq_index; /* 0x18 */
  32. u32 pad2;
  33. u32 enable; /* 0x20 */
  34. u32 pad3;
  35. u32 running; /* 0x28 */
  36. u32 pad4;
  37. u32 fetch_index; /* 0x30 */
  38. u32 pad5;
  39. u32 dca_value; /* 0x38 */
  40. u32 pad6;
  41. u32 error_interrupt_enable; /* 0x40 */
  42. u32 pad7;
  43. u32 error_interrupt_offset; /* 0x48 */
  44. u32 pad8;
  45. u32 error_status; /* 0x50 */
  46. u32 pad9;
  47. };
  48. struct vnic_wq_buf {
  49. struct vnic_wq_buf *next;
  50. dma_addr_t dma_addr;
  51. void *os_buf;
  52. unsigned int len;
  53. unsigned int index;
  54. int sop;
  55. void *desc;
  56. uint64_t wr_id; /* Cookie */
  57. uint8_t cq_entry; /* Gets completion event from hw */
  58. uint8_t desc_skip_cnt; /* Num descs to occupy */
  59. uint8_t compressed_send; /* Both hdr and payload in one desc */
  60. struct vnic_wq_buf *prev;
  61. };
  62. /* Break the vnic_wq_buf allocations into blocks of 32/64 entries */
  63. #define VNIC_WQ_BUF_MIN_BLK_ENTRIES 32
  64. #define VNIC_WQ_BUF_DFLT_BLK_ENTRIES 64
  65. #define VNIC_WQ_BUF_BLK_ENTRIES(entries) \
  66. ((unsigned int)((entries < VNIC_WQ_BUF_DFLT_BLK_ENTRIES) ? \
  67. VNIC_WQ_BUF_MIN_BLK_ENTRIES : VNIC_WQ_BUF_DFLT_BLK_ENTRIES))
  68. #define VNIC_WQ_BUF_BLK_SZ(entries) \
  69. (VNIC_WQ_BUF_BLK_ENTRIES(entries) * sizeof(struct vnic_wq_buf))
  70. #define VNIC_WQ_BUF_BLKS_NEEDED(entries) \
  71. DIV_ROUND_UP(entries, VNIC_WQ_BUF_BLK_ENTRIES(entries))
  72. #define VNIC_WQ_BUF_BLKS_MAX VNIC_WQ_BUF_BLKS_NEEDED(4096)
  73. struct vnic_wq {
  74. unsigned int index;
  75. struct vnic_dev *vdev;
  76. struct vnic_wq_ctrl __iomem *ctrl; /* memory-mapped */
  77. struct vnic_dev_ring ring;
  78. struct vnic_wq_buf *bufs[VNIC_WQ_BUF_BLKS_MAX];
  79. struct vnic_wq_buf *to_use;
  80. struct vnic_wq_buf *to_clean;
  81. unsigned int pkts_outstanding;
  82. };
  83. struct devcmd2_controller {
  84. struct vnic_wq_ctrl __iomem *wq_ctrl;
  85. struct vnic_devcmd2 *cmd_ring;
  86. struct devcmd2_result *result;
  87. u16 next_result;
  88. u16 result_size;
  89. int color;
  90. struct vnic_dev_ring results_ring;
  91. struct vnic_wq wq;
  92. u32 posted;
  93. };
  94. static inline unsigned int vnic_wq_desc_avail(struct vnic_wq *wq)
  95. {
  96. /* how many does SW own? */
  97. return wq->ring.desc_avail;
  98. }
  99. static inline unsigned int vnic_wq_desc_used(struct vnic_wq *wq)
  100. {
  101. /* how many does HW own? */
  102. return wq->ring.desc_count - wq->ring.desc_avail - 1;
  103. }
  104. static inline void *vnic_wq_next_desc(struct vnic_wq *wq)
  105. {
  106. return wq->to_use->desc;
  107. }
  108. static inline void vnic_wq_doorbell(struct vnic_wq *wq)
  109. {
  110. /* Adding write memory barrier prevents compiler and/or CPU
  111. * reordering, thus avoiding descriptor posting before
  112. * descriptor is initialized. Otherwise, hardware can read
  113. * stale descriptor fields.
  114. */
  115. wmb();
  116. iowrite32(wq->to_use->index, &wq->ctrl->posted_index);
  117. }
  118. static inline void vnic_wq_post(struct vnic_wq *wq,
  119. void *os_buf, dma_addr_t dma_addr,
  120. unsigned int len, int sop, int eop,
  121. uint8_t desc_skip_cnt, uint8_t cq_entry,
  122. uint8_t compressed_send, uint64_t wrid)
  123. {
  124. struct vnic_wq_buf *buf = wq->to_use;
  125. buf->sop = sop;
  126. buf->cq_entry = cq_entry;
  127. buf->compressed_send = compressed_send;
  128. buf->desc_skip_cnt = desc_skip_cnt;
  129. buf->os_buf = eop ? os_buf : NULL;
  130. buf->dma_addr = dma_addr;
  131. buf->len = len;
  132. buf->wr_id = wrid;
  133. buf = buf->next;
  134. wq->to_use = buf;
  135. wq->ring.desc_avail -= desc_skip_cnt;
  136. }
  137. static inline void vnic_wq_service(struct vnic_wq *wq,
  138. struct cq_desc *cq_desc, u16 completed_index,
  139. void (*buf_service)(struct vnic_wq *wq,
  140. struct cq_desc *cq_desc, struct vnic_wq_buf *buf, void *opaque),
  141. void *opaque)
  142. {
  143. struct vnic_wq_buf *buf;
  144. buf = wq->to_clean;
  145. while (1) {
  146. (*buf_service)(wq, cq_desc, buf, opaque);
  147. wq->ring.desc_avail++;
  148. wq->to_clean = buf->next;
  149. if (buf->index == completed_index)
  150. break;
  151. buf = wq->to_clean;
  152. }
  153. }
  154. void vnic_wq_free(struct vnic_wq *wq);
  155. int vnic_wq_alloc(struct vnic_dev *vdev, struct vnic_wq *wq, unsigned int index,
  156. unsigned int desc_count, unsigned int desc_size);
  157. void vnic_wq_init(struct vnic_wq *wq, unsigned int cq_index,
  158. unsigned int error_interrupt_enable,
  159. unsigned int error_interrupt_offset);
  160. unsigned int vnic_wq_error_status(struct vnic_wq *wq);
  161. void vnic_wq_enable(struct vnic_wq *wq);
  162. int vnic_wq_disable(struct vnic_wq *wq);
  163. void vnic_wq_clean(struct vnic_wq *wq,
  164. void (*buf_clean)(struct vnic_wq *wq, struct vnic_wq_buf *buf));
  165. int enic_wq_devcmd2_alloc(struct vnic_dev *vdev, struct vnic_wq *wq,
  166. unsigned int desc_count, unsigned int desc_size);
  167. void enic_wq_init_start(struct vnic_wq *wq, unsigned int cq_index,
  168. unsigned int fetch_index, unsigned int posted_index,
  169. unsigned int error_interrupt_enable,
  170. unsigned int error_interrupt_offset);
  171. #endif /* _VNIC_WQ_H_ */