cn66xx_device.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  1. /**********************************************************************
  2. * Author: Cavium, Inc.
  3. *
  4. * Contact: support@cavium.com
  5. * Please include "LiquidIO" in the subject.
  6. *
  7. * Copyright (c) 2003-2016 Cavium, Inc.
  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 details.
  17. ***********************************************************************/
  18. #include <linux/pci.h>
  19. #include <linux/netdevice.h>
  20. #include "liquidio_common.h"
  21. #include "octeon_droq.h"
  22. #include "octeon_iq.h"
  23. #include "response_manager.h"
  24. #include "octeon_device.h"
  25. #include "octeon_main.h"
  26. #include "cn66xx_regs.h"
  27. #include "cn66xx_device.h"
  28. int lio_cn6xxx_soft_reset(struct octeon_device *oct)
  29. {
  30. octeon_write_csr64(oct, CN6XXX_WIN_WR_MASK_REG, 0xFF);
  31. dev_dbg(&oct->pci_dev->dev, "BIST enabled for soft reset\n");
  32. lio_pci_writeq(oct, 1, CN6XXX_CIU_SOFT_BIST);
  33. octeon_write_csr64(oct, CN6XXX_SLI_SCRATCH1, 0x1234ULL);
  34. lio_pci_readq(oct, CN6XXX_CIU_SOFT_RST);
  35. lio_pci_writeq(oct, 1, CN6XXX_CIU_SOFT_RST);
  36. /* make sure that the reset is written before starting timer */
  37. mmiowb();
  38. /* Wait for 10ms as Octeon resets. */
  39. mdelay(100);
  40. if (octeon_read_csr64(oct, CN6XXX_SLI_SCRATCH1)) {
  41. dev_err(&oct->pci_dev->dev, "Soft reset failed\n");
  42. return 1;
  43. }
  44. dev_dbg(&oct->pci_dev->dev, "Reset completed\n");
  45. octeon_write_csr64(oct, CN6XXX_WIN_WR_MASK_REG, 0xFF);
  46. return 0;
  47. }
  48. void lio_cn6xxx_enable_error_reporting(struct octeon_device *oct)
  49. {
  50. u32 val;
  51. pci_read_config_dword(oct->pci_dev, CN6XXX_PCIE_DEVCTL, &val);
  52. if (val & 0x000c0000) {
  53. dev_err(&oct->pci_dev->dev, "PCI-E Link error detected: 0x%08x\n",
  54. val & 0x000c0000);
  55. }
  56. val |= 0xf; /* Enable Link error reporting */
  57. dev_dbg(&oct->pci_dev->dev, "Enabling PCI-E error reporting..\n");
  58. pci_write_config_dword(oct->pci_dev, CN6XXX_PCIE_DEVCTL, val);
  59. }
  60. void lio_cn6xxx_setup_pcie_mps(struct octeon_device *oct,
  61. enum octeon_pcie_mps mps)
  62. {
  63. u32 val;
  64. u64 r64;
  65. /* Read config register for MPS */
  66. pci_read_config_dword(oct->pci_dev, CN6XXX_PCIE_DEVCTL, &val);
  67. if (mps == PCIE_MPS_DEFAULT) {
  68. mps = ((val & (0x7 << 5)) >> 5);
  69. } else {
  70. val &= ~(0x7 << 5); /* Turn off any MPS bits */
  71. val |= (mps << 5); /* Set MPS */
  72. pci_write_config_dword(oct->pci_dev, CN6XXX_PCIE_DEVCTL, val);
  73. }
  74. /* Set MPS in DPI_SLI_PRT0_CFG to the same value. */
  75. r64 = lio_pci_readq(oct, CN6XXX_DPI_SLI_PRTX_CFG(oct->pcie_port));
  76. r64 |= (mps << 4);
  77. lio_pci_writeq(oct, r64, CN6XXX_DPI_SLI_PRTX_CFG(oct->pcie_port));
  78. }
  79. void lio_cn6xxx_setup_pcie_mrrs(struct octeon_device *oct,
  80. enum octeon_pcie_mrrs mrrs)
  81. {
  82. u32 val;
  83. u64 r64;
  84. /* Read config register for MRRS */
  85. pci_read_config_dword(oct->pci_dev, CN6XXX_PCIE_DEVCTL, &val);
  86. if (mrrs == PCIE_MRRS_DEFAULT) {
  87. mrrs = ((val & (0x7 << 12)) >> 12);
  88. } else {
  89. val &= ~(0x7 << 12); /* Turn off any MRRS bits */
  90. val |= (mrrs << 12); /* Set MRRS */
  91. pci_write_config_dword(oct->pci_dev, CN6XXX_PCIE_DEVCTL, val);
  92. }
  93. /* Set MRRS in SLI_S2M_PORT0_CTL to the same value. */
  94. r64 = octeon_read_csr64(oct, CN6XXX_SLI_S2M_PORTX_CTL(oct->pcie_port));
  95. r64 |= mrrs;
  96. octeon_write_csr64(oct, CN6XXX_SLI_S2M_PORTX_CTL(oct->pcie_port), r64);
  97. /* Set MRRS in DPI_SLI_PRT0_CFG to the same value. */
  98. r64 = lio_pci_readq(oct, CN6XXX_DPI_SLI_PRTX_CFG(oct->pcie_port));
  99. r64 |= mrrs;
  100. lio_pci_writeq(oct, r64, CN6XXX_DPI_SLI_PRTX_CFG(oct->pcie_port));
  101. }
  102. u32 lio_cn6xxx_coprocessor_clock(struct octeon_device *oct)
  103. {
  104. /* Bits 29:24 of MIO_RST_BOOT holds the ref. clock multiplier
  105. * for SLI.
  106. */
  107. return ((lio_pci_readq(oct, CN6XXX_MIO_RST_BOOT) >> 24) & 0x3f) * 50;
  108. }
  109. u32 lio_cn6xxx_get_oq_ticks(struct octeon_device *oct,
  110. u32 time_intr_in_us)
  111. {
  112. /* This gives the SLI clock per microsec */
  113. u32 oqticks_per_us = lio_cn6xxx_coprocessor_clock(oct);
  114. /* core clock per us / oq ticks will be fractional. TO avoid that
  115. * we use the method below.
  116. */
  117. /* This gives the clock cycles per millisecond */
  118. oqticks_per_us *= 1000;
  119. /* This gives the oq ticks (1024 core clock cycles) per millisecond */
  120. oqticks_per_us /= 1024;
  121. /* time_intr is in microseconds. The next 2 steps gives the oq ticks
  122. * corressponding to time_intr.
  123. */
  124. oqticks_per_us *= time_intr_in_us;
  125. oqticks_per_us /= 1000;
  126. return oqticks_per_us;
  127. }
  128. void lio_cn6xxx_setup_global_input_regs(struct octeon_device *oct)
  129. {
  130. /* Select Round-Robin Arb, ES, RO, NS for Input Queues */
  131. octeon_write_csr(oct, CN6XXX_SLI_PKT_INPUT_CONTROL,
  132. CN6XXX_INPUT_CTL_MASK);
  133. /* Instruction Read Size - Max 4 instructions per PCIE Read */
  134. octeon_write_csr64(oct, CN6XXX_SLI_PKT_INSTR_RD_SIZE,
  135. 0xFFFFFFFFFFFFFFFFULL);
  136. /* Select PCIE Port for all Input rings. */
  137. octeon_write_csr64(oct, CN6XXX_SLI_IN_PCIE_PORT,
  138. (oct->pcie_port * 0x5555555555555555ULL));
  139. }
  140. static void lio_cn66xx_setup_pkt_ctl_regs(struct octeon_device *oct)
  141. {
  142. u64 pktctl;
  143. struct octeon_cn6xxx *cn6xxx = (struct octeon_cn6xxx *)oct->chip;
  144. pktctl = octeon_read_csr64(oct, CN6XXX_SLI_PKT_CTL);
  145. /* 66XX SPECIFIC */
  146. if (CFG_GET_OQ_MAX_Q(cn6xxx->conf) <= 4)
  147. /* Disable RING_EN if only upto 4 rings are used. */
  148. pktctl &= ~(1 << 4);
  149. else
  150. pktctl |= (1 << 4);
  151. if (CFG_GET_IS_SLI_BP_ON(cn6xxx->conf))
  152. pktctl |= 0xF;
  153. else
  154. /* Disable per-port backpressure. */
  155. pktctl &= ~0xF;
  156. octeon_write_csr64(oct, CN6XXX_SLI_PKT_CTL, pktctl);
  157. }
  158. void lio_cn6xxx_setup_global_output_regs(struct octeon_device *oct)
  159. {
  160. u32 time_threshold;
  161. struct octeon_cn6xxx *cn6xxx = (struct octeon_cn6xxx *)oct->chip;
  162. /* / Select PCI-E Port for all Output queues */
  163. octeon_write_csr64(oct, CN6XXX_SLI_PKT_PCIE_PORT64,
  164. (oct->pcie_port * 0x5555555555555555ULL));
  165. if (CFG_GET_IS_SLI_BP_ON(cn6xxx->conf)) {
  166. octeon_write_csr64(oct, CN6XXX_SLI_OQ_WMARK, 32);
  167. } else {
  168. /* / Set Output queue watermark to 0 to disable backpressure */
  169. octeon_write_csr64(oct, CN6XXX_SLI_OQ_WMARK, 0);
  170. }
  171. /* / Select Packet count instead of bytes for SLI_PKTi_CNTS[CNT] */
  172. octeon_write_csr(oct, CN6XXX_SLI_PKT_OUT_BMODE, 0);
  173. /* Select ES, RO, NS setting from register for Output Queue Packet
  174. * Address
  175. */
  176. octeon_write_csr(oct, CN6XXX_SLI_PKT_DPADDR, 0xFFFFFFFF);
  177. /* No Relaxed Ordering, No Snoop, 64-bit swap for Output
  178. * Queue ScatterList
  179. */
  180. octeon_write_csr(oct, CN6XXX_SLI_PKT_SLIST_ROR, 0);
  181. octeon_write_csr(oct, CN6XXX_SLI_PKT_SLIST_NS, 0);
  182. /* / ENDIAN_SPECIFIC CHANGES - 0 works for LE. */
  183. #ifdef __BIG_ENDIAN_BITFIELD
  184. octeon_write_csr64(oct, CN6XXX_SLI_PKT_SLIST_ES64,
  185. 0x5555555555555555ULL);
  186. #else
  187. octeon_write_csr64(oct, CN6XXX_SLI_PKT_SLIST_ES64, 0ULL);
  188. #endif
  189. /* / No Relaxed Ordering, No Snoop, 64-bit swap for Output Queue Data */
  190. octeon_write_csr(oct, CN6XXX_SLI_PKT_DATA_OUT_ROR, 0);
  191. octeon_write_csr(oct, CN6XXX_SLI_PKT_DATA_OUT_NS, 0);
  192. octeon_write_csr64(oct, CN6XXX_SLI_PKT_DATA_OUT_ES64,
  193. 0x5555555555555555ULL);
  194. /* / Set up interrupt packet and time threshold */
  195. octeon_write_csr(oct, CN6XXX_SLI_OQ_INT_LEVEL_PKTS,
  196. (u32)CFG_GET_OQ_INTR_PKT(cn6xxx->conf));
  197. time_threshold =
  198. lio_cn6xxx_get_oq_ticks(oct, (u32)
  199. CFG_GET_OQ_INTR_TIME(cn6xxx->conf));
  200. octeon_write_csr(oct, CN6XXX_SLI_OQ_INT_LEVEL_TIME, time_threshold);
  201. }
  202. static int lio_cn6xxx_setup_device_regs(struct octeon_device *oct)
  203. {
  204. lio_cn6xxx_setup_pcie_mps(oct, PCIE_MPS_DEFAULT);
  205. lio_cn6xxx_setup_pcie_mrrs(oct, PCIE_MRRS_512B);
  206. lio_cn6xxx_enable_error_reporting(oct);
  207. lio_cn6xxx_setup_global_input_regs(oct);
  208. lio_cn66xx_setup_pkt_ctl_regs(oct);
  209. lio_cn6xxx_setup_global_output_regs(oct);
  210. /* Default error timeout value should be 0x200000 to avoid host hang
  211. * when reads invalid register
  212. */
  213. octeon_write_csr64(oct, CN6XXX_SLI_WINDOW_CTL, 0x200000ULL);
  214. return 0;
  215. }
  216. void lio_cn6xxx_setup_iq_regs(struct octeon_device *oct, u32 iq_no)
  217. {
  218. struct octeon_instr_queue *iq = oct->instr_queue[iq_no];
  219. octeon_write_csr64(oct, CN6XXX_SLI_IQ_PKT_INSTR_HDR64(iq_no), 0);
  220. /* Write the start of the input queue's ring and its size */
  221. octeon_write_csr64(oct, CN6XXX_SLI_IQ_BASE_ADDR64(iq_no),
  222. iq->base_addr_dma);
  223. octeon_write_csr(oct, CN6XXX_SLI_IQ_SIZE(iq_no), iq->max_count);
  224. /* Remember the doorbell & instruction count register addr for this
  225. * queue
  226. */
  227. iq->doorbell_reg = oct->mmio[0].hw_addr + CN6XXX_SLI_IQ_DOORBELL(iq_no);
  228. iq->inst_cnt_reg = oct->mmio[0].hw_addr
  229. + CN6XXX_SLI_IQ_INSTR_COUNT(iq_no);
  230. dev_dbg(&oct->pci_dev->dev, "InstQ[%d]:dbell reg @ 0x%p instcnt_reg @ 0x%p\n",
  231. iq_no, iq->doorbell_reg, iq->inst_cnt_reg);
  232. /* Store the current instruction counter
  233. * (used in flush_iq calculation)
  234. */
  235. iq->reset_instr_cnt = readl(iq->inst_cnt_reg);
  236. }
  237. static void lio_cn66xx_setup_iq_regs(struct octeon_device *oct, u32 iq_no)
  238. {
  239. lio_cn6xxx_setup_iq_regs(oct, iq_no);
  240. /* Backpressure for this queue - WMARK set to all F's. This effectively
  241. * disables the backpressure mechanism.
  242. */
  243. octeon_write_csr64(oct, CN66XX_SLI_IQ_BP64(iq_no),
  244. (0xFFFFFFFFULL << 32));
  245. }
  246. void lio_cn6xxx_setup_oq_regs(struct octeon_device *oct, u32 oq_no)
  247. {
  248. u32 intr;
  249. struct octeon_droq *droq = oct->droq[oq_no];
  250. octeon_write_csr64(oct, CN6XXX_SLI_OQ_BASE_ADDR64(oq_no),
  251. droq->desc_ring_dma);
  252. octeon_write_csr(oct, CN6XXX_SLI_OQ_SIZE(oq_no), droq->max_count);
  253. octeon_write_csr(oct, CN6XXX_SLI_OQ_BUFF_INFO_SIZE(oq_no),
  254. droq->buffer_size);
  255. /* Get the mapped address of the pkt_sent and pkts_credit regs */
  256. droq->pkts_sent_reg =
  257. oct->mmio[0].hw_addr + CN6XXX_SLI_OQ_PKTS_SENT(oq_no);
  258. droq->pkts_credit_reg =
  259. oct->mmio[0].hw_addr + CN6XXX_SLI_OQ_PKTS_CREDIT(oq_no);
  260. /* Enable this output queue to generate Packet Timer Interrupt */
  261. intr = octeon_read_csr(oct, CN6XXX_SLI_PKT_TIME_INT_ENB);
  262. intr |= (1 << oq_no);
  263. octeon_write_csr(oct, CN6XXX_SLI_PKT_TIME_INT_ENB, intr);
  264. /* Enable this output queue to generate Packet Timer Interrupt */
  265. intr = octeon_read_csr(oct, CN6XXX_SLI_PKT_CNT_INT_ENB);
  266. intr |= (1 << oq_no);
  267. octeon_write_csr(oct, CN6XXX_SLI_PKT_CNT_INT_ENB, intr);
  268. }
  269. int lio_cn6xxx_enable_io_queues(struct octeon_device *oct)
  270. {
  271. u32 mask;
  272. mask = octeon_read_csr(oct, CN6XXX_SLI_PKT_INSTR_SIZE);
  273. mask |= oct->io_qmask.iq64B;
  274. octeon_write_csr(oct, CN6XXX_SLI_PKT_INSTR_SIZE, mask);
  275. mask = octeon_read_csr(oct, CN6XXX_SLI_PKT_INSTR_ENB);
  276. mask |= oct->io_qmask.iq;
  277. octeon_write_csr(oct, CN6XXX_SLI_PKT_INSTR_ENB, mask);
  278. mask = octeon_read_csr(oct, CN6XXX_SLI_PKT_OUT_ENB);
  279. mask |= oct->io_qmask.oq;
  280. octeon_write_csr(oct, CN6XXX_SLI_PKT_OUT_ENB, mask);
  281. return 0;
  282. }
  283. void lio_cn6xxx_disable_io_queues(struct octeon_device *oct)
  284. {
  285. int i;
  286. u32 mask, loop = HZ;
  287. u32 d32;
  288. /* Reset the Enable bits for Input Queues. */
  289. mask = octeon_read_csr(oct, CN6XXX_SLI_PKT_INSTR_ENB);
  290. mask ^= oct->io_qmask.iq;
  291. octeon_write_csr(oct, CN6XXX_SLI_PKT_INSTR_ENB, mask);
  292. /* Wait until hardware indicates that the queues are out of reset. */
  293. mask = (u32)oct->io_qmask.iq;
  294. d32 = octeon_read_csr(oct, CN6XXX_SLI_PORT_IN_RST_IQ);
  295. while (((d32 & mask) != mask) && loop--) {
  296. d32 = octeon_read_csr(oct, CN6XXX_SLI_PORT_IN_RST_IQ);
  297. schedule_timeout_uninterruptible(1);
  298. }
  299. /* Reset the doorbell register for each Input queue. */
  300. for (i = 0; i < MAX_OCTEON_INSTR_QUEUES(oct); i++) {
  301. if (!(oct->io_qmask.iq & BIT_ULL(i)))
  302. continue;
  303. octeon_write_csr(oct, CN6XXX_SLI_IQ_DOORBELL(i), 0xFFFFFFFF);
  304. d32 = octeon_read_csr(oct, CN6XXX_SLI_IQ_DOORBELL(i));
  305. }
  306. /* Reset the Enable bits for Output Queues. */
  307. mask = octeon_read_csr(oct, CN6XXX_SLI_PKT_OUT_ENB);
  308. mask ^= oct->io_qmask.oq;
  309. octeon_write_csr(oct, CN6XXX_SLI_PKT_OUT_ENB, mask);
  310. /* Wait until hardware indicates that the queues are out of reset. */
  311. loop = HZ;
  312. mask = (u32)oct->io_qmask.oq;
  313. d32 = octeon_read_csr(oct, CN6XXX_SLI_PORT_IN_RST_OQ);
  314. while (((d32 & mask) != mask) && loop--) {
  315. d32 = octeon_read_csr(oct, CN6XXX_SLI_PORT_IN_RST_OQ);
  316. schedule_timeout_uninterruptible(1);
  317. }
  318. ;
  319. /* Reset the doorbell register for each Output queue. */
  320. for (i = 0; i < MAX_OCTEON_OUTPUT_QUEUES(oct); i++) {
  321. if (!(oct->io_qmask.oq & BIT_ULL(i)))
  322. continue;
  323. octeon_write_csr(oct, CN6XXX_SLI_OQ_PKTS_CREDIT(i), 0xFFFFFFFF);
  324. d32 = octeon_read_csr(oct, CN6XXX_SLI_OQ_PKTS_CREDIT(i));
  325. d32 = octeon_read_csr(oct, CN6XXX_SLI_OQ_PKTS_SENT(i));
  326. octeon_write_csr(oct, CN6XXX_SLI_OQ_PKTS_SENT(i), d32);
  327. }
  328. d32 = octeon_read_csr(oct, CN6XXX_SLI_PKT_CNT_INT);
  329. if (d32)
  330. octeon_write_csr(oct, CN6XXX_SLI_PKT_CNT_INT, d32);
  331. d32 = octeon_read_csr(oct, CN6XXX_SLI_PKT_TIME_INT);
  332. if (d32)
  333. octeon_write_csr(oct, CN6XXX_SLI_PKT_TIME_INT, d32);
  334. }
  335. void
  336. lio_cn6xxx_bar1_idx_setup(struct octeon_device *oct,
  337. u64 core_addr,
  338. u32 idx,
  339. int valid)
  340. {
  341. u64 bar1;
  342. if (valid == 0) {
  343. bar1 = lio_pci_readq(oct, CN6XXX_BAR1_REG(idx, oct->pcie_port));
  344. lio_pci_writeq(oct, (bar1 & 0xFFFFFFFEULL),
  345. CN6XXX_BAR1_REG(idx, oct->pcie_port));
  346. bar1 = lio_pci_readq(oct, CN6XXX_BAR1_REG(idx, oct->pcie_port));
  347. return;
  348. }
  349. /* Bits 17:4 of the PCI_BAR1_INDEXx stores bits 35:22 of
  350. * the Core Addr
  351. */
  352. lio_pci_writeq(oct, (((core_addr >> 22) << 4) | PCI_BAR1_MASK),
  353. CN6XXX_BAR1_REG(idx, oct->pcie_port));
  354. bar1 = lio_pci_readq(oct, CN6XXX_BAR1_REG(idx, oct->pcie_port));
  355. }
  356. void lio_cn6xxx_bar1_idx_write(struct octeon_device *oct,
  357. u32 idx,
  358. u32 mask)
  359. {
  360. lio_pci_writeq(oct, mask, CN6XXX_BAR1_REG(idx, oct->pcie_port));
  361. }
  362. u32 lio_cn6xxx_bar1_idx_read(struct octeon_device *oct, u32 idx)
  363. {
  364. return (u32)lio_pci_readq(oct, CN6XXX_BAR1_REG(idx, oct->pcie_port));
  365. }
  366. u32
  367. lio_cn6xxx_update_read_index(struct octeon_instr_queue *iq)
  368. {
  369. u32 new_idx = readl(iq->inst_cnt_reg);
  370. /* The new instr cnt reg is a 32-bit counter that can roll over. We have
  371. * noted the counter's initial value at init time into
  372. * reset_instr_cnt
  373. */
  374. if (iq->reset_instr_cnt < new_idx)
  375. new_idx -= iq->reset_instr_cnt;
  376. else
  377. new_idx += (0xffffffff - iq->reset_instr_cnt) + 1;
  378. /* Modulo of the new index with the IQ size will give us
  379. * the new index.
  380. */
  381. new_idx %= iq->max_count;
  382. return new_idx;
  383. }
  384. void lio_cn6xxx_enable_interrupt(struct octeon_device *oct,
  385. u8 unused __attribute__((unused)))
  386. {
  387. struct octeon_cn6xxx *cn6xxx = (struct octeon_cn6xxx *)oct->chip;
  388. u64 mask = cn6xxx->intr_mask64 | CN6XXX_INTR_DMA0_FORCE;
  389. /* Enable Interrupt */
  390. writeq(mask, cn6xxx->intr_enb_reg64);
  391. }
  392. void lio_cn6xxx_disable_interrupt(struct octeon_device *oct,
  393. u8 unused __attribute__((unused)))
  394. {
  395. struct octeon_cn6xxx *cn6xxx = (struct octeon_cn6xxx *)oct->chip;
  396. /* Disable Interrupts */
  397. writeq(0, cn6xxx->intr_enb_reg64);
  398. /* make sure interrupts are really disabled */
  399. mmiowb();
  400. }
  401. static void lio_cn6xxx_get_pcie_qlmport(struct octeon_device *oct)
  402. {
  403. /* CN63xx Pass2 and newer parts implements the SLI_MAC_NUMBER register
  404. * to determine the PCIE port #
  405. */
  406. oct->pcie_port = octeon_read_csr(oct, CN6XXX_SLI_MAC_NUMBER) & 0xff;
  407. dev_dbg(&oct->pci_dev->dev, "Using PCIE Port %d\n", oct->pcie_port);
  408. }
  409. static void
  410. lio_cn6xxx_process_pcie_error_intr(struct octeon_device *oct, u64 intr64)
  411. {
  412. dev_err(&oct->pci_dev->dev, "Error Intr: 0x%016llx\n",
  413. CVM_CAST64(intr64));
  414. }
  415. static int lio_cn6xxx_process_droq_intr_regs(struct octeon_device *oct)
  416. {
  417. struct octeon_droq *droq;
  418. int oq_no;
  419. u32 pkt_count, droq_time_mask, droq_mask, droq_int_enb;
  420. u32 droq_cnt_enb, droq_cnt_mask;
  421. droq_cnt_enb = octeon_read_csr(oct, CN6XXX_SLI_PKT_CNT_INT_ENB);
  422. droq_cnt_mask = octeon_read_csr(oct, CN6XXX_SLI_PKT_CNT_INT);
  423. droq_mask = droq_cnt_mask & droq_cnt_enb;
  424. droq_time_mask = octeon_read_csr(oct, CN6XXX_SLI_PKT_TIME_INT);
  425. droq_int_enb = octeon_read_csr(oct, CN6XXX_SLI_PKT_TIME_INT_ENB);
  426. droq_mask |= (droq_time_mask & droq_int_enb);
  427. droq_mask &= oct->io_qmask.oq;
  428. oct->droq_intr = 0;
  429. for (oq_no = 0; oq_no < MAX_OCTEON_OUTPUT_QUEUES(oct); oq_no++) {
  430. if (!(droq_mask & BIT_ULL(oq_no)))
  431. continue;
  432. droq = oct->droq[oq_no];
  433. pkt_count = octeon_droq_check_hw_for_pkts(droq);
  434. if (pkt_count) {
  435. oct->droq_intr |= BIT_ULL(oq_no);
  436. if (droq->ops.poll_mode) {
  437. u32 value;
  438. u32 reg;
  439. struct octeon_cn6xxx *cn6xxx =
  440. (struct octeon_cn6xxx *)oct->chip;
  441. /* disable interrupts for this droq */
  442. spin_lock
  443. (&cn6xxx->lock_for_droq_int_enb_reg);
  444. reg = CN6XXX_SLI_PKT_TIME_INT_ENB;
  445. value = octeon_read_csr(oct, reg);
  446. value &= ~(1 << oq_no);
  447. octeon_write_csr(oct, reg, value);
  448. reg = CN6XXX_SLI_PKT_CNT_INT_ENB;
  449. value = octeon_read_csr(oct, reg);
  450. value &= ~(1 << oq_no);
  451. octeon_write_csr(oct, reg, value);
  452. /* Ensure that the enable register is written.
  453. */
  454. mmiowb();
  455. spin_unlock(&cn6xxx->lock_for_droq_int_enb_reg);
  456. }
  457. }
  458. }
  459. droq_time_mask &= oct->io_qmask.oq;
  460. droq_cnt_mask &= oct->io_qmask.oq;
  461. /* Reset the PKT_CNT/TIME_INT registers. */
  462. if (droq_time_mask)
  463. octeon_write_csr(oct, CN6XXX_SLI_PKT_TIME_INT, droq_time_mask);
  464. if (droq_cnt_mask) /* reset PKT_CNT register:66xx */
  465. octeon_write_csr(oct, CN6XXX_SLI_PKT_CNT_INT, droq_cnt_mask);
  466. return 0;
  467. }
  468. irqreturn_t lio_cn6xxx_process_interrupt_regs(void *dev)
  469. {
  470. struct octeon_device *oct = (struct octeon_device *)dev;
  471. struct octeon_cn6xxx *cn6xxx = (struct octeon_cn6xxx *)oct->chip;
  472. u64 intr64;
  473. intr64 = readq(cn6xxx->intr_sum_reg64);
  474. /* If our device has interrupted, then proceed.
  475. * Also check for all f's if interrupt was triggered on an error
  476. * and the PCI read fails.
  477. */
  478. if (!intr64 || (intr64 == 0xFFFFFFFFFFFFFFFFULL))
  479. return IRQ_NONE;
  480. oct->int_status = 0;
  481. if (intr64 & CN6XXX_INTR_ERR)
  482. lio_cn6xxx_process_pcie_error_intr(oct, intr64);
  483. if (intr64 & CN6XXX_INTR_PKT_DATA) {
  484. lio_cn6xxx_process_droq_intr_regs(oct);
  485. oct->int_status |= OCT_DEV_INTR_PKT_DATA;
  486. }
  487. if (intr64 & CN6XXX_INTR_DMA0_FORCE)
  488. oct->int_status |= OCT_DEV_INTR_DMA0_FORCE;
  489. if (intr64 & CN6XXX_INTR_DMA1_FORCE)
  490. oct->int_status |= OCT_DEV_INTR_DMA1_FORCE;
  491. /* Clear the current interrupts */
  492. writeq(intr64, cn6xxx->intr_sum_reg64);
  493. return IRQ_HANDLED;
  494. }
  495. void lio_cn6xxx_setup_reg_address(struct octeon_device *oct,
  496. void *chip,
  497. struct octeon_reg_list *reg_list)
  498. {
  499. u8 __iomem *bar0_pciaddr = oct->mmio[0].hw_addr;
  500. struct octeon_cn6xxx *cn6xxx = (struct octeon_cn6xxx *)chip;
  501. reg_list->pci_win_wr_addr_hi =
  502. (u32 __iomem *)(bar0_pciaddr + CN6XXX_WIN_WR_ADDR_HI);
  503. reg_list->pci_win_wr_addr_lo =
  504. (u32 __iomem *)(bar0_pciaddr + CN6XXX_WIN_WR_ADDR_LO);
  505. reg_list->pci_win_wr_addr =
  506. (u64 __iomem *)(bar0_pciaddr + CN6XXX_WIN_WR_ADDR64);
  507. reg_list->pci_win_rd_addr_hi =
  508. (u32 __iomem *)(bar0_pciaddr + CN6XXX_WIN_RD_ADDR_HI);
  509. reg_list->pci_win_rd_addr_lo =
  510. (u32 __iomem *)(bar0_pciaddr + CN6XXX_WIN_RD_ADDR_LO);
  511. reg_list->pci_win_rd_addr =
  512. (u64 __iomem *)(bar0_pciaddr + CN6XXX_WIN_RD_ADDR64);
  513. reg_list->pci_win_wr_data_hi =
  514. (u32 __iomem *)(bar0_pciaddr + CN6XXX_WIN_WR_DATA_HI);
  515. reg_list->pci_win_wr_data_lo =
  516. (u32 __iomem *)(bar0_pciaddr + CN6XXX_WIN_WR_DATA_LO);
  517. reg_list->pci_win_wr_data =
  518. (u64 __iomem *)(bar0_pciaddr + CN6XXX_WIN_WR_DATA64);
  519. reg_list->pci_win_rd_data_hi =
  520. (u32 __iomem *)(bar0_pciaddr + CN6XXX_WIN_RD_DATA_HI);
  521. reg_list->pci_win_rd_data_lo =
  522. (u32 __iomem *)(bar0_pciaddr + CN6XXX_WIN_RD_DATA_LO);
  523. reg_list->pci_win_rd_data =
  524. (u64 __iomem *)(bar0_pciaddr + CN6XXX_WIN_RD_DATA64);
  525. lio_cn6xxx_get_pcie_qlmport(oct);
  526. cn6xxx->intr_sum_reg64 = bar0_pciaddr + CN6XXX_SLI_INT_SUM64;
  527. cn6xxx->intr_mask64 = CN6XXX_INTR_MASK;
  528. cn6xxx->intr_enb_reg64 =
  529. bar0_pciaddr + CN6XXX_SLI_INT_ENB64(oct->pcie_port);
  530. }
  531. int lio_setup_cn66xx_octeon_device(struct octeon_device *oct)
  532. {
  533. struct octeon_cn6xxx *cn6xxx = (struct octeon_cn6xxx *)oct->chip;
  534. if (octeon_map_pci_barx(oct, 0, 0))
  535. return 1;
  536. if (octeon_map_pci_barx(oct, 1, MAX_BAR1_IOREMAP_SIZE)) {
  537. dev_err(&oct->pci_dev->dev, "%s CN66XX BAR1 map failed\n",
  538. __func__);
  539. octeon_unmap_pci_barx(oct, 0);
  540. return 1;
  541. }
  542. spin_lock_init(&cn6xxx->lock_for_droq_int_enb_reg);
  543. oct->fn_list.setup_iq_regs = lio_cn66xx_setup_iq_regs;
  544. oct->fn_list.setup_oq_regs = lio_cn6xxx_setup_oq_regs;
  545. oct->fn_list.soft_reset = lio_cn6xxx_soft_reset;
  546. oct->fn_list.setup_device_regs = lio_cn6xxx_setup_device_regs;
  547. oct->fn_list.update_iq_read_idx = lio_cn6xxx_update_read_index;
  548. oct->fn_list.bar1_idx_setup = lio_cn6xxx_bar1_idx_setup;
  549. oct->fn_list.bar1_idx_write = lio_cn6xxx_bar1_idx_write;
  550. oct->fn_list.bar1_idx_read = lio_cn6xxx_bar1_idx_read;
  551. oct->fn_list.process_interrupt_regs = lio_cn6xxx_process_interrupt_regs;
  552. oct->fn_list.enable_interrupt = lio_cn6xxx_enable_interrupt;
  553. oct->fn_list.disable_interrupt = lio_cn6xxx_disable_interrupt;
  554. oct->fn_list.enable_io_queues = lio_cn6xxx_enable_io_queues;
  555. oct->fn_list.disable_io_queues = lio_cn6xxx_disable_io_queues;
  556. lio_cn6xxx_setup_reg_address(oct, oct->chip, &oct->reg_list);
  557. cn6xxx->conf = (struct octeon_config *)
  558. oct_get_config_info(oct, LIO_210SV);
  559. if (!cn6xxx->conf) {
  560. dev_err(&oct->pci_dev->dev, "%s No Config found for CN66XX\n",
  561. __func__);
  562. octeon_unmap_pci_barx(oct, 0);
  563. octeon_unmap_pci_barx(oct, 1);
  564. return 1;
  565. }
  566. oct->coproc_clock_rate = 1000000ULL * lio_cn6xxx_coprocessor_clock(oct);
  567. return 0;
  568. }
  569. int lio_validate_cn6xxx_config_info(struct octeon_device *oct,
  570. struct octeon_config *conf6xxx)
  571. {
  572. if (CFG_GET_IQ_MAX_Q(conf6xxx) > CN6XXX_MAX_INPUT_QUEUES) {
  573. dev_err(&oct->pci_dev->dev, "%s: Num IQ (%d) exceeds Max (%d)\n",
  574. __func__, CFG_GET_IQ_MAX_Q(conf6xxx),
  575. CN6XXX_MAX_INPUT_QUEUES);
  576. return 1;
  577. }
  578. if (CFG_GET_OQ_MAX_Q(conf6xxx) > CN6XXX_MAX_OUTPUT_QUEUES) {
  579. dev_err(&oct->pci_dev->dev, "%s: Num OQ (%d) exceeds Max (%d)\n",
  580. __func__, CFG_GET_OQ_MAX_Q(conf6xxx),
  581. CN6XXX_MAX_OUTPUT_QUEUES);
  582. return 1;
  583. }
  584. if (CFG_GET_IQ_INSTR_TYPE(conf6xxx) != OCTEON_32BYTE_INSTR &&
  585. CFG_GET_IQ_INSTR_TYPE(conf6xxx) != OCTEON_64BYTE_INSTR) {
  586. dev_err(&oct->pci_dev->dev, "%s: Invalid instr type for IQ\n",
  587. __func__);
  588. return 1;
  589. }
  590. if (!CFG_GET_OQ_REFILL_THRESHOLD(conf6xxx)) {
  591. dev_err(&oct->pci_dev->dev, "%s: Invalid parameter for OQ\n",
  592. __func__);
  593. return 1;
  594. }
  595. if (!(CFG_GET_OQ_INTR_TIME(conf6xxx))) {
  596. dev_err(&oct->pci_dev->dev, "%s: No Time Interrupt for OQ\n",
  597. __func__);
  598. return 1;
  599. }
  600. return 0;
  601. }