pch_gbe_api.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /*
  2. * Copyright (C) 1999 - 2010 Intel Corporation.
  3. * Copyright (C) 2010 OKI SEMICONDUCTOR Co., LTD.
  4. *
  5. * This code was derived from the Intel e1000e Linux driver.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; version 2 of the License.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
  19. */
  20. #include "pch_gbe.h"
  21. #include "pch_gbe_phy.h"
  22. /* bus type values */
  23. #define pch_gbe_bus_type_unknown 0
  24. #define pch_gbe_bus_type_pci 1
  25. #define pch_gbe_bus_type_pcix 2
  26. #define pch_gbe_bus_type_pci_express 3
  27. #define pch_gbe_bus_type_reserved 4
  28. /* bus speed values */
  29. #define pch_gbe_bus_speed_unknown 0
  30. #define pch_gbe_bus_speed_33 1
  31. #define pch_gbe_bus_speed_66 2
  32. #define pch_gbe_bus_speed_100 3
  33. #define pch_gbe_bus_speed_120 4
  34. #define pch_gbe_bus_speed_133 5
  35. #define pch_gbe_bus_speed_2500 6
  36. #define pch_gbe_bus_speed_reserved 7
  37. /* bus width values */
  38. #define pch_gbe_bus_width_unknown 0
  39. #define pch_gbe_bus_width_pcie_x1 1
  40. #define pch_gbe_bus_width_pcie_x2 2
  41. #define pch_gbe_bus_width_pcie_x4 4
  42. #define pch_gbe_bus_width_32 5
  43. #define pch_gbe_bus_width_64 6
  44. #define pch_gbe_bus_width_reserved 7
  45. /**
  46. * pch_gbe_plat_get_bus_info - Obtain bus information for adapter
  47. * @hw: Pointer to the HW structure
  48. */
  49. static void pch_gbe_plat_get_bus_info(struct pch_gbe_hw *hw)
  50. {
  51. hw->bus.type = pch_gbe_bus_type_pci_express;
  52. hw->bus.speed = pch_gbe_bus_speed_2500;
  53. hw->bus.width = pch_gbe_bus_width_pcie_x1;
  54. }
  55. /**
  56. * pch_gbe_plat_init_hw - Initialize hardware
  57. * @hw: Pointer to the HW structure
  58. * Returns
  59. * 0: Successfully
  60. * Negative value: Failed-EBUSY
  61. */
  62. static s32 pch_gbe_plat_init_hw(struct pch_gbe_hw *hw)
  63. {
  64. s32 ret_val;
  65. ret_val = pch_gbe_phy_get_id(hw);
  66. if (ret_val) {
  67. pr_err("pch_gbe_phy_get_id error\n");
  68. return ret_val;
  69. }
  70. pch_gbe_phy_init_setting(hw);
  71. /* Setup Mac interface option RGMII */
  72. #ifdef PCH_GBE_MAC_IFOP_RGMII
  73. pch_gbe_phy_set_rgmii(hw);
  74. #endif
  75. return ret_val;
  76. }
  77. static const struct pch_gbe_functions pch_gbe_ops = {
  78. .get_bus_info = pch_gbe_plat_get_bus_info,
  79. .init_hw = pch_gbe_plat_init_hw,
  80. .read_phy_reg = pch_gbe_phy_read_reg_miic,
  81. .write_phy_reg = pch_gbe_phy_write_reg_miic,
  82. .reset_phy = pch_gbe_phy_hw_reset,
  83. .sw_reset_phy = pch_gbe_phy_sw_reset,
  84. .power_up_phy = pch_gbe_phy_power_up,
  85. .power_down_phy = pch_gbe_phy_power_down,
  86. .read_mac_addr = pch_gbe_mac_read_mac_addr
  87. };
  88. /**
  89. * pch_gbe_plat_init_function_pointers - Init func ptrs
  90. * @hw: Pointer to the HW structure
  91. */
  92. static void pch_gbe_plat_init_function_pointers(struct pch_gbe_hw *hw)
  93. {
  94. /* Set PHY parameter */
  95. hw->phy.reset_delay_us = PCH_GBE_PHY_RESET_DELAY_US;
  96. /* Set function pointers */
  97. hw->func = &pch_gbe_ops;
  98. }
  99. /**
  100. * pch_gbe_hal_setup_init_funcs - Initializes function pointers
  101. * @hw: Pointer to the HW structure
  102. * Returns
  103. * 0: Successfully
  104. * ENOSYS: Function is not registered
  105. */
  106. inline s32 pch_gbe_hal_setup_init_funcs(struct pch_gbe_hw *hw)
  107. {
  108. if (!hw->reg) {
  109. pr_err("ERROR: Registers not mapped\n");
  110. return -ENOSYS;
  111. }
  112. pch_gbe_plat_init_function_pointers(hw);
  113. return 0;
  114. }
  115. /**
  116. * pch_gbe_hal_get_bus_info - Obtain bus information for adapter
  117. * @hw: Pointer to the HW structure
  118. */
  119. inline void pch_gbe_hal_get_bus_info(struct pch_gbe_hw *hw)
  120. {
  121. if (!hw->func->get_bus_info)
  122. pr_err("ERROR: configuration\n");
  123. else
  124. hw->func->get_bus_info(hw);
  125. }
  126. /**
  127. * pch_gbe_hal_init_hw - Initialize hardware
  128. * @hw: Pointer to the HW structure
  129. * Returns
  130. * 0: Successfully
  131. * ENOSYS: Function is not registered
  132. */
  133. inline s32 pch_gbe_hal_init_hw(struct pch_gbe_hw *hw)
  134. {
  135. if (!hw->func->init_hw) {
  136. pr_err("ERROR: configuration\n");
  137. return -ENOSYS;
  138. }
  139. return hw->func->init_hw(hw);
  140. }
  141. /**
  142. * pch_gbe_hal_read_phy_reg - Reads PHY register
  143. * @hw: Pointer to the HW structure
  144. * @offset: The register to read
  145. * @data: The buffer to store the 16-bit read.
  146. * Returns
  147. * 0: Successfully
  148. * Negative value: Failed
  149. */
  150. inline s32 pch_gbe_hal_read_phy_reg(struct pch_gbe_hw *hw, u32 offset,
  151. u16 *data)
  152. {
  153. if (!hw->func->read_phy_reg)
  154. return 0;
  155. return hw->func->read_phy_reg(hw, offset, data);
  156. }
  157. /**
  158. * pch_gbe_hal_write_phy_reg - Writes PHY register
  159. * @hw: Pointer to the HW structure
  160. * @offset: The register to read
  161. * @data: The value to write.
  162. * Returns
  163. * 0: Successfully
  164. * Negative value: Failed
  165. */
  166. inline s32 pch_gbe_hal_write_phy_reg(struct pch_gbe_hw *hw, u32 offset,
  167. u16 data)
  168. {
  169. if (!hw->func->write_phy_reg)
  170. return 0;
  171. return hw->func->write_phy_reg(hw, offset, data);
  172. }
  173. /**
  174. * pch_gbe_hal_phy_hw_reset - Hard PHY reset
  175. * @hw: Pointer to the HW structure
  176. */
  177. inline void pch_gbe_hal_phy_hw_reset(struct pch_gbe_hw *hw)
  178. {
  179. if (!hw->func->reset_phy)
  180. pr_err("ERROR: configuration\n");
  181. else
  182. hw->func->reset_phy(hw);
  183. }
  184. /**
  185. * pch_gbe_hal_phy_sw_reset - Soft PHY reset
  186. * @hw: Pointer to the HW structure
  187. */
  188. inline void pch_gbe_hal_phy_sw_reset(struct pch_gbe_hw *hw)
  189. {
  190. if (!hw->func->sw_reset_phy)
  191. pr_err("ERROR: configuration\n");
  192. else
  193. hw->func->sw_reset_phy(hw);
  194. }
  195. /**
  196. * pch_gbe_hal_read_mac_addr - Reads MAC address
  197. * @hw: Pointer to the HW structure
  198. * Returns
  199. * 0: Successfully
  200. * ENOSYS: Function is not registered
  201. */
  202. inline s32 pch_gbe_hal_read_mac_addr(struct pch_gbe_hw *hw)
  203. {
  204. if (!hw->func->read_mac_addr) {
  205. pr_err("ERROR: configuration\n");
  206. return -ENOSYS;
  207. }
  208. return hw->func->read_mac_addr(hw);
  209. }
  210. /**
  211. * pch_gbe_hal_power_up_phy - Power up PHY
  212. * @hw: Pointer to the HW structure
  213. */
  214. inline void pch_gbe_hal_power_up_phy(struct pch_gbe_hw *hw)
  215. {
  216. if (hw->func->power_up_phy)
  217. hw->func->power_up_phy(hw);
  218. }
  219. /**
  220. * pch_gbe_hal_power_down_phy - Power down PHY
  221. * @hw: Pointer to the HW structure
  222. */
  223. inline void pch_gbe_hal_power_down_phy(struct pch_gbe_hw *hw)
  224. {
  225. if (hw->func->power_down_phy)
  226. hw->func->power_down_phy(hw);
  227. }