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