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 125*e7537740STom Lendacky static int xgbe_config_multi_msi(struct xgbe_prv_data *pdata) 12647f164deSLendacky, Thomas { 127*e7537740STom Lendacky unsigned int vector_count; 12847f164deSLendacky, Thomas unsigned int i, j; 12947f164deSLendacky, Thomas int ret; 13047f164deSLendacky, Thomas 131*e7537740STom Lendacky vector_count = XGBE_MSI_BASE_COUNT; 132*e7537740STom Lendacky vector_count += max(pdata->rx_ring_count, 13347f164deSLendacky, Thomas pdata->tx_ring_count); 13447f164deSLendacky, Thomas 135*e7537740STom Lendacky ret = pci_alloc_irq_vectors(pdata->pcidev, XGBE_MSI_MIN_COUNT, 136*e7537740STom Lendacky vector_count, PCI_IRQ_MSI | PCI_IRQ_MSIX); 13747f164deSLendacky, Thomas if (ret < 0) { 138*e7537740STom Lendacky dev_info(pdata->dev, "multi MSI/MSI-X enablement failed\n"); 13947f164deSLendacky, Thomas return ret; 14047f164deSLendacky, Thomas } 14147f164deSLendacky, Thomas 14247f164deSLendacky, Thomas pdata->irq_count = ret; 14347f164deSLendacky, Thomas 144*e7537740STom Lendacky pdata->dev_irq = pci_irq_vector(pdata->pcidev, 0); 145*e7537740STom Lendacky pdata->ecc_irq = pci_irq_vector(pdata->pcidev, 1); 146*e7537740STom Lendacky pdata->i2c_irq = pci_irq_vector(pdata->pcidev, 2); 147*e7537740STom Lendacky pdata->an_irq = pci_irq_vector(pdata->pcidev, 3); 14847f164deSLendacky, Thomas 149*e7537740STom Lendacky for (i = XGBE_MSI_BASE_COUNT, j = 0; i < ret; i++, j++) 150*e7537740STom Lendacky pdata->channel_irq[j] = pci_irq_vector(pdata->pcidev, i); 15147f164deSLendacky, Thomas pdata->channel_irq_count = j; 15247f164deSLendacky, Thomas 15347f164deSLendacky, Thomas pdata->per_channel_irq = 1; 1544c70dd8aSLendacky, Thomas pdata->channel_irq_mode = XGBE_IRQ_MODE_LEVEL; 15547f164deSLendacky, Thomas 15647f164deSLendacky, Thomas if (netif_msg_probe(pdata)) 157*e7537740STom Lendacky dev_dbg(pdata->dev, "multi %s interrupts enabled\n", 158*e7537740STom Lendacky pdata->pcidev->msix_enabled ? "MSI-X" : "MSI"); 15947f164deSLendacky, Thomas 16047f164deSLendacky, Thomas return 0; 16147f164deSLendacky, Thomas } 16247f164deSLendacky, Thomas 16347f164deSLendacky, Thomas static int xgbe_config_irqs(struct xgbe_prv_data *pdata) 16447f164deSLendacky, Thomas { 16547f164deSLendacky, Thomas int ret; 16647f164deSLendacky, Thomas 167*e7537740STom Lendacky ret = xgbe_config_multi_msi(pdata); 16847f164deSLendacky, Thomas if (!ret) 16947f164deSLendacky, Thomas goto out; 17047f164deSLendacky, Thomas 171*e7537740STom Lendacky ret = pci_alloc_irq_vectors(pdata->pcidev, 1, 1, 172*e7537740STom Lendacky PCI_IRQ_LEGACY | PCI_IRQ_MSI); 173*e7537740STom Lendacky if (ret < 0) { 174*e7537740STom Lendacky dev_info(pdata->dev, "single IRQ enablement failed\n"); 175*e7537740STom Lendacky return ret; 176*e7537740STom Lendacky } 17747f164deSLendacky, Thomas 17847f164deSLendacky, Thomas pdata->irq_count = 1; 179*e7537740STom Lendacky pdata->channel_irq_count = 1; 18047f164deSLendacky, Thomas 181*e7537740STom Lendacky pdata->dev_irq = pci_irq_vector(pdata->pcidev, 0); 182*e7537740STom Lendacky pdata->ecc_irq = pci_irq_vector(pdata->pcidev, 0); 183*e7537740STom Lendacky pdata->i2c_irq = pci_irq_vector(pdata->pcidev, 0); 184*e7537740STom Lendacky pdata->an_irq = pci_irq_vector(pdata->pcidev, 0); 185*e7537740STom Lendacky 186*e7537740STom Lendacky if (netif_msg_probe(pdata)) 187*e7537740STom Lendacky dev_dbg(pdata->dev, "single %s interrupt enabled\n", 188*e7537740STom Lendacky pdata->pcidev->msi_enabled ? "MSI" : "legacy"); 18947f164deSLendacky, Thomas 19047f164deSLendacky, Thomas out: 19147f164deSLendacky, Thomas if (netif_msg_probe(pdata)) { 19247f164deSLendacky, Thomas unsigned int i; 19347f164deSLendacky, Thomas 19447f164deSLendacky, Thomas dev_dbg(pdata->dev, " dev irq=%d\n", pdata->dev_irq); 19547f164deSLendacky, Thomas dev_dbg(pdata->dev, " ecc irq=%d\n", pdata->ecc_irq); 19647f164deSLendacky, Thomas dev_dbg(pdata->dev, " i2c irq=%d\n", pdata->i2c_irq); 19747f164deSLendacky, Thomas dev_dbg(pdata->dev, " an irq=%d\n", pdata->an_irq); 19847f164deSLendacky, Thomas for (i = 0; i < pdata->channel_irq_count; i++) 19947f164deSLendacky, Thomas dev_dbg(pdata->dev, " dma%u irq=%d\n", 20047f164deSLendacky, Thomas i, pdata->channel_irq[i]); 20147f164deSLendacky, Thomas } 20247f164deSLendacky, Thomas 20347f164deSLendacky, Thomas return 0; 20447f164deSLendacky, Thomas } 20547f164deSLendacky, Thomas 20647f164deSLendacky, Thomas static int xgbe_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) 20747f164deSLendacky, Thomas { 20847f164deSLendacky, Thomas struct xgbe_prv_data *pdata; 20947f164deSLendacky, Thomas struct device *dev = &pdev->dev; 21047f164deSLendacky, Thomas void __iomem * const *iomap_table; 21147f164deSLendacky, Thomas unsigned int ma_lo, ma_hi; 21247f164deSLendacky, Thomas unsigned int reg; 21347f164deSLendacky, Thomas int bar_mask; 21447f164deSLendacky, Thomas int ret; 21547f164deSLendacky, Thomas 21647f164deSLendacky, Thomas pdata = xgbe_alloc_pdata(dev); 21747f164deSLendacky, Thomas if (IS_ERR(pdata)) { 21847f164deSLendacky, Thomas ret = PTR_ERR(pdata); 21947f164deSLendacky, Thomas goto err_alloc; 22047f164deSLendacky, Thomas } 22147f164deSLendacky, Thomas 22247f164deSLendacky, Thomas pdata->pcidev = pdev; 22347f164deSLendacky, Thomas pci_set_drvdata(pdev, pdata); 22447f164deSLendacky, Thomas 22547f164deSLendacky, Thomas /* Get the version data */ 22647f164deSLendacky, Thomas pdata->vdata = (struct xgbe_version_data *)id->driver_data; 22747f164deSLendacky, Thomas 22847f164deSLendacky, Thomas ret = pcim_enable_device(pdev); 22947f164deSLendacky, Thomas if (ret) { 23047f164deSLendacky, Thomas dev_err(dev, "pcim_enable_device failed\n"); 23147f164deSLendacky, Thomas goto err_pci_enable; 23247f164deSLendacky, Thomas } 23347f164deSLendacky, Thomas 23447f164deSLendacky, Thomas /* Obtain the mmio areas for the device */ 23547f164deSLendacky, Thomas bar_mask = pci_select_bars(pdev, IORESOURCE_MEM); 23647f164deSLendacky, Thomas ret = pcim_iomap_regions(pdev, bar_mask, XGBE_DRV_NAME); 23747f164deSLendacky, Thomas if (ret) { 23847f164deSLendacky, Thomas dev_err(dev, "pcim_iomap_regions failed\n"); 23947f164deSLendacky, Thomas goto err_pci_enable; 24047f164deSLendacky, Thomas } 24147f164deSLendacky, Thomas 24247f164deSLendacky, Thomas iomap_table = pcim_iomap_table(pdev); 24347f164deSLendacky, Thomas if (!iomap_table) { 24447f164deSLendacky, Thomas dev_err(dev, "pcim_iomap_table failed\n"); 24547f164deSLendacky, Thomas ret = -ENOMEM; 24647f164deSLendacky, Thomas goto err_pci_enable; 24747f164deSLendacky, Thomas } 24847f164deSLendacky, Thomas 24947f164deSLendacky, Thomas pdata->xgmac_regs = iomap_table[XGBE_XGMAC_BAR]; 25047f164deSLendacky, Thomas if (!pdata->xgmac_regs) { 25147f164deSLendacky, Thomas dev_err(dev, "xgmac ioremap failed\n"); 25247f164deSLendacky, Thomas ret = -ENOMEM; 25347f164deSLendacky, Thomas goto err_pci_enable; 25447f164deSLendacky, Thomas } 25547f164deSLendacky, Thomas pdata->xprop_regs = pdata->xgmac_regs + XGBE_MAC_PROP_OFFSET; 25647f164deSLendacky, Thomas pdata->xi2c_regs = pdata->xgmac_regs + XGBE_I2C_CTRL_OFFSET; 25747f164deSLendacky, Thomas if (netif_msg_probe(pdata)) { 25847f164deSLendacky, Thomas dev_dbg(dev, "xgmac_regs = %p\n", pdata->xgmac_regs); 25947f164deSLendacky, Thomas dev_dbg(dev, "xprop_regs = %p\n", pdata->xprop_regs); 26047f164deSLendacky, Thomas dev_dbg(dev, "xi2c_regs = %p\n", pdata->xi2c_regs); 26147f164deSLendacky, Thomas } 26247f164deSLendacky, Thomas 26347f164deSLendacky, Thomas pdata->xpcs_regs = iomap_table[XGBE_XPCS_BAR]; 26447f164deSLendacky, Thomas if (!pdata->xpcs_regs) { 26547f164deSLendacky, Thomas dev_err(dev, "xpcs ioremap failed\n"); 26647f164deSLendacky, Thomas ret = -ENOMEM; 26747f164deSLendacky, Thomas goto err_pci_enable; 26847f164deSLendacky, Thomas } 26947f164deSLendacky, Thomas if (netif_msg_probe(pdata)) 27047f164deSLendacky, Thomas dev_dbg(dev, "xpcs_regs = %p\n", pdata->xpcs_regs); 27147f164deSLendacky, Thomas 27247f164deSLendacky, Thomas /* Configure the PCS indirect addressing support */ 27347f164deSLendacky, Thomas reg = XPCS32_IOREAD(pdata, PCS_V2_WINDOW_DEF); 27447f164deSLendacky, Thomas pdata->xpcs_window = XPCS_GET_BITS(reg, PCS_V2_WINDOW_DEF, OFFSET); 27547f164deSLendacky, Thomas pdata->xpcs_window <<= 6; 27647f164deSLendacky, Thomas pdata->xpcs_window_size = XPCS_GET_BITS(reg, PCS_V2_WINDOW_DEF, SIZE); 27747f164deSLendacky, Thomas pdata->xpcs_window_size = 1 << (pdata->xpcs_window_size + 7); 27847f164deSLendacky, Thomas pdata->xpcs_window_mask = pdata->xpcs_window_size - 1; 27947f164deSLendacky, Thomas if (netif_msg_probe(pdata)) { 28047f164deSLendacky, Thomas dev_dbg(dev, "xpcs window = %#010x\n", 28147f164deSLendacky, Thomas pdata->xpcs_window); 28247f164deSLendacky, Thomas dev_dbg(dev, "xpcs window size = %#010x\n", 28347f164deSLendacky, Thomas pdata->xpcs_window_size); 28447f164deSLendacky, Thomas dev_dbg(dev, "xpcs window mask = %#010x\n", 28547f164deSLendacky, Thomas pdata->xpcs_window_mask); 28647f164deSLendacky, Thomas } 28747f164deSLendacky, Thomas 28847f164deSLendacky, Thomas pci_set_master(pdev); 28947f164deSLendacky, Thomas 29047f164deSLendacky, Thomas /* Enable all interrupts in the hardware */ 29147f164deSLendacky, Thomas XP_IOWRITE(pdata, XP_INT_EN, 0x1fffff); 29247f164deSLendacky, Thomas 29347f164deSLendacky, Thomas /* Retrieve the MAC address */ 29447f164deSLendacky, Thomas ma_lo = XP_IOREAD(pdata, XP_MAC_ADDR_LO); 29547f164deSLendacky, Thomas ma_hi = XP_IOREAD(pdata, XP_MAC_ADDR_HI); 29647f164deSLendacky, Thomas pdata->mac_addr[0] = ma_lo & 0xff; 29747f164deSLendacky, Thomas pdata->mac_addr[1] = (ma_lo >> 8) & 0xff; 29847f164deSLendacky, Thomas pdata->mac_addr[2] = (ma_lo >> 16) & 0xff; 29947f164deSLendacky, Thomas pdata->mac_addr[3] = (ma_lo >> 24) & 0xff; 30047f164deSLendacky, Thomas pdata->mac_addr[4] = ma_hi & 0xff; 30147f164deSLendacky, Thomas pdata->mac_addr[5] = (ma_hi >> 8) & 0xff; 30247f164deSLendacky, Thomas if (!XP_GET_BITS(ma_hi, XP_MAC_ADDR_HI, VALID) || 30347f164deSLendacky, Thomas !is_valid_ether_addr(pdata->mac_addr)) { 30447f164deSLendacky, Thomas dev_err(dev, "invalid mac address\n"); 30547f164deSLendacky, Thomas ret = -EINVAL; 30647f164deSLendacky, Thomas goto err_pci_enable; 30747f164deSLendacky, Thomas } 30847f164deSLendacky, Thomas 30947f164deSLendacky, Thomas /* Clock settings */ 31047f164deSLendacky, Thomas pdata->sysclk_rate = XGBE_V2_DMA_CLOCK_FREQ; 31147f164deSLendacky, Thomas pdata->ptpclk_rate = XGBE_V2_PTP_CLOCK_FREQ; 31247f164deSLendacky, Thomas 31347f164deSLendacky, Thomas /* Set the DMA coherency values */ 31447f164deSLendacky, Thomas pdata->coherent = 1; 31547f164deSLendacky, Thomas pdata->axdomain = XGBE_DMA_OS_AXDOMAIN; 31647f164deSLendacky, Thomas pdata->arcache = XGBE_DMA_OS_ARCACHE; 31747f164deSLendacky, Thomas pdata->awcache = XGBE_DMA_OS_AWCACHE; 31847f164deSLendacky, Thomas 31947f164deSLendacky, Thomas /* Set the maximum channels and queues */ 32047f164deSLendacky, Thomas reg = XP_IOREAD(pdata, XP_PROP_1); 32147f164deSLendacky, Thomas pdata->tx_max_channel_count = XP_GET_BITS(reg, XP_PROP_1, MAX_TX_DMA); 32247f164deSLendacky, Thomas pdata->rx_max_channel_count = XP_GET_BITS(reg, XP_PROP_1, MAX_RX_DMA); 32347f164deSLendacky, Thomas pdata->tx_max_q_count = XP_GET_BITS(reg, XP_PROP_1, MAX_TX_QUEUES); 32447f164deSLendacky, Thomas pdata->rx_max_q_count = XP_GET_BITS(reg, XP_PROP_1, MAX_RX_QUEUES); 32547f164deSLendacky, Thomas if (netif_msg_probe(pdata)) { 32647f164deSLendacky, Thomas dev_dbg(dev, "max tx/rx channel count = %u/%u\n", 32747f164deSLendacky, Thomas pdata->tx_max_channel_count, 32847f164deSLendacky, Thomas pdata->tx_max_channel_count); 32947f164deSLendacky, Thomas dev_dbg(dev, "max tx/rx hw queue count = %u/%u\n", 33047f164deSLendacky, Thomas pdata->tx_max_q_count, pdata->rx_max_q_count); 33147f164deSLendacky, Thomas } 33247f164deSLendacky, Thomas 33347f164deSLendacky, Thomas /* Set the hardware channel and queue counts */ 33447f164deSLendacky, Thomas xgbe_set_counts(pdata); 33547f164deSLendacky, Thomas 33647f164deSLendacky, Thomas /* Set the maximum fifo amounts */ 33747f164deSLendacky, Thomas reg = XP_IOREAD(pdata, XP_PROP_2); 33847f164deSLendacky, Thomas pdata->tx_max_fifo_size = XP_GET_BITS(reg, XP_PROP_2, TX_FIFO_SIZE); 33947f164deSLendacky, Thomas pdata->tx_max_fifo_size *= 16384; 34047f164deSLendacky, Thomas pdata->tx_max_fifo_size = min(pdata->tx_max_fifo_size, 34147f164deSLendacky, Thomas pdata->vdata->tx_max_fifo_size); 34247f164deSLendacky, Thomas pdata->rx_max_fifo_size = XP_GET_BITS(reg, XP_PROP_2, RX_FIFO_SIZE); 34347f164deSLendacky, Thomas pdata->rx_max_fifo_size *= 16384; 34447f164deSLendacky, Thomas pdata->rx_max_fifo_size = min(pdata->rx_max_fifo_size, 34547f164deSLendacky, Thomas pdata->vdata->rx_max_fifo_size); 34647f164deSLendacky, Thomas if (netif_msg_probe(pdata)) 34747f164deSLendacky, Thomas dev_dbg(dev, "max tx/rx max fifo size = %u/%u\n", 34847f164deSLendacky, Thomas pdata->tx_max_fifo_size, pdata->rx_max_fifo_size); 34947f164deSLendacky, Thomas 35047f164deSLendacky, Thomas /* Configure interrupt support */ 35147f164deSLendacky, Thomas ret = xgbe_config_irqs(pdata); 35247f164deSLendacky, Thomas if (ret) 35347f164deSLendacky, Thomas goto err_pci_enable; 35447f164deSLendacky, Thomas 35547f164deSLendacky, Thomas /* Configure the netdev resource */ 35647f164deSLendacky, Thomas ret = xgbe_config_netdev(pdata); 35747f164deSLendacky, Thomas if (ret) 358*e7537740STom Lendacky goto err_irq_vectors; 35947f164deSLendacky, Thomas 36047f164deSLendacky, Thomas netdev_notice(pdata->netdev, "net device enabled\n"); 36147f164deSLendacky, Thomas 36247f164deSLendacky, Thomas return 0; 36347f164deSLendacky, Thomas 364*e7537740STom Lendacky err_irq_vectors: 365*e7537740STom Lendacky pci_free_irq_vectors(pdata->pcidev); 366*e7537740STom Lendacky 36747f164deSLendacky, Thomas err_pci_enable: 36847f164deSLendacky, Thomas xgbe_free_pdata(pdata); 36947f164deSLendacky, Thomas 37047f164deSLendacky, Thomas err_alloc: 37147f164deSLendacky, Thomas dev_notice(dev, "net device not enabled\n"); 37247f164deSLendacky, Thomas 37347f164deSLendacky, Thomas return ret; 37447f164deSLendacky, Thomas } 37547f164deSLendacky, Thomas 37647f164deSLendacky, Thomas static void xgbe_pci_remove(struct pci_dev *pdev) 37747f164deSLendacky, Thomas { 37847f164deSLendacky, Thomas struct xgbe_prv_data *pdata = pci_get_drvdata(pdev); 37947f164deSLendacky, Thomas 38047f164deSLendacky, Thomas xgbe_deconfig_netdev(pdata); 38147f164deSLendacky, Thomas 382*e7537740STom Lendacky pci_free_irq_vectors(pdata->pcidev); 383*e7537740STom Lendacky 38447f164deSLendacky, Thomas xgbe_free_pdata(pdata); 38547f164deSLendacky, Thomas } 38647f164deSLendacky, Thomas 38747f164deSLendacky, Thomas #ifdef CONFIG_PM 38847f164deSLendacky, Thomas static int xgbe_pci_suspend(struct pci_dev *pdev, pm_message_t state) 38947f164deSLendacky, Thomas { 39047f164deSLendacky, Thomas struct xgbe_prv_data *pdata = pci_get_drvdata(pdev); 39147f164deSLendacky, Thomas struct net_device *netdev = pdata->netdev; 39247f164deSLendacky, Thomas int ret = 0; 39347f164deSLendacky, Thomas 39447f164deSLendacky, Thomas if (netif_running(netdev)) 39547f164deSLendacky, Thomas ret = xgbe_powerdown(netdev, XGMAC_DRIVER_CONTEXT); 39647f164deSLendacky, Thomas 39747f164deSLendacky, Thomas pdata->lpm_ctrl = XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_CTRL1); 39847f164deSLendacky, Thomas pdata->lpm_ctrl |= MDIO_CTRL1_LPOWER; 39947f164deSLendacky, Thomas XMDIO_WRITE(pdata, MDIO_MMD_PCS, MDIO_CTRL1, pdata->lpm_ctrl); 40047f164deSLendacky, Thomas 40147f164deSLendacky, Thomas return ret; 40247f164deSLendacky, Thomas } 40347f164deSLendacky, Thomas 40447f164deSLendacky, Thomas static int xgbe_pci_resume(struct pci_dev *pdev) 40547f164deSLendacky, Thomas { 40647f164deSLendacky, Thomas struct xgbe_prv_data *pdata = pci_get_drvdata(pdev); 40747f164deSLendacky, Thomas struct net_device *netdev = pdata->netdev; 40847f164deSLendacky, Thomas int ret = 0; 40947f164deSLendacky, Thomas 41047f164deSLendacky, Thomas pdata->lpm_ctrl &= ~MDIO_CTRL1_LPOWER; 41147f164deSLendacky, Thomas XMDIO_WRITE(pdata, MDIO_MMD_PCS, MDIO_CTRL1, pdata->lpm_ctrl); 41247f164deSLendacky, Thomas 41347f164deSLendacky, Thomas if (netif_running(netdev)) { 41447f164deSLendacky, Thomas ret = xgbe_powerup(netdev, XGMAC_DRIVER_CONTEXT); 41547f164deSLendacky, Thomas 41647f164deSLendacky, Thomas /* Schedule a restart in case the link or phy state changed 41747f164deSLendacky, Thomas * while we were powered down. 41847f164deSLendacky, Thomas */ 41947f164deSLendacky, Thomas schedule_work(&pdata->restart_work); 42047f164deSLendacky, Thomas } 42147f164deSLendacky, Thomas 42247f164deSLendacky, Thomas return ret; 42347f164deSLendacky, Thomas } 42447f164deSLendacky, Thomas #endif /* CONFIG_PM */ 42547f164deSLendacky, Thomas 42647f164deSLendacky, Thomas static const struct xgbe_version_data xgbe_v2a = { 42747f164deSLendacky, Thomas .init_function_ptrs_phy_impl = xgbe_init_function_ptrs_phy_v2, 42847f164deSLendacky, Thomas .xpcs_access = XGBE_XPCS_ACCESS_V2, 42947f164deSLendacky, Thomas .mmc_64bit = 1, 43047f164deSLendacky, Thomas .tx_max_fifo_size = 229376, 43147f164deSLendacky, Thomas .rx_max_fifo_size = 229376, 43247f164deSLendacky, Thomas .tx_tstamp_workaround = 1, 433e78332b2SLendacky, Thomas .ecc_support = 1, 4345ab1dcd5SLendacky, Thomas .i2c_support = 1, 43547f164deSLendacky, Thomas }; 43647f164deSLendacky, Thomas 43747f164deSLendacky, Thomas static const struct xgbe_version_data xgbe_v2b = { 43847f164deSLendacky, Thomas .init_function_ptrs_phy_impl = xgbe_init_function_ptrs_phy_v2, 43947f164deSLendacky, Thomas .xpcs_access = XGBE_XPCS_ACCESS_V2, 44047f164deSLendacky, Thomas .mmc_64bit = 1, 44147f164deSLendacky, Thomas .tx_max_fifo_size = 65536, 44247f164deSLendacky, Thomas .rx_max_fifo_size = 65536, 44347f164deSLendacky, Thomas .tx_tstamp_workaround = 1, 444e78332b2SLendacky, Thomas .ecc_support = 1, 4455ab1dcd5SLendacky, Thomas .i2c_support = 1, 44647f164deSLendacky, Thomas }; 44747f164deSLendacky, Thomas 44847f164deSLendacky, Thomas static const struct pci_device_id xgbe_pci_table[] = { 44947f164deSLendacky, Thomas { PCI_VDEVICE(AMD, 0x1458), 45047f164deSLendacky, Thomas .driver_data = (kernel_ulong_t)&xgbe_v2a }, 45147f164deSLendacky, Thomas { PCI_VDEVICE(AMD, 0x1459), 45247f164deSLendacky, Thomas .driver_data = (kernel_ulong_t)&xgbe_v2b }, 45347f164deSLendacky, Thomas /* Last entry must be zero */ 45447f164deSLendacky, Thomas { 0, } 45547f164deSLendacky, Thomas }; 45647f164deSLendacky, Thomas MODULE_DEVICE_TABLE(pci, xgbe_pci_table); 45747f164deSLendacky, Thomas 45847f164deSLendacky, Thomas static struct pci_driver xgbe_driver = { 45947f164deSLendacky, Thomas .name = XGBE_DRV_NAME, 46047f164deSLendacky, Thomas .id_table = xgbe_pci_table, 46147f164deSLendacky, Thomas .probe = xgbe_pci_probe, 46247f164deSLendacky, Thomas .remove = xgbe_pci_remove, 46347f164deSLendacky, Thomas #ifdef CONFIG_PM 46447f164deSLendacky, Thomas .suspend = xgbe_pci_suspend, 46547f164deSLendacky, Thomas .resume = xgbe_pci_resume, 46647f164deSLendacky, Thomas #endif 46747f164deSLendacky, Thomas }; 46847f164deSLendacky, Thomas 46947f164deSLendacky, Thomas int xgbe_pci_init(void) 47047f164deSLendacky, Thomas { 47147f164deSLendacky, Thomas return pci_register_driver(&xgbe_driver); 47247f164deSLendacky, Thomas } 47347f164deSLendacky, Thomas 47447f164deSLendacky, Thomas void xgbe_pci_exit(void) 47547f164deSLendacky, Thomas { 47647f164deSLendacky, Thomas pci_unregister_driver(&xgbe_driver); 47747f164deSLendacky, Thomas } 478