octeon_device.c 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478
  1. /**********************************************************************
  2. * Author: Cavium, Inc.
  3. *
  4. * Contact: support@cavium.com
  5. * Please include "LiquidIO" in the subject.
  6. *
  7. * Copyright (c) 2003-2016 Cavium, Inc.
  8. *
  9. * This file is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License, Version 2, as
  11. * published by the Free Software Foundation.
  12. *
  13. * This file is distributed in the hope that it will be useful, but
  14. * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
  15. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
  16. * NONINFRINGEMENT. See the GNU General Public License for more details.
  17. ***********************************************************************/
  18. #include <linux/pci.h>
  19. #include <linux/netdevice.h>
  20. #include <linux/vmalloc.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 "octeon_main.h"
  27. #include "octeon_network.h"
  28. #include "cn66xx_regs.h"
  29. #include "cn66xx_device.h"
  30. #include "cn23xx_pf_device.h"
  31. #include "cn23xx_vf_device.h"
  32. /** Default configuration
  33. * for CN66XX OCTEON Models.
  34. */
  35. static struct octeon_config default_cn66xx_conf = {
  36. .card_type = LIO_210SV,
  37. .card_name = LIO_210SV_NAME,
  38. /** IQ attributes */
  39. .iq = {
  40. .max_iqs = CN6XXX_CFG_IO_QUEUES,
  41. .pending_list_size =
  42. (CN6XXX_MAX_IQ_DESCRIPTORS * CN6XXX_CFG_IO_QUEUES),
  43. .instr_type = OCTEON_64BYTE_INSTR,
  44. .db_min = CN6XXX_DB_MIN,
  45. .db_timeout = CN6XXX_DB_TIMEOUT,
  46. }
  47. ,
  48. /** OQ attributes */
  49. .oq = {
  50. .max_oqs = CN6XXX_CFG_IO_QUEUES,
  51. .refill_threshold = CN6XXX_OQ_REFIL_THRESHOLD,
  52. .oq_intr_pkt = CN6XXX_OQ_INTR_PKT,
  53. .oq_intr_time = CN6XXX_OQ_INTR_TIME,
  54. .pkts_per_intr = CN6XXX_OQ_PKTSPER_INTR,
  55. }
  56. ,
  57. .num_nic_ports = DEFAULT_NUM_NIC_PORTS_66XX,
  58. .num_def_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS,
  59. .num_def_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS,
  60. .def_rx_buf_size = CN6XXX_OQ_BUF_SIZE,
  61. /* For ethernet interface 0: Port cfg Attributes */
  62. .nic_if_cfg[0] = {
  63. /* Max Txqs: Half for each of the two ports :max_iq/2 */
  64. .max_txqs = MAX_TXQS_PER_INTF,
  65. /* Actual configured value. Range could be: 1...max_txqs */
  66. .num_txqs = DEF_TXQS_PER_INTF,
  67. /* Max Rxqs: Half for each of the two ports :max_oq/2 */
  68. .max_rxqs = MAX_RXQS_PER_INTF,
  69. /* Actual configured value. Range could be: 1...max_rxqs */
  70. .num_rxqs = DEF_RXQS_PER_INTF,
  71. /* Num of desc for rx rings */
  72. .num_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS,
  73. /* Num of desc for tx rings */
  74. .num_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS,
  75. /* SKB size, We need not change buf size even for Jumbo frames.
  76. * Octeon can send jumbo frames in 4 consecutive descriptors,
  77. */
  78. .rx_buf_size = CN6XXX_OQ_BUF_SIZE,
  79. .base_queue = BASE_QUEUE_NOT_REQUESTED,
  80. .gmx_port_id = 0,
  81. },
  82. .nic_if_cfg[1] = {
  83. /* Max Txqs: Half for each of the two ports :max_iq/2 */
  84. .max_txqs = MAX_TXQS_PER_INTF,
  85. /* Actual configured value. Range could be: 1...max_txqs */
  86. .num_txqs = DEF_TXQS_PER_INTF,
  87. /* Max Rxqs: Half for each of the two ports :max_oq/2 */
  88. .max_rxqs = MAX_RXQS_PER_INTF,
  89. /* Actual configured value. Range could be: 1...max_rxqs */
  90. .num_rxqs = DEF_RXQS_PER_INTF,
  91. /* Num of desc for rx rings */
  92. .num_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS,
  93. /* Num of desc for tx rings */
  94. .num_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS,
  95. /* SKB size, We need not change buf size even for Jumbo frames.
  96. * Octeon can send jumbo frames in 4 consecutive descriptors,
  97. */
  98. .rx_buf_size = CN6XXX_OQ_BUF_SIZE,
  99. .base_queue = BASE_QUEUE_NOT_REQUESTED,
  100. .gmx_port_id = 1,
  101. },
  102. /** Miscellaneous attributes */
  103. .misc = {
  104. /* Host driver link query interval */
  105. .oct_link_query_interval = 100,
  106. /* Octeon link query interval */
  107. .host_link_query_interval = 500,
  108. .enable_sli_oq_bp = 0,
  109. /* Control queue group */
  110. .ctrlq_grp = 1,
  111. }
  112. ,
  113. };
  114. /** Default configuration
  115. * for CN68XX OCTEON Model.
  116. */
  117. static struct octeon_config default_cn68xx_conf = {
  118. .card_type = LIO_410NV,
  119. .card_name = LIO_410NV_NAME,
  120. /** IQ attributes */
  121. .iq = {
  122. .max_iqs = CN6XXX_CFG_IO_QUEUES,
  123. .pending_list_size =
  124. (CN6XXX_MAX_IQ_DESCRIPTORS * CN6XXX_CFG_IO_QUEUES),
  125. .instr_type = OCTEON_64BYTE_INSTR,
  126. .db_min = CN6XXX_DB_MIN,
  127. .db_timeout = CN6XXX_DB_TIMEOUT,
  128. }
  129. ,
  130. /** OQ attributes */
  131. .oq = {
  132. .max_oqs = CN6XXX_CFG_IO_QUEUES,
  133. .refill_threshold = CN6XXX_OQ_REFIL_THRESHOLD,
  134. .oq_intr_pkt = CN6XXX_OQ_INTR_PKT,
  135. .oq_intr_time = CN6XXX_OQ_INTR_TIME,
  136. .pkts_per_intr = CN6XXX_OQ_PKTSPER_INTR,
  137. }
  138. ,
  139. .num_nic_ports = DEFAULT_NUM_NIC_PORTS_68XX,
  140. .num_def_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS,
  141. .num_def_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS,
  142. .def_rx_buf_size = CN6XXX_OQ_BUF_SIZE,
  143. .nic_if_cfg[0] = {
  144. /* Max Txqs: Half for each of the two ports :max_iq/2 */
  145. .max_txqs = MAX_TXQS_PER_INTF,
  146. /* Actual configured value. Range could be: 1...max_txqs */
  147. .num_txqs = DEF_TXQS_PER_INTF,
  148. /* Max Rxqs: Half for each of the two ports :max_oq/2 */
  149. .max_rxqs = MAX_RXQS_PER_INTF,
  150. /* Actual configured value. Range could be: 1...max_rxqs */
  151. .num_rxqs = DEF_RXQS_PER_INTF,
  152. /* Num of desc for rx rings */
  153. .num_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS,
  154. /* Num of desc for tx rings */
  155. .num_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS,
  156. /* SKB size, We need not change buf size even for Jumbo frames.
  157. * Octeon can send jumbo frames in 4 consecutive descriptors,
  158. */
  159. .rx_buf_size = CN6XXX_OQ_BUF_SIZE,
  160. .base_queue = BASE_QUEUE_NOT_REQUESTED,
  161. .gmx_port_id = 0,
  162. },
  163. .nic_if_cfg[1] = {
  164. /* Max Txqs: Half for each of the two ports :max_iq/2 */
  165. .max_txqs = MAX_TXQS_PER_INTF,
  166. /* Actual configured value. Range could be: 1...max_txqs */
  167. .num_txqs = DEF_TXQS_PER_INTF,
  168. /* Max Rxqs: Half for each of the two ports :max_oq/2 */
  169. .max_rxqs = MAX_RXQS_PER_INTF,
  170. /* Actual configured value. Range could be: 1...max_rxqs */
  171. .num_rxqs = DEF_RXQS_PER_INTF,
  172. /* Num of desc for rx rings */
  173. .num_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS,
  174. /* Num of desc for tx rings */
  175. .num_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS,
  176. /* SKB size, We need not change buf size even for Jumbo frames.
  177. * Octeon can send jumbo frames in 4 consecutive descriptors,
  178. */
  179. .rx_buf_size = CN6XXX_OQ_BUF_SIZE,
  180. .base_queue = BASE_QUEUE_NOT_REQUESTED,
  181. .gmx_port_id = 1,
  182. },
  183. .nic_if_cfg[2] = {
  184. /* Max Txqs: Half for each of the two ports :max_iq/2 */
  185. .max_txqs = MAX_TXQS_PER_INTF,
  186. /* Actual configured value. Range could be: 1...max_txqs */
  187. .num_txqs = DEF_TXQS_PER_INTF,
  188. /* Max Rxqs: Half for each of the two ports :max_oq/2 */
  189. .max_rxqs = MAX_RXQS_PER_INTF,
  190. /* Actual configured value. Range could be: 1...max_rxqs */
  191. .num_rxqs = DEF_RXQS_PER_INTF,
  192. /* Num of desc for rx rings */
  193. .num_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS,
  194. /* Num of desc for tx rings */
  195. .num_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS,
  196. /* SKB size, We need not change buf size even for Jumbo frames.
  197. * Octeon can send jumbo frames in 4 consecutive descriptors,
  198. */
  199. .rx_buf_size = CN6XXX_OQ_BUF_SIZE,
  200. .base_queue = BASE_QUEUE_NOT_REQUESTED,
  201. .gmx_port_id = 2,
  202. },
  203. .nic_if_cfg[3] = {
  204. /* Max Txqs: Half for each of the two ports :max_iq/2 */
  205. .max_txqs = MAX_TXQS_PER_INTF,
  206. /* Actual configured value. Range could be: 1...max_txqs */
  207. .num_txqs = DEF_TXQS_PER_INTF,
  208. /* Max Rxqs: Half for each of the two ports :max_oq/2 */
  209. .max_rxqs = MAX_RXQS_PER_INTF,
  210. /* Actual configured value. Range could be: 1...max_rxqs */
  211. .num_rxqs = DEF_RXQS_PER_INTF,
  212. /* Num of desc for rx rings */
  213. .num_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS,
  214. /* Num of desc for tx rings */
  215. .num_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS,
  216. /* SKB size, We need not change buf size even for Jumbo frames.
  217. * Octeon can send jumbo frames in 4 consecutive descriptors,
  218. */
  219. .rx_buf_size = CN6XXX_OQ_BUF_SIZE,
  220. .base_queue = BASE_QUEUE_NOT_REQUESTED,
  221. .gmx_port_id = 3,
  222. },
  223. /** Miscellaneous attributes */
  224. .misc = {
  225. /* Host driver link query interval */
  226. .oct_link_query_interval = 100,
  227. /* Octeon link query interval */
  228. .host_link_query_interval = 500,
  229. .enable_sli_oq_bp = 0,
  230. /* Control queue group */
  231. .ctrlq_grp = 1,
  232. }
  233. ,
  234. };
  235. /** Default configuration
  236. * for CN68XX OCTEON Model.
  237. */
  238. static struct octeon_config default_cn68xx_210nv_conf = {
  239. .card_type = LIO_210NV,
  240. .card_name = LIO_210NV_NAME,
  241. /** IQ attributes */
  242. .iq = {
  243. .max_iqs = CN6XXX_CFG_IO_QUEUES,
  244. .pending_list_size =
  245. (CN6XXX_MAX_IQ_DESCRIPTORS * CN6XXX_CFG_IO_QUEUES),
  246. .instr_type = OCTEON_64BYTE_INSTR,
  247. .db_min = CN6XXX_DB_MIN,
  248. .db_timeout = CN6XXX_DB_TIMEOUT,
  249. }
  250. ,
  251. /** OQ attributes */
  252. .oq = {
  253. .max_oqs = CN6XXX_CFG_IO_QUEUES,
  254. .refill_threshold = CN6XXX_OQ_REFIL_THRESHOLD,
  255. .oq_intr_pkt = CN6XXX_OQ_INTR_PKT,
  256. .oq_intr_time = CN6XXX_OQ_INTR_TIME,
  257. .pkts_per_intr = CN6XXX_OQ_PKTSPER_INTR,
  258. }
  259. ,
  260. .num_nic_ports = DEFAULT_NUM_NIC_PORTS_68XX_210NV,
  261. .num_def_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS,
  262. .num_def_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS,
  263. .def_rx_buf_size = CN6XXX_OQ_BUF_SIZE,
  264. .nic_if_cfg[0] = {
  265. /* Max Txqs: Half for each of the two ports :max_iq/2 */
  266. .max_txqs = MAX_TXQS_PER_INTF,
  267. /* Actual configured value. Range could be: 1...max_txqs */
  268. .num_txqs = DEF_TXQS_PER_INTF,
  269. /* Max Rxqs: Half for each of the two ports :max_oq/2 */
  270. .max_rxqs = MAX_RXQS_PER_INTF,
  271. /* Actual configured value. Range could be: 1...max_rxqs */
  272. .num_rxqs = DEF_RXQS_PER_INTF,
  273. /* Num of desc for rx rings */
  274. .num_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS,
  275. /* Num of desc for tx rings */
  276. .num_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS,
  277. /* SKB size, We need not change buf size even for Jumbo frames.
  278. * Octeon can send jumbo frames in 4 consecutive descriptors,
  279. */
  280. .rx_buf_size = CN6XXX_OQ_BUF_SIZE,
  281. .base_queue = BASE_QUEUE_NOT_REQUESTED,
  282. .gmx_port_id = 0,
  283. },
  284. .nic_if_cfg[1] = {
  285. /* Max Txqs: Half for each of the two ports :max_iq/2 */
  286. .max_txqs = MAX_TXQS_PER_INTF,
  287. /* Actual configured value. Range could be: 1...max_txqs */
  288. .num_txqs = DEF_TXQS_PER_INTF,
  289. /* Max Rxqs: Half for each of the two ports :max_oq/2 */
  290. .max_rxqs = MAX_RXQS_PER_INTF,
  291. /* Actual configured value. Range could be: 1...max_rxqs */
  292. .num_rxqs = DEF_RXQS_PER_INTF,
  293. /* Num of desc for rx rings */
  294. .num_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS,
  295. /* Num of desc for tx rings */
  296. .num_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS,
  297. /* SKB size, We need not change buf size even for Jumbo frames.
  298. * Octeon can send jumbo frames in 4 consecutive descriptors,
  299. */
  300. .rx_buf_size = CN6XXX_OQ_BUF_SIZE,
  301. .base_queue = BASE_QUEUE_NOT_REQUESTED,
  302. .gmx_port_id = 1,
  303. },
  304. /** Miscellaneous attributes */
  305. .misc = {
  306. /* Host driver link query interval */
  307. .oct_link_query_interval = 100,
  308. /* Octeon link query interval */
  309. .host_link_query_interval = 500,
  310. .enable_sli_oq_bp = 0,
  311. /* Control queue group */
  312. .ctrlq_grp = 1,
  313. }
  314. ,
  315. };
  316. static struct octeon_config default_cn23xx_conf = {
  317. .card_type = LIO_23XX,
  318. .card_name = LIO_23XX_NAME,
  319. /** IQ attributes */
  320. .iq = {
  321. .max_iqs = CN23XX_CFG_IO_QUEUES,
  322. .pending_list_size = (CN23XX_DEFAULT_IQ_DESCRIPTORS *
  323. CN23XX_CFG_IO_QUEUES),
  324. .instr_type = OCTEON_64BYTE_INSTR,
  325. .db_min = CN23XX_DB_MIN,
  326. .db_timeout = CN23XX_DB_TIMEOUT,
  327. .iq_intr_pkt = CN23XX_DEF_IQ_INTR_THRESHOLD,
  328. },
  329. /** OQ attributes */
  330. .oq = {
  331. .max_oqs = CN23XX_CFG_IO_QUEUES,
  332. .pkts_per_intr = CN23XX_OQ_PKTSPER_INTR,
  333. .refill_threshold = CN23XX_OQ_REFIL_THRESHOLD,
  334. .oq_intr_pkt = CN23XX_OQ_INTR_PKT,
  335. .oq_intr_time = CN23XX_OQ_INTR_TIME,
  336. },
  337. .num_nic_ports = DEFAULT_NUM_NIC_PORTS_23XX,
  338. .num_def_rx_descs = CN23XX_DEFAULT_OQ_DESCRIPTORS,
  339. .num_def_tx_descs = CN23XX_DEFAULT_IQ_DESCRIPTORS,
  340. .def_rx_buf_size = CN23XX_OQ_BUF_SIZE,
  341. /* For ethernet interface 0: Port cfg Attributes */
  342. .nic_if_cfg[0] = {
  343. /* Max Txqs: Half for each of the two ports :max_iq/2 */
  344. .max_txqs = MAX_TXQS_PER_INTF,
  345. /* Actual configured value. Range could be: 1...max_txqs */
  346. .num_txqs = DEF_TXQS_PER_INTF,
  347. /* Max Rxqs: Half for each of the two ports :max_oq/2 */
  348. .max_rxqs = MAX_RXQS_PER_INTF,
  349. /* Actual configured value. Range could be: 1...max_rxqs */
  350. .num_rxqs = DEF_RXQS_PER_INTF,
  351. /* Num of desc for rx rings */
  352. .num_rx_descs = CN23XX_DEFAULT_OQ_DESCRIPTORS,
  353. /* Num of desc for tx rings */
  354. .num_tx_descs = CN23XX_DEFAULT_IQ_DESCRIPTORS,
  355. /* SKB size, We need not change buf size even for Jumbo frames.
  356. * Octeon can send jumbo frames in 4 consecutive descriptors,
  357. */
  358. .rx_buf_size = CN23XX_OQ_BUF_SIZE,
  359. .base_queue = BASE_QUEUE_NOT_REQUESTED,
  360. .gmx_port_id = 0,
  361. },
  362. .nic_if_cfg[1] = {
  363. /* Max Txqs: Half for each of the two ports :max_iq/2 */
  364. .max_txqs = MAX_TXQS_PER_INTF,
  365. /* Actual configured value. Range could be: 1...max_txqs */
  366. .num_txqs = DEF_TXQS_PER_INTF,
  367. /* Max Rxqs: Half for each of the two ports :max_oq/2 */
  368. .max_rxqs = MAX_RXQS_PER_INTF,
  369. /* Actual configured value. Range could be: 1...max_rxqs */
  370. .num_rxqs = DEF_RXQS_PER_INTF,
  371. /* Num of desc for rx rings */
  372. .num_rx_descs = CN23XX_DEFAULT_OQ_DESCRIPTORS,
  373. /* Num of desc for tx rings */
  374. .num_tx_descs = CN23XX_DEFAULT_IQ_DESCRIPTORS,
  375. /* SKB size, We need not change buf size even for Jumbo frames.
  376. * Octeon can send jumbo frames in 4 consecutive descriptors,
  377. */
  378. .rx_buf_size = CN23XX_OQ_BUF_SIZE,
  379. .base_queue = BASE_QUEUE_NOT_REQUESTED,
  380. .gmx_port_id = 1,
  381. },
  382. .misc = {
  383. /* Host driver link query interval */
  384. .oct_link_query_interval = 100,
  385. /* Octeon link query interval */
  386. .host_link_query_interval = 500,
  387. .enable_sli_oq_bp = 0,
  388. /* Control queue group */
  389. .ctrlq_grp = 1,
  390. }
  391. };
  392. static struct octeon_config_ptr {
  393. u32 conf_type;
  394. } oct_conf_info[MAX_OCTEON_DEVICES] = {
  395. {
  396. OCTEON_CONFIG_TYPE_DEFAULT,
  397. }, {
  398. OCTEON_CONFIG_TYPE_DEFAULT,
  399. }, {
  400. OCTEON_CONFIG_TYPE_DEFAULT,
  401. }, {
  402. OCTEON_CONFIG_TYPE_DEFAULT,
  403. },
  404. };
  405. static char oct_dev_state_str[OCT_DEV_STATES + 1][32] = {
  406. "BEGIN", "PCI-ENABLE-DONE", "PCI-MAP-DONE", "DISPATCH-INIT-DONE",
  407. "IQ-INIT-DONE", "SCBUFF-POOL-INIT-DONE", "RESPLIST-INIT-DONE",
  408. "DROQ-INIT-DONE", "MBOX-SETUP-DONE", "MSIX-ALLOC-VECTOR-DONE",
  409. "INTR-SET-DONE", "IO-QUEUES-INIT-DONE", "CONSOLE-INIT-DONE",
  410. "HOST-READY", "CORE-READY", "RUNNING", "IN-RESET",
  411. "INVALID"
  412. };
  413. static char oct_dev_app_str[CVM_DRV_APP_COUNT + 1][32] = {
  414. "BASE", "NIC", "UNKNOWN"};
  415. static struct octeon_device *octeon_device[MAX_OCTEON_DEVICES];
  416. static atomic_t adapter_refcounts[MAX_OCTEON_DEVICES];
  417. static atomic_t adapter_fw_states[MAX_OCTEON_DEVICES];
  418. static u32 octeon_device_count;
  419. /* locks device array (i.e. octeon_device[]) */
  420. static spinlock_t octeon_devices_lock;
  421. static struct octeon_core_setup core_setup[MAX_OCTEON_DEVICES];
  422. static void oct_set_config_info(int oct_id, int conf_type)
  423. {
  424. if (conf_type < 0 || conf_type > (NUM_OCTEON_CONFS - 1))
  425. conf_type = OCTEON_CONFIG_TYPE_DEFAULT;
  426. oct_conf_info[oct_id].conf_type = conf_type;
  427. }
  428. void octeon_init_device_list(int conf_type)
  429. {
  430. int i;
  431. memset(octeon_device, 0, (sizeof(void *) * MAX_OCTEON_DEVICES));
  432. for (i = 0; i < MAX_OCTEON_DEVICES; i++)
  433. oct_set_config_info(i, conf_type);
  434. spin_lock_init(&octeon_devices_lock);
  435. }
  436. static void *__retrieve_octeon_config_info(struct octeon_device *oct,
  437. u16 card_type)
  438. {
  439. u32 oct_id = oct->octeon_id;
  440. void *ret = NULL;
  441. switch (oct_conf_info[oct_id].conf_type) {
  442. case OCTEON_CONFIG_TYPE_DEFAULT:
  443. if (oct->chip_id == OCTEON_CN66XX) {
  444. ret = &default_cn66xx_conf;
  445. } else if ((oct->chip_id == OCTEON_CN68XX) &&
  446. (card_type == LIO_210NV)) {
  447. ret = &default_cn68xx_210nv_conf;
  448. } else if ((oct->chip_id == OCTEON_CN68XX) &&
  449. (card_type == LIO_410NV)) {
  450. ret = &default_cn68xx_conf;
  451. } else if (oct->chip_id == OCTEON_CN23XX_PF_VID) {
  452. ret = &default_cn23xx_conf;
  453. } else if (oct->chip_id == OCTEON_CN23XX_VF_VID) {
  454. ret = &default_cn23xx_conf;
  455. }
  456. break;
  457. default:
  458. break;
  459. }
  460. return ret;
  461. }
  462. static int __verify_octeon_config_info(struct octeon_device *oct, void *conf)
  463. {
  464. switch (oct->chip_id) {
  465. case OCTEON_CN66XX:
  466. case OCTEON_CN68XX:
  467. return lio_validate_cn6xxx_config_info(oct, conf);
  468. case OCTEON_CN23XX_PF_VID:
  469. case OCTEON_CN23XX_VF_VID:
  470. return 0;
  471. default:
  472. break;
  473. }
  474. return 1;
  475. }
  476. void *oct_get_config_info(struct octeon_device *oct, u16 card_type)
  477. {
  478. void *conf = NULL;
  479. conf = __retrieve_octeon_config_info(oct, card_type);
  480. if (!conf)
  481. return NULL;
  482. if (__verify_octeon_config_info(oct, conf)) {
  483. dev_err(&oct->pci_dev->dev, "Configuration verification failed\n");
  484. return NULL;
  485. }
  486. return conf;
  487. }
  488. char *lio_get_state_string(atomic_t *state_ptr)
  489. {
  490. s32 istate = (s32)atomic_read(state_ptr);
  491. if (istate > OCT_DEV_STATES || istate < 0)
  492. return oct_dev_state_str[OCT_DEV_STATE_INVALID];
  493. return oct_dev_state_str[istate];
  494. }
  495. static char *get_oct_app_string(u32 app_mode)
  496. {
  497. if (app_mode <= CVM_DRV_APP_END)
  498. return oct_dev_app_str[app_mode - CVM_DRV_APP_START];
  499. return oct_dev_app_str[CVM_DRV_INVALID_APP - CVM_DRV_APP_START];
  500. }
  501. void octeon_free_device_mem(struct octeon_device *oct)
  502. {
  503. int i;
  504. for (i = 0; i < MAX_OCTEON_OUTPUT_QUEUES(oct); i++) {
  505. if (oct->io_qmask.oq & BIT_ULL(i))
  506. vfree(oct->droq[i]);
  507. }
  508. for (i = 0; i < MAX_OCTEON_INSTR_QUEUES(oct); i++) {
  509. if (oct->io_qmask.iq & BIT_ULL(i))
  510. vfree(oct->instr_queue[i]);
  511. }
  512. i = oct->octeon_id;
  513. vfree(oct);
  514. octeon_device[i] = NULL;
  515. octeon_device_count--;
  516. }
  517. static struct octeon_device *octeon_allocate_device_mem(u32 pci_id,
  518. u32 priv_size)
  519. {
  520. struct octeon_device *oct;
  521. u8 *buf = NULL;
  522. u32 octdevsize = 0, configsize = 0, size;
  523. switch (pci_id) {
  524. case OCTEON_CN68XX:
  525. case OCTEON_CN66XX:
  526. configsize = sizeof(struct octeon_cn6xxx);
  527. break;
  528. case OCTEON_CN23XX_PF_VID:
  529. configsize = sizeof(struct octeon_cn23xx_pf);
  530. break;
  531. case OCTEON_CN23XX_VF_VID:
  532. configsize = sizeof(struct octeon_cn23xx_vf);
  533. break;
  534. default:
  535. pr_err("%s: Unknown PCI Device: 0x%x\n",
  536. __func__,
  537. pci_id);
  538. return NULL;
  539. }
  540. if (configsize & 0x7)
  541. configsize += (8 - (configsize & 0x7));
  542. octdevsize = sizeof(struct octeon_device);
  543. if (octdevsize & 0x7)
  544. octdevsize += (8 - (octdevsize & 0x7));
  545. if (priv_size & 0x7)
  546. priv_size += (8 - (priv_size & 0x7));
  547. size = octdevsize + priv_size + configsize +
  548. (sizeof(struct octeon_dispatch) * DISPATCH_LIST_SIZE);
  549. buf = vzalloc(size);
  550. if (!buf)
  551. return NULL;
  552. oct = (struct octeon_device *)buf;
  553. oct->priv = (void *)(buf + octdevsize);
  554. oct->chip = (void *)(buf + octdevsize + priv_size);
  555. oct->dispatch.dlist = (struct octeon_dispatch *)
  556. (buf + octdevsize + priv_size + configsize);
  557. return oct;
  558. }
  559. struct octeon_device *octeon_allocate_device(u32 pci_id,
  560. u32 priv_size)
  561. {
  562. u32 oct_idx = 0;
  563. struct octeon_device *oct = NULL;
  564. spin_lock(&octeon_devices_lock);
  565. for (oct_idx = 0; oct_idx < MAX_OCTEON_DEVICES; oct_idx++)
  566. if (!octeon_device[oct_idx])
  567. break;
  568. if (oct_idx < MAX_OCTEON_DEVICES) {
  569. oct = octeon_allocate_device_mem(pci_id, priv_size);
  570. if (oct) {
  571. octeon_device_count++;
  572. octeon_device[oct_idx] = oct;
  573. }
  574. }
  575. spin_unlock(&octeon_devices_lock);
  576. if (!oct)
  577. return NULL;
  578. spin_lock_init(&oct->pci_win_lock);
  579. spin_lock_init(&oct->mem_access_lock);
  580. oct->octeon_id = oct_idx;
  581. snprintf(oct->device_name, sizeof(oct->device_name),
  582. "LiquidIO%d", (oct->octeon_id));
  583. return oct;
  584. }
  585. /** Register a device's bus location at initialization time.
  586. * @param octeon_dev - pointer to the octeon device structure.
  587. * @param bus - PCIe bus #
  588. * @param dev - PCIe device #
  589. * @param func - PCIe function #
  590. * @param is_pf - TRUE for PF, FALSE for VF
  591. * @return reference count of device's adapter
  592. */
  593. int octeon_register_device(struct octeon_device *oct,
  594. int bus, int dev, int func, int is_pf)
  595. {
  596. int idx, refcount;
  597. oct->loc.bus = bus;
  598. oct->loc.dev = dev;
  599. oct->loc.func = func;
  600. oct->adapter_refcount = &adapter_refcounts[oct->octeon_id];
  601. atomic_set(oct->adapter_refcount, 0);
  602. /* Like the reference count, the f/w state is shared 'per-adapter' */
  603. oct->adapter_fw_state = &adapter_fw_states[oct->octeon_id];
  604. atomic_set(oct->adapter_fw_state, FW_NEEDS_TO_BE_LOADED);
  605. spin_lock(&octeon_devices_lock);
  606. for (idx = (int)oct->octeon_id - 1; idx >= 0; idx--) {
  607. if (!octeon_device[idx]) {
  608. dev_err(&oct->pci_dev->dev,
  609. "%s: Internal driver error, missing dev",
  610. __func__);
  611. spin_unlock(&octeon_devices_lock);
  612. atomic_inc(oct->adapter_refcount);
  613. return 1; /* here, refcount is guaranteed to be 1 */
  614. }
  615. /* If another device is at same bus/dev, use its refcounter
  616. * (and f/w state variable).
  617. */
  618. if ((octeon_device[idx]->loc.bus == bus) &&
  619. (octeon_device[idx]->loc.dev == dev)) {
  620. oct->adapter_refcount =
  621. octeon_device[idx]->adapter_refcount;
  622. oct->adapter_fw_state =
  623. octeon_device[idx]->adapter_fw_state;
  624. break;
  625. }
  626. }
  627. spin_unlock(&octeon_devices_lock);
  628. atomic_inc(oct->adapter_refcount);
  629. refcount = atomic_read(oct->adapter_refcount);
  630. dev_dbg(&oct->pci_dev->dev, "%s: %02x:%02x:%d refcount %u", __func__,
  631. oct->loc.bus, oct->loc.dev, oct->loc.func, refcount);
  632. return refcount;
  633. }
  634. /** Deregister a device at de-initialization time.
  635. * @param octeon_dev - pointer to the octeon device structure.
  636. * @return reference count of device's adapter
  637. */
  638. int octeon_deregister_device(struct octeon_device *oct)
  639. {
  640. int refcount;
  641. atomic_dec(oct->adapter_refcount);
  642. refcount = atomic_read(oct->adapter_refcount);
  643. dev_dbg(&oct->pci_dev->dev, "%s: %04d:%02d:%d refcount %u", __func__,
  644. oct->loc.bus, oct->loc.dev, oct->loc.func, refcount);
  645. return refcount;
  646. }
  647. int
  648. octeon_allocate_ioq_vector(struct octeon_device *oct)
  649. {
  650. int i, num_ioqs = 0;
  651. struct octeon_ioq_vector *ioq_vector;
  652. int cpu_num;
  653. int size;
  654. if (OCTEON_CN23XX_PF(oct))
  655. num_ioqs = oct->sriov_info.num_pf_rings;
  656. else if (OCTEON_CN23XX_VF(oct))
  657. num_ioqs = oct->sriov_info.rings_per_vf;
  658. size = sizeof(struct octeon_ioq_vector) * num_ioqs;
  659. oct->ioq_vector = vzalloc(size);
  660. if (!oct->ioq_vector)
  661. return 1;
  662. for (i = 0; i < num_ioqs; i++) {
  663. ioq_vector = &oct->ioq_vector[i];
  664. ioq_vector->oct_dev = oct;
  665. ioq_vector->iq_index = i;
  666. ioq_vector->droq_index = i;
  667. ioq_vector->mbox = oct->mbox[i];
  668. cpu_num = i % num_online_cpus();
  669. cpumask_set_cpu(cpu_num, &ioq_vector->affinity_mask);
  670. if (oct->chip_id == OCTEON_CN23XX_PF_VID)
  671. ioq_vector->ioq_num = i + oct->sriov_info.pf_srn;
  672. else
  673. ioq_vector->ioq_num = i;
  674. }
  675. return 0;
  676. }
  677. void
  678. octeon_free_ioq_vector(struct octeon_device *oct)
  679. {
  680. vfree(oct->ioq_vector);
  681. }
  682. /* this function is only for setting up the first queue */
  683. int octeon_setup_instr_queues(struct octeon_device *oct)
  684. {
  685. u32 num_descs = 0;
  686. u32 iq_no = 0;
  687. union oct_txpciq txpciq;
  688. int numa_node = dev_to_node(&oct->pci_dev->dev);
  689. if (OCTEON_CN6XXX(oct))
  690. num_descs =
  691. CFG_GET_NUM_DEF_TX_DESCS(CHIP_CONF(oct, cn6xxx));
  692. else if (OCTEON_CN23XX_PF(oct))
  693. num_descs = CFG_GET_NUM_DEF_TX_DESCS(CHIP_CONF(oct, cn23xx_pf));
  694. else if (OCTEON_CN23XX_VF(oct))
  695. num_descs = CFG_GET_NUM_DEF_TX_DESCS(CHIP_CONF(oct, cn23xx_vf));
  696. oct->num_iqs = 0;
  697. oct->instr_queue[0] = vzalloc_node(sizeof(*oct->instr_queue[0]),
  698. numa_node);
  699. if (!oct->instr_queue[0])
  700. oct->instr_queue[0] =
  701. vzalloc(sizeof(struct octeon_instr_queue));
  702. if (!oct->instr_queue[0])
  703. return 1;
  704. memset(oct->instr_queue[0], 0, sizeof(struct octeon_instr_queue));
  705. oct->instr_queue[0]->q_index = 0;
  706. oct->instr_queue[0]->app_ctx = (void *)(size_t)0;
  707. oct->instr_queue[0]->ifidx = 0;
  708. txpciq.u64 = 0;
  709. txpciq.s.q_no = iq_no;
  710. txpciq.s.pkind = oct->pfvf_hsword.pkind;
  711. txpciq.s.use_qpg = 0;
  712. txpciq.s.qpg = 0;
  713. if (octeon_init_instr_queue(oct, txpciq, num_descs)) {
  714. /* prevent memory leak */
  715. vfree(oct->instr_queue[0]);
  716. oct->instr_queue[0] = NULL;
  717. return 1;
  718. }
  719. oct->num_iqs++;
  720. return 0;
  721. }
  722. int octeon_setup_output_queues(struct octeon_device *oct)
  723. {
  724. u32 num_descs = 0;
  725. u32 desc_size = 0;
  726. u32 oq_no = 0;
  727. int numa_node = dev_to_node(&oct->pci_dev->dev);
  728. if (OCTEON_CN6XXX(oct)) {
  729. num_descs =
  730. CFG_GET_NUM_DEF_RX_DESCS(CHIP_CONF(oct, cn6xxx));
  731. desc_size =
  732. CFG_GET_DEF_RX_BUF_SIZE(CHIP_CONF(oct, cn6xxx));
  733. } else if (OCTEON_CN23XX_PF(oct)) {
  734. num_descs = CFG_GET_NUM_DEF_RX_DESCS(CHIP_CONF(oct, cn23xx_pf));
  735. desc_size = CFG_GET_DEF_RX_BUF_SIZE(CHIP_CONF(oct, cn23xx_pf));
  736. } else if (OCTEON_CN23XX_VF(oct)) {
  737. num_descs = CFG_GET_NUM_DEF_RX_DESCS(CHIP_CONF(oct, cn23xx_vf));
  738. desc_size = CFG_GET_DEF_RX_BUF_SIZE(CHIP_CONF(oct, cn23xx_vf));
  739. }
  740. oct->num_oqs = 0;
  741. oct->droq[0] = vzalloc_node(sizeof(*oct->droq[0]), numa_node);
  742. if (!oct->droq[0])
  743. oct->droq[0] = vzalloc(sizeof(*oct->droq[0]));
  744. if (!oct->droq[0])
  745. return 1;
  746. if (octeon_init_droq(oct, oq_no, num_descs, desc_size, NULL)) {
  747. vfree(oct->droq[oq_no]);
  748. oct->droq[oq_no] = NULL;
  749. return 1;
  750. }
  751. oct->num_oqs++;
  752. return 0;
  753. }
  754. int octeon_set_io_queues_off(struct octeon_device *oct)
  755. {
  756. int loop = BUSY_READING_REG_VF_LOOP_COUNT;
  757. if (OCTEON_CN6XXX(oct)) {
  758. octeon_write_csr(oct, CN6XXX_SLI_PKT_INSTR_ENB, 0);
  759. octeon_write_csr(oct, CN6XXX_SLI_PKT_OUT_ENB, 0);
  760. } else if (oct->chip_id == OCTEON_CN23XX_VF_VID) {
  761. u32 q_no;
  762. /* IOQs will already be in reset.
  763. * If RST bit is set, wait for quiet bit to be set.
  764. * Once quiet bit is set, clear the RST bit.
  765. */
  766. for (q_no = 0; q_no < oct->sriov_info.rings_per_vf; q_no++) {
  767. u64 reg_val = octeon_read_csr64(
  768. oct, CN23XX_VF_SLI_IQ_PKT_CONTROL64(q_no));
  769. while ((reg_val & CN23XX_PKT_INPUT_CTL_RST) &&
  770. !(reg_val & CN23XX_PKT_INPUT_CTL_QUIET) &&
  771. loop) {
  772. reg_val = octeon_read_csr64(
  773. oct, CN23XX_SLI_IQ_PKT_CONTROL64(q_no));
  774. loop--;
  775. }
  776. if (!loop) {
  777. dev_err(&oct->pci_dev->dev,
  778. "clearing the reset reg failed or setting the quiet reg failed for qno: %u\n",
  779. q_no);
  780. return -1;
  781. }
  782. reg_val = reg_val & ~CN23XX_PKT_INPUT_CTL_RST;
  783. octeon_write_csr64(oct,
  784. CN23XX_SLI_IQ_PKT_CONTROL64(q_no),
  785. reg_val);
  786. reg_val = octeon_read_csr64(
  787. oct, CN23XX_SLI_IQ_PKT_CONTROL64(q_no));
  788. if (reg_val & CN23XX_PKT_INPUT_CTL_RST) {
  789. dev_err(&oct->pci_dev->dev,
  790. "unable to reset qno %u\n", q_no);
  791. return -1;
  792. }
  793. }
  794. }
  795. return 0;
  796. }
  797. void octeon_set_droq_pkt_op(struct octeon_device *oct,
  798. u32 q_no,
  799. u32 enable)
  800. {
  801. u32 reg_val = 0;
  802. /* Disable the i/p and o/p queues for this Octeon. */
  803. if (OCTEON_CN6XXX(oct)) {
  804. reg_val = octeon_read_csr(oct, CN6XXX_SLI_PKT_OUT_ENB);
  805. if (enable)
  806. reg_val = reg_val | (1 << q_no);
  807. else
  808. reg_val = reg_val & (~(1 << q_no));
  809. octeon_write_csr(oct, CN6XXX_SLI_PKT_OUT_ENB, reg_val);
  810. }
  811. }
  812. int octeon_init_dispatch_list(struct octeon_device *oct)
  813. {
  814. u32 i;
  815. oct->dispatch.count = 0;
  816. for (i = 0; i < DISPATCH_LIST_SIZE; i++) {
  817. oct->dispatch.dlist[i].opcode = 0;
  818. INIT_LIST_HEAD(&oct->dispatch.dlist[i].list);
  819. }
  820. for (i = 0; i <= REQTYPE_LAST; i++)
  821. octeon_register_reqtype_free_fn(oct, i, NULL);
  822. spin_lock_init(&oct->dispatch.lock);
  823. return 0;
  824. }
  825. void octeon_delete_dispatch_list(struct octeon_device *oct)
  826. {
  827. u32 i;
  828. struct list_head freelist, *temp, *tmp2;
  829. INIT_LIST_HEAD(&freelist);
  830. spin_lock_bh(&oct->dispatch.lock);
  831. for (i = 0; i < DISPATCH_LIST_SIZE; i++) {
  832. struct list_head *dispatch;
  833. dispatch = &oct->dispatch.dlist[i].list;
  834. while (dispatch->next != dispatch) {
  835. temp = dispatch->next;
  836. list_del(temp);
  837. list_add_tail(temp, &freelist);
  838. }
  839. oct->dispatch.dlist[i].opcode = 0;
  840. }
  841. oct->dispatch.count = 0;
  842. spin_unlock_bh(&oct->dispatch.lock);
  843. list_for_each_safe(temp, tmp2, &freelist) {
  844. list_del(temp);
  845. vfree(temp);
  846. }
  847. }
  848. octeon_dispatch_fn_t
  849. octeon_get_dispatch(struct octeon_device *octeon_dev, u16 opcode,
  850. u16 subcode)
  851. {
  852. u32 idx;
  853. struct list_head *dispatch;
  854. octeon_dispatch_fn_t fn = NULL;
  855. u16 combined_opcode = OPCODE_SUBCODE(opcode, subcode);
  856. idx = combined_opcode & OCTEON_OPCODE_MASK;
  857. spin_lock_bh(&octeon_dev->dispatch.lock);
  858. if (octeon_dev->dispatch.count == 0) {
  859. spin_unlock_bh(&octeon_dev->dispatch.lock);
  860. return NULL;
  861. }
  862. if (!(octeon_dev->dispatch.dlist[idx].opcode)) {
  863. spin_unlock_bh(&octeon_dev->dispatch.lock);
  864. return NULL;
  865. }
  866. if (octeon_dev->dispatch.dlist[idx].opcode == combined_opcode) {
  867. fn = octeon_dev->dispatch.dlist[idx].dispatch_fn;
  868. } else {
  869. list_for_each(dispatch,
  870. &octeon_dev->dispatch.dlist[idx].list) {
  871. if (((struct octeon_dispatch *)dispatch)->opcode ==
  872. combined_opcode) {
  873. fn = ((struct octeon_dispatch *)
  874. dispatch)->dispatch_fn;
  875. break;
  876. }
  877. }
  878. }
  879. spin_unlock_bh(&octeon_dev->dispatch.lock);
  880. return fn;
  881. }
  882. /* octeon_register_dispatch_fn
  883. * Parameters:
  884. * octeon_id - id of the octeon device.
  885. * opcode - opcode for which driver should call the registered function
  886. * subcode - subcode for which driver should call the registered function
  887. * fn - The function to call when a packet with "opcode" arrives in
  888. * octeon output queues.
  889. * fn_arg - The argument to be passed when calling function "fn".
  890. * Description:
  891. * Registers a function and its argument to be called when a packet
  892. * arrives in Octeon output queues with "opcode".
  893. * Returns:
  894. * Success: 0
  895. * Failure: 1
  896. * Locks:
  897. * No locks are held.
  898. */
  899. int
  900. octeon_register_dispatch_fn(struct octeon_device *oct,
  901. u16 opcode,
  902. u16 subcode,
  903. octeon_dispatch_fn_t fn, void *fn_arg)
  904. {
  905. u32 idx;
  906. octeon_dispatch_fn_t pfn;
  907. u16 combined_opcode = OPCODE_SUBCODE(opcode, subcode);
  908. idx = combined_opcode & OCTEON_OPCODE_MASK;
  909. spin_lock_bh(&oct->dispatch.lock);
  910. /* Add dispatch function to first level of lookup table */
  911. if (oct->dispatch.dlist[idx].opcode == 0) {
  912. oct->dispatch.dlist[idx].opcode = combined_opcode;
  913. oct->dispatch.dlist[idx].dispatch_fn = fn;
  914. oct->dispatch.dlist[idx].arg = fn_arg;
  915. oct->dispatch.count++;
  916. spin_unlock_bh(&oct->dispatch.lock);
  917. return 0;
  918. }
  919. spin_unlock_bh(&oct->dispatch.lock);
  920. /* Check if there was a function already registered for this
  921. * opcode/subcode.
  922. */
  923. pfn = octeon_get_dispatch(oct, opcode, subcode);
  924. if (!pfn) {
  925. struct octeon_dispatch *dispatch;
  926. dev_dbg(&oct->pci_dev->dev,
  927. "Adding opcode to dispatch list linked list\n");
  928. dispatch = (struct octeon_dispatch *)
  929. vmalloc(sizeof(struct octeon_dispatch));
  930. if (!dispatch) {
  931. dev_err(&oct->pci_dev->dev,
  932. "No memory to add dispatch function\n");
  933. return 1;
  934. }
  935. dispatch->opcode = combined_opcode;
  936. dispatch->dispatch_fn = fn;
  937. dispatch->arg = fn_arg;
  938. /* Add dispatch function to linked list of fn ptrs
  939. * at the hashed index.
  940. */
  941. spin_lock_bh(&oct->dispatch.lock);
  942. list_add(&dispatch->list, &oct->dispatch.dlist[idx].list);
  943. oct->dispatch.count++;
  944. spin_unlock_bh(&oct->dispatch.lock);
  945. } else {
  946. if (pfn == fn &&
  947. octeon_get_dispatch_arg(oct, opcode, subcode) == fn_arg)
  948. return 0;
  949. dev_err(&oct->pci_dev->dev,
  950. "Found previously registered dispatch fn for opcode/subcode: %x/%x\n",
  951. opcode, subcode);
  952. return 1;
  953. }
  954. return 0;
  955. }
  956. int octeon_core_drv_init(struct octeon_recv_info *recv_info, void *buf)
  957. {
  958. u32 i;
  959. char app_name[16];
  960. struct octeon_device *oct = (struct octeon_device *)buf;
  961. struct octeon_recv_pkt *recv_pkt = recv_info->recv_pkt;
  962. struct octeon_core_setup *cs = NULL;
  963. u32 num_nic_ports = 0;
  964. if (OCTEON_CN6XXX(oct))
  965. num_nic_ports =
  966. CFG_GET_NUM_NIC_PORTS(CHIP_CONF(oct, cn6xxx));
  967. else if (OCTEON_CN23XX_PF(oct))
  968. num_nic_ports =
  969. CFG_GET_NUM_NIC_PORTS(CHIP_CONF(oct, cn23xx_pf));
  970. if (atomic_read(&oct->status) >= OCT_DEV_RUNNING) {
  971. dev_err(&oct->pci_dev->dev, "Received CORE OK when device state is 0x%x\n",
  972. atomic_read(&oct->status));
  973. goto core_drv_init_err;
  974. }
  975. strncpy(app_name,
  976. get_oct_app_string(
  977. (u32)recv_pkt->rh.r_core_drv_init.app_mode),
  978. sizeof(app_name) - 1);
  979. oct->app_mode = (u32)recv_pkt->rh.r_core_drv_init.app_mode;
  980. if (recv_pkt->rh.r_core_drv_init.app_mode == CVM_DRV_NIC_APP) {
  981. oct->fw_info.max_nic_ports =
  982. (u32)recv_pkt->rh.r_core_drv_init.max_nic_ports;
  983. oct->fw_info.num_gmx_ports =
  984. (u32)recv_pkt->rh.r_core_drv_init.num_gmx_ports;
  985. }
  986. if (oct->fw_info.max_nic_ports < num_nic_ports) {
  987. dev_err(&oct->pci_dev->dev,
  988. "Config has more ports than firmware allows (%d > %d).\n",
  989. num_nic_ports, oct->fw_info.max_nic_ports);
  990. goto core_drv_init_err;
  991. }
  992. oct->fw_info.app_cap_flags = recv_pkt->rh.r_core_drv_init.app_cap_flags;
  993. oct->fw_info.app_mode = (u32)recv_pkt->rh.r_core_drv_init.app_mode;
  994. oct->pfvf_hsword.app_mode = (u32)recv_pkt->rh.r_core_drv_init.app_mode;
  995. oct->pfvf_hsword.pkind = recv_pkt->rh.r_core_drv_init.pkind;
  996. for (i = 0; i < oct->num_iqs; i++)
  997. oct->instr_queue[i]->txpciq.s.pkind = oct->pfvf_hsword.pkind;
  998. atomic_set(&oct->status, OCT_DEV_CORE_OK);
  999. cs = &core_setup[oct->octeon_id];
  1000. if (recv_pkt->buffer_size[0] != (sizeof(*cs) + OCT_DROQ_INFO_SIZE)) {
  1001. dev_dbg(&oct->pci_dev->dev, "Core setup bytes expected %u found %d\n",
  1002. (u32)sizeof(*cs),
  1003. recv_pkt->buffer_size[0]);
  1004. }
  1005. memcpy(cs, get_rbd(
  1006. recv_pkt->buffer_ptr[0]) + OCT_DROQ_INFO_SIZE, sizeof(*cs));
  1007. strncpy(oct->boardinfo.name, cs->boardname, OCT_BOARD_NAME);
  1008. strncpy(oct->boardinfo.serial_number, cs->board_serial_number,
  1009. OCT_SERIAL_LEN);
  1010. octeon_swap_8B_data((u64 *)cs, (sizeof(*cs) >> 3));
  1011. oct->boardinfo.major = cs->board_rev_major;
  1012. oct->boardinfo.minor = cs->board_rev_minor;
  1013. dev_info(&oct->pci_dev->dev,
  1014. "Running %s (%llu Hz)\n",
  1015. app_name, CVM_CAST64(cs->corefreq));
  1016. core_drv_init_err:
  1017. for (i = 0; i < recv_pkt->buffer_count; i++)
  1018. recv_buffer_free(recv_pkt->buffer_ptr[i]);
  1019. octeon_free_recv_info(recv_info);
  1020. return 0;
  1021. }
  1022. int octeon_get_tx_qsize(struct octeon_device *oct, u32 q_no)
  1023. {
  1024. if (oct && (q_no < MAX_OCTEON_INSTR_QUEUES(oct)) &&
  1025. (oct->io_qmask.iq & BIT_ULL(q_no)))
  1026. return oct->instr_queue[q_no]->max_count;
  1027. return -1;
  1028. }
  1029. int octeon_get_rx_qsize(struct octeon_device *oct, u32 q_no)
  1030. {
  1031. if (oct && (q_no < MAX_OCTEON_OUTPUT_QUEUES(oct)) &&
  1032. (oct->io_qmask.oq & BIT_ULL(q_no)))
  1033. return oct->droq[q_no]->max_count;
  1034. return -1;
  1035. }
  1036. /* Retruns the host firmware handshake OCTEON specific configuration */
  1037. struct octeon_config *octeon_get_conf(struct octeon_device *oct)
  1038. {
  1039. struct octeon_config *default_oct_conf = NULL;
  1040. /* check the OCTEON Device model & return the corresponding octeon
  1041. * configuration
  1042. */
  1043. if (OCTEON_CN6XXX(oct)) {
  1044. default_oct_conf =
  1045. (struct octeon_config *)(CHIP_CONF(oct, cn6xxx));
  1046. } else if (OCTEON_CN23XX_PF(oct)) {
  1047. default_oct_conf = (struct octeon_config *)
  1048. (CHIP_CONF(oct, cn23xx_pf));
  1049. } else if (OCTEON_CN23XX_VF(oct)) {
  1050. default_oct_conf = (struct octeon_config *)
  1051. (CHIP_CONF(oct, cn23xx_vf));
  1052. }
  1053. return default_oct_conf;
  1054. }
  1055. /* scratch register address is same in all the OCT-II and CN70XX models */
  1056. #define CNXX_SLI_SCRATCH1 0x3C0
  1057. /** Get the octeon device pointer.
  1058. * @param octeon_id - The id for which the octeon device pointer is required.
  1059. * @return Success: Octeon device pointer.
  1060. * @return Failure: NULL.
  1061. */
  1062. struct octeon_device *lio_get_device(u32 octeon_id)
  1063. {
  1064. if (octeon_id >= MAX_OCTEON_DEVICES)
  1065. return NULL;
  1066. else
  1067. return octeon_device[octeon_id];
  1068. }
  1069. u64 lio_pci_readq(struct octeon_device *oct, u64 addr)
  1070. {
  1071. u64 val64;
  1072. unsigned long flags;
  1073. u32 val32, addrhi;
  1074. spin_lock_irqsave(&oct->pci_win_lock, flags);
  1075. /* The windowed read happens when the LSB of the addr is written.
  1076. * So write MSB first
  1077. */
  1078. addrhi = (addr >> 32);
  1079. if ((oct->chip_id == OCTEON_CN66XX) ||
  1080. (oct->chip_id == OCTEON_CN68XX) ||
  1081. (oct->chip_id == OCTEON_CN23XX_PF_VID))
  1082. addrhi |= 0x00060000;
  1083. writel(addrhi, oct->reg_list.pci_win_rd_addr_hi);
  1084. /* Read back to preserve ordering of writes */
  1085. val32 = readl(oct->reg_list.pci_win_rd_addr_hi);
  1086. writel(addr & 0xffffffff, oct->reg_list.pci_win_rd_addr_lo);
  1087. val32 = readl(oct->reg_list.pci_win_rd_addr_lo);
  1088. val64 = readq(oct->reg_list.pci_win_rd_data);
  1089. spin_unlock_irqrestore(&oct->pci_win_lock, flags);
  1090. return val64;
  1091. }
  1092. void lio_pci_writeq(struct octeon_device *oct,
  1093. u64 val,
  1094. u64 addr)
  1095. {
  1096. u32 val32;
  1097. unsigned long flags;
  1098. spin_lock_irqsave(&oct->pci_win_lock, flags);
  1099. writeq(addr, oct->reg_list.pci_win_wr_addr);
  1100. /* The write happens when the LSB is written. So write MSB first. */
  1101. writel(val >> 32, oct->reg_list.pci_win_wr_data_hi);
  1102. /* Read the MSB to ensure ordering of writes. */
  1103. val32 = readl(oct->reg_list.pci_win_wr_data_hi);
  1104. writel(val & 0xffffffff, oct->reg_list.pci_win_wr_data_lo);
  1105. spin_unlock_irqrestore(&oct->pci_win_lock, flags);
  1106. }
  1107. int octeon_mem_access_ok(struct octeon_device *oct)
  1108. {
  1109. u64 access_okay = 0;
  1110. u64 lmc0_reset_ctl;
  1111. /* Check to make sure a DDR interface is enabled */
  1112. if (OCTEON_CN23XX_PF(oct)) {
  1113. lmc0_reset_ctl = lio_pci_readq(oct, CN23XX_LMC0_RESET_CTL);
  1114. access_okay =
  1115. (lmc0_reset_ctl & CN23XX_LMC0_RESET_CTL_DDR3RST_MASK);
  1116. } else {
  1117. lmc0_reset_ctl = lio_pci_readq(oct, CN6XXX_LMC0_RESET_CTL);
  1118. access_okay =
  1119. (lmc0_reset_ctl & CN6XXX_LMC0_RESET_CTL_DDR3RST_MASK);
  1120. }
  1121. return access_okay ? 0 : 1;
  1122. }
  1123. int octeon_wait_for_ddr_init(struct octeon_device *oct, u32 *timeout)
  1124. {
  1125. int ret = 1;
  1126. u32 ms;
  1127. if (!timeout)
  1128. return ret;
  1129. for (ms = 0; (ret != 0) && ((*timeout == 0) || (ms <= *timeout));
  1130. ms += HZ / 10) {
  1131. ret = octeon_mem_access_ok(oct);
  1132. /* wait 100 ms */
  1133. if (ret)
  1134. schedule_timeout_uninterruptible(HZ / 10);
  1135. }
  1136. return ret;
  1137. }
  1138. /** Get the octeon id assigned to the octeon device passed as argument.
  1139. * This function is exported to other modules.
  1140. * @param dev - octeon device pointer passed as a void *.
  1141. * @return octeon device id
  1142. */
  1143. int lio_get_device_id(void *dev)
  1144. {
  1145. struct octeon_device *octeon_dev = (struct octeon_device *)dev;
  1146. u32 i;
  1147. for (i = 0; i < MAX_OCTEON_DEVICES; i++)
  1148. if (octeon_device[i] == octeon_dev)
  1149. return octeon_dev->octeon_id;
  1150. return -1;
  1151. }
  1152. void lio_enable_irq(struct octeon_droq *droq, struct octeon_instr_queue *iq)
  1153. {
  1154. u64 instr_cnt;
  1155. u32 pkts_pend;
  1156. struct octeon_device *oct = NULL;
  1157. /* the whole thing needs to be atomic, ideally */
  1158. if (droq) {
  1159. pkts_pend = (u32)atomic_read(&droq->pkts_pending);
  1160. spin_lock_bh(&droq->lock);
  1161. writel(droq->pkt_count - pkts_pend, droq->pkts_sent_reg);
  1162. droq->pkt_count = pkts_pend;
  1163. /* this write needs to be flushed before we release the lock */
  1164. mmiowb();
  1165. spin_unlock_bh(&droq->lock);
  1166. oct = droq->oct_dev;
  1167. }
  1168. if (iq) {
  1169. spin_lock_bh(&iq->lock);
  1170. writel(iq->pkt_in_done, iq->inst_cnt_reg);
  1171. iq->pkt_in_done = 0;
  1172. /* this write needs to be flushed before we release the lock */
  1173. mmiowb();
  1174. spin_unlock_bh(&iq->lock);
  1175. oct = iq->oct_dev;
  1176. }
  1177. /*write resend. Writing RESEND in SLI_PKTX_CNTS should be enough
  1178. *to trigger tx interrupts as well, if they are pending.
  1179. */
  1180. if (oct && (OCTEON_CN23XX_PF(oct) || OCTEON_CN23XX_VF(oct))) {
  1181. if (droq)
  1182. writeq(CN23XX_INTR_RESEND, droq->pkts_sent_reg);
  1183. /*we race with firmrware here. read and write the IN_DONE_CNTS*/
  1184. else if (iq) {
  1185. instr_cnt = readq(iq->inst_cnt_reg);
  1186. writeq(((instr_cnt & 0xFFFFFFFF00000000ULL) |
  1187. CN23XX_INTR_RESEND),
  1188. iq->inst_cnt_reg);
  1189. }
  1190. }
  1191. }