xgbe-main.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  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. #include <linux/module.h>
  117. #include <linux/device.h>
  118. #include <linux/platform_device.h>
  119. #include <linux/spinlock.h>
  120. #include <linux/netdevice.h>
  121. #include <linux/etherdevice.h>
  122. #include <linux/io.h>
  123. #include <linux/of.h>
  124. #include <linux/of_net.h>
  125. #include <linux/of_address.h>
  126. #include <linux/clk.h>
  127. #include <linux/property.h>
  128. #include <linux/acpi.h>
  129. #include "xgbe.h"
  130. #include "xgbe-common.h"
  131. MODULE_AUTHOR("Tom Lendacky <thomas.lendacky@amd.com>");
  132. MODULE_LICENSE("Dual BSD/GPL");
  133. MODULE_VERSION(XGBE_DRV_VERSION);
  134. MODULE_DESCRIPTION(XGBE_DRV_DESC);
  135. static void xgbe_default_config(struct xgbe_prv_data *pdata)
  136. {
  137. DBGPR("-->xgbe_default_config\n");
  138. pdata->pblx8 = DMA_PBL_X8_ENABLE;
  139. pdata->tx_sf_mode = MTL_TSF_ENABLE;
  140. pdata->tx_threshold = MTL_TX_THRESHOLD_64;
  141. pdata->tx_pbl = DMA_PBL_16;
  142. pdata->tx_osp_mode = DMA_OSP_ENABLE;
  143. pdata->rx_sf_mode = MTL_RSF_DISABLE;
  144. pdata->rx_threshold = MTL_RX_THRESHOLD_64;
  145. pdata->rx_pbl = DMA_PBL_16;
  146. pdata->pause_autoneg = 1;
  147. pdata->tx_pause = 1;
  148. pdata->rx_pause = 1;
  149. pdata->phy_speed = SPEED_UNKNOWN;
  150. pdata->power_down = 0;
  151. pdata->default_autoneg = AUTONEG_ENABLE;
  152. pdata->default_speed = SPEED_10000;
  153. DBGPR("<--xgbe_default_config\n");
  154. }
  155. static void xgbe_init_all_fptrs(struct xgbe_prv_data *pdata)
  156. {
  157. xgbe_init_function_ptrs_dev(&pdata->hw_if);
  158. xgbe_init_function_ptrs_desc(&pdata->desc_if);
  159. }
  160. #ifdef CONFIG_ACPI
  161. static int xgbe_acpi_support(struct xgbe_prv_data *pdata)
  162. {
  163. struct acpi_device *adev = pdata->adev;
  164. struct device *dev = pdata->dev;
  165. u32 property;
  166. acpi_handle handle;
  167. acpi_status status;
  168. unsigned long long data;
  169. int cca;
  170. int ret;
  171. /* Obtain the system clock setting */
  172. ret = device_property_read_u32(dev, XGBE_ACPI_DMA_FREQ, &property);
  173. if (ret) {
  174. dev_err(dev, "unable to obtain %s property\n",
  175. XGBE_ACPI_DMA_FREQ);
  176. return ret;
  177. }
  178. pdata->sysclk_rate = property;
  179. /* Obtain the PTP clock setting */
  180. ret = device_property_read_u32(dev, XGBE_ACPI_PTP_FREQ, &property);
  181. if (ret) {
  182. dev_err(dev, "unable to obtain %s property\n",
  183. XGBE_ACPI_PTP_FREQ);
  184. return ret;
  185. }
  186. pdata->ptpclk_rate = property;
  187. /* Retrieve the device cache coherency value */
  188. handle = adev->handle;
  189. do {
  190. status = acpi_evaluate_integer(handle, "_CCA", NULL, &data);
  191. if (!ACPI_FAILURE(status)) {
  192. cca = data;
  193. break;
  194. }
  195. status = acpi_get_parent(handle, &handle);
  196. } while (!ACPI_FAILURE(status));
  197. if (ACPI_FAILURE(status)) {
  198. dev_err(dev, "error obtaining acpi coherency value\n");
  199. return -EINVAL;
  200. }
  201. pdata->coherent = !!cca;
  202. return 0;
  203. }
  204. #else /* CONFIG_ACPI */
  205. static int xgbe_acpi_support(struct xgbe_prv_data *pdata)
  206. {
  207. return -EINVAL;
  208. }
  209. #endif /* CONFIG_ACPI */
  210. #ifdef CONFIG_OF
  211. static int xgbe_of_support(struct xgbe_prv_data *pdata)
  212. {
  213. struct device *dev = pdata->dev;
  214. /* Obtain the system clock setting */
  215. pdata->sysclk = devm_clk_get(dev, XGBE_DMA_CLOCK);
  216. if (IS_ERR(pdata->sysclk)) {
  217. dev_err(dev, "dma devm_clk_get failed\n");
  218. return PTR_ERR(pdata->sysclk);
  219. }
  220. pdata->sysclk_rate = clk_get_rate(pdata->sysclk);
  221. /* Obtain the PTP clock setting */
  222. pdata->ptpclk = devm_clk_get(dev, XGBE_PTP_CLOCK);
  223. if (IS_ERR(pdata->ptpclk)) {
  224. dev_err(dev, "ptp devm_clk_get failed\n");
  225. return PTR_ERR(pdata->ptpclk);
  226. }
  227. pdata->ptpclk_rate = clk_get_rate(pdata->ptpclk);
  228. /* Retrieve the device cache coherency value */
  229. pdata->coherent = of_dma_is_coherent(dev->of_node);
  230. return 0;
  231. }
  232. #else /* CONFIG_OF */
  233. static int xgbe_of_support(struct xgbe_prv_data *pdata)
  234. {
  235. return -EINVAL;
  236. }
  237. #endif /*CONFIG_OF */
  238. static int xgbe_probe(struct platform_device *pdev)
  239. {
  240. struct xgbe_prv_data *pdata;
  241. struct xgbe_hw_if *hw_if;
  242. struct xgbe_desc_if *desc_if;
  243. struct net_device *netdev;
  244. struct device *dev = &pdev->dev;
  245. struct resource *res;
  246. const char *phy_mode;
  247. unsigned int i;
  248. int ret;
  249. DBGPR("--> xgbe_probe\n");
  250. netdev = alloc_etherdev_mq(sizeof(struct xgbe_prv_data),
  251. XGBE_MAX_DMA_CHANNELS);
  252. if (!netdev) {
  253. dev_err(dev, "alloc_etherdev failed\n");
  254. ret = -ENOMEM;
  255. goto err_alloc;
  256. }
  257. SET_NETDEV_DEV(netdev, dev);
  258. pdata = netdev_priv(netdev);
  259. pdata->netdev = netdev;
  260. pdata->pdev = pdev;
  261. pdata->adev = ACPI_COMPANION(dev);
  262. pdata->dev = dev;
  263. platform_set_drvdata(pdev, netdev);
  264. spin_lock_init(&pdata->lock);
  265. mutex_init(&pdata->xpcs_mutex);
  266. mutex_init(&pdata->rss_mutex);
  267. spin_lock_init(&pdata->tstamp_lock);
  268. /* Check if we should use ACPI or DT */
  269. pdata->use_acpi = (!pdata->adev || acpi_disabled) ? 0 : 1;
  270. /* Set and validate the number of descriptors for a ring */
  271. BUILD_BUG_ON_NOT_POWER_OF_2(XGBE_TX_DESC_CNT);
  272. pdata->tx_desc_count = XGBE_TX_DESC_CNT;
  273. if (pdata->tx_desc_count & (pdata->tx_desc_count - 1)) {
  274. dev_err(dev, "tx descriptor count (%d) is not valid\n",
  275. pdata->tx_desc_count);
  276. ret = -EINVAL;
  277. goto err_io;
  278. }
  279. BUILD_BUG_ON_NOT_POWER_OF_2(XGBE_RX_DESC_CNT);
  280. pdata->rx_desc_count = XGBE_RX_DESC_CNT;
  281. if (pdata->rx_desc_count & (pdata->rx_desc_count - 1)) {
  282. dev_err(dev, "rx descriptor count (%d) is not valid\n",
  283. pdata->rx_desc_count);
  284. ret = -EINVAL;
  285. goto err_io;
  286. }
  287. /* Obtain the mmio areas for the device */
  288. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  289. pdata->xgmac_regs = devm_ioremap_resource(dev, res);
  290. if (IS_ERR(pdata->xgmac_regs)) {
  291. dev_err(dev, "xgmac ioremap failed\n");
  292. ret = PTR_ERR(pdata->xgmac_regs);
  293. goto err_io;
  294. }
  295. DBGPR(" xgmac_regs = %p\n", pdata->xgmac_regs);
  296. res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  297. pdata->xpcs_regs = devm_ioremap_resource(dev, res);
  298. if (IS_ERR(pdata->xpcs_regs)) {
  299. dev_err(dev, "xpcs ioremap failed\n");
  300. ret = PTR_ERR(pdata->xpcs_regs);
  301. goto err_io;
  302. }
  303. DBGPR(" xpcs_regs = %p\n", pdata->xpcs_regs);
  304. /* Retrieve the MAC address */
  305. ret = device_property_read_u8_array(dev, XGBE_MAC_ADDR_PROPERTY,
  306. pdata->mac_addr,
  307. sizeof(pdata->mac_addr));
  308. if (ret || !is_valid_ether_addr(pdata->mac_addr)) {
  309. dev_err(dev, "invalid %s property\n", XGBE_MAC_ADDR_PROPERTY);
  310. if (!ret)
  311. ret = -EINVAL;
  312. goto err_io;
  313. }
  314. /* Retrieve the PHY mode - it must be "xgmii" */
  315. ret = device_property_read_string(dev, XGBE_PHY_MODE_PROPERTY,
  316. &phy_mode);
  317. if (ret || strcmp(phy_mode, phy_modes(PHY_INTERFACE_MODE_XGMII))) {
  318. dev_err(dev, "invalid %s property\n", XGBE_PHY_MODE_PROPERTY);
  319. if (!ret)
  320. ret = -EINVAL;
  321. goto err_io;
  322. }
  323. pdata->phy_mode = PHY_INTERFACE_MODE_XGMII;
  324. /* Check for per channel interrupt support */
  325. if (device_property_present(dev, XGBE_DMA_IRQS_PROPERTY))
  326. pdata->per_channel_irq = 1;
  327. /* Obtain device settings unique to ACPI/OF */
  328. if (pdata->use_acpi)
  329. ret = xgbe_acpi_support(pdata);
  330. else
  331. ret = xgbe_of_support(pdata);
  332. if (ret)
  333. goto err_io;
  334. /* Set the DMA coherency values */
  335. if (pdata->coherent) {
  336. pdata->axdomain = XGBE_DMA_OS_AXDOMAIN;
  337. pdata->arcache = XGBE_DMA_OS_ARCACHE;
  338. pdata->awcache = XGBE_DMA_OS_AWCACHE;
  339. } else {
  340. pdata->axdomain = XGBE_DMA_SYS_AXDOMAIN;
  341. pdata->arcache = XGBE_DMA_SYS_ARCACHE;
  342. pdata->awcache = XGBE_DMA_SYS_AWCACHE;
  343. }
  344. /* Get the device interrupt */
  345. ret = platform_get_irq(pdev, 0);
  346. if (ret < 0) {
  347. dev_err(dev, "platform_get_irq 0 failed\n");
  348. goto err_io;
  349. }
  350. pdata->dev_irq = ret;
  351. netdev->irq = pdata->dev_irq;
  352. netdev->base_addr = (unsigned long)pdata->xgmac_regs;
  353. memcpy(netdev->dev_addr, pdata->mac_addr, netdev->addr_len);
  354. /* Set all the function pointers */
  355. xgbe_init_all_fptrs(pdata);
  356. hw_if = &pdata->hw_if;
  357. desc_if = &pdata->desc_if;
  358. /* Issue software reset to device */
  359. hw_if->exit(pdata);
  360. /* Populate the hardware features */
  361. xgbe_get_all_hw_features(pdata);
  362. /* Set default configuration data */
  363. xgbe_default_config(pdata);
  364. /* Set the DMA mask */
  365. if (!dev->dma_mask)
  366. dev->dma_mask = &dev->coherent_dma_mask;
  367. ret = dma_set_mask_and_coherent(dev,
  368. DMA_BIT_MASK(pdata->hw_feat.dma_width));
  369. if (ret) {
  370. dev_err(dev, "dma_set_mask_and_coherent failed\n");
  371. goto err_io;
  372. }
  373. /* Calculate the number of Tx and Rx rings to be created
  374. * -Tx (DMA) Channels map 1-to-1 to Tx Queues so set
  375. * the number of Tx queues to the number of Tx channels
  376. * enabled
  377. * -Rx (DMA) Channels do not map 1-to-1 so use the actual
  378. * number of Rx queues
  379. */
  380. pdata->tx_ring_count = min_t(unsigned int, num_online_cpus(),
  381. pdata->hw_feat.tx_ch_cnt);
  382. pdata->tx_q_count = pdata->tx_ring_count;
  383. ret = netif_set_real_num_tx_queues(netdev, pdata->tx_ring_count);
  384. if (ret) {
  385. dev_err(dev, "error setting real tx queue count\n");
  386. goto err_io;
  387. }
  388. pdata->rx_ring_count = min_t(unsigned int,
  389. netif_get_num_default_rss_queues(),
  390. pdata->hw_feat.rx_ch_cnt);
  391. pdata->rx_q_count = pdata->hw_feat.rx_q_cnt;
  392. ret = netif_set_real_num_rx_queues(netdev, pdata->rx_ring_count);
  393. if (ret) {
  394. dev_err(dev, "error setting real rx queue count\n");
  395. goto err_io;
  396. }
  397. /* Initialize RSS hash key and lookup table */
  398. netdev_rss_key_fill(pdata->rss_key, sizeof(pdata->rss_key));
  399. for (i = 0; i < XGBE_RSS_MAX_TABLE_SIZE; i++)
  400. XGMAC_SET_BITS(pdata->rss_table[i], MAC_RSSDR, DMCH,
  401. i % pdata->rx_ring_count);
  402. XGMAC_SET_BITS(pdata->rss_options, MAC_RSSCR, IP2TE, 1);
  403. XGMAC_SET_BITS(pdata->rss_options, MAC_RSSCR, TCP4TE, 1);
  404. XGMAC_SET_BITS(pdata->rss_options, MAC_RSSCR, UDP4TE, 1);
  405. /* Prepare to regsiter with MDIO */
  406. pdata->mii_bus_id = kasprintf(GFP_KERNEL, "%s", pdev->name);
  407. if (!pdata->mii_bus_id) {
  408. dev_err(dev, "failed to allocate mii bus id\n");
  409. ret = -ENOMEM;
  410. goto err_io;
  411. }
  412. ret = xgbe_mdio_register(pdata);
  413. if (ret)
  414. goto err_bus_id;
  415. /* Set device operations */
  416. netdev->netdev_ops = xgbe_get_netdev_ops();
  417. netdev->ethtool_ops = xgbe_get_ethtool_ops();
  418. #ifdef CONFIG_AMD_XGBE_DCB
  419. netdev->dcbnl_ops = xgbe_get_dcbnl_ops();
  420. #endif
  421. /* Set device features */
  422. netdev->hw_features = NETIF_F_SG |
  423. NETIF_F_IP_CSUM |
  424. NETIF_F_IPV6_CSUM |
  425. NETIF_F_RXCSUM |
  426. NETIF_F_TSO |
  427. NETIF_F_TSO6 |
  428. NETIF_F_GRO |
  429. NETIF_F_HW_VLAN_CTAG_RX |
  430. NETIF_F_HW_VLAN_CTAG_TX |
  431. NETIF_F_HW_VLAN_CTAG_FILTER;
  432. if (pdata->hw_feat.rss)
  433. netdev->hw_features |= NETIF_F_RXHASH;
  434. netdev->vlan_features |= NETIF_F_SG |
  435. NETIF_F_IP_CSUM |
  436. NETIF_F_IPV6_CSUM |
  437. NETIF_F_TSO |
  438. NETIF_F_TSO6;
  439. netdev->features |= netdev->hw_features;
  440. pdata->netdev_features = netdev->features;
  441. netdev->priv_flags |= IFF_UNICAST_FLT;
  442. /* Use default watchdog timeout */
  443. netdev->watchdog_timeo = 0;
  444. xgbe_init_rx_coalesce(pdata);
  445. xgbe_init_tx_coalesce(pdata);
  446. netif_carrier_off(netdev);
  447. ret = register_netdev(netdev);
  448. if (ret) {
  449. dev_err(dev, "net device registration failed\n");
  450. goto err_reg_netdev;
  451. }
  452. xgbe_ptp_register(pdata);
  453. xgbe_debugfs_init(pdata);
  454. netdev_notice(netdev, "net device enabled\n");
  455. DBGPR("<-- xgbe_probe\n");
  456. return 0;
  457. err_reg_netdev:
  458. xgbe_mdio_unregister(pdata);
  459. err_bus_id:
  460. kfree(pdata->mii_bus_id);
  461. err_io:
  462. free_netdev(netdev);
  463. err_alloc:
  464. dev_notice(dev, "net device not enabled\n");
  465. return ret;
  466. }
  467. static int xgbe_remove(struct platform_device *pdev)
  468. {
  469. struct net_device *netdev = platform_get_drvdata(pdev);
  470. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  471. DBGPR("-->xgbe_remove\n");
  472. xgbe_debugfs_exit(pdata);
  473. xgbe_ptp_unregister(pdata);
  474. unregister_netdev(netdev);
  475. xgbe_mdio_unregister(pdata);
  476. kfree(pdata->mii_bus_id);
  477. free_netdev(netdev);
  478. DBGPR("<--xgbe_remove\n");
  479. return 0;
  480. }
  481. #ifdef CONFIG_PM
  482. static int xgbe_suspend(struct device *dev)
  483. {
  484. struct net_device *netdev = dev_get_drvdata(dev);
  485. int ret;
  486. DBGPR("-->xgbe_suspend\n");
  487. if (!netif_running(netdev)) {
  488. DBGPR("<--xgbe_dev_suspend\n");
  489. return -EINVAL;
  490. }
  491. ret = xgbe_powerdown(netdev, XGMAC_DRIVER_CONTEXT);
  492. DBGPR("<--xgbe_suspend\n");
  493. return ret;
  494. }
  495. static int xgbe_resume(struct device *dev)
  496. {
  497. struct net_device *netdev = dev_get_drvdata(dev);
  498. int ret;
  499. DBGPR("-->xgbe_resume\n");
  500. if (!netif_running(netdev)) {
  501. DBGPR("<--xgbe_dev_resume\n");
  502. return -EINVAL;
  503. }
  504. ret = xgbe_powerup(netdev, XGMAC_DRIVER_CONTEXT);
  505. DBGPR("<--xgbe_resume\n");
  506. return ret;
  507. }
  508. #endif /* CONFIG_PM */
  509. #ifdef CONFIG_ACPI
  510. static const struct acpi_device_id xgbe_acpi_match[] = {
  511. { "AMDI8001", 0 },
  512. {},
  513. };
  514. MODULE_DEVICE_TABLE(acpi, xgbe_acpi_match);
  515. #endif
  516. #ifdef CONFIG_OF
  517. static const struct of_device_id xgbe_of_match[] = {
  518. { .compatible = "amd,xgbe-seattle-v1a", },
  519. {},
  520. };
  521. MODULE_DEVICE_TABLE(of, xgbe_of_match);
  522. #endif
  523. static SIMPLE_DEV_PM_OPS(xgbe_pm_ops, xgbe_suspend, xgbe_resume);
  524. static struct platform_driver xgbe_driver = {
  525. .driver = {
  526. .name = "amd-xgbe",
  527. #ifdef CONFIG_ACPI
  528. .acpi_match_table = xgbe_acpi_match,
  529. #endif
  530. #ifdef CONFIG_OF
  531. .of_match_table = xgbe_of_match,
  532. #endif
  533. .pm = &xgbe_pm_ops,
  534. },
  535. .probe = xgbe_probe,
  536. .remove = xgbe_remove,
  537. };
  538. module_platform_driver(xgbe_driver);