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