vnic_intr.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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_INTR_H_
  18. #define _VNIC_INTR_H_
  19. #include <linux/pci.h>
  20. #include "vnic_dev.h"
  21. #define VNIC_INTR_TIMER_MAX 0xffff
  22. #define VNIC_INTR_TIMER_TYPE_ABS 0
  23. #define VNIC_INTR_TIMER_TYPE_QUIET 1
  24. /* Interrupt control */
  25. struct vnic_intr_ctrl {
  26. u32 coalescing_timer; /* 0x00 */
  27. u32 pad0;
  28. u32 coalescing_value; /* 0x08 */
  29. u32 pad1;
  30. u32 coalescing_type; /* 0x10 */
  31. u32 pad2;
  32. u32 mask_on_assertion; /* 0x18 */
  33. u32 pad3;
  34. u32 mask; /* 0x20 */
  35. u32 pad4;
  36. u32 int_credits; /* 0x28 */
  37. u32 pad5;
  38. u32 int_credit_return; /* 0x30 */
  39. u32 pad6;
  40. };
  41. struct vnic_intr {
  42. unsigned int index;
  43. struct vnic_dev *vdev;
  44. struct vnic_intr_ctrl __iomem *ctrl; /* memory-mapped */
  45. };
  46. static inline void
  47. svnic_intr_unmask(struct vnic_intr *intr)
  48. {
  49. iowrite32(0, &intr->ctrl->mask);
  50. }
  51. static inline void
  52. svnic_intr_mask(struct vnic_intr *intr)
  53. {
  54. iowrite32(1, &intr->ctrl->mask);
  55. }
  56. static inline void
  57. svnic_intr_return_credits(struct vnic_intr *intr,
  58. unsigned int credits,
  59. int unmask,
  60. int reset_timer)
  61. {
  62. #define VNIC_INTR_UNMASK_SHIFT 16
  63. #define VNIC_INTR_RESET_TIMER_SHIFT 17
  64. u32 int_credit_return = (credits & 0xffff) |
  65. (unmask ? (1 << VNIC_INTR_UNMASK_SHIFT) : 0) |
  66. (reset_timer ? (1 << VNIC_INTR_RESET_TIMER_SHIFT) : 0);
  67. iowrite32(int_credit_return, &intr->ctrl->int_credit_return);
  68. }
  69. static inline unsigned int
  70. svnic_intr_credits(struct vnic_intr *intr)
  71. {
  72. return ioread32(&intr->ctrl->int_credits);
  73. }
  74. static inline void
  75. svnic_intr_return_all_credits(struct vnic_intr *intr)
  76. {
  77. unsigned int credits = svnic_intr_credits(intr);
  78. int unmask = 1;
  79. int reset_timer = 1;
  80. svnic_intr_return_credits(intr, credits, unmask, reset_timer);
  81. }
  82. void svnic_intr_free(struct vnic_intr *);
  83. int svnic_intr_alloc(struct vnic_dev *, struct vnic_intr *, unsigned int);
  84. void svnic_intr_init(struct vnic_intr *intr,
  85. unsigned int coalescing_timer,
  86. unsigned int coalescing_type,
  87. unsigned int mask_on_assertion);
  88. void svnic_intr_clean(struct vnic_intr *);
  89. #endif /* _VNIC_INTR_H_ */