blob: cb920aa88d3a1d48964317d2d429680d9f0cba0f [file] [log] [blame]
Frederic Barrat5ef31662018-01-23 12:31:41 +01001// SPDX-License-Identifier: GPL-2.0+
Alastair D'Silva1ba21432019-03-27 16:31:30 +11002// Copyright 2019 IBM Corp.
Frederic Barrat5ef31662018-01-23 12:31:41 +01003#include <linux/module.h>
Frederic Barrat5ef31662018-01-23 12:31:41 +01004#include "ocxl_internal.h"
5
6/*
7 * Any opencapi device which wants to use this 'generic' driver should
8 * use the 0x062B device ID. Vendors should define the subsystem
9 * vendor/device ID to help differentiate devices.
10 */
11static const struct pci_device_id ocxl_pci_tbl[] = {
12 { PCI_DEVICE(PCI_VENDOR_ID_IBM, 0x062B), },
13 { }
14};
15MODULE_DEVICE_TABLE(pci, ocxl_pci_tbl);
16
Frederic Barrat5ef31662018-01-23 12:31:41 +010017static int ocxl_probe(struct pci_dev *dev, const struct pci_device_id *id)
18{
Alastair D'Silva75ca7582019-03-27 16:31:32 +110019 int rc;
20 struct ocxl_afu *afu, *tmp;
Frederic Barrat5ef31662018-01-23 12:31:41 +010021 struct ocxl_fn *fn;
Alastair D'Silva75ca7582019-03-27 16:31:32 +110022 struct list_head *afu_list;
Frederic Barrat5ef31662018-01-23 12:31:41 +010023
Alastair D'Silva75ca7582019-03-27 16:31:32 +110024 fn = ocxl_function_open(dev);
25 if (IS_ERR(fn))
Frederic Barrat5ef31662018-01-23 12:31:41 +010026 return PTR_ERR(fn);
Frederic Barrat5ef31662018-01-23 12:31:41 +010027
Alastair D'Silva75ca7582019-03-27 16:31:32 +110028 pci_set_drvdata(dev, fn);
29
30 afu_list = ocxl_function_afu_list(fn);
31
32 list_for_each_entry_safe(afu, tmp, afu_list, list) {
33 // Cleanup handled within ocxl_file_register_afu()
34 rc = ocxl_file_register_afu(afu);
35 if (rc) {
36 dev_err(&dev->dev, "Failed to register AFU '%s' index %d",
37 afu->config.name, afu->config.idx);
Frederic Barrat5ef31662018-01-23 12:31:41 +010038 }
39 }
Alastair D'Silva75ca7582019-03-27 16:31:32 +110040
Frederic Barrat5ef31662018-01-23 12:31:41 +010041 return 0;
42}
43
YueHaibing00b0cdb2019-05-04 18:27:20 +080044static void ocxl_remove(struct pci_dev *dev)
Frederic Barrat5ef31662018-01-23 12:31:41 +010045{
Alastair D'Silva75ca7582019-03-27 16:31:32 +110046 struct ocxl_fn *fn;
47 struct ocxl_afu *afu;
48 struct list_head *afu_list;
Frederic Barrat5ef31662018-01-23 12:31:41 +010049
Alastair D'Silva75ca7582019-03-27 16:31:32 +110050 fn = pci_get_drvdata(dev);
51 afu_list = ocxl_function_afu_list(fn);
52
53 list_for_each_entry(afu, afu_list, list) {
54 ocxl_file_unregister_afu(afu);
Frederic Barrat5ef31662018-01-23 12:31:41 +010055 }
Alastair D'Silva75ca7582019-03-27 16:31:32 +110056
57 ocxl_function_close(fn);
Frederic Barrat5ef31662018-01-23 12:31:41 +010058}
59
60struct pci_driver ocxl_pci_driver = {
61 .name = "ocxl",
62 .id_table = ocxl_pci_tbl,
63 .probe = ocxl_probe,
64 .remove = ocxl_remove,
65 .shutdown = ocxl_remove,
66};