vnic_intr.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /* Copyright 2014 Cisco Systems, Inc. All rights reserved. */
  3. #ifndef _VNIC_INTR_H_
  4. #define _VNIC_INTR_H_
  5. #include <linux/pci.h>
  6. #include "vnic_dev.h"
  7. #define VNIC_INTR_TIMER_MAX 0xffff
  8. #define VNIC_INTR_TIMER_TYPE_ABS 0
  9. #define VNIC_INTR_TIMER_TYPE_QUIET 1
  10. /* Interrupt control */
  11. struct vnic_intr_ctrl {
  12. u32 coalescing_timer; /* 0x00 */
  13. u32 pad0;
  14. u32 coalescing_value; /* 0x08 */
  15. u32 pad1;
  16. u32 coalescing_type; /* 0x10 */
  17. u32 pad2;
  18. u32 mask_on_assertion; /* 0x18 */
  19. u32 pad3;
  20. u32 mask; /* 0x20 */
  21. u32 pad4;
  22. u32 int_credits; /* 0x28 */
  23. u32 pad5;
  24. u32 int_credit_return; /* 0x30 */
  25. u32 pad6;
  26. };
  27. struct vnic_intr {
  28. unsigned int index;
  29. struct vnic_dev *vdev;
  30. struct vnic_intr_ctrl __iomem *ctrl; /* memory-mapped */
  31. };
  32. static inline void
  33. svnic_intr_unmask(struct vnic_intr *intr)
  34. {
  35. iowrite32(0, &intr->ctrl->mask);
  36. }
  37. static inline void
  38. svnic_intr_mask(struct vnic_intr *intr)
  39. {
  40. iowrite32(1, &intr->ctrl->mask);
  41. }
  42. static inline void
  43. svnic_intr_return_credits(struct vnic_intr *intr,
  44. unsigned int credits,
  45. int unmask,
  46. int reset_timer)
  47. {
  48. #define VNIC_INTR_UNMASK_SHIFT 16
  49. #define VNIC_INTR_RESET_TIMER_SHIFT 17
  50. u32 int_credit_return = (credits & 0xffff) |
  51. (unmask ? (1 << VNIC_INTR_UNMASK_SHIFT) : 0) |
  52. (reset_timer ? (1 << VNIC_INTR_RESET_TIMER_SHIFT) : 0);
  53. iowrite32(int_credit_return, &intr->ctrl->int_credit_return);
  54. }
  55. static inline unsigned int
  56. svnic_intr_credits(struct vnic_intr *intr)
  57. {
  58. return ioread32(&intr->ctrl->int_credits);
  59. }
  60. static inline void
  61. svnic_intr_return_all_credits(struct vnic_intr *intr)
  62. {
  63. unsigned int credits = svnic_intr_credits(intr);
  64. int unmask = 1;
  65. int reset_timer = 1;
  66. svnic_intr_return_credits(intr, credits, unmask, reset_timer);
  67. }
  68. void svnic_intr_free(struct vnic_intr *);
  69. int svnic_intr_alloc(struct vnic_dev *, struct vnic_intr *, unsigned int);
  70. void svnic_intr_init(struct vnic_intr *intr,
  71. unsigned int coalescing_timer,
  72. unsigned int coalescing_type,
  73. unsigned int mask_on_assertion);
  74. void svnic_intr_clean(struct vnic_intr *);
  75. #endif /* _VNIC_INTR_H_ */