cn66xx_device.c 22 KB

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