static void adf_device_reset_worker(struct work_struct *work) { struct adf_reset_dev_data *reset_data = container_of(work, struct adf_reset_dev_data, reset_work); struct adf_accel_dev *accel_dev = reset_data->accel_dev; adf_dev_restarting_notify(accel_dev); adf_dev_stop(accel_dev); adf_dev_restore(accel_dev); if (adf_dev_start(accel_dev)) { /* The device hanged and we can't restart it so stop here */ dev_err(&GET_DEV(accel_dev), "Restart device failed\n"); kfree(reset_data); WARN(1, "QAT: device restart failed. Device is unusable\n"); return; } adf_dev_restarted_notify(accel_dev); clear_bit(ADF_STATUS_RESTARTING, &accel_dev->status); /* The dev is back alive. Notify the caller if in sync mode */ if (reset_data->mode == ADF_DEV_RESET_SYNC) complete(&reset_data->compl); else kfree(reset_data); }
static int adf_ctl_ioctl_dev_start(struct file *fp, unsigned int cmd, unsigned long arg) { int ret; struct adf_user_cfg_ctl_data *ctl_data; struct adf_accel_dev *accel_dev; ret = adf_ctl_alloc_resources(&ctl_data, arg); if (ret) return ret; accel_dev = adf_devmgr_get_dev_by_id(ctl_data->device_id); if (!accel_dev) { pr_err("QAT: Device %d not found\n", ctl_data->device_id); ret = -ENODEV; goto out; } if (!adf_dev_started(accel_dev)) { pr_info("QAT: Starting acceleration device qat_dev%d.\n", ctl_data->device_id); ret = adf_dev_start(accel_dev); } else { pr_info("QAT: Acceleration device qat_dev%d already started.\n", ctl_data->device_id); } if (ret) { pr_err("QAT: Failed to start qat_dev%d\n", ctl_data->device_id); adf_dev_stop(accel_dev); } out: kfree(ctl_data); return ret; }
static void adf_remove(struct pci_dev *pdev) { struct adf_accel_dev *accel_dev = adf_devmgr_pci_to_accel_dev(pdev); if (!accel_dev) { pr_err("QAT: Driver removal failed\n"); return; } if (adf_dev_stop(accel_dev)) dev_err(&GET_DEV(accel_dev), "Failed to stop QAT accel dev\n"); adf_disable_aer(accel_dev); adf_cleanup_accel(accel_dev); }
static void adf_dev_stop_async(struct work_struct *work) { struct adf_vf_stop_data *stop_data = container_of(work, struct adf_vf_stop_data, work); struct adf_accel_dev *accel_dev = stop_data->accel_dev; adf_dev_stop(accel_dev); adf_dev_shutdown(accel_dev); /* Re-enable PF2VF interrupts */ adf_enable_pf2vf_interrupts(accel_dev); kfree(stop_data); }
static int adf_ctl_stop_devices(uint32_t id) { struct list_head *itr, *head = adf_devmgr_get_head(); int ret = 0; list_for_each(itr, head) { struct adf_accel_dev *accel_dev = list_entry(itr, struct adf_accel_dev, list); if (id == accel_dev->accel_id || id == ADF_CFG_ALL_DEVICES) { if (!adf_dev_started(accel_dev)) continue; if (adf_dev_stop(accel_dev)) { pr_err("QAT: Failed to stop qat_dev%d\n", id); ret = -EFAULT; } } } return ret; }
static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) { struct adf_accel_dev *accel_dev; struct adf_accel_pci *accel_pci_dev; struct adf_hw_device_data *hw_data; char name[ADF_DEVICE_NAME_LENGTH]; unsigned int i, bar_nr; int ret; switch (ent->device) { case ADF_DH895XCC_PCI_DEVICE_ID: break; default: dev_err(&pdev->dev, "Invalid device 0x%x.\n", ent->device); return -ENODEV; } if (num_possible_nodes() > 1 && dev_to_node(&pdev->dev) < 0) { /* If the accelerator is connected to a node with no memory * there is no point in using the accelerator since the remote * memory transaction will be very slow. */ dev_err(&pdev->dev, "Invalid NUMA configuration.\n"); return -EINVAL; } accel_dev = kzalloc_node(sizeof(*accel_dev), GFP_KERNEL, dev_to_node(&pdev->dev)); if (!accel_dev) return -ENOMEM; INIT_LIST_HEAD(&accel_dev->crypto_list); /* Add accel device to accel table. * This should be called before adf_cleanup_accel is called */ if (adf_devmgr_add_dev(accel_dev)) { dev_err(&pdev->dev, "Failed to add new accelerator device.\n"); kfree(accel_dev); return -EFAULT; } accel_dev->owner = THIS_MODULE; /* Allocate and configure device configuration structure */ hw_data = kzalloc_node(sizeof(*hw_data), GFP_KERNEL, dev_to_node(&pdev->dev)); if (!hw_data) { ret = -ENOMEM; goto out_err; } accel_dev->hw_device = hw_data; switch (ent->device) { case ADF_DH895XCC_PCI_DEVICE_ID: adf_init_hw_data_dh895xcc(accel_dev->hw_device); break; default: return -ENODEV; } accel_pci_dev = &accel_dev->accel_pci_dev; pci_read_config_byte(pdev, PCI_REVISION_ID, &accel_pci_dev->revid); pci_read_config_dword(pdev, ADF_DH895XCC_FUSECTL_OFFSET, &hw_data->fuses); /* Get Accelerators and Accelerators Engines masks */ hw_data->accel_mask = hw_data->get_accel_mask(hw_data->fuses); hw_data->ae_mask = hw_data->get_ae_mask(hw_data->fuses); accel_pci_dev->sku = hw_data->get_sku(hw_data); accel_pci_dev->pci_dev = pdev; /* If the device has no acceleration engines then ignore it. */ if (!hw_data->accel_mask || !hw_data->ae_mask || ((~hw_data->ae_mask) & 0x01)) { dev_err(&pdev->dev, "No acceleration units found"); ret = -EFAULT; goto out_err; } /* Create dev top level debugfs entry */ snprintf(name, sizeof(name), "%s%s_dev%d", ADF_DEVICE_NAME_PREFIX, hw_data->dev_class->name, hw_data->instance_id); accel_dev->debugfs_dir = debugfs_create_dir(name, NULL); if (!accel_dev->debugfs_dir) { dev_err(&pdev->dev, "Could not create debugfs dir\n"); ret = -EINVAL; goto out_err; } /* Create device configuration table */ ret = adf_cfg_dev_add(accel_dev); if (ret) goto out_err; pcie_set_readrq(pdev, 1024); /* enable PCI device */ if (pci_enable_device(pdev)) { ret = -EFAULT; goto out_err; } /* set dma identifier */ if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) { if ((pci_set_dma_mask(pdev, DMA_BIT_MASK(32)))) { dev_err(&pdev->dev, "No usable DMA configuration\n"); ret = -EFAULT; goto out_err; } else { pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); } } else { pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)); } if (pci_request_regions(pdev, adf_driver_name)) { ret = -EFAULT; goto out_err; } /* Read accelerator capabilities mask */ pci_read_config_dword(pdev, ADF_DH895XCC_LEGFUSE_OFFSET, &hw_data->accel_capabilities_mask); /* Find and map all the device's BARS */ for (i = 0; i < ADF_PCI_MAX_BARS; i++) { struct adf_bar *bar = &accel_pci_dev->pci_bars[i]; bar_nr = i * 2; bar->base_addr = pci_resource_start(pdev, bar_nr); if (!bar->base_addr) break; bar->size = pci_resource_len(pdev, bar_nr); bar->virt_addr = pci_iomap(accel_pci_dev->pci_dev, bar_nr, 0); if (!bar->virt_addr) { dev_err(&pdev->dev, "Failed to map BAR %d\n", i); ret = -EFAULT; goto out_err; } } pci_set_master(pdev); if (adf_enable_aer(accel_dev, &adf_driver)) { dev_err(&pdev->dev, "Failed to enable aer\n"); ret = -EFAULT; goto out_err; } if (pci_save_state(pdev)) { dev_err(&pdev->dev, "Failed to save pci state\n"); ret = -ENOMEM; goto out_err; } ret = adf_dev_configure(accel_dev); if (ret) goto out_err; ret = adf_dev_init(accel_dev); if (ret) goto out_err; ret = adf_dev_start(accel_dev); if (ret) { adf_dev_stop(accel_dev); goto out_err; } return 0; out_err: adf_cleanup_accel(accel_dev); return ret; }