Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * AMD 10Gb Ethernet driver
0003  *
0004  * This file is available to you under your choice of the following two
0005  * licenses:
0006  *
0007  * License 1: GPLv2
0008  *
0009  * Copyright (c) 2014 Advanced Micro Devices, Inc.
0010  *
0011  * This file is free software; you may copy, redistribute and/or modify
0012  * it under the terms of the GNU General Public License as published by
0013  * the Free Software Foundation, either version 2 of the License, or (at
0014  * your option) any later version.
0015  *
0016  * This file is distributed in the hope that it will be useful, but
0017  * WITHOUT ANY WARRANTY; without even the implied warranty of
0018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0019  * General Public License for more details.
0020  *
0021  * You should have received a copy of the GNU General Public License
0022  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0023  *
0024  * This file incorporates work covered by the following copyright and
0025  * permission notice:
0026  *     The Synopsys DWC ETHER XGMAC Software Driver and documentation
0027  *     (hereinafter "Software") is an unsupported proprietary work of Synopsys,
0028  *     Inc. unless otherwise expressly agreed to in writing between Synopsys
0029  *     and you.
0030  *
0031  *     The Software IS NOT an item of Licensed Software or Licensed Product
0032  *     under any End User Software License Agreement or Agreement for Licensed
0033  *     Product with Synopsys or any supplement thereto.  Permission is hereby
0034  *     granted, free of charge, to any person obtaining a copy of this software
0035  *     annotated with this license and the Software, to deal in the Software
0036  *     without restriction, including without limitation the rights to use,
0037  *     copy, modify, merge, publish, distribute, sublicense, and/or sell copies
0038  *     of the Software, and to permit persons to whom the Software is furnished
0039  *     to do so, subject to the following conditions:
0040  *
0041  *     The above copyright notice and this permission notice shall be included
0042  *     in all copies or substantial portions of the Software.
0043  *
0044  *     THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
0045  *     BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
0046  *     TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
0047  *     PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS
0048  *     BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0049  *     CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0050  *     SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0051  *     INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0052  *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0053  *     ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
0054  *     THE POSSIBILITY OF SUCH DAMAGE.
0055  *
0056  *
0057  * License 2: Modified BSD
0058  *
0059  * Copyright (c) 2014 Advanced Micro Devices, Inc.
0060  * All rights reserved.
0061  *
0062  * Redistribution and use in source and binary forms, with or without
0063  * modification, are permitted provided that the following conditions are met:
0064  *     * Redistributions of source code must retain the above copyright
0065  *       notice, this list of conditions and the following disclaimer.
0066  *     * Redistributions in binary form must reproduce the above copyright
0067  *       notice, this list of conditions and the following disclaimer in the
0068  *       documentation and/or other materials provided with the distribution.
0069  *     * Neither the name of Advanced Micro Devices, Inc. nor the
0070  *       names of its contributors may be used to endorse or promote products
0071  *       derived from this software without specific prior written permission.
0072  *
0073  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0074  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0075  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0076  * ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
0077  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
0078  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
0079  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
0080  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0081  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
0082  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0083  *
0084  * This file incorporates work covered by the following copyright and
0085  * permission notice:
0086  *     The Synopsys DWC ETHER XGMAC Software Driver and documentation
0087  *     (hereinafter "Software") is an unsupported proprietary work of Synopsys,
0088  *     Inc. unless otherwise expressly agreed to in writing between Synopsys
0089  *     and you.
0090  *
0091  *     The Software IS NOT an item of Licensed Software or Licensed Product
0092  *     under any End User Software License Agreement or Agreement for Licensed
0093  *     Product with Synopsys or any supplement thereto.  Permission is hereby
0094  *     granted, free of charge, to any person obtaining a copy of this software
0095  *     annotated with this license and the Software, to deal in the Software
0096  *     without restriction, including without limitation the rights to use,
0097  *     copy, modify, merge, publish, distribute, sublicense, and/or sell copies
0098  *     of the Software, and to permit persons to whom the Software is furnished
0099  *     to do so, subject to the following conditions:
0100  *
0101  *     The above copyright notice and this permission notice shall be included
0102  *     in all copies or substantial portions of the Software.
0103  *
0104  *     THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
0105  *     BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
0106  *     TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
0107  *     PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS
0108  *     BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0109  *     CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0110  *     SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0111  *     INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0112  *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0113  *     ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
0114  *     THE POSSIBILITY OF SUCH DAMAGE.
0115  */
0116 
0117 #include <linux/debugfs.h>
0118 #include <linux/module.h>
0119 #include <linux/slab.h>
0120 
0121 #include "xgbe.h"
0122 #include "xgbe-common.h"
0123 
0124 static ssize_t xgbe_common_read(char __user *buffer, size_t count,
0125                 loff_t *ppos, unsigned int value)
0126 {
0127     char *buf;
0128     ssize_t len;
0129 
0130     if (*ppos != 0)
0131         return 0;
0132 
0133     buf = kasprintf(GFP_KERNEL, "0x%08x\n", value);
0134     if (!buf)
0135         return -ENOMEM;
0136 
0137     if (count < strlen(buf)) {
0138         kfree(buf);
0139         return -ENOSPC;
0140     }
0141 
0142     len = simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
0143     kfree(buf);
0144 
0145     return len;
0146 }
0147 
0148 static ssize_t xgbe_common_write(const char __user *buffer, size_t count,
0149                  loff_t *ppos, unsigned int *value)
0150 {
0151     char workarea[32];
0152     ssize_t len;
0153     int ret;
0154 
0155     if (*ppos != 0)
0156         return -EINVAL;
0157 
0158     if (count >= sizeof(workarea))
0159         return -ENOSPC;
0160 
0161     len = simple_write_to_buffer(workarea, sizeof(workarea) - 1, ppos,
0162                      buffer, count);
0163     if (len < 0)
0164         return len;
0165 
0166     workarea[len] = '\0';
0167     ret = kstrtouint(workarea, 16, value);
0168     if (ret)
0169         return -EIO;
0170 
0171     return len;
0172 }
0173 
0174 static ssize_t xgmac_reg_addr_read(struct file *filp, char __user *buffer,
0175                    size_t count, loff_t *ppos)
0176 {
0177     struct xgbe_prv_data *pdata = filp->private_data;
0178 
0179     return xgbe_common_read(buffer, count, ppos, pdata->debugfs_xgmac_reg);
0180 }
0181 
0182 static ssize_t xgmac_reg_addr_write(struct file *filp,
0183                     const char __user *buffer,
0184                     size_t count, loff_t *ppos)
0185 {
0186     struct xgbe_prv_data *pdata = filp->private_data;
0187 
0188     return xgbe_common_write(buffer, count, ppos,
0189                  &pdata->debugfs_xgmac_reg);
0190 }
0191 
0192 static ssize_t xgmac_reg_value_read(struct file *filp, char __user *buffer,
0193                     size_t count, loff_t *ppos)
0194 {
0195     struct xgbe_prv_data *pdata = filp->private_data;
0196     unsigned int value;
0197 
0198     value = XGMAC_IOREAD(pdata, pdata->debugfs_xgmac_reg);
0199 
0200     return xgbe_common_read(buffer, count, ppos, value);
0201 }
0202 
0203 static ssize_t xgmac_reg_value_write(struct file *filp,
0204                      const char __user *buffer,
0205                      size_t count, loff_t *ppos)
0206 {
0207     struct xgbe_prv_data *pdata = filp->private_data;
0208     unsigned int value;
0209     ssize_t len;
0210 
0211     len = xgbe_common_write(buffer, count, ppos, &value);
0212     if (len < 0)
0213         return len;
0214 
0215     XGMAC_IOWRITE(pdata, pdata->debugfs_xgmac_reg, value);
0216 
0217     return len;
0218 }
0219 
0220 static const struct file_operations xgmac_reg_addr_fops = {
0221     .owner = THIS_MODULE,
0222     .open = simple_open,
0223     .read =  xgmac_reg_addr_read,
0224     .write = xgmac_reg_addr_write,
0225 };
0226 
0227 static const struct file_operations xgmac_reg_value_fops = {
0228     .owner = THIS_MODULE,
0229     .open = simple_open,
0230     .read =  xgmac_reg_value_read,
0231     .write = xgmac_reg_value_write,
0232 };
0233 
0234 static ssize_t xpcs_mmd_read(struct file *filp, char __user *buffer,
0235                  size_t count, loff_t *ppos)
0236 {
0237     struct xgbe_prv_data *pdata = filp->private_data;
0238 
0239     return xgbe_common_read(buffer, count, ppos, pdata->debugfs_xpcs_mmd);
0240 }
0241 
0242 static ssize_t xpcs_mmd_write(struct file *filp, const char __user *buffer,
0243                   size_t count, loff_t *ppos)
0244 {
0245     struct xgbe_prv_data *pdata = filp->private_data;
0246 
0247     return xgbe_common_write(buffer, count, ppos,
0248                  &pdata->debugfs_xpcs_mmd);
0249 }
0250 
0251 static ssize_t xpcs_reg_addr_read(struct file *filp, char __user *buffer,
0252                   size_t count, loff_t *ppos)
0253 {
0254     struct xgbe_prv_data *pdata = filp->private_data;
0255 
0256     return xgbe_common_read(buffer, count, ppos, pdata->debugfs_xpcs_reg);
0257 }
0258 
0259 static ssize_t xpcs_reg_addr_write(struct file *filp, const char __user *buffer,
0260                    size_t count, loff_t *ppos)
0261 {
0262     struct xgbe_prv_data *pdata = filp->private_data;
0263 
0264     return xgbe_common_write(buffer, count, ppos,
0265                  &pdata->debugfs_xpcs_reg);
0266 }
0267 
0268 static ssize_t xpcs_reg_value_read(struct file *filp, char __user *buffer,
0269                    size_t count, loff_t *ppos)
0270 {
0271     struct xgbe_prv_data *pdata = filp->private_data;
0272     unsigned int value;
0273 
0274     value = XMDIO_READ(pdata, pdata->debugfs_xpcs_mmd,
0275                pdata->debugfs_xpcs_reg);
0276 
0277     return xgbe_common_read(buffer, count, ppos, value);
0278 }
0279 
0280 static ssize_t xpcs_reg_value_write(struct file *filp,
0281                     const char __user *buffer,
0282                     size_t count, loff_t *ppos)
0283 {
0284     struct xgbe_prv_data *pdata = filp->private_data;
0285     unsigned int value;
0286     ssize_t len;
0287 
0288     len = xgbe_common_write(buffer, count, ppos, &value);
0289     if (len < 0)
0290         return len;
0291 
0292     XMDIO_WRITE(pdata, pdata->debugfs_xpcs_mmd, pdata->debugfs_xpcs_reg,
0293             value);
0294 
0295     return len;
0296 }
0297 
0298 static const struct file_operations xpcs_mmd_fops = {
0299     .owner = THIS_MODULE,
0300     .open = simple_open,
0301     .read =  xpcs_mmd_read,
0302     .write = xpcs_mmd_write,
0303 };
0304 
0305 static const struct file_operations xpcs_reg_addr_fops = {
0306     .owner = THIS_MODULE,
0307     .open = simple_open,
0308     .read =  xpcs_reg_addr_read,
0309     .write = xpcs_reg_addr_write,
0310 };
0311 
0312 static const struct file_operations xpcs_reg_value_fops = {
0313     .owner = THIS_MODULE,
0314     .open = simple_open,
0315     .read =  xpcs_reg_value_read,
0316     .write = xpcs_reg_value_write,
0317 };
0318 
0319 static ssize_t xprop_reg_addr_read(struct file *filp, char __user *buffer,
0320                    size_t count, loff_t *ppos)
0321 {
0322     struct xgbe_prv_data *pdata = filp->private_data;
0323 
0324     return xgbe_common_read(buffer, count, ppos, pdata->debugfs_xprop_reg);
0325 }
0326 
0327 static ssize_t xprop_reg_addr_write(struct file *filp,
0328                     const char __user *buffer,
0329                     size_t count, loff_t *ppos)
0330 {
0331     struct xgbe_prv_data *pdata = filp->private_data;
0332 
0333     return xgbe_common_write(buffer, count, ppos,
0334                  &pdata->debugfs_xprop_reg);
0335 }
0336 
0337 static ssize_t xprop_reg_value_read(struct file *filp, char __user *buffer,
0338                     size_t count, loff_t *ppos)
0339 {
0340     struct xgbe_prv_data *pdata = filp->private_data;
0341     unsigned int value;
0342 
0343     value = XP_IOREAD(pdata, pdata->debugfs_xprop_reg);
0344 
0345     return xgbe_common_read(buffer, count, ppos, value);
0346 }
0347 
0348 static ssize_t xprop_reg_value_write(struct file *filp,
0349                      const char __user *buffer,
0350                      size_t count, loff_t *ppos)
0351 {
0352     struct xgbe_prv_data *pdata = filp->private_data;
0353     unsigned int value;
0354     ssize_t len;
0355 
0356     len = xgbe_common_write(buffer, count, ppos, &value);
0357     if (len < 0)
0358         return len;
0359 
0360     XP_IOWRITE(pdata, pdata->debugfs_xprop_reg, value);
0361 
0362     return len;
0363 }
0364 
0365 static const struct file_operations xprop_reg_addr_fops = {
0366     .owner = THIS_MODULE,
0367     .open = simple_open,
0368     .read =  xprop_reg_addr_read,
0369     .write = xprop_reg_addr_write,
0370 };
0371 
0372 static const struct file_operations xprop_reg_value_fops = {
0373     .owner = THIS_MODULE,
0374     .open = simple_open,
0375     .read =  xprop_reg_value_read,
0376     .write = xprop_reg_value_write,
0377 };
0378 
0379 static ssize_t xi2c_reg_addr_read(struct file *filp, char __user *buffer,
0380                   size_t count, loff_t *ppos)
0381 {
0382     struct xgbe_prv_data *pdata = filp->private_data;
0383 
0384     return xgbe_common_read(buffer, count, ppos, pdata->debugfs_xi2c_reg);
0385 }
0386 
0387 static ssize_t xi2c_reg_addr_write(struct file *filp,
0388                    const char __user *buffer,
0389                    size_t count, loff_t *ppos)
0390 {
0391     struct xgbe_prv_data *pdata = filp->private_data;
0392 
0393     return xgbe_common_write(buffer, count, ppos,
0394                  &pdata->debugfs_xi2c_reg);
0395 }
0396 
0397 static ssize_t xi2c_reg_value_read(struct file *filp, char __user *buffer,
0398                    size_t count, loff_t *ppos)
0399 {
0400     struct xgbe_prv_data *pdata = filp->private_data;
0401     unsigned int value;
0402 
0403     value = XI2C_IOREAD(pdata, pdata->debugfs_xi2c_reg);
0404 
0405     return xgbe_common_read(buffer, count, ppos, value);
0406 }
0407 
0408 static ssize_t xi2c_reg_value_write(struct file *filp,
0409                     const char __user *buffer,
0410                     size_t count, loff_t *ppos)
0411 {
0412     struct xgbe_prv_data *pdata = filp->private_data;
0413     unsigned int value;
0414     ssize_t len;
0415 
0416     len = xgbe_common_write(buffer, count, ppos, &value);
0417     if (len < 0)
0418         return len;
0419 
0420     XI2C_IOWRITE(pdata, pdata->debugfs_xi2c_reg, value);
0421 
0422     return len;
0423 }
0424 
0425 static const struct file_operations xi2c_reg_addr_fops = {
0426     .owner = THIS_MODULE,
0427     .open = simple_open,
0428     .read =  xi2c_reg_addr_read,
0429     .write = xi2c_reg_addr_write,
0430 };
0431 
0432 static const struct file_operations xi2c_reg_value_fops = {
0433     .owner = THIS_MODULE,
0434     .open = simple_open,
0435     .read =  xi2c_reg_value_read,
0436     .write = xi2c_reg_value_write,
0437 };
0438 
0439 void xgbe_debugfs_init(struct xgbe_prv_data *pdata)
0440 {
0441     char *buf;
0442 
0443     /* Set defaults */
0444     pdata->debugfs_xgmac_reg = 0;
0445     pdata->debugfs_xpcs_mmd = 1;
0446     pdata->debugfs_xpcs_reg = 0;
0447 
0448     buf = kasprintf(GFP_KERNEL, "amd-xgbe-%s", pdata->netdev->name);
0449     if (!buf)
0450         return;
0451 
0452     pdata->xgbe_debugfs = debugfs_create_dir(buf, NULL);
0453 
0454     debugfs_create_file("xgmac_register", 0600, pdata->xgbe_debugfs, pdata,
0455                 &xgmac_reg_addr_fops);
0456 
0457     debugfs_create_file("xgmac_register_value", 0600, pdata->xgbe_debugfs,
0458                 pdata, &xgmac_reg_value_fops);
0459 
0460     debugfs_create_file("xpcs_mmd", 0600, pdata->xgbe_debugfs, pdata,
0461                 &xpcs_mmd_fops);
0462 
0463     debugfs_create_file("xpcs_register", 0600, pdata->xgbe_debugfs, pdata,
0464                 &xpcs_reg_addr_fops);
0465 
0466     debugfs_create_file("xpcs_register_value", 0600, pdata->xgbe_debugfs,
0467                 pdata, &xpcs_reg_value_fops);
0468 
0469     if (pdata->xprop_regs) {
0470         debugfs_create_file("xprop_register", 0600, pdata->xgbe_debugfs,
0471                     pdata, &xprop_reg_addr_fops);
0472 
0473         debugfs_create_file("xprop_register_value", 0600,
0474                     pdata->xgbe_debugfs, pdata,
0475                     &xprop_reg_value_fops);
0476     }
0477 
0478     if (pdata->xi2c_regs) {
0479         debugfs_create_file("xi2c_register", 0600, pdata->xgbe_debugfs,
0480                     pdata, &xi2c_reg_addr_fops);
0481 
0482         debugfs_create_file("xi2c_register_value", 0600,
0483                     pdata->xgbe_debugfs, pdata,
0484                     &xi2c_reg_value_fops);
0485     }
0486 
0487     if (pdata->vdata->an_cdr_workaround) {
0488         debugfs_create_bool("an_cdr_workaround", 0600,
0489                     pdata->xgbe_debugfs,
0490                     &pdata->debugfs_an_cdr_workaround);
0491 
0492         debugfs_create_bool("an_cdr_track_early", 0600,
0493                     pdata->xgbe_debugfs,
0494                     &pdata->debugfs_an_cdr_track_early);
0495     }
0496 
0497     kfree(buf);
0498 }
0499 
0500 void xgbe_debugfs_exit(struct xgbe_prv_data *pdata)
0501 {
0502     debugfs_remove_recursive(pdata->xgbe_debugfs);
0503     pdata->xgbe_debugfs = NULL;
0504 }
0505 
0506 void xgbe_debugfs_rename(struct xgbe_prv_data *pdata)
0507 {
0508     char *buf;
0509 
0510     if (!pdata->xgbe_debugfs)
0511         return;
0512 
0513     buf = kasprintf(GFP_KERNEL, "amd-xgbe-%s", pdata->netdev->name);
0514     if (!buf)
0515         return;
0516 
0517     if (!strcmp(pdata->xgbe_debugfs->d_name.name, buf))
0518         goto out;
0519 
0520     debugfs_rename(pdata->xgbe_debugfs->d_parent, pdata->xgbe_debugfs,
0521                pdata->xgbe_debugfs->d_parent, buf);
0522 
0523 out:
0524     kfree(buf);
0525 }