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 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 
20 static 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 
33 static 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 
46 static 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 static int hns3_dcbnl_ieee_setapp(struct net_device *ndev, struct dcb_app *app)
60 {
61 	struct hnae3_handle *h = hns3_get_handle(ndev);
62 
63 	if (hns3_nic_resetting(ndev))
64 		return -EBUSY;
65 
66 	if (h->kinfo.dcb_ops->ieee_setapp)
67 		return h->kinfo.dcb_ops->ieee_setapp(h, app);
68 
69 	return -EOPNOTSUPP;
70 }
71 
72 static int hns3_dcbnl_ieee_delapp(struct net_device *ndev, struct dcb_app *app)
73 {
74 	struct hnae3_handle *h = hns3_get_handle(ndev);
75 
76 	if (hns3_nic_resetting(ndev))
77 		return -EBUSY;
78 
79 	if (h->kinfo.dcb_ops->ieee_setapp)
80 		return h->kinfo.dcb_ops->ieee_delapp(h, app);
81 
82 	return -EOPNOTSUPP;
83 }
84 
85 /* DCBX configuration */
86 static u8 hns3_dcbnl_getdcbx(struct net_device *ndev)
87 {
88 	struct hnae3_handle *h = hns3_get_handle(ndev);
89 
90 	if (h->kinfo.dcb_ops->getdcbx)
91 		return h->kinfo.dcb_ops->getdcbx(h);
92 
93 	return 0;
94 }
95 
96 /* return 0 if successful, otherwise fail */
97 static u8 hns3_dcbnl_setdcbx(struct net_device *ndev, u8 mode)
98 {
99 	struct hnae3_handle *h = hns3_get_handle(ndev);
100 
101 	if (h->kinfo.dcb_ops->setdcbx)
102 		return h->kinfo.dcb_ops->setdcbx(h, mode);
103 
104 	return 1;
105 }
106 
107 static const struct dcbnl_rtnl_ops hns3_dcbnl_ops = {
108 	.ieee_getets	= hns3_dcbnl_ieee_getets,
109 	.ieee_setets	= hns3_dcbnl_ieee_setets,
110 	.ieee_getpfc	= hns3_dcbnl_ieee_getpfc,
111 	.ieee_setpfc	= hns3_dcbnl_ieee_setpfc,
112 	.ieee_setapp    = hns3_dcbnl_ieee_setapp,
113 	.ieee_delapp    = hns3_dcbnl_ieee_delapp,
114 	.getdcbx	= hns3_dcbnl_getdcbx,
115 	.setdcbx	= hns3_dcbnl_setdcbx,
116 };
117 
118 /* hclge_dcbnl_setup - DCBNL setup
119  * @handle: the corresponding vport handle
120  * Set up DCBNL
121  */
122 void hns3_dcbnl_setup(struct hnae3_handle *handle)
123 {
124 	struct net_device *dev = handle->kinfo.netdev;
125 
126 	if ((!handle->kinfo.dcb_ops) || (handle->flags & HNAE3_SUPPORT_VF))
127 		return;
128 
129 	dev->dcbnl_ops = &hns3_dcbnl_ops;
130 }
131