octeon_device.c 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468
  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 u32 octeon_device_count;
  418. /* locks device array (i.e. octeon_device[]) */
  419. static spinlock_t octeon_devices_lock;
  420. static struct octeon_core_setup core_setup[MAX_OCTEON_DEVICES];
  421. static void oct_set_config_info(int oct_id, int conf_type)
  422. {
  423. if (conf_type < 0 || conf_type > (NUM_OCTEON_CONFS - 1))
  424. conf_type = OCTEON_CONFIG_TYPE_DEFAULT;
  425. oct_conf_info[oct_id].conf_type = conf_type;
  426. }
  427. void octeon_init_device_list(int conf_type)
  428. {
  429. int i;
  430. memset(octeon_device, 0, (sizeof(void *) * MAX_OCTEON_DEVICES));
  431. for (i = 0; i < MAX_OCTEON_DEVICES; i++)
  432. oct_set_config_info(i, conf_type);
  433. spin_lock_init(&octeon_devices_lock);
  434. }
  435. static void *__retrieve_octeon_config_info(struct octeon_device *oct,
  436. u16 card_type)
  437. {
  438. u32 oct_id = oct->octeon_id;
  439. void *ret = NULL;
  440. switch (oct_conf_info[oct_id].conf_type) {
  441. case OCTEON_CONFIG_TYPE_DEFAULT:
  442. if (oct->chip_id == OCTEON_CN66XX) {
  443. ret = &default_cn66xx_conf;
  444. } else if ((oct->chip_id == OCTEON_CN68XX) &&
  445. (card_type == LIO_210NV)) {
  446. ret = &default_cn68xx_210nv_conf;
  447. } else if ((oct->chip_id == OCTEON_CN68XX) &&
  448. (card_type == LIO_410NV)) {
  449. ret = &default_cn68xx_conf;
  450. } else if (oct->chip_id == OCTEON_CN23XX_PF_VID) {
  451. ret = &default_cn23xx_conf;
  452. } else if (oct->chip_id == OCTEON_CN23XX_VF_VID) {
  453. ret = &default_cn23xx_conf;
  454. }
  455. break;
  456. default:
  457. break;
  458. }
  459. return ret;
  460. }
  461. static int __verify_octeon_config_info(struct octeon_device *oct, void *conf)
  462. {
  463. switch (oct->chip_id) {
  464. case OCTEON_CN66XX:
  465. case OCTEON_CN68XX:
  466. return lio_validate_cn6xxx_config_info(oct, conf);
  467. case OCTEON_CN23XX_PF_VID:
  468. case OCTEON_CN23XX_VF_VID:
  469. return 0;
  470. default:
  471. break;
  472. }
  473. return 1;
  474. }
  475. void *oct_get_config_info(struct octeon_device *oct, u16 card_type)
  476. {
  477. void *conf = NULL;
  478. conf = __retrieve_octeon_config_info(oct, card_type);
  479. if (!conf)
  480. return NULL;
  481. if (__verify_octeon_config_info(oct, conf)) {
  482. dev_err(&oct->pci_dev->dev, "Configuration verification failed\n");
  483. return NULL;
  484. }
  485. return conf;
  486. }
  487. char *lio_get_state_string(atomic_t *state_ptr)
  488. {
  489. s32 istate = (s32)atomic_read(state_ptr);
  490. if (istate > OCT_DEV_STATES || istate < 0)
  491. return oct_dev_state_str[OCT_DEV_STATE_INVALID];
  492. return oct_dev_state_str[istate];
  493. }
  494. static char *get_oct_app_string(u32 app_mode)
  495. {
  496. if (app_mode <= CVM_DRV_APP_END)
  497. return oct_dev_app_str[app_mode - CVM_DRV_APP_START];
  498. return oct_dev_app_str[CVM_DRV_INVALID_APP - CVM_DRV_APP_START];
  499. }
  500. void octeon_free_device_mem(struct octeon_device *oct)
  501. {
  502. int i;
  503. for (i = 0; i < MAX_OCTEON_OUTPUT_QUEUES(oct); i++) {
  504. if (oct->io_qmask.oq & BIT_ULL(i))
  505. vfree(oct->droq[i]);
  506. }
  507. for (i = 0; i < MAX_OCTEON_INSTR_QUEUES(oct); i++) {
  508. if (oct->io_qmask.iq & BIT_ULL(i))
  509. vfree(oct->instr_queue[i]);
  510. }
  511. i = oct->octeon_id;
  512. vfree(oct);
  513. octeon_device[i] = NULL;
  514. octeon_device_count--;
  515. }
  516. static struct octeon_device *octeon_allocate_device_mem(u32 pci_id,
  517. u32 priv_size)
  518. {
  519. struct octeon_device *oct;
  520. u8 *buf = NULL;
  521. u32 octdevsize = 0, configsize = 0, size;
  522. switch (pci_id) {
  523. case OCTEON_CN68XX:
  524. case OCTEON_CN66XX:
  525. configsize = sizeof(struct octeon_cn6xxx);
  526. break;
  527. case OCTEON_CN23XX_PF_VID:
  528. configsize = sizeof(struct octeon_cn23xx_pf);
  529. break;
  530. case OCTEON_CN23XX_VF_VID:
  531. configsize = sizeof(struct octeon_cn23xx_vf);
  532. break;
  533. default:
  534. pr_err("%s: Unknown PCI Device: 0x%x\n",
  535. __func__,
  536. pci_id);
  537. return NULL;
  538. }
  539. if (configsize & 0x7)
  540. configsize += (8 - (configsize & 0x7));
  541. octdevsize = sizeof(struct octeon_device);
  542. if (octdevsize & 0x7)
  543. octdevsize += (8 - (octdevsize & 0x7));
  544. if (priv_size & 0x7)
  545. priv_size += (8 - (priv_size & 0x7));
  546. size = octdevsize + priv_size + configsize +
  547. (sizeof(struct octeon_dispatch) * DISPATCH_LIST_SIZE);
  548. buf = vmalloc(size);
  549. if (!buf)
  550. return NULL;
  551. memset(buf, 0, size);
  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. spin_lock(&octeon_devices_lock);
  603. for (idx = (int)oct->octeon_id - 1; idx >= 0; idx--) {
  604. if (!octeon_device[idx]) {
  605. dev_err(&oct->pci_dev->dev,
  606. "%s: Internal driver error, missing dev",
  607. __func__);
  608. spin_unlock(&octeon_devices_lock);
  609. atomic_inc(oct->adapter_refcount);
  610. return 1; /* here, refcount is guaranteed to be 1 */
  611. }
  612. /* if another device is at same bus/dev, use its refcounter */
  613. if ((octeon_device[idx]->loc.bus == bus) &&
  614. (octeon_device[idx]->loc.dev == dev)) {
  615. oct->adapter_refcount =
  616. octeon_device[idx]->adapter_refcount;
  617. break;
  618. }
  619. }
  620. spin_unlock(&octeon_devices_lock);
  621. atomic_inc(oct->adapter_refcount);
  622. refcount = atomic_read(oct->adapter_refcount);
  623. dev_dbg(&oct->pci_dev->dev, "%s: %02x:%02x:%d refcount %u", __func__,
  624. oct->loc.bus, oct->loc.dev, oct->loc.func, refcount);
  625. return refcount;
  626. }
  627. /** Deregister a device at de-initialization time.
  628. * @param octeon_dev - pointer to the octeon device structure.
  629. * @return reference count of device's adapter
  630. */
  631. int octeon_deregister_device(struct octeon_device *oct)
  632. {
  633. int refcount;
  634. atomic_dec(oct->adapter_refcount);
  635. refcount = atomic_read(oct->adapter_refcount);
  636. dev_dbg(&oct->pci_dev->dev, "%s: %04d:%02d:%d refcount %u", __func__,
  637. oct->loc.bus, oct->loc.dev, oct->loc.func, refcount);
  638. return refcount;
  639. }
  640. int
  641. octeon_allocate_ioq_vector(struct octeon_device *oct)
  642. {
  643. int i, num_ioqs = 0;
  644. struct octeon_ioq_vector *ioq_vector;
  645. int cpu_num;
  646. int size;
  647. if (OCTEON_CN23XX_PF(oct))
  648. num_ioqs = oct->sriov_info.num_pf_rings;
  649. else if (OCTEON_CN23XX_VF(oct))
  650. num_ioqs = oct->sriov_info.rings_per_vf;
  651. size = sizeof(struct octeon_ioq_vector) * num_ioqs;
  652. oct->ioq_vector = vmalloc(size);
  653. if (!oct->ioq_vector)
  654. return 1;
  655. memset(oct->ioq_vector, 0, size);
  656. for (i = 0; i < num_ioqs; i++) {
  657. ioq_vector = &oct->ioq_vector[i];
  658. ioq_vector->oct_dev = oct;
  659. ioq_vector->iq_index = i;
  660. ioq_vector->droq_index = i;
  661. ioq_vector->mbox = oct->mbox[i];
  662. cpu_num = i % num_online_cpus();
  663. cpumask_set_cpu(cpu_num, &ioq_vector->affinity_mask);
  664. if (oct->chip_id == OCTEON_CN23XX_PF_VID)
  665. ioq_vector->ioq_num = i + oct->sriov_info.pf_srn;
  666. else
  667. ioq_vector->ioq_num = i;
  668. }
  669. return 0;
  670. }
  671. void
  672. octeon_free_ioq_vector(struct octeon_device *oct)
  673. {
  674. vfree(oct->ioq_vector);
  675. }
  676. /* this function is only for setting up the first queue */
  677. int octeon_setup_instr_queues(struct octeon_device *oct)
  678. {
  679. u32 num_descs = 0;
  680. u32 iq_no = 0;
  681. union oct_txpciq txpciq;
  682. int numa_node = dev_to_node(&oct->pci_dev->dev);
  683. if (OCTEON_CN6XXX(oct))
  684. num_descs =
  685. CFG_GET_NUM_DEF_TX_DESCS(CHIP_CONF(oct, cn6xxx));
  686. else if (OCTEON_CN23XX_PF(oct))
  687. num_descs = CFG_GET_NUM_DEF_TX_DESCS(CHIP_CONF(oct, cn23xx_pf));
  688. else if (OCTEON_CN23XX_VF(oct))
  689. num_descs = CFG_GET_NUM_DEF_TX_DESCS(CHIP_CONF(oct, cn23xx_vf));
  690. oct->num_iqs = 0;
  691. oct->instr_queue[0] = vzalloc_node(sizeof(*oct->instr_queue[0]),
  692. numa_node);
  693. if (!oct->instr_queue[0])
  694. oct->instr_queue[0] =
  695. vzalloc(sizeof(struct octeon_instr_queue));
  696. if (!oct->instr_queue[0])
  697. return 1;
  698. memset(oct->instr_queue[0], 0, sizeof(struct octeon_instr_queue));
  699. oct->instr_queue[0]->q_index = 0;
  700. oct->instr_queue[0]->app_ctx = (void *)(size_t)0;
  701. oct->instr_queue[0]->ifidx = 0;
  702. txpciq.u64 = 0;
  703. txpciq.s.q_no = iq_no;
  704. txpciq.s.pkind = oct->pfvf_hsword.pkind;
  705. txpciq.s.use_qpg = 0;
  706. txpciq.s.qpg = 0;
  707. if (octeon_init_instr_queue(oct, txpciq, num_descs)) {
  708. /* prevent memory leak */
  709. vfree(oct->instr_queue[0]);
  710. oct->instr_queue[0] = NULL;
  711. return 1;
  712. }
  713. oct->num_iqs++;
  714. return 0;
  715. }
  716. int octeon_setup_output_queues(struct octeon_device *oct)
  717. {
  718. u32 num_descs = 0;
  719. u32 desc_size = 0;
  720. u32 oq_no = 0;
  721. int numa_node = dev_to_node(&oct->pci_dev->dev);
  722. if (OCTEON_CN6XXX(oct)) {
  723. num_descs =
  724. CFG_GET_NUM_DEF_RX_DESCS(CHIP_CONF(oct, cn6xxx));
  725. desc_size =
  726. CFG_GET_DEF_RX_BUF_SIZE(CHIP_CONF(oct, cn6xxx));
  727. } else if (OCTEON_CN23XX_PF(oct)) {
  728. num_descs = CFG_GET_NUM_DEF_RX_DESCS(CHIP_CONF(oct, cn23xx_pf));
  729. desc_size = CFG_GET_DEF_RX_BUF_SIZE(CHIP_CONF(oct, cn23xx_pf));
  730. } else if (OCTEON_CN23XX_VF(oct)) {
  731. num_descs = CFG_GET_NUM_DEF_RX_DESCS(CHIP_CONF(oct, cn23xx_vf));
  732. desc_size = CFG_GET_DEF_RX_BUF_SIZE(CHIP_CONF(oct, cn23xx_vf));
  733. }
  734. oct->num_oqs = 0;
  735. oct->droq[0] = vzalloc_node(sizeof(*oct->droq[0]), numa_node);
  736. if (!oct->droq[0])
  737. oct->droq[0] = vzalloc(sizeof(*oct->droq[0]));
  738. if (!oct->droq[0])
  739. return 1;
  740. if (octeon_init_droq(oct, oq_no, num_descs, desc_size, NULL)) {
  741. vfree(oct->droq[oq_no]);
  742. oct->droq[oq_no] = NULL;
  743. return 1;
  744. }
  745. oct->num_oqs++;
  746. return 0;
  747. }
  748. int octeon_set_io_queues_off(struct octeon_device *oct)
  749. {
  750. int loop = BUSY_READING_REG_VF_LOOP_COUNT;
  751. if (OCTEON_CN6XXX(oct)) {
  752. octeon_write_csr(oct, CN6XXX_SLI_PKT_INSTR_ENB, 0);
  753. octeon_write_csr(oct, CN6XXX_SLI_PKT_OUT_ENB, 0);
  754. } else if (oct->chip_id == OCTEON_CN23XX_VF_VID) {
  755. u32 q_no;
  756. /* IOQs will already be in reset.
  757. * If RST bit is set, wait for quiet bit to be set.
  758. * Once quiet bit is set, clear the RST bit.
  759. */
  760. for (q_no = 0; q_no < oct->sriov_info.rings_per_vf; q_no++) {
  761. u64 reg_val = octeon_read_csr64(
  762. oct, CN23XX_VF_SLI_IQ_PKT_CONTROL64(q_no));
  763. while ((reg_val & CN23XX_PKT_INPUT_CTL_RST) &&
  764. !(reg_val & CN23XX_PKT_INPUT_CTL_QUIET) &&
  765. loop) {
  766. reg_val = octeon_read_csr64(
  767. oct, CN23XX_SLI_IQ_PKT_CONTROL64(q_no));
  768. loop--;
  769. }
  770. if (!loop) {
  771. dev_err(&oct->pci_dev->dev,
  772. "clearing the reset reg failed or setting the quiet reg failed for qno: %u\n",
  773. q_no);
  774. return -1;
  775. }
  776. reg_val = reg_val & ~CN23XX_PKT_INPUT_CTL_RST;
  777. octeon_write_csr64(oct,
  778. CN23XX_SLI_IQ_PKT_CONTROL64(q_no),
  779. reg_val);
  780. reg_val = octeon_read_csr64(
  781. oct, CN23XX_SLI_IQ_PKT_CONTROL64(q_no));
  782. if (reg_val & CN23XX_PKT_INPUT_CTL_RST) {
  783. dev_err(&oct->pci_dev->dev,
  784. "unable to reset qno %u\n", q_no);
  785. return -1;
  786. }
  787. }
  788. }
  789. return 0;
  790. }
  791. void octeon_set_droq_pkt_op(struct octeon_device *oct,
  792. u32 q_no,
  793. u32 enable)
  794. {
  795. u32 reg_val = 0;
  796. /* Disable the i/p and o/p queues for this Octeon. */
  797. if (OCTEON_CN6XXX(oct)) {
  798. reg_val = octeon_read_csr(oct, CN6XXX_SLI_PKT_OUT_ENB);
  799. if (enable)
  800. reg_val = reg_val | (1 << q_no);
  801. else
  802. reg_val = reg_val & (~(1 << q_no));
  803. octeon_write_csr(oct, CN6XXX_SLI_PKT_OUT_ENB, reg_val);
  804. }
  805. }
  806. int octeon_init_dispatch_list(struct octeon_device *oct)
  807. {
  808. u32 i;
  809. oct->dispatch.count = 0;
  810. for (i = 0; i < DISPATCH_LIST_SIZE; i++) {
  811. oct->dispatch.dlist[i].opcode = 0;
  812. INIT_LIST_HEAD(&oct->dispatch.dlist[i].list);
  813. }
  814. for (i = 0; i <= REQTYPE_LAST; i++)
  815. octeon_register_reqtype_free_fn(oct, i, NULL);
  816. spin_lock_init(&oct->dispatch.lock);
  817. return 0;
  818. }
  819. void octeon_delete_dispatch_list(struct octeon_device *oct)
  820. {
  821. u32 i;
  822. struct list_head freelist, *temp, *tmp2;
  823. INIT_LIST_HEAD(&freelist);
  824. spin_lock_bh(&oct->dispatch.lock);
  825. for (i = 0; i < DISPATCH_LIST_SIZE; i++) {
  826. struct list_head *dispatch;
  827. dispatch = &oct->dispatch.dlist[i].list;
  828. while (dispatch->next != dispatch) {
  829. temp = dispatch->next;
  830. list_del(temp);
  831. list_add_tail(temp, &freelist);
  832. }
  833. oct->dispatch.dlist[i].opcode = 0;
  834. }
  835. oct->dispatch.count = 0;
  836. spin_unlock_bh(&oct->dispatch.lock);
  837. list_for_each_safe(temp, tmp2, &freelist) {
  838. list_del(temp);
  839. vfree(temp);
  840. }
  841. }
  842. octeon_dispatch_fn_t
  843. octeon_get_dispatch(struct octeon_device *octeon_dev, u16 opcode,
  844. u16 subcode)
  845. {
  846. u32 idx;
  847. struct list_head *dispatch;
  848. octeon_dispatch_fn_t fn = NULL;
  849. u16 combined_opcode = OPCODE_SUBCODE(opcode, subcode);
  850. idx = combined_opcode & OCTEON_OPCODE_MASK;
  851. spin_lock_bh(&octeon_dev->dispatch.lock);
  852. if (octeon_dev->dispatch.count == 0) {
  853. spin_unlock_bh(&octeon_dev->dispatch.lock);
  854. return NULL;
  855. }
  856. if (!(octeon_dev->dispatch.dlist[idx].opcode)) {
  857. spin_unlock_bh(&octeon_dev->dispatch.lock);
  858. return NULL;
  859. }
  860. if (octeon_dev->dispatch.dlist[idx].opcode == combined_opcode) {
  861. fn = octeon_dev->dispatch.dlist[idx].dispatch_fn;
  862. } else {
  863. list_for_each(dispatch,
  864. &octeon_dev->dispatch.dlist[idx].list) {
  865. if (((struct octeon_dispatch *)dispatch)->opcode ==
  866. combined_opcode) {
  867. fn = ((struct octeon_dispatch *)
  868. dispatch)->dispatch_fn;
  869. break;
  870. }
  871. }
  872. }
  873. spin_unlock_bh(&octeon_dev->dispatch.lock);
  874. return fn;
  875. }
  876. /* octeon_register_dispatch_fn
  877. * Parameters:
  878. * octeon_id - id of the octeon device.
  879. * opcode - opcode for which driver should call the registered function
  880. * subcode - subcode for which driver should call the registered function
  881. * fn - The function to call when a packet with "opcode" arrives in
  882. * octeon output queues.
  883. * fn_arg - The argument to be passed when calling function "fn".
  884. * Description:
  885. * Registers a function and its argument to be called when a packet
  886. * arrives in Octeon output queues with "opcode".
  887. * Returns:
  888. * Success: 0
  889. * Failure: 1
  890. * Locks:
  891. * No locks are held.
  892. */
  893. int
  894. octeon_register_dispatch_fn(struct octeon_device *oct,
  895. u16 opcode,
  896. u16 subcode,
  897. octeon_dispatch_fn_t fn, void *fn_arg)
  898. {
  899. u32 idx;
  900. octeon_dispatch_fn_t pfn;
  901. u16 combined_opcode = OPCODE_SUBCODE(opcode, subcode);
  902. idx = combined_opcode & OCTEON_OPCODE_MASK;
  903. spin_lock_bh(&oct->dispatch.lock);
  904. /* Add dispatch function to first level of lookup table */
  905. if (oct->dispatch.dlist[idx].opcode == 0) {
  906. oct->dispatch.dlist[idx].opcode = combined_opcode;
  907. oct->dispatch.dlist[idx].dispatch_fn = fn;
  908. oct->dispatch.dlist[idx].arg = fn_arg;
  909. oct->dispatch.count++;
  910. spin_unlock_bh(&oct->dispatch.lock);
  911. return 0;
  912. }
  913. spin_unlock_bh(&oct->dispatch.lock);
  914. /* Check if there was a function already registered for this
  915. * opcode/subcode.
  916. */
  917. pfn = octeon_get_dispatch(oct, opcode, subcode);
  918. if (!pfn) {
  919. struct octeon_dispatch *dispatch;
  920. dev_dbg(&oct->pci_dev->dev,
  921. "Adding opcode to dispatch list linked list\n");
  922. dispatch = (struct octeon_dispatch *)
  923. vmalloc(sizeof(struct octeon_dispatch));
  924. if (!dispatch) {
  925. dev_err(&oct->pci_dev->dev,
  926. "No memory to add dispatch function\n");
  927. return 1;
  928. }
  929. dispatch->opcode = combined_opcode;
  930. dispatch->dispatch_fn = fn;
  931. dispatch->arg = fn_arg;
  932. /* Add dispatch function to linked list of fn ptrs
  933. * at the hashed index.
  934. */
  935. spin_lock_bh(&oct->dispatch.lock);
  936. list_add(&dispatch->list, &oct->dispatch.dlist[idx].list);
  937. oct->dispatch.count++;
  938. spin_unlock_bh(&oct->dispatch.lock);
  939. } else {
  940. dev_err(&oct->pci_dev->dev,
  941. "Found previously registered dispatch fn for opcode/subcode: %x/%x\n",
  942. opcode, subcode);
  943. return 1;
  944. }
  945. return 0;
  946. }
  947. int octeon_core_drv_init(struct octeon_recv_info *recv_info, void *buf)
  948. {
  949. u32 i;
  950. char app_name[16];
  951. struct octeon_device *oct = (struct octeon_device *)buf;
  952. struct octeon_recv_pkt *recv_pkt = recv_info->recv_pkt;
  953. struct octeon_core_setup *cs = NULL;
  954. u32 num_nic_ports = 0;
  955. if (OCTEON_CN6XXX(oct))
  956. num_nic_ports =
  957. CFG_GET_NUM_NIC_PORTS(CHIP_CONF(oct, cn6xxx));
  958. else if (OCTEON_CN23XX_PF(oct))
  959. num_nic_ports =
  960. CFG_GET_NUM_NIC_PORTS(CHIP_CONF(oct, cn23xx_pf));
  961. if (atomic_read(&oct->status) >= OCT_DEV_RUNNING) {
  962. dev_err(&oct->pci_dev->dev, "Received CORE OK when device state is 0x%x\n",
  963. atomic_read(&oct->status));
  964. goto core_drv_init_err;
  965. }
  966. strncpy(app_name,
  967. get_oct_app_string(
  968. (u32)recv_pkt->rh.r_core_drv_init.app_mode),
  969. sizeof(app_name) - 1);
  970. oct->app_mode = (u32)recv_pkt->rh.r_core_drv_init.app_mode;
  971. if (recv_pkt->rh.r_core_drv_init.app_mode == CVM_DRV_NIC_APP) {
  972. oct->fw_info.max_nic_ports =
  973. (u32)recv_pkt->rh.r_core_drv_init.max_nic_ports;
  974. oct->fw_info.num_gmx_ports =
  975. (u32)recv_pkt->rh.r_core_drv_init.num_gmx_ports;
  976. }
  977. if (oct->fw_info.max_nic_ports < num_nic_ports) {
  978. dev_err(&oct->pci_dev->dev,
  979. "Config has more ports than firmware allows (%d > %d).\n",
  980. num_nic_ports, oct->fw_info.max_nic_ports);
  981. goto core_drv_init_err;
  982. }
  983. oct->fw_info.app_cap_flags = recv_pkt->rh.r_core_drv_init.app_cap_flags;
  984. oct->fw_info.app_mode = (u32)recv_pkt->rh.r_core_drv_init.app_mode;
  985. oct->pfvf_hsword.app_mode = (u32)recv_pkt->rh.r_core_drv_init.app_mode;
  986. oct->pfvf_hsword.pkind = recv_pkt->rh.r_core_drv_init.pkind;
  987. for (i = 0; i < oct->num_iqs; i++)
  988. oct->instr_queue[i]->txpciq.s.pkind = oct->pfvf_hsword.pkind;
  989. atomic_set(&oct->status, OCT_DEV_CORE_OK);
  990. cs = &core_setup[oct->octeon_id];
  991. if (recv_pkt->buffer_size[0] != (sizeof(*cs) + OCT_DROQ_INFO_SIZE)) {
  992. dev_dbg(&oct->pci_dev->dev, "Core setup bytes expected %u found %d\n",
  993. (u32)sizeof(*cs),
  994. recv_pkt->buffer_size[0]);
  995. }
  996. memcpy(cs, get_rbd(
  997. recv_pkt->buffer_ptr[0]) + OCT_DROQ_INFO_SIZE, sizeof(*cs));
  998. strncpy(oct->boardinfo.name, cs->boardname, OCT_BOARD_NAME);
  999. strncpy(oct->boardinfo.serial_number, cs->board_serial_number,
  1000. OCT_SERIAL_LEN);
  1001. octeon_swap_8B_data((u64 *)cs, (sizeof(*cs) >> 3));
  1002. oct->boardinfo.major = cs->board_rev_major;
  1003. oct->boardinfo.minor = cs->board_rev_minor;
  1004. dev_info(&oct->pci_dev->dev,
  1005. "Running %s (%llu Hz)\n",
  1006. app_name, CVM_CAST64(cs->corefreq));
  1007. core_drv_init_err:
  1008. for (i = 0; i < recv_pkt->buffer_count; i++)
  1009. recv_buffer_free(recv_pkt->buffer_ptr[i]);
  1010. octeon_free_recv_info(recv_info);
  1011. return 0;
  1012. }
  1013. int octeon_get_tx_qsize(struct octeon_device *oct, u32 q_no)
  1014. {
  1015. if (oct && (q_no < MAX_OCTEON_INSTR_QUEUES(oct)) &&
  1016. (oct->io_qmask.iq & BIT_ULL(q_no)))
  1017. return oct->instr_queue[q_no]->max_count;
  1018. return -1;
  1019. }
  1020. int octeon_get_rx_qsize(struct octeon_device *oct, u32 q_no)
  1021. {
  1022. if (oct && (q_no < MAX_OCTEON_OUTPUT_QUEUES(oct)) &&
  1023. (oct->io_qmask.oq & BIT_ULL(q_no)))
  1024. return oct->droq[q_no]->max_count;
  1025. return -1;
  1026. }
  1027. /* Retruns the host firmware handshake OCTEON specific configuration */
  1028. struct octeon_config *octeon_get_conf(struct octeon_device *oct)
  1029. {
  1030. struct octeon_config *default_oct_conf = NULL;
  1031. /* check the OCTEON Device model & return the corresponding octeon
  1032. * configuration
  1033. */
  1034. if (OCTEON_CN6XXX(oct)) {
  1035. default_oct_conf =
  1036. (struct octeon_config *)(CHIP_CONF(oct, cn6xxx));
  1037. } else if (OCTEON_CN23XX_PF(oct)) {
  1038. default_oct_conf = (struct octeon_config *)
  1039. (CHIP_CONF(oct, cn23xx_pf));
  1040. } else if (OCTEON_CN23XX_VF(oct)) {
  1041. default_oct_conf = (struct octeon_config *)
  1042. (CHIP_CONF(oct, cn23xx_vf));
  1043. }
  1044. return default_oct_conf;
  1045. }
  1046. /* scratch register address is same in all the OCT-II and CN70XX models */
  1047. #define CNXX_SLI_SCRATCH1 0x3C0
  1048. /** Get the octeon device pointer.
  1049. * @param octeon_id - The id for which the octeon device pointer is required.
  1050. * @return Success: Octeon device pointer.
  1051. * @return Failure: NULL.
  1052. */
  1053. struct octeon_device *lio_get_device(u32 octeon_id)
  1054. {
  1055. if (octeon_id >= MAX_OCTEON_DEVICES)
  1056. return NULL;
  1057. else
  1058. return octeon_device[octeon_id];
  1059. }
  1060. u64 lio_pci_readq(struct octeon_device *oct, u64 addr)
  1061. {
  1062. u64 val64;
  1063. unsigned long flags;
  1064. u32 val32, addrhi;
  1065. spin_lock_irqsave(&oct->pci_win_lock, flags);
  1066. /* The windowed read happens when the LSB of the addr is written.
  1067. * So write MSB first
  1068. */
  1069. addrhi = (addr >> 32);
  1070. if ((oct->chip_id == OCTEON_CN66XX) ||
  1071. (oct->chip_id == OCTEON_CN68XX) ||
  1072. (oct->chip_id == OCTEON_CN23XX_PF_VID))
  1073. addrhi |= 0x00060000;
  1074. writel(addrhi, oct->reg_list.pci_win_rd_addr_hi);
  1075. /* Read back to preserve ordering of writes */
  1076. val32 = readl(oct->reg_list.pci_win_rd_addr_hi);
  1077. writel(addr & 0xffffffff, oct->reg_list.pci_win_rd_addr_lo);
  1078. val32 = readl(oct->reg_list.pci_win_rd_addr_lo);
  1079. val64 = readq(oct->reg_list.pci_win_rd_data);
  1080. spin_unlock_irqrestore(&oct->pci_win_lock, flags);
  1081. return val64;
  1082. }
  1083. void lio_pci_writeq(struct octeon_device *oct,
  1084. u64 val,
  1085. u64 addr)
  1086. {
  1087. u32 val32;
  1088. unsigned long flags;
  1089. spin_lock_irqsave(&oct->pci_win_lock, flags);
  1090. writeq(addr, oct->reg_list.pci_win_wr_addr);
  1091. /* The write happens when the LSB is written. So write MSB first. */
  1092. writel(val >> 32, oct->reg_list.pci_win_wr_data_hi);
  1093. /* Read the MSB to ensure ordering of writes. */
  1094. val32 = readl(oct->reg_list.pci_win_wr_data_hi);
  1095. writel(val & 0xffffffff, oct->reg_list.pci_win_wr_data_lo);
  1096. spin_unlock_irqrestore(&oct->pci_win_lock, flags);
  1097. }
  1098. int octeon_mem_access_ok(struct octeon_device *oct)
  1099. {
  1100. u64 access_okay = 0;
  1101. u64 lmc0_reset_ctl;
  1102. /* Check to make sure a DDR interface is enabled */
  1103. if (OCTEON_CN23XX_PF(oct)) {
  1104. lmc0_reset_ctl = lio_pci_readq(oct, CN23XX_LMC0_RESET_CTL);
  1105. access_okay =
  1106. (lmc0_reset_ctl & CN23XX_LMC0_RESET_CTL_DDR3RST_MASK);
  1107. } else {
  1108. lmc0_reset_ctl = lio_pci_readq(oct, CN6XXX_LMC0_RESET_CTL);
  1109. access_okay =
  1110. (lmc0_reset_ctl & CN6XXX_LMC0_RESET_CTL_DDR3RST_MASK);
  1111. }
  1112. return access_okay ? 0 : 1;
  1113. }
  1114. int octeon_wait_for_ddr_init(struct octeon_device *oct, u32 *timeout)
  1115. {
  1116. int ret = 1;
  1117. u32 ms;
  1118. if (!timeout)
  1119. return ret;
  1120. for (ms = 0; (ret != 0) && ((*timeout == 0) || (ms <= *timeout));
  1121. ms += HZ / 10) {
  1122. ret = octeon_mem_access_ok(oct);
  1123. /* wait 100 ms */
  1124. if (ret)
  1125. schedule_timeout_uninterruptible(HZ / 10);
  1126. }
  1127. return ret;
  1128. }
  1129. /** Get the octeon id assigned to the octeon device passed as argument.
  1130. * This function is exported to other modules.
  1131. * @param dev - octeon device pointer passed as a void *.
  1132. * @return octeon device id
  1133. */
  1134. int lio_get_device_id(void *dev)
  1135. {
  1136. struct octeon_device *octeon_dev = (struct octeon_device *)dev;
  1137. u32 i;
  1138. for (i = 0; i < MAX_OCTEON_DEVICES; i++)
  1139. if (octeon_device[i] == octeon_dev)
  1140. return octeon_dev->octeon_id;
  1141. return -1;
  1142. }
  1143. void lio_enable_irq(struct octeon_droq *droq, struct octeon_instr_queue *iq)
  1144. {
  1145. u64 instr_cnt;
  1146. u32 pkts_pend;
  1147. struct octeon_device *oct = NULL;
  1148. /* the whole thing needs to be atomic, ideally */
  1149. if (droq) {
  1150. pkts_pend = (u32)atomic_read(&droq->pkts_pending);
  1151. spin_lock_bh(&droq->lock);
  1152. writel(droq->pkt_count - pkts_pend, droq->pkts_sent_reg);
  1153. droq->pkt_count = pkts_pend;
  1154. /* this write needs to be flushed before we release the lock */
  1155. mmiowb();
  1156. spin_unlock_bh(&droq->lock);
  1157. oct = droq->oct_dev;
  1158. }
  1159. if (iq) {
  1160. spin_lock_bh(&iq->lock);
  1161. writel(iq->pkt_in_done, iq->inst_cnt_reg);
  1162. iq->pkt_in_done = 0;
  1163. /* this write needs to be flushed before we release the lock */
  1164. mmiowb();
  1165. spin_unlock_bh(&iq->lock);
  1166. oct = iq->oct_dev;
  1167. }
  1168. /*write resend. Writing RESEND in SLI_PKTX_CNTS should be enough
  1169. *to trigger tx interrupts as well, if they are pending.
  1170. */
  1171. if (oct && (OCTEON_CN23XX_PF(oct) || OCTEON_CN23XX_VF(oct))) {
  1172. if (droq)
  1173. writeq(CN23XX_INTR_RESEND, droq->pkts_sent_reg);
  1174. /*we race with firmrware here. read and write the IN_DONE_CNTS*/
  1175. else if (iq) {
  1176. instr_cnt = readq(iq->inst_cnt_reg);
  1177. writeq(((instr_cnt & 0xFFFFFFFF00000000ULL) |
  1178. CN23XX_INTR_RESEND),
  1179. iq->inst_cnt_reg);
  1180. }
  1181. }
  1182. }