cn66xx_device.c 22 KB

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