vnic_cq.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright 2014 Cisco Systems, Inc. All rights reserved.
  3. *
  4. * This program is free software; you may redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; version 2 of the License.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  9. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  10. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  11. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  12. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  13. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  14. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  15. * SOFTWARE.
  16. */
  17. #ifndef _VNIC_CQ_H_
  18. #define _VNIC_CQ_H_
  19. #include "cq_desc.h"
  20. #include "vnic_dev.h"
  21. /* Completion queue control */
  22. struct vnic_cq_ctrl {
  23. u64 ring_base; /* 0x00 */
  24. u32 ring_size; /* 0x08 */
  25. u32 pad0;
  26. u32 flow_control_enable; /* 0x10 */
  27. u32 pad1;
  28. u32 color_enable; /* 0x18 */
  29. u32 pad2;
  30. u32 cq_head; /* 0x20 */
  31. u32 pad3;
  32. u32 cq_tail; /* 0x28 */
  33. u32 pad4;
  34. u32 cq_tail_color; /* 0x30 */
  35. u32 pad5;
  36. u32 interrupt_enable; /* 0x38 */
  37. u32 pad6;
  38. u32 cq_entry_enable; /* 0x40 */
  39. u32 pad7;
  40. u32 cq_message_enable; /* 0x48 */
  41. u32 pad8;
  42. u32 interrupt_offset; /* 0x50 */
  43. u32 pad9;
  44. u64 cq_message_addr; /* 0x58 */
  45. u32 pad10;
  46. };
  47. struct vnic_cq {
  48. unsigned int index;
  49. struct vnic_dev *vdev;
  50. struct vnic_cq_ctrl __iomem *ctrl; /* memory-mapped */
  51. struct vnic_dev_ring ring;
  52. unsigned int to_clean;
  53. unsigned int last_color;
  54. };
  55. static inline unsigned int svnic_cq_service(struct vnic_cq *cq,
  56. unsigned int work_to_do,
  57. int (*q_service)(struct vnic_dev *vdev, struct cq_desc *cq_desc,
  58. u8 type, u16 q_number, u16 completed_index, void *opaque),
  59. void *opaque)
  60. {
  61. struct cq_desc *cq_desc;
  62. unsigned int work_done = 0;
  63. u16 q_number, completed_index;
  64. u8 type, color;
  65. cq_desc = (struct cq_desc *)((u8 *)cq->ring.descs +
  66. cq->ring.desc_size * cq->to_clean);
  67. cq_desc_dec(cq_desc, &type, &color,
  68. &q_number, &completed_index);
  69. while (color != cq->last_color) {
  70. if ((*q_service)(cq->vdev, cq_desc, type,
  71. q_number, completed_index, opaque))
  72. break;
  73. cq->to_clean++;
  74. if (cq->to_clean == cq->ring.desc_count) {
  75. cq->to_clean = 0;
  76. cq->last_color = cq->last_color ? 0 : 1;
  77. }
  78. cq_desc = (struct cq_desc *)((u8 *)cq->ring.descs +
  79. cq->ring.desc_size * cq->to_clean);
  80. cq_desc_dec(cq_desc, &type, &color,
  81. &q_number, &completed_index);
  82. work_done++;
  83. if (work_done >= work_to_do)
  84. break;
  85. }
  86. return work_done;
  87. }
  88. void svnic_cq_free(struct vnic_cq *cq);
  89. int svnic_cq_alloc(struct vnic_dev *vdev, struct vnic_cq *cq,
  90. unsigned int index, unsigned int desc_count, unsigned int desc_size);
  91. void svnic_cq_init(struct vnic_cq *cq, unsigned int flow_control_enable,
  92. unsigned int color_enable, unsigned int cq_head, unsigned int cq_tail,
  93. unsigned int cq_tail_color, unsigned int interrupt_enable,
  94. unsigned int cq_entry_enable, unsigned int message_enable,
  95. unsigned int interrupt_offset, u64 message_addr);
  96. void svnic_cq_clean(struct vnic_cq *cq);
  97. #endif /* _VNIC_CQ_H_ */