blob: 385b7f6052007491a64c21858035ecb101b68092 [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 *
Lendacky, Thomasced3fca2016-02-17 11:49:28 -06009 * Copyright (c) 2014-2016 Advanced Micro Devices, Inc.
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -050010 *
11 * This file is free software; you may copy, redistribute and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 2 of the License, or (at
14 * your option) any later version.
15 *
16 * This file is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 *
24 * This file incorporates work covered by the following copyright and
25 * permission notice:
26 * The Synopsys DWC ETHER XGMAC Software Driver and documentation
27 * (hereinafter "Software") is an unsupported proprietary work of Synopsys,
28 * Inc. unless otherwise expressly agreed to in writing between Synopsys
29 * and you.
30 *
31 * The Software IS NOT an item of Licensed Software or Licensed Product
32 * under any End User Software License Agreement or Agreement for Licensed
33 * Product with Synopsys or any supplement thereto. Permission is hereby
34 * granted, free of charge, to any person obtaining a copy of this software
35 * annotated with this license and the Software, to deal in the Software
36 * without restriction, including without limitation the rights to use,
37 * copy, modify, merge, publish, distribute, sublicense, and/or sell copies
38 * of the Software, and to permit persons to whom the Software is furnished
39 * to do so, subject to the following conditions:
40 *
41 * The above copyright notice and this permission notice shall be included
42 * in all copies or substantial portions of the Software.
43 *
44 * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
45 * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
46 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
47 * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS
48 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
49 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
50 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
51 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
52 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
53 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
54 * THE POSSIBILITY OF SUCH DAMAGE.
55 *
56 *
57 * License 2: Modified BSD
58 *
Lendacky, Thomasced3fca2016-02-17 11:49:28 -060059 * Copyright (c) 2014-2016 Advanced Micro Devices, Inc.
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -050060 * 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>
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500119#include <linux/spinlock.h>
120#include <linux/netdevice.h>
121#include <linux/etherdevice.h>
122#include <linux/io.h>
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500123
124#include "xgbe.h"
125#include "xgbe-common.h"
126
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500127MODULE_AUTHOR("Tom Lendacky <thomas.lendacky@amd.com>");
128MODULE_LICENSE("Dual BSD/GPL");
129MODULE_VERSION(XGBE_DRV_VERSION);
130MODULE_DESCRIPTION(XGBE_DRV_DESC);
131
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -0500132static int debug = -1;
133module_param(debug, int, S_IWUSR | S_IRUGO);
134MODULE_PARM_DESC(debug, " Network interface message level setting");
135
136static const u32 default_msg_level = (NETIF_MSG_LINK | NETIF_MSG_IFDOWN |
137 NETIF_MSG_IFUP);
138
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500139static void xgbe_default_config(struct xgbe_prv_data *pdata)
140{
141 DBGPR("-->xgbe_default_config\n");
142
143 pdata->pblx8 = DMA_PBL_X8_ENABLE;
144 pdata->tx_sf_mode = MTL_TSF_ENABLE;
145 pdata->tx_threshold = MTL_TX_THRESHOLD_64;
146 pdata->tx_pbl = DMA_PBL_16;
147 pdata->tx_osp_mode = DMA_OSP_ENABLE;
148 pdata->rx_sf_mode = MTL_RSF_DISABLE;
149 pdata->rx_threshold = MTL_RX_THRESHOLD_64;
150 pdata->rx_pbl = DMA_PBL_16;
151 pdata->pause_autoneg = 1;
152 pdata->tx_pause = 1;
153 pdata->rx_pause = 1;
Lendacky, Thomas916102c2015-01-16 12:46:45 -0600154 pdata->phy_speed = SPEED_UNKNOWN;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500155 pdata->power_down = 0;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500156
157 DBGPR("<--xgbe_default_config\n");
158}
159
160static void xgbe_init_all_fptrs(struct xgbe_prv_data *pdata)
161{
162 xgbe_init_function_ptrs_dev(&pdata->hw_if);
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500163 xgbe_init_function_ptrs_phy(&pdata->phy_if);
Lendacky, Thomas5ab1dcd2016-11-10 17:10:36 -0600164 xgbe_init_function_ptrs_i2c(&pdata->i2c_if);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500165 xgbe_init_function_ptrs_desc(&pdata->desc_if);
Lendacky, Thomase57f7a32016-11-03 13:18:27 -0500166
167 pdata->vdata->init_function_ptrs_phy_impl(&pdata->phy_if);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500168}
169
Lendacky, Thomasbd8255d2016-11-03 13:19:27 -0500170struct xgbe_prv_data *xgbe_alloc_pdata(struct device *dev)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500171{
172 struct xgbe_prv_data *pdata;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500173 struct net_device *netdev;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500174
175 netdev = alloc_etherdev_mq(sizeof(struct xgbe_prv_data),
Lendacky, Thomasd5c48582014-06-09 09:19:32 -0500176 XGBE_MAX_DMA_CHANNELS);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500177 if (!netdev) {
Lendacky, Thomasbd8255d2016-11-03 13:19:27 -0500178 dev_err(dev, "alloc_etherdev_mq failed\n");
179 return ERR_PTR(-ENOMEM);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500180 }
181 SET_NETDEV_DEV(netdev, dev);
182 pdata = netdev_priv(netdev);
183 pdata->netdev = netdev;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500184 pdata->dev = dev;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500185
186 spin_lock_init(&pdata->lock);
Lendacky, Thomasced3fca2016-02-17 11:49:28 -0600187 spin_lock_init(&pdata->xpcs_lock);
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -0600188 mutex_init(&pdata->rss_mutex);
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500189 spin_lock_init(&pdata->tstamp_lock);
Lendacky, Thomas5ab1dcd2016-11-10 17:10:36 -0600190 mutex_init(&pdata->i2c_mutex);
191 init_completion(&pdata->i2c_complete);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500192
Lendacky, Thomas34bf65d2015-05-14 11:44:03 -0500193 pdata->msg_enable = netif_msg_init(debug, default_msg_level);
194
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500195 set_bit(XGBE_DOWN, &pdata->dev_state);
Lendacky, Thomase78332b2016-11-10 17:10:26 -0600196 set_bit(XGBE_STOPPED, &pdata->dev_state);
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500197
Lendacky, Thomasbd8255d2016-11-03 13:19:27 -0500198 return pdata;
199}
Lendacky, Thomas82a19032015-01-16 12:47:16 -0600200
Lendacky, Thomasbd8255d2016-11-03 13:19:27 -0500201void xgbe_free_pdata(struct xgbe_prv_data *pdata)
202{
203 struct net_device *netdev = pdata->netdev;
Lendacky, Thomase57f7a32016-11-03 13:18:27 -0500204
Lendacky, Thomasbd8255d2016-11-03 13:19:27 -0500205 free_netdev(netdev);
206}
207
208void xgbe_set_counts(struct xgbe_prv_data *pdata)
209{
210 /* Set all the function pointers */
211 xgbe_init_all_fptrs(pdata);
212
213 /* Populate the hardware features */
214 xgbe_get_all_hw_features(pdata);
215
216 /* Set default max values if not provided */
217 if (!pdata->tx_max_channel_count)
218 pdata->tx_max_channel_count = pdata->hw_feat.tx_ch_cnt;
219 if (!pdata->rx_max_channel_count)
220 pdata->rx_max_channel_count = pdata->hw_feat.rx_ch_cnt;
221
222 if (!pdata->tx_max_q_count)
223 pdata->tx_max_q_count = pdata->hw_feat.tx_q_cnt;
224 if (!pdata->rx_max_q_count)
225 pdata->rx_max_q_count = pdata->hw_feat.rx_q_cnt;
226
227 /* Calculate the number of Tx and Rx rings to be created
228 * -Tx (DMA) Channels map 1-to-1 to Tx Queues so set
229 * the number of Tx queues to the number of Tx channels
230 * enabled
231 * -Rx (DMA) Channels do not map 1-to-1 so use the actual
232 * number of Rx queues or maximum allowed
233 */
234 pdata->tx_ring_count = min_t(unsigned int, num_online_cpus(),
235 pdata->hw_feat.tx_ch_cnt);
236 pdata->tx_ring_count = min_t(unsigned int, pdata->tx_ring_count,
237 pdata->tx_max_channel_count);
238 pdata->tx_ring_count = min_t(unsigned int, pdata->tx_ring_count,
239 pdata->tx_max_q_count);
240
241 pdata->tx_q_count = pdata->tx_ring_count;
242
Lendacky, Thomas8d6b2e92016-11-10 17:10:05 -0600243 pdata->rx_ring_count = min_t(unsigned int, num_online_cpus(),
Lendacky, Thomasbd8255d2016-11-03 13:19:27 -0500244 pdata->hw_feat.rx_ch_cnt);
245 pdata->rx_ring_count = min_t(unsigned int, pdata->rx_ring_count,
246 pdata->rx_max_channel_count);
247
248 pdata->rx_q_count = min_t(unsigned int, pdata->hw_feat.rx_q_cnt,
249 pdata->rx_max_q_count);
250
251 if (netif_msg_probe(pdata)) {
252 dev_dbg(pdata->dev, "TX/RX DMA channel count = %u/%u\n",
253 pdata->tx_ring_count, pdata->rx_ring_count);
254 dev_dbg(pdata->dev, "TX/RX hardware queue count = %u/%u\n",
255 pdata->tx_q_count, pdata->rx_q_count);
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500256 }
Lendacky, Thomasbd8255d2016-11-03 13:19:27 -0500257}
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500258
Lendacky, Thomasbd8255d2016-11-03 13:19:27 -0500259int xgbe_config_netdev(struct xgbe_prv_data *pdata)
260{
261 struct net_device *netdev = pdata->netdev;
262 struct device *dev = pdata->dev;
263 unsigned int i;
264 int ret;
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500265
Lendacky, Thomas9227dc52014-11-04 16:06:56 -0600266 netdev->irq = pdata->dev_irq;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500267 netdev->base_addr = (unsigned long)pdata->xgmac_regs;
Lendacky, Thomas82a19032015-01-16 12:47:16 -0600268 memcpy(netdev->dev_addr, pdata->mac_addr, netdev->addr_len);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500269
Lendacky, Thomase78332b2016-11-10 17:10:26 -0600270 /* Initialize ECC timestamps */
271 pdata->tx_sec_period = jiffies;
272 pdata->tx_ded_period = jiffies;
273 pdata->rx_sec_period = jiffies;
274 pdata->rx_ded_period = jiffies;
275 pdata->desc_sec_period = jiffies;
276 pdata->desc_ded_period = jiffies;
277
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500278 /* Issue software reset to device */
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500279 pdata->hw_if.exit(pdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500280
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500281 /* Set default configuration data */
282 xgbe_default_config(pdata);
283
Lendacky, Thomas386d3252015-03-20 11:50:22 -0500284 /* Set the DMA mask */
Lendacky, Thomas386d3252015-03-20 11:50:22 -0500285 ret = dma_set_mask_and_coherent(dev,
286 DMA_BIT_MASK(pdata->hw_feat.dma_width));
287 if (ret) {
288 dev_err(dev, "dma_set_mask_and_coherent failed\n");
Lendacky, Thomasbd8255d2016-11-03 13:19:27 -0500289 return ret;
Lendacky, Thomas386d3252015-03-20 11:50:22 -0500290 }
291
Lendacky, Thomasbd8255d2016-11-03 13:19:27 -0500292 /* Set default max values if not provided */
293 if (!pdata->tx_max_fifo_size)
294 pdata->tx_max_fifo_size = pdata->hw_feat.tx_fifo_size;
295 if (!pdata->rx_max_fifo_size)
296 pdata->rx_max_fifo_size = pdata->hw_feat.rx_fifo_size;
297
298 /* Set and validate the number of descriptors for a ring */
299 BUILD_BUG_ON_NOT_POWER_OF_2(XGBE_TX_DESC_CNT);
300 pdata->tx_desc_count = XGBE_TX_DESC_CNT;
301
302 BUILD_BUG_ON_NOT_POWER_OF_2(XGBE_RX_DESC_CNT);
303 pdata->rx_desc_count = XGBE_RX_DESC_CNT;
304
Lendacky, Thomas47f164d2016-11-10 17:09:55 -0600305 /* Adjust the number of queues based on interrupts assigned */
306 if (pdata->channel_irq_count) {
307 pdata->tx_ring_count = min_t(unsigned int, pdata->tx_ring_count,
308 pdata->channel_irq_count);
309 pdata->rx_ring_count = min_t(unsigned int, pdata->rx_ring_count,
310 pdata->channel_irq_count);
311
312 if (netif_msg_probe(pdata))
313 dev_dbg(pdata->dev,
314 "adjusted TX/RX DMA channel count = %u/%u\n",
315 pdata->tx_ring_count, pdata->rx_ring_count);
316 }
317
Lendacky, Thomasbd8255d2016-11-03 13:19:27 -0500318 /* Set the number of queues */
Wei Yongjun332cfc82014-07-23 08:59:40 +0800319 ret = netif_set_real_num_tx_queues(netdev, pdata->tx_ring_count);
320 if (ret) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500321 dev_err(dev, "error setting real tx queue count\n");
Lendacky, Thomasbd8255d2016-11-03 13:19:27 -0500322 return ret;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500323 }
324
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500325 ret = netif_set_real_num_rx_queues(netdev, pdata->rx_ring_count);
326 if (ret) {
327 dev_err(dev, "error setting real rx queue count\n");
Lendacky, Thomasbd8255d2016-11-03 13:19:27 -0500328 return ret;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500329 }
330
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -0600331 /* Initialize RSS hash key and lookup table */
Eric Dumazetb2306302014-11-16 06:23:06 -0800332 netdev_rss_key_fill(pdata->rss_key, sizeof(pdata->rss_key));
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -0600333
334 for (i = 0; i < XGBE_RSS_MAX_TABLE_SIZE; i++)
335 XGMAC_SET_BITS(pdata->rss_table[i], MAC_RSSDR, DMCH,
336 i % pdata->rx_ring_count);
337
338 XGMAC_SET_BITS(pdata->rss_options, MAC_RSSCR, IP2TE, 1);
339 XGMAC_SET_BITS(pdata->rss_options, MAC_RSSCR, TCP4TE, 1);
340 XGMAC_SET_BITS(pdata->rss_options, MAC_RSSCR, UDP4TE, 1);
341
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500342 /* Call MDIO/PHY initialization routine */
Lendacky, Thomase57f7a32016-11-03 13:18:27 -0500343 ret = pdata->phy_if.phy_init(pdata);
344 if (ret)
Lendacky, Thomasbd8255d2016-11-03 13:19:27 -0500345 return ret;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500346
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500347 /* Set device operations */
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500348 netdev->netdev_ops = xgbe_get_netdev_ops();
349 netdev->ethtool_ops = xgbe_get_ethtool_ops();
Lendacky, Thomasfca2d992014-07-29 08:57:55 -0500350#ifdef CONFIG_AMD_XGBE_DCB
351 netdev->dcbnl_ops = xgbe_get_dcbnl_ops();
352#endif
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500353
354 /* Set device features */
355 netdev->hw_features = NETIF_F_SG |
356 NETIF_F_IP_CSUM |
357 NETIF_F_IPV6_CSUM |
358 NETIF_F_RXCSUM |
359 NETIF_F_TSO |
360 NETIF_F_TSO6 |
361 NETIF_F_GRO |
362 NETIF_F_HW_VLAN_CTAG_RX |
Lendacky, Thomas801c62d2014-06-24 16:19:24 -0500363 NETIF_F_HW_VLAN_CTAG_TX |
364 NETIF_F_HW_VLAN_CTAG_FILTER;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500365
Lendacky, Thomas5b9dfe22014-11-04 16:07:02 -0600366 if (pdata->hw_feat.rss)
367 netdev->hw_features |= NETIF_F_RXHASH;
368
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500369 netdev->vlan_features |= NETIF_F_SG |
370 NETIF_F_IP_CSUM |
371 NETIF_F_IPV6_CSUM |
372 NETIF_F_TSO |
373 NETIF_F_TSO6;
374
375 netdev->features |= netdev->hw_features;
376 pdata->netdev_features = netdev->features;
377
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500378 netdev->priv_flags |= IFF_UNICAST_FLT;
Jarod Wilsond894be52016-10-20 13:55:16 -0400379 netdev->min_mtu = 0;
380 netdev->max_mtu = XGMAC_JUMBO_PACKET_MTU;
Lendacky, Thomasb85e4d82014-06-24 16:19:29 -0500381
Lendacky, Thomasa8373f12015-04-09 12:12:03 -0500382 /* Use default watchdog timeout */
383 netdev->watchdog_timeo = 0;
384
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500385 xgbe_init_rx_coalesce(pdata);
386 xgbe_init_tx_coalesce(pdata);
387
388 netif_carrier_off(netdev);
389 ret = register_netdev(netdev);
390 if (ret) {
391 dev_err(dev, "net device registration failed\n");
Lendacky, Thomasbd8255d2016-11-03 13:19:27 -0500392 return ret;
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500393 }
394
395 /* Create the PHY/ANEG name based on netdev name */
396 snprintf(pdata->an_name, sizeof(pdata->an_name) - 1, "%s-pcs",
397 netdev_name(netdev));
398
Lendacky, Thomase78332b2016-11-10 17:10:26 -0600399 /* Create the ECC name based on netdev name */
400 snprintf(pdata->ecc_name, sizeof(pdata->ecc_name) - 1, "%s-ecc",
401 netdev_name(netdev));
402
Lendacky, Thomas5ab1dcd2016-11-10 17:10:36 -0600403 /* Create the I2C name based on netdev name */
404 snprintf(pdata->i2c_name, sizeof(pdata->i2c_name) - 1, "%s-i2c",
405 netdev_name(netdev));
406
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500407 /* Create workqueues */
408 pdata->dev_workqueue =
409 create_singlethread_workqueue(netdev_name(netdev));
410 if (!pdata->dev_workqueue) {
411 netdev_err(netdev, "device workqueue creation failed\n");
412 ret = -ENOMEM;
413 goto err_netdev;
414 }
415
416 pdata->an_workqueue =
417 create_singlethread_workqueue(pdata->an_name);
418 if (!pdata->an_workqueue) {
419 netdev_err(netdev, "phy workqueue creation failed\n");
420 ret = -ENOMEM;
421 goto err_wq;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500422 }
423
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500424 xgbe_ptp_register(pdata);
425
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500426 xgbe_debugfs_init(pdata);
427
Lendacky, Thomas47f164d2016-11-10 17:09:55 -0600428 netif_dbg(pdata, drv, pdata->netdev, "%u Tx software queues\n",
429 pdata->tx_ring_count);
430 netif_dbg(pdata, drv, pdata->netdev, "%u Rx software queues\n",
431 pdata->rx_ring_count);
432
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500433 return 0;
434
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500435err_wq:
436 destroy_workqueue(pdata->dev_workqueue);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500437
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500438err_netdev:
439 unregister_netdev(netdev);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500440
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500441 return ret;
442}
443
Lendacky, Thomasbd8255d2016-11-03 13:19:27 -0500444void xgbe_deconfig_netdev(struct xgbe_prv_data *pdata)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500445{
Lendacky, Thomasbd8255d2016-11-03 13:19:27 -0500446 struct net_device *netdev = pdata->netdev;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500447
448 xgbe_debugfs_exit(pdata);
449
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500450 xgbe_ptp_unregister(pdata);
451
Lendacky, Thomase57f7a32016-11-03 13:18:27 -0500452 pdata->phy_if.phy_exit(pdata);
453
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500454 flush_workqueue(pdata->an_workqueue);
455 destroy_workqueue(pdata->an_workqueue);
456
457 flush_workqueue(pdata->dev_workqueue);
458 destroy_workqueue(pdata->dev_workqueue);
459
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500460 unregister_netdev(netdev);
Lendacky, Thomasbd8255d2016-11-03 13:19:27 -0500461}
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500462
Lendacky, Thomasbd8255d2016-11-03 13:19:27 -0500463static int __init xgbe_mod_init(void)
464{
465 int ret;
Lendacky, Thomase57f7a32016-11-03 13:18:27 -0500466
Lendacky, Thomasbd8255d2016-11-03 13:19:27 -0500467 ret = xgbe_platform_init();
468 if (ret)
469 return ret;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500470
Lendacky, Thomas47f164d2016-11-10 17:09:55 -0600471 ret = xgbe_pci_init();
472 if (ret)
473 return ret;
474
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500475 return 0;
476}
477
Lendacky, Thomasbd8255d2016-11-03 13:19:27 -0500478static void __exit xgbe_mod_exit(void)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500479{
Lendacky, Thomas47f164d2016-11-10 17:09:55 -0600480 xgbe_pci_exit();
481
Lendacky, Thomasbd8255d2016-11-03 13:19:27 -0500482 xgbe_platform_exit();
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500483}
484
Lendacky, Thomasbd8255d2016-11-03 13:19:27 -0500485module_init(xgbe_mod_init);
486module_exit(xgbe_mod_exit);