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