cn23xx_pf_device.c 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434
  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/vmalloc.h>
  20. #include <linux/etherdevice.h>
  21. #include "liquidio_common.h"
  22. #include "octeon_droq.h"
  23. #include "octeon_iq.h"
  24. #include "response_manager.h"
  25. #include "octeon_device.h"
  26. #include "cn23xx_pf_device.h"
  27. #include "octeon_main.h"
  28. #include "octeon_mailbox.h"
  29. #define RESET_NOTDONE 0
  30. #define RESET_DONE 1
  31. /* Change the value of SLI Packet Input Jabber Register to allow
  32. * VXLAN TSO packets which can be 64424 bytes, exceeding the
  33. * MAX_GSO_SIZE we supplied to the kernel
  34. */
  35. #define CN23XX_INPUT_JABBER 64600
  36. void cn23xx_dump_pf_initialized_regs(struct octeon_device *oct)
  37. {
  38. int i = 0;
  39. u32 regval = 0;
  40. struct octeon_cn23xx_pf *cn23xx = (struct octeon_cn23xx_pf *)oct->chip;
  41. /*In cn23xx_soft_reset*/
  42. dev_dbg(&oct->pci_dev->dev, "%s[%llx] : 0x%llx\n",
  43. "CN23XX_WIN_WR_MASK_REG", CVM_CAST64(CN23XX_WIN_WR_MASK_REG),
  44. CVM_CAST64(octeon_read_csr64(oct, CN23XX_WIN_WR_MASK_REG)));
  45. dev_dbg(&oct->pci_dev->dev, "%s[%llx] : 0x%016llx\n",
  46. "CN23XX_SLI_SCRATCH1", CVM_CAST64(CN23XX_SLI_SCRATCH1),
  47. CVM_CAST64(octeon_read_csr64(oct, CN23XX_SLI_SCRATCH1)));
  48. dev_dbg(&oct->pci_dev->dev, "%s[%llx] : 0x%016llx\n",
  49. "CN23XX_RST_SOFT_RST", CN23XX_RST_SOFT_RST,
  50. lio_pci_readq(oct, CN23XX_RST_SOFT_RST));
  51. /*In cn23xx_set_dpi_regs*/
  52. dev_dbg(&oct->pci_dev->dev, "%s[%llx] : 0x%016llx\n",
  53. "CN23XX_DPI_DMA_CONTROL", CN23XX_DPI_DMA_CONTROL,
  54. lio_pci_readq(oct, CN23XX_DPI_DMA_CONTROL));
  55. for (i = 0; i < 6; i++) {
  56. dev_dbg(&oct->pci_dev->dev, "%s(%d)[%llx] : 0x%016llx\n",
  57. "CN23XX_DPI_DMA_ENG_ENB", i,
  58. CN23XX_DPI_DMA_ENG_ENB(i),
  59. lio_pci_readq(oct, CN23XX_DPI_DMA_ENG_ENB(i)));
  60. dev_dbg(&oct->pci_dev->dev, "%s(%d)[%llx] : 0x%016llx\n",
  61. "CN23XX_DPI_DMA_ENG_BUF", i,
  62. CN23XX_DPI_DMA_ENG_BUF(i),
  63. lio_pci_readq(oct, CN23XX_DPI_DMA_ENG_BUF(i)));
  64. }
  65. dev_dbg(&oct->pci_dev->dev, "%s[%llx] : 0x%016llx\n", "CN23XX_DPI_CTL",
  66. CN23XX_DPI_CTL, lio_pci_readq(oct, CN23XX_DPI_CTL));
  67. /*In cn23xx_setup_pcie_mps and cn23xx_setup_pcie_mrrs */
  68. pci_read_config_dword(oct->pci_dev, CN23XX_CONFIG_PCIE_DEVCTL, &regval);
  69. dev_dbg(&oct->pci_dev->dev, "%s[%llx] : 0x%016llx\n",
  70. "CN23XX_CONFIG_PCIE_DEVCTL",
  71. CVM_CAST64(CN23XX_CONFIG_PCIE_DEVCTL), CVM_CAST64(regval));
  72. dev_dbg(&oct->pci_dev->dev, "%s(%d)[%llx] : 0x%016llx\n",
  73. "CN23XX_DPI_SLI_PRTX_CFG", oct->pcie_port,
  74. CN23XX_DPI_SLI_PRTX_CFG(oct->pcie_port),
  75. lio_pci_readq(oct, CN23XX_DPI_SLI_PRTX_CFG(oct->pcie_port)));
  76. /*In cn23xx_specific_regs_setup */
  77. dev_dbg(&oct->pci_dev->dev, "%s(%d)[%llx] : 0x%016llx\n",
  78. "CN23XX_SLI_S2M_PORTX_CTL", oct->pcie_port,
  79. CVM_CAST64(CN23XX_SLI_S2M_PORTX_CTL(oct->pcie_port)),
  80. CVM_CAST64(octeon_read_csr64(
  81. oct, CN23XX_SLI_S2M_PORTX_CTL(oct->pcie_port))));
  82. dev_dbg(&oct->pci_dev->dev, "%s[%llx] : 0x%016llx\n",
  83. "CN23XX_SLI_RING_RST", CVM_CAST64(CN23XX_SLI_PKT_IOQ_RING_RST),
  84. (u64)octeon_read_csr64(oct, CN23XX_SLI_PKT_IOQ_RING_RST));
  85. /*In cn23xx_setup_global_mac_regs*/
  86. for (i = 0; i < CN23XX_MAX_MACS; i++) {
  87. dev_dbg(&oct->pci_dev->dev, "%s(%d)[%llx] : 0x%016llx\n",
  88. "CN23XX_SLI_PKT_MAC_RINFO64", i,
  89. CVM_CAST64(CN23XX_SLI_PKT_MAC_RINFO64(i, oct->pf_num)),
  90. CVM_CAST64(octeon_read_csr64
  91. (oct, CN23XX_SLI_PKT_MAC_RINFO64
  92. (i, oct->pf_num))));
  93. }
  94. /*In cn23xx_setup_global_input_regs*/
  95. for (i = 0; i < CN23XX_MAX_INPUT_QUEUES; i++) {
  96. dev_dbg(&oct->pci_dev->dev, "%s(%d)[%llx] : 0x%016llx\n",
  97. "CN23XX_SLI_IQ_PKT_CONTROL64", i,
  98. CVM_CAST64(CN23XX_SLI_IQ_PKT_CONTROL64(i)),
  99. CVM_CAST64(octeon_read_csr64
  100. (oct, CN23XX_SLI_IQ_PKT_CONTROL64(i))));
  101. }
  102. /*In cn23xx_setup_global_output_regs*/
  103. dev_dbg(&oct->pci_dev->dev, "%s[%llx] : 0x%016llx\n",
  104. "CN23XX_SLI_OQ_WMARK", CVM_CAST64(CN23XX_SLI_OQ_WMARK),
  105. CVM_CAST64(octeon_read_csr64(oct, CN23XX_SLI_OQ_WMARK)));
  106. for (i = 0; i < CN23XX_MAX_OUTPUT_QUEUES; i++) {
  107. dev_dbg(&oct->pci_dev->dev, "%s(%d)[%llx] : 0x%016llx\n",
  108. "CN23XX_SLI_OQ_PKT_CONTROL", i,
  109. CVM_CAST64(CN23XX_SLI_OQ_PKT_CONTROL(i)),
  110. CVM_CAST64(octeon_read_csr(
  111. oct, CN23XX_SLI_OQ_PKT_CONTROL(i))));
  112. dev_dbg(&oct->pci_dev->dev, "%s(%d)[%llx] : 0x%016llx\n",
  113. "CN23XX_SLI_OQ_PKT_INT_LEVELS", i,
  114. CVM_CAST64(CN23XX_SLI_OQ_PKT_INT_LEVELS(i)),
  115. CVM_CAST64(octeon_read_csr64(
  116. oct, CN23XX_SLI_OQ_PKT_INT_LEVELS(i))));
  117. }
  118. /*In cn23xx_enable_interrupt and cn23xx_disable_interrupt*/
  119. dev_dbg(&oct->pci_dev->dev, "%s[%llx] : 0x%016llx\n",
  120. "cn23xx->intr_enb_reg64",
  121. CVM_CAST64((long)(cn23xx->intr_enb_reg64)),
  122. CVM_CAST64(readq(cn23xx->intr_enb_reg64)));
  123. dev_dbg(&oct->pci_dev->dev, "%s[%llx] : 0x%016llx\n",
  124. "cn23xx->intr_sum_reg64",
  125. CVM_CAST64((long)(cn23xx->intr_sum_reg64)),
  126. CVM_CAST64(readq(cn23xx->intr_sum_reg64)));
  127. /*In cn23xx_setup_iq_regs*/
  128. for (i = 0; i < CN23XX_MAX_INPUT_QUEUES; i++) {
  129. dev_dbg(&oct->pci_dev->dev, "%s(%d)[%llx] : 0x%016llx\n",
  130. "CN23XX_SLI_IQ_BASE_ADDR64", i,
  131. CVM_CAST64(CN23XX_SLI_IQ_BASE_ADDR64(i)),
  132. CVM_CAST64(octeon_read_csr64(
  133. oct, CN23XX_SLI_IQ_BASE_ADDR64(i))));
  134. dev_dbg(&oct->pci_dev->dev, "%s(%d)[%llx] : 0x%016llx\n",
  135. "CN23XX_SLI_IQ_SIZE", i,
  136. CVM_CAST64(CN23XX_SLI_IQ_SIZE(i)),
  137. CVM_CAST64(octeon_read_csr
  138. (oct, CN23XX_SLI_IQ_SIZE(i))));
  139. dev_dbg(&oct->pci_dev->dev, "%s(%d)[%llx] : 0x%016llx\n",
  140. "CN23XX_SLI_IQ_DOORBELL", i,
  141. CVM_CAST64(CN23XX_SLI_IQ_DOORBELL(i)),
  142. CVM_CAST64(octeon_read_csr64(
  143. oct, CN23XX_SLI_IQ_DOORBELL(i))));
  144. dev_dbg(&oct->pci_dev->dev, "%s(%d)[%llx] : 0x%016llx\n",
  145. "CN23XX_SLI_IQ_INSTR_COUNT64", i,
  146. CVM_CAST64(CN23XX_SLI_IQ_INSTR_COUNT64(i)),
  147. CVM_CAST64(octeon_read_csr64(
  148. oct, CN23XX_SLI_IQ_INSTR_COUNT64(i))));
  149. }
  150. /*In cn23xx_setup_oq_regs*/
  151. for (i = 0; i < CN23XX_MAX_OUTPUT_QUEUES; i++) {
  152. dev_dbg(&oct->pci_dev->dev, "%s(%d)[%llx] : 0x%016llx\n",
  153. "CN23XX_SLI_OQ_BASE_ADDR64", i,
  154. CVM_CAST64(CN23XX_SLI_OQ_BASE_ADDR64(i)),
  155. CVM_CAST64(octeon_read_csr64(
  156. oct, CN23XX_SLI_OQ_BASE_ADDR64(i))));
  157. dev_dbg(&oct->pci_dev->dev, "%s(%d)[%llx] : 0x%016llx\n",
  158. "CN23XX_SLI_OQ_SIZE", i,
  159. CVM_CAST64(CN23XX_SLI_OQ_SIZE(i)),
  160. CVM_CAST64(octeon_read_csr
  161. (oct, CN23XX_SLI_OQ_SIZE(i))));
  162. dev_dbg(&oct->pci_dev->dev, "%s(%d)[%llx] : 0x%016llx\n",
  163. "CN23XX_SLI_OQ_BUFF_INFO_SIZE", i,
  164. CVM_CAST64(CN23XX_SLI_OQ_BUFF_INFO_SIZE(i)),
  165. CVM_CAST64(octeon_read_csr(
  166. oct, CN23XX_SLI_OQ_BUFF_INFO_SIZE(i))));
  167. dev_dbg(&oct->pci_dev->dev, "%s(%d)[%llx] : 0x%016llx\n",
  168. "CN23XX_SLI_OQ_PKTS_SENT", i,
  169. CVM_CAST64(CN23XX_SLI_OQ_PKTS_SENT(i)),
  170. CVM_CAST64(octeon_read_csr64(
  171. oct, CN23XX_SLI_OQ_PKTS_SENT(i))));
  172. dev_dbg(&oct->pci_dev->dev, "%s(%d)[%llx] : 0x%016llx\n",
  173. "CN23XX_SLI_OQ_PKTS_CREDIT", i,
  174. CVM_CAST64(CN23XX_SLI_OQ_PKTS_CREDIT(i)),
  175. CVM_CAST64(octeon_read_csr64(
  176. oct, CN23XX_SLI_OQ_PKTS_CREDIT(i))));
  177. }
  178. dev_dbg(&oct->pci_dev->dev, "%s[%llx] : 0x%016llx\n",
  179. "CN23XX_SLI_PKT_TIME_INT",
  180. CVM_CAST64(CN23XX_SLI_PKT_TIME_INT),
  181. CVM_CAST64(octeon_read_csr64(oct, CN23XX_SLI_PKT_TIME_INT)));
  182. dev_dbg(&oct->pci_dev->dev, "%s[%llx] : 0x%016llx\n",
  183. "CN23XX_SLI_PKT_CNT_INT",
  184. CVM_CAST64(CN23XX_SLI_PKT_CNT_INT),
  185. CVM_CAST64(octeon_read_csr64(oct, CN23XX_SLI_PKT_CNT_INT)));
  186. }
  187. static int cn23xx_pf_soft_reset(struct octeon_device *oct)
  188. {
  189. octeon_write_csr64(oct, CN23XX_WIN_WR_MASK_REG, 0xFF);
  190. dev_dbg(&oct->pci_dev->dev, "OCTEON[%d]: BIST enabled for CN23XX soft reset\n",
  191. oct->octeon_id);
  192. octeon_write_csr64(oct, CN23XX_SLI_SCRATCH1, 0x1234ULL);
  193. /* Initiate chip-wide soft reset */
  194. lio_pci_readq(oct, CN23XX_RST_SOFT_RST);
  195. lio_pci_writeq(oct, 1, CN23XX_RST_SOFT_RST);
  196. /* Wait for 100ms as Octeon resets. */
  197. mdelay(100);
  198. if (octeon_read_csr64(oct, CN23XX_SLI_SCRATCH1) == 0x1234ULL) {
  199. dev_err(&oct->pci_dev->dev, "OCTEON[%d]: Soft reset failed\n",
  200. oct->octeon_id);
  201. return 1;
  202. }
  203. dev_dbg(&oct->pci_dev->dev, "OCTEON[%d]: Reset completed\n",
  204. oct->octeon_id);
  205. /* restore the reset value*/
  206. octeon_write_csr64(oct, CN23XX_WIN_WR_MASK_REG, 0xFF);
  207. return 0;
  208. }
  209. static void cn23xx_enable_error_reporting(struct octeon_device *oct)
  210. {
  211. u32 regval;
  212. u32 uncorrectable_err_mask, corrtable_err_status;
  213. pci_read_config_dword(oct->pci_dev, CN23XX_CONFIG_PCIE_DEVCTL, &regval);
  214. if (regval & CN23XX_CONFIG_PCIE_DEVCTL_MASK) {
  215. uncorrectable_err_mask = 0;
  216. corrtable_err_status = 0;
  217. pci_read_config_dword(oct->pci_dev,
  218. CN23XX_CONFIG_PCIE_UNCORRECT_ERR_MASK,
  219. &uncorrectable_err_mask);
  220. pci_read_config_dword(oct->pci_dev,
  221. CN23XX_CONFIG_PCIE_CORRECT_ERR_STATUS,
  222. &corrtable_err_status);
  223. dev_err(&oct->pci_dev->dev, "PCI-E Fatal error detected;\n"
  224. "\tdev_ctl_status_reg = 0x%08x\n"
  225. "\tuncorrectable_error_mask_reg = 0x%08x\n"
  226. "\tcorrectable_error_status_reg = 0x%08x\n",
  227. regval, uncorrectable_err_mask,
  228. corrtable_err_status);
  229. }
  230. regval |= 0xf; /* Enable Link error reporting */
  231. dev_dbg(&oct->pci_dev->dev, "OCTEON[%d]: Enabling PCI-E error reporting..\n",
  232. oct->octeon_id);
  233. pci_write_config_dword(oct->pci_dev, CN23XX_CONFIG_PCIE_DEVCTL, regval);
  234. }
  235. static u32 cn23xx_coprocessor_clock(struct octeon_device *oct)
  236. {
  237. /* Bits 29:24 of RST_BOOT[PNR_MUL] holds the ref.clock MULTIPLIER
  238. * for SLI.
  239. */
  240. /* TBD: get the info in Hand-shake */
  241. return (((lio_pci_readq(oct, CN23XX_RST_BOOT) >> 24) & 0x3f) * 50);
  242. }
  243. u32 cn23xx_pf_get_oq_ticks(struct octeon_device *oct, u32 time_intr_in_us)
  244. {
  245. /* This gives the SLI clock per microsec */
  246. u32 oqticks_per_us = cn23xx_coprocessor_clock(oct);
  247. oct->pfvf_hsword.coproc_tics_per_us = oqticks_per_us;
  248. /* This gives the clock cycles per millisecond */
  249. oqticks_per_us *= 1000;
  250. /* This gives the oq ticks (1024 core clock cycles) per millisecond */
  251. oqticks_per_us /= 1024;
  252. /* time_intr is in microseconds. The next 2 steps gives the oq ticks
  253. * corressponding to time_intr.
  254. */
  255. oqticks_per_us *= time_intr_in_us;
  256. oqticks_per_us /= 1000;
  257. return oqticks_per_us;
  258. }
  259. static void cn23xx_setup_global_mac_regs(struct octeon_device *oct)
  260. {
  261. u16 mac_no = oct->pcie_port;
  262. u16 pf_num = oct->pf_num;
  263. u64 reg_val;
  264. u64 temp;
  265. /* programming SRN and TRS for each MAC(0..3) */
  266. dev_dbg(&oct->pci_dev->dev, "%s:Using pcie port %d\n",
  267. __func__, mac_no);
  268. /* By default, mapping all 64 IOQs to a single MACs */
  269. reg_val =
  270. octeon_read_csr64(oct, CN23XX_SLI_PKT_MAC_RINFO64(mac_no, pf_num));
  271. if (oct->rev_id == OCTEON_CN23XX_REV_1_1) {
  272. /* setting SRN <6:0> */
  273. reg_val = pf_num * CN23XX_MAX_RINGS_PER_PF_PASS_1_1;
  274. } else {
  275. /* setting SRN <6:0> */
  276. reg_val = pf_num * CN23XX_MAX_RINGS_PER_PF;
  277. }
  278. /* setting TRS <23:16> */
  279. reg_val = reg_val |
  280. (oct->sriov_info.trs << CN23XX_PKT_MAC_CTL_RINFO_TRS_BIT_POS);
  281. /* setting RPVF <39:32> */
  282. temp = oct->sriov_info.rings_per_vf & 0xff;
  283. reg_val |= (temp << CN23XX_PKT_MAC_CTL_RINFO_RPVF_BIT_POS);
  284. /* setting NVFS <55:48> */
  285. temp = oct->sriov_info.max_vfs & 0xff;
  286. reg_val |= (temp << CN23XX_PKT_MAC_CTL_RINFO_NVFS_BIT_POS);
  287. /* write these settings to MAC register */
  288. octeon_write_csr64(oct, CN23XX_SLI_PKT_MAC_RINFO64(mac_no, pf_num),
  289. reg_val);
  290. dev_dbg(&oct->pci_dev->dev, "SLI_PKT_MAC(%d)_PF(%d)_RINFO : 0x%016llx\n",
  291. mac_no, pf_num, (u64)octeon_read_csr64
  292. (oct, CN23XX_SLI_PKT_MAC_RINFO64(mac_no, pf_num)));
  293. }
  294. static int cn23xx_reset_io_queues(struct octeon_device *oct)
  295. {
  296. int ret_val = 0;
  297. u64 d64;
  298. u32 q_no, srn, ern;
  299. u32 loop = 1000;
  300. srn = oct->sriov_info.pf_srn;
  301. ern = srn + oct->sriov_info.num_pf_rings;
  302. /*As per HRM reg description, s/w cant write 0 to ENB. */
  303. /*to make the queue off, need to set the RST bit. */
  304. /* Reset the Enable bit for all the 64 IQs. */
  305. for (q_no = srn; q_no < ern; q_no++) {
  306. /* set RST bit to 1. This bit applies to both IQ and OQ */
  307. d64 = octeon_read_csr64(oct, CN23XX_SLI_IQ_PKT_CONTROL64(q_no));
  308. d64 = d64 | CN23XX_PKT_INPUT_CTL_RST;
  309. octeon_write_csr64(oct, CN23XX_SLI_IQ_PKT_CONTROL64(q_no), d64);
  310. }
  311. /*wait until the RST bit is clear or the RST and quite bits are set*/
  312. for (q_no = srn; q_no < ern; q_no++) {
  313. u64 reg_val = octeon_read_csr64(oct,
  314. CN23XX_SLI_IQ_PKT_CONTROL64(q_no));
  315. while ((READ_ONCE(reg_val) & CN23XX_PKT_INPUT_CTL_RST) &&
  316. !(READ_ONCE(reg_val) & CN23XX_PKT_INPUT_CTL_QUIET) &&
  317. loop--) {
  318. WRITE_ONCE(reg_val, octeon_read_csr64(
  319. oct, CN23XX_SLI_IQ_PKT_CONTROL64(q_no)));
  320. }
  321. if (!loop) {
  322. dev_err(&oct->pci_dev->dev,
  323. "clearing the reset reg failed or setting the quiet reg failed for qno: %u\n",
  324. q_no);
  325. return -1;
  326. }
  327. WRITE_ONCE(reg_val, READ_ONCE(reg_val) &
  328. ~CN23XX_PKT_INPUT_CTL_RST);
  329. octeon_write_csr64(oct, CN23XX_SLI_IQ_PKT_CONTROL64(q_no),
  330. READ_ONCE(reg_val));
  331. WRITE_ONCE(reg_val, octeon_read_csr64(
  332. oct, CN23XX_SLI_IQ_PKT_CONTROL64(q_no)));
  333. if (READ_ONCE(reg_val) & CN23XX_PKT_INPUT_CTL_RST) {
  334. dev_err(&oct->pci_dev->dev,
  335. "clearing the reset failed for qno: %u\n",
  336. q_no);
  337. ret_val = -1;
  338. }
  339. }
  340. return ret_val;
  341. }
  342. static int cn23xx_pf_setup_global_input_regs(struct octeon_device *oct)
  343. {
  344. struct octeon_cn23xx_pf *cn23xx = (struct octeon_cn23xx_pf *)oct->chip;
  345. struct octeon_instr_queue *iq;
  346. u64 intr_threshold, reg_val;
  347. u32 q_no, ern, srn;
  348. u64 pf_num;
  349. u64 vf_num;
  350. pf_num = oct->pf_num;
  351. srn = oct->sriov_info.pf_srn;
  352. ern = srn + oct->sriov_info.num_pf_rings;
  353. if (cn23xx_reset_io_queues(oct))
  354. return -1;
  355. /** Set the MAC_NUM and PVF_NUM in IQ_PKT_CONTROL reg
  356. * for all queues.Only PF can set these bits.
  357. * bits 29:30 indicate the MAC num.
  358. * bits 32:47 indicate the PVF num.
  359. */
  360. for (q_no = 0; q_no < ern; q_no++) {
  361. reg_val = oct->pcie_port << CN23XX_PKT_INPUT_CTL_MAC_NUM_POS;
  362. /* for VF assigned queues. */
  363. if (q_no < oct->sriov_info.pf_srn) {
  364. vf_num = q_no / oct->sriov_info.rings_per_vf;
  365. vf_num += 1; /* VF1, VF2,........ */
  366. } else {
  367. vf_num = 0;
  368. }
  369. reg_val |= vf_num << CN23XX_PKT_INPUT_CTL_VF_NUM_POS;
  370. reg_val |= pf_num << CN23XX_PKT_INPUT_CTL_PF_NUM_POS;
  371. octeon_write_csr64(oct, CN23XX_SLI_IQ_PKT_CONTROL64(q_no),
  372. reg_val);
  373. }
  374. /* Select ES, RO, NS, RDSIZE,DPTR Fomat#0 for
  375. * pf queues
  376. */
  377. for (q_no = srn; q_no < ern; q_no++) {
  378. void __iomem *inst_cnt_reg;
  379. iq = oct->instr_queue[q_no];
  380. if (iq)
  381. inst_cnt_reg = iq->inst_cnt_reg;
  382. else
  383. inst_cnt_reg = (u8 *)oct->mmio[0].hw_addr +
  384. CN23XX_SLI_IQ_INSTR_COUNT64(q_no);
  385. reg_val =
  386. octeon_read_csr64(oct, CN23XX_SLI_IQ_PKT_CONTROL64(q_no));
  387. reg_val |= CN23XX_PKT_INPUT_CTL_MASK;
  388. octeon_write_csr64(oct, CN23XX_SLI_IQ_PKT_CONTROL64(q_no),
  389. reg_val);
  390. /* Set WMARK level for triggering PI_INT */
  391. /* intr_threshold = CN23XX_DEF_IQ_INTR_THRESHOLD & */
  392. intr_threshold = CFG_GET_IQ_INTR_PKT(cn23xx->conf) &
  393. CN23XX_PKT_IN_DONE_WMARK_MASK;
  394. writeq((readq(inst_cnt_reg) &
  395. ~(CN23XX_PKT_IN_DONE_WMARK_MASK <<
  396. CN23XX_PKT_IN_DONE_WMARK_BIT_POS)) |
  397. (intr_threshold << CN23XX_PKT_IN_DONE_WMARK_BIT_POS),
  398. inst_cnt_reg);
  399. }
  400. return 0;
  401. }
  402. static void cn23xx_pf_setup_global_output_regs(struct octeon_device *oct)
  403. {
  404. u32 reg_val;
  405. u32 q_no, ern, srn;
  406. u64 time_threshold;
  407. struct octeon_cn23xx_pf *cn23xx = (struct octeon_cn23xx_pf *)oct->chip;
  408. srn = oct->sriov_info.pf_srn;
  409. ern = srn + oct->sriov_info.num_pf_rings;
  410. if (CFG_GET_IS_SLI_BP_ON(cn23xx->conf)) {
  411. octeon_write_csr64(oct, CN23XX_SLI_OQ_WMARK, 32);
  412. } else {
  413. /** Set Output queue watermark to 0 to disable backpressure */
  414. octeon_write_csr64(oct, CN23XX_SLI_OQ_WMARK, 0);
  415. }
  416. for (q_no = srn; q_no < ern; q_no++) {
  417. reg_val = octeon_read_csr(oct, CN23XX_SLI_OQ_PKT_CONTROL(q_no));
  418. /* set IPTR & DPTR */
  419. reg_val |=
  420. (CN23XX_PKT_OUTPUT_CTL_IPTR | CN23XX_PKT_OUTPUT_CTL_DPTR);
  421. /* reset BMODE */
  422. reg_val &= ~(CN23XX_PKT_OUTPUT_CTL_BMODE);
  423. /* No Relaxed Ordering, No Snoop, 64-bit Byte swap
  424. * for Output Queue ScatterList
  425. * reset ROR_P, NSR_P
  426. */
  427. reg_val &= ~(CN23XX_PKT_OUTPUT_CTL_ROR_P);
  428. reg_val &= ~(CN23XX_PKT_OUTPUT_CTL_NSR_P);
  429. #ifdef __LITTLE_ENDIAN_BITFIELD
  430. reg_val &= ~(CN23XX_PKT_OUTPUT_CTL_ES_P);
  431. #else
  432. reg_val |= (CN23XX_PKT_OUTPUT_CTL_ES_P);
  433. #endif
  434. /* No Relaxed Ordering, No Snoop, 64-bit Byte swap
  435. * for Output Queue Data
  436. * reset ROR, NSR
  437. */
  438. reg_val &= ~(CN23XX_PKT_OUTPUT_CTL_ROR);
  439. reg_val &= ~(CN23XX_PKT_OUTPUT_CTL_NSR);
  440. /* set the ES bit */
  441. reg_val |= (CN23XX_PKT_OUTPUT_CTL_ES);
  442. /* write all the selected settings */
  443. octeon_write_csr(oct, CN23XX_SLI_OQ_PKT_CONTROL(q_no), reg_val);
  444. /* Enabling these interrupt in oct->fn_list.enable_interrupt()
  445. * routine which called after IOQ init.
  446. * Set up interrupt packet and time thresholds
  447. * for all the OQs
  448. */
  449. time_threshold = cn23xx_pf_get_oq_ticks(
  450. oct, (u32)CFG_GET_OQ_INTR_TIME(cn23xx->conf));
  451. octeon_write_csr64(oct, CN23XX_SLI_OQ_PKT_INT_LEVELS(q_no),
  452. (CFG_GET_OQ_INTR_PKT(cn23xx->conf) |
  453. (time_threshold << 32)));
  454. }
  455. /** Setting the water mark level for pko back pressure **/
  456. writeq(0x40, (u8 *)oct->mmio[0].hw_addr + CN23XX_SLI_OQ_WMARK);
  457. /** Disabling setting OQs in reset when ring has no dorebells
  458. * enabling this will cause of head of line blocking
  459. */
  460. /* Do it only for pass1.1. and pass1.2 */
  461. if ((oct->rev_id == OCTEON_CN23XX_REV_1_0) ||
  462. (oct->rev_id == OCTEON_CN23XX_REV_1_1))
  463. writeq(readq((u8 *)oct->mmio[0].hw_addr +
  464. CN23XX_SLI_GBL_CONTROL) | 0x2,
  465. (u8 *)oct->mmio[0].hw_addr + CN23XX_SLI_GBL_CONTROL);
  466. /** Enable channel-level backpressure */
  467. if (oct->pf_num)
  468. writeq(0xffffffffffffffffULL,
  469. (u8 *)oct->mmio[0].hw_addr + CN23XX_SLI_OUT_BP_EN2_W1S);
  470. else
  471. writeq(0xffffffffffffffffULL,
  472. (u8 *)oct->mmio[0].hw_addr + CN23XX_SLI_OUT_BP_EN_W1S);
  473. }
  474. static int cn23xx_setup_pf_device_regs(struct octeon_device *oct)
  475. {
  476. cn23xx_enable_error_reporting(oct);
  477. /* program the MAC(0..3)_RINFO before setting up input/output regs */
  478. cn23xx_setup_global_mac_regs(oct);
  479. if (cn23xx_pf_setup_global_input_regs(oct))
  480. return -1;
  481. cn23xx_pf_setup_global_output_regs(oct);
  482. /* Default error timeout value should be 0x200000 to avoid host hang
  483. * when reads invalid register
  484. */
  485. octeon_write_csr64(oct, CN23XX_SLI_WINDOW_CTL,
  486. CN23XX_SLI_WINDOW_CTL_DEFAULT);
  487. /* set SLI_PKT_IN_JABBER to handle large VXLAN packets */
  488. octeon_write_csr64(oct, CN23XX_SLI_PKT_IN_JABBER, CN23XX_INPUT_JABBER);
  489. return 0;
  490. }
  491. static void cn23xx_setup_iq_regs(struct octeon_device *oct, u32 iq_no)
  492. {
  493. struct octeon_instr_queue *iq = oct->instr_queue[iq_no];
  494. u64 pkt_in_done;
  495. iq_no += oct->sriov_info.pf_srn;
  496. /* Write the start of the input queue's ring and its size */
  497. octeon_write_csr64(oct, CN23XX_SLI_IQ_BASE_ADDR64(iq_no),
  498. iq->base_addr_dma);
  499. octeon_write_csr(oct, CN23XX_SLI_IQ_SIZE(iq_no), iq->max_count);
  500. /* Remember the doorbell & instruction count register addr
  501. * for this queue
  502. */
  503. iq->doorbell_reg =
  504. (u8 *)oct->mmio[0].hw_addr + CN23XX_SLI_IQ_DOORBELL(iq_no);
  505. iq->inst_cnt_reg =
  506. (u8 *)oct->mmio[0].hw_addr + CN23XX_SLI_IQ_INSTR_COUNT64(iq_no);
  507. dev_dbg(&oct->pci_dev->dev, "InstQ[%d]:dbell reg @ 0x%p instcnt_reg @ 0x%p\n",
  508. iq_no, iq->doorbell_reg, iq->inst_cnt_reg);
  509. /* Store the current instruction counter (used in flush_iq
  510. * calculation)
  511. */
  512. pkt_in_done = readq(iq->inst_cnt_reg);
  513. if (oct->msix_on) {
  514. /* Set CINT_ENB to enable IQ interrupt */
  515. writeq((pkt_in_done | CN23XX_INTR_CINT_ENB),
  516. iq->inst_cnt_reg);
  517. } else {
  518. /* Clear the count by writing back what we read, but don't
  519. * enable interrupts
  520. */
  521. writeq(pkt_in_done, iq->inst_cnt_reg);
  522. }
  523. iq->reset_instr_cnt = 0;
  524. }
  525. static void cn23xx_setup_oq_regs(struct octeon_device *oct, u32 oq_no)
  526. {
  527. u32 reg_val;
  528. struct octeon_droq *droq = oct->droq[oq_no];
  529. struct octeon_cn23xx_pf *cn23xx = (struct octeon_cn23xx_pf *)oct->chip;
  530. u64 time_threshold;
  531. u64 cnt_threshold;
  532. oq_no += oct->sriov_info.pf_srn;
  533. octeon_write_csr64(oct, CN23XX_SLI_OQ_BASE_ADDR64(oq_no),
  534. droq->desc_ring_dma);
  535. octeon_write_csr(oct, CN23XX_SLI_OQ_SIZE(oq_no), droq->max_count);
  536. octeon_write_csr(oct, CN23XX_SLI_OQ_BUFF_INFO_SIZE(oq_no),
  537. (droq->buffer_size | (OCT_RH_SIZE << 16)));
  538. /* Get the mapped address of the pkt_sent and pkts_credit regs */
  539. droq->pkts_sent_reg =
  540. (u8 *)oct->mmio[0].hw_addr + CN23XX_SLI_OQ_PKTS_SENT(oq_no);
  541. droq->pkts_credit_reg =
  542. (u8 *)oct->mmio[0].hw_addr + CN23XX_SLI_OQ_PKTS_CREDIT(oq_no);
  543. if (!oct->msix_on) {
  544. /* Enable this output queue to generate Packet Timer Interrupt
  545. */
  546. reg_val =
  547. octeon_read_csr(oct, CN23XX_SLI_OQ_PKT_CONTROL(oq_no));
  548. reg_val |= CN23XX_PKT_OUTPUT_CTL_TENB;
  549. octeon_write_csr(oct, CN23XX_SLI_OQ_PKT_CONTROL(oq_no),
  550. reg_val);
  551. /* Enable this output queue to generate Packet Count Interrupt
  552. */
  553. reg_val =
  554. octeon_read_csr(oct, CN23XX_SLI_OQ_PKT_CONTROL(oq_no));
  555. reg_val |= CN23XX_PKT_OUTPUT_CTL_CENB;
  556. octeon_write_csr(oct, CN23XX_SLI_OQ_PKT_CONTROL(oq_no),
  557. reg_val);
  558. } else {
  559. time_threshold = cn23xx_pf_get_oq_ticks(
  560. oct, (u32)CFG_GET_OQ_INTR_TIME(cn23xx->conf));
  561. cnt_threshold = (u32)CFG_GET_OQ_INTR_PKT(cn23xx->conf);
  562. octeon_write_csr64(
  563. oct, CN23XX_SLI_OQ_PKT_INT_LEVELS(oq_no),
  564. ((time_threshold << 32 | cnt_threshold)));
  565. }
  566. }
  567. static void cn23xx_pf_mbox_thread(struct work_struct *work)
  568. {
  569. struct cavium_wk *wk = (struct cavium_wk *)work;
  570. struct octeon_mbox *mbox = (struct octeon_mbox *)wk->ctxptr;
  571. struct octeon_device *oct = mbox->oct_dev;
  572. u64 mbox_int_val, val64;
  573. u32 q_no, i;
  574. if (oct->rev_id < OCTEON_CN23XX_REV_1_1) {
  575. /*read and clear by writing 1*/
  576. mbox_int_val = readq(mbox->mbox_int_reg);
  577. writeq(mbox_int_val, mbox->mbox_int_reg);
  578. for (i = 0; i < oct->sriov_info.num_vfs_alloced; i++) {
  579. q_no = i * oct->sriov_info.rings_per_vf;
  580. val64 = readq(oct->mbox[q_no]->mbox_write_reg);
  581. if (val64 && (val64 != OCTEON_PFVFACK)) {
  582. if (octeon_mbox_read(oct->mbox[q_no]))
  583. octeon_mbox_process_message(
  584. oct->mbox[q_no]);
  585. }
  586. }
  587. schedule_delayed_work(&wk->work, msecs_to_jiffies(10));
  588. } else {
  589. octeon_mbox_process_message(mbox);
  590. }
  591. }
  592. static int cn23xx_setup_pf_mbox(struct octeon_device *oct)
  593. {
  594. struct octeon_mbox *mbox = NULL;
  595. u16 mac_no = oct->pcie_port;
  596. u16 pf_num = oct->pf_num;
  597. u32 q_no, i;
  598. if (!oct->sriov_info.max_vfs)
  599. return 0;
  600. for (i = 0; i < oct->sriov_info.max_vfs; i++) {
  601. q_no = i * oct->sriov_info.rings_per_vf;
  602. mbox = vmalloc(sizeof(*mbox));
  603. if (!mbox)
  604. goto free_mbox;
  605. memset(mbox, 0, sizeof(struct octeon_mbox));
  606. spin_lock_init(&mbox->lock);
  607. mbox->oct_dev = oct;
  608. mbox->q_no = q_no;
  609. mbox->state = OCTEON_MBOX_STATE_IDLE;
  610. /* PF mbox interrupt reg */
  611. mbox->mbox_int_reg = (u8 *)oct->mmio[0].hw_addr +
  612. CN23XX_SLI_MAC_PF_MBOX_INT(mac_no, pf_num);
  613. /* PF writes into SIG0 reg */
  614. mbox->mbox_write_reg = (u8 *)oct->mmio[0].hw_addr +
  615. CN23XX_SLI_PKT_PF_VF_MBOX_SIG(q_no, 0);
  616. /* PF reads from SIG1 reg */
  617. mbox->mbox_read_reg = (u8 *)oct->mmio[0].hw_addr +
  618. CN23XX_SLI_PKT_PF_VF_MBOX_SIG(q_no, 1);
  619. /*Mail Box Thread creation*/
  620. INIT_DELAYED_WORK(&mbox->mbox_poll_wk.work,
  621. cn23xx_pf_mbox_thread);
  622. mbox->mbox_poll_wk.ctxptr = (void *)mbox;
  623. oct->mbox[q_no] = mbox;
  624. writeq(OCTEON_PFVFSIG, mbox->mbox_read_reg);
  625. }
  626. if (oct->rev_id < OCTEON_CN23XX_REV_1_1)
  627. schedule_delayed_work(&oct->mbox[0]->mbox_poll_wk.work,
  628. msecs_to_jiffies(0));
  629. return 0;
  630. free_mbox:
  631. while (i) {
  632. i--;
  633. vfree(oct->mbox[i]);
  634. }
  635. return 1;
  636. }
  637. static int cn23xx_free_pf_mbox(struct octeon_device *oct)
  638. {
  639. u32 q_no, i;
  640. if (!oct->sriov_info.max_vfs)
  641. return 0;
  642. for (i = 0; i < oct->sriov_info.max_vfs; i++) {
  643. q_no = i * oct->sriov_info.rings_per_vf;
  644. cancel_delayed_work_sync(
  645. &oct->mbox[q_no]->mbox_poll_wk.work);
  646. vfree(oct->mbox[q_no]);
  647. }
  648. return 0;
  649. }
  650. static int cn23xx_enable_io_queues(struct octeon_device *oct)
  651. {
  652. u64 reg_val;
  653. u32 srn, ern, q_no;
  654. u32 loop = 1000;
  655. srn = oct->sriov_info.pf_srn;
  656. ern = srn + oct->num_iqs;
  657. for (q_no = srn; q_no < ern; q_no++) {
  658. /* set the corresponding IQ IS_64B bit */
  659. if (oct->io_qmask.iq64B & BIT_ULL(q_no - srn)) {
  660. reg_val = octeon_read_csr64(
  661. oct, CN23XX_SLI_IQ_PKT_CONTROL64(q_no));
  662. reg_val = reg_val | CN23XX_PKT_INPUT_CTL_IS_64B;
  663. octeon_write_csr64(
  664. oct, CN23XX_SLI_IQ_PKT_CONTROL64(q_no), reg_val);
  665. }
  666. /* set the corresponding IQ ENB bit */
  667. if (oct->io_qmask.iq & BIT_ULL(q_no - srn)) {
  668. /* IOQs are in reset by default in PEM2 mode,
  669. * clearing reset bit
  670. */
  671. reg_val = octeon_read_csr64(
  672. oct, CN23XX_SLI_IQ_PKT_CONTROL64(q_no));
  673. if (reg_val & CN23XX_PKT_INPUT_CTL_RST) {
  674. while ((reg_val & CN23XX_PKT_INPUT_CTL_RST) &&
  675. !(reg_val &
  676. CN23XX_PKT_INPUT_CTL_QUIET) &&
  677. --loop) {
  678. reg_val = octeon_read_csr64(
  679. oct,
  680. CN23XX_SLI_IQ_PKT_CONTROL64(q_no));
  681. }
  682. if (!loop) {
  683. dev_err(&oct->pci_dev->dev,
  684. "clearing the reset reg failed or setting the quiet reg failed for qno: %u\n",
  685. q_no);
  686. return -1;
  687. }
  688. reg_val = reg_val & ~CN23XX_PKT_INPUT_CTL_RST;
  689. octeon_write_csr64(
  690. oct, CN23XX_SLI_IQ_PKT_CONTROL64(q_no),
  691. reg_val);
  692. reg_val = octeon_read_csr64(
  693. oct, CN23XX_SLI_IQ_PKT_CONTROL64(q_no));
  694. if (reg_val & CN23XX_PKT_INPUT_CTL_RST) {
  695. dev_err(&oct->pci_dev->dev,
  696. "clearing the reset failed for qno: %u\n",
  697. q_no);
  698. return -1;
  699. }
  700. }
  701. reg_val = octeon_read_csr64(
  702. oct, CN23XX_SLI_IQ_PKT_CONTROL64(q_no));
  703. reg_val = reg_val | CN23XX_PKT_INPUT_CTL_RING_ENB;
  704. octeon_write_csr64(
  705. oct, CN23XX_SLI_IQ_PKT_CONTROL64(q_no), reg_val);
  706. }
  707. }
  708. for (q_no = srn; q_no < ern; q_no++) {
  709. u32 reg_val;
  710. /* set the corresponding OQ ENB bit */
  711. if (oct->io_qmask.oq & BIT_ULL(q_no - srn)) {
  712. reg_val = octeon_read_csr(
  713. oct, CN23XX_SLI_OQ_PKT_CONTROL(q_no));
  714. reg_val = reg_val | CN23XX_PKT_OUTPUT_CTL_RING_ENB;
  715. octeon_write_csr(oct, CN23XX_SLI_OQ_PKT_CONTROL(q_no),
  716. reg_val);
  717. }
  718. }
  719. return 0;
  720. }
  721. static void cn23xx_disable_io_queues(struct octeon_device *oct)
  722. {
  723. int q_no, loop;
  724. u64 d64;
  725. u32 d32;
  726. u32 srn, ern;
  727. srn = oct->sriov_info.pf_srn;
  728. ern = srn + oct->num_iqs;
  729. /*** Disable Input Queues. ***/
  730. for (q_no = srn; q_no < ern; q_no++) {
  731. loop = HZ;
  732. /* start the Reset for a particular ring */
  733. WRITE_ONCE(d64, octeon_read_csr64(
  734. oct, CN23XX_SLI_IQ_PKT_CONTROL64(q_no)));
  735. WRITE_ONCE(d64, READ_ONCE(d64) &
  736. (~(CN23XX_PKT_INPUT_CTL_RING_ENB)));
  737. WRITE_ONCE(d64, READ_ONCE(d64) | CN23XX_PKT_INPUT_CTL_RST);
  738. octeon_write_csr64(oct, CN23XX_SLI_IQ_PKT_CONTROL64(q_no),
  739. READ_ONCE(d64));
  740. /* Wait until hardware indicates that the particular IQ
  741. * is out of reset.
  742. */
  743. WRITE_ONCE(d64, octeon_read_csr64(
  744. oct, CN23XX_SLI_PKT_IOQ_RING_RST));
  745. while (!(READ_ONCE(d64) & BIT_ULL(q_no)) && loop--) {
  746. WRITE_ONCE(d64, octeon_read_csr64(
  747. oct, CN23XX_SLI_PKT_IOQ_RING_RST));
  748. schedule_timeout_uninterruptible(1);
  749. }
  750. /* Reset the doorbell register for this Input Queue. */
  751. octeon_write_csr(oct, CN23XX_SLI_IQ_DOORBELL(q_no), 0xFFFFFFFF);
  752. while (octeon_read_csr64(oct, CN23XX_SLI_IQ_DOORBELL(q_no)) &&
  753. loop--) {
  754. schedule_timeout_uninterruptible(1);
  755. }
  756. }
  757. /*** Disable Output Queues. ***/
  758. for (q_no = srn; q_no < ern; q_no++) {
  759. loop = HZ;
  760. /* Wait until hardware indicates that the particular IQ
  761. * is out of reset.It given that SLI_PKT_RING_RST is
  762. * common for both IQs and OQs
  763. */
  764. WRITE_ONCE(d64, octeon_read_csr64(
  765. oct, CN23XX_SLI_PKT_IOQ_RING_RST));
  766. while (!(READ_ONCE(d64) & BIT_ULL(q_no)) && loop--) {
  767. WRITE_ONCE(d64, octeon_read_csr64(
  768. oct, CN23XX_SLI_PKT_IOQ_RING_RST));
  769. schedule_timeout_uninterruptible(1);
  770. }
  771. /* Reset the doorbell register for this Output Queue. */
  772. octeon_write_csr(oct, CN23XX_SLI_OQ_PKTS_CREDIT(q_no),
  773. 0xFFFFFFFF);
  774. while (octeon_read_csr64(oct,
  775. CN23XX_SLI_OQ_PKTS_CREDIT(q_no)) &&
  776. loop--) {
  777. schedule_timeout_uninterruptible(1);
  778. }
  779. /* clear the SLI_PKT(0..63)_CNTS[CNT] reg value */
  780. WRITE_ONCE(d32, octeon_read_csr(
  781. oct, CN23XX_SLI_OQ_PKTS_SENT(q_no)));
  782. octeon_write_csr(oct, CN23XX_SLI_OQ_PKTS_SENT(q_no),
  783. READ_ONCE(d32));
  784. }
  785. }
  786. static u64 cn23xx_pf_msix_interrupt_handler(void *dev)
  787. {
  788. struct octeon_ioq_vector *ioq_vector = (struct octeon_ioq_vector *)dev;
  789. struct octeon_device *oct = ioq_vector->oct_dev;
  790. u64 pkts_sent;
  791. u64 ret = 0;
  792. struct octeon_droq *droq = oct->droq[ioq_vector->droq_index];
  793. dev_dbg(&oct->pci_dev->dev, "In %s octeon_dev @ %p\n", __func__, oct);
  794. if (!droq) {
  795. dev_err(&oct->pci_dev->dev, "23XX bringup FIXME: oct pfnum:%d ioq_vector->ioq_num :%d droq is NULL\n",
  796. oct->pf_num, ioq_vector->ioq_num);
  797. return 0;
  798. }
  799. pkts_sent = readq(droq->pkts_sent_reg);
  800. /* If our device has interrupted, then proceed. Also check
  801. * for all f's if interrupt was triggered on an error
  802. * and the PCI read fails.
  803. */
  804. if (!pkts_sent || (pkts_sent == 0xFFFFFFFFFFFFFFFFULL))
  805. return ret;
  806. /* Write count reg in sli_pkt_cnts to clear these int.*/
  807. if ((pkts_sent & CN23XX_INTR_PO_INT) ||
  808. (pkts_sent & CN23XX_INTR_PI_INT)) {
  809. if (pkts_sent & CN23XX_INTR_PO_INT)
  810. ret |= MSIX_PO_INT;
  811. }
  812. if (pkts_sent & CN23XX_INTR_PI_INT)
  813. /* We will clear the count when we update the read_index. */
  814. ret |= MSIX_PI_INT;
  815. /* Never need to handle msix mbox intr for pf. They arrive on the last
  816. * msix
  817. */
  818. return ret;
  819. }
  820. static void cn23xx_handle_pf_mbox_intr(struct octeon_device *oct)
  821. {
  822. struct delayed_work *work;
  823. u64 mbox_int_val;
  824. u32 i, q_no;
  825. mbox_int_val = readq(oct->mbox[0]->mbox_int_reg);
  826. for (i = 0; i < oct->sriov_info.num_vfs_alloced; i++) {
  827. q_no = i * oct->sriov_info.rings_per_vf;
  828. if (mbox_int_val & BIT_ULL(q_no)) {
  829. writeq(BIT_ULL(q_no),
  830. oct->mbox[0]->mbox_int_reg);
  831. if (octeon_mbox_read(oct->mbox[q_no])) {
  832. work = &oct->mbox[q_no]->mbox_poll_wk.work;
  833. schedule_delayed_work(work,
  834. msecs_to_jiffies(0));
  835. }
  836. }
  837. }
  838. }
  839. static irqreturn_t cn23xx_interrupt_handler(void *dev)
  840. {
  841. struct octeon_device *oct = (struct octeon_device *)dev;
  842. struct octeon_cn23xx_pf *cn23xx = (struct octeon_cn23xx_pf *)oct->chip;
  843. u64 intr64;
  844. dev_dbg(&oct->pci_dev->dev, "In %s octeon_dev @ %p\n", __func__, oct);
  845. intr64 = readq(cn23xx->intr_sum_reg64);
  846. oct->int_status = 0;
  847. if (intr64 & CN23XX_INTR_ERR)
  848. dev_err(&oct->pci_dev->dev, "OCTEON[%d]: Error Intr: 0x%016llx\n",
  849. oct->octeon_id, CVM_CAST64(intr64));
  850. /* When VFs write into MBOX_SIG2 reg,these intr is set in PF */
  851. if (intr64 & CN23XX_INTR_VF_MBOX)
  852. cn23xx_handle_pf_mbox_intr(oct);
  853. if (oct->msix_on != LIO_FLAG_MSIX_ENABLED) {
  854. if (intr64 & CN23XX_INTR_PKT_DATA)
  855. oct->int_status |= OCT_DEV_INTR_PKT_DATA;
  856. }
  857. if (intr64 & (CN23XX_INTR_DMA0_FORCE))
  858. oct->int_status |= OCT_DEV_INTR_DMA0_FORCE;
  859. if (intr64 & (CN23XX_INTR_DMA1_FORCE))
  860. oct->int_status |= OCT_DEV_INTR_DMA1_FORCE;
  861. /* Clear the current interrupts */
  862. writeq(intr64, cn23xx->intr_sum_reg64);
  863. return IRQ_HANDLED;
  864. }
  865. static void cn23xx_bar1_idx_setup(struct octeon_device *oct, u64 core_addr,
  866. u32 idx, int valid)
  867. {
  868. u64 bar1;
  869. u64 reg_adr;
  870. if (!valid) {
  871. reg_adr = lio_pci_readq(
  872. oct, CN23XX_PEM_BAR1_INDEX_REG(oct->pcie_port, idx));
  873. WRITE_ONCE(bar1, reg_adr);
  874. lio_pci_writeq(oct, (READ_ONCE(bar1) & 0xFFFFFFFEULL),
  875. CN23XX_PEM_BAR1_INDEX_REG(oct->pcie_port, idx));
  876. reg_adr = lio_pci_readq(
  877. oct, CN23XX_PEM_BAR1_INDEX_REG(oct->pcie_port, idx));
  878. WRITE_ONCE(bar1, reg_adr);
  879. return;
  880. }
  881. /* The PEM(0..3)_BAR1_INDEX(0..15)[ADDR_IDX]<23:4> stores
  882. * bits <41:22> of the Core Addr
  883. */
  884. lio_pci_writeq(oct, (((core_addr >> 22) << 4) | PCI_BAR1_MASK),
  885. CN23XX_PEM_BAR1_INDEX_REG(oct->pcie_port, idx));
  886. WRITE_ONCE(bar1, lio_pci_readq(
  887. oct, CN23XX_PEM_BAR1_INDEX_REG(oct->pcie_port, idx)));
  888. }
  889. static void cn23xx_bar1_idx_write(struct octeon_device *oct, u32 idx, u32 mask)
  890. {
  891. lio_pci_writeq(oct, mask,
  892. CN23XX_PEM_BAR1_INDEX_REG(oct->pcie_port, idx));
  893. }
  894. static u32 cn23xx_bar1_idx_read(struct octeon_device *oct, u32 idx)
  895. {
  896. return (u32)lio_pci_readq(
  897. oct, CN23XX_PEM_BAR1_INDEX_REG(oct->pcie_port, idx));
  898. }
  899. /* always call with lock held */
  900. static u32 cn23xx_update_read_index(struct octeon_instr_queue *iq)
  901. {
  902. u32 new_idx;
  903. u32 last_done;
  904. u32 pkt_in_done = readl(iq->inst_cnt_reg);
  905. last_done = pkt_in_done - iq->pkt_in_done;
  906. iq->pkt_in_done = pkt_in_done;
  907. /* Modulo of the new index with the IQ size will give us
  908. * the new index. The iq->reset_instr_cnt is always zero for
  909. * cn23xx, so no extra adjustments are needed.
  910. */
  911. new_idx = (iq->octeon_read_index +
  912. (u32)(last_done & CN23XX_PKT_IN_DONE_CNT_MASK)) %
  913. iq->max_count;
  914. return new_idx;
  915. }
  916. static void cn23xx_enable_pf_interrupt(struct octeon_device *oct, u8 intr_flag)
  917. {
  918. struct octeon_cn23xx_pf *cn23xx = (struct octeon_cn23xx_pf *)oct->chip;
  919. u64 intr_val = 0;
  920. /* Divide the single write to multiple writes based on the flag. */
  921. /* Enable Interrupt */
  922. if (intr_flag == OCTEON_ALL_INTR) {
  923. writeq(cn23xx->intr_mask64, cn23xx->intr_enb_reg64);
  924. } else if (intr_flag & OCTEON_OUTPUT_INTR) {
  925. intr_val = readq(cn23xx->intr_enb_reg64);
  926. intr_val |= CN23XX_INTR_PKT_DATA;
  927. writeq(intr_val, cn23xx->intr_enb_reg64);
  928. } else if ((intr_flag & OCTEON_MBOX_INTR) &&
  929. (oct->sriov_info.max_vfs > 0)) {
  930. if (oct->rev_id >= OCTEON_CN23XX_REV_1_1) {
  931. intr_val = readq(cn23xx->intr_enb_reg64);
  932. intr_val |= CN23XX_INTR_VF_MBOX;
  933. writeq(intr_val, cn23xx->intr_enb_reg64);
  934. }
  935. }
  936. }
  937. static void cn23xx_disable_pf_interrupt(struct octeon_device *oct, u8 intr_flag)
  938. {
  939. struct octeon_cn23xx_pf *cn23xx = (struct octeon_cn23xx_pf *)oct->chip;
  940. u64 intr_val = 0;
  941. /* Disable Interrupts */
  942. if (intr_flag == OCTEON_ALL_INTR) {
  943. writeq(0, cn23xx->intr_enb_reg64);
  944. } else if (intr_flag & OCTEON_OUTPUT_INTR) {
  945. intr_val = readq(cn23xx->intr_enb_reg64);
  946. intr_val &= ~CN23XX_INTR_PKT_DATA;
  947. writeq(intr_val, cn23xx->intr_enb_reg64);
  948. } else if ((intr_flag & OCTEON_MBOX_INTR) &&
  949. (oct->sriov_info.max_vfs > 0)) {
  950. if (oct->rev_id >= OCTEON_CN23XX_REV_1_1) {
  951. intr_val = readq(cn23xx->intr_enb_reg64);
  952. intr_val &= ~CN23XX_INTR_VF_MBOX;
  953. writeq(intr_val, cn23xx->intr_enb_reg64);
  954. }
  955. }
  956. }
  957. static void cn23xx_get_pcie_qlmport(struct octeon_device *oct)
  958. {
  959. oct->pcie_port = (octeon_read_csr(oct, CN23XX_SLI_MAC_NUMBER)) & 0xff;
  960. dev_dbg(&oct->pci_dev->dev, "OCTEON: CN23xx uses PCIE Port %d\n",
  961. oct->pcie_port);
  962. }
  963. static void cn23xx_get_pf_num(struct octeon_device *oct)
  964. {
  965. u32 fdl_bit = 0;
  966. /** Read Function Dependency Link reg to get the function number */
  967. pci_read_config_dword(oct->pci_dev, CN23XX_PCIE_SRIOV_FDL, &fdl_bit);
  968. oct->pf_num = ((fdl_bit >> CN23XX_PCIE_SRIOV_FDL_BIT_POS) &
  969. CN23XX_PCIE_SRIOV_FDL_MASK);
  970. }
  971. static void cn23xx_setup_reg_address(struct octeon_device *oct)
  972. {
  973. u8 __iomem *bar0_pciaddr = oct->mmio[0].hw_addr;
  974. struct octeon_cn23xx_pf *cn23xx = (struct octeon_cn23xx_pf *)oct->chip;
  975. oct->reg_list.pci_win_wr_addr_hi =
  976. (u32 __iomem *)(bar0_pciaddr + CN23XX_WIN_WR_ADDR_HI);
  977. oct->reg_list.pci_win_wr_addr_lo =
  978. (u32 __iomem *)(bar0_pciaddr + CN23XX_WIN_WR_ADDR_LO);
  979. oct->reg_list.pci_win_wr_addr =
  980. (u64 __iomem *)(bar0_pciaddr + CN23XX_WIN_WR_ADDR64);
  981. oct->reg_list.pci_win_rd_addr_hi =
  982. (u32 __iomem *)(bar0_pciaddr + CN23XX_WIN_RD_ADDR_HI);
  983. oct->reg_list.pci_win_rd_addr_lo =
  984. (u32 __iomem *)(bar0_pciaddr + CN23XX_WIN_RD_ADDR_LO);
  985. oct->reg_list.pci_win_rd_addr =
  986. (u64 __iomem *)(bar0_pciaddr + CN23XX_WIN_RD_ADDR64);
  987. oct->reg_list.pci_win_wr_data_hi =
  988. (u32 __iomem *)(bar0_pciaddr + CN23XX_WIN_WR_DATA_HI);
  989. oct->reg_list.pci_win_wr_data_lo =
  990. (u32 __iomem *)(bar0_pciaddr + CN23XX_WIN_WR_DATA_LO);
  991. oct->reg_list.pci_win_wr_data =
  992. (u64 __iomem *)(bar0_pciaddr + CN23XX_WIN_WR_DATA64);
  993. oct->reg_list.pci_win_rd_data_hi =
  994. (u32 __iomem *)(bar0_pciaddr + CN23XX_WIN_RD_DATA_HI);
  995. oct->reg_list.pci_win_rd_data_lo =
  996. (u32 __iomem *)(bar0_pciaddr + CN23XX_WIN_RD_DATA_LO);
  997. oct->reg_list.pci_win_rd_data =
  998. (u64 __iomem *)(bar0_pciaddr + CN23XX_WIN_RD_DATA64);
  999. cn23xx_get_pcie_qlmport(oct);
  1000. cn23xx->intr_mask64 = CN23XX_INTR_MASK;
  1001. if (!oct->msix_on)
  1002. cn23xx->intr_mask64 |= CN23XX_INTR_PKT_TIME;
  1003. if (oct->rev_id >= OCTEON_CN23XX_REV_1_1)
  1004. cn23xx->intr_mask64 |= CN23XX_INTR_VF_MBOX;
  1005. cn23xx->intr_sum_reg64 =
  1006. bar0_pciaddr +
  1007. CN23XX_SLI_MAC_PF_INT_SUM64(oct->pcie_port, oct->pf_num);
  1008. cn23xx->intr_enb_reg64 =
  1009. bar0_pciaddr +
  1010. CN23XX_SLI_MAC_PF_INT_ENB64(oct->pcie_port, oct->pf_num);
  1011. }
  1012. static int cn23xx_sriov_config(struct octeon_device *oct)
  1013. {
  1014. struct octeon_cn23xx_pf *cn23xx = (struct octeon_cn23xx_pf *)oct->chip;
  1015. u32 max_rings, total_rings, max_vfs, rings_per_vf;
  1016. u32 pf_srn, num_pf_rings;
  1017. u32 max_possible_vfs;
  1018. cn23xx->conf =
  1019. (struct octeon_config *)oct_get_config_info(oct, LIO_23XX);
  1020. switch (oct->rev_id) {
  1021. case OCTEON_CN23XX_REV_1_0:
  1022. max_rings = CN23XX_MAX_RINGS_PER_PF_PASS_1_0;
  1023. max_possible_vfs = CN23XX_MAX_VFS_PER_PF_PASS_1_0;
  1024. break;
  1025. case OCTEON_CN23XX_REV_1_1:
  1026. max_rings = CN23XX_MAX_RINGS_PER_PF_PASS_1_1;
  1027. max_possible_vfs = CN23XX_MAX_VFS_PER_PF_PASS_1_1;
  1028. break;
  1029. default:
  1030. max_rings = CN23XX_MAX_RINGS_PER_PF;
  1031. max_possible_vfs = CN23XX_MAX_VFS_PER_PF;
  1032. break;
  1033. }
  1034. if (max_rings <= num_present_cpus())
  1035. num_pf_rings = 1;
  1036. else
  1037. num_pf_rings = num_present_cpus();
  1038. #ifdef CONFIG_PCI_IOV
  1039. max_vfs = min_t(u32,
  1040. (max_rings - num_pf_rings), max_possible_vfs);
  1041. rings_per_vf = 1;
  1042. #else
  1043. max_vfs = 0;
  1044. rings_per_vf = 0;
  1045. #endif
  1046. total_rings = num_pf_rings + max_vfs;
  1047. /* the first ring of the pf */
  1048. pf_srn = total_rings - num_pf_rings;
  1049. oct->sriov_info.trs = total_rings;
  1050. oct->sriov_info.max_vfs = max_vfs;
  1051. oct->sriov_info.rings_per_vf = rings_per_vf;
  1052. oct->sriov_info.pf_srn = pf_srn;
  1053. oct->sriov_info.num_pf_rings = num_pf_rings;
  1054. dev_notice(&oct->pci_dev->dev, "trs:%d max_vfs:%d rings_per_vf:%d pf_srn:%d num_pf_rings:%d\n",
  1055. oct->sriov_info.trs, oct->sriov_info.max_vfs,
  1056. oct->sriov_info.rings_per_vf, oct->sriov_info.pf_srn,
  1057. oct->sriov_info.num_pf_rings);
  1058. oct->sriov_info.sriov_enabled = 0;
  1059. return 0;
  1060. }
  1061. int setup_cn23xx_octeon_pf_device(struct octeon_device *oct)
  1062. {
  1063. if (octeon_map_pci_barx(oct, 0, 0))
  1064. return 1;
  1065. if (octeon_map_pci_barx(oct, 1, MAX_BAR1_IOREMAP_SIZE)) {
  1066. dev_err(&oct->pci_dev->dev, "%s CN23XX BAR1 map failed\n",
  1067. __func__);
  1068. octeon_unmap_pci_barx(oct, 0);
  1069. return 1;
  1070. }
  1071. cn23xx_get_pf_num(oct);
  1072. if (cn23xx_sriov_config(oct)) {
  1073. octeon_unmap_pci_barx(oct, 0);
  1074. octeon_unmap_pci_barx(oct, 1);
  1075. return 1;
  1076. }
  1077. octeon_write_csr64(oct, CN23XX_SLI_MAC_CREDIT_CNT, 0x3F802080802080ULL);
  1078. oct->fn_list.setup_iq_regs = cn23xx_setup_iq_regs;
  1079. oct->fn_list.setup_oq_regs = cn23xx_setup_oq_regs;
  1080. oct->fn_list.setup_mbox = cn23xx_setup_pf_mbox;
  1081. oct->fn_list.free_mbox = cn23xx_free_pf_mbox;
  1082. oct->fn_list.process_interrupt_regs = cn23xx_interrupt_handler;
  1083. oct->fn_list.msix_interrupt_handler = cn23xx_pf_msix_interrupt_handler;
  1084. oct->fn_list.soft_reset = cn23xx_pf_soft_reset;
  1085. oct->fn_list.setup_device_regs = cn23xx_setup_pf_device_regs;
  1086. oct->fn_list.update_iq_read_idx = cn23xx_update_read_index;
  1087. oct->fn_list.bar1_idx_setup = cn23xx_bar1_idx_setup;
  1088. oct->fn_list.bar1_idx_write = cn23xx_bar1_idx_write;
  1089. oct->fn_list.bar1_idx_read = cn23xx_bar1_idx_read;
  1090. oct->fn_list.enable_interrupt = cn23xx_enable_pf_interrupt;
  1091. oct->fn_list.disable_interrupt = cn23xx_disable_pf_interrupt;
  1092. oct->fn_list.enable_io_queues = cn23xx_enable_io_queues;
  1093. oct->fn_list.disable_io_queues = cn23xx_disable_io_queues;
  1094. cn23xx_setup_reg_address(oct);
  1095. oct->coproc_clock_rate = 1000000ULL * cn23xx_coprocessor_clock(oct);
  1096. return 0;
  1097. }
  1098. int validate_cn23xx_pf_config_info(struct octeon_device *oct,
  1099. struct octeon_config *conf23xx)
  1100. {
  1101. if (CFG_GET_IQ_MAX_Q(conf23xx) > CN23XX_MAX_INPUT_QUEUES) {
  1102. dev_err(&oct->pci_dev->dev, "%s: Num IQ (%d) exceeds Max (%d)\n",
  1103. __func__, CFG_GET_IQ_MAX_Q(conf23xx),
  1104. CN23XX_MAX_INPUT_QUEUES);
  1105. return 1;
  1106. }
  1107. if (CFG_GET_OQ_MAX_Q(conf23xx) > CN23XX_MAX_OUTPUT_QUEUES) {
  1108. dev_err(&oct->pci_dev->dev, "%s: Num OQ (%d) exceeds Max (%d)\n",
  1109. __func__, CFG_GET_OQ_MAX_Q(conf23xx),
  1110. CN23XX_MAX_OUTPUT_QUEUES);
  1111. return 1;
  1112. }
  1113. if (CFG_GET_IQ_INSTR_TYPE(conf23xx) != OCTEON_32BYTE_INSTR &&
  1114. CFG_GET_IQ_INSTR_TYPE(conf23xx) != OCTEON_64BYTE_INSTR) {
  1115. dev_err(&oct->pci_dev->dev, "%s: Invalid instr type for IQ\n",
  1116. __func__);
  1117. return 1;
  1118. }
  1119. if (!(CFG_GET_OQ_INFO_PTR(conf23xx)) ||
  1120. !(CFG_GET_OQ_REFILL_THRESHOLD(conf23xx))) {
  1121. dev_err(&oct->pci_dev->dev, "%s: Invalid parameter for OQ\n",
  1122. __func__);
  1123. return 1;
  1124. }
  1125. if (!(CFG_GET_OQ_INTR_TIME(conf23xx))) {
  1126. dev_err(&oct->pci_dev->dev, "%s: Invalid parameter for OQ\n",
  1127. __func__);
  1128. return 1;
  1129. }
  1130. return 0;
  1131. }
  1132. void cn23xx_dump_iq_regs(struct octeon_device *oct)
  1133. {
  1134. u32 regval, q_no;
  1135. dev_dbg(&oct->pci_dev->dev, "SLI_IQ_DOORBELL_0 [0x%x]: 0x%016llx\n",
  1136. CN23XX_SLI_IQ_DOORBELL(0),
  1137. CVM_CAST64(octeon_read_csr64
  1138. (oct, CN23XX_SLI_IQ_DOORBELL(0))));
  1139. dev_dbg(&oct->pci_dev->dev, "SLI_IQ_BASEADDR_0 [0x%x]: 0x%016llx\n",
  1140. CN23XX_SLI_IQ_BASE_ADDR64(0),
  1141. CVM_CAST64(octeon_read_csr64
  1142. (oct, CN23XX_SLI_IQ_BASE_ADDR64(0))));
  1143. dev_dbg(&oct->pci_dev->dev, "SLI_IQ_FIFO_RSIZE_0 [0x%x]: 0x%016llx\n",
  1144. CN23XX_SLI_IQ_SIZE(0),
  1145. CVM_CAST64(octeon_read_csr64(oct, CN23XX_SLI_IQ_SIZE(0))));
  1146. dev_dbg(&oct->pci_dev->dev, "SLI_CTL_STATUS [0x%x]: 0x%016llx\n",
  1147. CN23XX_SLI_CTL_STATUS,
  1148. CVM_CAST64(octeon_read_csr64(oct, CN23XX_SLI_CTL_STATUS)));
  1149. for (q_no = 0; q_no < CN23XX_MAX_INPUT_QUEUES; q_no++) {
  1150. dev_dbg(&oct->pci_dev->dev, "SLI_PKT[%d]_INPUT_CTL [0x%x]: 0x%016llx\n",
  1151. q_no, CN23XX_SLI_IQ_PKT_CONTROL64(q_no),
  1152. CVM_CAST64(octeon_read_csr64
  1153. (oct, CN23XX_SLI_IQ_PKT_CONTROL64(q_no))));
  1154. }
  1155. pci_read_config_dword(oct->pci_dev, CN23XX_CONFIG_PCIE_DEVCTL, &regval);
  1156. dev_dbg(&oct->pci_dev->dev, "Config DevCtl [0x%x]: 0x%08x\n",
  1157. CN23XX_CONFIG_PCIE_DEVCTL, regval);
  1158. dev_dbg(&oct->pci_dev->dev, "SLI_PRT[%d]_CFG [0x%llx]: 0x%016llx\n",
  1159. oct->pcie_port, CN23XX_DPI_SLI_PRTX_CFG(oct->pcie_port),
  1160. CVM_CAST64(lio_pci_readq(
  1161. oct, CN23XX_DPI_SLI_PRTX_CFG(oct->pcie_port))));
  1162. dev_dbg(&oct->pci_dev->dev, "SLI_S2M_PORT[%d]_CTL [0x%x]: 0x%016llx\n",
  1163. oct->pcie_port, CN23XX_SLI_S2M_PORTX_CTL(oct->pcie_port),
  1164. CVM_CAST64(octeon_read_csr64(
  1165. oct, CN23XX_SLI_S2M_PORTX_CTL(oct->pcie_port))));
  1166. }
  1167. int cn23xx_fw_loaded(struct octeon_device *oct)
  1168. {
  1169. u64 val;
  1170. val = octeon_read_csr64(oct, CN23XX_SLI_SCRATCH1);
  1171. return (val >> 1) & 1ULL;
  1172. }
  1173. void cn23xx_tell_vf_its_macaddr_changed(struct octeon_device *oct, int vfidx,
  1174. u8 *mac)
  1175. {
  1176. if (oct->sriov_info.vf_drv_loaded_mask & BIT_ULL(vfidx)) {
  1177. struct octeon_mbox_cmd mbox_cmd;
  1178. mbox_cmd.msg.u64 = 0;
  1179. mbox_cmd.msg.s.type = OCTEON_MBOX_REQUEST;
  1180. mbox_cmd.msg.s.resp_needed = 0;
  1181. mbox_cmd.msg.s.cmd = OCTEON_PF_CHANGED_VF_MACADDR;
  1182. mbox_cmd.msg.s.len = 1;
  1183. mbox_cmd.recv_len = 0;
  1184. mbox_cmd.recv_status = 0;
  1185. mbox_cmd.fn = NULL;
  1186. mbox_cmd.fn_arg = 0;
  1187. ether_addr_copy(mbox_cmd.msg.s.params, mac);
  1188. mbox_cmd.q_no = vfidx * oct->sriov_info.rings_per_vf;
  1189. octeon_mbox_write(oct, &mbox_cmd);
  1190. }
  1191. }