xgbe-pci.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  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) 2016 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) 2016 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/pci.h>
  119. #include <linux/log2.h>
  120. #include "xgbe.h"
  121. #include "xgbe-common.h"
  122. static int xgbe_config_multi_msi(struct xgbe_prv_data *pdata)
  123. {
  124. unsigned int vector_count;
  125. unsigned int i, j;
  126. int ret;
  127. vector_count = XGBE_MSI_BASE_COUNT;
  128. vector_count += max(pdata->rx_ring_count,
  129. pdata->tx_ring_count);
  130. ret = pci_alloc_irq_vectors(pdata->pcidev, XGBE_MSI_MIN_COUNT,
  131. vector_count, PCI_IRQ_MSI | PCI_IRQ_MSIX);
  132. if (ret < 0) {
  133. dev_info(pdata->dev, "multi MSI/MSI-X enablement failed\n");
  134. return ret;
  135. }
  136. pdata->isr_as_tasklet = 1;
  137. pdata->irq_count = ret;
  138. pdata->dev_irq = pci_irq_vector(pdata->pcidev, 0);
  139. pdata->ecc_irq = pci_irq_vector(pdata->pcidev, 1);
  140. pdata->i2c_irq = pci_irq_vector(pdata->pcidev, 2);
  141. pdata->an_irq = pci_irq_vector(pdata->pcidev, 3);
  142. for (i = XGBE_MSI_BASE_COUNT, j = 0; i < ret; i++, j++)
  143. pdata->channel_irq[j] = pci_irq_vector(pdata->pcidev, i);
  144. pdata->channel_irq_count = j;
  145. pdata->per_channel_irq = 1;
  146. pdata->channel_irq_mode = XGBE_IRQ_MODE_LEVEL;
  147. if (netif_msg_probe(pdata))
  148. dev_dbg(pdata->dev, "multi %s interrupts enabled\n",
  149. pdata->pcidev->msix_enabled ? "MSI-X" : "MSI");
  150. return 0;
  151. }
  152. static int xgbe_config_irqs(struct xgbe_prv_data *pdata)
  153. {
  154. int ret;
  155. ret = xgbe_config_multi_msi(pdata);
  156. if (!ret)
  157. goto out;
  158. ret = pci_alloc_irq_vectors(pdata->pcidev, 1, 1,
  159. PCI_IRQ_LEGACY | PCI_IRQ_MSI);
  160. if (ret < 0) {
  161. dev_info(pdata->dev, "single IRQ enablement failed\n");
  162. return ret;
  163. }
  164. pdata->isr_as_tasklet = pdata->pcidev->msi_enabled ? 1 : 0;
  165. pdata->irq_count = 1;
  166. pdata->channel_irq_count = 1;
  167. pdata->dev_irq = pci_irq_vector(pdata->pcidev, 0);
  168. pdata->ecc_irq = pci_irq_vector(pdata->pcidev, 0);
  169. pdata->i2c_irq = pci_irq_vector(pdata->pcidev, 0);
  170. pdata->an_irq = pci_irq_vector(pdata->pcidev, 0);
  171. if (netif_msg_probe(pdata))
  172. dev_dbg(pdata->dev, "single %s interrupt enabled\n",
  173. pdata->pcidev->msi_enabled ? "MSI" : "legacy");
  174. out:
  175. if (netif_msg_probe(pdata)) {
  176. unsigned int i;
  177. dev_dbg(pdata->dev, " dev irq=%d\n", pdata->dev_irq);
  178. dev_dbg(pdata->dev, " ecc irq=%d\n", pdata->ecc_irq);
  179. dev_dbg(pdata->dev, " i2c irq=%d\n", pdata->i2c_irq);
  180. dev_dbg(pdata->dev, " an irq=%d\n", pdata->an_irq);
  181. for (i = 0; i < pdata->channel_irq_count; i++)
  182. dev_dbg(pdata->dev, " dma%u irq=%d\n",
  183. i, pdata->channel_irq[i]);
  184. }
  185. return 0;
  186. }
  187. static int xgbe_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  188. {
  189. struct xgbe_prv_data *pdata;
  190. struct device *dev = &pdev->dev;
  191. void __iomem * const *iomap_table;
  192. struct pci_dev *rdev;
  193. unsigned int ma_lo, ma_hi;
  194. unsigned int reg;
  195. int bar_mask;
  196. int ret;
  197. pdata = xgbe_alloc_pdata(dev);
  198. if (IS_ERR(pdata)) {
  199. ret = PTR_ERR(pdata);
  200. goto err_alloc;
  201. }
  202. pdata->pcidev = pdev;
  203. pci_set_drvdata(pdev, pdata);
  204. /* Get the version data */
  205. pdata->vdata = (struct xgbe_version_data *)id->driver_data;
  206. ret = pcim_enable_device(pdev);
  207. if (ret) {
  208. dev_err(dev, "pcim_enable_device failed\n");
  209. goto err_pci_enable;
  210. }
  211. /* Obtain the mmio areas for the device */
  212. bar_mask = pci_select_bars(pdev, IORESOURCE_MEM);
  213. ret = pcim_iomap_regions(pdev, bar_mask, XGBE_DRV_NAME);
  214. if (ret) {
  215. dev_err(dev, "pcim_iomap_regions failed\n");
  216. goto err_pci_enable;
  217. }
  218. iomap_table = pcim_iomap_table(pdev);
  219. if (!iomap_table) {
  220. dev_err(dev, "pcim_iomap_table failed\n");
  221. ret = -ENOMEM;
  222. goto err_pci_enable;
  223. }
  224. pdata->xgmac_regs = iomap_table[XGBE_XGMAC_BAR];
  225. if (!pdata->xgmac_regs) {
  226. dev_err(dev, "xgmac ioremap failed\n");
  227. ret = -ENOMEM;
  228. goto err_pci_enable;
  229. }
  230. pdata->xprop_regs = pdata->xgmac_regs + XGBE_MAC_PROP_OFFSET;
  231. pdata->xi2c_regs = pdata->xgmac_regs + XGBE_I2C_CTRL_OFFSET;
  232. if (netif_msg_probe(pdata)) {
  233. dev_dbg(dev, "xgmac_regs = %p\n", pdata->xgmac_regs);
  234. dev_dbg(dev, "xprop_regs = %p\n", pdata->xprop_regs);
  235. dev_dbg(dev, "xi2c_regs = %p\n", pdata->xi2c_regs);
  236. }
  237. pdata->xpcs_regs = iomap_table[XGBE_XPCS_BAR];
  238. if (!pdata->xpcs_regs) {
  239. dev_err(dev, "xpcs ioremap failed\n");
  240. ret = -ENOMEM;
  241. goto err_pci_enable;
  242. }
  243. if (netif_msg_probe(pdata))
  244. dev_dbg(dev, "xpcs_regs = %p\n", pdata->xpcs_regs);
  245. /* Set the PCS indirect addressing definition registers */
  246. rdev = pci_get_domain_bus_and_slot(0, 0, PCI_DEVFN(0, 0));
  247. if (rdev &&
  248. (rdev->vendor == PCI_VENDOR_ID_AMD) && (rdev->device == 0x15d0)) {
  249. pdata->xpcs_window_def_reg = PCS_V2_RV_WINDOW_DEF;
  250. pdata->xpcs_window_sel_reg = PCS_V2_RV_WINDOW_SELECT;
  251. } else if (rdev && (rdev->vendor == PCI_VENDOR_ID_AMD) &&
  252. (rdev->device == 0x14b5)) {
  253. pdata->xpcs_window_def_reg = PCS_V2_YC_WINDOW_DEF;
  254. pdata->xpcs_window_sel_reg = PCS_V2_YC_WINDOW_SELECT;
  255. /* Yellow Carp devices do not need cdr workaround */
  256. pdata->vdata->an_cdr_workaround = 0;
  257. /* Yellow Carp devices do not need rrc */
  258. pdata->vdata->enable_rrc = 0;
  259. } else {
  260. pdata->xpcs_window_def_reg = PCS_V2_WINDOW_DEF;
  261. pdata->xpcs_window_sel_reg = PCS_V2_WINDOW_SELECT;
  262. }
  263. pci_dev_put(rdev);
  264. /* Configure the PCS indirect addressing support */
  265. reg = XPCS32_IOREAD(pdata, pdata->xpcs_window_def_reg);
  266. pdata->xpcs_window = XPCS_GET_BITS(reg, PCS_V2_WINDOW_DEF, OFFSET);
  267. pdata->xpcs_window <<= 6;
  268. pdata->xpcs_window_size = XPCS_GET_BITS(reg, PCS_V2_WINDOW_DEF, SIZE);
  269. pdata->xpcs_window_size = 1 << (pdata->xpcs_window_size + 7);
  270. pdata->xpcs_window_mask = pdata->xpcs_window_size - 1;
  271. if (netif_msg_probe(pdata)) {
  272. dev_dbg(dev, "xpcs window def = %#010x\n",
  273. pdata->xpcs_window_def_reg);
  274. dev_dbg(dev, "xpcs window sel = %#010x\n",
  275. pdata->xpcs_window_sel_reg);
  276. dev_dbg(dev, "xpcs window = %#010x\n",
  277. pdata->xpcs_window);
  278. dev_dbg(dev, "xpcs window size = %#010x\n",
  279. pdata->xpcs_window_size);
  280. dev_dbg(dev, "xpcs window mask = %#010x\n",
  281. pdata->xpcs_window_mask);
  282. }
  283. pci_set_master(pdev);
  284. /* Enable all interrupts in the hardware */
  285. XP_IOWRITE(pdata, XP_INT_EN, 0x1fffff);
  286. /* Retrieve the MAC address */
  287. ma_lo = XP_IOREAD(pdata, XP_MAC_ADDR_LO);
  288. ma_hi = XP_IOREAD(pdata, XP_MAC_ADDR_HI);
  289. pdata->mac_addr[0] = ma_lo & 0xff;
  290. pdata->mac_addr[1] = (ma_lo >> 8) & 0xff;
  291. pdata->mac_addr[2] = (ma_lo >> 16) & 0xff;
  292. pdata->mac_addr[3] = (ma_lo >> 24) & 0xff;
  293. pdata->mac_addr[4] = ma_hi & 0xff;
  294. pdata->mac_addr[5] = (ma_hi >> 8) & 0xff;
  295. if (!XP_GET_BITS(ma_hi, XP_MAC_ADDR_HI, VALID) ||
  296. !is_valid_ether_addr(pdata->mac_addr)) {
  297. dev_err(dev, "invalid mac address\n");
  298. ret = -EINVAL;
  299. goto err_pci_enable;
  300. }
  301. /* Clock settings */
  302. pdata->sysclk_rate = XGBE_V2_DMA_CLOCK_FREQ;
  303. pdata->ptpclk_rate = XGBE_V2_PTP_CLOCK_FREQ;
  304. /* Set the DMA coherency values */
  305. pdata->coherent = 1;
  306. pdata->arcr = XGBE_DMA_PCI_ARCR;
  307. pdata->awcr = XGBE_DMA_PCI_AWCR;
  308. pdata->awarcr = XGBE_DMA_PCI_AWARCR;
  309. /* Read the port property registers */
  310. pdata->pp0 = XP_IOREAD(pdata, XP_PROP_0);
  311. pdata->pp1 = XP_IOREAD(pdata, XP_PROP_1);
  312. pdata->pp2 = XP_IOREAD(pdata, XP_PROP_2);
  313. pdata->pp3 = XP_IOREAD(pdata, XP_PROP_3);
  314. pdata->pp4 = XP_IOREAD(pdata, XP_PROP_4);
  315. if (netif_msg_probe(pdata)) {
  316. dev_dbg(dev, "port property 0 = %#010x\n", pdata->pp0);
  317. dev_dbg(dev, "port property 1 = %#010x\n", pdata->pp1);
  318. dev_dbg(dev, "port property 2 = %#010x\n", pdata->pp2);
  319. dev_dbg(dev, "port property 3 = %#010x\n", pdata->pp3);
  320. dev_dbg(dev, "port property 4 = %#010x\n", pdata->pp4);
  321. }
  322. /* Set the maximum channels and queues */
  323. pdata->tx_max_channel_count = XP_GET_BITS(pdata->pp1, XP_PROP_1,
  324. MAX_TX_DMA);
  325. pdata->rx_max_channel_count = XP_GET_BITS(pdata->pp1, XP_PROP_1,
  326. MAX_RX_DMA);
  327. pdata->tx_max_q_count = XP_GET_BITS(pdata->pp1, XP_PROP_1,
  328. MAX_TX_QUEUES);
  329. pdata->rx_max_q_count = XP_GET_BITS(pdata->pp1, XP_PROP_1,
  330. MAX_RX_QUEUES);
  331. if (netif_msg_probe(pdata)) {
  332. dev_dbg(dev, "max tx/rx channel count = %u/%u\n",
  333. pdata->tx_max_channel_count,
  334. pdata->rx_max_channel_count);
  335. dev_dbg(dev, "max tx/rx hw queue count = %u/%u\n",
  336. pdata->tx_max_q_count, pdata->rx_max_q_count);
  337. }
  338. /* Set the hardware channel and queue counts */
  339. xgbe_set_counts(pdata);
  340. /* Set the maximum fifo amounts */
  341. pdata->tx_max_fifo_size = XP_GET_BITS(pdata->pp2, XP_PROP_2,
  342. TX_FIFO_SIZE);
  343. pdata->tx_max_fifo_size *= 16384;
  344. pdata->tx_max_fifo_size = min(pdata->tx_max_fifo_size,
  345. pdata->vdata->tx_max_fifo_size);
  346. pdata->rx_max_fifo_size = XP_GET_BITS(pdata->pp2, XP_PROP_2,
  347. RX_FIFO_SIZE);
  348. pdata->rx_max_fifo_size *= 16384;
  349. pdata->rx_max_fifo_size = min(pdata->rx_max_fifo_size,
  350. pdata->vdata->rx_max_fifo_size);
  351. if (netif_msg_probe(pdata))
  352. dev_dbg(dev, "max tx/rx max fifo size = %u/%u\n",
  353. pdata->tx_max_fifo_size, pdata->rx_max_fifo_size);
  354. /* Configure interrupt support */
  355. ret = xgbe_config_irqs(pdata);
  356. if (ret)
  357. goto err_pci_enable;
  358. /* Configure the netdev resource */
  359. ret = xgbe_config_netdev(pdata);
  360. if (ret)
  361. goto err_irq_vectors;
  362. netdev_notice(pdata->netdev, "net device enabled\n");
  363. return 0;
  364. err_irq_vectors:
  365. pci_free_irq_vectors(pdata->pcidev);
  366. err_pci_enable:
  367. xgbe_free_pdata(pdata);
  368. err_alloc:
  369. dev_notice(dev, "net device not enabled\n");
  370. return ret;
  371. }
  372. static void xgbe_pci_remove(struct pci_dev *pdev)
  373. {
  374. struct xgbe_prv_data *pdata = pci_get_drvdata(pdev);
  375. xgbe_deconfig_netdev(pdata);
  376. pci_free_irq_vectors(pdata->pcidev);
  377. /* Disable all interrupts in the hardware */
  378. XP_IOWRITE(pdata, XP_INT_EN, 0x0);
  379. xgbe_free_pdata(pdata);
  380. }
  381. static int __maybe_unused xgbe_pci_suspend(struct device *dev)
  382. {
  383. struct xgbe_prv_data *pdata = dev_get_drvdata(dev);
  384. struct net_device *netdev = pdata->netdev;
  385. int ret = 0;
  386. if (netif_running(netdev))
  387. ret = xgbe_powerdown(netdev, XGMAC_DRIVER_CONTEXT);
  388. pdata->lpm_ctrl = XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_CTRL1);
  389. pdata->lpm_ctrl |= MDIO_CTRL1_LPOWER;
  390. XMDIO_WRITE(pdata, MDIO_MMD_PCS, MDIO_CTRL1, pdata->lpm_ctrl);
  391. return ret;
  392. }
  393. static int __maybe_unused xgbe_pci_resume(struct device *dev)
  394. {
  395. struct xgbe_prv_data *pdata = dev_get_drvdata(dev);
  396. struct net_device *netdev = pdata->netdev;
  397. int ret = 0;
  398. XP_IOWRITE(pdata, XP_INT_EN, 0x1fffff);
  399. pdata->lpm_ctrl &= ~MDIO_CTRL1_LPOWER;
  400. XMDIO_WRITE(pdata, MDIO_MMD_PCS, MDIO_CTRL1, pdata->lpm_ctrl);
  401. if (netif_running(netdev)) {
  402. ret = xgbe_powerup(netdev, XGMAC_DRIVER_CONTEXT);
  403. /* Schedule a restart in case the link or phy state changed
  404. * while we were powered down.
  405. */
  406. schedule_work(&pdata->restart_work);
  407. }
  408. return ret;
  409. }
  410. static struct xgbe_version_data xgbe_v2a = {
  411. .init_function_ptrs_phy_impl = xgbe_init_function_ptrs_phy_v2,
  412. .xpcs_access = XGBE_XPCS_ACCESS_V2,
  413. .mmc_64bit = 1,
  414. .tx_max_fifo_size = 229376,
  415. .rx_max_fifo_size = 229376,
  416. .tx_tstamp_workaround = 1,
  417. .ecc_support = 1,
  418. .i2c_support = 1,
  419. .irq_reissue_support = 1,
  420. .tx_desc_prefetch = 5,
  421. .rx_desc_prefetch = 5,
  422. .an_cdr_workaround = 1,
  423. .enable_rrc = 1,
  424. };
  425. static struct xgbe_version_data xgbe_v2b = {
  426. .init_function_ptrs_phy_impl = xgbe_init_function_ptrs_phy_v2,
  427. .xpcs_access = XGBE_XPCS_ACCESS_V2,
  428. .mmc_64bit = 1,
  429. .tx_max_fifo_size = 65536,
  430. .rx_max_fifo_size = 65536,
  431. .tx_tstamp_workaround = 1,
  432. .ecc_support = 1,
  433. .i2c_support = 1,
  434. .irq_reissue_support = 1,
  435. .tx_desc_prefetch = 5,
  436. .rx_desc_prefetch = 5,
  437. .an_cdr_workaround = 1,
  438. .enable_rrc = 1,
  439. };
  440. static const struct pci_device_id xgbe_pci_table[] = {
  441. { PCI_VDEVICE(AMD, 0x1458),
  442. .driver_data = (kernel_ulong_t)&xgbe_v2a },
  443. { PCI_VDEVICE(AMD, 0x1459),
  444. .driver_data = (kernel_ulong_t)&xgbe_v2b },
  445. /* Last entry must be zero */
  446. { 0, }
  447. };
  448. MODULE_DEVICE_TABLE(pci, xgbe_pci_table);
  449. static SIMPLE_DEV_PM_OPS(xgbe_pci_pm_ops, xgbe_pci_suspend, xgbe_pci_resume);
  450. static struct pci_driver xgbe_driver = {
  451. .name = XGBE_DRV_NAME,
  452. .id_table = xgbe_pci_table,
  453. .probe = xgbe_pci_probe,
  454. .remove = xgbe_pci_remove,
  455. .driver = {
  456. .pm = &xgbe_pci_pm_ops,
  457. }
  458. };
  459. int xgbe_pci_init(void)
  460. {
  461. return pci_register_driver(&xgbe_driver);
  462. }
  463. void xgbe_pci_exit(void)
  464. {
  465. pci_unregister_driver(&xgbe_driver);
  466. }