147f164deSLendacky, Thomas /* 247f164deSLendacky, Thomas * AMD 10Gb Ethernet driver 347f164deSLendacky, Thomas * 447f164deSLendacky, Thomas * This file is available to you under your choice of the following two 547f164deSLendacky, Thomas * licenses: 647f164deSLendacky, Thomas * 747f164deSLendacky, Thomas * License 1: GPLv2 847f164deSLendacky, Thomas * 947f164deSLendacky, Thomas * Copyright (c) 2016 Advanced Micro Devices, Inc. 1047f164deSLendacky, Thomas * 1147f164deSLendacky, Thomas * This file is free software; you may copy, redistribute and/or modify 1247f164deSLendacky, Thomas * it under the terms of the GNU General Public License as published by 1347f164deSLendacky, Thomas * the Free Software Foundation, either version 2 of the License, or (at 1447f164deSLendacky, Thomas * your option) any later version. 1547f164deSLendacky, Thomas * 1647f164deSLendacky, Thomas * This file is distributed in the hope that it will be useful, but 1747f164deSLendacky, Thomas * WITHOUT ANY WARRANTY; without even the implied warranty of 1847f164deSLendacky, Thomas * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1947f164deSLendacky, Thomas * General Public License for more details. 2047f164deSLendacky, Thomas * 2147f164deSLendacky, Thomas * You should have received a copy of the GNU General Public License 2247f164deSLendacky, Thomas * along with this program. If not, see <http://www.gnu.org/licenses/>. 2347f164deSLendacky, Thomas * 2447f164deSLendacky, Thomas * This file incorporates work covered by the following copyright and 2547f164deSLendacky, Thomas * permission notice: 2647f164deSLendacky, Thomas * The Synopsys DWC ETHER XGMAC Software Driver and documentation 2747f164deSLendacky, Thomas * (hereinafter "Software") is an unsupported proprietary work of Synopsys, 2847f164deSLendacky, Thomas * Inc. unless otherwise expressly agreed to in writing between Synopsys 2947f164deSLendacky, Thomas * and you. 3047f164deSLendacky, Thomas * 3147f164deSLendacky, Thomas * The Software IS NOT an item of Licensed Software or Licensed Product 3247f164deSLendacky, Thomas * under any End User Software License Agreement or Agreement for Licensed 3347f164deSLendacky, Thomas * Product with Synopsys or any supplement thereto. Permission is hereby 3447f164deSLendacky, Thomas * granted, free of charge, to any person obtaining a copy of this software 3547f164deSLendacky, Thomas * annotated with this license and the Software, to deal in the Software 3647f164deSLendacky, Thomas * without restriction, including without limitation the rights to use, 3747f164deSLendacky, Thomas * copy, modify, merge, publish, distribute, sublicense, and/or sell copies 3847f164deSLendacky, Thomas * of the Software, and to permit persons to whom the Software is furnished 3947f164deSLendacky, Thomas * to do so, subject to the following conditions: 4047f164deSLendacky, Thomas * 4147f164deSLendacky, Thomas * The above copyright notice and this permission notice shall be included 4247f164deSLendacky, Thomas * in all copies or substantial portions of the Software. 4347f164deSLendacky, Thomas * 4447f164deSLendacky, Thomas * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" 4547f164deSLendacky, Thomas * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 4647f164deSLendacky, Thomas * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 4747f164deSLendacky, Thomas * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS 4847f164deSLendacky, Thomas * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 4947f164deSLendacky, Thomas * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 5047f164deSLendacky, Thomas * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 5147f164deSLendacky, Thomas * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 5247f164deSLendacky, Thomas * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 5347f164deSLendacky, Thomas * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 5447f164deSLendacky, Thomas * THE POSSIBILITY OF SUCH DAMAGE. 5547f164deSLendacky, Thomas * 5647f164deSLendacky, Thomas * 5747f164deSLendacky, Thomas * License 2: Modified BSD 5847f164deSLendacky, Thomas * 5947f164deSLendacky, Thomas * Copyright (c) 2016 Advanced Micro Devices, Inc. 6047f164deSLendacky, Thomas * All rights reserved. 6147f164deSLendacky, Thomas * 6247f164deSLendacky, Thomas * Redistribution and use in source and binary forms, with or without 6347f164deSLendacky, Thomas * modification, are permitted provided that the following conditions are met: 6447f164deSLendacky, Thomas * * Redistributions of source code must retain the above copyright 6547f164deSLendacky, Thomas * notice, this list of conditions and the following disclaimer. 6647f164deSLendacky, Thomas * * Redistributions in binary form must reproduce the above copyright 6747f164deSLendacky, Thomas * notice, this list of conditions and the following disclaimer in the 6847f164deSLendacky, Thomas * documentation and/or other materials provided with the distribution. 6947f164deSLendacky, Thomas * * Neither the name of Advanced Micro Devices, Inc. nor the 7047f164deSLendacky, Thomas * names of its contributors may be used to endorse or promote products 7147f164deSLendacky, Thomas * derived from this software without specific prior written permission. 7247f164deSLendacky, Thomas * 7347f164deSLendacky, Thomas * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 7447f164deSLendacky, Thomas * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 7547f164deSLendacky, Thomas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 7647f164deSLendacky, Thomas * ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY 7747f164deSLendacky, Thomas * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 7847f164deSLendacky, Thomas * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 7947f164deSLendacky, Thomas * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 8047f164deSLendacky, Thomas * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 8147f164deSLendacky, Thomas * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 8247f164deSLendacky, Thomas * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 8347f164deSLendacky, Thomas * 8447f164deSLendacky, Thomas * This file incorporates work covered by the following copyright and 8547f164deSLendacky, Thomas * permission notice: 8647f164deSLendacky, Thomas * The Synopsys DWC ETHER XGMAC Software Driver and documentation 8747f164deSLendacky, Thomas * (hereinafter "Software") is an unsupported proprietary work of Synopsys, 8847f164deSLendacky, Thomas * Inc. unless otherwise expressly agreed to in writing between Synopsys 8947f164deSLendacky, Thomas * and you. 9047f164deSLendacky, Thomas * 9147f164deSLendacky, Thomas * The Software IS NOT an item of Licensed Software or Licensed Product 9247f164deSLendacky, Thomas * under any End User Software License Agreement or Agreement for Licensed 9347f164deSLendacky, Thomas * Product with Synopsys or any supplement thereto. Permission is hereby 9447f164deSLendacky, Thomas * granted, free of charge, to any person obtaining a copy of this software 9547f164deSLendacky, Thomas * annotated with this license and the Software, to deal in the Software 9647f164deSLendacky, Thomas * without restriction, including without limitation the rights to use, 9747f164deSLendacky, Thomas * copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9847f164deSLendacky, Thomas * of the Software, and to permit persons to whom the Software is furnished 9947f164deSLendacky, Thomas * to do so, subject to the following conditions: 10047f164deSLendacky, Thomas * 10147f164deSLendacky, Thomas * The above copyright notice and this permission notice shall be included 10247f164deSLendacky, Thomas * in all copies or substantial portions of the Software. 10347f164deSLendacky, Thomas * 10447f164deSLendacky, Thomas * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" 10547f164deSLendacky, Thomas * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 10647f164deSLendacky, Thomas * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 10747f164deSLendacky, Thomas * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS 10847f164deSLendacky, Thomas * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 10947f164deSLendacky, Thomas * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 11047f164deSLendacky, Thomas * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 11147f164deSLendacky, Thomas * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 11247f164deSLendacky, Thomas * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 11347f164deSLendacky, Thomas * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 11447f164deSLendacky, Thomas * THE POSSIBILITY OF SUCH DAMAGE. 11547f164deSLendacky, Thomas */ 11647f164deSLendacky, Thomas 11747f164deSLendacky, Thomas #include <linux/module.h> 11847f164deSLendacky, Thomas #include <linux/device.h> 11947f164deSLendacky, Thomas #include <linux/pci.h> 12047f164deSLendacky, Thomas #include <linux/log2.h> 12147f164deSLendacky, Thomas 12247f164deSLendacky, Thomas #include "xgbe.h" 12347f164deSLendacky, Thomas #include "xgbe-common.h" 12447f164deSLendacky, Thomas 125e7537740STom Lendacky static int xgbe_config_multi_msi(struct xgbe_prv_data *pdata) 12647f164deSLendacky, Thomas { 127e7537740STom Lendacky unsigned int vector_count; 12847f164deSLendacky, Thomas unsigned int i, j; 12947f164deSLendacky, Thomas int ret; 13047f164deSLendacky, Thomas 131e7537740STom Lendacky vector_count = XGBE_MSI_BASE_COUNT; 132e7537740STom Lendacky vector_count += max(pdata->rx_ring_count, 13347f164deSLendacky, Thomas pdata->tx_ring_count); 13447f164deSLendacky, Thomas 135e7537740STom Lendacky ret = pci_alloc_irq_vectors(pdata->pcidev, XGBE_MSI_MIN_COUNT, 136e7537740STom Lendacky vector_count, PCI_IRQ_MSI | PCI_IRQ_MSIX); 13747f164deSLendacky, Thomas if (ret < 0) { 138e7537740STom Lendacky dev_info(pdata->dev, "multi MSI/MSI-X enablement failed\n"); 13947f164deSLendacky, Thomas return ret; 14047f164deSLendacky, Thomas } 14147f164deSLendacky, Thomas 14285b85c85SLendacky, Thomas pdata->isr_as_tasklet = 1; 14347f164deSLendacky, Thomas pdata->irq_count = ret; 14447f164deSLendacky, Thomas 145e7537740STom Lendacky pdata->dev_irq = pci_irq_vector(pdata->pcidev, 0); 146e7537740STom Lendacky pdata->ecc_irq = pci_irq_vector(pdata->pcidev, 1); 147e7537740STom Lendacky pdata->i2c_irq = pci_irq_vector(pdata->pcidev, 2); 148e7537740STom Lendacky pdata->an_irq = pci_irq_vector(pdata->pcidev, 3); 14947f164deSLendacky, Thomas 150e7537740STom Lendacky for (i = XGBE_MSI_BASE_COUNT, j = 0; i < ret; i++, j++) 151e7537740STom Lendacky pdata->channel_irq[j] = pci_irq_vector(pdata->pcidev, i); 15247f164deSLendacky, Thomas pdata->channel_irq_count = j; 15347f164deSLendacky, Thomas 15447f164deSLendacky, Thomas pdata->per_channel_irq = 1; 1554c70dd8aSLendacky, Thomas pdata->channel_irq_mode = XGBE_IRQ_MODE_LEVEL; 15647f164deSLendacky, Thomas 15747f164deSLendacky, Thomas if (netif_msg_probe(pdata)) 158e7537740STom Lendacky dev_dbg(pdata->dev, "multi %s interrupts enabled\n", 159e7537740STom Lendacky pdata->pcidev->msix_enabled ? "MSI-X" : "MSI"); 16047f164deSLendacky, Thomas 16147f164deSLendacky, Thomas return 0; 16247f164deSLendacky, Thomas } 16347f164deSLendacky, Thomas 16447f164deSLendacky, Thomas static int xgbe_config_irqs(struct xgbe_prv_data *pdata) 16547f164deSLendacky, Thomas { 16647f164deSLendacky, Thomas int ret; 16747f164deSLendacky, Thomas 168e7537740STom Lendacky ret = xgbe_config_multi_msi(pdata); 16947f164deSLendacky, Thomas if (!ret) 17047f164deSLendacky, Thomas goto out; 17147f164deSLendacky, Thomas 172e7537740STom Lendacky ret = pci_alloc_irq_vectors(pdata->pcidev, 1, 1, 173e7537740STom Lendacky PCI_IRQ_LEGACY | PCI_IRQ_MSI); 174e7537740STom Lendacky if (ret < 0) { 175e7537740STom Lendacky dev_info(pdata->dev, "single IRQ enablement failed\n"); 176e7537740STom Lendacky return ret; 177e7537740STom Lendacky } 17847f164deSLendacky, Thomas 17985b85c85SLendacky, Thomas pdata->isr_as_tasklet = pdata->pcidev->msi_enabled ? 1 : 0; 18047f164deSLendacky, Thomas pdata->irq_count = 1; 181e7537740STom Lendacky pdata->channel_irq_count = 1; 18247f164deSLendacky, Thomas 183e7537740STom Lendacky pdata->dev_irq = pci_irq_vector(pdata->pcidev, 0); 184e7537740STom Lendacky pdata->ecc_irq = pci_irq_vector(pdata->pcidev, 0); 185e7537740STom Lendacky pdata->i2c_irq = pci_irq_vector(pdata->pcidev, 0); 186e7537740STom Lendacky pdata->an_irq = pci_irq_vector(pdata->pcidev, 0); 187e7537740STom Lendacky 188e7537740STom Lendacky if (netif_msg_probe(pdata)) 189e7537740STom Lendacky dev_dbg(pdata->dev, "single %s interrupt enabled\n", 190e7537740STom Lendacky pdata->pcidev->msi_enabled ? "MSI" : "legacy"); 19147f164deSLendacky, Thomas 19247f164deSLendacky, Thomas out: 19347f164deSLendacky, Thomas if (netif_msg_probe(pdata)) { 19447f164deSLendacky, Thomas unsigned int i; 19547f164deSLendacky, Thomas 19647f164deSLendacky, Thomas dev_dbg(pdata->dev, " dev irq=%d\n", pdata->dev_irq); 19747f164deSLendacky, Thomas dev_dbg(pdata->dev, " ecc irq=%d\n", pdata->ecc_irq); 19847f164deSLendacky, Thomas dev_dbg(pdata->dev, " i2c irq=%d\n", pdata->i2c_irq); 19947f164deSLendacky, Thomas dev_dbg(pdata->dev, " an irq=%d\n", pdata->an_irq); 20047f164deSLendacky, Thomas for (i = 0; i < pdata->channel_irq_count; i++) 20147f164deSLendacky, Thomas dev_dbg(pdata->dev, " dma%u irq=%d\n", 20247f164deSLendacky, Thomas i, pdata->channel_irq[i]); 20347f164deSLendacky, Thomas } 20447f164deSLendacky, Thomas 20547f164deSLendacky, Thomas return 0; 20647f164deSLendacky, Thomas } 20747f164deSLendacky, Thomas 20847f164deSLendacky, Thomas static int xgbe_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) 20947f164deSLendacky, Thomas { 21047f164deSLendacky, Thomas struct xgbe_prv_data *pdata; 21147f164deSLendacky, Thomas struct device *dev = &pdev->dev; 21247f164deSLendacky, Thomas void __iomem * const *iomap_table; 2134eccbfc3SLendacky, Thomas struct pci_dev *rdev; 21447f164deSLendacky, Thomas unsigned int ma_lo, ma_hi; 21547f164deSLendacky, Thomas unsigned int reg; 21647f164deSLendacky, Thomas int bar_mask; 21747f164deSLendacky, Thomas int ret; 21847f164deSLendacky, Thomas 21947f164deSLendacky, Thomas pdata = xgbe_alloc_pdata(dev); 22047f164deSLendacky, Thomas if (IS_ERR(pdata)) { 22147f164deSLendacky, Thomas ret = PTR_ERR(pdata); 22247f164deSLendacky, Thomas goto err_alloc; 22347f164deSLendacky, Thomas } 22447f164deSLendacky, Thomas 22547f164deSLendacky, Thomas pdata->pcidev = pdev; 22647f164deSLendacky, Thomas pci_set_drvdata(pdev, pdata); 22747f164deSLendacky, Thomas 22847f164deSLendacky, Thomas /* Get the version data */ 22947f164deSLendacky, Thomas pdata->vdata = (struct xgbe_version_data *)id->driver_data; 23047f164deSLendacky, Thomas 23147f164deSLendacky, Thomas ret = pcim_enable_device(pdev); 23247f164deSLendacky, Thomas if (ret) { 23347f164deSLendacky, Thomas dev_err(dev, "pcim_enable_device failed\n"); 23447f164deSLendacky, Thomas goto err_pci_enable; 23547f164deSLendacky, Thomas } 23647f164deSLendacky, Thomas 23747f164deSLendacky, Thomas /* Obtain the mmio areas for the device */ 23847f164deSLendacky, Thomas bar_mask = pci_select_bars(pdev, IORESOURCE_MEM); 23947f164deSLendacky, Thomas ret = pcim_iomap_regions(pdev, bar_mask, XGBE_DRV_NAME); 24047f164deSLendacky, Thomas if (ret) { 24147f164deSLendacky, Thomas dev_err(dev, "pcim_iomap_regions failed\n"); 24247f164deSLendacky, Thomas goto err_pci_enable; 24347f164deSLendacky, Thomas } 24447f164deSLendacky, Thomas 24547f164deSLendacky, Thomas iomap_table = pcim_iomap_table(pdev); 24647f164deSLendacky, Thomas if (!iomap_table) { 24747f164deSLendacky, Thomas dev_err(dev, "pcim_iomap_table failed\n"); 24847f164deSLendacky, Thomas ret = -ENOMEM; 24947f164deSLendacky, Thomas goto err_pci_enable; 25047f164deSLendacky, Thomas } 25147f164deSLendacky, Thomas 25247f164deSLendacky, Thomas pdata->xgmac_regs = iomap_table[XGBE_XGMAC_BAR]; 25347f164deSLendacky, Thomas if (!pdata->xgmac_regs) { 25447f164deSLendacky, Thomas dev_err(dev, "xgmac ioremap failed\n"); 25547f164deSLendacky, Thomas ret = -ENOMEM; 25647f164deSLendacky, Thomas goto err_pci_enable; 25747f164deSLendacky, Thomas } 25847f164deSLendacky, Thomas pdata->xprop_regs = pdata->xgmac_regs + XGBE_MAC_PROP_OFFSET; 25947f164deSLendacky, Thomas pdata->xi2c_regs = pdata->xgmac_regs + XGBE_I2C_CTRL_OFFSET; 26047f164deSLendacky, Thomas if (netif_msg_probe(pdata)) { 26147f164deSLendacky, Thomas dev_dbg(dev, "xgmac_regs = %p\n", pdata->xgmac_regs); 26247f164deSLendacky, Thomas dev_dbg(dev, "xprop_regs = %p\n", pdata->xprop_regs); 26347f164deSLendacky, Thomas dev_dbg(dev, "xi2c_regs = %p\n", pdata->xi2c_regs); 26447f164deSLendacky, Thomas } 26547f164deSLendacky, Thomas 26647f164deSLendacky, Thomas pdata->xpcs_regs = iomap_table[XGBE_XPCS_BAR]; 26747f164deSLendacky, Thomas if (!pdata->xpcs_regs) { 26847f164deSLendacky, Thomas dev_err(dev, "xpcs ioremap failed\n"); 26947f164deSLendacky, Thomas ret = -ENOMEM; 27047f164deSLendacky, Thomas goto err_pci_enable; 27147f164deSLendacky, Thomas } 27247f164deSLendacky, Thomas if (netif_msg_probe(pdata)) 27347f164deSLendacky, Thomas dev_dbg(dev, "xpcs_regs = %p\n", pdata->xpcs_regs); 27447f164deSLendacky, Thomas 2754eccbfc3SLendacky, Thomas /* Set the PCS indirect addressing definition registers */ 2764eccbfc3SLendacky, Thomas rdev = pci_get_domain_bus_and_slot(0, 0, PCI_DEVFN(0, 0)); 2774eccbfc3SLendacky, Thomas if (rdev && 2784eccbfc3SLendacky, Thomas (rdev->vendor == PCI_VENDOR_ID_AMD) && (rdev->device == 0x15d0)) { 2794eccbfc3SLendacky, Thomas pdata->xpcs_window_def_reg = PCS_V2_RV_WINDOW_DEF; 2804eccbfc3SLendacky, Thomas pdata->xpcs_window_sel_reg = PCS_V2_RV_WINDOW_SELECT; 2814eccbfc3SLendacky, Thomas } else { 2824eccbfc3SLendacky, Thomas pdata->xpcs_window_def_reg = PCS_V2_WINDOW_DEF; 2834eccbfc3SLendacky, Thomas pdata->xpcs_window_sel_reg = PCS_V2_WINDOW_SELECT; 2844eccbfc3SLendacky, Thomas } 2854eccbfc3SLendacky, Thomas pci_dev_put(rdev); 2864eccbfc3SLendacky, Thomas 28747f164deSLendacky, Thomas /* Configure the PCS indirect addressing support */ 2884eccbfc3SLendacky, Thomas reg = XPCS32_IOREAD(pdata, pdata->xpcs_window_def_reg); 28947f164deSLendacky, Thomas pdata->xpcs_window = XPCS_GET_BITS(reg, PCS_V2_WINDOW_DEF, OFFSET); 29047f164deSLendacky, Thomas pdata->xpcs_window <<= 6; 29147f164deSLendacky, Thomas pdata->xpcs_window_size = XPCS_GET_BITS(reg, PCS_V2_WINDOW_DEF, SIZE); 29247f164deSLendacky, Thomas pdata->xpcs_window_size = 1 << (pdata->xpcs_window_size + 7); 29347f164deSLendacky, Thomas pdata->xpcs_window_mask = pdata->xpcs_window_size - 1; 29447f164deSLendacky, Thomas if (netif_msg_probe(pdata)) { 29540452f0eSLendacky, Thomas dev_dbg(dev, "xpcs window def = %#010x\n", 29640452f0eSLendacky, Thomas pdata->xpcs_window_def_reg); 29740452f0eSLendacky, Thomas dev_dbg(dev, "xpcs window sel = %#010x\n", 29840452f0eSLendacky, Thomas pdata->xpcs_window_sel_reg); 29947f164deSLendacky, Thomas dev_dbg(dev, "xpcs window = %#010x\n", 30047f164deSLendacky, Thomas pdata->xpcs_window); 30147f164deSLendacky, Thomas dev_dbg(dev, "xpcs window size = %#010x\n", 30247f164deSLendacky, Thomas pdata->xpcs_window_size); 30347f164deSLendacky, Thomas dev_dbg(dev, "xpcs window mask = %#010x\n", 30447f164deSLendacky, Thomas pdata->xpcs_window_mask); 30547f164deSLendacky, Thomas } 30647f164deSLendacky, Thomas 30747f164deSLendacky, Thomas pci_set_master(pdev); 30847f164deSLendacky, Thomas 30947f164deSLendacky, Thomas /* Enable all interrupts in the hardware */ 31047f164deSLendacky, Thomas XP_IOWRITE(pdata, XP_INT_EN, 0x1fffff); 31147f164deSLendacky, Thomas 31247f164deSLendacky, Thomas /* Retrieve the MAC address */ 31347f164deSLendacky, Thomas ma_lo = XP_IOREAD(pdata, XP_MAC_ADDR_LO); 31447f164deSLendacky, Thomas ma_hi = XP_IOREAD(pdata, XP_MAC_ADDR_HI); 31547f164deSLendacky, Thomas pdata->mac_addr[0] = ma_lo & 0xff; 31647f164deSLendacky, Thomas pdata->mac_addr[1] = (ma_lo >> 8) & 0xff; 31747f164deSLendacky, Thomas pdata->mac_addr[2] = (ma_lo >> 16) & 0xff; 31847f164deSLendacky, Thomas pdata->mac_addr[3] = (ma_lo >> 24) & 0xff; 31947f164deSLendacky, Thomas pdata->mac_addr[4] = ma_hi & 0xff; 32047f164deSLendacky, Thomas pdata->mac_addr[5] = (ma_hi >> 8) & 0xff; 32147f164deSLendacky, Thomas if (!XP_GET_BITS(ma_hi, XP_MAC_ADDR_HI, VALID) || 32247f164deSLendacky, Thomas !is_valid_ether_addr(pdata->mac_addr)) { 32347f164deSLendacky, Thomas dev_err(dev, "invalid mac address\n"); 32447f164deSLendacky, Thomas ret = -EINVAL; 32547f164deSLendacky, Thomas goto err_pci_enable; 32647f164deSLendacky, Thomas } 32747f164deSLendacky, Thomas 32847f164deSLendacky, Thomas /* Clock settings */ 32947f164deSLendacky, Thomas pdata->sysclk_rate = XGBE_V2_DMA_CLOCK_FREQ; 33047f164deSLendacky, Thomas pdata->ptpclk_rate = XGBE_V2_PTP_CLOCK_FREQ; 33147f164deSLendacky, Thomas 33247f164deSLendacky, Thomas /* Set the DMA coherency values */ 33347f164deSLendacky, Thomas pdata->coherent = 1; 3346f595959SLendacky, Thomas pdata->arcr = XGBE_DMA_PCI_ARCR; 3356f595959SLendacky, Thomas pdata->awcr = XGBE_DMA_PCI_AWCR; 3366f595959SLendacky, Thomas pdata->awarcr = XGBE_DMA_PCI_AWARCR; 33747f164deSLendacky, Thomas 33847f164deSLendacky, Thomas /* Set the maximum channels and queues */ 33947f164deSLendacky, Thomas reg = XP_IOREAD(pdata, XP_PROP_1); 34047f164deSLendacky, Thomas pdata->tx_max_channel_count = XP_GET_BITS(reg, XP_PROP_1, MAX_TX_DMA); 34147f164deSLendacky, Thomas pdata->rx_max_channel_count = XP_GET_BITS(reg, XP_PROP_1, MAX_RX_DMA); 34247f164deSLendacky, Thomas pdata->tx_max_q_count = XP_GET_BITS(reg, XP_PROP_1, MAX_TX_QUEUES); 34347f164deSLendacky, Thomas pdata->rx_max_q_count = XP_GET_BITS(reg, XP_PROP_1, MAX_RX_QUEUES); 34447f164deSLendacky, Thomas if (netif_msg_probe(pdata)) { 34547f164deSLendacky, Thomas dev_dbg(dev, "max tx/rx channel count = %u/%u\n", 34647f164deSLendacky, Thomas pdata->tx_max_channel_count, 34747f164deSLendacky, Thomas pdata->tx_max_channel_count); 34847f164deSLendacky, Thomas dev_dbg(dev, "max tx/rx hw queue count = %u/%u\n", 34947f164deSLendacky, Thomas pdata->tx_max_q_count, pdata->rx_max_q_count); 35047f164deSLendacky, Thomas } 35147f164deSLendacky, Thomas 35247f164deSLendacky, Thomas /* Set the hardware channel and queue counts */ 35347f164deSLendacky, Thomas xgbe_set_counts(pdata); 35447f164deSLendacky, Thomas 35547f164deSLendacky, Thomas /* Set the maximum fifo amounts */ 35647f164deSLendacky, Thomas reg = XP_IOREAD(pdata, XP_PROP_2); 35747f164deSLendacky, Thomas pdata->tx_max_fifo_size = XP_GET_BITS(reg, XP_PROP_2, TX_FIFO_SIZE); 35847f164deSLendacky, Thomas pdata->tx_max_fifo_size *= 16384; 35947f164deSLendacky, Thomas pdata->tx_max_fifo_size = min(pdata->tx_max_fifo_size, 36047f164deSLendacky, Thomas pdata->vdata->tx_max_fifo_size); 36147f164deSLendacky, Thomas pdata->rx_max_fifo_size = XP_GET_BITS(reg, XP_PROP_2, RX_FIFO_SIZE); 36247f164deSLendacky, Thomas pdata->rx_max_fifo_size *= 16384; 36347f164deSLendacky, Thomas pdata->rx_max_fifo_size = min(pdata->rx_max_fifo_size, 36447f164deSLendacky, Thomas pdata->vdata->rx_max_fifo_size); 36547f164deSLendacky, Thomas if (netif_msg_probe(pdata)) 36647f164deSLendacky, Thomas dev_dbg(dev, "max tx/rx max fifo size = %u/%u\n", 36747f164deSLendacky, Thomas pdata->tx_max_fifo_size, pdata->rx_max_fifo_size); 36847f164deSLendacky, Thomas 36947f164deSLendacky, Thomas /* Configure interrupt support */ 37047f164deSLendacky, Thomas ret = xgbe_config_irqs(pdata); 37147f164deSLendacky, Thomas if (ret) 37247f164deSLendacky, Thomas goto err_pci_enable; 37347f164deSLendacky, Thomas 37447f164deSLendacky, Thomas /* Configure the netdev resource */ 37547f164deSLendacky, Thomas ret = xgbe_config_netdev(pdata); 37647f164deSLendacky, Thomas if (ret) 377e7537740STom Lendacky goto err_irq_vectors; 37847f164deSLendacky, Thomas 37947f164deSLendacky, Thomas netdev_notice(pdata->netdev, "net device enabled\n"); 38047f164deSLendacky, Thomas 38147f164deSLendacky, Thomas return 0; 38247f164deSLendacky, Thomas 383e7537740STom Lendacky err_irq_vectors: 384e7537740STom Lendacky pci_free_irq_vectors(pdata->pcidev); 385e7537740STom Lendacky 38647f164deSLendacky, Thomas err_pci_enable: 38747f164deSLendacky, Thomas xgbe_free_pdata(pdata); 38847f164deSLendacky, Thomas 38947f164deSLendacky, Thomas err_alloc: 39047f164deSLendacky, Thomas dev_notice(dev, "net device not enabled\n"); 39147f164deSLendacky, Thomas 39247f164deSLendacky, Thomas return ret; 39347f164deSLendacky, Thomas } 39447f164deSLendacky, Thomas 39547f164deSLendacky, Thomas static void xgbe_pci_remove(struct pci_dev *pdev) 39647f164deSLendacky, Thomas { 39747f164deSLendacky, Thomas struct xgbe_prv_data *pdata = pci_get_drvdata(pdev); 39847f164deSLendacky, Thomas 39947f164deSLendacky, Thomas xgbe_deconfig_netdev(pdata); 40047f164deSLendacky, Thomas 401e7537740STom Lendacky pci_free_irq_vectors(pdata->pcidev); 402e7537740STom Lendacky 40347f164deSLendacky, Thomas xgbe_free_pdata(pdata); 40447f164deSLendacky, Thomas } 40547f164deSLendacky, Thomas 40647f164deSLendacky, Thomas #ifdef CONFIG_PM 40747f164deSLendacky, Thomas static int xgbe_pci_suspend(struct pci_dev *pdev, pm_message_t state) 40847f164deSLendacky, Thomas { 40947f164deSLendacky, Thomas struct xgbe_prv_data *pdata = pci_get_drvdata(pdev); 41047f164deSLendacky, Thomas struct net_device *netdev = pdata->netdev; 41147f164deSLendacky, Thomas int ret = 0; 41247f164deSLendacky, Thomas 41347f164deSLendacky, Thomas if (netif_running(netdev)) 41447f164deSLendacky, Thomas ret = xgbe_powerdown(netdev, XGMAC_DRIVER_CONTEXT); 41547f164deSLendacky, Thomas 41647f164deSLendacky, Thomas pdata->lpm_ctrl = XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_CTRL1); 41747f164deSLendacky, Thomas pdata->lpm_ctrl |= MDIO_CTRL1_LPOWER; 41847f164deSLendacky, Thomas XMDIO_WRITE(pdata, MDIO_MMD_PCS, MDIO_CTRL1, pdata->lpm_ctrl); 41947f164deSLendacky, Thomas 42047f164deSLendacky, Thomas return ret; 42147f164deSLendacky, Thomas } 42247f164deSLendacky, Thomas 42347f164deSLendacky, Thomas static int xgbe_pci_resume(struct pci_dev *pdev) 42447f164deSLendacky, Thomas { 42547f164deSLendacky, Thomas struct xgbe_prv_data *pdata = pci_get_drvdata(pdev); 42647f164deSLendacky, Thomas struct net_device *netdev = pdata->netdev; 42747f164deSLendacky, Thomas int ret = 0; 42847f164deSLendacky, Thomas 429*cfd092f2STom Lendacky XP_IOWRITE(pdata, XP_INT_EN, 0x1fffff); 430*cfd092f2STom Lendacky 43147f164deSLendacky, Thomas pdata->lpm_ctrl &= ~MDIO_CTRL1_LPOWER; 43247f164deSLendacky, Thomas XMDIO_WRITE(pdata, MDIO_MMD_PCS, MDIO_CTRL1, pdata->lpm_ctrl); 43347f164deSLendacky, Thomas 43447f164deSLendacky, Thomas if (netif_running(netdev)) { 43547f164deSLendacky, Thomas ret = xgbe_powerup(netdev, XGMAC_DRIVER_CONTEXT); 43647f164deSLendacky, Thomas 43747f164deSLendacky, Thomas /* Schedule a restart in case the link or phy state changed 43847f164deSLendacky, Thomas * while we were powered down. 43947f164deSLendacky, Thomas */ 44047f164deSLendacky, Thomas schedule_work(&pdata->restart_work); 44147f164deSLendacky, Thomas } 44247f164deSLendacky, Thomas 44347f164deSLendacky, Thomas return ret; 44447f164deSLendacky, Thomas } 44547f164deSLendacky, Thomas #endif /* CONFIG_PM */ 44647f164deSLendacky, Thomas 44747f164deSLendacky, Thomas static const struct xgbe_version_data xgbe_v2a = { 44847f164deSLendacky, Thomas .init_function_ptrs_phy_impl = xgbe_init_function_ptrs_phy_v2, 44947f164deSLendacky, Thomas .xpcs_access = XGBE_XPCS_ACCESS_V2, 45047f164deSLendacky, Thomas .mmc_64bit = 1, 45147f164deSLendacky, Thomas .tx_max_fifo_size = 229376, 45247f164deSLendacky, Thomas .rx_max_fifo_size = 229376, 45347f164deSLendacky, Thomas .tx_tstamp_workaround = 1, 454e78332b2SLendacky, Thomas .ecc_support = 1, 4555ab1dcd5SLendacky, Thomas .i2c_support = 1, 45685b85c85SLendacky, Thomas .irq_reissue_support = 1, 4576f595959SLendacky, Thomas .tx_desc_prefetch = 5, 4586f595959SLendacky, Thomas .rx_desc_prefetch = 5, 45947f164deSLendacky, Thomas }; 46047f164deSLendacky, Thomas 46147f164deSLendacky, Thomas static const struct xgbe_version_data xgbe_v2b = { 46247f164deSLendacky, Thomas .init_function_ptrs_phy_impl = xgbe_init_function_ptrs_phy_v2, 46347f164deSLendacky, Thomas .xpcs_access = XGBE_XPCS_ACCESS_V2, 46447f164deSLendacky, Thomas .mmc_64bit = 1, 46547f164deSLendacky, Thomas .tx_max_fifo_size = 65536, 46647f164deSLendacky, Thomas .rx_max_fifo_size = 65536, 46747f164deSLendacky, Thomas .tx_tstamp_workaround = 1, 468e78332b2SLendacky, Thomas .ecc_support = 1, 4695ab1dcd5SLendacky, Thomas .i2c_support = 1, 47085b85c85SLendacky, Thomas .irq_reissue_support = 1, 4716f595959SLendacky, Thomas .tx_desc_prefetch = 5, 4726f595959SLendacky, Thomas .rx_desc_prefetch = 5, 47347f164deSLendacky, Thomas }; 47447f164deSLendacky, Thomas 47547f164deSLendacky, Thomas static const struct pci_device_id xgbe_pci_table[] = { 47647f164deSLendacky, Thomas { PCI_VDEVICE(AMD, 0x1458), 47747f164deSLendacky, Thomas .driver_data = (kernel_ulong_t)&xgbe_v2a }, 47847f164deSLendacky, Thomas { PCI_VDEVICE(AMD, 0x1459), 47947f164deSLendacky, Thomas .driver_data = (kernel_ulong_t)&xgbe_v2b }, 48047f164deSLendacky, Thomas /* Last entry must be zero */ 48147f164deSLendacky, Thomas { 0, } 48247f164deSLendacky, Thomas }; 48347f164deSLendacky, Thomas MODULE_DEVICE_TABLE(pci, xgbe_pci_table); 48447f164deSLendacky, Thomas 48547f164deSLendacky, Thomas static struct pci_driver xgbe_driver = { 48647f164deSLendacky, Thomas .name = XGBE_DRV_NAME, 48747f164deSLendacky, Thomas .id_table = xgbe_pci_table, 48847f164deSLendacky, Thomas .probe = xgbe_pci_probe, 48947f164deSLendacky, Thomas .remove = xgbe_pci_remove, 49047f164deSLendacky, Thomas #ifdef CONFIG_PM 49147f164deSLendacky, Thomas .suspend = xgbe_pci_suspend, 49247f164deSLendacky, Thomas .resume = xgbe_pci_resume, 49347f164deSLendacky, Thomas #endif 49447f164deSLendacky, Thomas }; 49547f164deSLendacky, Thomas 49647f164deSLendacky, Thomas int xgbe_pci_init(void) 49747f164deSLendacky, Thomas { 49847f164deSLendacky, Thomas return pci_register_driver(&xgbe_driver); 49947f164deSLendacky, Thomas } 50047f164deSLendacky, Thomas 50147f164deSLendacky, Thomas void xgbe_pci_exit(void) 50247f164deSLendacky, Thomas { 50347f164deSLendacky, Thomas pci_unregister_driver(&xgbe_driver); 50447f164deSLendacky, Thomas } 505