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