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