cvmx-helper.c 40 KB

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