PageRenderTime 62ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/linux-3.4.x/drivers/net/rtl8367/api_8370/rtl8370_asicdrv_rrcp.c

https://gitlab.com/thanhnhat041/padavan-ng
C | 267 lines | 100 code | 38 blank | 129 comment | 28 complexity | 6b112c5b98c0764a804e0f1b5dcafac2 MD5 | raw file
  1. /*
  2. * Copyright (C) 2009 Realtek Semiconductor Corp.
  3. * All Rights Reserved.
  4. *
  5. * This program is the proprietary software of Realtek Semiconductor
  6. * Corporation and/or its licensors, and only be used, duplicated,
  7. * modified or distributed under the authorized license from Realtek.
  8. *
  9. * ANY USE OF THE SOFTWARE OTHER THAN AS AUTHORIZED UNDER
  10. * THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.
  11. *
  12. * $Revision: 1.1.1.1 $
  13. * $Date: 2010/12/02 04:34:26 $
  14. *
  15. * Purpose : RTL8370 switch high-level API for RTL8367B
  16. * Feature :
  17. *
  18. */
  19. #include "rtl8370_asicdrv_rrcp.h"
  20. /* [FIXME] these macro should be removed in formal chip */
  21. #define RTL8370_OLD_RRCP_CTRL 0x122b
  22. #define RTL8370_OLD_RRCP_TPMSK 0x122e
  23. #define RTL8370_OLD_RRCP_AUTHKEY 0x122d
  24. #define RTL8370_OLD_RRCP_PRIKEY 0x122c
  25. /*
  26. @func ret_t | rtl8370_setAsicRrcp | Set RRCP function enable/disable.
  27. @parm uint32 | vOneEnable | 1: enabled, 0: disabled.
  28. @parm uint32 | vTwoEnable | 1: enabled, 0: disabled.
  29. @rvalue RT_ERR_OK | Success.
  30. @rvalue RT_ERR_SMI | SMI access error.
  31. @rvalue RT_ERR_INPUT | Invalid input parameter.
  32. @comm
  33. Enable / Disable RRCPv1 and RRCPv2 function
  34. Note that RRCPv1 and RRCPv2 shall not be enabled together
  35. Only one is needed.
  36. */
  37. ret_t rtl8370_setAsicRrcp(uint32 vOneEnable, uint32 vTwoEnable)
  38. {
  39. ret_t retVal;
  40. uint32 tmp;
  41. if((vOneEnable > 1) || (vTwoEnable > 1))
  42. return RT_ERR_INPUT;
  43. retVal = rtl8370_getAsicReg(RTL8370_RRCP_CTRL0_REG, &tmp);
  44. if(retVal != RT_ERR_OK)
  45. return RT_ERR_FAILED;
  46. tmp &= ~(1 << RTL8370_RRCP_V1_EN_OFFSET);
  47. tmp &= ~(1 << RTL8370_RRCP_V2_EN_OFFSET);
  48. tmp |= ((vOneEnable & 1) << RTL8370_RRCP_V1_EN_OFFSET);
  49. tmp |= ((vTwoEnable & 1) << RTL8370_RRCP_V2_EN_OFFSET);
  50. retVal = rtl8370_setAsicReg(RTL8370_RRCP_CTRL0_REG, tmp);
  51. if(retVal != RT_ERR_OK)
  52. return RT_ERR_FAILED;
  53. retVal = rtl8370_setAsicReg(RTL8370_OLD_RRCP_CTRL, tmp);
  54. if(retVal != RT_ERR_OK)
  55. return RT_ERR_FAILED;
  56. return RT_ERR_OK;
  57. }
  58. /*
  59. @func ret_t | rtl8370_getAsicRrcp | Get RRCP function enable/disable.
  60. @parm uint32* | vOneEnable | 1: enabled, 0: disabled.
  61. @parm uint32* | vTwoEnable | 1: enabled, 0: disabled.
  62. @rvalue RT_ERR_OK | Success.
  63. @rvalue RT_ERR_SMI | SMI access error.
  64. @rvalue RT_ERR_INPUT | Invalid input parameter.
  65. @comm
  66. Enable / Disable RRCPv1 and RRCPv2 function
  67. Note that RRCPv1 and RRCPv2 shall not be enabled together
  68. Only one is needed.
  69. */
  70. ret_t rtl8370_getAsicRrcp(uint32 *vOneEnable, uint32 *vTwoEnable)
  71. {
  72. ret_t retVal;
  73. retVal = rtl8370_getAsicRegBit(RTL8370_RRCP_CTRL0_REG, RTL8370_RRCP_V1_EN_OFFSET, vOneEnable);
  74. if(retVal != RT_ERR_OK)
  75. return RT_ERR_FAILED;
  76. return rtl8370_getAsicRegBit(RTL8370_RRCP_CTRL0_REG, RTL8370_RRCP_V2_EN_OFFSET, vTwoEnable);
  77. }
  78. /*
  79. @func ret_t | rtl8370_setAsicRrcpTrustPortmask | Set turst portmask of RRCP.
  80. @parm uint32 | pmsk | (0~0xFFFF).
  81. @rvalue RT_ERR_OK | Success.
  82. @rvalue RT_ERR_SMI | SMI access error.
  83. @rvalue RT_ERR_INPUT | Invalid input parameter.
  84. @comm
  85. This API set the trust port mask of RRCP packet.
  86. If SPA of a RRCP is not in the set of trust portmask, the RRCP
  87. frame will be dropped.
  88. */
  89. ret_t rtl8370_setAsicRrcpTrustPortmask(uint32 pmsk)
  90. {
  91. ret_t retVal;
  92. if(pmsk > RTL8370_PORTMASK)
  93. return RT_ERR_PORT_MASK;
  94. retVal = rtl8370_setAsicReg(RTL8370_RRCP_TRUST_PORTMASK_REG, pmsk);
  95. if(retVal != RT_ERR_OK )
  96. return retVal;
  97. retVal = rtl8370_setAsicReg(RTL8370_OLD_RRCP_TPMSK, pmsk);
  98. if(retVal != RT_ERR_OK )
  99. return retVal;
  100. return RT_ERR_OK;
  101. }
  102. /*
  103. @func ret_t | rtl8370_getAsicRrcpTrustPortmask | Get turst portmask of RRCP.
  104. @parm uint32* | authKey | (0~0xFFFF).
  105. @rvalue RT_ERR_OK | Success.
  106. @rvalue RT_ERR_SMI | SMI access error.
  107. @rvalue RT_ERR_INPUT | Invalid input parameter.
  108. @comm
  109. This API get the trust port mask of RRCP packet.
  110. If SPA of a RRCP is not in the set of trust portmask, the RRCP
  111. frame will be dropped.
  112. */
  113. ret_t rtl8370_getAsicRrcpTrustPortmask(uint32 *pmsk)
  114. {
  115. return rtl8370_getAsicReg(RTL8370_RRCP_TRUST_PORTMASK_REG, pmsk);
  116. }
  117. /*
  118. @func ret_t | rtl8370_setAsicRrcpAuthenticationKey | Set authentication key of RRCP.
  119. @parm uint32 | authKey | (0~0xFFFF).
  120. @rvalue RT_ERR_OK | Success.
  121. @rvalue RT_ERR_SMI | SMI access error.
  122. @rvalue RT_ERR_INPUT | Invalid input parameter.
  123. @comm
  124. This API set the authentication register.
  125. Authentication Key Register is used to compare with Authentication key field of
  126. RRCPv1 Frame, and Public Key field of RRCPv2 frame.
  127. */
  128. ret_t rtl8370_setAsicRrcpAuthenticationKey(uint32 authKey)
  129. {
  130. ret_t retVal;
  131. if(authKey > RTL8370_REGDATAMAX)
  132. return RT_ERR_PHY_DATAMASK;
  133. retVal = rtl8370_setAsicReg(RTL8370_RRCP_AUTH_KEY_REG, authKey);
  134. if(retVal != RT_ERR_OK )
  135. return retVal;
  136. retVal = rtl8370_setAsicReg(RTL8370_OLD_RRCP_AUTHKEY, authKey);
  137. if(retVal != RT_ERR_OK )
  138. return retVal;
  139. return RT_ERR_OK;
  140. }
  141. /*
  142. @func ret_t | rtl8370_getAsicRrcpAuthenticationKey | Get authentication key of RRCP.
  143. @parm uint32* | pmsk | (0~0xFFFF).
  144. @rvalue RT_ERR_OK | Success.
  145. @rvalue RT_ERR_SMI | SMI access error.
  146. @rvalue RT_ERR_INPUT | Invalid input parameter.
  147. @comm
  148. This API get the authentication register.
  149. Authentication Key Register is used to compare with Authentication key field of
  150. RRCPv1 Frame, and Public Key field of RRCPv2 frame.
  151. */
  152. ret_t rtl8370_getAsicRrcpAuthenticationKey(uint32 *authKey)
  153. {
  154. return rtl8370_getAsicReg(RTL8370_RRCP_AUTH_KEY_REG, authKey);
  155. }
  156. /*
  157. @func ret_t | rtl8370_setAsicPrivateKey | Set private key of RRCP.
  158. @parm uint32 | privateKey | (0~0xFFFF).
  159. @rvalue RT_ERR_OK | Success.
  160. @rvalue RT_ERR_SMI | SMI access error.
  161. @rvalue RT_ERR_INPUT | Invalid input parameter.
  162. @comm
  163. This API set the private key of RRCPv2
  164. Authentication Key Register is used to compare with private Key field of RRCPv2 frame.
  165. */
  166. ret_t rtl8370_setAsicRrcpPrivateKey(uint32 privateKey)
  167. {
  168. ret_t retVal;
  169. if(privateKey> RTL8370_REGDATAMAX)
  170. return RT_ERR_PHY_DATAMASK;
  171. retVal = rtl8370_setAsicReg(RTL8370_RRCP_PRIVATE_KEY_REG, privateKey);
  172. if(retVal != RT_ERR_OK )
  173. return retVal;
  174. retVal = rtl8370_setAsicReg(RTL8370_OLD_RRCP_PRIKEY, privateKey);
  175. if(retVal != RT_ERR_OK )
  176. return retVal;
  177. return RT_ERR_OK;
  178. }
  179. /*
  180. @func ret_t | rtl8370_getAsicPrivateKey | Get private key of RRCP.
  181. @parm uint32* | privateKey | (0~0xFFFF).
  182. @rvalue RT_ERR_OK | Success.
  183. @rvalue RT_ERR_SMI | SMI access error.
  184. @rvalue RT_ERR_INPUT | Invalid input parameter.
  185. @comm
  186. This API get the private key of RRCPv2
  187. Authentication Key Register is used to compare with private Key field of RRCPv2 frame.
  188. */
  189. ret_t rtl8370_getAsicRrcpPrivateKey(uint32 *privateKey)
  190. {
  191. return rtl8370_getAsicReg(RTL8370_RRCP_PRIVATE_KEY_REG, privateKey);
  192. }
  193. /*
  194. @func ret_t | rtl8370_setAsicRrcpV2Trap8051 | Set trap to 8051 setting enable/disable.
  195. @parm uint32 | trap | 0: disable/1: enable.
  196. @rvalue RT_ERR_OK | Success.
  197. @rvalue RT_ERR_SMI | SMI access error.
  198. @rvalue RT_ERR_INPUT | Invalid input parameter.
  199. @comm
  200. This API set trap RRCPv2 frame to 8051 enable/disable
  201. Trap to RRCP frame to 8051 setting. If this bit is set, ASIC will
  202. not handled the received RRCP frame.
  203. */
  204. ret_t rtl8370_setAsicRrcpV2Trap8051(uint32 trap)
  205. {
  206. ret_t retVal;
  207. if(trap > 1)
  208. return RT_ERR_INPUT;
  209. retVal = rtl8370_setAsicRegBit(RTL8370_RRCP_CTRL0_REG, RTL8370_RRCP_TRAP_8051_OFFSET, trap);
  210. if(retVal != RT_ERR_OK)
  211. return retVal;
  212. retVal = rtl8370_setAsicRegBit(RTL8370_OLD_RRCP_CTRL, RTL8370_RRCP_TRAP_8051_OFFSET, trap);
  213. return retVal;
  214. }
  215. /*
  216. @func ret_t | rtl8370_getAsicRrcpV2Trap8051 | Set trap to 8051 setting enable/disable.
  217. @parm uint32* | trap | 0: disable/1: enable.
  218. @rvalue RT_ERR_OK | Success.
  219. @rvalue RT_ERR_SMI | SMI access error.
  220. @rvalue RT_ERR_INPUT | Invalid input parameter.
  221. @comm
  222. This API get trap RRCPv2 frame to 8051 enable/disable
  223. Trap to RRCP frame to 8051 setting. If this bit is set, ASIC will
  224. not handled the received RRCP frame.
  225. */
  226. ret_t rtl8370_getAsicRrcpV2Trap8051(uint32 *trap)
  227. {
  228. return rtl8370_getAsicRegBit(RTL8370_RRCP_CTRL0_REG, RTL8370_RRCP_TRAP_8051_OFFSET, trap);
  229. }