1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
2 /* QLogic qede NIC Driver
3  * Copyright (c) 2015 QLogic Corporation
4  * Copyright (c) 2019-2020 Marvell International Ltd.
5  */
6 
7 #include <linux/types.h>
8 #include <linux/netdevice.h>
9 #include <linux/rtnetlink.h>
10 #include <net/dcbnl.h>
11 #include "qede.h"
12 
qede_dcbnl_getstate(struct net_device * netdev)13 static u8 qede_dcbnl_getstate(struct net_device *netdev)
14 {
15 	struct qede_dev *edev = netdev_priv(netdev);
16 
17 	return edev->ops->dcb->getstate(edev->cdev);
18 }
19 
qede_dcbnl_setstate(struct net_device * netdev,u8 state)20 static u8 qede_dcbnl_setstate(struct net_device *netdev, u8 state)
21 {
22 	struct qede_dev *edev = netdev_priv(netdev);
23 
24 	return edev->ops->dcb->setstate(edev->cdev, state);
25 }
26 
qede_dcbnl_getpermhwaddr(struct net_device * netdev,u8 * perm_addr)27 static void qede_dcbnl_getpermhwaddr(struct net_device *netdev,
28 				     u8 *perm_addr)
29 {
30 	memcpy(perm_addr, netdev->dev_addr, netdev->addr_len);
31 }
32 
qede_dcbnl_getpgtccfgtx(struct net_device * netdev,int prio,u8 * prio_type,u8 * pgid,u8 * bw_pct,u8 * up_map)33 static void qede_dcbnl_getpgtccfgtx(struct net_device *netdev, int prio,
34 				    u8 *prio_type, u8 *pgid, u8 *bw_pct,
35 				    u8 *up_map)
36 {
37 	struct qede_dev *edev = netdev_priv(netdev);
38 
39 	edev->ops->dcb->getpgtccfgtx(edev->cdev, prio, prio_type,
40 				     pgid, bw_pct, up_map);
41 }
42 
qede_dcbnl_getpgbwgcfgtx(struct net_device * netdev,int pgid,u8 * bw_pct)43 static void qede_dcbnl_getpgbwgcfgtx(struct net_device *netdev,
44 				     int pgid, u8 *bw_pct)
45 {
46 	struct qede_dev *edev = netdev_priv(netdev);
47 
48 	edev->ops->dcb->getpgbwgcfgtx(edev->cdev, pgid, bw_pct);
49 }
50 
qede_dcbnl_getpgtccfgrx(struct net_device * netdev,int prio,u8 * prio_type,u8 * pgid,u8 * bw_pct,u8 * up_map)51 static void qede_dcbnl_getpgtccfgrx(struct net_device *netdev, int prio,
52 				    u8 *prio_type, u8 *pgid, u8 *bw_pct,
53 				    u8 *up_map)
54 {
55 	struct qede_dev *edev = netdev_priv(netdev);
56 
57 	edev->ops->dcb->getpgtccfgrx(edev->cdev, prio, prio_type, pgid, bw_pct,
58 				     up_map);
59 }
60 
qede_dcbnl_getpgbwgcfgrx(struct net_device * netdev,int pgid,u8 * bw_pct)61 static void qede_dcbnl_getpgbwgcfgrx(struct net_device *netdev,
62 				     int pgid, u8 *bw_pct)
63 {
64 	struct qede_dev *edev = netdev_priv(netdev);
65 
66 	edev->ops->dcb->getpgbwgcfgrx(edev->cdev, pgid, bw_pct);
67 }
68 
qede_dcbnl_getpfccfg(struct net_device * netdev,int prio,u8 * setting)69 static void qede_dcbnl_getpfccfg(struct net_device *netdev, int prio,
70 				 u8 *setting)
71 {
72 	struct qede_dev *edev = netdev_priv(netdev);
73 
74 	edev->ops->dcb->getpfccfg(edev->cdev, prio, setting);
75 }
76 
qede_dcbnl_setpfccfg(struct net_device * netdev,int prio,u8 setting)77 static void qede_dcbnl_setpfccfg(struct net_device *netdev, int prio,
78 				 u8 setting)
79 {
80 	struct qede_dev *edev = netdev_priv(netdev);
81 
82 	edev->ops->dcb->setpfccfg(edev->cdev, prio, setting);
83 }
84 
qede_dcbnl_getcap(struct net_device * netdev,int capid,u8 * cap)85 static u8 qede_dcbnl_getcap(struct net_device *netdev, int capid, u8 *cap)
86 {
87 	struct qede_dev *edev = netdev_priv(netdev);
88 
89 	return edev->ops->dcb->getcap(edev->cdev, capid, cap);
90 }
91 
qede_dcbnl_getnumtcs(struct net_device * netdev,int tcid,u8 * num)92 static int qede_dcbnl_getnumtcs(struct net_device *netdev, int tcid, u8 *num)
93 {
94 	struct qede_dev *edev = netdev_priv(netdev);
95 
96 	return edev->ops->dcb->getnumtcs(edev->cdev, tcid, num);
97 }
98 
qede_dcbnl_getpfcstate(struct net_device * netdev)99 static u8 qede_dcbnl_getpfcstate(struct net_device *netdev)
100 {
101 	struct qede_dev *edev = netdev_priv(netdev);
102 
103 	return edev->ops->dcb->getpfcstate(edev->cdev);
104 }
105 
qede_dcbnl_getapp(struct net_device * netdev,u8 idtype,u16 id)106 static int qede_dcbnl_getapp(struct net_device *netdev, u8 idtype, u16 id)
107 {
108 	struct qede_dev *edev = netdev_priv(netdev);
109 
110 	return edev->ops->dcb->getapp(edev->cdev, idtype, id);
111 }
112 
qede_dcbnl_getdcbx(struct net_device * netdev)113 static u8 qede_dcbnl_getdcbx(struct net_device *netdev)
114 {
115 	struct qede_dev *edev = netdev_priv(netdev);
116 
117 	return edev->ops->dcb->getdcbx(edev->cdev);
118 }
119 
qede_dcbnl_setpgtccfgtx(struct net_device * netdev,int prio,u8 pri_type,u8 pgid,u8 bw_pct,u8 up_map)120 static void qede_dcbnl_setpgtccfgtx(struct net_device *netdev, int prio,
121 				    u8 pri_type, u8 pgid, u8 bw_pct, u8 up_map)
122 {
123 	struct qede_dev *edev = netdev_priv(netdev);
124 
125 	return edev->ops->dcb->setpgtccfgtx(edev->cdev, prio, pri_type, pgid,
126 					    bw_pct, up_map);
127 }
128 
qede_dcbnl_setpgtccfgrx(struct net_device * netdev,int prio,u8 pri_type,u8 pgid,u8 bw_pct,u8 up_map)129 static void qede_dcbnl_setpgtccfgrx(struct net_device *netdev, int prio,
130 				    u8 pri_type, u8 pgid, u8 bw_pct, u8 up_map)
131 {
132 	struct qede_dev *edev = netdev_priv(netdev);
133 
134 	return edev->ops->dcb->setpgtccfgrx(edev->cdev, prio, pri_type, pgid,
135 					    bw_pct, up_map);
136 }
137 
qede_dcbnl_setpgbwgcfgtx(struct net_device * netdev,int pgid,u8 bw_pct)138 static void qede_dcbnl_setpgbwgcfgtx(struct net_device *netdev, int pgid,
139 				     u8 bw_pct)
140 {
141 	struct qede_dev *edev = netdev_priv(netdev);
142 
143 	return edev->ops->dcb->setpgbwgcfgtx(edev->cdev, pgid, bw_pct);
144 }
145 
qede_dcbnl_setpgbwgcfgrx(struct net_device * netdev,int pgid,u8 bw_pct)146 static void qede_dcbnl_setpgbwgcfgrx(struct net_device *netdev, int pgid,
147 				     u8 bw_pct)
148 {
149 	struct qede_dev *edev = netdev_priv(netdev);
150 
151 	return edev->ops->dcb->setpgbwgcfgrx(edev->cdev, pgid, bw_pct);
152 }
153 
qede_dcbnl_setall(struct net_device * netdev)154 static u8 qede_dcbnl_setall(struct net_device *netdev)
155 {
156 	struct qede_dev *edev = netdev_priv(netdev);
157 
158 	return edev->ops->dcb->setall(edev->cdev);
159 }
160 
qede_dcbnl_setnumtcs(struct net_device * netdev,int tcid,u8 num)161 static int qede_dcbnl_setnumtcs(struct net_device *netdev, int tcid, u8 num)
162 {
163 	struct qede_dev *edev = netdev_priv(netdev);
164 
165 	return edev->ops->dcb->setnumtcs(edev->cdev, tcid, num);
166 }
167 
qede_dcbnl_setpfcstate(struct net_device * netdev,u8 state)168 static void qede_dcbnl_setpfcstate(struct net_device *netdev, u8 state)
169 {
170 	struct qede_dev *edev = netdev_priv(netdev);
171 
172 	return edev->ops->dcb->setpfcstate(edev->cdev, state);
173 }
174 
qede_dcbnl_setapp(struct net_device * netdev,u8 idtype,u16 idval,u8 up)175 static int qede_dcbnl_setapp(struct net_device *netdev, u8 idtype, u16 idval,
176 			     u8 up)
177 {
178 	struct qede_dev *edev = netdev_priv(netdev);
179 
180 	return edev->ops->dcb->setapp(edev->cdev, idtype, idval, up);
181 }
182 
qede_dcbnl_setdcbx(struct net_device * netdev,u8 state)183 static u8 qede_dcbnl_setdcbx(struct net_device *netdev, u8 state)
184 {
185 	struct qede_dev *edev = netdev_priv(netdev);
186 
187 	return edev->ops->dcb->setdcbx(edev->cdev, state);
188 }
189 
qede_dcbnl_getfeatcfg(struct net_device * netdev,int featid,u8 * flags)190 static u8 qede_dcbnl_getfeatcfg(struct net_device *netdev, int featid,
191 				u8 *flags)
192 {
193 	struct qede_dev *edev = netdev_priv(netdev);
194 
195 	return edev->ops->dcb->getfeatcfg(edev->cdev, featid, flags);
196 }
197 
qede_dcbnl_setfeatcfg(struct net_device * netdev,int featid,u8 flags)198 static u8 qede_dcbnl_setfeatcfg(struct net_device *netdev, int featid, u8 flags)
199 {
200 	struct qede_dev *edev = netdev_priv(netdev);
201 
202 	return edev->ops->dcb->setfeatcfg(edev->cdev, featid, flags);
203 }
204 
qede_dcbnl_peer_getappinfo(struct net_device * netdev,struct dcb_peer_app_info * info,u16 * count)205 static int qede_dcbnl_peer_getappinfo(struct net_device *netdev,
206 				      struct dcb_peer_app_info *info,
207 				      u16 *count)
208 {
209 	struct qede_dev *edev = netdev_priv(netdev);
210 
211 	return edev->ops->dcb->peer_getappinfo(edev->cdev, info, count);
212 }
213 
qede_dcbnl_peer_getapptable(struct net_device * netdev,struct dcb_app * app)214 static int qede_dcbnl_peer_getapptable(struct net_device *netdev,
215 				       struct dcb_app *app)
216 {
217 	struct qede_dev *edev = netdev_priv(netdev);
218 
219 	return edev->ops->dcb->peer_getapptable(edev->cdev, app);
220 }
221 
qede_dcbnl_cee_peer_getpfc(struct net_device * netdev,struct cee_pfc * pfc)222 static int qede_dcbnl_cee_peer_getpfc(struct net_device *netdev,
223 				      struct cee_pfc *pfc)
224 {
225 	struct qede_dev *edev = netdev_priv(netdev);
226 
227 	return edev->ops->dcb->cee_peer_getpfc(edev->cdev, pfc);
228 }
229 
qede_dcbnl_cee_peer_getpg(struct net_device * netdev,struct cee_pg * pg)230 static int qede_dcbnl_cee_peer_getpg(struct net_device *netdev,
231 				     struct cee_pg *pg)
232 {
233 	struct qede_dev *edev = netdev_priv(netdev);
234 
235 	return edev->ops->dcb->cee_peer_getpg(edev->cdev, pg);
236 }
237 
qede_dcbnl_ieee_getpfc(struct net_device * netdev,struct ieee_pfc * pfc)238 static int qede_dcbnl_ieee_getpfc(struct net_device *netdev,
239 				  struct ieee_pfc *pfc)
240 {
241 	struct qede_dev *edev = netdev_priv(netdev);
242 
243 	return edev->ops->dcb->ieee_getpfc(edev->cdev, pfc);
244 }
245 
qede_dcbnl_ieee_setpfc(struct net_device * netdev,struct ieee_pfc * pfc)246 static int qede_dcbnl_ieee_setpfc(struct net_device *netdev,
247 				  struct ieee_pfc *pfc)
248 {
249 	struct qede_dev *edev = netdev_priv(netdev);
250 
251 	return edev->ops->dcb->ieee_setpfc(edev->cdev, pfc);
252 }
253 
qede_dcbnl_ieee_getets(struct net_device * netdev,struct ieee_ets * ets)254 static int qede_dcbnl_ieee_getets(struct net_device *netdev,
255 				  struct ieee_ets *ets)
256 {
257 	struct qede_dev *edev = netdev_priv(netdev);
258 
259 	return edev->ops->dcb->ieee_getets(edev->cdev, ets);
260 }
261 
qede_dcbnl_ieee_setets(struct net_device * netdev,struct ieee_ets * ets)262 static int qede_dcbnl_ieee_setets(struct net_device *netdev,
263 				  struct ieee_ets *ets)
264 {
265 	struct qede_dev *edev = netdev_priv(netdev);
266 
267 	return edev->ops->dcb->ieee_setets(edev->cdev, ets);
268 }
269 
qede_dcbnl_ieee_getapp(struct net_device * netdev,struct dcb_app * app)270 static int qede_dcbnl_ieee_getapp(struct net_device *netdev,
271 				  struct dcb_app *app)
272 {
273 	struct qede_dev *edev = netdev_priv(netdev);
274 
275 	return edev->ops->dcb->ieee_getapp(edev->cdev, app);
276 }
277 
qede_dcbnl_ieee_setapp(struct net_device * netdev,struct dcb_app * app)278 static int qede_dcbnl_ieee_setapp(struct net_device *netdev,
279 				  struct dcb_app *app)
280 {
281 	struct qede_dev *edev = netdev_priv(netdev);
282 	int err;
283 
284 	err = dcb_ieee_setapp(netdev, app);
285 	if (err)
286 		return err;
287 
288 	return edev->ops->dcb->ieee_setapp(edev->cdev, app);
289 }
290 
qede_dcbnl_ieee_peer_getpfc(struct net_device * netdev,struct ieee_pfc * pfc)291 static int qede_dcbnl_ieee_peer_getpfc(struct net_device *netdev,
292 				       struct ieee_pfc *pfc)
293 {
294 	struct qede_dev *edev = netdev_priv(netdev);
295 
296 	return edev->ops->dcb->ieee_peer_getpfc(edev->cdev, pfc);
297 }
298 
qede_dcbnl_ieee_peer_getets(struct net_device * netdev,struct ieee_ets * ets)299 static int qede_dcbnl_ieee_peer_getets(struct net_device *netdev,
300 				       struct ieee_ets *ets)
301 {
302 	struct qede_dev *edev = netdev_priv(netdev);
303 
304 	return edev->ops->dcb->ieee_peer_getets(edev->cdev, ets);
305 }
306 
307 static const struct dcbnl_rtnl_ops qede_dcbnl_ops = {
308 	.ieee_getpfc = qede_dcbnl_ieee_getpfc,
309 	.ieee_setpfc = qede_dcbnl_ieee_setpfc,
310 	.ieee_getets = qede_dcbnl_ieee_getets,
311 	.ieee_setets = qede_dcbnl_ieee_setets,
312 	.ieee_getapp = qede_dcbnl_ieee_getapp,
313 	.ieee_setapp = qede_dcbnl_ieee_setapp,
314 	.ieee_peer_getpfc = qede_dcbnl_ieee_peer_getpfc,
315 	.ieee_peer_getets = qede_dcbnl_ieee_peer_getets,
316 	.getstate = qede_dcbnl_getstate,
317 	.setstate = qede_dcbnl_setstate,
318 	.getpermhwaddr = qede_dcbnl_getpermhwaddr,
319 	.getpgtccfgtx = qede_dcbnl_getpgtccfgtx,
320 	.getpgbwgcfgtx = qede_dcbnl_getpgbwgcfgtx,
321 	.getpgtccfgrx = qede_dcbnl_getpgtccfgrx,
322 	.getpgbwgcfgrx = qede_dcbnl_getpgbwgcfgrx,
323 	.getpfccfg = qede_dcbnl_getpfccfg,
324 	.setpfccfg = qede_dcbnl_setpfccfg,
325 	.getcap = qede_dcbnl_getcap,
326 	.getnumtcs = qede_dcbnl_getnumtcs,
327 	.getpfcstate = qede_dcbnl_getpfcstate,
328 	.getapp = qede_dcbnl_getapp,
329 	.getdcbx = qede_dcbnl_getdcbx,
330 	.setpgtccfgtx = qede_dcbnl_setpgtccfgtx,
331 	.setpgtccfgrx = qede_dcbnl_setpgtccfgrx,
332 	.setpgbwgcfgtx = qede_dcbnl_setpgbwgcfgtx,
333 	.setpgbwgcfgrx = qede_dcbnl_setpgbwgcfgrx,
334 	.setall = qede_dcbnl_setall,
335 	.setnumtcs = qede_dcbnl_setnumtcs,
336 	.setpfcstate = qede_dcbnl_setpfcstate,
337 	.setapp = qede_dcbnl_setapp,
338 	.setdcbx = qede_dcbnl_setdcbx,
339 	.setfeatcfg = qede_dcbnl_setfeatcfg,
340 	.getfeatcfg = qede_dcbnl_getfeatcfg,
341 	.peer_getappinfo = qede_dcbnl_peer_getappinfo,
342 	.peer_getapptable = qede_dcbnl_peer_getapptable,
343 	.cee_peer_getpfc = qede_dcbnl_cee_peer_getpfc,
344 	.cee_peer_getpg = qede_dcbnl_cee_peer_getpg,
345 };
346 
qede_set_dcbnl_ops(struct net_device * dev)347 void qede_set_dcbnl_ops(struct net_device *dev)
348 {
349 	dev->dcbnl_ops = &qede_dcbnl_ops;
350 }
351