cn23xx_pf_device.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512
  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)) {
  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. /* clear IPTR */
  419. reg_val &= ~CN23XX_PKT_OUTPUT_CTL_IPTR;
  420. /* set DPTR */
  421. reg_val |= CN23XX_PKT_OUTPUT_CTL_DPTR;
  422. /* reset BMODE */
  423. reg_val &= ~(CN23XX_PKT_OUTPUT_CTL_BMODE);
  424. /* No Relaxed Ordering, No Snoop, 64-bit Byte swap
  425. * for Output Queue ScatterList
  426. * reset ROR_P, NSR_P
  427. */
  428. reg_val &= ~(CN23XX_PKT_OUTPUT_CTL_ROR_P);
  429. reg_val &= ~(CN23XX_PKT_OUTPUT_CTL_NSR_P);
  430. #ifdef __LITTLE_ENDIAN_BITFIELD
  431. reg_val &= ~(CN23XX_PKT_OUTPUT_CTL_ES_P);
  432. #else
  433. reg_val |= (CN23XX_PKT_OUTPUT_CTL_ES_P);
  434. #endif
  435. /* No Relaxed Ordering, No Snoop, 64-bit Byte swap
  436. * for Output Queue Data
  437. * reset ROR, NSR
  438. */
  439. reg_val &= ~(CN23XX_PKT_OUTPUT_CTL_ROR);
  440. reg_val &= ~(CN23XX_PKT_OUTPUT_CTL_NSR);
  441. /* set the ES bit */
  442. reg_val |= (CN23XX_PKT_OUTPUT_CTL_ES);
  443. /* write all the selected settings */
  444. octeon_write_csr(oct, CN23XX_SLI_OQ_PKT_CONTROL(q_no), reg_val);
  445. /* Enabling these interrupt in oct->fn_list.enable_interrupt()
  446. * routine which called after IOQ init.
  447. * Set up interrupt packet and time thresholds
  448. * for all the OQs
  449. */
  450. time_threshold = cn23xx_pf_get_oq_ticks(
  451. oct, (u32)CFG_GET_OQ_INTR_TIME(cn23xx->conf));
  452. octeon_write_csr64(oct, CN23XX_SLI_OQ_PKT_INT_LEVELS(q_no),
  453. (CFG_GET_OQ_INTR_PKT(cn23xx->conf) |
  454. (time_threshold << 32)));
  455. }
  456. /** Setting the water mark level for pko back pressure **/
  457. writeq(0x40, (u8 *)oct->mmio[0].hw_addr + CN23XX_SLI_OQ_WMARK);
  458. /** Disabling setting OQs in reset when ring has no dorebells
  459. * enabling this will cause of head of line blocking
  460. */
  461. /* Do it only for pass1.1. and pass1.2 */
  462. if ((oct->rev_id == OCTEON_CN23XX_REV_1_0) ||
  463. (oct->rev_id == OCTEON_CN23XX_REV_1_1))
  464. writeq(readq((u8 *)oct->mmio[0].hw_addr +
  465. CN23XX_SLI_GBL_CONTROL) | 0x2,
  466. (u8 *)oct->mmio[0].hw_addr + CN23XX_SLI_GBL_CONTROL);
  467. /** Enable channel-level backpressure */
  468. if (oct->pf_num)
  469. writeq(0xffffffffffffffffULL,
  470. (u8 *)oct->mmio[0].hw_addr + CN23XX_SLI_OUT_BP_EN2_W1S);
  471. else
  472. writeq(0xffffffffffffffffULL,
  473. (u8 *)oct->mmio[0].hw_addr + CN23XX_SLI_OUT_BP_EN_W1S);
  474. }
  475. static int cn23xx_setup_pf_device_regs(struct octeon_device *oct)
  476. {
  477. cn23xx_enable_error_reporting(oct);
  478. /* program the MAC(0..3)_RINFO before setting up input/output regs */
  479. cn23xx_setup_global_mac_regs(oct);
  480. if (cn23xx_pf_setup_global_input_regs(oct))
  481. return -1;
  482. cn23xx_pf_setup_global_output_regs(oct);
  483. /* Default error timeout value should be 0x200000 to avoid host hang
  484. * when reads invalid register
  485. */
  486. octeon_write_csr64(oct, CN23XX_SLI_WINDOW_CTL,
  487. CN23XX_SLI_WINDOW_CTL_DEFAULT);
  488. /* set SLI_PKT_IN_JABBER to handle large VXLAN packets */
  489. octeon_write_csr64(oct, CN23XX_SLI_PKT_IN_JABBER, CN23XX_INPUT_JABBER);
  490. return 0;
  491. }
  492. static void cn23xx_setup_iq_regs(struct octeon_device *oct, u32 iq_no)
  493. {
  494. struct octeon_instr_queue *iq = oct->instr_queue[iq_no];
  495. u64 pkt_in_done;
  496. iq_no += oct->sriov_info.pf_srn;
  497. /* Write the start of the input queue's ring and its size */
  498. octeon_write_csr64(oct, CN23XX_SLI_IQ_BASE_ADDR64(iq_no),
  499. iq->base_addr_dma);
  500. octeon_write_csr(oct, CN23XX_SLI_IQ_SIZE(iq_no), iq->max_count);
  501. /* Remember the doorbell & instruction count register addr
  502. * for this queue
  503. */
  504. iq->doorbell_reg =
  505. (u8 *)oct->mmio[0].hw_addr + CN23XX_SLI_IQ_DOORBELL(iq_no);
  506. iq->inst_cnt_reg =
  507. (u8 *)oct->mmio[0].hw_addr + CN23XX_SLI_IQ_INSTR_COUNT64(iq_no);
  508. dev_dbg(&oct->pci_dev->dev, "InstQ[%d]:dbell reg @ 0x%p instcnt_reg @ 0x%p\n",
  509. iq_no, iq->doorbell_reg, iq->inst_cnt_reg);
  510. /* Store the current instruction counter (used in flush_iq
  511. * calculation)
  512. */
  513. pkt_in_done = readq(iq->inst_cnt_reg);
  514. if (oct->msix_on) {
  515. /* Set CINT_ENB to enable IQ interrupt */
  516. writeq((pkt_in_done | CN23XX_INTR_CINT_ENB),
  517. iq->inst_cnt_reg);
  518. } else {
  519. /* Clear the count by writing back what we read, but don't
  520. * enable interrupts
  521. */
  522. writeq(pkt_in_done, iq->inst_cnt_reg);
  523. }
  524. iq->reset_instr_cnt = 0;
  525. }
  526. static void cn23xx_setup_oq_regs(struct octeon_device *oct, u32 oq_no)
  527. {
  528. u32 reg_val;
  529. struct octeon_droq *droq = oct->droq[oq_no];
  530. struct octeon_cn23xx_pf *cn23xx = (struct octeon_cn23xx_pf *)oct->chip;
  531. u64 time_threshold;
  532. u64 cnt_threshold;
  533. oq_no += oct->sriov_info.pf_srn;
  534. octeon_write_csr64(oct, CN23XX_SLI_OQ_BASE_ADDR64(oq_no),
  535. droq->desc_ring_dma);
  536. octeon_write_csr(oct, CN23XX_SLI_OQ_SIZE(oq_no), droq->max_count);
  537. octeon_write_csr(oct, CN23XX_SLI_OQ_BUFF_INFO_SIZE(oq_no),
  538. droq->buffer_size);
  539. /* Get the mapped address of the pkt_sent and pkts_credit regs */
  540. droq->pkts_sent_reg =
  541. (u8 *)oct->mmio[0].hw_addr + CN23XX_SLI_OQ_PKTS_SENT(oq_no);
  542. droq->pkts_credit_reg =
  543. (u8 *)oct->mmio[0].hw_addr + CN23XX_SLI_OQ_PKTS_CREDIT(oq_no);
  544. if (!oct->msix_on) {
  545. /* Enable this output queue to generate Packet Timer Interrupt
  546. */
  547. reg_val =
  548. octeon_read_csr(oct, CN23XX_SLI_OQ_PKT_CONTROL(oq_no));
  549. reg_val |= CN23XX_PKT_OUTPUT_CTL_TENB;
  550. octeon_write_csr(oct, CN23XX_SLI_OQ_PKT_CONTROL(oq_no),
  551. reg_val);
  552. /* Enable this output queue to generate Packet Count Interrupt
  553. */
  554. reg_val =
  555. octeon_read_csr(oct, CN23XX_SLI_OQ_PKT_CONTROL(oq_no));
  556. reg_val |= CN23XX_PKT_OUTPUT_CTL_CENB;
  557. octeon_write_csr(oct, CN23XX_SLI_OQ_PKT_CONTROL(oq_no),
  558. reg_val);
  559. } else {
  560. time_threshold = cn23xx_pf_get_oq_ticks(
  561. oct, (u32)CFG_GET_OQ_INTR_TIME(cn23xx->conf));
  562. cnt_threshold = (u32)CFG_GET_OQ_INTR_PKT(cn23xx->conf);
  563. octeon_write_csr64(
  564. oct, CN23XX_SLI_OQ_PKT_INT_LEVELS(oq_no),
  565. ((time_threshold << 32 | cnt_threshold)));
  566. }
  567. }
  568. static void cn23xx_pf_mbox_thread(struct work_struct *work)
  569. {
  570. struct cavium_wk *wk = (struct cavium_wk *)work;
  571. struct octeon_mbox *mbox = (struct octeon_mbox *)wk->ctxptr;
  572. struct octeon_device *oct = mbox->oct_dev;
  573. u64 mbox_int_val, val64;
  574. u32 q_no, i;
  575. if (oct->rev_id < OCTEON_CN23XX_REV_1_1) {
  576. /*read and clear by writing 1*/
  577. mbox_int_val = readq(mbox->mbox_int_reg);
  578. writeq(mbox_int_val, mbox->mbox_int_reg);
  579. for (i = 0; i < oct->sriov_info.num_vfs_alloced; i++) {
  580. q_no = i * oct->sriov_info.rings_per_vf;
  581. val64 = readq(oct->mbox[q_no]->mbox_write_reg);
  582. if (val64 && (val64 != OCTEON_PFVFACK)) {
  583. if (octeon_mbox_read(oct->mbox[q_no]))
  584. octeon_mbox_process_message(
  585. oct->mbox[q_no]);
  586. }
  587. }
  588. schedule_delayed_work(&wk->work, msecs_to_jiffies(10));
  589. } else {
  590. octeon_mbox_process_message(mbox);
  591. }
  592. }
  593. static int cn23xx_setup_pf_mbox(struct octeon_device *oct)
  594. {
  595. struct octeon_mbox *mbox = NULL;
  596. u16 mac_no = oct->pcie_port;
  597. u16 pf_num = oct->pf_num;
  598. u32 q_no, i;
  599. if (!oct->sriov_info.max_vfs)
  600. return 0;
  601. for (i = 0; i < oct->sriov_info.max_vfs; i++) {
  602. q_no = i * oct->sriov_info.rings_per_vf;
  603. mbox = vmalloc(sizeof(*mbox));
  604. if (!mbox)
  605. goto free_mbox;
  606. memset(mbox, 0, sizeof(struct octeon_mbox));
  607. spin_lock_init(&mbox->lock);
  608. mbox->oct_dev = oct;
  609. mbox->q_no = q_no;
  610. mbox->state = OCTEON_MBOX_STATE_IDLE;
  611. /* PF mbox interrupt reg */
  612. mbox->mbox_int_reg = (u8 *)oct->mmio[0].hw_addr +
  613. CN23XX_SLI_MAC_PF_MBOX_INT(mac_no, pf_num);
  614. /* PF writes into SIG0 reg */
  615. mbox->mbox_write_reg = (u8 *)oct->mmio[0].hw_addr +
  616. CN23XX_SLI_PKT_PF_VF_MBOX_SIG(q_no, 0);
  617. /* PF reads from SIG1 reg */
  618. mbox->mbox_read_reg = (u8 *)oct->mmio[0].hw_addr +
  619. CN23XX_SLI_PKT_PF_VF_MBOX_SIG(q_no, 1);
  620. /*Mail Box Thread creation*/
  621. INIT_DELAYED_WORK(&mbox->mbox_poll_wk.work,
  622. cn23xx_pf_mbox_thread);
  623. mbox->mbox_poll_wk.ctxptr = (void *)mbox;
  624. oct->mbox[q_no] = mbox;
  625. writeq(OCTEON_PFVFSIG, mbox->mbox_read_reg);
  626. }
  627. if (oct->rev_id < OCTEON_CN23XX_REV_1_1)
  628. schedule_delayed_work(&oct->mbox[0]->mbox_poll_wk.work,
  629. msecs_to_jiffies(0));
  630. return 0;
  631. free_mbox:
  632. while (i) {
  633. i--;
  634. vfree(oct->mbox[i]);
  635. }
  636. return 1;
  637. }
  638. static int cn23xx_free_pf_mbox(struct octeon_device *oct)
  639. {
  640. u32 q_no, i;
  641. if (!oct->sriov_info.max_vfs)
  642. return 0;
  643. for (i = 0; i < oct->sriov_info.max_vfs; i++) {
  644. q_no = i * oct->sriov_info.rings_per_vf;
  645. cancel_delayed_work_sync(
  646. &oct->mbox[q_no]->mbox_poll_wk.work);
  647. vfree(oct->mbox[q_no]);
  648. }
  649. return 0;
  650. }
  651. static int cn23xx_enable_io_queues(struct octeon_device *oct)
  652. {
  653. u64 reg_val;
  654. u32 srn, ern, q_no;
  655. u32 loop = 1000;
  656. srn = oct->sriov_info.pf_srn;
  657. ern = srn + oct->num_iqs;
  658. for (q_no = srn; q_no < ern; q_no++) {
  659. /* set the corresponding IQ IS_64B bit */
  660. if (oct->io_qmask.iq64B & BIT_ULL(q_no - srn)) {
  661. reg_val = octeon_read_csr64(
  662. oct, CN23XX_SLI_IQ_PKT_CONTROL64(q_no));
  663. reg_val = reg_val | CN23XX_PKT_INPUT_CTL_IS_64B;
  664. octeon_write_csr64(
  665. oct, CN23XX_SLI_IQ_PKT_CONTROL64(q_no), reg_val);
  666. }
  667. /* set the corresponding IQ ENB bit */
  668. if (oct->io_qmask.iq & BIT_ULL(q_no - srn)) {
  669. /* IOQs are in reset by default in PEM2 mode,
  670. * clearing reset bit
  671. */
  672. reg_val = octeon_read_csr64(
  673. oct, CN23XX_SLI_IQ_PKT_CONTROL64(q_no));
  674. if (reg_val & CN23XX_PKT_INPUT_CTL_RST) {
  675. while ((reg_val & CN23XX_PKT_INPUT_CTL_RST) &&
  676. !(reg_val &
  677. CN23XX_PKT_INPUT_CTL_QUIET) &&
  678. --loop) {
  679. reg_val = octeon_read_csr64(
  680. oct,
  681. CN23XX_SLI_IQ_PKT_CONTROL64(q_no));
  682. }
  683. if (!loop) {
  684. dev_err(&oct->pci_dev->dev,
  685. "clearing the reset reg failed or setting the quiet reg failed for qno: %u\n",
  686. q_no);
  687. return -1;
  688. }
  689. reg_val = reg_val & ~CN23XX_PKT_INPUT_CTL_RST;
  690. octeon_write_csr64(
  691. oct, CN23XX_SLI_IQ_PKT_CONTROL64(q_no),
  692. reg_val);
  693. reg_val = octeon_read_csr64(
  694. oct, CN23XX_SLI_IQ_PKT_CONTROL64(q_no));
  695. if (reg_val & CN23XX_PKT_INPUT_CTL_RST) {
  696. dev_err(&oct->pci_dev->dev,
  697. "clearing the reset failed for qno: %u\n",
  698. q_no);
  699. return -1;
  700. }
  701. }
  702. reg_val = octeon_read_csr64(
  703. oct, CN23XX_SLI_IQ_PKT_CONTROL64(q_no));
  704. reg_val = reg_val | CN23XX_PKT_INPUT_CTL_RING_ENB;
  705. octeon_write_csr64(
  706. oct, CN23XX_SLI_IQ_PKT_CONTROL64(q_no), reg_val);
  707. }
  708. }
  709. for (q_no = srn; q_no < ern; q_no++) {
  710. u32 reg_val;
  711. /* set the corresponding OQ ENB bit */
  712. if (oct->io_qmask.oq & BIT_ULL(q_no - srn)) {
  713. reg_val = octeon_read_csr(
  714. oct, CN23XX_SLI_OQ_PKT_CONTROL(q_no));
  715. reg_val = reg_val | CN23XX_PKT_OUTPUT_CTL_RING_ENB;
  716. octeon_write_csr(oct, CN23XX_SLI_OQ_PKT_CONTROL(q_no),
  717. reg_val);
  718. }
  719. }
  720. return 0;
  721. }
  722. static void cn23xx_disable_io_queues(struct octeon_device *oct)
  723. {
  724. int q_no, loop;
  725. u64 d64;
  726. u32 d32;
  727. u32 srn, ern;
  728. srn = oct->sriov_info.pf_srn;
  729. ern = srn + oct->num_iqs;
  730. /*** Disable Input Queues. ***/
  731. for (q_no = srn; q_no < ern; q_no++) {
  732. loop = HZ;
  733. /* start the Reset for a particular ring */
  734. WRITE_ONCE(d64, octeon_read_csr64(
  735. oct, CN23XX_SLI_IQ_PKT_CONTROL64(q_no)));
  736. WRITE_ONCE(d64, READ_ONCE(d64) &
  737. (~(CN23XX_PKT_INPUT_CTL_RING_ENB)));
  738. WRITE_ONCE(d64, READ_ONCE(d64) | CN23XX_PKT_INPUT_CTL_RST);
  739. octeon_write_csr64(oct, CN23XX_SLI_IQ_PKT_CONTROL64(q_no),
  740. READ_ONCE(d64));
  741. /* Wait until hardware indicates that the particular IQ
  742. * is out of reset.
  743. */
  744. WRITE_ONCE(d64, octeon_read_csr64(
  745. oct, CN23XX_SLI_PKT_IOQ_RING_RST));
  746. while (!(READ_ONCE(d64) & BIT_ULL(q_no)) && loop--) {
  747. WRITE_ONCE(d64, octeon_read_csr64(
  748. oct, CN23XX_SLI_PKT_IOQ_RING_RST));
  749. schedule_timeout_uninterruptible(1);
  750. }
  751. /* Reset the doorbell register for this Input Queue. */
  752. octeon_write_csr(oct, CN23XX_SLI_IQ_DOORBELL(q_no), 0xFFFFFFFF);
  753. while (octeon_read_csr64(oct, CN23XX_SLI_IQ_DOORBELL(q_no)) &&
  754. loop--) {
  755. schedule_timeout_uninterruptible(1);
  756. }
  757. }
  758. /*** Disable Output Queues. ***/
  759. for (q_no = srn; q_no < ern; q_no++) {
  760. loop = HZ;
  761. /* Wait until hardware indicates that the particular IQ
  762. * is out of reset.It given that SLI_PKT_RING_RST is
  763. * common for both IQs and OQs
  764. */
  765. WRITE_ONCE(d64, octeon_read_csr64(
  766. oct, CN23XX_SLI_PKT_IOQ_RING_RST));
  767. while (!(READ_ONCE(d64) & BIT_ULL(q_no)) && loop--) {
  768. WRITE_ONCE(d64, octeon_read_csr64(
  769. oct, CN23XX_SLI_PKT_IOQ_RING_RST));
  770. schedule_timeout_uninterruptible(1);
  771. }
  772. /* Reset the doorbell register for this Output Queue. */
  773. octeon_write_csr(oct, CN23XX_SLI_OQ_PKTS_CREDIT(q_no),
  774. 0xFFFFFFFF);
  775. while (octeon_read_csr64(oct,
  776. CN23XX_SLI_OQ_PKTS_CREDIT(q_no)) &&
  777. loop--) {
  778. schedule_timeout_uninterruptible(1);
  779. }
  780. /* clear the SLI_PKT(0..63)_CNTS[CNT] reg value */
  781. WRITE_ONCE(d32, octeon_read_csr(
  782. oct, CN23XX_SLI_OQ_PKTS_SENT(q_no)));
  783. octeon_write_csr(oct, CN23XX_SLI_OQ_PKTS_SENT(q_no),
  784. READ_ONCE(d32));
  785. }
  786. }
  787. static u64 cn23xx_pf_msix_interrupt_handler(void *dev)
  788. {
  789. struct octeon_ioq_vector *ioq_vector = (struct octeon_ioq_vector *)dev;
  790. struct octeon_device *oct = ioq_vector->oct_dev;
  791. u64 pkts_sent;
  792. u64 ret = 0;
  793. struct octeon_droq *droq = oct->droq[ioq_vector->droq_index];
  794. dev_dbg(&oct->pci_dev->dev, "In %s octeon_dev @ %p\n", __func__, oct);
  795. if (!droq) {
  796. dev_err(&oct->pci_dev->dev, "23XX bringup FIXME: oct pfnum:%d ioq_vector->ioq_num :%d droq is NULL\n",
  797. oct->pf_num, ioq_vector->ioq_num);
  798. return 0;
  799. }
  800. pkts_sent = readq(droq->pkts_sent_reg);
  801. /* If our device has interrupted, then proceed. Also check
  802. * for all f's if interrupt was triggered on an error
  803. * and the PCI read fails.
  804. */
  805. if (!pkts_sent || (pkts_sent == 0xFFFFFFFFFFFFFFFFULL))
  806. return ret;
  807. /* Write count reg in sli_pkt_cnts to clear these int.*/
  808. if ((pkts_sent & CN23XX_INTR_PO_INT) ||
  809. (pkts_sent & CN23XX_INTR_PI_INT)) {
  810. if (pkts_sent & CN23XX_INTR_PO_INT)
  811. ret |= MSIX_PO_INT;
  812. }
  813. if (pkts_sent & CN23XX_INTR_PI_INT)
  814. /* We will clear the count when we update the read_index. */
  815. ret |= MSIX_PI_INT;
  816. /* Never need to handle msix mbox intr for pf. They arrive on the last
  817. * msix
  818. */
  819. return ret;
  820. }
  821. static void cn23xx_handle_pf_mbox_intr(struct octeon_device *oct)
  822. {
  823. struct delayed_work *work;
  824. u64 mbox_int_val;
  825. u32 i, q_no;
  826. mbox_int_val = readq(oct->mbox[0]->mbox_int_reg);
  827. for (i = 0; i < oct->sriov_info.num_vfs_alloced; i++) {
  828. q_no = i * oct->sriov_info.rings_per_vf;
  829. if (mbox_int_val & BIT_ULL(q_no)) {
  830. writeq(BIT_ULL(q_no),
  831. oct->mbox[0]->mbox_int_reg);
  832. if (octeon_mbox_read(oct->mbox[q_no])) {
  833. work = &oct->mbox[q_no]->mbox_poll_wk.work;
  834. schedule_delayed_work(work,
  835. msecs_to_jiffies(0));
  836. }
  837. }
  838. }
  839. }
  840. static irqreturn_t cn23xx_interrupt_handler(void *dev)
  841. {
  842. struct octeon_device *oct = (struct octeon_device *)dev;
  843. struct octeon_cn23xx_pf *cn23xx = (struct octeon_cn23xx_pf *)oct->chip;
  844. u64 intr64;
  845. dev_dbg(&oct->pci_dev->dev, "In %s octeon_dev @ %p\n", __func__, oct);
  846. intr64 = readq(cn23xx->intr_sum_reg64);
  847. oct->int_status = 0;
  848. if (intr64 & CN23XX_INTR_ERR)
  849. dev_err(&oct->pci_dev->dev, "OCTEON[%d]: Error Intr: 0x%016llx\n",
  850. oct->octeon_id, CVM_CAST64(intr64));
  851. /* When VFs write into MBOX_SIG2 reg,these intr is set in PF */
  852. if (intr64 & CN23XX_INTR_VF_MBOX)
  853. cn23xx_handle_pf_mbox_intr(oct);
  854. if (oct->msix_on != LIO_FLAG_MSIX_ENABLED) {
  855. if (intr64 & CN23XX_INTR_PKT_DATA)
  856. oct->int_status |= OCT_DEV_INTR_PKT_DATA;
  857. }
  858. if (intr64 & (CN23XX_INTR_DMA0_FORCE))
  859. oct->int_status |= OCT_DEV_INTR_DMA0_FORCE;
  860. if (intr64 & (CN23XX_INTR_DMA1_FORCE))
  861. oct->int_status |= OCT_DEV_INTR_DMA1_FORCE;
  862. /* Clear the current interrupts */
  863. writeq(intr64, cn23xx->intr_sum_reg64);
  864. return IRQ_HANDLED;
  865. }
  866. static void cn23xx_bar1_idx_setup(struct octeon_device *oct, u64 core_addr,
  867. u32 idx, int valid)
  868. {
  869. u64 bar1;
  870. u64 reg_adr;
  871. if (!valid) {
  872. reg_adr = lio_pci_readq(
  873. oct, CN23XX_PEM_BAR1_INDEX_REG(oct->pcie_port, idx));
  874. WRITE_ONCE(bar1, reg_adr);
  875. lio_pci_writeq(oct, (READ_ONCE(bar1) & 0xFFFFFFFEULL),
  876. CN23XX_PEM_BAR1_INDEX_REG(oct->pcie_port, idx));
  877. reg_adr = lio_pci_readq(
  878. oct, CN23XX_PEM_BAR1_INDEX_REG(oct->pcie_port, idx));
  879. WRITE_ONCE(bar1, reg_adr);
  880. return;
  881. }
  882. /* The PEM(0..3)_BAR1_INDEX(0..15)[ADDR_IDX]<23:4> stores
  883. * bits <41:22> of the Core Addr
  884. */
  885. lio_pci_writeq(oct, (((core_addr >> 22) << 4) | PCI_BAR1_MASK),
  886. CN23XX_PEM_BAR1_INDEX_REG(oct->pcie_port, idx));
  887. WRITE_ONCE(bar1, lio_pci_readq(
  888. oct, CN23XX_PEM_BAR1_INDEX_REG(oct->pcie_port, idx)));
  889. }
  890. static void cn23xx_bar1_idx_write(struct octeon_device *oct, u32 idx, u32 mask)
  891. {
  892. lio_pci_writeq(oct, mask,
  893. CN23XX_PEM_BAR1_INDEX_REG(oct->pcie_port, idx));
  894. }
  895. static u32 cn23xx_bar1_idx_read(struct octeon_device *oct, u32 idx)
  896. {
  897. return (u32)lio_pci_readq(
  898. oct, CN23XX_PEM_BAR1_INDEX_REG(oct->pcie_port, idx));
  899. }
  900. /* always call with lock held */
  901. static u32 cn23xx_update_read_index(struct octeon_instr_queue *iq)
  902. {
  903. u32 new_idx;
  904. u32 last_done;
  905. u32 pkt_in_done = readl(iq->inst_cnt_reg);
  906. last_done = pkt_in_done - iq->pkt_in_done;
  907. iq->pkt_in_done = pkt_in_done;
  908. /* Modulo of the new index with the IQ size will give us
  909. * the new index. The iq->reset_instr_cnt is always zero for
  910. * cn23xx, so no extra adjustments are needed.
  911. */
  912. new_idx = (iq->octeon_read_index +
  913. (u32)(last_done & CN23XX_PKT_IN_DONE_CNT_MASK)) %
  914. iq->max_count;
  915. return new_idx;
  916. }
  917. static void cn23xx_enable_pf_interrupt(struct octeon_device *oct, u8 intr_flag)
  918. {
  919. struct octeon_cn23xx_pf *cn23xx = (struct octeon_cn23xx_pf *)oct->chip;
  920. u64 intr_val = 0;
  921. /* Divide the single write to multiple writes based on the flag. */
  922. /* Enable Interrupt */
  923. if (intr_flag == OCTEON_ALL_INTR) {
  924. writeq(cn23xx->intr_mask64, cn23xx->intr_enb_reg64);
  925. } else if (intr_flag & OCTEON_OUTPUT_INTR) {
  926. intr_val = readq(cn23xx->intr_enb_reg64);
  927. intr_val |= CN23XX_INTR_PKT_DATA;
  928. writeq(intr_val, cn23xx->intr_enb_reg64);
  929. } else if ((intr_flag & OCTEON_MBOX_INTR) &&
  930. (oct->sriov_info.max_vfs > 0)) {
  931. if (oct->rev_id >= OCTEON_CN23XX_REV_1_1) {
  932. intr_val = readq(cn23xx->intr_enb_reg64);
  933. intr_val |= CN23XX_INTR_VF_MBOX;
  934. writeq(intr_val, cn23xx->intr_enb_reg64);
  935. }
  936. }
  937. }
  938. static void cn23xx_disable_pf_interrupt(struct octeon_device *oct, u8 intr_flag)
  939. {
  940. struct octeon_cn23xx_pf *cn23xx = (struct octeon_cn23xx_pf *)oct->chip;
  941. u64 intr_val = 0;
  942. /* Disable Interrupts */
  943. if (intr_flag == OCTEON_ALL_INTR) {
  944. writeq(0, cn23xx->intr_enb_reg64);
  945. } else if (intr_flag & OCTEON_OUTPUT_INTR) {
  946. intr_val = readq(cn23xx->intr_enb_reg64);
  947. intr_val &= ~CN23XX_INTR_PKT_DATA;
  948. writeq(intr_val, cn23xx->intr_enb_reg64);
  949. } else if ((intr_flag & OCTEON_MBOX_INTR) &&
  950. (oct->sriov_info.max_vfs > 0)) {
  951. if (oct->rev_id >= OCTEON_CN23XX_REV_1_1) {
  952. intr_val = readq(cn23xx->intr_enb_reg64);
  953. intr_val &= ~CN23XX_INTR_VF_MBOX;
  954. writeq(intr_val, cn23xx->intr_enb_reg64);
  955. }
  956. }
  957. }
  958. static void cn23xx_get_pcie_qlmport(struct octeon_device *oct)
  959. {
  960. oct->pcie_port = (octeon_read_csr(oct, CN23XX_SLI_MAC_NUMBER)) & 0xff;
  961. dev_dbg(&oct->pci_dev->dev, "OCTEON: CN23xx uses PCIE Port %d\n",
  962. oct->pcie_port);
  963. }
  964. static int cn23xx_get_pf_num(struct octeon_device *oct)
  965. {
  966. u32 fdl_bit = 0;
  967. u64 pkt0_in_ctl, d64;
  968. int pfnum, mac, trs, ret;
  969. ret = 0;
  970. /** Read Function Dependency Link reg to get the function number */
  971. if (pci_read_config_dword(oct->pci_dev, CN23XX_PCIE_SRIOV_FDL,
  972. &fdl_bit) == 0) {
  973. oct->pf_num = ((fdl_bit >> CN23XX_PCIE_SRIOV_FDL_BIT_POS) &
  974. CN23XX_PCIE_SRIOV_FDL_MASK);
  975. } else {
  976. ret = -EINVAL;
  977. /* Under some virtual environments, extended PCI regs are
  978. * inaccessible, in which case the above read will have failed.
  979. * In this case, read the PF number from the
  980. * SLI_PKT0_INPUT_CONTROL reg (written by f/w)
  981. */
  982. pkt0_in_ctl = octeon_read_csr64(oct,
  983. CN23XX_SLI_IQ_PKT_CONTROL64(0));
  984. pfnum = (pkt0_in_ctl >> CN23XX_PKT_INPUT_CTL_PF_NUM_POS) &
  985. CN23XX_PKT_INPUT_CTL_PF_NUM_MASK;
  986. mac = (octeon_read_csr(oct, CN23XX_SLI_MAC_NUMBER)) & 0xff;
  987. /* validate PF num by reading RINFO; f/w writes RINFO.trs == 1*/
  988. d64 = octeon_read_csr64(oct,
  989. CN23XX_SLI_PKT_MAC_RINFO64(mac, pfnum));
  990. trs = (int)(d64 >> CN23XX_PKT_MAC_CTL_RINFO_TRS_BIT_POS) & 0xff;
  991. if (trs == 1) {
  992. dev_err(&oct->pci_dev->dev,
  993. "OCTEON: error reading PCI cfg space pfnum, re-read %u\n",
  994. pfnum);
  995. oct->pf_num = pfnum;
  996. ret = 0;
  997. } else {
  998. dev_err(&oct->pci_dev->dev,
  999. "OCTEON: error reading PCI cfg space pfnum; could not ascertain PF number\n");
  1000. }
  1001. }
  1002. return ret;
  1003. }
  1004. static void cn23xx_setup_reg_address(struct octeon_device *oct)
  1005. {
  1006. u8 __iomem *bar0_pciaddr = oct->mmio[0].hw_addr;
  1007. struct octeon_cn23xx_pf *cn23xx = (struct octeon_cn23xx_pf *)oct->chip;
  1008. oct->reg_list.pci_win_wr_addr_hi =
  1009. (u32 __iomem *)(bar0_pciaddr + CN23XX_WIN_WR_ADDR_HI);
  1010. oct->reg_list.pci_win_wr_addr_lo =
  1011. (u32 __iomem *)(bar0_pciaddr + CN23XX_WIN_WR_ADDR_LO);
  1012. oct->reg_list.pci_win_wr_addr =
  1013. (u64 __iomem *)(bar0_pciaddr + CN23XX_WIN_WR_ADDR64);
  1014. oct->reg_list.pci_win_rd_addr_hi =
  1015. (u32 __iomem *)(bar0_pciaddr + CN23XX_WIN_RD_ADDR_HI);
  1016. oct->reg_list.pci_win_rd_addr_lo =
  1017. (u32 __iomem *)(bar0_pciaddr + CN23XX_WIN_RD_ADDR_LO);
  1018. oct->reg_list.pci_win_rd_addr =
  1019. (u64 __iomem *)(bar0_pciaddr + CN23XX_WIN_RD_ADDR64);
  1020. oct->reg_list.pci_win_wr_data_hi =
  1021. (u32 __iomem *)(bar0_pciaddr + CN23XX_WIN_WR_DATA_HI);
  1022. oct->reg_list.pci_win_wr_data_lo =
  1023. (u32 __iomem *)(bar0_pciaddr + CN23XX_WIN_WR_DATA_LO);
  1024. oct->reg_list.pci_win_wr_data =
  1025. (u64 __iomem *)(bar0_pciaddr + CN23XX_WIN_WR_DATA64);
  1026. oct->reg_list.pci_win_rd_data_hi =
  1027. (u32 __iomem *)(bar0_pciaddr + CN23XX_WIN_RD_DATA_HI);
  1028. oct->reg_list.pci_win_rd_data_lo =
  1029. (u32 __iomem *)(bar0_pciaddr + CN23XX_WIN_RD_DATA_LO);
  1030. oct->reg_list.pci_win_rd_data =
  1031. (u64 __iomem *)(bar0_pciaddr + CN23XX_WIN_RD_DATA64);
  1032. cn23xx_get_pcie_qlmport(oct);
  1033. cn23xx->intr_mask64 = CN23XX_INTR_MASK;
  1034. if (!oct->msix_on)
  1035. cn23xx->intr_mask64 |= CN23XX_INTR_PKT_TIME;
  1036. if (oct->rev_id >= OCTEON_CN23XX_REV_1_1)
  1037. cn23xx->intr_mask64 |= CN23XX_INTR_VF_MBOX;
  1038. cn23xx->intr_sum_reg64 =
  1039. bar0_pciaddr +
  1040. CN23XX_SLI_MAC_PF_INT_SUM64(oct->pcie_port, oct->pf_num);
  1041. cn23xx->intr_enb_reg64 =
  1042. bar0_pciaddr +
  1043. CN23XX_SLI_MAC_PF_INT_ENB64(oct->pcie_port, oct->pf_num);
  1044. }
  1045. int cn23xx_sriov_config(struct octeon_device *oct)
  1046. {
  1047. struct octeon_cn23xx_pf *cn23xx = (struct octeon_cn23xx_pf *)oct->chip;
  1048. u32 max_rings, total_rings, max_vfs, rings_per_vf;
  1049. u32 pf_srn, num_pf_rings;
  1050. u32 max_possible_vfs;
  1051. cn23xx->conf =
  1052. (struct octeon_config *)oct_get_config_info(oct, LIO_23XX);
  1053. switch (oct->rev_id) {
  1054. case OCTEON_CN23XX_REV_1_0:
  1055. max_rings = CN23XX_MAX_RINGS_PER_PF_PASS_1_0;
  1056. max_possible_vfs = CN23XX_MAX_VFS_PER_PF_PASS_1_0;
  1057. break;
  1058. case OCTEON_CN23XX_REV_1_1:
  1059. max_rings = CN23XX_MAX_RINGS_PER_PF_PASS_1_1;
  1060. max_possible_vfs = CN23XX_MAX_VFS_PER_PF_PASS_1_1;
  1061. break;
  1062. default:
  1063. max_rings = CN23XX_MAX_RINGS_PER_PF;
  1064. max_possible_vfs = CN23XX_MAX_VFS_PER_PF;
  1065. break;
  1066. }
  1067. if (oct->sriov_info.num_pf_rings)
  1068. num_pf_rings = oct->sriov_info.num_pf_rings;
  1069. else
  1070. num_pf_rings = num_present_cpus();
  1071. #ifdef CONFIG_PCI_IOV
  1072. max_vfs = min_t(u32,
  1073. (max_rings - num_pf_rings), max_possible_vfs);
  1074. rings_per_vf = 1;
  1075. #else
  1076. max_vfs = 0;
  1077. rings_per_vf = 0;
  1078. #endif
  1079. total_rings = num_pf_rings + max_vfs;
  1080. /* the first ring of the pf */
  1081. pf_srn = total_rings - num_pf_rings;
  1082. oct->sriov_info.trs = total_rings;
  1083. oct->sriov_info.max_vfs = max_vfs;
  1084. oct->sriov_info.rings_per_vf = rings_per_vf;
  1085. oct->sriov_info.pf_srn = pf_srn;
  1086. oct->sriov_info.num_pf_rings = num_pf_rings;
  1087. dev_notice(&oct->pci_dev->dev, "trs:%d max_vfs:%d rings_per_vf:%d pf_srn:%d num_pf_rings:%d\n",
  1088. oct->sriov_info.trs, oct->sriov_info.max_vfs,
  1089. oct->sriov_info.rings_per_vf, oct->sriov_info.pf_srn,
  1090. oct->sriov_info.num_pf_rings);
  1091. oct->sriov_info.sriov_enabled = 0;
  1092. return 0;
  1093. }
  1094. int setup_cn23xx_octeon_pf_device(struct octeon_device *oct)
  1095. {
  1096. u32 data32;
  1097. u64 BAR0, BAR1;
  1098. pci_read_config_dword(oct->pci_dev, PCI_BASE_ADDRESS_0, &data32);
  1099. BAR0 = (u64)(data32 & ~0xf);
  1100. pci_read_config_dword(oct->pci_dev, PCI_BASE_ADDRESS_1, &data32);
  1101. BAR0 |= ((u64)data32 << 32);
  1102. pci_read_config_dword(oct->pci_dev, PCI_BASE_ADDRESS_2, &data32);
  1103. BAR1 = (u64)(data32 & ~0xf);
  1104. pci_read_config_dword(oct->pci_dev, PCI_BASE_ADDRESS_3, &data32);
  1105. BAR1 |= ((u64)data32 << 32);
  1106. if (!BAR0 || !BAR1) {
  1107. if (!BAR0)
  1108. dev_err(&oct->pci_dev->dev, "device BAR0 unassigned\n");
  1109. if (!BAR1)
  1110. dev_err(&oct->pci_dev->dev, "device BAR1 unassigned\n");
  1111. return 1;
  1112. }
  1113. if (octeon_map_pci_barx(oct, 0, 0))
  1114. return 1;
  1115. if (octeon_map_pci_barx(oct, 1, MAX_BAR1_IOREMAP_SIZE)) {
  1116. dev_err(&oct->pci_dev->dev, "%s CN23XX BAR1 map failed\n",
  1117. __func__);
  1118. octeon_unmap_pci_barx(oct, 0);
  1119. return 1;
  1120. }
  1121. if (cn23xx_get_pf_num(oct) != 0)
  1122. return 1;
  1123. if (cn23xx_sriov_config(oct)) {
  1124. octeon_unmap_pci_barx(oct, 0);
  1125. octeon_unmap_pci_barx(oct, 1);
  1126. return 1;
  1127. }
  1128. octeon_write_csr64(oct, CN23XX_SLI_MAC_CREDIT_CNT, 0x3F802080802080ULL);
  1129. oct->fn_list.setup_iq_regs = cn23xx_setup_iq_regs;
  1130. oct->fn_list.setup_oq_regs = cn23xx_setup_oq_regs;
  1131. oct->fn_list.setup_mbox = cn23xx_setup_pf_mbox;
  1132. oct->fn_list.free_mbox = cn23xx_free_pf_mbox;
  1133. oct->fn_list.process_interrupt_regs = cn23xx_interrupt_handler;
  1134. oct->fn_list.msix_interrupt_handler = cn23xx_pf_msix_interrupt_handler;
  1135. oct->fn_list.soft_reset = cn23xx_pf_soft_reset;
  1136. oct->fn_list.setup_device_regs = cn23xx_setup_pf_device_regs;
  1137. oct->fn_list.update_iq_read_idx = cn23xx_update_read_index;
  1138. oct->fn_list.bar1_idx_setup = cn23xx_bar1_idx_setup;
  1139. oct->fn_list.bar1_idx_write = cn23xx_bar1_idx_write;
  1140. oct->fn_list.bar1_idx_read = cn23xx_bar1_idx_read;
  1141. oct->fn_list.enable_interrupt = cn23xx_enable_pf_interrupt;
  1142. oct->fn_list.disable_interrupt = cn23xx_disable_pf_interrupt;
  1143. oct->fn_list.enable_io_queues = cn23xx_enable_io_queues;
  1144. oct->fn_list.disable_io_queues = cn23xx_disable_io_queues;
  1145. cn23xx_setup_reg_address(oct);
  1146. oct->coproc_clock_rate = 1000000ULL * cn23xx_coprocessor_clock(oct);
  1147. return 0;
  1148. }
  1149. int validate_cn23xx_pf_config_info(struct octeon_device *oct,
  1150. struct octeon_config *conf23xx)
  1151. {
  1152. if (CFG_GET_IQ_MAX_Q(conf23xx) > CN23XX_MAX_INPUT_QUEUES) {
  1153. dev_err(&oct->pci_dev->dev, "%s: Num IQ (%d) exceeds Max (%d)\n",
  1154. __func__, CFG_GET_IQ_MAX_Q(conf23xx),
  1155. CN23XX_MAX_INPUT_QUEUES);
  1156. return 1;
  1157. }
  1158. if (CFG_GET_OQ_MAX_Q(conf23xx) > CN23XX_MAX_OUTPUT_QUEUES) {
  1159. dev_err(&oct->pci_dev->dev, "%s: Num OQ (%d) exceeds Max (%d)\n",
  1160. __func__, CFG_GET_OQ_MAX_Q(conf23xx),
  1161. CN23XX_MAX_OUTPUT_QUEUES);
  1162. return 1;
  1163. }
  1164. if (CFG_GET_IQ_INSTR_TYPE(conf23xx) != OCTEON_32BYTE_INSTR &&
  1165. CFG_GET_IQ_INSTR_TYPE(conf23xx) != OCTEON_64BYTE_INSTR) {
  1166. dev_err(&oct->pci_dev->dev, "%s: Invalid instr type for IQ\n",
  1167. __func__);
  1168. return 1;
  1169. }
  1170. if (!CFG_GET_OQ_REFILL_THRESHOLD(conf23xx)) {
  1171. dev_err(&oct->pci_dev->dev, "%s: Invalid parameter for OQ\n",
  1172. __func__);
  1173. return 1;
  1174. }
  1175. if (!(CFG_GET_OQ_INTR_TIME(conf23xx))) {
  1176. dev_err(&oct->pci_dev->dev, "%s: Invalid parameter for OQ\n",
  1177. __func__);
  1178. return 1;
  1179. }
  1180. return 0;
  1181. }
  1182. int cn23xx_fw_loaded(struct octeon_device *oct)
  1183. {
  1184. u64 val;
  1185. /* If there's more than one active PF on this NIC, then that
  1186. * implies that the NIC firmware is loaded and running. This check
  1187. * prevents a rare false negative that might occur if we only relied
  1188. * on checking the SCR2_BIT_FW_LOADED flag. The false negative would
  1189. * happen if the PF driver sees SCR2_BIT_FW_LOADED as cleared even
  1190. * though the firmware was already loaded but still booting and has yet
  1191. * to set SCR2_BIT_FW_LOADED.
  1192. */
  1193. if (atomic_read(oct->adapter_refcount) > 1)
  1194. return 1;
  1195. val = octeon_read_csr64(oct, CN23XX_SLI_SCRATCH2);
  1196. return (val >> SCR2_BIT_FW_LOADED) & 1ULL;
  1197. }
  1198. void cn23xx_tell_vf_its_macaddr_changed(struct octeon_device *oct, int vfidx,
  1199. u8 *mac)
  1200. {
  1201. if (oct->sriov_info.vf_drv_loaded_mask & BIT_ULL(vfidx)) {
  1202. struct octeon_mbox_cmd mbox_cmd;
  1203. mbox_cmd.msg.u64 = 0;
  1204. mbox_cmd.msg.s.type = OCTEON_MBOX_REQUEST;
  1205. mbox_cmd.msg.s.resp_needed = 0;
  1206. mbox_cmd.msg.s.cmd = OCTEON_PF_CHANGED_VF_MACADDR;
  1207. mbox_cmd.msg.s.len = 1;
  1208. mbox_cmd.recv_len = 0;
  1209. mbox_cmd.recv_status = 0;
  1210. mbox_cmd.fn = NULL;
  1211. mbox_cmd.fn_arg = 0;
  1212. ether_addr_copy(mbox_cmd.msg.s.params, mac);
  1213. mbox_cmd.q_no = vfidx * oct->sriov_info.rings_per_vf;
  1214. octeon_mbox_write(oct, &mbox_cmd);
  1215. }
  1216. }
  1217. static void
  1218. cn23xx_get_vf_stats_callback(struct octeon_device *oct,
  1219. struct octeon_mbox_cmd *cmd, void *arg)
  1220. {
  1221. struct oct_vf_stats_ctx *ctx = arg;
  1222. memcpy(ctx->stats, cmd->data, sizeof(struct oct_vf_stats));
  1223. atomic_set(&ctx->status, 1);
  1224. }
  1225. int cn23xx_get_vf_stats(struct octeon_device *oct, int vfidx,
  1226. struct oct_vf_stats *stats)
  1227. {
  1228. u32 timeout = HZ; // 1sec
  1229. struct octeon_mbox_cmd mbox_cmd;
  1230. struct oct_vf_stats_ctx ctx;
  1231. u32 count = 0, ret;
  1232. if (!(oct->sriov_info.vf_drv_loaded_mask & (1ULL << vfidx)))
  1233. return -1;
  1234. if (sizeof(struct oct_vf_stats) > sizeof(mbox_cmd.data))
  1235. return -1;
  1236. mbox_cmd.msg.u64 = 0;
  1237. mbox_cmd.msg.s.type = OCTEON_MBOX_REQUEST;
  1238. mbox_cmd.msg.s.resp_needed = 1;
  1239. mbox_cmd.msg.s.cmd = OCTEON_GET_VF_STATS;
  1240. mbox_cmd.msg.s.len = 1;
  1241. mbox_cmd.q_no = vfidx * oct->sriov_info.rings_per_vf;
  1242. mbox_cmd.recv_len = 0;
  1243. mbox_cmd.recv_status = 0;
  1244. mbox_cmd.fn = (octeon_mbox_callback_t)cn23xx_get_vf_stats_callback;
  1245. ctx.stats = stats;
  1246. atomic_set(&ctx.status, 0);
  1247. mbox_cmd.fn_arg = (void *)&ctx;
  1248. memset(mbox_cmd.data, 0, sizeof(mbox_cmd.data));
  1249. octeon_mbox_write(oct, &mbox_cmd);
  1250. do {
  1251. schedule_timeout_uninterruptible(1);
  1252. } while ((atomic_read(&ctx.status) == 0) && (count++ < timeout));
  1253. ret = atomic_read(&ctx.status);
  1254. if (ret == 0) {
  1255. octeon_mbox_cancel(oct, 0);
  1256. dev_err(&oct->pci_dev->dev, "Unable to get stats from VF-%d, timedout\n",
  1257. vfidx);
  1258. return -1;
  1259. }
  1260. return 0;
  1261. }