hns3_dcbnl.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // SPDX-License-Identifier: GPL-2.0+
  2. // Copyright (c) 2016-2017 Hisilicon Limited.
  3. #include "hnae3.h"
  4. #include "hns3_enet.h"
  5. static int hns3_dcbnl_ieee_getets(struct net_device *ndev, struct ieee_ets *ets)
  6. {
  7. struct hnae3_handle *h = hns3_get_handle(ndev);
  8. if (hns3_nic_resetting(ndev))
  9. return -EBUSY;
  10. if (h->kinfo.dcb_ops->ieee_getets)
  11. return h->kinfo.dcb_ops->ieee_getets(h, ets);
  12. return -EOPNOTSUPP;
  13. }
  14. static int hns3_dcbnl_ieee_setets(struct net_device *ndev, struct ieee_ets *ets)
  15. {
  16. struct hnae3_handle *h = hns3_get_handle(ndev);
  17. if (hns3_nic_resetting(ndev))
  18. return -EBUSY;
  19. if (h->kinfo.dcb_ops->ieee_setets)
  20. return h->kinfo.dcb_ops->ieee_setets(h, ets);
  21. return -EOPNOTSUPP;
  22. }
  23. static int hns3_dcbnl_ieee_getpfc(struct net_device *ndev, struct ieee_pfc *pfc)
  24. {
  25. struct hnae3_handle *h = hns3_get_handle(ndev);
  26. if (hns3_nic_resetting(ndev))
  27. return -EBUSY;
  28. if (h->kinfo.dcb_ops->ieee_getpfc)
  29. return h->kinfo.dcb_ops->ieee_getpfc(h, pfc);
  30. return -EOPNOTSUPP;
  31. }
  32. static int hns3_dcbnl_ieee_setpfc(struct net_device *ndev, struct ieee_pfc *pfc)
  33. {
  34. struct hnae3_handle *h = hns3_get_handle(ndev);
  35. if (hns3_nic_resetting(ndev))
  36. return -EBUSY;
  37. if (h->kinfo.dcb_ops->ieee_setpfc)
  38. return h->kinfo.dcb_ops->ieee_setpfc(h, pfc);
  39. return -EOPNOTSUPP;
  40. }
  41. /* DCBX configuration */
  42. static u8 hns3_dcbnl_getdcbx(struct net_device *ndev)
  43. {
  44. struct hnae3_handle *h = hns3_get_handle(ndev);
  45. if (h->kinfo.dcb_ops->getdcbx)
  46. return h->kinfo.dcb_ops->getdcbx(h);
  47. return 0;
  48. }
  49. /* return 0 if successful, otherwise fail */
  50. static u8 hns3_dcbnl_setdcbx(struct net_device *ndev, u8 mode)
  51. {
  52. struct hnae3_handle *h = hns3_get_handle(ndev);
  53. if (h->kinfo.dcb_ops->setdcbx)
  54. return h->kinfo.dcb_ops->setdcbx(h, mode);
  55. return 1;
  56. }
  57. static const struct dcbnl_rtnl_ops hns3_dcbnl_ops = {
  58. .ieee_getets = hns3_dcbnl_ieee_getets,
  59. .ieee_setets = hns3_dcbnl_ieee_setets,
  60. .ieee_getpfc = hns3_dcbnl_ieee_getpfc,
  61. .ieee_setpfc = hns3_dcbnl_ieee_setpfc,
  62. .getdcbx = hns3_dcbnl_getdcbx,
  63. .setdcbx = hns3_dcbnl_setdcbx,
  64. };
  65. /* hclge_dcbnl_setup - DCBNL setup
  66. * @handle: the corresponding vport handle
  67. * Set up DCBNL
  68. */
  69. void hns3_dcbnl_setup(struct hnae3_handle *handle)
  70. {
  71. struct net_device *dev = handle->kinfo.netdev;
  72. if ((!handle->kinfo.dcb_ops) || (handle->flags & HNAE3_SUPPORT_VF))
  73. return;
  74. dev->dcbnl_ops = &hns3_dcbnl_ops;
  75. }