cvmx-helper-bgx.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2020 Marvell International Ltd.
  4. *
  5. * Functions to configure the BGX MAC.
  6. */
  7. #ifndef __CVMX_HELPER_BGX_H__
  8. #define __CVMX_HELPER_BGX_H__
  9. #define CVMX_BGX_RX_FIFO_SIZE (64 * 1024)
  10. #define CVMX_BGX_TX_FIFO_SIZE (32 * 1024)
  11. int __cvmx_helper_bgx_enumerate(int xiface);
  12. /**
  13. * @INTERNAL
  14. * Disable the BGX port
  15. *
  16. * @param xipd_port IPD port of the BGX interface to disable
  17. */
  18. void cvmx_helper_bgx_disable(int xipd_port);
  19. /**
  20. * @INTERNAL
  21. * Probe a SGMII interface and determine the number of ports
  22. * connected to it. The SGMII/XAUI interface should still be down after
  23. * this call. This is used by interfaces using the bgx mac.
  24. *
  25. * @param xiface Interface to probe
  26. *
  27. * Return: Number of ports on the interface. Zero to disable.
  28. */
  29. int __cvmx_helper_bgx_probe(int xiface);
  30. /**
  31. * @INTERNAL
  32. * Bringup and enable a SGMII interface. After this call packet
  33. * I/O should be fully functional. This is called with IPD
  34. * enabled but PKO disabled. This is used by interfaces using the
  35. * bgx mac.
  36. *
  37. * @param xiface Interface to bring up
  38. *
  39. * Return: Zero on success, negative on failure
  40. */
  41. int __cvmx_helper_bgx_sgmii_enable(int xiface);
  42. /**
  43. * @INTERNAL
  44. * Return the link state of an IPD/PKO port as returned by
  45. * auto negotiation. The result of this function may not match
  46. * Octeon's link config if auto negotiation has changed since
  47. * the last call to cvmx_helper_link_set(). This is used by
  48. * interfaces using the bgx mac.
  49. *
  50. * @param xipd_port IPD/PKO port to query
  51. *
  52. * Return: Link state
  53. */
  54. cvmx_helper_link_info_t __cvmx_helper_bgx_sgmii_link_get(int xipd_port);
  55. /**
  56. * @INTERNAL
  57. * Configure an IPD/PKO port for the specified link state. This
  58. * function does not influence auto negotiation at the PHY level.
  59. * The passed link state must always match the link state returned
  60. * by cvmx_helper_link_get(). It is normally best to use
  61. * cvmx_helper_link_autoconf() instead. This is used by interfaces
  62. * using the bgx mac.
  63. *
  64. * @param xipd_port IPD/PKO port to configure
  65. * @param link_info The new link state
  66. *
  67. * Return: Zero on success, negative on failure
  68. */
  69. int __cvmx_helper_bgx_sgmii_link_set(int xipd_port, cvmx_helper_link_info_t link_info);
  70. /**
  71. * @INTERNAL
  72. * Configure a port for internal and/or external loopback. Internal loopback
  73. * causes packets sent by the port to be received by Octeon. External loopback
  74. * causes packets received from the wire to sent out again. This is used by
  75. * interfaces using the bgx mac.
  76. *
  77. * @param xipd_port IPD/PKO port to loopback.
  78. * @param enable_internal
  79. * Non zero if you want internal loopback
  80. * @param enable_external
  81. * Non zero if you want external loopback
  82. *
  83. * Return: Zero on success, negative on failure.
  84. */
  85. int __cvmx_helper_bgx_sgmii_configure_loopback(int xipd_port, int enable_internal,
  86. int enable_external);
  87. /**
  88. * @INTERNAL
  89. * Bringup and enable a XAUI interface. After this call packet
  90. * I/O should be fully functional. This is called with IPD
  91. * enabled but PKO disabled. This is used by interfaces using the
  92. * bgx mac.
  93. *
  94. * @param xiface Interface to bring up
  95. *
  96. * Return: Zero on success, negative on failure
  97. */
  98. int __cvmx_helper_bgx_xaui_enable(int xiface);
  99. /**
  100. * @INTERNAL
  101. * Return the link state of an IPD/PKO port as returned by
  102. * auto negotiation. The result of this function may not match
  103. * Octeon's link config if auto negotiation has changed since
  104. * the last call to cvmx_helper_link_set(). This is used by
  105. * interfaces using the bgx mac.
  106. *
  107. * @param xipd_port IPD/PKO port to query
  108. *
  109. * Return: Link state
  110. */
  111. cvmx_helper_link_info_t __cvmx_helper_bgx_xaui_link_get(int xipd_port);
  112. /**
  113. * @INTERNAL
  114. * Configure an IPD/PKO port for the specified link state. This
  115. * function does not influence auto negotiation at the PHY level.
  116. * The passed link state must always match the link state returned
  117. * by cvmx_helper_link_get(). It is normally best to use
  118. * cvmx_helper_link_autoconf() instead. This is used by interfaces
  119. * using the bgx mac.
  120. *
  121. * @param xipd_port IPD/PKO port to configure
  122. * @param link_info The new link state
  123. *
  124. * Return: Zero on success, negative on failure
  125. */
  126. int __cvmx_helper_bgx_xaui_link_set(int xipd_port, cvmx_helper_link_info_t link_info);
  127. /**
  128. * @INTERNAL
  129. * Configure a port for internal and/or external loopback. Internal loopback
  130. * causes packets sent by the port to be received by Octeon. External loopback
  131. * causes packets received from the wire to sent out again. This is used by
  132. * interfaces using the bgx mac.
  133. *
  134. * @param xipd_port IPD/PKO port to loopback.
  135. * @param enable_internal
  136. * Non zero if you want internal loopback
  137. * @param enable_external
  138. * Non zero if you want external loopback
  139. *
  140. * Return: Zero on success, negative on failure.
  141. */
  142. int __cvmx_helper_bgx_xaui_configure_loopback(int xipd_port, int enable_internal,
  143. int enable_external);
  144. int __cvmx_helper_bgx_mixed_enable(int xiface);
  145. cvmx_helper_link_info_t __cvmx_helper_bgx_mixed_link_get(int xipd_port);
  146. int __cvmx_helper_bgx_mixed_link_set(int xipd_port, cvmx_helper_link_info_t link_info);
  147. int __cvmx_helper_bgx_mixed_configure_loopback(int xipd_port, int enable_internal,
  148. int enable_external);
  149. cvmx_helper_interface_mode_t cvmx_helper_bgx_get_mode(int xiface, int index);
  150. /**
  151. * @INTERNAL
  152. * Configure Priority-Based Flow Control (a.k.a. PFC/CBFC)
  153. * on a specific BGX interface/port.
  154. */
  155. void __cvmx_helper_bgx_xaui_config_pfc(unsigned int node, unsigned int interface, unsigned int port,
  156. bool pfc_enable);
  157. /**
  158. * This function control how the hardware handles incoming PAUSE
  159. * packets. The most common modes of operation:
  160. * ctl_bck = 1, ctl_drp = 1: hardware handles everything
  161. * ctl_bck = 0, ctl_drp = 0: software sees all PAUSE frames
  162. * ctl_bck = 0, ctl_drp = 1: all PAUSE frames are completely ignored
  163. * @param node node number.
  164. * @param interface interface number
  165. * @param port port number
  166. * @param ctl_bck 1: Forward PAUSE information to TX block
  167. * @param ctl_drp 1: Drop control PAUSE frames.
  168. */
  169. void cvmx_helper_bgx_rx_pause_ctl(unsigned int node, unsigned int interface, unsigned int port,
  170. unsigned int ctl_bck, unsigned int ctl_drp);
  171. /**
  172. * This function configures the receive action taken for multicast, broadcast
  173. * and dmac filter match packets.
  174. * @param node node number.
  175. * @param interface interface number
  176. * @param port port number
  177. * @param cam_accept 0: reject packets on dmac filter match
  178. * 1: accept packet on dmac filter match
  179. * @param mcast_mode 0x0 = Force reject all multicast packets
  180. * 0x1 = Force accept all multicast packets
  181. * 0x2 = Use the address filter CAM
  182. * @param bcast_accept 0 = Reject all broadcast packets
  183. * 1 = Accept all broadcast packets
  184. */
  185. void cvmx_helper_bgx_rx_adr_ctl(unsigned int node, unsigned int interface, unsigned int port,
  186. unsigned int cam_accept, unsigned int mcast_mode,
  187. unsigned int bcast_accept);
  188. /**
  189. * Function to control the generation of FCS, padding by the BGX
  190. *
  191. */
  192. void cvmx_helper_bgx_tx_options(unsigned int node, unsigned int interface, unsigned int index,
  193. bool fcs_enable, bool pad_enable);
  194. /**
  195. * Set mac for the ipd_port
  196. *
  197. * @param xipd_port ipd_port to set the mac
  198. * @param bcst If set, accept all broadcast packets
  199. * @param mcst Multicast mode
  200. * 0 = Force reject all multicast packets
  201. * 1 = Force accept all multicast packets
  202. * 2 = use the address filter CAM.
  203. * @param mac mac address for the ipd_port
  204. */
  205. void cvmx_helper_bgx_set_mac(int xipd_port, int bcst, int mcst, u64 mac);
  206. int __cvmx_helper_bgx_port_init(int xipd_port, int phy_pres);
  207. void cvmx_helper_bgx_set_jabber(int xiface, unsigned int index, unsigned int size);
  208. int cvmx_helper_bgx_shutdown_port(int xiface, int index);
  209. int cvmx_bgx_set_backpressure_override(int xiface, unsigned int port_mask);
  210. int __cvmx_helper_bgx_fifo_size(int xiface, unsigned int lmac);
  211. /**
  212. * Returns if an interface is RGMII or not
  213. *
  214. * @param xiface xinterface to check
  215. * @param index port index (must be 0 for rgmii)
  216. *
  217. * Return: true if RGMII, false otherwise
  218. */
  219. static inline bool cvmx_helper_bgx_is_rgmii(int xiface, int index)
  220. {
  221. union cvmx_bgxx_cmrx_config cmr_config;
  222. if (!OCTEON_IS_MODEL(OCTEON_CN73XX) || index != 0)
  223. return false;
  224. cmr_config.u64 = csr_rd(CVMX_BGXX_CMRX_CONFIG(index, xiface));
  225. return cmr_config.s.lmac_type == 5;
  226. }
  227. /**
  228. * Probes the BGX Super Path (SMU/SPU) mode
  229. *
  230. * @param xiface global interface number
  231. * @param index interface index
  232. *
  233. * Return: true, if Super-MAC/PCS mode, false -- otherwise
  234. */
  235. bool cvmx_helper_bgx_is_smu(int xiface, int index);
  236. /**
  237. * @INTERNAL
  238. * Configure parameters of PAUSE packet.
  239. *
  240. * @param xipd_port Global IPD port (node + IPD port).
  241. * @param smac Source MAC address.
  242. * @param dmac Destination MAC address.
  243. * @param type PAUSE packet type.
  244. * @param time Pause time for PAUSE packets (number of 512 bit-times).
  245. * @param interval Interval between PAUSE packets (number of 512 bit-times).
  246. * Return: Zero on success, negative on failure.
  247. */
  248. int cvmx_bgx_set_pause_pkt_param(int xipd_port, u64 smac, u64 dmac, unsigned int type,
  249. unsigned int time, unsigned int interval);
  250. /**
  251. * @INTERNAL
  252. * Setup the BGX flow-control mode.
  253. *
  254. * @param xipd_port Global IPD port (node + IPD port).
  255. * @param type Flow-control type/protocol.
  256. * @param mode Flow-control mode.
  257. * Return: Zero on success, negative on failure.
  258. */
  259. int cvmx_bgx_set_flowctl_mode(int xipd_port, cvmx_qos_proto_t qos, cvmx_qos_pkt_mode_t mode);
  260. /**
  261. * Enables or disables autonegotiation for an interface.
  262. *
  263. * @param xiface interface to set autonegotiation
  264. * @param index port index
  265. * @param enable true to enable autonegotiation, false to disable it
  266. *
  267. * Return: 0 for success, -1 on error.
  268. */
  269. int cvmx_helper_set_autonegotiation(int xiface, int index, bool enable);
  270. /**
  271. * Enables or disables forward error correction
  272. *
  273. * @param xiface interface
  274. * @param index port index
  275. * @param enable set to true to enable FEC, false to disable
  276. *
  277. * Return: 0 for success, -1 on error
  278. *
  279. * @NOTE: If autonegotiation is enabled then autonegotiation will be
  280. * restarted for negotiating FEC.
  281. */
  282. int cvmx_helper_set_fec(int xiface, int index, bool enable);
  283. #ifdef CVMX_DUMP_BGX
  284. /**
  285. * Dump BGX configuration for node 0
  286. */
  287. int cvmx_dump_bgx_config(unsigned int bgx);
  288. /**
  289. * Dump BGX status for node 0
  290. */
  291. int cvmx_dump_bgx_status(unsigned int bgx);
  292. /**
  293. * Dump BGX configuration
  294. */
  295. int cvmx_dump_bgx_config_node(unsigned int node, unsigned int bgx);
  296. /**
  297. * Dump BGX status
  298. */
  299. int cvmx_dump_bgx_status_node(unsigned int node, unsigned int bgx);
  300. #endif
  301. #endif