1
2
3
4
5
6
7
8
9
10#include <linux/pci.h>
11#include <linux/netdevice.h>
12#include "bnxt_hsi.h"
13#include "bnxt.h"
14#include "bnxt_vfr.h"
15#include "bnxt_devlink.h"
16
17static const struct devlink_ops bnxt_dl_ops = {
18#ifdef CONFIG_BNXT_SRIOV
19 .eswitch_mode_set = bnxt_dl_eswitch_mode_set,
20 .eswitch_mode_get = bnxt_dl_eswitch_mode_get,
21#endif
22};
23
24int bnxt_dl_register(struct bnxt *bp)
25{
26 struct devlink *dl;
27 int rc;
28
29 if (!pci_find_ext_capability(bp->pdev, PCI_EXT_CAP_ID_SRIOV))
30 return 0;
31
32 if (bp->hwrm_spec_code < 0x10803) {
33 netdev_warn(bp->dev, "Firmware does not support SR-IOV E-Switch SWITCHDEV mode.\n");
34 return -ENOTSUPP;
35 }
36
37 dl = devlink_alloc(&bnxt_dl_ops, sizeof(struct bnxt_dl));
38 if (!dl) {
39 netdev_warn(bp->dev, "devlink_alloc failed");
40 return -ENOMEM;
41 }
42
43 bnxt_link_bp_to_dl(bp, dl);
44 bp->eswitch_mode = DEVLINK_ESWITCH_MODE_LEGACY;
45 rc = devlink_register(dl, &bp->pdev->dev);
46 if (rc) {
47 bnxt_link_bp_to_dl(bp, NULL);
48 devlink_free(dl);
49 netdev_warn(bp->dev, "devlink_register failed. rc=%d", rc);
50 return rc;
51 }
52
53 return 0;
54}
55
56void bnxt_dl_unregister(struct bnxt *bp)
57{
58 struct devlink *dl = bp->dl;
59
60 if (!dl)
61 return;
62
63 devlink_unregister(dl);
64 devlink_free(dl);
65}
66