cptpf_main.c 16 KB

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