2018-01-23 19:31:41 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2019-03-27 13:31:30 +08:00
|
|
|
// Copyright 2019 IBM Corp.
|
2018-01-23 19:31:41 +08:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include "ocxl_internal.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Any opencapi device which wants to use this 'generic' driver should
|
|
|
|
* use the 0x062B device ID. Vendors should define the subsystem
|
|
|
|
* vendor/device ID to help differentiate devices.
|
|
|
|
*/
|
|
|
|
static const struct pci_device_id ocxl_pci_tbl[] = {
|
|
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_IBM, 0x062B), },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(pci, ocxl_pci_tbl);
|
|
|
|
|
|
|
|
static int ocxl_probe(struct pci_dev *dev, const struct pci_device_id *id)
|
|
|
|
{
|
2019-03-27 13:31:32 +08:00
|
|
|
int rc;
|
|
|
|
struct ocxl_afu *afu, *tmp;
|
2018-01-23 19:31:41 +08:00
|
|
|
struct ocxl_fn *fn;
|
2019-03-27 13:31:32 +08:00
|
|
|
struct list_head *afu_list;
|
2018-01-23 19:31:41 +08:00
|
|
|
|
2019-03-27 13:31:32 +08:00
|
|
|
fn = ocxl_function_open(dev);
|
|
|
|
if (IS_ERR(fn))
|
2018-01-23 19:31:41 +08:00
|
|
|
return PTR_ERR(fn);
|
|
|
|
|
2019-03-27 13:31:32 +08:00
|
|
|
pci_set_drvdata(dev, fn);
|
|
|
|
|
|
|
|
afu_list = ocxl_function_afu_list(fn);
|
|
|
|
|
|
|
|
list_for_each_entry_safe(afu, tmp, afu_list, list) {
|
|
|
|
// Cleanup handled within ocxl_file_register_afu()
|
|
|
|
rc = ocxl_file_register_afu(afu);
|
|
|
|
if (rc) {
|
|
|
|
dev_err(&dev->dev, "Failed to register AFU '%s' index %d",
|
|
|
|
afu->config.name, afu->config.idx);
|
2018-01-23 19:31:41 +08:00
|
|
|
}
|
|
|
|
}
|
2019-03-27 13:31:32 +08:00
|
|
|
|
2018-01-23 19:31:41 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-03-27 13:31:32 +08:00
|
|
|
void ocxl_remove(struct pci_dev *dev)
|
2018-01-23 19:31:41 +08:00
|
|
|
{
|
2019-03-27 13:31:32 +08:00
|
|
|
struct ocxl_fn *fn;
|
|
|
|
struct ocxl_afu *afu;
|
|
|
|
struct list_head *afu_list;
|
2018-01-23 19:31:41 +08:00
|
|
|
|
2019-03-27 13:31:32 +08:00
|
|
|
fn = pci_get_drvdata(dev);
|
|
|
|
afu_list = ocxl_function_afu_list(fn);
|
|
|
|
|
|
|
|
list_for_each_entry(afu, afu_list, list) {
|
|
|
|
ocxl_file_unregister_afu(afu);
|
2018-01-23 19:31:41 +08:00
|
|
|
}
|
2019-03-27 13:31:32 +08:00
|
|
|
|
|
|
|
ocxl_function_close(fn);
|
2018-01-23 19:31:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
struct pci_driver ocxl_pci_driver = {
|
|
|
|
.name = "ocxl",
|
|
|
|
.id_table = ocxl_pci_tbl,
|
|
|
|
.probe = ocxl_probe,
|
|
|
|
.remove = ocxl_remove,
|
|
|
|
.shutdown = ocxl_remove,
|
|
|
|
};
|