fgmac_intr.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * Copyright : (C) 2022 Phytium Information Technology, Inc.
  3. * All Rights Reserved.
  4. *
  5. * This program is OPEN SOURCE software: you can redistribute it and/or modify it
  6. * under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
  7. * either version 1.0 of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
  10. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. * See the Phytium Public License for more details.
  12. *
  13. *
  14. * FilePath: fgmac_intr.c
  15. * Date: 2022-04-06 14:46:52
  16. * LastEditTime: 2022-04-06 14:46:58
  17. * Description:  This file is for
  18. *
  19. * Modify History:
  20. * Ver   Who        Date         Changes
  21. * ----- ------     --------    --------------------------------------
  22. */
  23. /***************************** Include Files *********************************/
  24. #include "fgmac.h"
  25. #include "fgmac_hw.h"
  26. /************************** Constant Definitions *****************************/
  27. /**************************** Type Definitions *******************************/
  28. /***************** Macros (Inline Functions) Definitions *********************/
  29. #define FGMAC_CALL_EVT_HANDLER(instance_p, evt) \
  30. {\
  31. if (NULL != (instance_p)->evt_handler[(evt)]) \
  32. { \
  33. (instance_p)->evt_handler[evt]((void *)(instance_p)); \
  34. }\
  35. }
  36. /************************** Variable Definitions *****************************/
  37. /************************** Function Prototypes ******************************/
  38. /**
  39. * @name: FGmacInterruptHandler
  40. * @msg: FGMAC中断处理函数
  41. * @return {*}
  42. * @param {s32} vector, 中断向量号,此处没有用到
  43. {void} *param, 中断输入参数,此处传入的是FGMAC的驱动控制数据
  44. * @note 此函数运行在中断上下文
  45. */
  46. void FGmacInterruptHandler(s32 vector, void *param)
  47. {
  48. FASSERT(param);
  49. FGmac *instance_p = (FGmac *)param;
  50. uintptr base_addr = instance_p->config.base_addr;
  51. u32 status = 0;
  52. /* dma interrupt */
  53. status = FGMAC_READ_REG32(base_addr, FGMAC_DMA_STATUS_OFFSET);
  54. if (FGMAC_DMA_STATUS_GLI & status)
  55. {
  56. FGMAC_CALL_EVT_HANDLER(instance_p, FGMAC_PHY_STATUS_EVT);
  57. }
  58. if (FGMAC_DMA_STATUS_RI & status)
  59. {
  60. FGMAC_CALL_EVT_HANDLER(instance_p, FGMAC_RX_COMPLETE_EVT);
  61. FGMAC_SET_REG32(base_addr, FGMAC_DMA_STATUS_OFFSET, FGMAC_DMA_STATUS_RI); /* write to clear */
  62. }
  63. if (FGMAC_DMA_STATUS_TI & status)
  64. {
  65. FGMAC_CALL_EVT_HANDLER(instance_p, FGMAC_TX_COMPLETE_EVT);
  66. FGMAC_SET_REG32(base_addr, FGMAC_DMA_STATUS_OFFSET, FGMAC_DMA_STATUS_TI); /* write to clear */
  67. }
  68. if (FGMAC_DMA_STATUS_AIS & status)
  69. {
  70. FGMAC_CALL_EVT_HANDLER(instance_p, FGMAC_DMA_ERR_EVT);
  71. FGMAC_SET_REG32(base_addr, FGMAC_DMA_STATUS_OFFSET, FGMAC_DMA_STATUS_CLR_ABLE);
  72. }
  73. FGMAC_WRITE_REG32(base_addr, FGMAC_DMA_STATUS_OFFSET, status); /* write to clear */
  74. /* RGMII/SGMII Interrupt */
  75. status = FGMAC_READ_REG32(base_addr, FGMAC_INTR_STATUS_OFFSET);
  76. if (status & FGMAC_ISR_STATUS_RSIS)
  77. {
  78. /* status changed, read SGMII register to clear */
  79. FGMAC_READ_REG32(base_addr, FGMAC_MAC_PHY_STATUS);
  80. }
  81. return;
  82. }
  83. /**
  84. * @name: FGmacRegisterEvtHandler
  85. * @msg: 注册FGMAC中断事件响应函数
  86. * @return {*}
  87. * @param {FGmac} *instance_p 驱动控制数据
  88. * @param {u32} evt 中断事件类型
  89. * @param {FGmacEvtHandler} handler 中断事件响应函数
  90. * @note 注册的函数handler会在中断上下文执行
  91. */
  92. void FGmacRegisterEvtHandler(FGmac *instance_p, u32 evt, FGmacEvtHandler handler)
  93. {
  94. FASSERT((NULL != instance_p) && (FGMAC_INTR_EVT_NUM > evt));
  95. instance_p->evt_handler[evt] = handler;
  96. }
  97. /**
  98. * @name: FGmacSetInterruptMask
  99. * @msg: 屏蔽FGMAC中断
  100. * @return {*}
  101. * @param {FGmac} *instance_p 驱动控制数据
  102. * @param {u32} intr_type 中断类型 GMAC中断/DMA中断
  103. * @param {u32} mask 中断屏蔽位
  104. * @note 在FGMAC驱动初始化成功后调用此函数
  105. */
  106. void FGmacSetInterruptMask(FGmac *instance_p, u32 intr_type, u32 mask)
  107. {
  108. FASSERT(instance_p);
  109. FASSERT(FGMAC_MAX_INTR_TYPE > intr_type);
  110. u32 cur_mask = 0;
  111. uintptr base_addr = instance_p->config.base_addr;
  112. if (FGMAC_CTRL_INTR == intr_type)
  113. {
  114. cur_mask = FGMAC_READ_REG32(base_addr, FGMAC_INTR_MASK_OFFSET);
  115. cur_mask |= mask;
  116. FGMAC_WRITE_REG32(base_addr, FGMAC_INTR_MASK_OFFSET, cur_mask);
  117. }
  118. else
  119. {
  120. cur_mask = FGMAC_READ_REG32(base_addr, FGMAC_DMA_INTR_OFFSET);
  121. cur_mask &= (~mask);
  122. FGMAC_WRITE_REG32(base_addr, FGMAC_DMA_INTR_OFFSET, cur_mask);
  123. }
  124. return;
  125. }
  126. /**
  127. * @name: FGmacSetInterruptUmask
  128. * @msg: 使能FGMAC中断
  129. * @return {*}
  130. * @param {FGmac} *instance_p 驱动控制数据
  131. * @param {u32} intr_type 中断类型 GMAC中断/DMA中断
  132. * @param {u32} mask 中断使能标志位
  133. * @note 在FGMAC驱动初始化成功后调用此函数
  134. */
  135. void FGmacSetInterruptUmask(FGmac *instance_p, u32 intr_type, u32 mask)
  136. {
  137. FASSERT(instance_p);
  138. FASSERT(FGMAC_MAX_INTR_TYPE > intr_type);
  139. u32 cur_mask = 0;
  140. uintptr base_addr = instance_p->config.base_addr;
  141. if (FGMAC_CTRL_INTR == intr_type)
  142. {
  143. cur_mask = FGMAC_READ_REG32(base_addr, FGMAC_INTR_MASK_OFFSET);
  144. cur_mask &= (~mask);
  145. FGMAC_WRITE_REG32(base_addr, FGMAC_INTR_MASK_OFFSET, cur_mask);
  146. }
  147. else
  148. {
  149. cur_mask = FGMAC_READ_REG32(base_addr, FGMAC_DMA_INTR_OFFSET);
  150. cur_mask |= mask;
  151. FGMAC_WRITE_REG32(base_addr, FGMAC_DMA_INTR_OFFSET, cur_mask);
  152. }
  153. return;
  154. }