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