Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 2 | // Copyright 2019 IBM Corp. |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 3 | #include <linux/module.h> |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 4 | #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 | */ |
| 11 | static const struct pci_device_id ocxl_pci_tbl[] = { |
| 12 | { PCI_DEVICE(PCI_VENDOR_ID_IBM, 0x062B), }, |
| 13 | { } |
| 14 | }; |
| 15 | MODULE_DEVICE_TABLE(pci, ocxl_pci_tbl); |
| 16 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 17 | static int ocxl_probe(struct pci_dev *dev, const struct pci_device_id *id) |
| 18 | { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 19 | int rc; |
| 20 | struct ocxl_afu *afu, *tmp; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 21 | struct ocxl_fn *fn; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 22 | struct list_head *afu_list; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 23 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 24 | fn = ocxl_function_open(dev); |
| 25 | if (IS_ERR(fn)) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 26 | return PTR_ERR(fn); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 27 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 28 | 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); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 38 | } |
| 39 | } |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 40 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 41 | return 0; |
| 42 | } |
| 43 | |
| 44 | static void ocxl_remove(struct pci_dev *dev) |
| 45 | { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 46 | struct ocxl_fn *fn; |
| 47 | struct ocxl_afu *afu; |
| 48 | struct list_head *afu_list; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 49 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 50 | 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); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 55 | } |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 56 | |
| 57 | ocxl_function_close(fn); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | struct 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 | }; |