cptpf_main.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. /*
  2. * Copyright (C) 2016 Cavium, Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of version 2 of the GNU General Public License
  6. * as published by the Free Software Foundation.
  7. */
  8. #include <linux/device.h>
  9. #include <linux/firmware.h>
  10. #include <linux/interrupt.h>
  11. #include <linux/module.h>
  12. #include <linux/moduleparam.h>
  13. #include <linux/pci.h>
  14. #include <linux/printk.h>
  15. #include <linux/version.h>
  16. #include "cptpf.h"
  17. #define DRV_NAME "thunder-cpt"
  18. #define DRV_VERSION "1.0"
  19. static u32 num_vfs = 4; /* Default 4 VF enabled */
  20. module_param(num_vfs, uint, 0444);
  21. MODULE_PARM_DESC(num_vfs, "Number of VFs to enable(1-16)");
  22. /*
  23. * Disable cores specified by coremask
  24. */
  25. static void cpt_disable_cores(struct cpt_device *cpt, u64 coremask,
  26. u8 type, u8 grp)
  27. {
  28. u64 pf_exe_ctl;
  29. u32 timeout = 100;
  30. u64 grpmask = 0;
  31. struct device *dev = &cpt->pdev->dev;
  32. if (type == AE_TYPES)
  33. coremask = (coremask << cpt->max_se_cores);
  34. /* Disengage the cores from groups */
  35. grpmask = cpt_read_csr64(cpt->reg_base, CPTX_PF_GX_EN(0, grp));
  36. cpt_write_csr64(cpt->reg_base, CPTX_PF_GX_EN(0, grp),
  37. (grpmask & ~coremask));
  38. udelay(CSR_DELAY);
  39. grp = cpt_read_csr64(cpt->reg_base, CPTX_PF_EXEC_BUSY(0));
  40. while (grp & coremask) {
  41. dev_err(dev, "Cores still busy %llx", coremask);
  42. grp = cpt_read_csr64(cpt->reg_base,
  43. CPTX_PF_EXEC_BUSY(0));
  44. if (timeout--)
  45. break;
  46. udelay(CSR_DELAY);
  47. }
  48. /* Disable the cores */
  49. pf_exe_ctl = cpt_read_csr64(cpt->reg_base, CPTX_PF_EXE_CTL(0));
  50. cpt_write_csr64(cpt->reg_base, CPTX_PF_EXE_CTL(0),
  51. (pf_exe_ctl & ~coremask));
  52. udelay(CSR_DELAY);
  53. }
  54. /*
  55. * Enable cores specified by coremask
  56. */
  57. static void cpt_enable_cores(struct cpt_device *cpt, u64 coremask,
  58. u8 type)
  59. {
  60. u64 pf_exe_ctl;
  61. if (type == AE_TYPES)
  62. coremask = (coremask << cpt->max_se_cores);
  63. pf_exe_ctl = cpt_read_csr64(cpt->reg_base, CPTX_PF_EXE_CTL(0));
  64. cpt_write_csr64(cpt->reg_base, CPTX_PF_EXE_CTL(0),
  65. (pf_exe_ctl | coremask));
  66. udelay(CSR_DELAY);
  67. }
  68. static void cpt_configure_group(struct cpt_device *cpt, u8 grp,
  69. u64 coremask, u8 type)
  70. {
  71. u64 pf_gx_en = 0;
  72. if (type == AE_TYPES)
  73. coremask = (coremask << cpt->max_se_cores);
  74. pf_gx_en = cpt_read_csr64(cpt->reg_base, CPTX_PF_GX_EN(0, grp));
  75. cpt_write_csr64(cpt->reg_base, CPTX_PF_GX_EN(0, grp),
  76. (pf_gx_en | coremask));
  77. udelay(CSR_DELAY);
  78. }
  79. static void cpt_disable_mbox_interrupts(struct cpt_device *cpt)
  80. {
  81. /* Clear mbox(0) interupts for all vfs */
  82. cpt_write_csr64(cpt->reg_base, CPTX_PF_MBOX_ENA_W1CX(0, 0), ~0ull);
  83. }
  84. static void cpt_disable_ecc_interrupts(struct cpt_device *cpt)
  85. {
  86. /* Clear ecc(0) interupts for all vfs */
  87. cpt_write_csr64(cpt->reg_base, CPTX_PF_ECC0_ENA_W1C(0), ~0ull);
  88. }
  89. static void cpt_disable_exec_interrupts(struct cpt_device *cpt)
  90. {
  91. /* Clear exec interupts for all vfs */
  92. cpt_write_csr64(cpt->reg_base, CPTX_PF_EXEC_ENA_W1C(0), ~0ull);
  93. }
  94. static void cpt_disable_all_interrupts(struct cpt_device *cpt)
  95. {
  96. cpt_disable_mbox_interrupts(cpt);
  97. cpt_disable_ecc_interrupts(cpt);
  98. cpt_disable_exec_interrupts(cpt);
  99. }
  100. static void cpt_enable_mbox_interrupts(struct cpt_device *cpt)
  101. {
  102. /* Set mbox(0) interupts for all vfs */
  103. cpt_write_csr64(cpt->reg_base, CPTX_PF_MBOX_ENA_W1SX(0, 0), ~0ull);
  104. }
  105. static int cpt_load_microcode(struct cpt_device *cpt, struct microcode *mcode)
  106. {
  107. int ret = 0, core = 0, shift = 0;
  108. u32 total_cores = 0;
  109. struct device *dev = &cpt->pdev->dev;
  110. if (!mcode || !mcode->code) {
  111. dev_err(dev, "Either the mcode is null or data is NULL\n");
  112. return -EINVAL;
  113. }
  114. if (mcode->code_size == 0) {
  115. dev_err(dev, "microcode size is 0\n");
  116. return -EINVAL;
  117. }
  118. /* Assumes 0-9 are SE cores for UCODE_BASE registers and
  119. * AE core bases follow
  120. */
  121. if (mcode->is_ae) {
  122. core = CPT_MAX_SE_CORES; /* start couting from 10 */
  123. total_cores = CPT_MAX_TOTAL_CORES; /* upto 15 */
  124. } else {
  125. core = 0; /* start couting from 0 */
  126. total_cores = CPT_MAX_SE_CORES; /* upto 9 */
  127. }
  128. /* Point to microcode for each core of the group */
  129. for (; core < total_cores ; core++, shift++) {
  130. if (mcode->core_mask & (1 << shift)) {
  131. cpt_write_csr64(cpt->reg_base,
  132. CPTX_PF_ENGX_UCODE_BASE(0, core),
  133. (u64)mcode->phys_base);
  134. }
  135. }
  136. return ret;
  137. }
  138. static int do_cpt_init(struct cpt_device *cpt, struct microcode *mcode)
  139. {
  140. int ret = 0;
  141. struct device *dev = &cpt->pdev->dev;
  142. /* Make device not ready */
  143. cpt->flags &= ~CPT_FLAG_DEVICE_READY;
  144. /* Disable All PF interrupts */
  145. cpt_disable_all_interrupts(cpt);
  146. /* Calculate mcode group and coremasks */
  147. if (mcode->is_ae) {
  148. if (mcode->num_cores > cpt->max_ae_cores) {
  149. dev_err(dev, "Requested for more cores than available AE cores\n");
  150. ret = -EINVAL;
  151. goto cpt_init_fail;
  152. }
  153. if (cpt->next_group >= CPT_MAX_CORE_GROUPS) {
  154. dev_err(dev, "Can't load, all eight microcode groups in use");
  155. return -ENFILE;
  156. }
  157. mcode->group = cpt->next_group;
  158. /* Convert requested cores to mask */
  159. mcode->core_mask = GENMASK(mcode->num_cores, 0);
  160. cpt_disable_cores(cpt, mcode->core_mask, AE_TYPES,
  161. mcode->group);
  162. /* Load microcode for AE engines */
  163. ret = cpt_load_microcode(cpt, mcode);
  164. if (ret) {
  165. dev_err(dev, "Microcode load Failed for %s\n",
  166. mcode->version);
  167. goto cpt_init_fail;
  168. }
  169. cpt->next_group++;
  170. /* Configure group mask for the mcode */
  171. cpt_configure_group(cpt, mcode->group, mcode->core_mask,
  172. AE_TYPES);
  173. /* Enable AE cores for the group mask */
  174. cpt_enable_cores(cpt, mcode->core_mask, AE_TYPES);
  175. } else {
  176. if (mcode->num_cores > cpt->max_se_cores) {
  177. dev_err(dev, "Requested for more cores than available SE cores\n");
  178. ret = -EINVAL;
  179. goto cpt_init_fail;
  180. }
  181. if (cpt->next_group >= CPT_MAX_CORE_GROUPS) {
  182. dev_err(dev, "Can't load, all eight microcode groups in use");
  183. return -ENFILE;
  184. }
  185. mcode->group = cpt->next_group;
  186. /* Covert requested cores to mask */
  187. mcode->core_mask = GENMASK(mcode->num_cores, 0);
  188. cpt_disable_cores(cpt, mcode->core_mask, SE_TYPES,
  189. mcode->group);
  190. /* Load microcode for SE engines */
  191. ret = cpt_load_microcode(cpt, mcode);
  192. if (ret) {
  193. dev_err(dev, "Microcode load Failed for %s\n",
  194. mcode->version);
  195. goto cpt_init_fail;
  196. }
  197. cpt->next_group++;
  198. /* Configure group mask for the mcode */
  199. cpt_configure_group(cpt, mcode->group, mcode->core_mask,
  200. SE_TYPES);
  201. /* Enable SE cores for the group mask */
  202. cpt_enable_cores(cpt, mcode->core_mask, SE_TYPES);
  203. }
  204. /* Enabled PF mailbox interrupts */
  205. cpt_enable_mbox_interrupts(cpt);
  206. cpt->flags |= CPT_FLAG_DEVICE_READY;
  207. return ret;
  208. cpt_init_fail:
  209. /* Enabled PF mailbox interrupts */
  210. cpt_enable_mbox_interrupts(cpt);
  211. return ret;
  212. }
  213. struct ucode_header {
  214. u8 version[CPT_UCODE_VERSION_SZ];
  215. u32 code_length;
  216. u32 data_length;
  217. u64 sram_address;
  218. };
  219. static int cpt_ucode_load_fw(struct cpt_device *cpt, const u8 *fw, bool is_ae)
  220. {
  221. const struct firmware *fw_entry;
  222. struct device *dev = &cpt->pdev->dev;
  223. struct ucode_header *ucode;
  224. struct microcode *mcode;
  225. int j, ret = 0;
  226. ret = request_firmware(&fw_entry, fw, dev);
  227. if (ret)
  228. return ret;
  229. ucode = (struct ucode_header *)fw_entry->data;
  230. mcode = &cpt->mcode[cpt->next_mc_idx];
  231. memcpy(mcode->version, (u8 *)fw_entry->data, CPT_UCODE_VERSION_SZ);
  232. mcode->code_size = ntohl(ucode->code_length) * 2;
  233. if (!mcode->code_size)
  234. return -EINVAL;
  235. mcode->is_ae = is_ae;
  236. mcode->core_mask = 0ULL;
  237. mcode->num_cores = is_ae ? 6 : 10;
  238. /* Allocate DMAable space */
  239. mcode->code = dma_zalloc_coherent(&cpt->pdev->dev, mcode->code_size,
  240. &mcode->phys_base, GFP_KERNEL);
  241. if (!mcode->code) {
  242. dev_err(dev, "Unable to allocate space for microcode");
  243. return -ENOMEM;
  244. }
  245. memcpy((void *)mcode->code, (void *)(fw_entry->data + sizeof(*ucode)),
  246. mcode->code_size);
  247. /* Byte swap 64-bit */
  248. for (j = 0; j < (mcode->code_size / 8); j++)
  249. ((u64 *)mcode->code)[j] = cpu_to_be64(((u64 *)mcode->code)[j]);
  250. /* MC needs 16-bit swap */
  251. for (j = 0; j < (mcode->code_size / 2); j++)
  252. ((u16 *)mcode->code)[j] = cpu_to_be16(((u16 *)mcode->code)[j]);
  253. dev_dbg(dev, "mcode->code_size = %u\n", mcode->code_size);
  254. dev_dbg(dev, "mcode->is_ae = %u\n", mcode->is_ae);
  255. dev_dbg(dev, "mcode->num_cores = %u\n", mcode->num_cores);
  256. dev_dbg(dev, "mcode->code = %llx\n", (u64)mcode->code);
  257. dev_dbg(dev, "mcode->phys_base = %llx\n", mcode->phys_base);
  258. ret = do_cpt_init(cpt, mcode);
  259. if (ret) {
  260. dev_err(dev, "do_cpt_init failed with ret: %d\n", ret);
  261. return ret;
  262. }
  263. dev_info(dev, "Microcode Loaded %s\n", mcode->version);
  264. mcode->is_mc_valid = 1;
  265. cpt->next_mc_idx++;
  266. release_firmware(fw_entry);
  267. return ret;
  268. }
  269. static int cpt_ucode_load(struct cpt_device *cpt)
  270. {
  271. int ret = 0;
  272. struct device *dev = &cpt->pdev->dev;
  273. ret = cpt_ucode_load_fw(cpt, "cpt8x-mc-ae.out", true);
  274. if (ret) {
  275. dev_err(dev, "ae:cpt_ucode_load failed with ret: %d\n", ret);
  276. return ret;
  277. }
  278. ret = cpt_ucode_load_fw(cpt, "cpt8x-mc-se.out", false);
  279. if (ret) {
  280. dev_err(dev, "se:cpt_ucode_load failed with ret: %d\n", ret);
  281. return ret;
  282. }
  283. return ret;
  284. }
  285. static irqreturn_t cpt_mbx0_intr_handler(int irq, void *cpt_irq)
  286. {
  287. struct cpt_device *cpt = (struct cpt_device *)cpt_irq;
  288. cpt_mbox_intr_handler(cpt, 0);
  289. return IRQ_HANDLED;
  290. }
  291. static void cpt_reset(struct cpt_device *cpt)
  292. {
  293. cpt_write_csr64(cpt->reg_base, CPTX_PF_RESET(0), 1);
  294. }
  295. static void cpt_find_max_enabled_cores(struct cpt_device *cpt)
  296. {
  297. union cptx_pf_constants pf_cnsts = {0};
  298. pf_cnsts.u = cpt_read_csr64(cpt->reg_base, CPTX_PF_CONSTANTS(0));
  299. cpt->max_se_cores = pf_cnsts.s.se;
  300. cpt->max_ae_cores = pf_cnsts.s.ae;
  301. }
  302. static u32 cpt_check_bist_status(struct cpt_device *cpt)
  303. {
  304. union cptx_pf_bist_status bist_sts = {0};
  305. bist_sts.u = cpt_read_csr64(cpt->reg_base,
  306. CPTX_PF_BIST_STATUS(0));
  307. return bist_sts.u;
  308. }
  309. static u64 cpt_check_exe_bist_status(struct cpt_device *cpt)
  310. {
  311. union cptx_pf_exe_bist_status bist_sts = {0};
  312. bist_sts.u = cpt_read_csr64(cpt->reg_base,
  313. CPTX_PF_EXE_BIST_STATUS(0));
  314. return bist_sts.u;
  315. }
  316. static void cpt_disable_all_cores(struct cpt_device *cpt)
  317. {
  318. u32 grp, timeout = 100;
  319. struct device *dev = &cpt->pdev->dev;
  320. /* Disengage the cores from groups */
  321. for (grp = 0; grp < CPT_MAX_CORE_GROUPS; grp++) {
  322. cpt_write_csr64(cpt->reg_base, CPTX_PF_GX_EN(0, grp), 0);
  323. udelay(CSR_DELAY);
  324. }
  325. grp = cpt_read_csr64(cpt->reg_base, CPTX_PF_EXEC_BUSY(0));
  326. while (grp) {
  327. dev_err(dev, "Cores still busy");
  328. grp = cpt_read_csr64(cpt->reg_base,
  329. CPTX_PF_EXEC_BUSY(0));
  330. if (timeout--)
  331. break;
  332. udelay(CSR_DELAY);
  333. }
  334. /* Disable the cores */
  335. cpt_write_csr64(cpt->reg_base, CPTX_PF_EXE_CTL(0), 0);
  336. }
  337. /**
  338. * Ensure all cores are disengaged from all groups by
  339. * calling cpt_disable_all_cores() before calling this
  340. * function.
  341. */
  342. static void cpt_unload_microcode(struct cpt_device *cpt)
  343. {
  344. u32 grp = 0, core;
  345. /* Free microcode bases and reset group masks */
  346. for (grp = 0; grp < CPT_MAX_CORE_GROUPS; grp++) {
  347. struct microcode *mcode = &cpt->mcode[grp];
  348. if (cpt->mcode[grp].code)
  349. dma_free_coherent(&cpt->pdev->dev, mcode->code_size,
  350. mcode->code, mcode->phys_base);
  351. mcode->code = NULL;
  352. }
  353. /* Clear UCODE_BASE registers for all engines */
  354. for (core = 0; core < CPT_MAX_TOTAL_CORES; core++)
  355. cpt_write_csr64(cpt->reg_base,
  356. CPTX_PF_ENGX_UCODE_BASE(0, core), 0ull);
  357. }
  358. static int cpt_device_init(struct cpt_device *cpt)
  359. {
  360. u64 bist;
  361. struct device *dev = &cpt->pdev->dev;
  362. /* Reset the PF when probed first */
  363. cpt_reset(cpt);
  364. mdelay(100);
  365. /*Check BIST status*/
  366. bist = (u64)cpt_check_bist_status(cpt);
  367. if (bist) {
  368. dev_err(dev, "RAM BIST failed with code 0x%llx", bist);
  369. return -ENODEV;
  370. }
  371. bist = cpt_check_exe_bist_status(cpt);
  372. if (bist) {
  373. dev_err(dev, "Engine BIST failed with code 0x%llx", bist);
  374. return -ENODEV;
  375. }
  376. /*Get CLK frequency*/
  377. /*Get max enabled cores */
  378. cpt_find_max_enabled_cores(cpt);
  379. /*Disable all cores*/
  380. cpt_disable_all_cores(cpt);
  381. /*Reset device parameters*/
  382. cpt->next_mc_idx = 0;
  383. cpt->next_group = 0;
  384. /* PF is ready */
  385. cpt->flags |= CPT_FLAG_DEVICE_READY;
  386. return 0;
  387. }
  388. static int cpt_register_interrupts(struct cpt_device *cpt)
  389. {
  390. int ret;
  391. struct device *dev = &cpt->pdev->dev;
  392. /* Enable MSI-X */
  393. ret = pci_alloc_irq_vectors(cpt->pdev, CPT_PF_MSIX_VECTORS,
  394. CPT_PF_MSIX_VECTORS, PCI_IRQ_MSIX);
  395. if (ret < 0) {
  396. dev_err(&cpt->pdev->dev, "Request for #%d msix vectors failed\n",
  397. CPT_PF_MSIX_VECTORS);
  398. return ret;
  399. }
  400. /* Register mailbox interrupt handlers */
  401. ret = request_irq(pci_irq_vector(cpt->pdev, CPT_PF_INT_VEC_E_MBOXX(0)),
  402. cpt_mbx0_intr_handler, 0, "CPT Mbox0", cpt);
  403. if (ret)
  404. goto fail;
  405. /* Enable mailbox interrupt */
  406. cpt_enable_mbox_interrupts(cpt);
  407. return 0;
  408. fail:
  409. dev_err(dev, "Request irq failed\n");
  410. pci_disable_msix(cpt->pdev);
  411. return ret;
  412. }
  413. static void cpt_unregister_interrupts(struct cpt_device *cpt)
  414. {
  415. free_irq(pci_irq_vector(cpt->pdev, CPT_PF_INT_VEC_E_MBOXX(0)), cpt);
  416. pci_disable_msix(cpt->pdev);
  417. }
  418. static int cpt_sriov_init(struct cpt_device *cpt, int num_vfs)
  419. {
  420. int pos = 0;
  421. int err;
  422. u16 total_vf_cnt;
  423. struct pci_dev *pdev = cpt->pdev;
  424. pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
  425. if (!pos) {
  426. dev_err(&pdev->dev, "SRIOV capability is not found in PCIe config space\n");
  427. return -ENODEV;
  428. }
  429. cpt->num_vf_en = num_vfs; /* User requested VFs */
  430. pci_read_config_word(pdev, (pos + PCI_SRIOV_TOTAL_VF), &total_vf_cnt);
  431. if (total_vf_cnt < cpt->num_vf_en)
  432. cpt->num_vf_en = total_vf_cnt;
  433. if (!total_vf_cnt)
  434. return 0;
  435. /*Enabled the available VFs */
  436. err = pci_enable_sriov(pdev, cpt->num_vf_en);
  437. if (err) {
  438. dev_err(&pdev->dev, "SRIOV enable failed, num VF is %d\n",
  439. cpt->num_vf_en);
  440. cpt->num_vf_en = 0;
  441. return err;
  442. }
  443. /* TODO: Optionally enable static VQ priorities feature */
  444. dev_info(&pdev->dev, "SRIOV enabled, number of VF available %d\n",
  445. cpt->num_vf_en);
  446. cpt->flags |= CPT_FLAG_SRIOV_ENABLED;
  447. return 0;
  448. }
  449. static int cpt_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  450. {
  451. struct device *dev = &pdev->dev;
  452. struct cpt_device *cpt;
  453. int err;
  454. if (num_vfs > 16 || num_vfs < 4) {
  455. dev_warn(dev, "Invalid vf count %d, Resetting it to 4(default)\n",
  456. num_vfs);
  457. num_vfs = 4;
  458. }
  459. cpt = devm_kzalloc(dev, sizeof(*cpt), GFP_KERNEL);
  460. if (!cpt)
  461. return -ENOMEM;
  462. pci_set_drvdata(pdev, cpt);
  463. cpt->pdev = pdev;
  464. err = pci_enable_device(pdev);
  465. if (err) {
  466. dev_err(dev, "Failed to enable PCI device\n");
  467. pci_set_drvdata(pdev, NULL);
  468. return err;
  469. }
  470. err = pci_request_regions(pdev, DRV_NAME);
  471. if (err) {
  472. dev_err(dev, "PCI request regions failed 0x%x\n", err);
  473. goto cpt_err_disable_device;
  474. }
  475. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(48));
  476. if (err) {
  477. dev_err(dev, "Unable to get usable DMA configuration\n");
  478. goto cpt_err_release_regions;
  479. }
  480. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(48));
  481. if (err) {
  482. dev_err(dev, "Unable to get 48-bit DMA for consistent allocations\n");
  483. goto cpt_err_release_regions;
  484. }
  485. /* MAP PF's configuration registers */
  486. cpt->reg_base = pcim_iomap(pdev, 0, 0);
  487. if (!cpt->reg_base) {
  488. dev_err(dev, "Cannot map config register space, aborting\n");
  489. err = -ENOMEM;
  490. goto cpt_err_release_regions;
  491. }
  492. /* CPT device HW initialization */
  493. cpt_device_init(cpt);
  494. /* Register interrupts */
  495. err = cpt_register_interrupts(cpt);
  496. if (err)
  497. goto cpt_err_release_regions;
  498. err = cpt_ucode_load(cpt);
  499. if (err)
  500. goto cpt_err_unregister_interrupts;
  501. /* Configure SRIOV */
  502. err = cpt_sriov_init(cpt, num_vfs);
  503. if (err)
  504. goto cpt_err_unregister_interrupts;
  505. return 0;
  506. cpt_err_unregister_interrupts:
  507. cpt_unregister_interrupts(cpt);
  508. cpt_err_release_regions:
  509. pci_release_regions(pdev);
  510. cpt_err_disable_device:
  511. pci_disable_device(pdev);
  512. pci_set_drvdata(pdev, NULL);
  513. return err;
  514. }
  515. static void cpt_remove(struct pci_dev *pdev)
  516. {
  517. struct cpt_device *cpt = pci_get_drvdata(pdev);
  518. /* Disengage SE and AE cores from all groups*/
  519. cpt_disable_all_cores(cpt);
  520. /* Unload microcodes */
  521. cpt_unload_microcode(cpt);
  522. cpt_unregister_interrupts(cpt);
  523. pci_disable_sriov(pdev);
  524. pci_release_regions(pdev);
  525. pci_disable_device(pdev);
  526. pci_set_drvdata(pdev, NULL);
  527. }
  528. static void cpt_shutdown(struct pci_dev *pdev)
  529. {
  530. struct cpt_device *cpt = pci_get_drvdata(pdev);
  531. if (!cpt)
  532. return;
  533. dev_info(&pdev->dev, "Shutdown device %x:%x.\n",
  534. (u32)pdev->vendor, (u32)pdev->device);
  535. cpt_unregister_interrupts(cpt);
  536. pci_release_regions(pdev);
  537. pci_disable_device(pdev);
  538. pci_set_drvdata(pdev, NULL);
  539. }
  540. /* Supported devices */
  541. static const struct pci_device_id cpt_id_table[] = {
  542. { PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, CPT_81XX_PCI_PF_DEVICE_ID) },
  543. { 0, } /* end of table */
  544. };
  545. static struct pci_driver cpt_pci_driver = {
  546. .name = DRV_NAME,
  547. .id_table = cpt_id_table,
  548. .probe = cpt_probe,
  549. .remove = cpt_remove,
  550. .shutdown = cpt_shutdown,
  551. };
  552. module_pci_driver(cpt_pci_driver);
  553. MODULE_AUTHOR("George Cherian <george.cherian@cavium.com>");
  554. MODULE_DESCRIPTION("Cavium Thunder CPT Physical Function Driver");
  555. MODULE_LICENSE("GPL v2");
  556. MODULE_VERSION(DRV_VERSION);
  557. MODULE_DEVICE_TABLE(pci, cpt_id_table);