octeon_device.c 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476
  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, u32 num_ioqs)
  649. {
  650. struct octeon_ioq_vector *ioq_vector;
  651. int cpu_num;
  652. int size;
  653. int i;
  654. size = sizeof(struct octeon_ioq_vector) * num_ioqs;
  655. oct->ioq_vector = vzalloc(size);
  656. if (!oct->ioq_vector)
  657. return -1;
  658. for (i = 0; i < num_ioqs; i++) {
  659. ioq_vector = &oct->ioq_vector[i];
  660. ioq_vector->oct_dev = oct;
  661. ioq_vector->iq_index = i;
  662. ioq_vector->droq_index = i;
  663. ioq_vector->mbox = oct->mbox[i];
  664. cpu_num = i % num_online_cpus();
  665. cpumask_set_cpu(cpu_num, &ioq_vector->affinity_mask);
  666. if (oct->chip_id == OCTEON_CN23XX_PF_VID)
  667. ioq_vector->ioq_num = i + oct->sriov_info.pf_srn;
  668. else
  669. ioq_vector->ioq_num = i;
  670. }
  671. return 0;
  672. }
  673. void
  674. octeon_free_ioq_vector(struct octeon_device *oct)
  675. {
  676. vfree(oct->ioq_vector);
  677. }
  678. /* this function is only for setting up the first queue */
  679. int octeon_setup_instr_queues(struct octeon_device *oct)
  680. {
  681. u32 num_descs = 0;
  682. u32 iq_no = 0;
  683. union oct_txpciq txpciq;
  684. int numa_node = dev_to_node(&oct->pci_dev->dev);
  685. if (OCTEON_CN6XXX(oct))
  686. num_descs =
  687. CFG_GET_NUM_DEF_TX_DESCS(CHIP_CONF(oct, cn6xxx));
  688. else if (OCTEON_CN23XX_PF(oct))
  689. num_descs = CFG_GET_NUM_DEF_TX_DESCS(CHIP_CONF(oct, cn23xx_pf));
  690. else if (OCTEON_CN23XX_VF(oct))
  691. num_descs = CFG_GET_NUM_DEF_TX_DESCS(CHIP_CONF(oct, cn23xx_vf));
  692. oct->num_iqs = 0;
  693. oct->instr_queue[0] = vzalloc_node(sizeof(*oct->instr_queue[0]),
  694. numa_node);
  695. if (!oct->instr_queue[0])
  696. oct->instr_queue[0] =
  697. vzalloc(sizeof(struct octeon_instr_queue));
  698. if (!oct->instr_queue[0])
  699. return 1;
  700. memset(oct->instr_queue[0], 0, sizeof(struct octeon_instr_queue));
  701. oct->instr_queue[0]->q_index = 0;
  702. oct->instr_queue[0]->app_ctx = (void *)(size_t)0;
  703. oct->instr_queue[0]->ifidx = 0;
  704. txpciq.u64 = 0;
  705. txpciq.s.q_no = iq_no;
  706. txpciq.s.pkind = oct->pfvf_hsword.pkind;
  707. txpciq.s.use_qpg = 0;
  708. txpciq.s.qpg = 0;
  709. if (octeon_init_instr_queue(oct, txpciq, num_descs)) {
  710. /* prevent memory leak */
  711. vfree(oct->instr_queue[0]);
  712. oct->instr_queue[0] = NULL;
  713. return 1;
  714. }
  715. oct->num_iqs++;
  716. return 0;
  717. }
  718. int octeon_setup_output_queues(struct octeon_device *oct)
  719. {
  720. u32 num_descs = 0;
  721. u32 desc_size = 0;
  722. u32 oq_no = 0;
  723. int numa_node = dev_to_node(&oct->pci_dev->dev);
  724. if (OCTEON_CN6XXX(oct)) {
  725. num_descs =
  726. CFG_GET_NUM_DEF_RX_DESCS(CHIP_CONF(oct, cn6xxx));
  727. desc_size =
  728. CFG_GET_DEF_RX_BUF_SIZE(CHIP_CONF(oct, cn6xxx));
  729. } else if (OCTEON_CN23XX_PF(oct)) {
  730. num_descs = CFG_GET_NUM_DEF_RX_DESCS(CHIP_CONF(oct, cn23xx_pf));
  731. desc_size = CFG_GET_DEF_RX_BUF_SIZE(CHIP_CONF(oct, cn23xx_pf));
  732. } else if (OCTEON_CN23XX_VF(oct)) {
  733. num_descs = CFG_GET_NUM_DEF_RX_DESCS(CHIP_CONF(oct, cn23xx_vf));
  734. desc_size = CFG_GET_DEF_RX_BUF_SIZE(CHIP_CONF(oct, cn23xx_vf));
  735. }
  736. oct->num_oqs = 0;
  737. oct->droq[0] = vzalloc_node(sizeof(*oct->droq[0]), numa_node);
  738. if (!oct->droq[0])
  739. oct->droq[0] = vzalloc(sizeof(*oct->droq[0]));
  740. if (!oct->droq[0])
  741. return 1;
  742. if (octeon_init_droq(oct, oq_no, num_descs, desc_size, NULL)) {
  743. vfree(oct->droq[oq_no]);
  744. oct->droq[oq_no] = NULL;
  745. return 1;
  746. }
  747. oct->num_oqs++;
  748. return 0;
  749. }
  750. int octeon_set_io_queues_off(struct octeon_device *oct)
  751. {
  752. int loop = BUSY_READING_REG_VF_LOOP_COUNT;
  753. if (OCTEON_CN6XXX(oct)) {
  754. octeon_write_csr(oct, CN6XXX_SLI_PKT_INSTR_ENB, 0);
  755. octeon_write_csr(oct, CN6XXX_SLI_PKT_OUT_ENB, 0);
  756. } else if (oct->chip_id == OCTEON_CN23XX_VF_VID) {
  757. u32 q_no;
  758. /* IOQs will already be in reset.
  759. * If RST bit is set, wait for quiet bit to be set.
  760. * Once quiet bit is set, clear the RST bit.
  761. */
  762. for (q_no = 0; q_no < oct->sriov_info.rings_per_vf; q_no++) {
  763. u64 reg_val = octeon_read_csr64(
  764. oct, CN23XX_VF_SLI_IQ_PKT_CONTROL64(q_no));
  765. while ((reg_val & CN23XX_PKT_INPUT_CTL_RST) &&
  766. !(reg_val & CN23XX_PKT_INPUT_CTL_QUIET) &&
  767. loop) {
  768. reg_val = octeon_read_csr64(
  769. oct, CN23XX_SLI_IQ_PKT_CONTROL64(q_no));
  770. loop--;
  771. }
  772. if (!loop) {
  773. dev_err(&oct->pci_dev->dev,
  774. "clearing the reset reg failed or setting the quiet reg failed for qno: %u\n",
  775. q_no);
  776. return -1;
  777. }
  778. reg_val = reg_val & ~CN23XX_PKT_INPUT_CTL_RST;
  779. octeon_write_csr64(oct,
  780. CN23XX_SLI_IQ_PKT_CONTROL64(q_no),
  781. reg_val);
  782. reg_val = octeon_read_csr64(
  783. oct, CN23XX_SLI_IQ_PKT_CONTROL64(q_no));
  784. if (reg_val & CN23XX_PKT_INPUT_CTL_RST) {
  785. dev_err(&oct->pci_dev->dev,
  786. "unable to reset qno %u\n", q_no);
  787. return -1;
  788. }
  789. }
  790. }
  791. return 0;
  792. }
  793. void octeon_set_droq_pkt_op(struct octeon_device *oct,
  794. u32 q_no,
  795. u32 enable)
  796. {
  797. u32 reg_val = 0;
  798. /* Disable the i/p and o/p queues for this Octeon. */
  799. if (OCTEON_CN6XXX(oct)) {
  800. reg_val = octeon_read_csr(oct, CN6XXX_SLI_PKT_OUT_ENB);
  801. if (enable)
  802. reg_val = reg_val | (1 << q_no);
  803. else
  804. reg_val = reg_val & (~(1 << q_no));
  805. octeon_write_csr(oct, CN6XXX_SLI_PKT_OUT_ENB, reg_val);
  806. }
  807. }
  808. int octeon_init_dispatch_list(struct octeon_device *oct)
  809. {
  810. u32 i;
  811. oct->dispatch.count = 0;
  812. for (i = 0; i < DISPATCH_LIST_SIZE; i++) {
  813. oct->dispatch.dlist[i].opcode = 0;
  814. INIT_LIST_HEAD(&oct->dispatch.dlist[i].list);
  815. }
  816. for (i = 0; i <= REQTYPE_LAST; i++)
  817. octeon_register_reqtype_free_fn(oct, i, NULL);
  818. spin_lock_init(&oct->dispatch.lock);
  819. return 0;
  820. }
  821. void octeon_delete_dispatch_list(struct octeon_device *oct)
  822. {
  823. u32 i;
  824. struct list_head freelist, *temp, *tmp2;
  825. INIT_LIST_HEAD(&freelist);
  826. spin_lock_bh(&oct->dispatch.lock);
  827. for (i = 0; i < DISPATCH_LIST_SIZE; i++) {
  828. struct list_head *dispatch;
  829. dispatch = &oct->dispatch.dlist[i].list;
  830. while (dispatch->next != dispatch) {
  831. temp = dispatch->next;
  832. list_del(temp);
  833. list_add_tail(temp, &freelist);
  834. }
  835. oct->dispatch.dlist[i].opcode = 0;
  836. }
  837. oct->dispatch.count = 0;
  838. spin_unlock_bh(&oct->dispatch.lock);
  839. list_for_each_safe(temp, tmp2, &freelist) {
  840. list_del(temp);
  841. vfree(temp);
  842. }
  843. }
  844. octeon_dispatch_fn_t
  845. octeon_get_dispatch(struct octeon_device *octeon_dev, u16 opcode,
  846. u16 subcode)
  847. {
  848. u32 idx;
  849. struct list_head *dispatch;
  850. octeon_dispatch_fn_t fn = NULL;
  851. u16 combined_opcode = OPCODE_SUBCODE(opcode, subcode);
  852. idx = combined_opcode & OCTEON_OPCODE_MASK;
  853. spin_lock_bh(&octeon_dev->dispatch.lock);
  854. if (octeon_dev->dispatch.count == 0) {
  855. spin_unlock_bh(&octeon_dev->dispatch.lock);
  856. return NULL;
  857. }
  858. if (!(octeon_dev->dispatch.dlist[idx].opcode)) {
  859. spin_unlock_bh(&octeon_dev->dispatch.lock);
  860. return NULL;
  861. }
  862. if (octeon_dev->dispatch.dlist[idx].opcode == combined_opcode) {
  863. fn = octeon_dev->dispatch.dlist[idx].dispatch_fn;
  864. } else {
  865. list_for_each(dispatch,
  866. &octeon_dev->dispatch.dlist[idx].list) {
  867. if (((struct octeon_dispatch *)dispatch)->opcode ==
  868. combined_opcode) {
  869. fn = ((struct octeon_dispatch *)
  870. dispatch)->dispatch_fn;
  871. break;
  872. }
  873. }
  874. }
  875. spin_unlock_bh(&octeon_dev->dispatch.lock);
  876. return fn;
  877. }
  878. /* octeon_register_dispatch_fn
  879. * Parameters:
  880. * octeon_id - id of the octeon device.
  881. * opcode - opcode for which driver should call the registered function
  882. * subcode - subcode for which driver should call the registered function
  883. * fn - The function to call when a packet with "opcode" arrives in
  884. * octeon output queues.
  885. * fn_arg - The argument to be passed when calling function "fn".
  886. * Description:
  887. * Registers a function and its argument to be called when a packet
  888. * arrives in Octeon output queues with "opcode".
  889. * Returns:
  890. * Success: 0
  891. * Failure: 1
  892. * Locks:
  893. * No locks are held.
  894. */
  895. int
  896. octeon_register_dispatch_fn(struct octeon_device *oct,
  897. u16 opcode,
  898. u16 subcode,
  899. octeon_dispatch_fn_t fn, void *fn_arg)
  900. {
  901. u32 idx;
  902. octeon_dispatch_fn_t pfn;
  903. u16 combined_opcode = OPCODE_SUBCODE(opcode, subcode);
  904. idx = combined_opcode & OCTEON_OPCODE_MASK;
  905. spin_lock_bh(&oct->dispatch.lock);
  906. /* Add dispatch function to first level of lookup table */
  907. if (oct->dispatch.dlist[idx].opcode == 0) {
  908. oct->dispatch.dlist[idx].opcode = combined_opcode;
  909. oct->dispatch.dlist[idx].dispatch_fn = fn;
  910. oct->dispatch.dlist[idx].arg = fn_arg;
  911. oct->dispatch.count++;
  912. spin_unlock_bh(&oct->dispatch.lock);
  913. return 0;
  914. }
  915. spin_unlock_bh(&oct->dispatch.lock);
  916. /* Check if there was a function already registered for this
  917. * opcode/subcode.
  918. */
  919. pfn = octeon_get_dispatch(oct, opcode, subcode);
  920. if (!pfn) {
  921. struct octeon_dispatch *dispatch;
  922. dev_dbg(&oct->pci_dev->dev,
  923. "Adding opcode to dispatch list linked list\n");
  924. dispatch = (struct octeon_dispatch *)
  925. vmalloc(sizeof(struct octeon_dispatch));
  926. if (!dispatch) {
  927. dev_err(&oct->pci_dev->dev,
  928. "No memory to add dispatch function\n");
  929. return 1;
  930. }
  931. dispatch->opcode = combined_opcode;
  932. dispatch->dispatch_fn = fn;
  933. dispatch->arg = fn_arg;
  934. /* Add dispatch function to linked list of fn ptrs
  935. * at the hashed index.
  936. */
  937. spin_lock_bh(&oct->dispatch.lock);
  938. list_add(&dispatch->list, &oct->dispatch.dlist[idx].list);
  939. oct->dispatch.count++;
  940. spin_unlock_bh(&oct->dispatch.lock);
  941. } else {
  942. if (pfn == fn &&
  943. octeon_get_dispatch_arg(oct, opcode, subcode) == fn_arg)
  944. return 0;
  945. dev_err(&oct->pci_dev->dev,
  946. "Found previously registered dispatch fn for opcode/subcode: %x/%x\n",
  947. opcode, subcode);
  948. return 1;
  949. }
  950. return 0;
  951. }
  952. int octeon_core_drv_init(struct octeon_recv_info *recv_info, void *buf)
  953. {
  954. u32 i;
  955. char app_name[16];
  956. struct octeon_device *oct = (struct octeon_device *)buf;
  957. struct octeon_recv_pkt *recv_pkt = recv_info->recv_pkt;
  958. struct octeon_core_setup *cs = NULL;
  959. u32 num_nic_ports = 0;
  960. if (OCTEON_CN6XXX(oct))
  961. num_nic_ports =
  962. CFG_GET_NUM_NIC_PORTS(CHIP_CONF(oct, cn6xxx));
  963. else if (OCTEON_CN23XX_PF(oct))
  964. num_nic_ports =
  965. CFG_GET_NUM_NIC_PORTS(CHIP_CONF(oct, cn23xx_pf));
  966. if (atomic_read(&oct->status) >= OCT_DEV_RUNNING) {
  967. dev_err(&oct->pci_dev->dev, "Received CORE OK when device state is 0x%x\n",
  968. atomic_read(&oct->status));
  969. goto core_drv_init_err;
  970. }
  971. strncpy(app_name,
  972. get_oct_app_string(
  973. (u32)recv_pkt->rh.r_core_drv_init.app_mode),
  974. sizeof(app_name) - 1);
  975. oct->app_mode = (u32)recv_pkt->rh.r_core_drv_init.app_mode;
  976. if (recv_pkt->rh.r_core_drv_init.app_mode == CVM_DRV_NIC_APP) {
  977. oct->fw_info.max_nic_ports =
  978. (u32)recv_pkt->rh.r_core_drv_init.max_nic_ports;
  979. oct->fw_info.num_gmx_ports =
  980. (u32)recv_pkt->rh.r_core_drv_init.num_gmx_ports;
  981. }
  982. if (oct->fw_info.max_nic_ports < num_nic_ports) {
  983. dev_err(&oct->pci_dev->dev,
  984. "Config has more ports than firmware allows (%d > %d).\n",
  985. num_nic_ports, oct->fw_info.max_nic_ports);
  986. goto core_drv_init_err;
  987. }
  988. oct->fw_info.app_cap_flags = recv_pkt->rh.r_core_drv_init.app_cap_flags;
  989. oct->fw_info.app_mode = (u32)recv_pkt->rh.r_core_drv_init.app_mode;
  990. oct->pfvf_hsword.app_mode = (u32)recv_pkt->rh.r_core_drv_init.app_mode;
  991. oct->pfvf_hsword.pkind = recv_pkt->rh.r_core_drv_init.pkind;
  992. for (i = 0; i < oct->num_iqs; i++)
  993. oct->instr_queue[i]->txpciq.s.pkind = oct->pfvf_hsword.pkind;
  994. atomic_set(&oct->status, OCT_DEV_CORE_OK);
  995. cs = &core_setup[oct->octeon_id];
  996. if (recv_pkt->buffer_size[0] != (sizeof(*cs) + OCT_DROQ_INFO_SIZE)) {
  997. dev_dbg(&oct->pci_dev->dev, "Core setup bytes expected %u found %d\n",
  998. (u32)sizeof(*cs),
  999. recv_pkt->buffer_size[0]);
  1000. }
  1001. memcpy(cs, get_rbd(
  1002. recv_pkt->buffer_ptr[0]) + OCT_DROQ_INFO_SIZE, sizeof(*cs));
  1003. strncpy(oct->boardinfo.name, cs->boardname, OCT_BOARD_NAME);
  1004. strncpy(oct->boardinfo.serial_number, cs->board_serial_number,
  1005. OCT_SERIAL_LEN);
  1006. octeon_swap_8B_data((u64 *)cs, (sizeof(*cs) >> 3));
  1007. oct->boardinfo.major = cs->board_rev_major;
  1008. oct->boardinfo.minor = cs->board_rev_minor;
  1009. dev_info(&oct->pci_dev->dev,
  1010. "Running %s (%llu Hz)\n",
  1011. app_name, CVM_CAST64(cs->corefreq));
  1012. core_drv_init_err:
  1013. for (i = 0; i < recv_pkt->buffer_count; i++)
  1014. recv_buffer_free(recv_pkt->buffer_ptr[i]);
  1015. octeon_free_recv_info(recv_info);
  1016. return 0;
  1017. }
  1018. int octeon_get_tx_qsize(struct octeon_device *oct, u32 q_no)
  1019. {
  1020. if (oct && (q_no < MAX_OCTEON_INSTR_QUEUES(oct)) &&
  1021. (oct->io_qmask.iq & BIT_ULL(q_no)))
  1022. return oct->instr_queue[q_no]->max_count;
  1023. return -1;
  1024. }
  1025. int octeon_get_rx_qsize(struct octeon_device *oct, u32 q_no)
  1026. {
  1027. if (oct && (q_no < MAX_OCTEON_OUTPUT_QUEUES(oct)) &&
  1028. (oct->io_qmask.oq & BIT_ULL(q_no)))
  1029. return oct->droq[q_no]->max_count;
  1030. return -1;
  1031. }
  1032. /* Retruns the host firmware handshake OCTEON specific configuration */
  1033. struct octeon_config *octeon_get_conf(struct octeon_device *oct)
  1034. {
  1035. struct octeon_config *default_oct_conf = NULL;
  1036. /* check the OCTEON Device model & return the corresponding octeon
  1037. * configuration
  1038. */
  1039. if (OCTEON_CN6XXX(oct)) {
  1040. default_oct_conf =
  1041. (struct octeon_config *)(CHIP_CONF(oct, cn6xxx));
  1042. } else if (OCTEON_CN23XX_PF(oct)) {
  1043. default_oct_conf = (struct octeon_config *)
  1044. (CHIP_CONF(oct, cn23xx_pf));
  1045. } else if (OCTEON_CN23XX_VF(oct)) {
  1046. default_oct_conf = (struct octeon_config *)
  1047. (CHIP_CONF(oct, cn23xx_vf));
  1048. }
  1049. return default_oct_conf;
  1050. }
  1051. /* scratch register address is same in all the OCT-II and CN70XX models */
  1052. #define CNXX_SLI_SCRATCH1 0x3C0
  1053. /** Get the octeon device pointer.
  1054. * @param octeon_id - The id for which the octeon device pointer is required.
  1055. * @return Success: Octeon device pointer.
  1056. * @return Failure: NULL.
  1057. */
  1058. struct octeon_device *lio_get_device(u32 octeon_id)
  1059. {
  1060. if (octeon_id >= MAX_OCTEON_DEVICES)
  1061. return NULL;
  1062. else
  1063. return octeon_device[octeon_id];
  1064. }
  1065. u64 lio_pci_readq(struct octeon_device *oct, u64 addr)
  1066. {
  1067. u64 val64;
  1068. unsigned long flags;
  1069. u32 val32, addrhi;
  1070. spin_lock_irqsave(&oct->pci_win_lock, flags);
  1071. /* The windowed read happens when the LSB of the addr is written.
  1072. * So write MSB first
  1073. */
  1074. addrhi = (addr >> 32);
  1075. if ((oct->chip_id == OCTEON_CN66XX) ||
  1076. (oct->chip_id == OCTEON_CN68XX) ||
  1077. (oct->chip_id == OCTEON_CN23XX_PF_VID))
  1078. addrhi |= 0x00060000;
  1079. writel(addrhi, oct->reg_list.pci_win_rd_addr_hi);
  1080. /* Read back to preserve ordering of writes */
  1081. val32 = readl(oct->reg_list.pci_win_rd_addr_hi);
  1082. writel(addr & 0xffffffff, oct->reg_list.pci_win_rd_addr_lo);
  1083. val32 = readl(oct->reg_list.pci_win_rd_addr_lo);
  1084. val64 = readq(oct->reg_list.pci_win_rd_data);
  1085. spin_unlock_irqrestore(&oct->pci_win_lock, flags);
  1086. return val64;
  1087. }
  1088. void lio_pci_writeq(struct octeon_device *oct,
  1089. u64 val,
  1090. u64 addr)
  1091. {
  1092. u32 val32;
  1093. unsigned long flags;
  1094. spin_lock_irqsave(&oct->pci_win_lock, flags);
  1095. writeq(addr, oct->reg_list.pci_win_wr_addr);
  1096. /* The write happens when the LSB is written. So write MSB first. */
  1097. writel(val >> 32, oct->reg_list.pci_win_wr_data_hi);
  1098. /* Read the MSB to ensure ordering of writes. */
  1099. val32 = readl(oct->reg_list.pci_win_wr_data_hi);
  1100. writel(val & 0xffffffff, oct->reg_list.pci_win_wr_data_lo);
  1101. spin_unlock_irqrestore(&oct->pci_win_lock, flags);
  1102. }
  1103. int octeon_mem_access_ok(struct octeon_device *oct)
  1104. {
  1105. u64 access_okay = 0;
  1106. u64 lmc0_reset_ctl;
  1107. /* Check to make sure a DDR interface is enabled */
  1108. if (OCTEON_CN23XX_PF(oct)) {
  1109. lmc0_reset_ctl = lio_pci_readq(oct, CN23XX_LMC0_RESET_CTL);
  1110. access_okay =
  1111. (lmc0_reset_ctl & CN23XX_LMC0_RESET_CTL_DDR3RST_MASK);
  1112. } else {
  1113. lmc0_reset_ctl = lio_pci_readq(oct, CN6XXX_LMC0_RESET_CTL);
  1114. access_okay =
  1115. (lmc0_reset_ctl & CN6XXX_LMC0_RESET_CTL_DDR3RST_MASK);
  1116. }
  1117. return access_okay ? 0 : 1;
  1118. }
  1119. int octeon_wait_for_ddr_init(struct octeon_device *oct, u32 *timeout)
  1120. {
  1121. int ret = 1;
  1122. u32 ms;
  1123. if (!timeout)
  1124. return ret;
  1125. for (ms = 0; (ret != 0) && ((*timeout == 0) || (ms <= *timeout));
  1126. ms += HZ / 10) {
  1127. ret = octeon_mem_access_ok(oct);
  1128. /* wait 100 ms */
  1129. if (ret)
  1130. schedule_timeout_uninterruptible(HZ / 10);
  1131. }
  1132. return ret;
  1133. }
  1134. /** Get the octeon id assigned to the octeon device passed as argument.
  1135. * This function is exported to other modules.
  1136. * @param dev - octeon device pointer passed as a void *.
  1137. * @return octeon device id
  1138. */
  1139. int lio_get_device_id(void *dev)
  1140. {
  1141. struct octeon_device *octeon_dev = (struct octeon_device *)dev;
  1142. u32 i;
  1143. for (i = 0; i < MAX_OCTEON_DEVICES; i++)
  1144. if (octeon_device[i] == octeon_dev)
  1145. return octeon_dev->octeon_id;
  1146. return -1;
  1147. }
  1148. void lio_enable_irq(struct octeon_droq *droq, struct octeon_instr_queue *iq)
  1149. {
  1150. u64 instr_cnt;
  1151. u32 pkts_pend;
  1152. struct octeon_device *oct = NULL;
  1153. /* the whole thing needs to be atomic, ideally */
  1154. if (droq) {
  1155. pkts_pend = (u32)atomic_read(&droq->pkts_pending);
  1156. spin_lock_bh(&droq->lock);
  1157. writel(droq->pkt_count - pkts_pend, droq->pkts_sent_reg);
  1158. droq->pkt_count = pkts_pend;
  1159. /* this write needs to be flushed before we release the lock */
  1160. mmiowb();
  1161. spin_unlock_bh(&droq->lock);
  1162. oct = droq->oct_dev;
  1163. }
  1164. if (iq) {
  1165. spin_lock_bh(&iq->lock);
  1166. writel(iq->pkts_processed, iq->inst_cnt_reg);
  1167. iq->pkt_in_done -= iq->pkts_processed;
  1168. iq->pkts_processed = 0;
  1169. /* this write needs to be flushed before we release the lock */
  1170. mmiowb();
  1171. spin_unlock_bh(&iq->lock);
  1172. oct = iq->oct_dev;
  1173. }
  1174. /*write resend. Writing RESEND in SLI_PKTX_CNTS should be enough
  1175. *to trigger tx interrupts as well, if they are pending.
  1176. */
  1177. if (oct && (OCTEON_CN23XX_PF(oct) || OCTEON_CN23XX_VF(oct))) {
  1178. if (droq)
  1179. writeq(CN23XX_INTR_RESEND, droq->pkts_sent_reg);
  1180. /*we race with firmrware here. read and write the IN_DONE_CNTS*/
  1181. else if (iq) {
  1182. instr_cnt = readq(iq->inst_cnt_reg);
  1183. writeq(((instr_cnt & 0xFFFFFFFF00000000ULL) |
  1184. CN23XX_INTR_RESEND),
  1185. iq->inst_cnt_reg);
  1186. }
  1187. }
  1188. }