blob: ae869d41cec87f4c3e2b3bbb1f2b764e0ec88021 [file] [log] [blame]
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001/*
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, Thomas82a19032015-01-16 12:47:16 -0600126#include <linux/of_address.h>
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500127#include <linux/clk.h>
Lendacky, Thomas82a19032015-01-16 12:47:16 -0600128#include <linux/property.h>
129#include <linux/acpi.h>
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500130
131#include "xgbe.h"
132#include "xgbe-common.h"
133
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500134MODULE_AUTHOR("Tom Lendacky <thomas.lendacky@amd.com>");
135MODULE_LICENSE("Dual BSD/GPL");
136MODULE_VERSION(XGBE_DRV_VERSION);
137MODULE_DESCRIPTION(XGBE_DRV_DESC);
138
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -0500139static int debug = -1;
140module_param(debug, int, S_IWUSR | S_IRUGO);
141MODULE_PARM_DESC(debug, " Network interface message level setting");
142
143static const u32 default_msg_level = (NETIF_MSG_LINK | NETIF_MSG_IFDOWN |
144 NETIF_MSG_IFUP);
145
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500146static void xgbe_default_config(struct xgbe_prv_data *pdata)
147{
148 DBGPR("-->xgbe_default_config\n");
149
150 pdata->pblx8 = DMA_PBL_X8_ENABLE;
151 pdata->tx_sf_mode = MTL_TSF_ENABLE;
152 pdata->tx_threshold = MTL_TX_THRESHOLD_64;
153 pdata->tx_pbl = DMA_PBL_16;
154 pdata->tx_osp_mode = DMA_OSP_ENABLE;
155 pdata->rx_sf_mode = MTL_RSF_DISABLE;
156 pdata->rx_threshold = MTL_RX_THRESHOLD_64;
157 pdata->rx_pbl = DMA_PBL_16;
158 pdata->pause_autoneg = 1;
159 pdata->tx_pause = 1;
160 pdata->rx_pause = 1;
Lendacky, Thomas916102c2015-01-16 12:46:45 -0600161 pdata->phy_speed = SPEED_UNKNOWN;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500162 pdata->power_down = 0;
163 pdata->default_autoneg = AUTONEG_ENABLE;
164 pdata->default_speed = SPEED_10000;
165
166 DBGPR("<--xgbe_default_config\n");
167}
168
169static void xgbe_init_all_fptrs(struct xgbe_prv_data *pdata)
170{
171 xgbe_init_function_ptrs_dev(&pdata->hw_if);
172 xgbe_init_function_ptrs_desc(&pdata->desc_if);
173}
174
Lendacky, Thomas82a19032015-01-16 12:47:16 -0600175#ifdef CONFIG_ACPI
176static int xgbe_acpi_support(struct xgbe_prv_data *pdata)
177{
178 struct acpi_device *adev = pdata->adev;
179 struct device *dev = pdata->dev;
180 u32 property;
181 acpi_handle handle;
182 acpi_status status;
183 unsigned long long data;
184 int cca;
185 int ret;
186
187 /* Obtain the system clock setting */
188 ret = device_property_read_u32(dev, XGBE_ACPI_DMA_FREQ, &property);
189 if (ret) {
190 dev_err(dev, "unable to obtain %s property\n",
191 XGBE_ACPI_DMA_FREQ);
192 return ret;
193 }
194 pdata->sysclk_rate = property;
195
196 /* Obtain the PTP clock setting */
197 ret = device_property_read_u32(dev, XGBE_ACPI_PTP_FREQ, &property);
198 if (ret) {
199 dev_err(dev, "unable to obtain %s property\n",
200 XGBE_ACPI_PTP_FREQ);
201 return ret;
202 }
203 pdata->ptpclk_rate = property;
204
205 /* Retrieve the device cache coherency value */
206 handle = adev->handle;
207 do {
208 status = acpi_evaluate_integer(handle, "_CCA", NULL, &data);
209 if (!ACPI_FAILURE(status)) {
210 cca = data;
211 break;
212 }
213
214 status = acpi_get_parent(handle, &handle);
215 } while (!ACPI_FAILURE(status));
216
217 if (ACPI_FAILURE(status)) {
218 dev_err(dev, "error obtaining acpi coherency value\n");
219 return -EINVAL;
220 }
221 pdata->coherent = !!cca;
222
223 return 0;
224}
225#else /* CONFIG_ACPI */
226static int xgbe_acpi_support(struct xgbe_prv_data *pdata)
227{
228 return -EINVAL;
229}
230#endif /* CONFIG_ACPI */
231
232#ifdef CONFIG_OF
233static int xgbe_of_support(struct xgbe_prv_data *pdata)
234{
235 struct device *dev = pdata->dev;
236
237 /* Obtain the system clock setting */
238 pdata->sysclk = devm_clk_get(dev, XGBE_DMA_CLOCK);
239 if (IS_ERR(pdata->sysclk)) {
240 dev_err(dev, "dma devm_clk_get failed\n");
241 return PTR_ERR(pdata->sysclk);
242 }
243 pdata->sysclk_rate = clk_get_rate(pdata->sysclk);
244
245 /* Obtain the PTP clock setting */
246 pdata->ptpclk = devm_clk_get(dev, XGBE_PTP_CLOCK);
247 if (IS_ERR(pdata->ptpclk)) {
248 dev_err(dev, "ptp devm_clk_get failed\n");
249 return PTR_ERR(pdata->ptpclk);
250 }
251 pdata->ptpclk_rate = clk_get_rate(pdata->ptpclk);
252
253 /* Retrieve the device cache coherency value */
254 pdata->coherent = of_dma_is_coherent(dev->of_node);
255
256 return 0;
257}
258#else /* CONFIG_OF */
259static int xgbe_of_support(struct xgbe_prv_data *pdata)
260{
261 return -EINVAL;
262}
263#endif /*CONFIG_OF */
264
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500265static int xgbe_probe(struct platform_device *pdev)
266{
267 struct xgbe_prv_data *pdata;
268 struct xgbe_hw_if *hw_if;
269 struct xgbe_desc_if *desc_if;
270 struct net_device *netdev;
271 struct device *dev = &pdev->dev;
272 struct resource *res;
Lendacky, Thomas82a19032015-01-16 12:47:16 -0600273 const char *phy_mode;
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -0600274 unsigned int i;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500275 int ret;
276
277 DBGPR("--> xgbe_probe\n");
278
279 netdev = alloc_etherdev_mq(sizeof(struct xgbe_prv_data),
Lendacky, Thomasd5c48582014-06-09 09:19:32 -0500280 XGBE_MAX_DMA_CHANNELS);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500281 if (!netdev) {
282 dev_err(dev, "alloc_etherdev failed\n");
283 ret = -ENOMEM;
284 goto err_alloc;
285 }
286 SET_NETDEV_DEV(netdev, dev);
287 pdata = netdev_priv(netdev);
288 pdata->netdev = netdev;
289 pdata->pdev = pdev;
Lendacky, Thomas82a19032015-01-16 12:47:16 -0600290 pdata->adev = ACPI_COMPANION(dev);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500291 pdata->dev = dev;
292 platform_set_drvdata(pdev, netdev);
293
294 spin_lock_init(&pdata->lock);
295 mutex_init(&pdata->xpcs_mutex);
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -0600296 mutex_init(&pdata->rss_mutex);
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500297 spin_lock_init(&pdata->tstamp_lock);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500298
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -0500299 pdata->msg_enable = netif_msg_init(debug, default_msg_level);
300
Lendacky, Thomas82a19032015-01-16 12:47:16 -0600301 /* Check if we should use ACPI or DT */
302 pdata->use_acpi = (!pdata->adev || acpi_disabled) ? 0 : 1;
303
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500304 /* Set and validate the number of descriptors for a ring */
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -0500305 BUILD_BUG_ON_NOT_POWER_OF_2(XGBE_TX_DESC_CNT);
306 pdata->tx_desc_count = XGBE_TX_DESC_CNT;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500307 if (pdata->tx_desc_count & (pdata->tx_desc_count - 1)) {
308 dev_err(dev, "tx descriptor count (%d) is not valid\n",
309 pdata->tx_desc_count);
310 ret = -EINVAL;
311 goto err_io;
312 }
Lendacky, Thomasd0a8ba62014-06-24 16:19:06 -0500313 BUILD_BUG_ON_NOT_POWER_OF_2(XGBE_RX_DESC_CNT);
314 pdata->rx_desc_count = XGBE_RX_DESC_CNT;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500315 if (pdata->rx_desc_count & (pdata->rx_desc_count - 1)) {
316 dev_err(dev, "rx descriptor count (%d) is not valid\n",
317 pdata->rx_desc_count);
318 ret = -EINVAL;
319 goto err_io;
320 }
321
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500322 /* Obtain the mmio areas for the device */
323 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
324 pdata->xgmac_regs = devm_ioremap_resource(dev, res);
325 if (IS_ERR(pdata->xgmac_regs)) {
326 dev_err(dev, "xgmac ioremap failed\n");
327 ret = PTR_ERR(pdata->xgmac_regs);
328 goto err_io;
329 }
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -0500330 if (netif_msg_probe(pdata))
331 dev_dbg(dev, "xgmac_regs = %p\n", pdata->xgmac_regs);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500332
333 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
334 pdata->xpcs_regs = devm_ioremap_resource(dev, res);
335 if (IS_ERR(pdata->xpcs_regs)) {
336 dev_err(dev, "xpcs ioremap failed\n");
337 ret = PTR_ERR(pdata->xpcs_regs);
338 goto err_io;
339 }
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -0500340 if (netif_msg_probe(pdata))
341 dev_dbg(dev, "xpcs_regs = %p\n", pdata->xpcs_regs);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500342
Lendacky, Thomas82a19032015-01-16 12:47:16 -0600343 /* Retrieve the MAC address */
344 ret = device_property_read_u8_array(dev, XGBE_MAC_ADDR_PROPERTY,
345 pdata->mac_addr,
346 sizeof(pdata->mac_addr));
347 if (ret || !is_valid_ether_addr(pdata->mac_addr)) {
348 dev_err(dev, "invalid %s property\n", XGBE_MAC_ADDR_PROPERTY);
349 if (!ret)
350 ret = -EINVAL;
Lendacky, Thomasf3d0e782014-08-05 13:30:38 -0500351 goto err_io;
352 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500353
Lendacky, Thomas82a19032015-01-16 12:47:16 -0600354 /* Retrieve the PHY mode - it must be "xgmii" */
355 ret = device_property_read_string(dev, XGBE_PHY_MODE_PROPERTY,
356 &phy_mode);
357 if (ret || strcmp(phy_mode, phy_modes(PHY_INTERFACE_MODE_XGMII))) {
358 dev_err(dev, "invalid %s property\n", XGBE_PHY_MODE_PROPERTY);
359 if (!ret)
360 ret = -EINVAL;
361 goto err_io;
362 }
363 pdata->phy_mode = PHY_INTERFACE_MODE_XGMII;
364
365 /* Check for per channel interrupt support */
366 if (device_property_present(dev, XGBE_DMA_IRQS_PROPERTY))
367 pdata->per_channel_irq = 1;
368
369 /* Obtain device settings unique to ACPI/OF */
370 if (pdata->use_acpi)
371 ret = xgbe_acpi_support(pdata);
372 else
373 ret = xgbe_of_support(pdata);
374 if (ret)
375 goto err_io;
376
377 /* Set the DMA coherency values */
378 if (pdata->coherent) {
Lendacky, Thomascfa50c72014-07-02 13:04:57 -0500379 pdata->axdomain = XGBE_DMA_OS_AXDOMAIN;
380 pdata->arcache = XGBE_DMA_OS_ARCACHE;
381 pdata->awcache = XGBE_DMA_OS_AWCACHE;
382 } else {
383 pdata->axdomain = XGBE_DMA_SYS_AXDOMAIN;
384 pdata->arcache = XGBE_DMA_SYS_ARCACHE;
385 pdata->awcache = XGBE_DMA_SYS_AWCACHE;
386 }
387
Lendacky, Thomas82a19032015-01-16 12:47:16 -0600388 /* Get the device interrupt */
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500389 ret = platform_get_irq(pdev, 0);
390 if (ret < 0) {
Lendacky, Thomas9227dc52014-11-04 16:06:56 -0600391 dev_err(dev, "platform_get_irq 0 failed\n");
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500392 goto err_io;
393 }
Lendacky, Thomas9227dc52014-11-04 16:06:56 -0600394 pdata->dev_irq = ret;
395
396 netdev->irq = pdata->dev_irq;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500397 netdev->base_addr = (unsigned long)pdata->xgmac_regs;
Lendacky, Thomas82a19032015-01-16 12:47:16 -0600398 memcpy(netdev->dev_addr, pdata->mac_addr, netdev->addr_len);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500399
400 /* Set all the function pointers */
401 xgbe_init_all_fptrs(pdata);
402 hw_if = &pdata->hw_if;
403 desc_if = &pdata->desc_if;
404
405 /* Issue software reset to device */
406 hw_if->exit(pdata);
407
408 /* Populate the hardware features */
409 xgbe_get_all_hw_features(pdata);
410
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500411 /* Set default configuration data */
412 xgbe_default_config(pdata);
413
Lendacky, Thomas386d3252015-03-20 11:50:22 -0500414 /* Set the DMA mask */
415 if (!dev->dma_mask)
416 dev->dma_mask = &dev->coherent_dma_mask;
417 ret = dma_set_mask_and_coherent(dev,
418 DMA_BIT_MASK(pdata->hw_feat.dma_width));
419 if (ret) {
420 dev_err(dev, "dma_set_mask_and_coherent failed\n");
421 goto err_io;
422 }
423
Lendacky, Thomas853eb162014-07-29 08:57:31 -0500424 /* Calculate the number of Tx and Rx rings to be created
425 * -Tx (DMA) Channels map 1-to-1 to Tx Queues so set
426 * the number of Tx queues to the number of Tx channels
427 * enabled
428 * -Rx (DMA) Channels do not map 1-to-1 so use the actual
429 * number of Rx queues
430 */
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500431 pdata->tx_ring_count = min_t(unsigned int, num_online_cpus(),
432 pdata->hw_feat.tx_ch_cnt);
Lendacky, Thomas853eb162014-07-29 08:57:31 -0500433 pdata->tx_q_count = pdata->tx_ring_count;
Wei Yongjun332cfc82014-07-23 08:59:40 +0800434 ret = netif_set_real_num_tx_queues(netdev, pdata->tx_ring_count);
435 if (ret) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500436 dev_err(dev, "error setting real tx queue count\n");
437 goto err_io;
438 }
439
440 pdata->rx_ring_count = min_t(unsigned int,
441 netif_get_num_default_rss_queues(),
442 pdata->hw_feat.rx_ch_cnt);
Lendacky, Thomas853eb162014-07-29 08:57:31 -0500443 pdata->rx_q_count = pdata->hw_feat.rx_q_cnt;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500444 ret = netif_set_real_num_rx_queues(netdev, pdata->rx_ring_count);
445 if (ret) {
446 dev_err(dev, "error setting real rx queue count\n");
447 goto err_io;
448 }
449
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -0600450 /* Initialize RSS hash key and lookup table */
Eric Dumazetb2306302014-11-16 06:23:06 -0800451 netdev_rss_key_fill(pdata->rss_key, sizeof(pdata->rss_key));
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -0600452
453 for (i = 0; i < XGBE_RSS_MAX_TABLE_SIZE; i++)
454 XGMAC_SET_BITS(pdata->rss_table[i], MAC_RSSDR, DMCH,
455 i % pdata->rx_ring_count);
456
457 XGMAC_SET_BITS(pdata->rss_options, MAC_RSSCR, IP2TE, 1);
458 XGMAC_SET_BITS(pdata->rss_options, MAC_RSSCR, TCP4TE, 1);
459 XGMAC_SET_BITS(pdata->rss_options, MAC_RSSCR, UDP4TE, 1);
460
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500461 /* Prepare to regsiter with MDIO */
462 pdata->mii_bus_id = kasprintf(GFP_KERNEL, "%s", pdev->name);
463 if (!pdata->mii_bus_id) {
464 dev_err(dev, "failed to allocate mii bus id\n");
465 ret = -ENOMEM;
466 goto err_io;
467 }
468 ret = xgbe_mdio_register(pdata);
469 if (ret)
470 goto err_bus_id;
471
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500472 /* Set device operations */
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500473 netdev->netdev_ops = xgbe_get_netdev_ops();
474 netdev->ethtool_ops = xgbe_get_ethtool_ops();
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500475#ifdef CONFIG_AMD_XGBE_DCB
476 netdev->dcbnl_ops = xgbe_get_dcbnl_ops();
477#endif
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500478
479 /* Set device features */
480 netdev->hw_features = NETIF_F_SG |
481 NETIF_F_IP_CSUM |
482 NETIF_F_IPV6_CSUM |
483 NETIF_F_RXCSUM |
484 NETIF_F_TSO |
485 NETIF_F_TSO6 |
486 NETIF_F_GRO |
487 NETIF_F_HW_VLAN_CTAG_RX |
Lendacky, Thomas801c62d2014-06-24 16:19:24 -0500488 NETIF_F_HW_VLAN_CTAG_TX |
489 NETIF_F_HW_VLAN_CTAG_FILTER;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500490
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -0600491 if (pdata->hw_feat.rss)
492 netdev->hw_features |= NETIF_F_RXHASH;
493
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500494 netdev->vlan_features |= NETIF_F_SG |
495 NETIF_F_IP_CSUM |
496 NETIF_F_IPV6_CSUM |
497 NETIF_F_TSO |
498 NETIF_F_TSO6;
499
500 netdev->features |= netdev->hw_features;
501 pdata->netdev_features = netdev->features;
502
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500503 netdev->priv_flags |= IFF_UNICAST_FLT;
504
Lendacky, Thomasa8373f12015-04-09 12:12:03 -0500505 /* Use default watchdog timeout */
506 netdev->watchdog_timeo = 0;
507
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500508 xgbe_init_rx_coalesce(pdata);
509 xgbe_init_tx_coalesce(pdata);
510
511 netif_carrier_off(netdev);
512 ret = register_netdev(netdev);
513 if (ret) {
514 dev_err(dev, "net device registration failed\n");
515 goto err_reg_netdev;
516 }
517
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500518 xgbe_ptp_register(pdata);
519
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500520 xgbe_debugfs_init(pdata);
521
522 netdev_notice(netdev, "net device enabled\n");
523
524 DBGPR("<-- xgbe_probe\n");
525
526 return 0;
527
528err_reg_netdev:
529 xgbe_mdio_unregister(pdata);
530
531err_bus_id:
532 kfree(pdata->mii_bus_id);
533
534err_io:
535 free_netdev(netdev);
536
537err_alloc:
538 dev_notice(dev, "net device not enabled\n");
539
540 return ret;
541}
542
543static int xgbe_remove(struct platform_device *pdev)
544{
545 struct net_device *netdev = platform_get_drvdata(pdev);
546 struct xgbe_prv_data *pdata = netdev_priv(netdev);
547
548 DBGPR("-->xgbe_remove\n");
549
550 xgbe_debugfs_exit(pdata);
551
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500552 xgbe_ptp_unregister(pdata);
553
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500554 unregister_netdev(netdev);
555
556 xgbe_mdio_unregister(pdata);
557
558 kfree(pdata->mii_bus_id);
559
560 free_netdev(netdev);
561
562 DBGPR("<--xgbe_remove\n");
563
564 return 0;
565}
566
567#ifdef CONFIG_PM
568static int xgbe_suspend(struct device *dev)
569{
570 struct net_device *netdev = dev_get_drvdata(dev);
571 int ret;
572
573 DBGPR("-->xgbe_suspend\n");
574
575 if (!netif_running(netdev)) {
576 DBGPR("<--xgbe_dev_suspend\n");
577 return -EINVAL;
578 }
579
580 ret = xgbe_powerdown(netdev, XGMAC_DRIVER_CONTEXT);
581
582 DBGPR("<--xgbe_suspend\n");
583
584 return ret;
585}
586
587static int xgbe_resume(struct device *dev)
588{
589 struct net_device *netdev = dev_get_drvdata(dev);
590 int ret;
591
592 DBGPR("-->xgbe_resume\n");
593
594 if (!netif_running(netdev)) {
595 DBGPR("<--xgbe_dev_resume\n");
596 return -EINVAL;
597 }
598
599 ret = xgbe_powerup(netdev, XGMAC_DRIVER_CONTEXT);
600
601 DBGPR("<--xgbe_resume\n");
602
603 return ret;
604}
605#endif /* CONFIG_PM */
606
Lendacky, Thomas82a19032015-01-16 12:47:16 -0600607#ifdef CONFIG_ACPI
608static const struct acpi_device_id xgbe_acpi_match[] = {
609 { "AMDI8001", 0 },
610 {},
611};
612
613MODULE_DEVICE_TABLE(acpi, xgbe_acpi_match);
614#endif
615
616#ifdef CONFIG_OF
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500617static const struct of_device_id xgbe_of_match[] = {
618 { .compatible = "amd,xgbe-seattle-v1a", },
619 {},
620};
621
622MODULE_DEVICE_TABLE(of, xgbe_of_match);
Lendacky, Thomas82a19032015-01-16 12:47:16 -0600623#endif
624
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500625static SIMPLE_DEV_PM_OPS(xgbe_pm_ops, xgbe_suspend, xgbe_resume);
626
627static struct platform_driver xgbe_driver = {
628 .driver = {
629 .name = "amd-xgbe",
Lendacky, Thomas82a19032015-01-16 12:47:16 -0600630#ifdef CONFIG_ACPI
631 .acpi_match_table = xgbe_acpi_match,
632#endif
633#ifdef CONFIG_OF
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500634 .of_match_table = xgbe_of_match,
Lendacky, Thomas82a19032015-01-16 12:47:16 -0600635#endif
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500636 .pm = &xgbe_pm_ops,
637 },
638 .probe = xgbe_probe,
639 .remove = xgbe_remove,
640};
641
642module_platform_driver(xgbe_driver);