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