linux/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c
<<
>>
Prefs
   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
  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 /* CONFIG_BNXT_SRIOV */
  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