ethernet-spi.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. /**********************************************************************
  2. * Author: Cavium Networks
  3. *
  4. * Contact: support@caviumnetworks.com
  5. * This file is part of the OCTEON SDK
  6. *
  7. * Copyright (c) 2003-2007 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. **********************************************************************/
  27. #include <linux/kernel.h>
  28. #include <linux/netdevice.h>
  29. #include <net/dst.h>
  30. #include <asm/octeon/octeon.h>
  31. #include "ethernet-defines.h"
  32. #include "octeon-ethernet.h"
  33. #include "ethernet-util.h"
  34. #include "cvmx-spi.h"
  35. #include <asm/octeon/cvmx-npi-defs.h>
  36. #include "cvmx-spxx-defs.h"
  37. #include "cvmx-stxx-defs.h"
  38. static int number_spi_ports;
  39. static int need_retrain[2] = { 0, 0 };
  40. static irqreturn_t cvm_oct_spi_rml_interrupt(int cpl, void *dev_id)
  41. {
  42. irqreturn_t return_status = IRQ_NONE;
  43. union cvmx_npi_rsl_int_blocks rsl_int_blocks;
  44. /* Check and see if this interrupt was caused by the GMX block */
  45. rsl_int_blocks.u64 = cvmx_read_csr(CVMX_NPI_RSL_INT_BLOCKS);
  46. if (rsl_int_blocks.s.spx1) { /* 19 - SPX1_INT_REG & STX1_INT_REG */
  47. union cvmx_spxx_int_reg spx_int_reg;
  48. union cvmx_stxx_int_reg stx_int_reg;
  49. spx_int_reg.u64 = cvmx_read_csr(CVMX_SPXX_INT_REG(1));
  50. cvmx_write_csr(CVMX_SPXX_INT_REG(1), spx_int_reg.u64);
  51. if (!need_retrain[1]) {
  52. spx_int_reg.u64 &= cvmx_read_csr(CVMX_SPXX_INT_MSK(1));
  53. if (spx_int_reg.s.spf)
  54. pr_err("SPI1: SRX Spi4 interface down\n");
  55. if (spx_int_reg.s.calerr)
  56. pr_err("SPI1: SRX Spi4 Calendar table "
  57. "parity error\n");
  58. if (spx_int_reg.s.syncerr)
  59. pr_err("SPI1: SRX Consecutive Spi4 DIP4 "
  60. "errors have exceeded "
  61. "SPX_ERR_CTL[ERRCNT]\n");
  62. if (spx_int_reg.s.diperr)
  63. pr_err("SPI1: SRX Spi4 DIP4 error\n");
  64. if (spx_int_reg.s.tpaovr)
  65. pr_err("SPI1: SRX Selected port has hit "
  66. "TPA overflow\n");
  67. if (spx_int_reg.s.rsverr)
  68. pr_err("SPI1: SRX Spi4 reserved control "
  69. "word detected\n");
  70. if (spx_int_reg.s.drwnng)
  71. pr_err("SPI1: SRX Spi4 receive FIFO "
  72. "drowning/overflow\n");
  73. if (spx_int_reg.s.clserr)
  74. pr_err("SPI1: SRX Spi4 packet closed on "
  75. "non-16B alignment without EOP\n");
  76. if (spx_int_reg.s.spiovr)
  77. pr_err("SPI1: SRX Spi4 async FIFO overflow\n");
  78. if (spx_int_reg.s.abnorm)
  79. pr_err("SPI1: SRX Abnormal packet "
  80. "termination (ERR bit)\n");
  81. if (spx_int_reg.s.prtnxa)
  82. pr_err("SPI1: SRX Port out of range\n");
  83. }
  84. stx_int_reg.u64 = cvmx_read_csr(CVMX_STXX_INT_REG(1));
  85. cvmx_write_csr(CVMX_STXX_INT_REG(1), stx_int_reg.u64);
  86. if (!need_retrain[1]) {
  87. stx_int_reg.u64 &= cvmx_read_csr(CVMX_STXX_INT_MSK(1));
  88. if (stx_int_reg.s.syncerr)
  89. pr_err("SPI1: STX Interface encountered a "
  90. "fatal error\n");
  91. if (stx_int_reg.s.frmerr)
  92. pr_err("SPI1: STX FRMCNT has exceeded "
  93. "STX_DIP_CNT[MAXFRM]\n");
  94. if (stx_int_reg.s.unxfrm)
  95. pr_err("SPI1: STX Unexpected framing "
  96. "sequence\n");
  97. if (stx_int_reg.s.nosync)
  98. pr_err("SPI1: STX ERRCNT has exceeded "
  99. "STX_DIP_CNT[MAXDIP]\n");
  100. if (stx_int_reg.s.diperr)
  101. pr_err("SPI1: STX DIP2 error on the Spi4 "
  102. "Status channel\n");
  103. if (stx_int_reg.s.datovr)
  104. pr_err("SPI1: STX Spi4 FIFO overflow error\n");
  105. if (stx_int_reg.s.ovrbst)
  106. pr_err("SPI1: STX Transmit packet burst "
  107. "too big\n");
  108. if (stx_int_reg.s.calpar1)
  109. pr_err("SPI1: STX Calendar Table Parity "
  110. "Error Bank1\n");
  111. if (stx_int_reg.s.calpar0)
  112. pr_err("SPI1: STX Calendar Table Parity "
  113. "Error Bank0\n");
  114. }
  115. cvmx_write_csr(CVMX_SPXX_INT_MSK(1), 0);
  116. cvmx_write_csr(CVMX_STXX_INT_MSK(1), 0);
  117. need_retrain[1] = 1;
  118. return_status = IRQ_HANDLED;
  119. }
  120. if (rsl_int_blocks.s.spx0) { /* 18 - SPX0_INT_REG & STX0_INT_REG */
  121. union cvmx_spxx_int_reg spx_int_reg;
  122. union cvmx_stxx_int_reg stx_int_reg;
  123. spx_int_reg.u64 = cvmx_read_csr(CVMX_SPXX_INT_REG(0));
  124. cvmx_write_csr(CVMX_SPXX_INT_REG(0), spx_int_reg.u64);
  125. if (!need_retrain[0]) {
  126. spx_int_reg.u64 &= cvmx_read_csr(CVMX_SPXX_INT_MSK(0));
  127. if (spx_int_reg.s.spf)
  128. pr_err("SPI0: SRX Spi4 interface down\n");
  129. if (spx_int_reg.s.calerr)
  130. pr_err("SPI0: SRX Spi4 Calendar table "
  131. "parity error\n");
  132. if (spx_int_reg.s.syncerr)
  133. pr_err("SPI0: SRX Consecutive Spi4 DIP4 "
  134. "errors have exceeded "
  135. "SPX_ERR_CTL[ERRCNT]\n");
  136. if (spx_int_reg.s.diperr)
  137. pr_err("SPI0: SRX Spi4 DIP4 error\n");
  138. if (spx_int_reg.s.tpaovr)
  139. pr_err("SPI0: SRX Selected port has hit "
  140. "TPA overflow\n");
  141. if (spx_int_reg.s.rsverr)
  142. pr_err("SPI0: SRX Spi4 reserved control "
  143. "word detected\n");
  144. if (spx_int_reg.s.drwnng)
  145. pr_err("SPI0: SRX Spi4 receive FIFO "
  146. "drowning/overflow\n");
  147. if (spx_int_reg.s.clserr)
  148. pr_err("SPI0: SRX Spi4 packet closed on "
  149. "non-16B alignment without EOP\n");
  150. if (spx_int_reg.s.spiovr)
  151. pr_err("SPI0: SRX Spi4 async FIFO overflow\n");
  152. if (spx_int_reg.s.abnorm)
  153. pr_err("SPI0: SRX Abnormal packet "
  154. "termination (ERR bit)\n");
  155. if (spx_int_reg.s.prtnxa)
  156. pr_err("SPI0: SRX Port out of range\n");
  157. }
  158. stx_int_reg.u64 = cvmx_read_csr(CVMX_STXX_INT_REG(0));
  159. cvmx_write_csr(CVMX_STXX_INT_REG(0), stx_int_reg.u64);
  160. if (!need_retrain[0]) {
  161. stx_int_reg.u64 &= cvmx_read_csr(CVMX_STXX_INT_MSK(0));
  162. if (stx_int_reg.s.syncerr)
  163. pr_err("SPI0: STX Interface encountered a "
  164. "fatal error\n");
  165. if (stx_int_reg.s.frmerr)
  166. pr_err("SPI0: STX FRMCNT has exceeded "
  167. "STX_DIP_CNT[MAXFRM]\n");
  168. if (stx_int_reg.s.unxfrm)
  169. pr_err("SPI0: STX Unexpected framing "
  170. "sequence\n");
  171. if (stx_int_reg.s.nosync)
  172. pr_err("SPI0: STX ERRCNT has exceeded "
  173. "STX_DIP_CNT[MAXDIP]\n");
  174. if (stx_int_reg.s.diperr)
  175. pr_err("SPI0: STX DIP2 error on the Spi4 "
  176. "Status channel\n");
  177. if (stx_int_reg.s.datovr)
  178. pr_err("SPI0: STX Spi4 FIFO overflow error\n");
  179. if (stx_int_reg.s.ovrbst)
  180. pr_err("SPI0: STX Transmit packet burst "
  181. "too big\n");
  182. if (stx_int_reg.s.calpar1)
  183. pr_err("SPI0: STX Calendar Table Parity "
  184. "Error Bank1\n");
  185. if (stx_int_reg.s.calpar0)
  186. pr_err("SPI0: STX Calendar Table Parity "
  187. "Error Bank0\n");
  188. }
  189. cvmx_write_csr(CVMX_SPXX_INT_MSK(0), 0);
  190. cvmx_write_csr(CVMX_STXX_INT_MSK(0), 0);
  191. need_retrain[0] = 1;
  192. return_status = IRQ_HANDLED;
  193. }
  194. return return_status;
  195. }
  196. static void cvm_oct_spi_enable_error_reporting(int interface)
  197. {
  198. union cvmx_spxx_int_msk spxx_int_msk;
  199. union cvmx_stxx_int_msk stxx_int_msk;
  200. spxx_int_msk.u64 = cvmx_read_csr(CVMX_SPXX_INT_MSK(interface));
  201. spxx_int_msk.s.calerr = 1;
  202. spxx_int_msk.s.syncerr = 1;
  203. spxx_int_msk.s.diperr = 1;
  204. spxx_int_msk.s.tpaovr = 1;
  205. spxx_int_msk.s.rsverr = 1;
  206. spxx_int_msk.s.drwnng = 1;
  207. spxx_int_msk.s.clserr = 1;
  208. spxx_int_msk.s.spiovr = 1;
  209. spxx_int_msk.s.abnorm = 1;
  210. spxx_int_msk.s.prtnxa = 1;
  211. cvmx_write_csr(CVMX_SPXX_INT_MSK(interface), spxx_int_msk.u64);
  212. stxx_int_msk.u64 = cvmx_read_csr(CVMX_STXX_INT_MSK(interface));
  213. stxx_int_msk.s.frmerr = 1;
  214. stxx_int_msk.s.unxfrm = 1;
  215. stxx_int_msk.s.nosync = 1;
  216. stxx_int_msk.s.diperr = 1;
  217. stxx_int_msk.s.datovr = 1;
  218. stxx_int_msk.s.ovrbst = 1;
  219. stxx_int_msk.s.calpar1 = 1;
  220. stxx_int_msk.s.calpar0 = 1;
  221. cvmx_write_csr(CVMX_STXX_INT_MSK(interface), stxx_int_msk.u64);
  222. }
  223. static void cvm_oct_spi_poll(struct net_device *dev)
  224. {
  225. static int spi4000_port;
  226. struct octeon_ethernet *priv = netdev_priv(dev);
  227. int interface;
  228. for (interface = 0; interface < 2; interface++) {
  229. if ((priv->port == interface * 16) && need_retrain[interface]) {
  230. if (cvmx_spi_restart_interface
  231. (interface, CVMX_SPI_MODE_DUPLEX, 10) == 0) {
  232. need_retrain[interface] = 0;
  233. cvm_oct_spi_enable_error_reporting(interface);
  234. }
  235. }
  236. /*
  237. * The SPI4000 TWSI interface is very slow. In order
  238. * not to bring the system to a crawl, we only poll a
  239. * single port every second. This means negotiation
  240. * speed changes take up to 10 seconds, but at least
  241. * we don't waste absurd amounts of time waiting for
  242. * TWSI.
  243. */
  244. if (priv->port == spi4000_port) {
  245. /*
  246. * This function does nothing if it is called on an
  247. * interface without a SPI4000.
  248. */
  249. cvmx_spi4000_check_speed(interface, priv->port);
  250. /*
  251. * Normal ordering increments. By decrementing
  252. * we only match once per iteration.
  253. */
  254. spi4000_port--;
  255. if (spi4000_port < 0)
  256. spi4000_port = 10;
  257. }
  258. }
  259. }
  260. int cvm_oct_spi_init(struct net_device *dev)
  261. {
  262. int r;
  263. struct octeon_ethernet *priv = netdev_priv(dev);
  264. if (number_spi_ports == 0) {
  265. r = request_irq(OCTEON_IRQ_RML, cvm_oct_spi_rml_interrupt,
  266. IRQF_SHARED, "SPI", &number_spi_ports);
  267. if (r)
  268. return r;
  269. }
  270. number_spi_ports++;
  271. if ((priv->port == 0) || (priv->port == 16)) {
  272. cvm_oct_spi_enable_error_reporting(INTERFACE(priv->port));
  273. priv->poll = cvm_oct_spi_poll;
  274. }
  275. cvm_oct_common_init(dev);
  276. return 0;
  277. }
  278. void cvm_oct_spi_uninit(struct net_device *dev)
  279. {
  280. int interface;
  281. cvm_oct_common_uninit(dev);
  282. number_spi_ports--;
  283. if (number_spi_ports == 0) {
  284. for (interface = 0; interface < 2; interface++) {
  285. cvmx_write_csr(CVMX_SPXX_INT_MSK(interface), 0);
  286. cvmx_write_csr(CVMX_STXX_INT_MSK(interface), 0);
  287. }
  288. free_irq(OCTEON_IRQ_RML, &number_spi_ports);
  289. }
  290. }