pci.c 1.5 KB

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