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