octeon_device.c 36 KB

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