cptpf_main.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  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. ret = -EINVAL;
  235. goto fw_release;
  236. }
  237. mcode->is_ae = is_ae;
  238. mcode->core_mask = 0ULL;
  239. mcode->num_cores = is_ae ? 6 : 10;
  240. /* Allocate DMAable space */
  241. mcode->code = dma_zalloc_coherent(&cpt->pdev->dev, mcode->code_size,
  242. &mcode->phys_base, GFP_KERNEL);
  243. if (!mcode->code) {
  244. dev_err(dev, "Unable to allocate space for microcode");
  245. ret = -ENOMEM;
  246. goto fw_release;
  247. }
  248. memcpy((void *)mcode->code, (void *)(fw_entry->data + sizeof(*ucode)),
  249. mcode->code_size);
  250. /* Byte swap 64-bit */
  251. for (j = 0; j < (mcode->code_size / 8); j++)
  252. ((u64 *)mcode->code)[j] = cpu_to_be64(((u64 *)mcode->code)[j]);
  253. /* MC needs 16-bit swap */
  254. for (j = 0; j < (mcode->code_size / 2); j++)
  255. ((u16 *)mcode->code)[j] = cpu_to_be16(((u16 *)mcode->code)[j]);
  256. dev_dbg(dev, "mcode->code_size = %u\n", mcode->code_size);
  257. dev_dbg(dev, "mcode->is_ae = %u\n", mcode->is_ae);
  258. dev_dbg(dev, "mcode->num_cores = %u\n", mcode->num_cores);
  259. dev_dbg(dev, "mcode->code = %llx\n", (u64)mcode->code);
  260. dev_dbg(dev, "mcode->phys_base = %llx\n", mcode->phys_base);
  261. ret = do_cpt_init(cpt, mcode);
  262. if (ret) {
  263. dev_err(dev, "do_cpt_init failed with ret: %d\n", ret);
  264. goto fw_release;
  265. }
  266. dev_info(dev, "Microcode Loaded %s\n", mcode->version);
  267. mcode->is_mc_valid = 1;
  268. cpt->next_mc_idx++;
  269. fw_release:
  270. release_firmware(fw_entry);
  271. return ret;
  272. }
  273. static int cpt_ucode_load(struct cpt_device *cpt)
  274. {
  275. int ret = 0;
  276. struct device *dev = &cpt->pdev->dev;
  277. ret = cpt_ucode_load_fw(cpt, "cpt8x-mc-ae.out", true);
  278. if (ret) {
  279. dev_err(dev, "ae:cpt_ucode_load failed with ret: %d\n", ret);
  280. return ret;
  281. }
  282. ret = cpt_ucode_load_fw(cpt, "cpt8x-mc-se.out", false);
  283. if (ret) {
  284. dev_err(dev, "se:cpt_ucode_load failed with ret: %d\n", ret);
  285. return ret;
  286. }
  287. return ret;
  288. }
  289. static irqreturn_t cpt_mbx0_intr_handler(int irq, void *cpt_irq)
  290. {
  291. struct cpt_device *cpt = (struct cpt_device *)cpt_irq;
  292. cpt_mbox_intr_handler(cpt, 0);
  293. return IRQ_HANDLED;
  294. }
  295. static void cpt_reset(struct cpt_device *cpt)
  296. {
  297. cpt_write_csr64(cpt->reg_base, CPTX_PF_RESET(0), 1);
  298. }
  299. static void cpt_find_max_enabled_cores(struct cpt_device *cpt)
  300. {
  301. union cptx_pf_constants pf_cnsts = {0};
  302. pf_cnsts.u = cpt_read_csr64(cpt->reg_base, CPTX_PF_CONSTANTS(0));
  303. cpt->max_se_cores = pf_cnsts.s.se;
  304. cpt->max_ae_cores = pf_cnsts.s.ae;
  305. }
  306. static u32 cpt_check_bist_status(struct cpt_device *cpt)
  307. {
  308. union cptx_pf_bist_status bist_sts = {0};
  309. bist_sts.u = cpt_read_csr64(cpt->reg_base,
  310. CPTX_PF_BIST_STATUS(0));
  311. return bist_sts.u;
  312. }
  313. static u64 cpt_check_exe_bist_status(struct cpt_device *cpt)
  314. {
  315. union cptx_pf_exe_bist_status bist_sts = {0};
  316. bist_sts.u = cpt_read_csr64(cpt->reg_base,
  317. CPTX_PF_EXE_BIST_STATUS(0));
  318. return bist_sts.u;
  319. }
  320. static void cpt_disable_all_cores(struct cpt_device *cpt)
  321. {
  322. u32 grp, timeout = 100;
  323. struct device *dev = &cpt->pdev->dev;
  324. /* Disengage the cores from groups */
  325. for (grp = 0; grp < CPT_MAX_CORE_GROUPS; grp++) {
  326. cpt_write_csr64(cpt->reg_base, CPTX_PF_GX_EN(0, grp), 0);
  327. udelay(CSR_DELAY);
  328. }
  329. grp = cpt_read_csr64(cpt->reg_base, CPTX_PF_EXEC_BUSY(0));
  330. while (grp) {
  331. dev_err(dev, "Cores still busy");
  332. grp = cpt_read_csr64(cpt->reg_base,
  333. CPTX_PF_EXEC_BUSY(0));
  334. if (timeout--)
  335. break;
  336. udelay(CSR_DELAY);
  337. }
  338. /* Disable the cores */
  339. cpt_write_csr64(cpt->reg_base, CPTX_PF_EXE_CTL(0), 0);
  340. }
  341. /**
  342. * Ensure all cores are disengaged from all groups by
  343. * calling cpt_disable_all_cores() before calling this
  344. * function.
  345. */
  346. static void cpt_unload_microcode(struct cpt_device *cpt)
  347. {
  348. u32 grp = 0, core;
  349. /* Free microcode bases and reset group masks */
  350. for (grp = 0; grp < CPT_MAX_CORE_GROUPS; grp++) {
  351. struct microcode *mcode = &cpt->mcode[grp];
  352. if (cpt->mcode[grp].code)
  353. dma_free_coherent(&cpt->pdev->dev, mcode->code_size,
  354. mcode->code, mcode->phys_base);
  355. mcode->code = NULL;
  356. }
  357. /* Clear UCODE_BASE registers for all engines */
  358. for (core = 0; core < CPT_MAX_TOTAL_CORES; core++)
  359. cpt_write_csr64(cpt->reg_base,
  360. CPTX_PF_ENGX_UCODE_BASE(0, core), 0ull);
  361. }
  362. static int cpt_device_init(struct cpt_device *cpt)
  363. {
  364. u64 bist;
  365. struct device *dev = &cpt->pdev->dev;
  366. /* Reset the PF when probed first */
  367. cpt_reset(cpt);
  368. msleep(100);
  369. /*Check BIST status*/
  370. bist = (u64)cpt_check_bist_status(cpt);
  371. if (bist) {
  372. dev_err(dev, "RAM BIST failed with code 0x%llx", bist);
  373. return -ENODEV;
  374. }
  375. bist = cpt_check_exe_bist_status(cpt);
  376. if (bist) {
  377. dev_err(dev, "Engine BIST failed with code 0x%llx", bist);
  378. return -ENODEV;
  379. }
  380. /*Get CLK frequency*/
  381. /*Get max enabled cores */
  382. cpt_find_max_enabled_cores(cpt);
  383. /*Disable all cores*/
  384. cpt_disable_all_cores(cpt);
  385. /*Reset device parameters*/
  386. cpt->next_mc_idx = 0;
  387. cpt->next_group = 0;
  388. /* PF is ready */
  389. cpt->flags |= CPT_FLAG_DEVICE_READY;
  390. return 0;
  391. }
  392. static int cpt_register_interrupts(struct cpt_device *cpt)
  393. {
  394. int ret;
  395. struct device *dev = &cpt->pdev->dev;
  396. /* Enable MSI-X */
  397. ret = pci_alloc_irq_vectors(cpt->pdev, CPT_PF_MSIX_VECTORS,
  398. CPT_PF_MSIX_VECTORS, PCI_IRQ_MSIX);
  399. if (ret < 0) {
  400. dev_err(&cpt->pdev->dev, "Request for #%d msix vectors failed\n",
  401. CPT_PF_MSIX_VECTORS);
  402. return ret;
  403. }
  404. /* Register mailbox interrupt handlers */
  405. ret = request_irq(pci_irq_vector(cpt->pdev, CPT_PF_INT_VEC_E_MBOXX(0)),
  406. cpt_mbx0_intr_handler, 0, "CPT Mbox0", cpt);
  407. if (ret)
  408. goto fail;
  409. /* Enable mailbox interrupt */
  410. cpt_enable_mbox_interrupts(cpt);
  411. return 0;
  412. fail:
  413. dev_err(dev, "Request irq failed\n");
  414. pci_disable_msix(cpt->pdev);
  415. return ret;
  416. }
  417. static void cpt_unregister_interrupts(struct cpt_device *cpt)
  418. {
  419. free_irq(pci_irq_vector(cpt->pdev, CPT_PF_INT_VEC_E_MBOXX(0)), cpt);
  420. pci_disable_msix(cpt->pdev);
  421. }
  422. static int cpt_sriov_init(struct cpt_device *cpt, int num_vfs)
  423. {
  424. int pos = 0;
  425. int err;
  426. u16 total_vf_cnt;
  427. struct pci_dev *pdev = cpt->pdev;
  428. pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
  429. if (!pos) {
  430. dev_err(&pdev->dev, "SRIOV capability is not found in PCIe config space\n");
  431. return -ENODEV;
  432. }
  433. cpt->num_vf_en = num_vfs; /* User requested VFs */
  434. pci_read_config_word(pdev, (pos + PCI_SRIOV_TOTAL_VF), &total_vf_cnt);
  435. if (total_vf_cnt < cpt->num_vf_en)
  436. cpt->num_vf_en = total_vf_cnt;
  437. if (!total_vf_cnt)
  438. return 0;
  439. /*Enabled the available VFs */
  440. err = pci_enable_sriov(pdev, cpt->num_vf_en);
  441. if (err) {
  442. dev_err(&pdev->dev, "SRIOV enable failed, num VF is %d\n",
  443. cpt->num_vf_en);
  444. cpt->num_vf_en = 0;
  445. return err;
  446. }
  447. /* TODO: Optionally enable static VQ priorities feature */
  448. dev_info(&pdev->dev, "SRIOV enabled, number of VF available %d\n",
  449. cpt->num_vf_en);
  450. cpt->flags |= CPT_FLAG_SRIOV_ENABLED;
  451. return 0;
  452. }
  453. static int cpt_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  454. {
  455. struct device *dev = &pdev->dev;
  456. struct cpt_device *cpt;
  457. int err;
  458. if (num_vfs > 16 || num_vfs < 4) {
  459. dev_warn(dev, "Invalid vf count %d, Resetting it to 4(default)\n",
  460. num_vfs);
  461. num_vfs = 4;
  462. }
  463. cpt = devm_kzalloc(dev, sizeof(*cpt), GFP_KERNEL);
  464. if (!cpt)
  465. return -ENOMEM;
  466. pci_set_drvdata(pdev, cpt);
  467. cpt->pdev = pdev;
  468. err = pci_enable_device(pdev);
  469. if (err) {
  470. dev_err(dev, "Failed to enable PCI device\n");
  471. pci_set_drvdata(pdev, NULL);
  472. return err;
  473. }
  474. err = pci_request_regions(pdev, DRV_NAME);
  475. if (err) {
  476. dev_err(dev, "PCI request regions failed 0x%x\n", err);
  477. goto cpt_err_disable_device;
  478. }
  479. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(48));
  480. if (err) {
  481. dev_err(dev, "Unable to get usable DMA configuration\n");
  482. goto cpt_err_release_regions;
  483. }
  484. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(48));
  485. if (err) {
  486. dev_err(dev, "Unable to get 48-bit DMA for consistent allocations\n");
  487. goto cpt_err_release_regions;
  488. }
  489. /* MAP PF's configuration registers */
  490. cpt->reg_base = pcim_iomap(pdev, 0, 0);
  491. if (!cpt->reg_base) {
  492. dev_err(dev, "Cannot map config register space, aborting\n");
  493. err = -ENOMEM;
  494. goto cpt_err_release_regions;
  495. }
  496. /* CPT device HW initialization */
  497. cpt_device_init(cpt);
  498. /* Register interrupts */
  499. err = cpt_register_interrupts(cpt);
  500. if (err)
  501. goto cpt_err_release_regions;
  502. err = cpt_ucode_load(cpt);
  503. if (err)
  504. goto cpt_err_unregister_interrupts;
  505. /* Configure SRIOV */
  506. err = cpt_sriov_init(cpt, num_vfs);
  507. if (err)
  508. goto cpt_err_unregister_interrupts;
  509. return 0;
  510. cpt_err_unregister_interrupts:
  511. cpt_unregister_interrupts(cpt);
  512. cpt_err_release_regions:
  513. pci_release_regions(pdev);
  514. cpt_err_disable_device:
  515. pci_disable_device(pdev);
  516. pci_set_drvdata(pdev, NULL);
  517. return err;
  518. }
  519. static void cpt_remove(struct pci_dev *pdev)
  520. {
  521. struct cpt_device *cpt = pci_get_drvdata(pdev);
  522. /* Disengage SE and AE cores from all groups*/
  523. cpt_disable_all_cores(cpt);
  524. /* Unload microcodes */
  525. cpt_unload_microcode(cpt);
  526. cpt_unregister_interrupts(cpt);
  527. pci_disable_sriov(pdev);
  528. pci_release_regions(pdev);
  529. pci_disable_device(pdev);
  530. pci_set_drvdata(pdev, NULL);
  531. }
  532. static void cpt_shutdown(struct pci_dev *pdev)
  533. {
  534. struct cpt_device *cpt = pci_get_drvdata(pdev);
  535. if (!cpt)
  536. return;
  537. dev_info(&pdev->dev, "Shutdown device %x:%x.\n",
  538. (u32)pdev->vendor, (u32)pdev->device);
  539. cpt_unregister_interrupts(cpt);
  540. pci_release_regions(pdev);
  541. pci_disable_device(pdev);
  542. pci_set_drvdata(pdev, NULL);
  543. }
  544. /* Supported devices */
  545. static const struct pci_device_id cpt_id_table[] = {
  546. { PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, CPT_81XX_PCI_PF_DEVICE_ID) },
  547. { 0, } /* end of table */
  548. };
  549. static struct pci_driver cpt_pci_driver = {
  550. .name = DRV_NAME,
  551. .id_table = cpt_id_table,
  552. .probe = cpt_probe,
  553. .remove = cpt_remove,
  554. .shutdown = cpt_shutdown,
  555. };
  556. module_pci_driver(cpt_pci_driver);
  557. MODULE_AUTHOR("George Cherian <george.cherian@cavium.com>");
  558. MODULE_DESCRIPTION("Cavium Thunder CPT Physical Function Driver");
  559. MODULE_LICENSE("GPL v2");
  560. MODULE_VERSION(DRV_VERSION);
  561. MODULE_DEVICE_TABLE(pci, cpt_id_table);