linux/drivers/net/ethernet/hisilicon/hns3/hns3_dcbnl.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0+
   2// Copyright (c) 2016-2017 Hisilicon Limited.
   3
   4#include "hnae3.h"
   5#include "hns3_enet.h"
   6
   7static
   8int hns3_dcbnl_ieee_getets(struct net_device *ndev, struct ieee_ets *ets)
   9{
  10        struct hnae3_handle *h = hns3_get_handle(ndev);
  11
  12        if (hns3_nic_resetting(ndev))
  13                return -EBUSY;
  14
  15        if (h->kinfo.dcb_ops->ieee_getets)
  16                return h->kinfo.dcb_ops->ieee_getets(h, ets);
  17
  18        return -EOPNOTSUPP;
  19}
  20
  21static
  22int hns3_dcbnl_ieee_setets(struct net_device *ndev, struct ieee_ets *ets)
  23{
  24        struct hnae3_handle *h = hns3_get_handle(ndev);
  25
  26        if (hns3_nic_resetting(ndev))
  27                return -EBUSY;
  28
  29        if (h->kinfo.dcb_ops->ieee_setets)
  30                return h->kinfo.dcb_ops->ieee_setets(h, ets);
  31
  32        return -EOPNOTSUPP;
  33}
  34
  35static
  36int hns3_dcbnl_ieee_getpfc(struct net_device *ndev, struct ieee_pfc *pfc)
  37{
  38        struct hnae3_handle *h = hns3_get_handle(ndev);
  39
  40        if (hns3_nic_resetting(ndev))
  41                return -EBUSY;
  42
  43        if (h->kinfo.dcb_ops->ieee_getpfc)
  44                return h->kinfo.dcb_ops->ieee_getpfc(h, pfc);
  45
  46        return -EOPNOTSUPP;
  47}
  48
  49static
  50int hns3_dcbnl_ieee_setpfc(struct net_device *ndev, struct ieee_pfc *pfc)
  51{
  52        struct hnae3_handle *h = hns3_get_handle(ndev);
  53
  54        if (hns3_nic_resetting(ndev))
  55                return -EBUSY;
  56
  57        if (h->kinfo.dcb_ops->ieee_setpfc)
  58                return h->kinfo.dcb_ops->ieee_setpfc(h, pfc);
  59
  60        return -EOPNOTSUPP;
  61}
  62
  63/* DCBX configuration */
  64static u8 hns3_dcbnl_getdcbx(struct net_device *ndev)
  65{
  66        struct hnae3_handle *h = hns3_get_handle(ndev);
  67
  68        if (h->kinfo.dcb_ops->getdcbx)
  69                return h->kinfo.dcb_ops->getdcbx(h);
  70
  71        return 0;
  72}
  73
  74/* return 0 if successful, otherwise fail */
  75static u8 hns3_dcbnl_setdcbx(struct net_device *ndev, u8 mode)
  76{
  77        struct hnae3_handle *h = hns3_get_handle(ndev);
  78
  79        if (h->kinfo.dcb_ops->setdcbx)
  80                return h->kinfo.dcb_ops->setdcbx(h, mode);
  81
  82        return 1;
  83}
  84
  85static const struct dcbnl_rtnl_ops hns3_dcbnl_ops = {
  86        .ieee_getets    = hns3_dcbnl_ieee_getets,
  87        .ieee_setets    = hns3_dcbnl_ieee_setets,
  88        .ieee_getpfc    = hns3_dcbnl_ieee_getpfc,
  89        .ieee_setpfc    = hns3_dcbnl_ieee_setpfc,
  90        .getdcbx        = hns3_dcbnl_getdcbx,
  91        .setdcbx        = hns3_dcbnl_setdcbx,
  92};
  93
  94/* hclge_dcbnl_setup - DCBNL setup
  95 * @handle: the corresponding vport handle
  96 * Set up DCBNL
  97 */
  98void hns3_dcbnl_setup(struct hnae3_handle *handle)
  99{
 100        struct net_device *dev = handle->kinfo.netdev;
 101
 102        if ((!handle->kinfo.dcb_ops) || (handle->flags & HNAE3_SUPPORT_VF))
 103                return;
 104
 105        dev->dcbnl_ops = &hns3_dcbnl_ops;
 106}
 107