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 | * |
| 9 | * Copyright (c) 2014 Advanced Micro Devices, Inc. |
| 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 | * |
| 59 | * Copyright (c) 2014 Advanced Micro Devices, Inc. |
| 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 | { |
| 215 | struct acpi_device *adev = pdata->adev; |
| 216 | struct device *dev = pdata->dev; |
| 217 | u32 property; |
| 218 | acpi_handle handle; |
| 219 | acpi_status status; |
| 220 | unsigned long long data; |
| 221 | int cca; |
| 222 | int ret; |
| 223 | |
| 224 | /* Obtain the system clock setting */ |
| 225 | ret = device_property_read_u32(dev, XGBE_ACPI_DMA_FREQ, &property); |
| 226 | if (ret) { |
| 227 | dev_err(dev, "unable to obtain %s property\n", |
| 228 | XGBE_ACPI_DMA_FREQ); |
| 229 | return ret; |
| 230 | } |
| 231 | pdata->sysclk_rate = property; |
| 232 | |
| 233 | /* Obtain the PTP clock setting */ |
| 234 | ret = device_property_read_u32(dev, XGBE_ACPI_PTP_FREQ, &property); |
| 235 | if (ret) { |
| 236 | dev_err(dev, "unable to obtain %s property\n", |
| 237 | XGBE_ACPI_PTP_FREQ); |
| 238 | return ret; |
| 239 | } |
| 240 | pdata->ptpclk_rate = property; |
| 241 | |
| 242 | /* Retrieve the device cache coherency value */ |
| 243 | handle = adev->handle; |
| 244 | do { |
| 245 | status = acpi_evaluate_integer(handle, "_CCA", NULL, &data); |
| 246 | if (!ACPI_FAILURE(status)) { |
| 247 | cca = data; |
| 248 | break; |
| 249 | } |
| 250 | |
| 251 | status = acpi_get_parent(handle, &handle); |
| 252 | } while (!ACPI_FAILURE(status)); |
| 253 | |
| 254 | if (ACPI_FAILURE(status)) { |
| 255 | dev_err(dev, "error obtaining acpi coherency value\n"); |
| 256 | return -EINVAL; |
| 257 | } |
| 258 | pdata->coherent = !!cca; |
| 259 | |
| 260 | return 0; |
| 261 | } |
| 262 | #else /* CONFIG_ACPI */ |
| 263 | static int xgbe_acpi_support(struct xgbe_prv_data *pdata) |
| 264 | { |
| 265 | return -EINVAL; |
| 266 | } |
| 267 | #endif /* CONFIG_ACPI */ |
| 268 | |
| 269 | #ifdef CONFIG_OF |
| 270 | static int xgbe_of_support(struct xgbe_prv_data *pdata) |
| 271 | { |
| 272 | struct device *dev = pdata->dev; |
| 273 | |
| 274 | /* Obtain the system clock setting */ |
| 275 | pdata->sysclk = devm_clk_get(dev, XGBE_DMA_CLOCK); |
| 276 | if (IS_ERR(pdata->sysclk)) { |
| 277 | dev_err(dev, "dma devm_clk_get failed\n"); |
| 278 | return PTR_ERR(pdata->sysclk); |
| 279 | } |
| 280 | pdata->sysclk_rate = clk_get_rate(pdata->sysclk); |
| 281 | |
| 282 | /* Obtain the PTP clock setting */ |
| 283 | pdata->ptpclk = devm_clk_get(dev, XGBE_PTP_CLOCK); |
| 284 | if (IS_ERR(pdata->ptpclk)) { |
| 285 | dev_err(dev, "ptp devm_clk_get failed\n"); |
| 286 | return PTR_ERR(pdata->ptpclk); |
| 287 | } |
| 288 | pdata->ptpclk_rate = clk_get_rate(pdata->ptpclk); |
| 289 | |
| 290 | /* Retrieve the device cache coherency value */ |
| 291 | pdata->coherent = of_dma_is_coherent(dev->of_node); |
| 292 | |
| 293 | return 0; |
| 294 | } |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 295 | |
| 296 | static struct platform_device *xgbe_of_get_phy_pdev(struct xgbe_prv_data *pdata) |
| 297 | { |
| 298 | struct device *dev = pdata->dev; |
| 299 | struct device_node *phy_node; |
| 300 | struct platform_device *phy_pdev; |
| 301 | |
| 302 | phy_node = of_parse_phandle(dev->of_node, "phy-handle", 0); |
Lendacky, Thomas | 34bfff4 | 2015-05-14 11:44:21 -0500 | [diff] [blame^] | 303 | if (phy_node) { |
| 304 | /* Old style device tree: |
| 305 | * The XGBE and PHY resources are separate |
| 306 | */ |
| 307 | phy_pdev = of_find_device_by_node(phy_node); |
| 308 | of_node_put(phy_node); |
| 309 | } else { |
| 310 | /* New style device tree: |
| 311 | * The XGBE and PHY resources are grouped together with |
| 312 | * the PHY resources listed last |
| 313 | */ |
| 314 | get_device(dev); |
| 315 | phy_pdev = pdata->pdev; |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 316 | } |
| 317 | |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 318 | return phy_pdev; |
| 319 | } |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 320 | #else /* CONFIG_OF */ |
| 321 | static int xgbe_of_support(struct xgbe_prv_data *pdata) |
| 322 | { |
| 323 | return -EINVAL; |
| 324 | } |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 325 | |
| 326 | static struct platform_device *xgbe_of_get_phy_pdev(struct xgbe_prv_data *pdata) |
| 327 | { |
| 328 | return NULL; |
| 329 | } |
| 330 | #endif /* CONFIG_OF */ |
| 331 | |
| 332 | static unsigned int xgbe_resource_count(struct platform_device *pdev, |
| 333 | unsigned int type) |
| 334 | { |
| 335 | unsigned int count; |
| 336 | int i; |
| 337 | |
| 338 | for (i = 0, count = 0; i < pdev->num_resources; i++) { |
| 339 | struct resource *res = &pdev->resource[i]; |
| 340 | |
| 341 | if (type == resource_type(res)) |
| 342 | count++; |
| 343 | } |
| 344 | |
| 345 | return count; |
| 346 | } |
| 347 | |
| 348 | static struct platform_device *xgbe_get_phy_pdev(struct xgbe_prv_data *pdata) |
| 349 | { |
| 350 | struct platform_device *phy_pdev; |
| 351 | |
| 352 | if (pdata->use_acpi) { |
| 353 | get_device(pdata->dev); |
| 354 | phy_pdev = pdata->pdev; |
| 355 | } else { |
| 356 | phy_pdev = xgbe_of_get_phy_pdev(pdata); |
| 357 | } |
| 358 | |
| 359 | return phy_pdev; |
| 360 | } |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 361 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 362 | static int xgbe_probe(struct platform_device *pdev) |
| 363 | { |
| 364 | struct xgbe_prv_data *pdata; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 365 | struct net_device *netdev; |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 366 | struct device *dev = &pdev->dev, *phy_dev; |
| 367 | struct platform_device *phy_pdev; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 368 | struct resource *res; |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 369 | const char *phy_mode; |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 370 | unsigned int i, phy_memnum, phy_irqnum; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 371 | int ret; |
| 372 | |
| 373 | DBGPR("--> xgbe_probe\n"); |
| 374 | |
| 375 | netdev = alloc_etherdev_mq(sizeof(struct xgbe_prv_data), |
Lendacky, Thomas | d5c4858 | 2014-06-09 09:19:32 -0500 | [diff] [blame] | 376 | XGBE_MAX_DMA_CHANNELS); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 377 | if (!netdev) { |
| 378 | dev_err(dev, "alloc_etherdev failed\n"); |
| 379 | ret = -ENOMEM; |
| 380 | goto err_alloc; |
| 381 | } |
| 382 | SET_NETDEV_DEV(netdev, dev); |
| 383 | pdata = netdev_priv(netdev); |
| 384 | pdata->netdev = netdev; |
| 385 | pdata->pdev = pdev; |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 386 | pdata->adev = ACPI_COMPANION(dev); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 387 | pdata->dev = dev; |
| 388 | platform_set_drvdata(pdev, netdev); |
| 389 | |
| 390 | spin_lock_init(&pdata->lock); |
| 391 | mutex_init(&pdata->xpcs_mutex); |
Lendacky, Thomas | 5b9dfe2 | 2014-11-04 16:07:02 -0600 | [diff] [blame] | 392 | mutex_init(&pdata->rss_mutex); |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 393 | spin_lock_init(&pdata->tstamp_lock); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 394 | |
Lendacky, Thomas | 34bf65d | 2015-05-14 11:44:03 -0500 | [diff] [blame] | 395 | pdata->msg_enable = netif_msg_init(debug, default_msg_level); |
| 396 | |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 397 | set_bit(XGBE_DOWN, &pdata->dev_state); |
| 398 | |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 399 | /* Check if we should use ACPI or DT */ |
| 400 | pdata->use_acpi = (!pdata->adev || acpi_disabled) ? 0 : 1; |
| 401 | |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 402 | phy_pdev = xgbe_get_phy_pdev(pdata); |
| 403 | if (!phy_pdev) { |
| 404 | dev_err(dev, "unable to obtain phy device\n"); |
| 405 | ret = -EINVAL; |
| 406 | goto err_phydev; |
| 407 | } |
| 408 | phy_dev = &phy_pdev->dev; |
| 409 | |
| 410 | if (pdev == phy_pdev) { |
Lendacky, Thomas | 34bfff4 | 2015-05-14 11:44:21 -0500 | [diff] [blame^] | 411 | /* New style device tree or ACPI: |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 412 | * The XGBE and PHY resources are grouped together with |
| 413 | * the PHY resources listed last |
| 414 | */ |
| 415 | phy_memnum = xgbe_resource_count(pdev, IORESOURCE_MEM) - 3; |
| 416 | phy_irqnum = xgbe_resource_count(pdev, IORESOURCE_IRQ) - 1; |
| 417 | } else { |
Lendacky, Thomas | 34bfff4 | 2015-05-14 11:44:21 -0500 | [diff] [blame^] | 418 | /* Old style device tree: |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 419 | * The XGBE and PHY resources are separate |
| 420 | */ |
| 421 | phy_memnum = 0; |
| 422 | phy_irqnum = 0; |
| 423 | } |
| 424 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 425 | /* Set and validate the number of descriptors for a ring */ |
Lendacky, Thomas | d0a8ba6 | 2014-06-24 16:19:06 -0500 | [diff] [blame] | 426 | BUILD_BUG_ON_NOT_POWER_OF_2(XGBE_TX_DESC_CNT); |
| 427 | pdata->tx_desc_count = XGBE_TX_DESC_CNT; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 428 | if (pdata->tx_desc_count & (pdata->tx_desc_count - 1)) { |
| 429 | dev_err(dev, "tx descriptor count (%d) is not valid\n", |
| 430 | pdata->tx_desc_count); |
| 431 | ret = -EINVAL; |
| 432 | goto err_io; |
| 433 | } |
Lendacky, Thomas | d0a8ba6 | 2014-06-24 16:19:06 -0500 | [diff] [blame] | 434 | BUILD_BUG_ON_NOT_POWER_OF_2(XGBE_RX_DESC_CNT); |
| 435 | pdata->rx_desc_count = XGBE_RX_DESC_CNT; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 436 | if (pdata->rx_desc_count & (pdata->rx_desc_count - 1)) { |
| 437 | dev_err(dev, "rx descriptor count (%d) is not valid\n", |
| 438 | pdata->rx_desc_count); |
| 439 | ret = -EINVAL; |
| 440 | goto err_io; |
| 441 | } |
| 442 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 443 | /* Obtain the mmio areas for the device */ |
| 444 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 445 | pdata->xgmac_regs = devm_ioremap_resource(dev, res); |
| 446 | if (IS_ERR(pdata->xgmac_regs)) { |
| 447 | dev_err(dev, "xgmac ioremap failed\n"); |
| 448 | ret = PTR_ERR(pdata->xgmac_regs); |
| 449 | goto err_io; |
| 450 | } |
Lendacky, Thomas | 34bf65d | 2015-05-14 11:44:03 -0500 | [diff] [blame] | 451 | if (netif_msg_probe(pdata)) |
| 452 | dev_dbg(dev, "xgmac_regs = %p\n", pdata->xgmac_regs); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 453 | |
| 454 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
| 455 | pdata->xpcs_regs = devm_ioremap_resource(dev, res); |
| 456 | if (IS_ERR(pdata->xpcs_regs)) { |
| 457 | dev_err(dev, "xpcs ioremap failed\n"); |
| 458 | ret = PTR_ERR(pdata->xpcs_regs); |
| 459 | goto err_io; |
| 460 | } |
Lendacky, Thomas | 34bf65d | 2015-05-14 11:44:03 -0500 | [diff] [blame] | 461 | if (netif_msg_probe(pdata)) |
| 462 | dev_dbg(dev, "xpcs_regs = %p\n", pdata->xpcs_regs); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 463 | |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 464 | res = platform_get_resource(phy_pdev, IORESOURCE_MEM, phy_memnum++); |
| 465 | pdata->rxtx_regs = devm_ioremap_resource(dev, res); |
| 466 | if (IS_ERR(pdata->rxtx_regs)) { |
| 467 | dev_err(dev, "rxtx ioremap failed\n"); |
| 468 | ret = PTR_ERR(pdata->rxtx_regs); |
| 469 | goto err_io; |
| 470 | } |
| 471 | if (netif_msg_probe(pdata)) |
| 472 | dev_dbg(dev, "rxtx_regs = %p\n", pdata->rxtx_regs); |
| 473 | |
| 474 | res = platform_get_resource(phy_pdev, IORESOURCE_MEM, phy_memnum++); |
| 475 | pdata->sir0_regs = devm_ioremap_resource(dev, res); |
| 476 | if (IS_ERR(pdata->sir0_regs)) { |
| 477 | dev_err(dev, "sir0 ioremap failed\n"); |
| 478 | ret = PTR_ERR(pdata->sir0_regs); |
| 479 | goto err_io; |
| 480 | } |
| 481 | if (netif_msg_probe(pdata)) |
| 482 | dev_dbg(dev, "sir0_regs = %p\n", pdata->sir0_regs); |
| 483 | |
| 484 | res = platform_get_resource(phy_pdev, IORESOURCE_MEM, phy_memnum++); |
| 485 | pdata->sir1_regs = devm_ioremap_resource(dev, res); |
| 486 | if (IS_ERR(pdata->sir1_regs)) { |
| 487 | dev_err(dev, "sir1 ioremap failed\n"); |
| 488 | ret = PTR_ERR(pdata->sir1_regs); |
| 489 | goto err_io; |
| 490 | } |
| 491 | if (netif_msg_probe(pdata)) |
| 492 | dev_dbg(dev, "sir1_regs = %p\n", pdata->sir1_regs); |
| 493 | |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 494 | /* Retrieve the MAC address */ |
| 495 | ret = device_property_read_u8_array(dev, XGBE_MAC_ADDR_PROPERTY, |
| 496 | pdata->mac_addr, |
| 497 | sizeof(pdata->mac_addr)); |
| 498 | if (ret || !is_valid_ether_addr(pdata->mac_addr)) { |
| 499 | dev_err(dev, "invalid %s property\n", XGBE_MAC_ADDR_PROPERTY); |
| 500 | if (!ret) |
| 501 | ret = -EINVAL; |
Lendacky, Thomas | f3d0e78 | 2014-08-05 13:30:38 -0500 | [diff] [blame] | 502 | goto err_io; |
| 503 | } |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 504 | |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 505 | /* Retrieve the PHY mode - it must be "xgmii" */ |
| 506 | ret = device_property_read_string(dev, XGBE_PHY_MODE_PROPERTY, |
| 507 | &phy_mode); |
| 508 | if (ret || strcmp(phy_mode, phy_modes(PHY_INTERFACE_MODE_XGMII))) { |
| 509 | dev_err(dev, "invalid %s property\n", XGBE_PHY_MODE_PROPERTY); |
| 510 | if (!ret) |
| 511 | ret = -EINVAL; |
| 512 | goto err_io; |
| 513 | } |
| 514 | pdata->phy_mode = PHY_INTERFACE_MODE_XGMII; |
| 515 | |
| 516 | /* Check for per channel interrupt support */ |
| 517 | if (device_property_present(dev, XGBE_DMA_IRQS_PROPERTY)) |
| 518 | pdata->per_channel_irq = 1; |
| 519 | |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 520 | /* Retrieve the PHY speedset */ |
| 521 | ret = device_property_read_u32(phy_dev, XGBE_SPEEDSET_PROPERTY, |
| 522 | &pdata->speed_set); |
| 523 | if (ret) { |
| 524 | dev_err(dev, "invalid %s property\n", XGBE_SPEEDSET_PROPERTY); |
| 525 | goto err_io; |
| 526 | } |
| 527 | |
| 528 | switch (pdata->speed_set) { |
| 529 | case XGBE_SPEEDSET_1000_10000: |
| 530 | case XGBE_SPEEDSET_2500_10000: |
| 531 | break; |
| 532 | default: |
| 533 | dev_err(dev, "invalid %s property\n", XGBE_SPEEDSET_PROPERTY); |
| 534 | ret = -EINVAL; |
| 535 | goto err_io; |
| 536 | } |
| 537 | |
| 538 | /* Retrieve the PHY configuration properties */ |
| 539 | if (device_property_present(phy_dev, XGBE_BLWC_PROPERTY)) { |
| 540 | ret = device_property_read_u32_array(phy_dev, |
| 541 | XGBE_BLWC_PROPERTY, |
| 542 | pdata->serdes_blwc, |
| 543 | XGBE_SPEEDS); |
| 544 | if (ret) { |
| 545 | dev_err(dev, "invalid %s property\n", |
| 546 | XGBE_BLWC_PROPERTY); |
| 547 | goto err_io; |
| 548 | } |
| 549 | } else { |
| 550 | memcpy(pdata->serdes_blwc, xgbe_serdes_blwc, |
| 551 | sizeof(pdata->serdes_blwc)); |
| 552 | } |
| 553 | |
| 554 | if (device_property_present(phy_dev, XGBE_CDR_RATE_PROPERTY)) { |
| 555 | ret = device_property_read_u32_array(phy_dev, |
| 556 | XGBE_CDR_RATE_PROPERTY, |
| 557 | pdata->serdes_cdr_rate, |
| 558 | XGBE_SPEEDS); |
| 559 | if (ret) { |
| 560 | dev_err(dev, "invalid %s property\n", |
| 561 | XGBE_CDR_RATE_PROPERTY); |
| 562 | goto err_io; |
| 563 | } |
| 564 | } else { |
| 565 | memcpy(pdata->serdes_cdr_rate, xgbe_serdes_cdr_rate, |
| 566 | sizeof(pdata->serdes_cdr_rate)); |
| 567 | } |
| 568 | |
| 569 | if (device_property_present(phy_dev, XGBE_PQ_SKEW_PROPERTY)) { |
| 570 | ret = device_property_read_u32_array(phy_dev, |
| 571 | XGBE_PQ_SKEW_PROPERTY, |
| 572 | pdata->serdes_pq_skew, |
| 573 | XGBE_SPEEDS); |
| 574 | if (ret) { |
| 575 | dev_err(dev, "invalid %s property\n", |
| 576 | XGBE_PQ_SKEW_PROPERTY); |
| 577 | goto err_io; |
| 578 | } |
| 579 | } else { |
| 580 | memcpy(pdata->serdes_pq_skew, xgbe_serdes_pq_skew, |
| 581 | sizeof(pdata->serdes_pq_skew)); |
| 582 | } |
| 583 | |
| 584 | if (device_property_present(phy_dev, XGBE_TX_AMP_PROPERTY)) { |
| 585 | ret = device_property_read_u32_array(phy_dev, |
| 586 | XGBE_TX_AMP_PROPERTY, |
| 587 | pdata->serdes_tx_amp, |
| 588 | XGBE_SPEEDS); |
| 589 | if (ret) { |
| 590 | dev_err(dev, "invalid %s property\n", |
| 591 | XGBE_TX_AMP_PROPERTY); |
| 592 | goto err_io; |
| 593 | } |
| 594 | } else { |
| 595 | memcpy(pdata->serdes_tx_amp, xgbe_serdes_tx_amp, |
| 596 | sizeof(pdata->serdes_tx_amp)); |
| 597 | } |
| 598 | |
| 599 | if (device_property_present(phy_dev, XGBE_DFE_CFG_PROPERTY)) { |
| 600 | ret = device_property_read_u32_array(phy_dev, |
| 601 | XGBE_DFE_CFG_PROPERTY, |
| 602 | pdata->serdes_dfe_tap_cfg, |
| 603 | XGBE_SPEEDS); |
| 604 | if (ret) { |
| 605 | dev_err(dev, "invalid %s property\n", |
| 606 | XGBE_DFE_CFG_PROPERTY); |
| 607 | goto err_io; |
| 608 | } |
| 609 | } else { |
| 610 | memcpy(pdata->serdes_dfe_tap_cfg, xgbe_serdes_dfe_tap_cfg, |
| 611 | sizeof(pdata->serdes_dfe_tap_cfg)); |
| 612 | } |
| 613 | |
| 614 | if (device_property_present(phy_dev, XGBE_DFE_ENA_PROPERTY)) { |
| 615 | ret = device_property_read_u32_array(phy_dev, |
| 616 | XGBE_DFE_ENA_PROPERTY, |
| 617 | pdata->serdes_dfe_tap_ena, |
| 618 | XGBE_SPEEDS); |
| 619 | if (ret) { |
| 620 | dev_err(dev, "invalid %s property\n", |
| 621 | XGBE_DFE_ENA_PROPERTY); |
| 622 | goto err_io; |
| 623 | } |
| 624 | } else { |
| 625 | memcpy(pdata->serdes_dfe_tap_ena, xgbe_serdes_dfe_tap_ena, |
| 626 | sizeof(pdata->serdes_dfe_tap_ena)); |
| 627 | } |
| 628 | |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 629 | /* Obtain device settings unique to ACPI/OF */ |
| 630 | if (pdata->use_acpi) |
| 631 | ret = xgbe_acpi_support(pdata); |
| 632 | else |
| 633 | ret = xgbe_of_support(pdata); |
| 634 | if (ret) |
| 635 | goto err_io; |
| 636 | |
| 637 | /* Set the DMA coherency values */ |
| 638 | if (pdata->coherent) { |
Lendacky, Thomas | cfa50c7 | 2014-07-02 13:04:57 -0500 | [diff] [blame] | 639 | pdata->axdomain = XGBE_DMA_OS_AXDOMAIN; |
| 640 | pdata->arcache = XGBE_DMA_OS_ARCACHE; |
| 641 | pdata->awcache = XGBE_DMA_OS_AWCACHE; |
| 642 | } else { |
| 643 | pdata->axdomain = XGBE_DMA_SYS_AXDOMAIN; |
| 644 | pdata->arcache = XGBE_DMA_SYS_ARCACHE; |
| 645 | pdata->awcache = XGBE_DMA_SYS_AWCACHE; |
| 646 | } |
| 647 | |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 648 | /* Get the device interrupt */ |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 649 | ret = platform_get_irq(pdev, 0); |
| 650 | if (ret < 0) { |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 651 | dev_err(dev, "platform_get_irq 0 failed\n"); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 652 | goto err_io; |
| 653 | } |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 654 | pdata->dev_irq = ret; |
| 655 | |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 656 | /* Get the auto-negotiation interrupt */ |
| 657 | ret = platform_get_irq(phy_pdev, phy_irqnum++); |
| 658 | if (ret < 0) { |
| 659 | dev_err(dev, "platform_get_irq phy 0 failed\n"); |
| 660 | goto err_io; |
| 661 | } |
| 662 | pdata->an_irq = ret; |
| 663 | |
Lendacky, Thomas | 9227dc5 | 2014-11-04 16:06:56 -0600 | [diff] [blame] | 664 | netdev->irq = pdata->dev_irq; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 665 | netdev->base_addr = (unsigned long)pdata->xgmac_regs; |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 666 | memcpy(netdev->dev_addr, pdata->mac_addr, netdev->addr_len); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 667 | |
| 668 | /* Set all the function pointers */ |
| 669 | xgbe_init_all_fptrs(pdata); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 670 | |
| 671 | /* Issue software reset to device */ |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 672 | pdata->hw_if.exit(pdata); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 673 | |
| 674 | /* Populate the hardware features */ |
| 675 | xgbe_get_all_hw_features(pdata); |
| 676 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 677 | /* Set default configuration data */ |
| 678 | xgbe_default_config(pdata); |
| 679 | |
Lendacky, Thomas | 386d325 | 2015-03-20 11:50:22 -0500 | [diff] [blame] | 680 | /* Set the DMA mask */ |
| 681 | if (!dev->dma_mask) |
| 682 | dev->dma_mask = &dev->coherent_dma_mask; |
| 683 | ret = dma_set_mask_and_coherent(dev, |
| 684 | DMA_BIT_MASK(pdata->hw_feat.dma_width)); |
| 685 | if (ret) { |
| 686 | dev_err(dev, "dma_set_mask_and_coherent failed\n"); |
| 687 | goto err_io; |
| 688 | } |
| 689 | |
Lendacky, Thomas | 853eb16 | 2014-07-29 08:57:31 -0500 | [diff] [blame] | 690 | /* Calculate the number of Tx and Rx rings to be created |
| 691 | * -Tx (DMA) Channels map 1-to-1 to Tx Queues so set |
| 692 | * the number of Tx queues to the number of Tx channels |
| 693 | * enabled |
| 694 | * -Rx (DMA) Channels do not map 1-to-1 so use the actual |
| 695 | * number of Rx queues |
| 696 | */ |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 697 | pdata->tx_ring_count = min_t(unsigned int, num_online_cpus(), |
| 698 | pdata->hw_feat.tx_ch_cnt); |
Lendacky, Thomas | 853eb16 | 2014-07-29 08:57:31 -0500 | [diff] [blame] | 699 | pdata->tx_q_count = pdata->tx_ring_count; |
Wei Yongjun | 332cfc8 | 2014-07-23 08:59:40 +0800 | [diff] [blame] | 700 | ret = netif_set_real_num_tx_queues(netdev, pdata->tx_ring_count); |
| 701 | if (ret) { |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 702 | dev_err(dev, "error setting real tx queue count\n"); |
| 703 | goto err_io; |
| 704 | } |
| 705 | |
| 706 | pdata->rx_ring_count = min_t(unsigned int, |
| 707 | netif_get_num_default_rss_queues(), |
| 708 | pdata->hw_feat.rx_ch_cnt); |
Lendacky, Thomas | 853eb16 | 2014-07-29 08:57:31 -0500 | [diff] [blame] | 709 | pdata->rx_q_count = pdata->hw_feat.rx_q_cnt; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 710 | ret = netif_set_real_num_rx_queues(netdev, pdata->rx_ring_count); |
| 711 | if (ret) { |
| 712 | dev_err(dev, "error setting real rx queue count\n"); |
| 713 | goto err_io; |
| 714 | } |
| 715 | |
Lendacky, Thomas | 5b9dfe2 | 2014-11-04 16:07:02 -0600 | [diff] [blame] | 716 | /* Initialize RSS hash key and lookup table */ |
Eric Dumazet | b230630 | 2014-11-16 06:23:06 -0800 | [diff] [blame] | 717 | netdev_rss_key_fill(pdata->rss_key, sizeof(pdata->rss_key)); |
Lendacky, Thomas | 5b9dfe2 | 2014-11-04 16:07:02 -0600 | [diff] [blame] | 718 | |
| 719 | for (i = 0; i < XGBE_RSS_MAX_TABLE_SIZE; i++) |
| 720 | XGMAC_SET_BITS(pdata->rss_table[i], MAC_RSSDR, DMCH, |
| 721 | i % pdata->rx_ring_count); |
| 722 | |
| 723 | XGMAC_SET_BITS(pdata->rss_options, MAC_RSSCR, IP2TE, 1); |
| 724 | XGMAC_SET_BITS(pdata->rss_options, MAC_RSSCR, TCP4TE, 1); |
| 725 | XGMAC_SET_BITS(pdata->rss_options, MAC_RSSCR, UDP4TE, 1); |
| 726 | |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 727 | /* Call MDIO/PHY initialization routine */ |
| 728 | pdata->phy_if.phy_init(pdata); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 729 | |
Lendacky, Thomas | fca2d99 | 2014-07-29 08:57:55 -0500 | [diff] [blame] | 730 | /* Set device operations */ |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 731 | netdev->netdev_ops = xgbe_get_netdev_ops(); |
| 732 | netdev->ethtool_ops = xgbe_get_ethtool_ops(); |
Lendacky, Thomas | fca2d99 | 2014-07-29 08:57:55 -0500 | [diff] [blame] | 733 | #ifdef CONFIG_AMD_XGBE_DCB |
| 734 | netdev->dcbnl_ops = xgbe_get_dcbnl_ops(); |
| 735 | #endif |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 736 | |
| 737 | /* Set device features */ |
| 738 | netdev->hw_features = NETIF_F_SG | |
| 739 | NETIF_F_IP_CSUM | |
| 740 | NETIF_F_IPV6_CSUM | |
| 741 | NETIF_F_RXCSUM | |
| 742 | NETIF_F_TSO | |
| 743 | NETIF_F_TSO6 | |
| 744 | NETIF_F_GRO | |
| 745 | NETIF_F_HW_VLAN_CTAG_RX | |
Lendacky, Thomas | 801c62d | 2014-06-24 16:19:24 -0500 | [diff] [blame] | 746 | NETIF_F_HW_VLAN_CTAG_TX | |
| 747 | NETIF_F_HW_VLAN_CTAG_FILTER; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 748 | |
Lendacky, Thomas | 5b9dfe2 | 2014-11-04 16:07:02 -0600 | [diff] [blame] | 749 | if (pdata->hw_feat.rss) |
| 750 | netdev->hw_features |= NETIF_F_RXHASH; |
| 751 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 752 | netdev->vlan_features |= NETIF_F_SG | |
| 753 | NETIF_F_IP_CSUM | |
| 754 | NETIF_F_IPV6_CSUM | |
| 755 | NETIF_F_TSO | |
| 756 | NETIF_F_TSO6; |
| 757 | |
| 758 | netdev->features |= netdev->hw_features; |
| 759 | pdata->netdev_features = netdev->features; |
| 760 | |
Lendacky, Thomas | b85e4d8 | 2014-06-24 16:19:29 -0500 | [diff] [blame] | 761 | netdev->priv_flags |= IFF_UNICAST_FLT; |
| 762 | |
Lendacky, Thomas | a8373f1 | 2015-04-09 12:12:03 -0500 | [diff] [blame] | 763 | /* Use default watchdog timeout */ |
| 764 | netdev->watchdog_timeo = 0; |
| 765 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 766 | xgbe_init_rx_coalesce(pdata); |
| 767 | xgbe_init_tx_coalesce(pdata); |
| 768 | |
| 769 | netif_carrier_off(netdev); |
| 770 | ret = register_netdev(netdev); |
| 771 | if (ret) { |
| 772 | dev_err(dev, "net device registration failed\n"); |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 773 | goto err_io; |
| 774 | } |
| 775 | |
| 776 | /* Create the PHY/ANEG name based on netdev name */ |
| 777 | snprintf(pdata->an_name, sizeof(pdata->an_name) - 1, "%s-pcs", |
| 778 | netdev_name(netdev)); |
| 779 | |
| 780 | /* Create workqueues */ |
| 781 | pdata->dev_workqueue = |
| 782 | create_singlethread_workqueue(netdev_name(netdev)); |
| 783 | if (!pdata->dev_workqueue) { |
| 784 | netdev_err(netdev, "device workqueue creation failed\n"); |
| 785 | ret = -ENOMEM; |
| 786 | goto err_netdev; |
| 787 | } |
| 788 | |
| 789 | pdata->an_workqueue = |
| 790 | create_singlethread_workqueue(pdata->an_name); |
| 791 | if (!pdata->an_workqueue) { |
| 792 | netdev_err(netdev, "phy workqueue creation failed\n"); |
| 793 | ret = -ENOMEM; |
| 794 | goto err_wq; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 795 | } |
| 796 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 797 | xgbe_ptp_register(pdata); |
| 798 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 799 | xgbe_debugfs_init(pdata); |
| 800 | |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 801 | platform_device_put(phy_pdev); |
| 802 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 803 | netdev_notice(netdev, "net device enabled\n"); |
| 804 | |
| 805 | DBGPR("<-- xgbe_probe\n"); |
| 806 | |
| 807 | return 0; |
| 808 | |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 809 | err_wq: |
| 810 | destroy_workqueue(pdata->dev_workqueue); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 811 | |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 812 | err_netdev: |
| 813 | unregister_netdev(netdev); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 814 | |
| 815 | err_io: |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 816 | platform_device_put(phy_pdev); |
| 817 | |
| 818 | err_phydev: |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 819 | free_netdev(netdev); |
| 820 | |
| 821 | err_alloc: |
| 822 | dev_notice(dev, "net device not enabled\n"); |
| 823 | |
| 824 | return ret; |
| 825 | } |
| 826 | |
| 827 | static int xgbe_remove(struct platform_device *pdev) |
| 828 | { |
| 829 | struct net_device *netdev = platform_get_drvdata(pdev); |
| 830 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 831 | |
| 832 | DBGPR("-->xgbe_remove\n"); |
| 833 | |
| 834 | xgbe_debugfs_exit(pdata); |
| 835 | |
Lendacky, Thomas | 23e4eef | 2014-07-29 08:57:19 -0500 | [diff] [blame] | 836 | xgbe_ptp_unregister(pdata); |
| 837 | |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 838 | flush_workqueue(pdata->an_workqueue); |
| 839 | destroy_workqueue(pdata->an_workqueue); |
| 840 | |
| 841 | flush_workqueue(pdata->dev_workqueue); |
| 842 | destroy_workqueue(pdata->dev_workqueue); |
| 843 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 844 | unregister_netdev(netdev); |
| 845 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 846 | free_netdev(netdev); |
| 847 | |
| 848 | DBGPR("<--xgbe_remove\n"); |
| 849 | |
| 850 | return 0; |
| 851 | } |
| 852 | |
| 853 | #ifdef CONFIG_PM |
| 854 | static int xgbe_suspend(struct device *dev) |
| 855 | { |
| 856 | struct net_device *netdev = dev_get_drvdata(dev); |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 857 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 858 | int ret = 0; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 859 | |
| 860 | DBGPR("-->xgbe_suspend\n"); |
| 861 | |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 862 | if (netif_running(netdev)) |
| 863 | ret = xgbe_powerdown(netdev, XGMAC_DRIVER_CONTEXT); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 864 | |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 865 | pdata->lpm_ctrl = XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_CTRL1); |
| 866 | pdata->lpm_ctrl |= MDIO_CTRL1_LPOWER; |
| 867 | XMDIO_WRITE(pdata, MDIO_MMD_PCS, MDIO_CTRL1, pdata->lpm_ctrl); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 868 | |
| 869 | DBGPR("<--xgbe_suspend\n"); |
| 870 | |
| 871 | return ret; |
| 872 | } |
| 873 | |
| 874 | static int xgbe_resume(struct device *dev) |
| 875 | { |
| 876 | struct net_device *netdev = dev_get_drvdata(dev); |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 877 | struct xgbe_prv_data *pdata = netdev_priv(netdev); |
| 878 | int ret = 0; |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 879 | |
| 880 | DBGPR("-->xgbe_resume\n"); |
| 881 | |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 882 | pdata->lpm_ctrl &= ~MDIO_CTRL1_LPOWER; |
| 883 | XMDIO_WRITE(pdata, MDIO_MMD_PCS, MDIO_CTRL1, pdata->lpm_ctrl); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 884 | |
Lendacky, Thomas | 7c12aa0 | 2015-05-14 11:44:15 -0500 | [diff] [blame] | 885 | if (netif_running(netdev)) |
| 886 | ret = xgbe_powerup(netdev, XGMAC_DRIVER_CONTEXT); |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 887 | |
| 888 | DBGPR("<--xgbe_resume\n"); |
| 889 | |
| 890 | return ret; |
| 891 | } |
| 892 | #endif /* CONFIG_PM */ |
| 893 | |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 894 | #ifdef CONFIG_ACPI |
| 895 | static const struct acpi_device_id xgbe_acpi_match[] = { |
| 896 | { "AMDI8001", 0 }, |
| 897 | {}, |
| 898 | }; |
| 899 | |
| 900 | MODULE_DEVICE_TABLE(acpi, xgbe_acpi_match); |
| 901 | #endif |
| 902 | |
| 903 | #ifdef CONFIG_OF |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 904 | static const struct of_device_id xgbe_of_match[] = { |
| 905 | { .compatible = "amd,xgbe-seattle-v1a", }, |
| 906 | {}, |
| 907 | }; |
| 908 | |
| 909 | MODULE_DEVICE_TABLE(of, xgbe_of_match); |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 910 | #endif |
| 911 | |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 912 | static SIMPLE_DEV_PM_OPS(xgbe_pm_ops, xgbe_suspend, xgbe_resume); |
| 913 | |
| 914 | static struct platform_driver xgbe_driver = { |
| 915 | .driver = { |
| 916 | .name = "amd-xgbe", |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 917 | #ifdef CONFIG_ACPI |
| 918 | .acpi_match_table = xgbe_acpi_match, |
| 919 | #endif |
| 920 | #ifdef CONFIG_OF |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 921 | .of_match_table = xgbe_of_match, |
Lendacky, Thomas | 82a1903 | 2015-01-16 12:47:16 -0600 | [diff] [blame] | 922 | #endif |
Lendacky, Thomas | c5aa9e3 | 2014-06-05 09:15:06 -0500 | [diff] [blame] | 923 | .pm = &xgbe_pm_ops, |
| 924 | }, |
| 925 | .probe = xgbe_probe, |
| 926 | .remove = xgbe_remove, |
| 927 | }; |
| 928 | |
| 929 | module_platform_driver(xgbe_driver); |