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