vnic_intr.h 2.4 KB

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