^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) // Copyright 2019 IBM Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) #include "ocxl_internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Any opencapi device which wants to use this 'generic' driver should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * use the 0x062B device ID. Vendors should define the subsystem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * vendor/device ID to help differentiate devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) static const struct pci_device_id ocxl_pci_tbl[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) { PCI_DEVICE(PCI_VENDOR_ID_IBM, 0x062B), },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) MODULE_DEVICE_TABLE(pci, ocxl_pci_tbl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) static int ocxl_probe(struct pci_dev *dev, const struct pci_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) struct ocxl_afu *afu, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) struct ocxl_fn *fn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) struct list_head *afu_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) fn = ocxl_function_open(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) if (IS_ERR(fn))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) return PTR_ERR(fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) pci_set_drvdata(dev, fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) afu_list = ocxl_function_afu_list(fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) list_for_each_entry_safe(afu, tmp, afu_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) // Cleanup handled within ocxl_file_register_afu()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) rc = ocxl_file_register_afu(afu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) dev_err(&dev->dev, "Failed to register AFU '%s' index %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) afu->config.name, afu->config.idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) static void ocxl_remove(struct pci_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct ocxl_fn *fn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct ocxl_afu *afu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct list_head *afu_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) fn = pci_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) afu_list = ocxl_function_afu_list(fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) list_for_each_entry(afu, afu_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) ocxl_file_unregister_afu(afu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) ocxl_function_close(fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) struct pci_driver ocxl_pci_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) .name = "ocxl",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) .id_table = ocxl_pci_tbl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) .probe = ocxl_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) .remove = ocxl_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) .shutdown = ocxl_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) };