vnic_wq.h 4.5 KB

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