cn23xx_pf_device.c 45 KB

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