cvmx-helper.c 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291
  1. /***********************license start***************
  2. * Author: Cavium Networks
  3. *
  4. * Contact: support@caviumnetworks.com
  5. * This file is part of the OCTEON SDK
  6. *
  7. * Copyright (c) 2003-2008 Cavium Networks
  8. *
  9. * This file is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License, Version 2, as
  11. * published by the Free Software Foundation.
  12. *
  13. * This file is distributed in the hope that it will be useful, but
  14. * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
  15. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
  16. * NONINFRINGEMENT. See the GNU General Public License for more
  17. * details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this file; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  22. * or visit http://www.gnu.org/licenses/.
  23. *
  24. * This file may also be available under a different license from Cavium.
  25. * Contact Cavium Networks for more information
  26. ***********************license end**************************************/
  27. /*
  28. *
  29. * Helper functions for common, but complicated tasks.
  30. *
  31. */
  32. #include <asm/octeon/octeon.h>
  33. #include <asm/octeon/cvmx-config.h>
  34. #include <asm/octeon/cvmx-fpa.h>
  35. #include <asm/octeon/cvmx-pip.h>
  36. #include <asm/octeon/cvmx-pko.h>
  37. #include <asm/octeon/cvmx-ipd.h>
  38. #include <asm/octeon/cvmx-spi.h>
  39. #include <asm/octeon/cvmx-helper.h>
  40. #include <asm/octeon/cvmx-helper-board.h>
  41. #include <asm/octeon/cvmx-pip-defs.h>
  42. #include <asm/octeon/cvmx-smix-defs.h>
  43. #include <asm/octeon/cvmx-asxx-defs.h>
  44. /**
  45. * cvmx_override_pko_queue_priority(int ipd_port, uint64_t
  46. * priorities[16]) is a function pointer. It is meant to allow
  47. * customization of the PKO queue priorities based on the port
  48. * number. Users should set this pointer to a function before
  49. * calling any cvmx-helper operations.
  50. */
  51. void (*cvmx_override_pko_queue_priority) (int pko_port,
  52. uint64_t priorities[16]);
  53. /**
  54. * cvmx_override_ipd_port_setup(int ipd_port) is a function
  55. * pointer. It is meant to allow customization of the IPD port
  56. * setup before packet input/output comes online. It is called
  57. * after cvmx-helper does the default IPD configuration, but
  58. * before IPD is enabled. Users should set this pointer to a
  59. * function before calling any cvmx-helper operations.
  60. */
  61. void (*cvmx_override_ipd_port_setup) (int ipd_port);
  62. /* Port count per interface */
  63. static int interface_port_count[5];
  64. /* Port last configured link info index by IPD/PKO port */
  65. static cvmx_helper_link_info_t
  66. port_link_info[CVMX_PIP_NUM_INPUT_PORTS];
  67. /**
  68. * Return the number of interfaces the chip has. Each interface
  69. * may have multiple ports. Most chips support two interfaces,
  70. * but the CNX0XX and CNX1XX are exceptions. These only support
  71. * one interface.
  72. *
  73. * Returns Number of interfaces on chip
  74. */
  75. int cvmx_helper_get_number_of_interfaces(void)
  76. {
  77. if (OCTEON_IS_MODEL(OCTEON_CN56XX) || OCTEON_IS_MODEL(OCTEON_CN52XX))
  78. return 4;
  79. else
  80. return 3;
  81. }
  82. EXPORT_SYMBOL_GPL(cvmx_helper_get_number_of_interfaces);
  83. /**
  84. * Return the number of ports on an interface. Depending on the
  85. * chip and configuration, this can be 1-16. A value of 0
  86. * specifies that the interface doesn't exist or isn't usable.
  87. *
  88. * @interface: Interface to get the port count for
  89. *
  90. * Returns Number of ports on interface. Can be Zero.
  91. */
  92. int cvmx_helper_ports_on_interface(int interface)
  93. {
  94. return interface_port_count[interface];
  95. }
  96. EXPORT_SYMBOL_GPL(cvmx_helper_ports_on_interface);
  97. /**
  98. * @INTERNAL
  99. * Return interface mode for CN68xx.
  100. */
  101. static cvmx_helper_interface_mode_t __cvmx_get_mode_cn68xx(int interface)
  102. {
  103. union cvmx_mio_qlmx_cfg qlm_cfg;
  104. switch (interface) {
  105. case 0:
  106. qlm_cfg.u64 = cvmx_read_csr(CVMX_MIO_QLMX_CFG(0));
  107. /* QLM is disabled when QLM SPD is 15. */
  108. if (qlm_cfg.s.qlm_spd == 15)
  109. return CVMX_HELPER_INTERFACE_MODE_DISABLED;
  110. if (qlm_cfg.s.qlm_cfg == 2)
  111. return CVMX_HELPER_INTERFACE_MODE_SGMII;
  112. else if (qlm_cfg.s.qlm_cfg == 3)
  113. return CVMX_HELPER_INTERFACE_MODE_XAUI;
  114. else
  115. return CVMX_HELPER_INTERFACE_MODE_DISABLED;
  116. case 2:
  117. case 3:
  118. case 4:
  119. qlm_cfg.u64 = cvmx_read_csr(CVMX_MIO_QLMX_CFG(interface));
  120. /* QLM is disabled when QLM SPD is 15. */
  121. if (qlm_cfg.s.qlm_spd == 15)
  122. return CVMX_HELPER_INTERFACE_MODE_DISABLED;
  123. if (qlm_cfg.s.qlm_cfg == 2)
  124. return CVMX_HELPER_INTERFACE_MODE_SGMII;
  125. else if (qlm_cfg.s.qlm_cfg == 3)
  126. return CVMX_HELPER_INTERFACE_MODE_XAUI;
  127. else
  128. return CVMX_HELPER_INTERFACE_MODE_DISABLED;
  129. case 7:
  130. qlm_cfg.u64 = cvmx_read_csr(CVMX_MIO_QLMX_CFG(3));
  131. /* QLM is disabled when QLM SPD is 15. */
  132. if (qlm_cfg.s.qlm_spd == 15) {
  133. return CVMX_HELPER_INTERFACE_MODE_DISABLED;
  134. } else if (qlm_cfg.s.qlm_cfg != 0) {
  135. qlm_cfg.u64 = cvmx_read_csr(CVMX_MIO_QLMX_CFG(1));
  136. if (qlm_cfg.s.qlm_cfg != 0)
  137. return CVMX_HELPER_INTERFACE_MODE_DISABLED;
  138. }
  139. return CVMX_HELPER_INTERFACE_MODE_NPI;
  140. case 8:
  141. return CVMX_HELPER_INTERFACE_MODE_LOOP;
  142. default:
  143. return CVMX_HELPER_INTERFACE_MODE_DISABLED;
  144. }
  145. }
  146. /**
  147. * @INTERNAL
  148. * Return interface mode for an Octeon II
  149. */
  150. static cvmx_helper_interface_mode_t __cvmx_get_mode_octeon2(int interface)
  151. {
  152. union cvmx_gmxx_inf_mode mode;
  153. if (OCTEON_IS_MODEL(OCTEON_CN68XX))
  154. return __cvmx_get_mode_cn68xx(interface);
  155. if (interface == 2)
  156. return CVMX_HELPER_INTERFACE_MODE_NPI;
  157. if (interface == 3)
  158. return CVMX_HELPER_INTERFACE_MODE_LOOP;
  159. /* Only present in CN63XX & CN66XX Octeon model */
  160. if ((OCTEON_IS_MODEL(OCTEON_CN63XX) &&
  161. (interface == 4 || interface == 5)) ||
  162. (OCTEON_IS_MODEL(OCTEON_CN66XX) &&
  163. interface >= 4 && interface <= 7)) {
  164. return CVMX_HELPER_INTERFACE_MODE_DISABLED;
  165. }
  166. if (OCTEON_IS_MODEL(OCTEON_CN66XX)) {
  167. union cvmx_mio_qlmx_cfg mio_qlm_cfg;
  168. /* QLM2 is SGMII0 and QLM1 is SGMII1 */
  169. if (interface == 0)
  170. mio_qlm_cfg.u64 = cvmx_read_csr(CVMX_MIO_QLMX_CFG(2));
  171. else if (interface == 1)
  172. mio_qlm_cfg.u64 = cvmx_read_csr(CVMX_MIO_QLMX_CFG(1));
  173. else
  174. return CVMX_HELPER_INTERFACE_MODE_DISABLED;
  175. if (mio_qlm_cfg.s.qlm_spd == 15)
  176. return CVMX_HELPER_INTERFACE_MODE_DISABLED;
  177. if (mio_qlm_cfg.s.qlm_cfg == 9)
  178. return CVMX_HELPER_INTERFACE_MODE_SGMII;
  179. else if (mio_qlm_cfg.s.qlm_cfg == 11)
  180. return CVMX_HELPER_INTERFACE_MODE_XAUI;
  181. else
  182. return CVMX_HELPER_INTERFACE_MODE_DISABLED;
  183. } else if (OCTEON_IS_MODEL(OCTEON_CN61XX)) {
  184. union cvmx_mio_qlmx_cfg qlm_cfg;
  185. if (interface == 0) {
  186. qlm_cfg.u64 = cvmx_read_csr(CVMX_MIO_QLMX_CFG(2));
  187. if (qlm_cfg.s.qlm_cfg == 2)
  188. return CVMX_HELPER_INTERFACE_MODE_SGMII;
  189. else if (qlm_cfg.s.qlm_cfg == 3)
  190. return CVMX_HELPER_INTERFACE_MODE_XAUI;
  191. else
  192. return CVMX_HELPER_INTERFACE_MODE_DISABLED;
  193. } else if (interface == 1) {
  194. qlm_cfg.u64 = cvmx_read_csr(CVMX_MIO_QLMX_CFG(0));
  195. if (qlm_cfg.s.qlm_cfg == 2)
  196. return CVMX_HELPER_INTERFACE_MODE_SGMII;
  197. else if (qlm_cfg.s.qlm_cfg == 3)
  198. return CVMX_HELPER_INTERFACE_MODE_XAUI;
  199. else
  200. return CVMX_HELPER_INTERFACE_MODE_DISABLED;
  201. }
  202. } else if (OCTEON_IS_MODEL(OCTEON_CNF71XX)) {
  203. if (interface == 0) {
  204. union cvmx_mio_qlmx_cfg qlm_cfg;
  205. qlm_cfg.u64 = cvmx_read_csr(CVMX_MIO_QLMX_CFG(0));
  206. if (qlm_cfg.s.qlm_cfg == 2)
  207. return CVMX_HELPER_INTERFACE_MODE_SGMII;
  208. }
  209. return CVMX_HELPER_INTERFACE_MODE_DISABLED;
  210. }
  211. if (interface == 1 && OCTEON_IS_MODEL(OCTEON_CN63XX))
  212. return CVMX_HELPER_INTERFACE_MODE_DISABLED;
  213. mode.u64 = cvmx_read_csr(CVMX_GMXX_INF_MODE(interface));
  214. if (OCTEON_IS_MODEL(OCTEON_CN63XX)) {
  215. switch (mode.cn63xx.mode) {
  216. case 0:
  217. return CVMX_HELPER_INTERFACE_MODE_SGMII;
  218. case 1:
  219. return CVMX_HELPER_INTERFACE_MODE_XAUI;
  220. default:
  221. return CVMX_HELPER_INTERFACE_MODE_DISABLED;
  222. }
  223. } else {
  224. if (!mode.s.en)
  225. return CVMX_HELPER_INTERFACE_MODE_DISABLED;
  226. if (mode.s.type)
  227. return CVMX_HELPER_INTERFACE_MODE_GMII;
  228. else
  229. return CVMX_HELPER_INTERFACE_MODE_RGMII;
  230. }
  231. }
  232. /**
  233. * Get the operating mode of an interface. Depending on the Octeon
  234. * chip and configuration, this function returns an enumeration
  235. * of the type of packet I/O supported by an interface.
  236. *
  237. * @interface: Interface to probe
  238. *
  239. * Returns Mode of the interface. Unknown or unsupported interfaces return
  240. * DISABLED.
  241. */
  242. cvmx_helper_interface_mode_t cvmx_helper_interface_get_mode(int interface)
  243. {
  244. union cvmx_gmxx_inf_mode mode;
  245. if (interface < 0 ||
  246. interface >= cvmx_helper_get_number_of_interfaces())
  247. return CVMX_HELPER_INTERFACE_MODE_DISABLED;
  248. /*
  249. * Octeon II models
  250. */
  251. if (OCTEON_IS_MODEL(OCTEON_CN6XXX) || OCTEON_IS_MODEL(OCTEON_CNF71XX))
  252. return __cvmx_get_mode_octeon2(interface);
  253. /*
  254. * Octeon and Octeon Plus models
  255. */
  256. if (interface == 2)
  257. return CVMX_HELPER_INTERFACE_MODE_NPI;
  258. if (interface == 3) {
  259. if (OCTEON_IS_MODEL(OCTEON_CN56XX)
  260. || OCTEON_IS_MODEL(OCTEON_CN52XX))
  261. return CVMX_HELPER_INTERFACE_MODE_LOOP;
  262. else
  263. return CVMX_HELPER_INTERFACE_MODE_DISABLED;
  264. }
  265. if (interface == 0
  266. && cvmx_sysinfo_get()->board_type == CVMX_BOARD_TYPE_CN3005_EVB_HS5
  267. && cvmx_sysinfo_get()->board_rev_major == 1) {
  268. /*
  269. * Lie about interface type of CN3005 board. This
  270. * board has a switch on port 1 like the other
  271. * evaluation boards, but it is connected over RGMII
  272. * instead of GMII. Report GMII mode so that the
  273. * speed is forced to 1 Gbit full duplex. Other than
  274. * some initial configuration (which does not use the
  275. * output of this function) there is no difference in
  276. * setup between GMII and RGMII modes.
  277. */
  278. return CVMX_HELPER_INTERFACE_MODE_GMII;
  279. }
  280. /* Interface 1 is always disabled on CN31XX and CN30XX */
  281. if ((interface == 1)
  282. && (OCTEON_IS_MODEL(OCTEON_CN31XX) || OCTEON_IS_MODEL(OCTEON_CN30XX)
  283. || OCTEON_IS_MODEL(OCTEON_CN50XX)
  284. || OCTEON_IS_MODEL(OCTEON_CN52XX)))
  285. return CVMX_HELPER_INTERFACE_MODE_DISABLED;
  286. mode.u64 = cvmx_read_csr(CVMX_GMXX_INF_MODE(interface));
  287. if (OCTEON_IS_MODEL(OCTEON_CN56XX) || OCTEON_IS_MODEL(OCTEON_CN52XX)) {
  288. switch (mode.cn56xx.mode) {
  289. case 0:
  290. return CVMX_HELPER_INTERFACE_MODE_DISABLED;
  291. case 1:
  292. return CVMX_HELPER_INTERFACE_MODE_XAUI;
  293. case 2:
  294. return CVMX_HELPER_INTERFACE_MODE_SGMII;
  295. case 3:
  296. return CVMX_HELPER_INTERFACE_MODE_PICMG;
  297. default:
  298. return CVMX_HELPER_INTERFACE_MODE_DISABLED;
  299. }
  300. } else {
  301. if (!mode.s.en)
  302. return CVMX_HELPER_INTERFACE_MODE_DISABLED;
  303. if (mode.s.type) {
  304. if (OCTEON_IS_MODEL(OCTEON_CN38XX)
  305. || OCTEON_IS_MODEL(OCTEON_CN58XX))
  306. return CVMX_HELPER_INTERFACE_MODE_SPI;
  307. else
  308. return CVMX_HELPER_INTERFACE_MODE_GMII;
  309. } else
  310. return CVMX_HELPER_INTERFACE_MODE_RGMII;
  311. }
  312. }
  313. EXPORT_SYMBOL_GPL(cvmx_helper_interface_get_mode);
  314. /**
  315. * Configure the IPD/PIP tagging and QoS options for a specific
  316. * port. This function determines the POW work queue entry
  317. * contents for a port. The setup performed here is controlled by
  318. * the defines in executive-config.h.
  319. *
  320. * @ipd_port: Port to configure. This follows the IPD numbering, not the
  321. * per interface numbering
  322. *
  323. * Returns Zero on success, negative on failure
  324. */
  325. static int __cvmx_helper_port_setup_ipd(int ipd_port)
  326. {
  327. union cvmx_pip_prt_cfgx port_config;
  328. union cvmx_pip_prt_tagx tag_config;
  329. port_config.u64 = cvmx_read_csr(CVMX_PIP_PRT_CFGX(ipd_port));
  330. tag_config.u64 = cvmx_read_csr(CVMX_PIP_PRT_TAGX(ipd_port));
  331. /* Have each port go to a different POW queue */
  332. port_config.s.qos = ipd_port & 0x7;
  333. /* Process the headers and place the IP header in the work queue */
  334. port_config.s.mode = CVMX_HELPER_INPUT_PORT_SKIP_MODE;
  335. tag_config.s.ip6_src_flag = CVMX_HELPER_INPUT_TAG_IPV6_SRC_IP;
  336. tag_config.s.ip6_dst_flag = CVMX_HELPER_INPUT_TAG_IPV6_DST_IP;
  337. tag_config.s.ip6_sprt_flag = CVMX_HELPER_INPUT_TAG_IPV6_SRC_PORT;
  338. tag_config.s.ip6_dprt_flag = CVMX_HELPER_INPUT_TAG_IPV6_DST_PORT;
  339. tag_config.s.ip6_nxth_flag = CVMX_HELPER_INPUT_TAG_IPV6_NEXT_HEADER;
  340. tag_config.s.ip4_src_flag = CVMX_HELPER_INPUT_TAG_IPV4_SRC_IP;
  341. tag_config.s.ip4_dst_flag = CVMX_HELPER_INPUT_TAG_IPV4_DST_IP;
  342. tag_config.s.ip4_sprt_flag = CVMX_HELPER_INPUT_TAG_IPV4_SRC_PORT;
  343. tag_config.s.ip4_dprt_flag = CVMX_HELPER_INPUT_TAG_IPV4_DST_PORT;
  344. tag_config.s.ip4_pctl_flag = CVMX_HELPER_INPUT_TAG_IPV4_PROTOCOL;
  345. tag_config.s.inc_prt_flag = CVMX_HELPER_INPUT_TAG_INPUT_PORT;
  346. tag_config.s.tcp6_tag_type = CVMX_HELPER_INPUT_TAG_TYPE;
  347. tag_config.s.tcp4_tag_type = CVMX_HELPER_INPUT_TAG_TYPE;
  348. tag_config.s.ip6_tag_type = CVMX_HELPER_INPUT_TAG_TYPE;
  349. tag_config.s.ip4_tag_type = CVMX_HELPER_INPUT_TAG_TYPE;
  350. tag_config.s.non_tag_type = CVMX_HELPER_INPUT_TAG_TYPE;
  351. /* Put all packets in group 0. Other groups can be used by the app */
  352. tag_config.s.grp = 0;
  353. cvmx_pip_config_port(ipd_port, port_config, tag_config);
  354. /* Give the user a chance to override our setting for each port */
  355. if (cvmx_override_ipd_port_setup)
  356. cvmx_override_ipd_port_setup(ipd_port);
  357. return 0;
  358. }
  359. /**
  360. * This function sets the interface_port_count[interface] correctly,
  361. * without modifying any hardware configuration. Hardware setup of
  362. * the ports will be performed later.
  363. *
  364. * @interface: Interface to probe
  365. *
  366. * Returns Zero on success, negative on failure
  367. */
  368. int cvmx_helper_interface_enumerate(int interface)
  369. {
  370. switch (cvmx_helper_interface_get_mode(interface)) {
  371. /* These types don't support ports to IPD/PKO */
  372. case CVMX_HELPER_INTERFACE_MODE_DISABLED:
  373. case CVMX_HELPER_INTERFACE_MODE_PCIE:
  374. interface_port_count[interface] = 0;
  375. break;
  376. /* XAUI is a single high speed port */
  377. case CVMX_HELPER_INTERFACE_MODE_XAUI:
  378. interface_port_count[interface] =
  379. __cvmx_helper_xaui_enumerate(interface);
  380. break;
  381. /*
  382. * RGMII/GMII/MII are all treated about the same. Most
  383. * functions refer to these ports as RGMII.
  384. */
  385. case CVMX_HELPER_INTERFACE_MODE_RGMII:
  386. case CVMX_HELPER_INTERFACE_MODE_GMII:
  387. interface_port_count[interface] =
  388. __cvmx_helper_rgmii_enumerate(interface);
  389. break;
  390. /*
  391. * SPI4 can have 1-16 ports depending on the device at
  392. * the other end.
  393. */
  394. case CVMX_HELPER_INTERFACE_MODE_SPI:
  395. interface_port_count[interface] =
  396. __cvmx_helper_spi_enumerate(interface);
  397. break;
  398. /*
  399. * SGMII can have 1-4 ports depending on how many are
  400. * hooked up.
  401. */
  402. case CVMX_HELPER_INTERFACE_MODE_SGMII:
  403. case CVMX_HELPER_INTERFACE_MODE_PICMG:
  404. interface_port_count[interface] =
  405. __cvmx_helper_sgmii_enumerate(interface);
  406. break;
  407. /* PCI target Network Packet Interface */
  408. case CVMX_HELPER_INTERFACE_MODE_NPI:
  409. interface_port_count[interface] =
  410. __cvmx_helper_npi_enumerate(interface);
  411. break;
  412. /*
  413. * Special loopback only ports. These are not the same
  414. * as other ports in loopback mode.
  415. */
  416. case CVMX_HELPER_INTERFACE_MODE_LOOP:
  417. interface_port_count[interface] =
  418. __cvmx_helper_loop_enumerate(interface);
  419. break;
  420. }
  421. interface_port_count[interface] =
  422. __cvmx_helper_board_interface_probe(interface,
  423. interface_port_count
  424. [interface]);
  425. /* Make sure all global variables propagate to other cores */
  426. CVMX_SYNCWS;
  427. return 0;
  428. }
  429. /**
  430. * This function probes an interface to determine the actual
  431. * number of hardware ports connected to it. It doesn't setup the
  432. * ports or enable them. The main goal here is to set the global
  433. * interface_port_count[interface] correctly. Hardware setup of the
  434. * ports will be performed later.
  435. *
  436. * @interface: Interface to probe
  437. *
  438. * Returns Zero on success, negative on failure
  439. */
  440. int cvmx_helper_interface_probe(int interface)
  441. {
  442. cvmx_helper_interface_enumerate(interface);
  443. /* At this stage in the game we don't want packets to be moving yet.
  444. The following probe calls should perform hardware setup
  445. needed to determine port counts. Receive must still be disabled */
  446. switch (cvmx_helper_interface_get_mode(interface)) {
  447. /* These types don't support ports to IPD/PKO */
  448. case CVMX_HELPER_INTERFACE_MODE_DISABLED:
  449. case CVMX_HELPER_INTERFACE_MODE_PCIE:
  450. break;
  451. /* XAUI is a single high speed port */
  452. case CVMX_HELPER_INTERFACE_MODE_XAUI:
  453. __cvmx_helper_xaui_probe(interface);
  454. break;
  455. /*
  456. * RGMII/GMII/MII are all treated about the same. Most
  457. * functions refer to these ports as RGMII.
  458. */
  459. case CVMX_HELPER_INTERFACE_MODE_RGMII:
  460. case CVMX_HELPER_INTERFACE_MODE_GMII:
  461. __cvmx_helper_rgmii_probe(interface);
  462. break;
  463. /*
  464. * SPI4 can have 1-16 ports depending on the device at
  465. * the other end.
  466. */
  467. case CVMX_HELPER_INTERFACE_MODE_SPI:
  468. __cvmx_helper_spi_probe(interface);
  469. break;
  470. /*
  471. * SGMII can have 1-4 ports depending on how many are
  472. * hooked up.
  473. */
  474. case CVMX_HELPER_INTERFACE_MODE_SGMII:
  475. case CVMX_HELPER_INTERFACE_MODE_PICMG:
  476. __cvmx_helper_sgmii_probe(interface);
  477. break;
  478. /* PCI target Network Packet Interface */
  479. case CVMX_HELPER_INTERFACE_MODE_NPI:
  480. __cvmx_helper_npi_probe(interface);
  481. break;
  482. /*
  483. * Special loopback only ports. These are not the same
  484. * as other ports in loopback mode.
  485. */
  486. case CVMX_HELPER_INTERFACE_MODE_LOOP:
  487. __cvmx_helper_loop_probe(interface);
  488. break;
  489. }
  490. /* Make sure all global variables propagate to other cores */
  491. CVMX_SYNCWS;
  492. return 0;
  493. }
  494. /**
  495. * Setup the IPD/PIP for the ports on an interface. Packet
  496. * classification and tagging are set for every port on the
  497. * interface. The number of ports on the interface must already
  498. * have been probed.
  499. *
  500. * @interface: Interface to setup IPD/PIP for
  501. *
  502. * Returns Zero on success, negative on failure
  503. */
  504. static int __cvmx_helper_interface_setup_ipd(int interface)
  505. {
  506. int ipd_port = cvmx_helper_get_ipd_port(interface, 0);
  507. int num_ports = interface_port_count[interface];
  508. while (num_ports--) {
  509. __cvmx_helper_port_setup_ipd(ipd_port);
  510. ipd_port++;
  511. }
  512. return 0;
  513. }
  514. /**
  515. * Setup global setting for IPD/PIP not related to a specific
  516. * interface or port. This must be called before IPD is enabled.
  517. *
  518. * Returns Zero on success, negative on failure.
  519. */
  520. static int __cvmx_helper_global_setup_ipd(void)
  521. {
  522. /* Setup the global packet input options */
  523. cvmx_ipd_config(CVMX_FPA_PACKET_POOL_SIZE / 8,
  524. CVMX_HELPER_FIRST_MBUFF_SKIP / 8,
  525. CVMX_HELPER_NOT_FIRST_MBUFF_SKIP / 8,
  526. /* The +8 is to account for the next ptr */
  527. (CVMX_HELPER_FIRST_MBUFF_SKIP + 8) / 128,
  528. /* The +8 is to account for the next ptr */
  529. (CVMX_HELPER_NOT_FIRST_MBUFF_SKIP + 8) / 128,
  530. CVMX_FPA_WQE_POOL,
  531. CVMX_IPD_OPC_MODE_STT,
  532. CVMX_HELPER_ENABLE_BACK_PRESSURE);
  533. return 0;
  534. }
  535. /**
  536. * Setup the PKO for the ports on an interface. The number of
  537. * queues per port and the priority of each PKO output queue
  538. * is set here. PKO must be disabled when this function is called.
  539. *
  540. * @interface: Interface to setup PKO for
  541. *
  542. * Returns Zero on success, negative on failure
  543. */
  544. static int __cvmx_helper_interface_setup_pko(int interface)
  545. {
  546. /*
  547. * Each packet output queue has an associated priority. The
  548. * higher the priority, the more often it can send a packet. A
  549. * priority of 8 means it can send in all 8 rounds of
  550. * contention. We're going to make each queue one less than
  551. * the last. The vector of priorities has been extended to
  552. * support CN5xxx CPUs, where up to 16 queues can be
  553. * associated to a port. To keep backward compatibility we
  554. * don't change the initial 8 priorities and replicate them in
  555. * the second half. With per-core PKO queues (PKO lockless
  556. * operation) all queues have the same priority.
  557. */
  558. uint64_t priorities[16] =
  559. { 8, 7, 6, 5, 4, 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, 1 };
  560. /*
  561. * Setup the IPD/PIP and PKO for the ports discovered
  562. * above. Here packet classification, tagging and output
  563. * priorities are set.
  564. */
  565. int ipd_port = cvmx_helper_get_ipd_port(interface, 0);
  566. int num_ports = interface_port_count[interface];
  567. while (num_ports--) {
  568. /*
  569. * Give the user a chance to override the per queue
  570. * priorities.
  571. */
  572. if (cvmx_override_pko_queue_priority)
  573. cvmx_override_pko_queue_priority(ipd_port, priorities);
  574. cvmx_pko_config_port(ipd_port,
  575. cvmx_pko_get_base_queue_per_core(ipd_port,
  576. 0),
  577. cvmx_pko_get_num_queues(ipd_port),
  578. priorities);
  579. ipd_port++;
  580. }
  581. return 0;
  582. }
  583. /**
  584. * Setup global setting for PKO not related to a specific
  585. * interface or port. This must be called before PKO is enabled.
  586. *
  587. * Returns Zero on success, negative on failure.
  588. */
  589. static int __cvmx_helper_global_setup_pko(void)
  590. {
  591. /*
  592. * Disable tagwait FAU timeout. This needs to be done before
  593. * anyone might start packet output using tags.
  594. */
  595. union cvmx_iob_fau_timeout fau_to;
  596. fau_to.u64 = 0;
  597. fau_to.s.tout_val = 0xfff;
  598. fau_to.s.tout_enb = 0;
  599. cvmx_write_csr(CVMX_IOB_FAU_TIMEOUT, fau_to.u64);
  600. return 0;
  601. }
  602. /**
  603. * Setup global backpressure setting.
  604. *
  605. * Returns Zero on success, negative on failure
  606. */
  607. static int __cvmx_helper_global_setup_backpressure(void)
  608. {
  609. #if CVMX_HELPER_DISABLE_RGMII_BACKPRESSURE
  610. /* Disable backpressure if configured to do so */
  611. /* Disable backpressure (pause frame) generation */
  612. int num_interfaces = cvmx_helper_get_number_of_interfaces();
  613. int interface;
  614. for (interface = 0; interface < num_interfaces; interface++) {
  615. switch (cvmx_helper_interface_get_mode(interface)) {
  616. case CVMX_HELPER_INTERFACE_MODE_DISABLED:
  617. case CVMX_HELPER_INTERFACE_MODE_PCIE:
  618. case CVMX_HELPER_INTERFACE_MODE_NPI:
  619. case CVMX_HELPER_INTERFACE_MODE_LOOP:
  620. case CVMX_HELPER_INTERFACE_MODE_XAUI:
  621. break;
  622. case CVMX_HELPER_INTERFACE_MODE_RGMII:
  623. case CVMX_HELPER_INTERFACE_MODE_GMII:
  624. case CVMX_HELPER_INTERFACE_MODE_SPI:
  625. case CVMX_HELPER_INTERFACE_MODE_SGMII:
  626. case CVMX_HELPER_INTERFACE_MODE_PICMG:
  627. cvmx_gmx_set_backpressure_override(interface, 0xf);
  628. break;
  629. }
  630. }
  631. #endif
  632. return 0;
  633. }
  634. /**
  635. * Enable packet input/output from the hardware. This function is
  636. * called after all internal setup is complete and IPD is enabled.
  637. * After this function completes, packets will be accepted from the
  638. * hardware ports. PKO should still be disabled to make sure packets
  639. * aren't sent out partially setup hardware.
  640. *
  641. * @interface: Interface to enable
  642. *
  643. * Returns Zero on success, negative on failure
  644. */
  645. static int __cvmx_helper_packet_hardware_enable(int interface)
  646. {
  647. int result = 0;
  648. switch (cvmx_helper_interface_get_mode(interface)) {
  649. /* These types don't support ports to IPD/PKO */
  650. case CVMX_HELPER_INTERFACE_MODE_DISABLED:
  651. case CVMX_HELPER_INTERFACE_MODE_PCIE:
  652. /* Nothing to do */
  653. break;
  654. /* XAUI is a single high speed port */
  655. case CVMX_HELPER_INTERFACE_MODE_XAUI:
  656. result = __cvmx_helper_xaui_enable(interface);
  657. break;
  658. /*
  659. * RGMII/GMII/MII are all treated about the same. Most
  660. * functions refer to these ports as RGMII
  661. */
  662. case CVMX_HELPER_INTERFACE_MODE_RGMII:
  663. case CVMX_HELPER_INTERFACE_MODE_GMII:
  664. result = __cvmx_helper_rgmii_enable(interface);
  665. break;
  666. /*
  667. * SPI4 can have 1-16 ports depending on the device at
  668. * the other end
  669. */
  670. case CVMX_HELPER_INTERFACE_MODE_SPI:
  671. result = __cvmx_helper_spi_enable(interface);
  672. break;
  673. /*
  674. * SGMII can have 1-4 ports depending on how many are
  675. * hooked up
  676. */
  677. case CVMX_HELPER_INTERFACE_MODE_SGMII:
  678. case CVMX_HELPER_INTERFACE_MODE_PICMG:
  679. result = __cvmx_helper_sgmii_enable(interface);
  680. break;
  681. /* PCI target Network Packet Interface */
  682. case CVMX_HELPER_INTERFACE_MODE_NPI:
  683. result = __cvmx_helper_npi_enable(interface);
  684. break;
  685. /*
  686. * Special loopback only ports. These are not the same
  687. * as other ports in loopback mode
  688. */
  689. case CVMX_HELPER_INTERFACE_MODE_LOOP:
  690. result = __cvmx_helper_loop_enable(interface);
  691. break;
  692. }
  693. result |= __cvmx_helper_board_hardware_enable(interface);
  694. return result;
  695. }
  696. /**
  697. * Function to adjust internal IPD pointer alignments
  698. *
  699. * Returns 0 on success
  700. * !0 on failure
  701. */
  702. int __cvmx_helper_errata_fix_ipd_ptr_alignment(void)
  703. {
  704. #define FIX_IPD_FIRST_BUFF_PAYLOAD_BYTES \
  705. (CVMX_FPA_PACKET_POOL_SIZE-8-CVMX_HELPER_FIRST_MBUFF_SKIP)
  706. #define FIX_IPD_NON_FIRST_BUFF_PAYLOAD_BYTES \
  707. (CVMX_FPA_PACKET_POOL_SIZE-8-CVMX_HELPER_NOT_FIRST_MBUFF_SKIP)
  708. #define FIX_IPD_OUTPORT 0
  709. /* Ports 0-15 are interface 0, 16-31 are interface 1 */
  710. #define INTERFACE(port) (port >> 4)
  711. #define INDEX(port) (port & 0xf)
  712. uint64_t *p64;
  713. cvmx_pko_command_word0_t pko_command;
  714. union cvmx_buf_ptr g_buffer, pkt_buffer;
  715. cvmx_wqe_t *work;
  716. int size, num_segs = 0, wqe_pcnt, pkt_pcnt;
  717. union cvmx_gmxx_prtx_cfg gmx_cfg;
  718. int retry_cnt;
  719. int retry_loop_cnt;
  720. int i;
  721. cvmx_helper_link_info_t link_info;
  722. /* Save values for restore at end */
  723. uint64_t prtx_cfg =
  724. cvmx_read_csr(CVMX_GMXX_PRTX_CFG
  725. (INDEX(FIX_IPD_OUTPORT), INTERFACE(FIX_IPD_OUTPORT)));
  726. uint64_t tx_ptr_en =
  727. cvmx_read_csr(CVMX_ASXX_TX_PRT_EN(INTERFACE(FIX_IPD_OUTPORT)));
  728. uint64_t rx_ptr_en =
  729. cvmx_read_csr(CVMX_ASXX_RX_PRT_EN(INTERFACE(FIX_IPD_OUTPORT)));
  730. uint64_t rxx_jabber =
  731. cvmx_read_csr(CVMX_GMXX_RXX_JABBER
  732. (INDEX(FIX_IPD_OUTPORT), INTERFACE(FIX_IPD_OUTPORT)));
  733. uint64_t frame_max =
  734. cvmx_read_csr(CVMX_GMXX_RXX_FRM_MAX
  735. (INDEX(FIX_IPD_OUTPORT), INTERFACE(FIX_IPD_OUTPORT)));
  736. /* Configure port to gig FDX as required for loopback mode */
  737. cvmx_helper_rgmii_internal_loopback(FIX_IPD_OUTPORT);
  738. /*
  739. * Disable reception on all ports so if traffic is present it
  740. * will not interfere.
  741. */
  742. cvmx_write_csr(CVMX_ASXX_RX_PRT_EN(INTERFACE(FIX_IPD_OUTPORT)), 0);
  743. cvmx_wait(100000000ull);
  744. for (retry_loop_cnt = 0; retry_loop_cnt < 10; retry_loop_cnt++) {
  745. retry_cnt = 100000;
  746. wqe_pcnt = cvmx_read_csr(CVMX_IPD_PTR_COUNT);
  747. pkt_pcnt = (wqe_pcnt >> 7) & 0x7f;
  748. wqe_pcnt &= 0x7f;
  749. num_segs = (2 + pkt_pcnt - wqe_pcnt) & 3;
  750. if (num_segs == 0)
  751. goto fix_ipd_exit;
  752. num_segs += 1;
  753. size =
  754. FIX_IPD_FIRST_BUFF_PAYLOAD_BYTES +
  755. ((num_segs - 1) * FIX_IPD_NON_FIRST_BUFF_PAYLOAD_BYTES) -
  756. (FIX_IPD_NON_FIRST_BUFF_PAYLOAD_BYTES / 2);
  757. cvmx_write_csr(CVMX_ASXX_PRT_LOOP(INTERFACE(FIX_IPD_OUTPORT)),
  758. 1 << INDEX(FIX_IPD_OUTPORT));
  759. CVMX_SYNC;
  760. g_buffer.u64 = 0;
  761. g_buffer.s.addr =
  762. cvmx_ptr_to_phys(cvmx_fpa_alloc(CVMX_FPA_WQE_POOL));
  763. if (g_buffer.s.addr == 0) {
  764. cvmx_dprintf("WARNING: FIX_IPD_PTR_ALIGNMENT "
  765. "buffer allocation failure.\n");
  766. goto fix_ipd_exit;
  767. }
  768. g_buffer.s.pool = CVMX_FPA_WQE_POOL;
  769. g_buffer.s.size = num_segs;
  770. pkt_buffer.u64 = 0;
  771. pkt_buffer.s.addr =
  772. cvmx_ptr_to_phys(cvmx_fpa_alloc(CVMX_FPA_PACKET_POOL));
  773. if (pkt_buffer.s.addr == 0) {
  774. cvmx_dprintf("WARNING: FIX_IPD_PTR_ALIGNMENT "
  775. "buffer allocation failure.\n");
  776. goto fix_ipd_exit;
  777. }
  778. pkt_buffer.s.i = 1;
  779. pkt_buffer.s.pool = CVMX_FPA_PACKET_POOL;
  780. pkt_buffer.s.size = FIX_IPD_FIRST_BUFF_PAYLOAD_BYTES;
  781. p64 = (uint64_t *) cvmx_phys_to_ptr(pkt_buffer.s.addr);
  782. p64[0] = 0xffffffffffff0000ull;
  783. p64[1] = 0x08004510ull;
  784. p64[2] = ((uint64_t) (size - 14) << 48) | 0x5ae740004000ull;
  785. p64[3] = 0x3a5fc0a81073c0a8ull;
  786. for (i = 0; i < num_segs; i++) {
  787. if (i > 0)
  788. pkt_buffer.s.size =
  789. FIX_IPD_NON_FIRST_BUFF_PAYLOAD_BYTES;
  790. if (i == (num_segs - 1))
  791. pkt_buffer.s.i = 0;
  792. *(uint64_t *) cvmx_phys_to_ptr(g_buffer.s.addr +
  793. 8 * i) = pkt_buffer.u64;
  794. }
  795. /* Build the PKO command */
  796. pko_command.u64 = 0;
  797. pko_command.s.segs = num_segs;
  798. pko_command.s.total_bytes = size;
  799. pko_command.s.dontfree = 0;
  800. pko_command.s.gather = 1;
  801. gmx_cfg.u64 =
  802. cvmx_read_csr(CVMX_GMXX_PRTX_CFG
  803. (INDEX(FIX_IPD_OUTPORT),
  804. INTERFACE(FIX_IPD_OUTPORT)));
  805. gmx_cfg.s.en = 1;
  806. cvmx_write_csr(CVMX_GMXX_PRTX_CFG
  807. (INDEX(FIX_IPD_OUTPORT),
  808. INTERFACE(FIX_IPD_OUTPORT)), gmx_cfg.u64);
  809. cvmx_write_csr(CVMX_ASXX_TX_PRT_EN(INTERFACE(FIX_IPD_OUTPORT)),
  810. 1 << INDEX(FIX_IPD_OUTPORT));
  811. cvmx_write_csr(CVMX_ASXX_RX_PRT_EN(INTERFACE(FIX_IPD_OUTPORT)),
  812. 1 << INDEX(FIX_IPD_OUTPORT));
  813. cvmx_write_csr(CVMX_GMXX_RXX_JABBER
  814. (INDEX(FIX_IPD_OUTPORT),
  815. INTERFACE(FIX_IPD_OUTPORT)), 65392 - 14 - 4);
  816. cvmx_write_csr(CVMX_GMXX_RXX_FRM_MAX
  817. (INDEX(FIX_IPD_OUTPORT),
  818. INTERFACE(FIX_IPD_OUTPORT)), 65392 - 14 - 4);
  819. cvmx_pko_send_packet_prepare(FIX_IPD_OUTPORT,
  820. cvmx_pko_get_base_queue
  821. (FIX_IPD_OUTPORT),
  822. CVMX_PKO_LOCK_CMD_QUEUE);
  823. cvmx_pko_send_packet_finish(FIX_IPD_OUTPORT,
  824. cvmx_pko_get_base_queue
  825. (FIX_IPD_OUTPORT), pko_command,
  826. g_buffer, CVMX_PKO_LOCK_CMD_QUEUE);
  827. CVMX_SYNC;
  828. do {
  829. work = cvmx_pow_work_request_sync(CVMX_POW_WAIT);
  830. retry_cnt--;
  831. } while ((work == NULL) && (retry_cnt > 0));
  832. if (!retry_cnt)
  833. cvmx_dprintf("WARNING: FIX_IPD_PTR_ALIGNMENT "
  834. "get_work() timeout occurred.\n");
  835. /* Free packet */
  836. if (work)
  837. cvmx_helper_free_packet_data(work);
  838. }
  839. fix_ipd_exit:
  840. /* Return CSR configs to saved values */
  841. cvmx_write_csr(CVMX_GMXX_PRTX_CFG
  842. (INDEX(FIX_IPD_OUTPORT), INTERFACE(FIX_IPD_OUTPORT)),
  843. prtx_cfg);
  844. cvmx_write_csr(CVMX_ASXX_TX_PRT_EN(INTERFACE(FIX_IPD_OUTPORT)),
  845. tx_ptr_en);
  846. cvmx_write_csr(CVMX_ASXX_RX_PRT_EN(INTERFACE(FIX_IPD_OUTPORT)),
  847. rx_ptr_en);
  848. cvmx_write_csr(CVMX_GMXX_RXX_JABBER
  849. (INDEX(FIX_IPD_OUTPORT), INTERFACE(FIX_IPD_OUTPORT)),
  850. rxx_jabber);
  851. cvmx_write_csr(CVMX_GMXX_RXX_FRM_MAX
  852. (INDEX(FIX_IPD_OUTPORT), INTERFACE(FIX_IPD_OUTPORT)),
  853. frame_max);
  854. cvmx_write_csr(CVMX_ASXX_PRT_LOOP(INTERFACE(FIX_IPD_OUTPORT)), 0);
  855. /* Set link to down so autonegotiation will set it up again */
  856. link_info.u64 = 0;
  857. cvmx_helper_link_set(FIX_IPD_OUTPORT, link_info);
  858. /*
  859. * Bring the link back up as autonegotiation is not done in
  860. * user applications.
  861. */
  862. cvmx_helper_link_autoconf(FIX_IPD_OUTPORT);
  863. CVMX_SYNC;
  864. if (num_segs)
  865. cvmx_dprintf("WARNING: FIX_IPD_PTR_ALIGNMENT failed.\n");
  866. return !!num_segs;
  867. }
  868. /**
  869. * Called after all internal packet IO paths are setup. This
  870. * function enables IPD/PIP and begins packet input and output.
  871. *
  872. * Returns Zero on success, negative on failure
  873. */
  874. int cvmx_helper_ipd_and_packet_input_enable(void)
  875. {
  876. int num_interfaces;
  877. int interface;
  878. /* Enable IPD */
  879. cvmx_ipd_enable();
  880. /*
  881. * Time to enable hardware ports packet input and output. Note
  882. * that at this point IPD/PIP must be fully functional and PKO
  883. * must be disabled
  884. */
  885. num_interfaces = cvmx_helper_get_number_of_interfaces();
  886. for (interface = 0; interface < num_interfaces; interface++) {
  887. if (cvmx_helper_ports_on_interface(interface) > 0)
  888. __cvmx_helper_packet_hardware_enable(interface);
  889. }
  890. /* Finally enable PKO now that the entire path is up and running */
  891. cvmx_pko_enable();
  892. if ((OCTEON_IS_MODEL(OCTEON_CN31XX_PASS1)
  893. || OCTEON_IS_MODEL(OCTEON_CN30XX_PASS1))
  894. && (cvmx_sysinfo_get()->board_type != CVMX_BOARD_TYPE_SIM))
  895. __cvmx_helper_errata_fix_ipd_ptr_alignment();
  896. return 0;
  897. }
  898. EXPORT_SYMBOL_GPL(cvmx_helper_ipd_and_packet_input_enable);
  899. /**
  900. * Initialize the PIP, IPD, and PKO hardware to support
  901. * simple priority based queues for the ethernet ports. Each
  902. * port is configured with a number of priority queues based
  903. * on CVMX_PKO_QUEUES_PER_PORT_* where each queue is lower
  904. * priority than the previous.
  905. *
  906. * Returns Zero on success, non-zero on failure
  907. */
  908. int cvmx_helper_initialize_packet_io_global(void)
  909. {
  910. int result = 0;
  911. int interface;
  912. union cvmx_l2c_cfg l2c_cfg;
  913. union cvmx_smix_en smix_en;
  914. const int num_interfaces = cvmx_helper_get_number_of_interfaces();
  915. /*
  916. * CN52XX pass 1: Due to a bug in 2nd order CDR, it needs to
  917. * be disabled.
  918. */
  919. if (OCTEON_IS_MODEL(OCTEON_CN52XX_PASS1_0))
  920. __cvmx_helper_errata_qlm_disable_2nd_order_cdr(1);
  921. /*
  922. * Tell L2 to give the IOB statically higher priority compared
  923. * to the cores. This avoids conditions where IO blocks might
  924. * be starved under very high L2 loads.
  925. */
  926. l2c_cfg.u64 = cvmx_read_csr(CVMX_L2C_CFG);
  927. l2c_cfg.s.lrf_arb_mode = 0;
  928. l2c_cfg.s.rfb_arb_mode = 0;
  929. cvmx_write_csr(CVMX_L2C_CFG, l2c_cfg.u64);
  930. /* Make sure SMI/MDIO is enabled so we can query PHYs */
  931. smix_en.u64 = cvmx_read_csr(CVMX_SMIX_EN(0));
  932. if (!smix_en.s.en) {
  933. smix_en.s.en = 1;
  934. cvmx_write_csr(CVMX_SMIX_EN(0), smix_en.u64);
  935. }
  936. /* Newer chips actually have two SMI/MDIO interfaces */
  937. if (!OCTEON_IS_MODEL(OCTEON_CN3XXX) &&
  938. !OCTEON_IS_MODEL(OCTEON_CN58XX) &&
  939. !OCTEON_IS_MODEL(OCTEON_CN50XX)) {
  940. smix_en.u64 = cvmx_read_csr(CVMX_SMIX_EN(1));
  941. if (!smix_en.s.en) {
  942. smix_en.s.en = 1;
  943. cvmx_write_csr(CVMX_SMIX_EN(1), smix_en.u64);
  944. }
  945. }
  946. cvmx_pko_initialize_global();
  947. for (interface = 0; interface < num_interfaces; interface++) {
  948. result |= cvmx_helper_interface_probe(interface);
  949. if (cvmx_helper_ports_on_interface(interface) > 0)
  950. cvmx_dprintf("Interface %d has %d ports (%s)\n",
  951. interface,
  952. cvmx_helper_ports_on_interface(interface),
  953. cvmx_helper_interface_mode_to_string
  954. (cvmx_helper_interface_get_mode
  955. (interface)));
  956. result |= __cvmx_helper_interface_setup_ipd(interface);
  957. result |= __cvmx_helper_interface_setup_pko(interface);
  958. }
  959. result |= __cvmx_helper_global_setup_ipd();
  960. result |= __cvmx_helper_global_setup_pko();
  961. /* Enable any flow control and backpressure */
  962. result |= __cvmx_helper_global_setup_backpressure();
  963. #if CVMX_HELPER_ENABLE_IPD
  964. result |= cvmx_helper_ipd_and_packet_input_enable();
  965. #endif
  966. return result;
  967. }
  968. EXPORT_SYMBOL_GPL(cvmx_helper_initialize_packet_io_global);
  969. /**
  970. * Does core local initialization for packet io
  971. *
  972. * Returns Zero on success, non-zero on failure
  973. */
  974. int cvmx_helper_initialize_packet_io_local(void)
  975. {
  976. return cvmx_pko_initialize_local();
  977. }
  978. /**
  979. * Auto configure an IPD/PKO port link state and speed. This
  980. * function basically does the equivalent of:
  981. * cvmx_helper_link_set(ipd_port, cvmx_helper_link_get(ipd_port));
  982. *
  983. * @ipd_port: IPD/PKO port to auto configure
  984. *
  985. * Returns Link state after configure
  986. */
  987. cvmx_helper_link_info_t cvmx_helper_link_autoconf(int ipd_port)
  988. {
  989. cvmx_helper_link_info_t link_info;
  990. int interface = cvmx_helper_get_interface_num(ipd_port);
  991. int index = cvmx_helper_get_interface_index_num(ipd_port);
  992. if (index >= cvmx_helper_ports_on_interface(interface)) {
  993. link_info.u64 = 0;
  994. return link_info;
  995. }
  996. link_info = cvmx_helper_link_get(ipd_port);
  997. if (link_info.u64 == port_link_info[ipd_port].u64)
  998. return link_info;
  999. /* If we fail to set the link speed, port_link_info will not change */
  1000. cvmx_helper_link_set(ipd_port, link_info);
  1001. /*
  1002. * port_link_info should be the current value, which will be
  1003. * different than expect if cvmx_helper_link_set() failed.
  1004. */
  1005. return port_link_info[ipd_port];
  1006. }
  1007. EXPORT_SYMBOL_GPL(cvmx_helper_link_autoconf);
  1008. /**
  1009. * Return the link state of an IPD/PKO port as returned by
  1010. * auto negotiation. The result of this function may not match
  1011. * Octeon's link config if auto negotiation has changed since
  1012. * the last call to cvmx_helper_link_set().
  1013. *
  1014. * @ipd_port: IPD/PKO port to query
  1015. *
  1016. * Returns Link state
  1017. */
  1018. cvmx_helper_link_info_t cvmx_helper_link_get(int ipd_port)
  1019. {
  1020. cvmx_helper_link_info_t result;
  1021. int interface = cvmx_helper_get_interface_num(ipd_port);
  1022. int index = cvmx_helper_get_interface_index_num(ipd_port);
  1023. /* The default result will be a down link unless the code below
  1024. changes it */
  1025. result.u64 = 0;
  1026. if (index >= cvmx_helper_ports_on_interface(interface))
  1027. return result;
  1028. switch (cvmx_helper_interface_get_mode(interface)) {
  1029. case CVMX_HELPER_INTERFACE_MODE_DISABLED:
  1030. case CVMX_HELPER_INTERFACE_MODE_PCIE:
  1031. /* Network links are not supported */
  1032. break;
  1033. case CVMX_HELPER_INTERFACE_MODE_XAUI:
  1034. result = __cvmx_helper_xaui_link_get(ipd_port);
  1035. break;
  1036. case CVMX_HELPER_INTERFACE_MODE_GMII:
  1037. if (index == 0)
  1038. result = __cvmx_helper_rgmii_link_get(ipd_port);
  1039. else {
  1040. result.s.full_duplex = 1;
  1041. result.s.link_up = 1;
  1042. result.s.speed = 1000;
  1043. }
  1044. break;
  1045. case CVMX_HELPER_INTERFACE_MODE_RGMII:
  1046. result = __cvmx_helper_rgmii_link_get(ipd_port);
  1047. break;
  1048. case CVMX_HELPER_INTERFACE_MODE_SPI:
  1049. result = __cvmx_helper_spi_link_get(ipd_port);
  1050. break;
  1051. case CVMX_HELPER_INTERFACE_MODE_SGMII:
  1052. case CVMX_HELPER_INTERFACE_MODE_PICMG:
  1053. result = __cvmx_helper_sgmii_link_get(ipd_port);
  1054. break;
  1055. case CVMX_HELPER_INTERFACE_MODE_NPI:
  1056. case CVMX_HELPER_INTERFACE_MODE_LOOP:
  1057. /* Network links are not supported */
  1058. break;
  1059. }
  1060. return result;
  1061. }
  1062. EXPORT_SYMBOL_GPL(cvmx_helper_link_get);
  1063. /**
  1064. * Configure an IPD/PKO port for the specified link state. This
  1065. * function does not influence auto negotiation at the PHY level.
  1066. * The passed link state must always match the link state returned
  1067. * by cvmx_helper_link_get(). It is normally best to use
  1068. * cvmx_helper_link_autoconf() instead.
  1069. *
  1070. * @ipd_port: IPD/PKO port to configure
  1071. * @link_info: The new link state
  1072. *
  1073. * Returns Zero on success, negative on failure
  1074. */
  1075. int cvmx_helper_link_set(int ipd_port, cvmx_helper_link_info_t link_info)
  1076. {
  1077. int result = -1;
  1078. int interface = cvmx_helper_get_interface_num(ipd_port);
  1079. int index = cvmx_helper_get_interface_index_num(ipd_port);
  1080. if (index >= cvmx_helper_ports_on_interface(interface))
  1081. return -1;
  1082. switch (cvmx_helper_interface_get_mode(interface)) {
  1083. case CVMX_HELPER_INTERFACE_MODE_DISABLED:
  1084. case CVMX_HELPER_INTERFACE_MODE_PCIE:
  1085. break;
  1086. case CVMX_HELPER_INTERFACE_MODE_XAUI:
  1087. result = __cvmx_helper_xaui_link_set(ipd_port, link_info);
  1088. break;
  1089. /*
  1090. * RGMII/GMII/MII are all treated about the same. Most
  1091. * functions refer to these ports as RGMII.
  1092. */
  1093. case CVMX_HELPER_INTERFACE_MODE_RGMII:
  1094. case CVMX_HELPER_INTERFACE_MODE_GMII:
  1095. result = __cvmx_helper_rgmii_link_set(ipd_port, link_info);
  1096. break;
  1097. case CVMX_HELPER_INTERFACE_MODE_SPI:
  1098. result = __cvmx_helper_spi_link_set(ipd_port, link_info);
  1099. break;
  1100. case CVMX_HELPER_INTERFACE_MODE_SGMII:
  1101. case CVMX_HELPER_INTERFACE_MODE_PICMG:
  1102. result = __cvmx_helper_sgmii_link_set(ipd_port, link_info);
  1103. break;
  1104. case CVMX_HELPER_INTERFACE_MODE_NPI:
  1105. case CVMX_HELPER_INTERFACE_MODE_LOOP:
  1106. break;
  1107. }
  1108. /* Set the port_link_info here so that the link status is updated
  1109. no matter how cvmx_helper_link_set is called. We don't change
  1110. the value if link_set failed */
  1111. if (result == 0)
  1112. port_link_info[ipd_port].u64 = link_info.u64;
  1113. return result;
  1114. }
  1115. EXPORT_SYMBOL_GPL(cvmx_helper_link_set);
  1116. /**
  1117. * Configure a port for internal and/or external loopback. Internal loopback
  1118. * causes packets sent by the port to be received by Octeon. External loopback
  1119. * causes packets received from the wire to sent out again.
  1120. *
  1121. * @ipd_port: IPD/PKO port to loopback.
  1122. * @enable_internal:
  1123. * Non zero if you want internal loopback
  1124. * @enable_external:
  1125. * Non zero if you want external loopback
  1126. *
  1127. * Returns Zero on success, negative on failure.
  1128. */
  1129. int cvmx_helper_configure_loopback(int ipd_port, int enable_internal,
  1130. int enable_external)
  1131. {
  1132. int result = -1;
  1133. int interface = cvmx_helper_get_interface_num(ipd_port);
  1134. int index = cvmx_helper_get_interface_index_num(ipd_port);
  1135. if (index >= cvmx_helper_ports_on_interface(interface))
  1136. return -1;
  1137. switch (cvmx_helper_interface_get_mode(interface)) {
  1138. case CVMX_HELPER_INTERFACE_MODE_DISABLED:
  1139. case CVMX_HELPER_INTERFACE_MODE_PCIE:
  1140. case CVMX_HELPER_INTERFACE_MODE_SPI:
  1141. case CVMX_HELPER_INTERFACE_MODE_NPI:
  1142. case CVMX_HELPER_INTERFACE_MODE_LOOP:
  1143. break;
  1144. case CVMX_HELPER_INTERFACE_MODE_XAUI:
  1145. result =
  1146. __cvmx_helper_xaui_configure_loopback(ipd_port,
  1147. enable_internal,
  1148. enable_external);
  1149. break;
  1150. case CVMX_HELPER_INTERFACE_MODE_RGMII:
  1151. case CVMX_HELPER_INTERFACE_MODE_GMII:
  1152. result =
  1153. __cvmx_helper_rgmii_configure_loopback(ipd_port,
  1154. enable_internal,
  1155. enable_external);
  1156. break;
  1157. case CVMX_HELPER_INTERFACE_MODE_SGMII:
  1158. case CVMX_HELPER_INTERFACE_MODE_PICMG:
  1159. result =
  1160. __cvmx_helper_sgmii_configure_loopback(ipd_port,
  1161. enable_internal,
  1162. enable_external);
  1163. break;
  1164. }
  1165. return result;
  1166. }