Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 1 | /* |
| 2 | * AMD 10Gb Ethernet driver |
| 3 | * |
| 4 | * This file is available to you under your choice of the following two |
| 5 | * licenses: |
| 6 | * |
| 7 | * License 1: GPLv2 |
| 8 | * |
Lendacky, Thomas | ced3fca | 2016-02-17 11:49:28 -0600 | [diff] [blame] | 9 | * Copyright (c) 2014-2016 Advanced Micro Devices, Inc. |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 10 | * |
| 11 | * This file is free software; you may copy, redistribute and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation, either version 2 of the License, or (at |
| 14 | * your option) any later version. |
| 15 | * |
| 16 | * This file is distributed in the hope that it will be useful, but |
| 17 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 19 | * General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 23 | * |
| 24 | * This file incorporates work covered by the following copyright and |
| 25 | * permission notice: |
| 26 | * The Synopsys DWC ETHER XGMAC Software Driver and documentation |
| 27 | * (hereinafter "Software") is an unsupported proprietary work of Synopsys, |
| 28 | * Inc. unless otherwise expressly agreed to in writing between Synopsys |
| 29 | * and you. |
| 30 | * |
| 31 | * The Software IS NOT an item of Licensed Software or Licensed Product |
| 32 | * under any End User Software License Agreement or Agreement for Licensed |
| 33 | * Product with Synopsys or any supplement thereto. Permission is hereby |
| 34 | * granted, free of charge, to any person obtaining a copy of this software |
| 35 | * annotated with this license and the Software, to deal in the Software |
| 36 | * without restriction, including without limitation the rights to use, |
| 37 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies |
| 38 | * of the Software, and to permit persons to whom the Software is furnished |
| 39 | * to do so, subject to the following conditions: |
| 40 | * |
| 41 | * The above copyright notice and this permission notice shall be included |
| 42 | * in all copies or substantial portions of the Software. |
| 43 | * |
| 44 | * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" |
| 45 | * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
| 46 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
| 47 | * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS |
| 48 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 49 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 50 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 51 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 52 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 53 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 54 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 55 | * |
| 56 | * |
| 57 | * License 2: Modified BSD |
| 58 | * |
Lendacky, Thomas | ced3fca | 2016-02-17 11:49:28 -0600 | [diff] [blame] | 59 | * Copyright (c) 2014-2016 Advanced Micro Devices, Inc. |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 60 | * All rights reserved. |
| 61 | * |
| 62 | * Redistribution and use in source and binary forms, with or without |
| 63 | * modification, are permitted provided that the following conditions are met: |
| 64 | * * Redistributions of source code must retain the above copyright |
| 65 | * notice, this list of conditions and the following disclaimer. |
| 66 | * * Redistributions in binary form must reproduce the above copyright |
| 67 | * notice, this list of conditions and the following disclaimer in the |
| 68 | * documentation and/or other materials provided with the distribution. |
| 69 | * * Neither the name of Advanced Micro Devices, Inc. nor the |
| 70 | * names of its contributors may be used to endorse or promote products |
| 71 | * derived from this software without specific prior written permission. |
| 72 | * |
| 73 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 74 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 75 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 76 | * ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY |
| 77 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 78 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 79 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 80 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 81 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 82 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 83 | * |
| 84 | * This file incorporates work covered by the following copyright and |
| 85 | * permission notice: |
| 86 | * The Synopsys DWC ETHER XGMAC Software Driver and documentation |
| 87 | * (hereinafter "Software") is an unsupported proprietary work of Synopsys, |
| 88 | * Inc. unless otherwise expressly agreed to in writing between Synopsys |
| 89 | * and you. |
| 90 | * |
| 91 | * The Software IS NOT an item of Licensed Software or Licensed Product |
| 92 | * under any End User Software License Agreement or Agreement for Licensed |
| 93 | * Product with Synopsys or any supplement thereto. Permission is hereby |
| 94 | * granted, free of charge, to any person obtaining a copy of this software |
| 95 | * annotated with this license and the Software, to deal in the Software |
| 96 | * without restriction, including without limitation the rights to use, |
| 97 | * copy, modify, merge, publish, distribute, sublicense, and/or sell copies |
| 98 | * of the Software, and to permit persons to whom the Software is furnished |
| 99 | * to do so, subject to the following conditions: |
| 100 | * |
| 101 | * The above copyright notice and this permission notice shall be included |
| 102 | * in all copies or substantial portions of the Software. |
| 103 | * |
| 104 | * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" |
| 105 | * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
| 106 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
| 107 | * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS |
| 108 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 109 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 110 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 111 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 112 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 113 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 114 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 115 | */ |
| 116 | |
| 117 | #include <linux/module.h> |
| 118 | #include <linux/device.h> |
| 119 | #include <linux/platform_device.h> |
| 120 | #include <linux/spinlock.h> |
| 121 | #include <linux/netdevice.h> |
| 122 | #include <linux/etherdevice.h> |
| 123 | #include <linux/io.h> |
| 124 | #include <linux/of.h> |
| 125 | #include <linux/of_net.h> |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 126 | #include <linux/of_address.h> |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 127 | #include <linux/of_platform.h> |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 128 | #include <linux/clk.h> |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 129 | #include <linux/property.h> |
| 130 | #include <linux/acpi.h> |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 131 | #include <linux/mdio.h> |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 132 | |
| 133 | #include "xgbe.h" |
| 134 | #include "xgbe-common.h" |
| 135 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 136 | MODULE_AUTHOR("Tom Lendacky <thomas.lendacky@amd.com>"); |
| 137 | MODULE_LICENSE("Dual BSD/GPL"); |
| 138 | MODULE_VERSION(XGBE_DRV_VERSION); |
| 139 | MODULE_DESCRIPTION(XGBE_DRV_DESC); |
| 140 | |
Lendacky, Thomas | 34bf65d | 2015-05-14 11:44:03 -0500 | [diff] [blame] | 141 | static int debug = -1; |
| 142 | module_param(debug, int, S_IWUSR | S_IRUGO); |
| 143 | MODULE_PARM_DESC(debug, " Network interface message level setting"); |
| 144 | |
| 145 | static const u32 default_msg_level = (NETIF_MSG_LINK | NETIF_MSG_IFDOWN | |
| 146 | NETIF_MSG_IFUP); |
| 147 | |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 148 | static const u32 xgbe_serdes_blwc[] = { |
| 149 | XGBE_SPEED_1000_BLWC, |
| 150 | XGBE_SPEED_2500_BLWC, |
| 151 | XGBE_SPEED_10000_BLWC, |
| 152 | }; |
| 153 | |
| 154 | static const u32 xgbe_serdes_cdr_rate[] = { |
| 155 | XGBE_SPEED_1000_CDR, |
| 156 | XGBE_SPEED_2500_CDR, |
| 157 | XGBE_SPEED_10000_CDR, |
| 158 | }; |
| 159 | |
| 160 | static const u32 xgbe_serdes_pq_skew[] = { |
| 161 | XGBE_SPEED_1000_PQ, |
| 162 | XGBE_SPEED_2500_PQ, |
| 163 | XGBE_SPEED_10000_PQ, |
| 164 | }; |
| 165 | |
| 166 | static const u32 xgbe_serdes_tx_amp[] = { |
| 167 | XGBE_SPEED_1000_TXAMP, |
| 168 | XGBE_SPEED_2500_TXAMP, |
| 169 | XGBE_SPEED_10000_TXAMP, |
| 170 | }; |
| 171 | |
| 172 | static const u32 xgbe_serdes_dfe_tap_cfg[] = { |
| 173 | XGBE_SPEED_1000_DFE_TAP_CONFIG, |
| 174 | XGBE_SPEED_2500_DFE_TAP_CONFIG, |
| 175 | XGBE_SPEED_10000_DFE_TAP_CONFIG, |
| 176 | }; |
| 177 | |
| 178 | static const u32 xgbe_serdes_dfe_tap_ena[] = { |
| 179 | XGBE_SPEED_1000_DFE_TAP_ENABLE, |
| 180 | XGBE_SPEED_2500_DFE_TAP_ENABLE, |
| 181 | XGBE_SPEED_10000_DFE_TAP_ENABLE, |
| 182 | }; |
| 183 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 184 | static void xgbe_default_config(struct xgbe_prv_data *pdata) |
| 185 | { |
| 186 | DBGPR("-->xgbe_default_config\n"); |
| 187 | |
| 188 | pdata->pblx8 = DMA_PBL_X8_ENABLE; |
| 189 | pdata->tx_sf_mode = MTL_TSF_ENABLE; |
| 190 | pdata->tx_threshold = MTL_TX_THRESHOLD_64; |
| 191 | pdata->tx_pbl = DMA_PBL_16; |
| 192 | pdata->tx_osp_mode = DMA_OSP_ENABLE; |
| 193 | pdata->rx_sf_mode = MTL_RSF_DISABLE; |
| 194 | pdata->rx_threshold = MTL_RX_THRESHOLD_64; |
| 195 | pdata->rx_pbl = DMA_PBL_16; |
| 196 | pdata->pause_autoneg = 1; |
| 197 | pdata->tx_pause = 1; |
| 198 | pdata->rx_pause = 1; |
Lendacky, Thomas | 916102c | 2015-01-16 12:46:45 -0600 | [diff] [blame] | 199 | pdata->phy_speed = SPEED_UNKNOWN; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 200 | pdata->power_down = 0; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 201 | |
| 202 | DBGPR("<--xgbe_default_config\n"); |
| 203 | } |
| 204 | |
| 205 | static void xgbe_init_all_fptrs(struct xgbe_prv_data *pdata) |
| 206 | { |
| 207 | xgbe_init_function_ptrs_dev(&pdata->hw_if); |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 208 | xgbe_init_function_ptrs_phy(&pdata->phy_if); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 209 | xgbe_init_function_ptrs_desc(&pdata->desc_if); |
| 210 | } |
| 211 | |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 212 | #ifdef CONFIG_ACPI |
| 213 | static int xgbe_acpi_support(struct xgbe_prv_data *pdata) |
| 214 | { |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 215 | struct device *dev = pdata->dev; |
| 216 | u32 property; |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 217 | int ret; |
| 218 | |
| 219 | /* Obtain the system clock setting */ |
| 220 | ret = device_property_read_u32(dev, XGBE_ACPI_DMA_FREQ, &property); |
| 221 | if (ret) { |
| 222 | dev_err(dev, "unable to obtain %s property\n", |
| 223 | XGBE_ACPI_DMA_FREQ); |
| 224 | return ret; |
| 225 | } |
| 226 | pdata->sysclk_rate = property; |
| 227 | |
| 228 | /* Obtain the PTP clock setting */ |
| 229 | ret = device_property_read_u32(dev, XGBE_ACPI_PTP_FREQ, &property); |
| 230 | if (ret) { |
| 231 | dev_err(dev, "unable to obtain %s property\n", |
| 232 | XGBE_ACPI_PTP_FREQ); |
| 233 | return ret; |
| 234 | } |
| 235 | pdata->ptpclk_rate = property; |
| 236 | |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 237 | return 0; |
| 238 | } |
| 239 | #else /* CONFIG_ACPI */ |
| 240 | static int xgbe_acpi_support(struct xgbe_prv_data *pdata) |
| 241 | { |
| 242 | return -EINVAL; |
| 243 | } |
| 244 | #endif /* CONFIG_ACPI */ |
| 245 | |
| 246 | #ifdef CONFIG_OF |
| 247 | static int xgbe_of_support(struct xgbe_prv_data *pdata) |
| 248 | { |
| 249 | struct device *dev = pdata->dev; |
| 250 | |
| 251 | /* Obtain the system clock setting */ |
| 252 | pdata->sysclk = devm_clk_get(dev, XGBE_DMA_CLOCK); |
| 253 | if (IS_ERR(pdata->sysclk)) { |
| 254 | dev_err(dev, "dma devm_clk_get failed\n"); |
| 255 | return PTR_ERR(pdata->sysclk); |
| 256 | } |
| 257 | pdata->sysclk_rate = clk_get_rate(pdata->sysclk); |
| 258 | |
| 259 | /* Obtain the PTP clock setting */ |
| 260 | pdata->ptpclk = devm_clk_get(dev, XGBE_PTP_CLOCK); |
| 261 | if (IS_ERR(pdata->ptpclk)) { |
| 262 | dev_err(dev, "ptp devm_clk_get failed\n"); |
| 263 | return PTR_ERR(pdata->ptpclk); |
| 264 | } |
| 265 | pdata->ptpclk_rate = clk_get_rate(pdata->ptpclk); |
| 266 | |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 267 | return 0; |
| 268 | } |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 269 | |
| 270 | static struct platform_device *xgbe_of_get_phy_pdev(struct xgbe_prv_data *pdata) |
| 271 | { |
| 272 | struct device *dev = pdata->dev; |
| 273 | struct device_node *phy_node; |
| 274 | struct platform_device *phy_pdev; |
| 275 | |
| 276 | phy_node = of_parse_phandle(dev->of_node, "phy-handle", 0); |
Lendacky, Thomas | 34bfff4 | 2015-05-14 11:44:21 -0500 | [diff] [blame] | 277 | if (phy_node) { |
| 278 | /* Old style device tree: |
| 279 | * The XGBE and PHY resources are separate |
| 280 | */ |
| 281 | phy_pdev = of_find_device_by_node(phy_node); |
| 282 | of_node_put(phy_node); |
| 283 | } else { |
| 284 | /* New style device tree: |
| 285 | * The XGBE and PHY resources are grouped together with |
| 286 | * the PHY resources listed last |
| 287 | */ |
| 288 | get_device(dev); |
| 289 | phy_pdev = pdata->pdev; |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 290 | } |
| 291 | |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 292 | return phy_pdev; |
| 293 | } |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 294 | #else /* CONFIG_OF */ |
| 295 | static int xgbe_of_support(struct xgbe_prv_data *pdata) |
| 296 | { |
| 297 | return -EINVAL; |
| 298 | } |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 299 | |
| 300 | static struct platform_device *xgbe_of_get_phy_pdev(struct xgbe_prv_data *pdata) |
| 301 | { |
| 302 | return NULL; |
| 303 | } |
| 304 | #endif /* CONFIG_OF */ |
| 305 | |
| 306 | static unsigned int xgbe_resource_count(struct platform_device *pdev, |
| 307 | unsigned int type) |
| 308 | { |
| 309 | unsigned int count; |
| 310 | int i; |
| 311 | |
| 312 | for (i = 0, count = 0; i < pdev->num_resources; i++) { |
| 313 | struct resource *res = &pdev->resource[i]; |
| 314 | |
| 315 | if (type == resource_type(res)) |
| 316 | count++; |
| 317 | } |
| 318 | |
| 319 | return count; |
| 320 | } |
| 321 | |
| 322 | static struct platform_device *xgbe_get_phy_pdev(struct xgbe_prv_data *pdata) |
| 323 | { |
| 324 | struct platform_device *phy_pdev; |
| 325 | |
| 326 | if (pdata->use_acpi) { |
| 327 | get_device(pdata->dev); |
| 328 | phy_pdev = pdata->pdev; |
| 329 | } else { |
| 330 | phy_pdev = xgbe_of_get_phy_pdev(pdata); |
| 331 | } |
| 332 | |
| 333 | return phy_pdev; |
| 334 | } |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 335 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 336 | static int xgbe_probe(struct platform_device *pdev) |
| 337 | { |
| 338 | struct xgbe_prv_data *pdata; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 339 | struct net_device *netdev; |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 340 | struct device *dev = &pdev->dev, *phy_dev; |
| 341 | struct platform_device *phy_pdev; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 342 | struct resource *res; |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 343 | const char *phy_mode; |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 344 | unsigned int i, phy_memnum, phy_irqnum; |
Suthikulpanit, Suravee | 1831eff | 2015-10-28 15:50:50 -0700 | [diff] [blame] | 345 | enum dev_dma_attr attr; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 346 | int ret; |
| 347 | |
| 348 | DBGPR("--> xgbe_probe\n"); |
| 349 | |
| 350 | netdev = alloc_etherdev_mq(sizeof(struct xgbe_prv_data), |
Lendacky, Thomas | d5c4858 | 2014-06-09 09:19:32 -0500 | [diff] [blame] | 351 | XGBE_MAX_DMA_CHANNELS); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 352 | if (!netdev) { |
| 353 | dev_err(dev, "alloc_etherdev failed\n"); |
| 354 | ret = -ENOMEM; |
| 355 | goto err_alloc; |
| 356 | } |
| 357 | SET_NETDEV_DEV(netdev, dev); |
| 358 | pdata = netdev_priv(netdev); |
| 359 | pdata->netdev = netdev; |
| 360 | pdata->pdev = pdev; |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 361 | pdata->adev = ACPI_COMPANION(dev); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 362 | pdata->dev = dev; |
| 363 | platform_set_drvdata(pdev, netdev); |
| 364 | |
| 365 | spin_lock_init(&pdata->lock); |
Lendacky, Thomas | ced3fca | 2016-02-17 11:49:28 -0600 | [diff] [blame] | 366 | spin_lock_init(&pdata->xpcs_lock); |
Lendacky, Thomas | 5b9dfe2 | 2014-11-04 16:07:02 -0600 | [diff] [blame] | 367 | mutex_init(&pdata->rss_mutex); |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 368 | spin_lock_init(&pdata->tstamp_lock); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 369 | |
Lendacky, Thomas | 34bf65d | 2015-05-14 11:44:03 -0500 | [diff] [blame] | 370 | pdata->msg_enable = netif_msg_init(debug, default_msg_level); |
| 371 | |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 372 | set_bit(XGBE_DOWN, &pdata->dev_state); |
| 373 | |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 374 | /* Check if we should use ACPI or DT */ |
Lendacky, Thomas | 47f2e6c | 2015-09-30 08:52:45 -0500 | [diff] [blame] | 375 | pdata->use_acpi = dev->of_node ? 0 : 1; |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 376 | |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 377 | phy_pdev = xgbe_get_phy_pdev(pdata); |
| 378 | if (!phy_pdev) { |
| 379 | dev_err(dev, "unable to obtain phy device\n"); |
| 380 | ret = -EINVAL; |
| 381 | goto err_phydev; |
| 382 | } |
| 383 | phy_dev = &phy_pdev->dev; |
| 384 | |
| 385 | if (pdev == phy_pdev) { |
Lendacky, Thomas | 34bfff4 | 2015-05-14 11:44:21 -0500 | [diff] [blame] | 386 | /* New style device tree or ACPI: |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 387 | * The XGBE and PHY resources are grouped together with |
| 388 | * the PHY resources listed last |
| 389 | */ |
| 390 | phy_memnum = xgbe_resource_count(pdev, IORESOURCE_MEM) - 3; |
| 391 | phy_irqnum = xgbe_resource_count(pdev, IORESOURCE_IRQ) - 1; |
| 392 | } else { |
Lendacky, Thomas | 34bfff4 | 2015-05-14 11:44:21 -0500 | [diff] [blame] | 393 | /* Old style device tree: |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 394 | * The XGBE and PHY resources are separate |
| 395 | */ |
| 396 | phy_memnum = 0; |
| 397 | phy_irqnum = 0; |
| 398 | } |
| 399 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 400 | /* Set and validate the number of descriptors for a ring */ |
Lendacky, Thomas | d0a8ba6 | 2014-06-24 16:19:06 -0500 | [diff] [blame] | 401 | BUILD_BUG_ON_NOT_POWER_OF_2(XGBE_TX_DESC_CNT); |
| 402 | pdata->tx_desc_count = XGBE_TX_DESC_CNT; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 403 | if (pdata->tx_desc_count & (pdata->tx_desc_count - 1)) { |
| 404 | dev_err(dev, "tx descriptor count (%d) is not valid\n", |
| 405 | pdata->tx_desc_count); |
| 406 | ret = -EINVAL; |
| 407 | goto err_io; |
| 408 | } |
Lendacky, Thomas | d0a8ba6 | 2014-06-24 16:19:06 -0500 | [diff] [blame] | 409 | BUILD_BUG_ON_NOT_POWER_OF_2(XGBE_RX_DESC_CNT); |
| 410 | pdata->rx_desc_count = XGBE_RX_DESC_CNT; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 411 | if (pdata->rx_desc_count & (pdata->rx_desc_count - 1)) { |
| 412 | dev_err(dev, "rx descriptor count (%d) is not valid\n", |
| 413 | pdata->rx_desc_count); |
| 414 | ret = -EINVAL; |
| 415 | goto err_io; |
| 416 | } |
| 417 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 418 | /* Obtain the mmio areas for the device */ |
| 419 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 420 | pdata->xgmac_regs = devm_ioremap_resource(dev, res); |
| 421 | if (IS_ERR(pdata->xgmac_regs)) { |
| 422 | dev_err(dev, "xgmac ioremap failed\n"); |
| 423 | ret = PTR_ERR(pdata->xgmac_regs); |
| 424 | goto err_io; |
| 425 | } |
Lendacky, Thomas | 34bf65d | 2015-05-14 11:44:03 -0500 | [diff] [blame] | 426 | if (netif_msg_probe(pdata)) |
| 427 | dev_dbg(dev, "xgmac_regs = %p\n", pdata->xgmac_regs); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 428 | |
| 429 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
| 430 | pdata->xpcs_regs = devm_ioremap_resource(dev, res); |
| 431 | if (IS_ERR(pdata->xpcs_regs)) { |
| 432 | dev_err(dev, "xpcs ioremap failed\n"); |
| 433 | ret = PTR_ERR(pdata->xpcs_regs); |
| 434 | goto err_io; |
| 435 | } |
Lendacky, Thomas | 34bf65d | 2015-05-14 11:44:03 -0500 | [diff] [blame] | 436 | if (netif_msg_probe(pdata)) |
| 437 | dev_dbg(dev, "xpcs_regs = %p\n", pdata->xpcs_regs); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 438 | |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 439 | res = platform_get_resource(phy_pdev, IORESOURCE_MEM, phy_memnum++); |
| 440 | pdata->rxtx_regs = devm_ioremap_resource(dev, res); |
| 441 | if (IS_ERR(pdata->rxtx_regs)) { |
| 442 | dev_err(dev, "rxtx ioremap failed\n"); |
| 443 | ret = PTR_ERR(pdata->rxtx_regs); |
| 444 | goto err_io; |
| 445 | } |
| 446 | if (netif_msg_probe(pdata)) |
| 447 | dev_dbg(dev, "rxtx_regs = %p\n", pdata->rxtx_regs); |
| 448 | |
| 449 | res = platform_get_resource(phy_pdev, IORESOURCE_MEM, phy_memnum++); |
| 450 | pdata->sir0_regs = devm_ioremap_resource(dev, res); |
| 451 | if (IS_ERR(pdata->sir0_regs)) { |
| 452 | dev_err(dev, "sir0 ioremap failed\n"); |
| 453 | ret = PTR_ERR(pdata->sir0_regs); |
| 454 | goto err_io; |
| 455 | } |
| 456 | if (netif_msg_probe(pdata)) |
| 457 | dev_dbg(dev, "sir0_regs = %p\n", pdata->sir0_regs); |
| 458 | |
| 459 | res = platform_get_resource(phy_pdev, IORESOURCE_MEM, phy_memnum++); |
| 460 | pdata->sir1_regs = devm_ioremap_resource(dev, res); |
| 461 | if (IS_ERR(pdata->sir1_regs)) { |
| 462 | dev_err(dev, "sir1 ioremap failed\n"); |
| 463 | ret = PTR_ERR(pdata->sir1_regs); |
| 464 | goto err_io; |
| 465 | } |
| 466 | if (netif_msg_probe(pdata)) |
| 467 | dev_dbg(dev, "sir1_regs = %p\n", pdata->sir1_regs); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 468 | |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 469 | /* Retrieve the MAC address */ |
| 470 | ret = device_property_read_u8_array(dev, XGBE_MAC_ADDR_PROPERTY, |
| 471 | pdata->mac_addr, |
| 472 | sizeof(pdata->mac_addr)); |
| 473 | if (ret || !is_valid_ether_addr(pdata->mac_addr)) { |
| 474 | dev_err(dev, "invalid %s property\n", XGBE_MAC_ADDR_PROPERTY); |
| 475 | if (!ret) |
| 476 | ret = -EINVAL; |
Lendacky, Thomas | f3d0e78 | 2014-08-05 13:30:38 -0500 | [diff] [blame] | 477 | goto err_io; |
| 478 | } |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 479 | |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 480 | /* Retrieve the PHY mode - it must be "xgmii" */ |
| 481 | ret = device_property_read_string(dev, XGBE_PHY_MODE_PROPERTY, |
| 482 | &phy_mode); |
| 483 | if (ret || strcmp(phy_mode, phy_modes(PHY_INTERFACE_MODE_XGMII))) { |
| 484 | dev_err(dev, "invalid %s property\n", XGBE_PHY_MODE_PROPERTY); |
| 485 | if (!ret) |
| 486 | ret = -EINVAL; |
| 487 | goto err_io; |
| 488 | } |
| 489 | pdata->phy_mode = PHY_INTERFACE_MODE_XGMII; |
| 490 | |
| 491 | /* Check for per channel interrupt support */ |
| 492 | if (device_property_present(dev, XGBE_DMA_IRQS_PROPERTY)) |
| 493 | pdata->per_channel_irq = 1; |
| 494 | |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 495 | /* Retrieve the PHY speedset */ |
| 496 | ret = device_property_read_u32(phy_dev, XGBE_SPEEDSET_PROPERTY, |
| 497 | &pdata->speed_set); |
| 498 | if (ret) { |
| 499 | dev_err(dev, "invalid %s property\n", XGBE_SPEEDSET_PROPERTY); |
| 500 | goto err_io; |
| 501 | } |
| 502 | |
| 503 | switch (pdata->speed_set) { |
| 504 | case XGBE_SPEEDSET_1000_10000: |
| 505 | case XGBE_SPEEDSET_2500_10000: |
| 506 | break; |
| 507 | default: |
| 508 | dev_err(dev, "invalid %s property\n", XGBE_SPEEDSET_PROPERTY); |
| 509 | ret = -EINVAL; |
| 510 | goto err_io; |
| 511 | } |
| 512 | |
| 513 | /* Retrieve the PHY configuration properties */ |
| 514 | if (device_property_present(phy_dev, XGBE_BLWC_PROPERTY)) { |
| 515 | ret = device_property_read_u32_array(phy_dev, |
| 516 | XGBE_BLWC_PROPERTY, |
| 517 | pdata->serdes_blwc, |
| 518 | XGBE_SPEEDS); |
| 519 | if (ret) { |
| 520 | dev_err(dev, "invalid %s property\n", |
| 521 | XGBE_BLWC_PROPERTY); |
| 522 | goto err_io; |
| 523 | } |
| 524 | } else { |
| 525 | memcpy(pdata->serdes_blwc, xgbe_serdes_blwc, |
| 526 | sizeof(pdata->serdes_blwc)); |
| 527 | } |
| 528 | |
| 529 | if (device_property_present(phy_dev, XGBE_CDR_RATE_PROPERTY)) { |
| 530 | ret = device_property_read_u32_array(phy_dev, |
| 531 | XGBE_CDR_RATE_PROPERTY, |
| 532 | pdata->serdes_cdr_rate, |
| 533 | XGBE_SPEEDS); |
| 534 | if (ret) { |
| 535 | dev_err(dev, "invalid %s property\n", |
| 536 | XGBE_CDR_RATE_PROPERTY); |
| 537 | goto err_io; |
| 538 | } |
| 539 | } else { |
| 540 | memcpy(pdata->serdes_cdr_rate, xgbe_serdes_cdr_rate, |
| 541 | sizeof(pdata->serdes_cdr_rate)); |
| 542 | } |
| 543 | |
| 544 | if (device_property_present(phy_dev, XGBE_PQ_SKEW_PROPERTY)) { |
| 545 | ret = device_property_read_u32_array(phy_dev, |
| 546 | XGBE_PQ_SKEW_PROPERTY, |
| 547 | pdata->serdes_pq_skew, |
| 548 | XGBE_SPEEDS); |
| 549 | if (ret) { |
| 550 | dev_err(dev, "invalid %s property\n", |
| 551 | XGBE_PQ_SKEW_PROPERTY); |
| 552 | goto err_io; |
| 553 | } |
| 554 | } else { |
| 555 | memcpy(pdata->serdes_pq_skew, xgbe_serdes_pq_skew, |
| 556 | sizeof(pdata->serdes_pq_skew)); |
| 557 | } |
| 558 | |
| 559 | if (device_property_present(phy_dev, XGBE_TX_AMP_PROPERTY)) { |
| 560 | ret = device_property_read_u32_array(phy_dev, |
| 561 | XGBE_TX_AMP_PROPERTY, |
| 562 | pdata->serdes_tx_amp, |
| 563 | XGBE_SPEEDS); |
| 564 | if (ret) { |
| 565 | dev_err(dev, "invalid %s property\n", |
| 566 | XGBE_TX_AMP_PROPERTY); |
| 567 | goto err_io; |
| 568 | } |
| 569 | } else { |
| 570 | memcpy(pdata->serdes_tx_amp, xgbe_serdes_tx_amp, |
| 571 | sizeof(pdata->serdes_tx_amp)); |
| 572 | } |
| 573 | |
| 574 | if (device_property_present(phy_dev, XGBE_DFE_CFG_PROPERTY)) { |
| 575 | ret = device_property_read_u32_array(phy_dev, |
| 576 | XGBE_DFE_CFG_PROPERTY, |
| 577 | pdata->serdes_dfe_tap_cfg, |
| 578 | XGBE_SPEEDS); |
| 579 | if (ret) { |
| 580 | dev_err(dev, "invalid %s property\n", |
| 581 | XGBE_DFE_CFG_PROPERTY); |
| 582 | goto err_io; |
| 583 | } |
| 584 | } else { |
| 585 | memcpy(pdata->serdes_dfe_tap_cfg, xgbe_serdes_dfe_tap_cfg, |
| 586 | sizeof(pdata->serdes_dfe_tap_cfg)); |
| 587 | } |
| 588 | |
| 589 | if (device_property_present(phy_dev, XGBE_DFE_ENA_PROPERTY)) { |
| 590 | ret = device_property_read_u32_array(phy_dev, |
| 591 | XGBE_DFE_ENA_PROPERTY, |
| 592 | pdata->serdes_dfe_tap_ena, |
| 593 | XGBE_SPEEDS); |
| 594 | if (ret) { |
| 595 | dev_err(dev, "invalid %s property\n", |
| 596 | XGBE_DFE_ENA_PROPERTY); |
| 597 | goto err_io; |
| 598 | } |
| 599 | } else { |
| 600 | memcpy(pdata->serdes_dfe_tap_ena, xgbe_serdes_dfe_tap_ena, |
| 601 | sizeof(pdata->serdes_dfe_tap_ena)); |
| 602 | } |
| 603 | |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 604 | /* Obtain device settings unique to ACPI/OF */ |
| 605 | if (pdata->use_acpi) |
| 606 | ret = xgbe_acpi_support(pdata); |
| 607 | else |
| 608 | ret = xgbe_of_support(pdata); |
| 609 | if (ret) |
| 610 | goto err_io; |
| 611 | |
| 612 | /* Set the DMA coherency values */ |
Suthikulpanit, Suravee | 1831eff | 2015-10-28 15:50:50 -0700 | [diff] [blame] | 613 | attr = device_get_dma_attr(dev); |
| 614 | if (attr == DEV_DMA_NOT_SUPPORTED) { |
| 615 | dev_err(dev, "DMA is not supported"); |
Wei Yongjun | 675a6ce | 2016-10-22 14:35:30 +0000 | [diff] [blame^] | 616 | ret = -ENODEV; |
Suthikulpanit, Suravee | 1831eff | 2015-10-28 15:50:50 -0700 | [diff] [blame] | 617 | goto err_io; |
| 618 | } |
| 619 | pdata->coherent = (attr == DEV_DMA_COHERENT); |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 620 | if (pdata->coherent) { |
Lendacky, Thomas | cfa50c7 | 2014-07-02 13:04:57 -0500 | [diff] [blame] | 621 | pdata->axdomain = XGBE_DMA_OS_AXDOMAIN; |
| 622 | pdata->arcache = XGBE_DMA_OS_ARCACHE; |
| 623 | pdata->awcache = XGBE_DMA_OS_AWCACHE; |
| 624 | } else { |
| 625 | pdata->axdomain = XGBE_DMA_SYS_AXDOMAIN; |
| 626 | pdata->arcache = XGBE_DMA_SYS_ARCACHE; |
| 627 | pdata->awcache = XGBE_DMA_SYS_AWCACHE; |
| 628 | } |
| 629 | |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 630 | /* Get the device interrupt */ |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 631 | ret = platform_get_irq(pdev, 0); |
| 632 | if (ret < 0) { |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 633 | dev_err(dev, "platform_get_irq 0 failed\n"); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 634 | goto err_io; |
| 635 | } |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 636 | pdata->dev_irq = ret; |
| 637 | |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 638 | /* Get the auto-negotiation interrupt */ |
| 639 | ret = platform_get_irq(phy_pdev, phy_irqnum++); |
| 640 | if (ret < 0) { |
| 641 | dev_err(dev, "platform_get_irq phy 0 failed\n"); |
| 642 | goto err_io; |
| 643 | } |
| 644 | pdata->an_irq = ret; |
| 645 | |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 646 | netdev->irq = pdata->dev_irq; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 647 | netdev->base_addr = (unsigned long)pdata->xgmac_regs; |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 648 | memcpy(netdev->dev_addr, pdata->mac_addr, netdev->addr_len); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 649 | |
| 650 | /* Set all the function pointers */ |
| 651 | xgbe_init_all_fptrs(pdata); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 652 | |
| 653 | /* Issue software reset to device */ |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 654 | pdata->hw_if.exit(pdata); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 655 | |
| 656 | /* Populate the hardware features */ |
| 657 | xgbe_get_all_hw_features(pdata); |
| 658 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 659 | /* Set default configuration data */ |
| 660 | xgbe_default_config(pdata); |
| 661 | |
Lendacky, Thomas | 386d325 | 2015-03-20 11:50:22 -0500 | [diff] [blame] | 662 | /* Set the DMA mask */ |
Lendacky, Thomas | 386d325 | 2015-03-20 11:50:22 -0500 | [diff] [blame] | 663 | ret = dma_set_mask_and_coherent(dev, |
| 664 | DMA_BIT_MASK(pdata->hw_feat.dma_width)); |
| 665 | if (ret) { |
| 666 | dev_err(dev, "dma_set_mask_and_coherent failed\n"); |
| 667 | goto err_io; |
| 668 | } |
| 669 | |
Lendacky, Thomas | 853eb16 | 2014-07-29 08:57:31 -0500 | [diff] [blame] | 670 | /* Calculate the number of Tx and Rx rings to be created |
| 671 | * -Tx (DMA) Channels map 1-to-1 to Tx Queues so set |
| 672 | * the number of Tx queues to the number of Tx channels |
| 673 | * enabled |
| 674 | * -Rx (DMA) Channels do not map 1-to-1 so use the actual |
| 675 | * number of Rx queues |
| 676 | */ |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 677 | pdata->tx_ring_count = min_t(unsigned int, num_online_cpus(), |
| 678 | pdata->hw_feat.tx_ch_cnt); |
Lendacky, Thomas | 853eb16 | 2014-07-29 08:57:31 -0500 | [diff] [blame] | 679 | pdata->tx_q_count = pdata->tx_ring_count; |
Wei Yongjun | 332cfc8 | 2014-07-23 08:59:40 +0800 | [diff] [blame] | 680 | ret = netif_set_real_num_tx_queues(netdev, pdata->tx_ring_count); |
| 681 | if (ret) { |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 682 | dev_err(dev, "error setting real tx queue count\n"); |
| 683 | goto err_io; |
| 684 | } |
| 685 | |
| 686 | pdata->rx_ring_count = min_t(unsigned int, |
| 687 | netif_get_num_default_rss_queues(), |
| 688 | pdata->hw_feat.rx_ch_cnt); |
Lendacky, Thomas | 853eb16 | 2014-07-29 08:57:31 -0500 | [diff] [blame] | 689 | pdata->rx_q_count = pdata->hw_feat.rx_q_cnt; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 690 | ret = netif_set_real_num_rx_queues(netdev, pdata->rx_ring_count); |
| 691 | if (ret) { |
| 692 | dev_err(dev, "error setting real rx queue count\n"); |
| 693 | goto err_io; |
| 694 | } |
| 695 | |
Lendacky, Thomas | 5b9dfe2 | 2014-11-04 16:07:02 -0600 | [diff] [blame] | 696 | /* Initialize RSS hash key and lookup table */ |
Eric Dumazet | b230630 | 2014-11-16 06:23:06 -0800 | [diff] [blame] | 697 | netdev_rss_key_fill(pdata->rss_key, sizeof(pdata->rss_key)); |
Lendacky, Thomas | 5b9dfe2 | 2014-11-04 16:07:02 -0600 | [diff] [blame] | 698 | |
| 699 | for (i = 0; i < XGBE_RSS_MAX_TABLE_SIZE; i++) |
| 700 | XGMAC_SET_BITS(pdata->rss_table[i], MAC_RSSDR, DMCH, |
| 701 | i % pdata->rx_ring_count); |
| 702 | |
| 703 | XGMAC_SET_BITS(pdata->rss_options, MAC_RSSCR, IP2TE, 1); |
| 704 | XGMAC_SET_BITS(pdata->rss_options, MAC_RSSCR, TCP4TE, 1); |
| 705 | XGMAC_SET_BITS(pdata->rss_options, MAC_RSSCR, UDP4TE, 1); |
| 706 | |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 707 | /* Call MDIO/PHY initialization routine */ |
| 708 | pdata->phy_if.phy_init(pdata); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 709 | |
Lendacky, Thomas | fca2d99 | 2014-07-29 08:57:55 -0500 | [diff] [blame] | 710 | /* Set device operations */ |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 711 | netdev->netdev_ops = xgbe_get_netdev_ops(); |
| 712 | netdev->ethtool_ops = xgbe_get_ethtool_ops(); |
Lendacky, Thomas | fca2d99 | 2014-07-29 08:57:55 -0500 | [diff] [blame] | 713 | #ifdef CONFIG_AMD_XGBE_DCB |
| 714 | netdev->dcbnl_ops = xgbe_get_dcbnl_ops(); |
| 715 | #endif |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 716 | |
| 717 | /* Set device features */ |
| 718 | netdev->hw_features = NETIF_F_SG | |
| 719 | NETIF_F_IP_CSUM | |
| 720 | NETIF_F_IPV6_CSUM | |
| 721 | NETIF_F_RXCSUM | |
| 722 | NETIF_F_TSO | |
| 723 | NETIF_F_TSO6 | |
| 724 | NETIF_F_GRO | |
| 725 | NETIF_F_HW_VLAN_CTAG_RX | |
Lendacky, Thomas | 801c62d | 2014-06-24 16:19:24 -0500 | [diff] [blame] | 726 | NETIF_F_HW_VLAN_CTAG_TX | |
| 727 | NETIF_F_HW_VLAN_CTAG_FILTER; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 728 | |
Lendacky, Thomas | 5b9dfe2 | 2014-11-04 16:07:02 -0600 | [diff] [blame] | 729 | if (pdata->hw_feat.rss) |
| 730 | netdev->hw_features |= NETIF_F_RXHASH; |
| 731 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 732 | netdev->vlan_features |= NETIF_F_SG | |
| 733 | NETIF_F_IP_CSUM | |
| 734 | NETIF_F_IPV6_CSUM | |
| 735 | NETIF_F_TSO | |
| 736 | NETIF_F_TSO6; |
| 737 | |
| 738 | netdev->features |= netdev->hw_features; |
| 739 | pdata->netdev_features = netdev->features; |
| 740 | |
Lendacky, Thomas | b85e4d8 | 2014-06-24 16:19:29 -0500 | [diff] [blame] | 741 | netdev->priv_flags |= IFF_UNICAST_FLT; |
Jarod Wilson | d894be5 | 2016-10-20 13:55:16 -0400 | [diff] [blame] | 742 | netdev->min_mtu = 0; |
| 743 | netdev->max_mtu = XGMAC_JUMBO_PACKET_MTU; |
Lendacky, Thomas | b85e4d8 | 2014-06-24 16:19:29 -0500 | [diff] [blame] | 744 | |
Lendacky, Thomas | a8373f1 | 2015-04-09 12:12:03 -0500 | [diff] [blame] | 745 | /* Use default watchdog timeout */ |
| 746 | netdev->watchdog_timeo = 0; |
| 747 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 748 | xgbe_init_rx_coalesce(pdata); |
| 749 | xgbe_init_tx_coalesce(pdata); |
| 750 | |
| 751 | netif_carrier_off(netdev); |
| 752 | ret = register_netdev(netdev); |
| 753 | if (ret) { |
| 754 | dev_err(dev, "net device registration failed\n"); |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 755 | goto err_io; |
| 756 | } |
| 757 | |
| 758 | /* Create the PHY/ANEG name based on netdev name */ |
| 759 | snprintf(pdata->an_name, sizeof(pdata->an_name) - 1, "%s-pcs", |
| 760 | netdev_name(netdev)); |
| 761 | |
| 762 | /* Create workqueues */ |
| 763 | pdata->dev_workqueue = |
| 764 | create_singlethread_workqueue(netdev_name(netdev)); |
| 765 | if (!pdata->dev_workqueue) { |
| 766 | netdev_err(netdev, "device workqueue creation failed\n"); |
| 767 | ret = -ENOMEM; |
| 768 | goto err_netdev; |
| 769 | } |
| 770 | |
| 771 | pdata->an_workqueue = |
| 772 | create_singlethread_workqueue(pdata->an_name); |
| 773 | if (!pdata->an_workqueue) { |
| 774 | netdev_err(netdev, "phy workqueue creation failed\n"); |
| 775 | ret = -ENOMEM; |
| 776 | goto err_wq; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 777 | } |
| 778 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 779 | xgbe_ptp_register(pdata); |
| 780 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 781 | xgbe_debugfs_init(pdata); |
| 782 | |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 783 | platform_device_put(phy_pdev); |
| 784 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 785 | netdev_notice(netdev, "net device enabled\n"); |
| 786 | |
| 787 | DBGPR("<-- xgbe_probe\n"); |
| 788 | |
| 789 | return 0; |
| 790 | |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 791 | err_wq: |
| 792 | destroy_workqueue(pdata->dev_workqueue); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 793 | |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 794 | err_netdev: |
| 795 | unregister_netdev(netdev); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 796 | |
| 797 | err_io: |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 798 | platform_device_put(phy_pdev); |
| 799 | |
| 800 | err_phydev: |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 801 | free_netdev(netdev); |
| 802 | |
| 803 | err_alloc: |
| 804 | dev_notice(dev, "net device not enabled\n"); |
| 805 | |
| 806 | return ret; |
| 807 | } |
| 808 | |
| 809 | static int xgbe_remove(struct platform_device *pdev) |
| 810 | { |
| 811 | struct net_device *netdev = platform_get_drvdata(pdev); |
| 812 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 813 | |
| 814 | DBGPR("-->xgbe_remove\n"); |
| 815 | |
| 816 | xgbe_debugfs_exit(pdata); |
| 817 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 818 | xgbe_ptp_unregister(pdata); |
| 819 | |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 820 | flush_workqueue(pdata->an_workqueue); |
| 821 | destroy_workqueue(pdata->an_workqueue); |
| 822 | |
| 823 | flush_workqueue(pdata->dev_workqueue); |
| 824 | destroy_workqueue(pdata->dev_workqueue); |
| 825 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 826 | unregister_netdev(netdev); |
| 827 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 828 | free_netdev(netdev); |
| 829 | |
| 830 | DBGPR("<--xgbe_remove\n"); |
| 831 | |
| 832 | return 0; |
| 833 | } |
| 834 | |
| 835 | #ifdef CONFIG_PM |
| 836 | static int xgbe_suspend(struct device *dev) |
| 837 | { |
| 838 | struct net_device *netdev = dev_get_drvdata(dev); |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 839 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 840 | int ret = 0; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 841 | |
| 842 | DBGPR("-->xgbe_suspend\n"); |
| 843 | |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 844 | if (netif_running(netdev)) |
| 845 | ret = xgbe_powerdown(netdev, XGMAC_DRIVER_CONTEXT); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 846 | |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 847 | pdata->lpm_ctrl = XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_CTRL1); |
| 848 | pdata->lpm_ctrl |= MDIO_CTRL1_LPOWER; |
| 849 | XMDIO_WRITE(pdata, MDIO_MMD_PCS, MDIO_CTRL1, pdata->lpm_ctrl); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 850 | |
| 851 | DBGPR("<--xgbe_suspend\n"); |
| 852 | |
| 853 | return ret; |
| 854 | } |
| 855 | |
| 856 | static int xgbe_resume(struct device *dev) |
| 857 | { |
| 858 | struct net_device *netdev = dev_get_drvdata(dev); |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 859 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 860 | int ret = 0; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 861 | |
| 862 | DBGPR("-->xgbe_resume\n"); |
| 863 | |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 864 | pdata->lpm_ctrl &= ~MDIO_CTRL1_LPOWER; |
| 865 | XMDIO_WRITE(pdata, MDIO_MMD_PCS, MDIO_CTRL1, pdata->lpm_ctrl); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 866 | |
James Morse | a039b63 | 2016-08-26 09:21:23 +0100 | [diff] [blame] | 867 | if (netif_running(netdev)) { |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 868 | ret = xgbe_powerup(netdev, XGMAC_DRIVER_CONTEXT); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 869 | |
James Morse | a039b63 | 2016-08-26 09:21:23 +0100 | [diff] [blame] | 870 | /* Schedule a restart in case the link or phy state changed |
| 871 | * while we were powered down. |
| 872 | */ |
| 873 | schedule_work(&pdata->restart_work); |
| 874 | } |
| 875 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 876 | DBGPR("<--xgbe_resume\n"); |
| 877 | |
| 878 | return ret; |
| 879 | } |
| 880 | #endif /* CONFIG_PM */ |
| 881 | |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 882 | #ifdef CONFIG_ACPI |
| 883 | static const struct acpi_device_id xgbe_acpi_match[] = { |
| 884 | { "AMDI8001", 0 }, |
| 885 | {}, |
| 886 | }; |
| 887 | |
| 888 | MODULE_DEVICE_TABLE(acpi, xgbe_acpi_match); |
| 889 | #endif |
| 890 | |
| 891 | #ifdef CONFIG_OF |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 892 | static const struct of_device_id xgbe_of_match[] = { |
| 893 | { .compatible = "amd,xgbe-seattle-v1a", }, |
| 894 | {}, |
| 895 | }; |
| 896 | |
| 897 | MODULE_DEVICE_TABLE(of, xgbe_of_match); |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 898 | #endif |
| 899 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 900 | static SIMPLE_DEV_PM_OPS(xgbe_pm_ops, xgbe_suspend, xgbe_resume); |
| 901 | |
| 902 | static struct platform_driver xgbe_driver = { |
| 903 | .driver = { |
| 904 | .name = "amd-xgbe", |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 905 | #ifdef CONFIG_ACPI |
| 906 | .acpi_match_table = xgbe_acpi_match, |
| 907 | #endif |
| 908 | #ifdef CONFIG_OF |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 909 | .of_match_table = xgbe_of_match, |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 910 | #endif |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 911 | .pm = &xgbe_pm_ops, |
| 912 | }, |
| 913 | .probe = xgbe_probe, |
| 914 | .remove = xgbe_remove, |
| 915 | }; |
| 916 | |
| 917 | module_platform_driver(xgbe_driver); |