]>
Commit | Line | Data |
---|---|---|
c5aa9e3b LT |
1 | /* |
2 | * AMD 10Gb Ethernet driver | |
3 | * | |
4 | * This file is available to you under your choice of the following two | |
5 | * licenses: | |
6 | * | |
7 | * License 1: GPLv2 | |
8 | * | |
9 | * Copyright (c) 2014 Advanced Micro Devices, Inc. | |
10 | * | |
11 | * This file is free software; you may copy, redistribute and/or modify | |
12 | * it under the terms of the GNU General Public License as published by | |
13 | * the Free Software Foundation, either version 2 of the License, or (at | |
14 | * your option) any later version. | |
15 | * | |
16 | * This file is distributed in the hope that it will be useful, but | |
17 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
19 | * General Public License for more details. | |
20 | * | |
21 | * You should have received a copy of the GNU General Public License | |
22 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
23 | * | |
24 | * This file incorporates work covered by the following copyright and | |
25 | * permission notice: | |
26 | * The Synopsys DWC ETHER XGMAC Software Driver and documentation | |
27 | * (hereinafter "Software") is an unsupported proprietary work of Synopsys, | |
28 | * Inc. unless otherwise expressly agreed to in writing between Synopsys | |
29 | * and you. | |
30 | * | |
31 | * The Software IS NOT an item of Licensed Software or Licensed Product | |
32 | * under any End User Software License Agreement or Agreement for Licensed | |
33 | * Product with Synopsys or any supplement thereto. Permission is hereby | |
34 | * granted, free of charge, to any person obtaining a copy of this software | |
35 | * annotated with this license and the Software, to deal in the Software | |
36 | * without restriction, including without limitation the rights to use, | |
37 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies | |
38 | * of the Software, and to permit persons to whom the Software is furnished | |
39 | * to do so, subject to the following conditions: | |
40 | * | |
41 | * The above copyright notice and this permission notice shall be included | |
42 | * in all copies or substantial portions of the Software. | |
43 | * | |
44 | * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" | |
45 | * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |
46 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | |
47 | * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS | |
48 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
49 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
50 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
51 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
52 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
53 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | |
54 | * THE POSSIBILITY OF SUCH DAMAGE. | |
55 | * | |
56 | * | |
57 | * License 2: Modified BSD | |
58 | * | |
59 | * Copyright (c) 2014 Advanced Micro Devices, Inc. | |
60 | * All rights reserved. | |
61 | * | |
62 | * Redistribution and use in source and binary forms, with or without | |
63 | * modification, are permitted provided that the following conditions are met: | |
64 | * * Redistributions of source code must retain the above copyright | |
65 | * notice, this list of conditions and the following disclaimer. | |
66 | * * Redistributions in binary form must reproduce the above copyright | |
67 | * notice, this list of conditions and the following disclaimer in the | |
68 | * documentation and/or other materials provided with the distribution. | |
69 | * * Neither the name of Advanced Micro Devices, Inc. nor the | |
70 | * names of its contributors may be used to endorse or promote products | |
71 | * derived from this software without specific prior written permission. | |
72 | * | |
73 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
74 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
75 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
76 | * ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY | |
77 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
78 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
79 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
80 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
81 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
82 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
83 | * | |
84 | * This file incorporates work covered by the following copyright and | |
85 | * permission notice: | |
86 | * The Synopsys DWC ETHER XGMAC Software Driver and documentation | |
87 | * (hereinafter "Software") is an unsupported proprietary work of Synopsys, | |
88 | * Inc. unless otherwise expressly agreed to in writing between Synopsys | |
89 | * and you. | |
90 | * | |
91 | * The Software IS NOT an item of Licensed Software or Licensed Product | |
92 | * under any End User Software License Agreement or Agreement for Licensed | |
93 | * Product with Synopsys or any supplement thereto. Permission is hereby | |
94 | * granted, free of charge, to any person obtaining a copy of this software | |
95 | * annotated with this license and the Software, to deal in the Software | |
96 | * without restriction, including without limitation the rights to use, | |
97 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies | |
98 | * of the Software, and to permit persons to whom the Software is furnished | |
99 | * to do so, subject to the following conditions: | |
100 | * | |
101 | * The above copyright notice and this permission notice shall be included | |
102 | * in all copies or substantial portions of the Software. | |
103 | * | |
104 | * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" | |
105 | * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |
106 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | |
107 | * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS | |
108 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
109 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
110 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
111 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
112 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
113 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | |
114 | * THE POSSIBILITY OF SUCH DAMAGE. | |
115 | */ | |
116 | ||
117 | #include <linux/debugfs.h> | |
118 | #include <linux/module.h> | |
119 | #include <linux/slab.h> | |
120 | ||
121 | #include "xgbe.h" | |
122 | #include "xgbe-common.h" | |
123 | ||
c5aa9e3b LT |
124 | static ssize_t xgbe_common_read(char __user *buffer, size_t count, |
125 | loff_t *ppos, unsigned int value) | |
126 | { | |
127 | char *buf; | |
128 | ssize_t len; | |
129 | ||
130 | if (*ppos != 0) | |
131 | return 0; | |
132 | ||
133 | buf = kasprintf(GFP_KERNEL, "0x%08x\n", value); | |
134 | if (!buf) | |
135 | return -ENOMEM; | |
136 | ||
137 | if (count < strlen(buf)) { | |
138 | kfree(buf); | |
139 | return -ENOSPC; | |
140 | } | |
141 | ||
142 | len = simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf)); | |
143 | kfree(buf); | |
144 | ||
145 | return len; | |
146 | } | |
147 | ||
148 | static ssize_t xgbe_common_write(const char __user *buffer, size_t count, | |
149 | loff_t *ppos, unsigned int *value) | |
150 | { | |
151 | char workarea[32]; | |
152 | ssize_t len; | |
66f95c35 | 153 | int ret; |
c5aa9e3b LT |
154 | |
155 | if (*ppos != 0) | |
156 | return 0; | |
157 | ||
158 | if (count >= sizeof(workarea)) | |
159 | return -ENOSPC; | |
160 | ||
161 | len = simple_write_to_buffer(workarea, sizeof(workarea) - 1, ppos, | |
162 | buffer, count); | |
163 | if (len < 0) | |
164 | return len; | |
165 | ||
166 | workarea[len] = '\0'; | |
f3f128d4 | 167 | ret = kstrtouint(workarea, 16, value); |
66f95c35 | 168 | if (ret) |
f3f128d4 | 169 | return -EIO; |
c5aa9e3b LT |
170 | |
171 | return len; | |
172 | } | |
173 | ||
174 | static ssize_t xgmac_reg_addr_read(struct file *filp, char __user *buffer, | |
175 | size_t count, loff_t *ppos) | |
176 | { | |
177 | struct xgbe_prv_data *pdata = filp->private_data; | |
178 | ||
179 | return xgbe_common_read(buffer, count, ppos, pdata->debugfs_xgmac_reg); | |
180 | } | |
181 | ||
182 | static ssize_t xgmac_reg_addr_write(struct file *filp, | |
183 | const char __user *buffer, | |
184 | size_t count, loff_t *ppos) | |
185 | { | |
186 | struct xgbe_prv_data *pdata = filp->private_data; | |
187 | ||
188 | return xgbe_common_write(buffer, count, ppos, | |
189 | &pdata->debugfs_xgmac_reg); | |
190 | } | |
191 | ||
192 | static ssize_t xgmac_reg_value_read(struct file *filp, char __user *buffer, | |
193 | size_t count, loff_t *ppos) | |
194 | { | |
195 | struct xgbe_prv_data *pdata = filp->private_data; | |
196 | unsigned int value; | |
197 | ||
198 | value = XGMAC_IOREAD(pdata, pdata->debugfs_xgmac_reg); | |
199 | ||
200 | return xgbe_common_read(buffer, count, ppos, value); | |
201 | } | |
202 | ||
203 | static ssize_t xgmac_reg_value_write(struct file *filp, | |
204 | const char __user *buffer, | |
205 | size_t count, loff_t *ppos) | |
206 | { | |
207 | struct xgbe_prv_data *pdata = filp->private_data; | |
208 | unsigned int value; | |
209 | ssize_t len; | |
210 | ||
211 | len = xgbe_common_write(buffer, count, ppos, &value); | |
212 | if (len < 0) | |
213 | return len; | |
214 | ||
215 | XGMAC_IOWRITE(pdata, pdata->debugfs_xgmac_reg, value); | |
216 | ||
217 | return len; | |
218 | } | |
219 | ||
220 | static const struct file_operations xgmac_reg_addr_fops = { | |
221 | .owner = THIS_MODULE, | |
222 | .open = simple_open, | |
223 | .read = xgmac_reg_addr_read, | |
224 | .write = xgmac_reg_addr_write, | |
225 | }; | |
226 | ||
227 | static const struct file_operations xgmac_reg_value_fops = { | |
228 | .owner = THIS_MODULE, | |
229 | .open = simple_open, | |
230 | .read = xgmac_reg_value_read, | |
231 | .write = xgmac_reg_value_write, | |
232 | }; | |
233 | ||
234 | static ssize_t xpcs_mmd_read(struct file *filp, char __user *buffer, | |
235 | size_t count, loff_t *ppos) | |
236 | { | |
237 | struct xgbe_prv_data *pdata = filp->private_data; | |
238 | ||
239 | return xgbe_common_read(buffer, count, ppos, pdata->debugfs_xpcs_mmd); | |
240 | } | |
241 | ||
242 | static ssize_t xpcs_mmd_write(struct file *filp, const char __user *buffer, | |
243 | size_t count, loff_t *ppos) | |
244 | { | |
245 | struct xgbe_prv_data *pdata = filp->private_data; | |
246 | ||
247 | return xgbe_common_write(buffer, count, ppos, | |
248 | &pdata->debugfs_xpcs_mmd); | |
249 | } | |
250 | ||
251 | static ssize_t xpcs_reg_addr_read(struct file *filp, char __user *buffer, | |
252 | size_t count, loff_t *ppos) | |
253 | { | |
254 | struct xgbe_prv_data *pdata = filp->private_data; | |
255 | ||
256 | return xgbe_common_read(buffer, count, ppos, pdata->debugfs_xpcs_reg); | |
257 | } | |
258 | ||
259 | static ssize_t xpcs_reg_addr_write(struct file *filp, const char __user *buffer, | |
260 | size_t count, loff_t *ppos) | |
261 | { | |
262 | struct xgbe_prv_data *pdata = filp->private_data; | |
263 | ||
264 | return xgbe_common_write(buffer, count, ppos, | |
265 | &pdata->debugfs_xpcs_reg); | |
266 | } | |
267 | ||
268 | static ssize_t xpcs_reg_value_read(struct file *filp, char __user *buffer, | |
269 | size_t count, loff_t *ppos) | |
270 | { | |
271 | struct xgbe_prv_data *pdata = filp->private_data; | |
272 | unsigned int value; | |
273 | ||
625c8e4a LT |
274 | value = XMDIO_READ(pdata, pdata->debugfs_xpcs_mmd, |
275 | pdata->debugfs_xpcs_reg); | |
c5aa9e3b LT |
276 | |
277 | return xgbe_common_read(buffer, count, ppos, value); | |
278 | } | |
279 | ||
280 | static ssize_t xpcs_reg_value_write(struct file *filp, | |
281 | const char __user *buffer, | |
282 | size_t count, loff_t *ppos) | |
283 | { | |
284 | struct xgbe_prv_data *pdata = filp->private_data; | |
285 | unsigned int value; | |
286 | ssize_t len; | |
287 | ||
288 | len = xgbe_common_write(buffer, count, ppos, &value); | |
289 | if (len < 0) | |
290 | return len; | |
291 | ||
625c8e4a LT |
292 | XMDIO_WRITE(pdata, pdata->debugfs_xpcs_mmd, pdata->debugfs_xpcs_reg, |
293 | value); | |
c5aa9e3b LT |
294 | |
295 | return len; | |
296 | } | |
297 | ||
298 | static const struct file_operations xpcs_mmd_fops = { | |
299 | .owner = THIS_MODULE, | |
300 | .open = simple_open, | |
301 | .read = xpcs_mmd_read, | |
302 | .write = xpcs_mmd_write, | |
303 | }; | |
304 | ||
305 | static const struct file_operations xpcs_reg_addr_fops = { | |
306 | .owner = THIS_MODULE, | |
307 | .open = simple_open, | |
308 | .read = xpcs_reg_addr_read, | |
309 | .write = xpcs_reg_addr_write, | |
310 | }; | |
311 | ||
312 | static const struct file_operations xpcs_reg_value_fops = { | |
313 | .owner = THIS_MODULE, | |
314 | .open = simple_open, | |
315 | .read = xpcs_reg_value_read, | |
316 | .write = xpcs_reg_value_write, | |
317 | }; | |
318 | ||
47f164de LT |
319 | static ssize_t xprop_reg_addr_read(struct file *filp, char __user *buffer, |
320 | size_t count, loff_t *ppos) | |
321 | { | |
322 | struct xgbe_prv_data *pdata = filp->private_data; | |
323 | ||
324 | return xgbe_common_read(buffer, count, ppos, pdata->debugfs_xprop_reg); | |
325 | } | |
326 | ||
327 | static ssize_t xprop_reg_addr_write(struct file *filp, | |
328 | const char __user *buffer, | |
329 | size_t count, loff_t *ppos) | |
330 | { | |
331 | struct xgbe_prv_data *pdata = filp->private_data; | |
332 | ||
333 | return xgbe_common_write(buffer, count, ppos, | |
334 | &pdata->debugfs_xprop_reg); | |
335 | } | |
336 | ||
337 | static ssize_t xprop_reg_value_read(struct file *filp, char __user *buffer, | |
338 | size_t count, loff_t *ppos) | |
339 | { | |
340 | struct xgbe_prv_data *pdata = filp->private_data; | |
341 | unsigned int value; | |
342 | ||
343 | value = XP_IOREAD(pdata, pdata->debugfs_xprop_reg); | |
344 | ||
345 | return xgbe_common_read(buffer, count, ppos, value); | |
346 | } | |
347 | ||
348 | static ssize_t xprop_reg_value_write(struct file *filp, | |
349 | const char __user *buffer, | |
350 | size_t count, loff_t *ppos) | |
351 | { | |
352 | struct xgbe_prv_data *pdata = filp->private_data; | |
353 | unsigned int value; | |
354 | ssize_t len; | |
355 | ||
356 | len = xgbe_common_write(buffer, count, ppos, &value); | |
357 | if (len < 0) | |
358 | return len; | |
359 | ||
360 | XP_IOWRITE(pdata, pdata->debugfs_xprop_reg, value); | |
361 | ||
362 | return len; | |
363 | } | |
364 | ||
365 | static const struct file_operations xprop_reg_addr_fops = { | |
366 | .owner = THIS_MODULE, | |
367 | .open = simple_open, | |
368 | .read = xprop_reg_addr_read, | |
369 | .write = xprop_reg_addr_write, | |
370 | }; | |
371 | ||
372 | static const struct file_operations xprop_reg_value_fops = { | |
373 | .owner = THIS_MODULE, | |
374 | .open = simple_open, | |
375 | .read = xprop_reg_value_read, | |
376 | .write = xprop_reg_value_write, | |
377 | }; | |
378 | ||
c5aa9e3b LT |
379 | void xgbe_debugfs_init(struct xgbe_prv_data *pdata) |
380 | { | |
381 | struct dentry *pfile; | |
382 | char *buf; | |
383 | ||
384 | /* Set defaults */ | |
385 | pdata->debugfs_xgmac_reg = 0; | |
386 | pdata->debugfs_xpcs_mmd = 1; | |
387 | pdata->debugfs_xpcs_reg = 0; | |
388 | ||
389 | buf = kasprintf(GFP_KERNEL, "amd-xgbe-%s", pdata->netdev->name); | |
855591d2 TL |
390 | if (!buf) |
391 | return; | |
392 | ||
c5aa9e3b | 393 | pdata->xgbe_debugfs = debugfs_create_dir(buf, NULL); |
1d67d7f6 | 394 | if (!pdata->xgbe_debugfs) { |
c5aa9e3b | 395 | netdev_err(pdata->netdev, "debugfs_create_dir failed\n"); |
9dc80a74 | 396 | kfree(buf); |
c5aa9e3b LT |
397 | return; |
398 | } | |
399 | ||
400 | pfile = debugfs_create_file("xgmac_register", 0600, | |
401 | pdata->xgbe_debugfs, pdata, | |
402 | &xgmac_reg_addr_fops); | |
403 | if (!pfile) | |
404 | netdev_err(pdata->netdev, "debugfs_create_file failed\n"); | |
405 | ||
406 | pfile = debugfs_create_file("xgmac_register_value", 0600, | |
407 | pdata->xgbe_debugfs, pdata, | |
408 | &xgmac_reg_value_fops); | |
409 | if (!pfile) | |
410 | netdev_err(pdata->netdev, "debugfs_create_file failed\n"); | |
411 | ||
412 | pfile = debugfs_create_file("xpcs_mmd", 0600, | |
413 | pdata->xgbe_debugfs, pdata, | |
414 | &xpcs_mmd_fops); | |
415 | if (!pfile) | |
416 | netdev_err(pdata->netdev, "debugfs_create_file failed\n"); | |
417 | ||
418 | pfile = debugfs_create_file("xpcs_register", 0600, | |
419 | pdata->xgbe_debugfs, pdata, | |
420 | &xpcs_reg_addr_fops); | |
421 | if (!pfile) | |
422 | netdev_err(pdata->netdev, "debugfs_create_file failed\n"); | |
423 | ||
424 | pfile = debugfs_create_file("xpcs_register_value", 0600, | |
425 | pdata->xgbe_debugfs, pdata, | |
426 | &xpcs_reg_value_fops); | |
427 | if (!pfile) | |
428 | netdev_err(pdata->netdev, "debugfs_create_file failed\n"); | |
429 | ||
47f164de LT |
430 | if (pdata->xprop_regs) { |
431 | pfile = debugfs_create_file("xprop_register", 0600, | |
432 | pdata->xgbe_debugfs, pdata, | |
433 | &xprop_reg_addr_fops); | |
434 | if (!pfile) | |
435 | netdev_err(pdata->netdev, | |
436 | "debugfs_create_file failed\n"); | |
437 | ||
438 | pfile = debugfs_create_file("xprop_register_value", 0600, | |
439 | pdata->xgbe_debugfs, pdata, | |
440 | &xprop_reg_value_fops); | |
441 | if (!pfile) | |
442 | netdev_err(pdata->netdev, | |
443 | "debugfs_create_file failed\n"); | |
444 | } | |
445 | ||
c5aa9e3b LT |
446 | kfree(buf); |
447 | } | |
448 | ||
449 | void xgbe_debugfs_exit(struct xgbe_prv_data *pdata) | |
450 | { | |
451 | debugfs_remove_recursive(pdata->xgbe_debugfs); | |
452 | pdata->xgbe_debugfs = NULL; | |
453 | } |