bnxt_devlink.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* Broadcom NetXtreme-C/E network driver.
  2. *
  3. * Copyright (c) 2017 Broadcom Limited
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation.
  8. */
  9. #include <linux/pci.h>
  10. #include <linux/netdevice.h>
  11. #include "bnxt_hsi.h"
  12. #include "bnxt.h"
  13. #include "bnxt_vfr.h"
  14. #include "bnxt_devlink.h"
  15. static const struct devlink_ops bnxt_dl_ops = {
  16. #ifdef CONFIG_BNXT_SRIOV
  17. .eswitch_mode_set = bnxt_dl_eswitch_mode_set,
  18. .eswitch_mode_get = bnxt_dl_eswitch_mode_get,
  19. #endif /* CONFIG_BNXT_SRIOV */
  20. };
  21. int bnxt_dl_register(struct bnxt *bp)
  22. {
  23. struct devlink *dl;
  24. int rc;
  25. if (!pci_find_ext_capability(bp->pdev, PCI_EXT_CAP_ID_SRIOV))
  26. return 0;
  27. if (bp->hwrm_spec_code < 0x10803) {
  28. netdev_warn(bp->dev, "Firmware does not support SR-IOV E-Switch SWITCHDEV mode.\n");
  29. return -ENOTSUPP;
  30. }
  31. dl = devlink_alloc(&bnxt_dl_ops, sizeof(struct bnxt_dl));
  32. if (!dl) {
  33. netdev_warn(bp->dev, "devlink_alloc failed");
  34. return -ENOMEM;
  35. }
  36. bnxt_link_bp_to_dl(bp, dl);
  37. bp->eswitch_mode = DEVLINK_ESWITCH_MODE_LEGACY;
  38. rc = devlink_register(dl, &bp->pdev->dev);
  39. if (rc) {
  40. bnxt_link_bp_to_dl(bp, NULL);
  41. devlink_free(dl);
  42. netdev_warn(bp->dev, "devlink_register failed. rc=%d", rc);
  43. return rc;
  44. }
  45. return 0;
  46. }
  47. void bnxt_dl_unregister(struct bnxt *bp)
  48. {
  49. struct devlink *dl = bp->dl;
  50. if (!dl)
  51. return;
  52. devlink_unregister(dl);
  53. devlink_free(dl);
  54. }