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
xgbe_config_multi_msi(struct xgbe_prv_data * pdata)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
xgbe_config_irqs(struct xgbe_prv_data * pdata)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
xgbe_pci_probe(struct pci_dev * pdev,const struct pci_device_id * id)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;
281dbb6c58bSRaju Rangoju } else if (rdev && (rdev->vendor == PCI_VENDOR_ID_AMD) &&
282dbb6c58bSRaju Rangoju (rdev->device == 0x14b5)) {
283dbb6c58bSRaju Rangoju pdata->xpcs_window_def_reg = PCS_V2_YC_WINDOW_DEF;
284dbb6c58bSRaju Rangoju pdata->xpcs_window_sel_reg = PCS_V2_YC_WINDOW_SELECT;
2856f60ecf2SRaju Rangoju
2866f60ecf2SRaju Rangoju /* Yellow Carp devices do not need cdr workaround */
2876f60ecf2SRaju Rangoju pdata->vdata->an_cdr_workaround = 0;
288*f97fc7efSRaju Rangoju
289*f97fc7efSRaju Rangoju /* Yellow Carp devices do not need rrc */
290*f97fc7efSRaju Rangoju pdata->vdata->enable_rrc = 0;
2914eccbfc3SLendacky, Thomas } else {
2924eccbfc3SLendacky, Thomas pdata->xpcs_window_def_reg = PCS_V2_WINDOW_DEF;
2934eccbfc3SLendacky, Thomas pdata->xpcs_window_sel_reg = PCS_V2_WINDOW_SELECT;
2944eccbfc3SLendacky, Thomas }
2954eccbfc3SLendacky, Thomas pci_dev_put(rdev);
2964eccbfc3SLendacky, Thomas
29747f164deSLendacky, Thomas /* Configure the PCS indirect addressing support */
2984eccbfc3SLendacky, Thomas reg = XPCS32_IOREAD(pdata, pdata->xpcs_window_def_reg);
29947f164deSLendacky, Thomas pdata->xpcs_window = XPCS_GET_BITS(reg, PCS_V2_WINDOW_DEF, OFFSET);
30047f164deSLendacky, Thomas pdata->xpcs_window <<= 6;
30147f164deSLendacky, Thomas pdata->xpcs_window_size = XPCS_GET_BITS(reg, PCS_V2_WINDOW_DEF, SIZE);
30247f164deSLendacky, Thomas pdata->xpcs_window_size = 1 << (pdata->xpcs_window_size + 7);
30347f164deSLendacky, Thomas pdata->xpcs_window_mask = pdata->xpcs_window_size - 1;
30447f164deSLendacky, Thomas if (netif_msg_probe(pdata)) {
30540452f0eSLendacky, Thomas dev_dbg(dev, "xpcs window def = %#010x\n",
30640452f0eSLendacky, Thomas pdata->xpcs_window_def_reg);
30740452f0eSLendacky, Thomas dev_dbg(dev, "xpcs window sel = %#010x\n",
30840452f0eSLendacky, Thomas pdata->xpcs_window_sel_reg);
30947f164deSLendacky, Thomas dev_dbg(dev, "xpcs window = %#010x\n",
31047f164deSLendacky, Thomas pdata->xpcs_window);
31147f164deSLendacky, Thomas dev_dbg(dev, "xpcs window size = %#010x\n",
31247f164deSLendacky, Thomas pdata->xpcs_window_size);
31347f164deSLendacky, Thomas dev_dbg(dev, "xpcs window mask = %#010x\n",
31447f164deSLendacky, Thomas pdata->xpcs_window_mask);
31547f164deSLendacky, Thomas }
31647f164deSLendacky, Thomas
31747f164deSLendacky, Thomas pci_set_master(pdev);
31847f164deSLendacky, Thomas
31947f164deSLendacky, Thomas /* Enable all interrupts in the hardware */
32047f164deSLendacky, Thomas XP_IOWRITE(pdata, XP_INT_EN, 0x1fffff);
32147f164deSLendacky, Thomas
32247f164deSLendacky, Thomas /* Retrieve the MAC address */
32347f164deSLendacky, Thomas ma_lo = XP_IOREAD(pdata, XP_MAC_ADDR_LO);
32447f164deSLendacky, Thomas ma_hi = XP_IOREAD(pdata, XP_MAC_ADDR_HI);
32547f164deSLendacky, Thomas pdata->mac_addr[0] = ma_lo & 0xff;
32647f164deSLendacky, Thomas pdata->mac_addr[1] = (ma_lo >> 8) & 0xff;
32747f164deSLendacky, Thomas pdata->mac_addr[2] = (ma_lo >> 16) & 0xff;
32847f164deSLendacky, Thomas pdata->mac_addr[3] = (ma_lo >> 24) & 0xff;
32947f164deSLendacky, Thomas pdata->mac_addr[4] = ma_hi & 0xff;
33047f164deSLendacky, Thomas pdata->mac_addr[5] = (ma_hi >> 8) & 0xff;
33147f164deSLendacky, Thomas if (!XP_GET_BITS(ma_hi, XP_MAC_ADDR_HI, VALID) ||
33247f164deSLendacky, Thomas !is_valid_ether_addr(pdata->mac_addr)) {
33347f164deSLendacky, Thomas dev_err(dev, "invalid mac address\n");
33447f164deSLendacky, Thomas ret = -EINVAL;
33547f164deSLendacky, Thomas goto err_pci_enable;
33647f164deSLendacky, Thomas }
33747f164deSLendacky, Thomas
33847f164deSLendacky, Thomas /* Clock settings */
33947f164deSLendacky, Thomas pdata->sysclk_rate = XGBE_V2_DMA_CLOCK_FREQ;
34047f164deSLendacky, Thomas pdata->ptpclk_rate = XGBE_V2_PTP_CLOCK_FREQ;
34147f164deSLendacky, Thomas
34247f164deSLendacky, Thomas /* Set the DMA coherency values */
34347f164deSLendacky, Thomas pdata->coherent = 1;
3446f595959SLendacky, Thomas pdata->arcr = XGBE_DMA_PCI_ARCR;
3456f595959SLendacky, Thomas pdata->awcr = XGBE_DMA_PCI_AWCR;
3466f595959SLendacky, Thomas pdata->awarcr = XGBE_DMA_PCI_AWARCR;
34747f164deSLendacky, Thomas
348b93c3ab6STom Lendacky /* Read the port property registers */
349b93c3ab6STom Lendacky pdata->pp0 = XP_IOREAD(pdata, XP_PROP_0);
350b93c3ab6STom Lendacky pdata->pp1 = XP_IOREAD(pdata, XP_PROP_1);
351b93c3ab6STom Lendacky pdata->pp2 = XP_IOREAD(pdata, XP_PROP_2);
352b93c3ab6STom Lendacky pdata->pp3 = XP_IOREAD(pdata, XP_PROP_3);
353b93c3ab6STom Lendacky pdata->pp4 = XP_IOREAD(pdata, XP_PROP_4);
354b93c3ab6STom Lendacky if (netif_msg_probe(pdata)) {
355b93c3ab6STom Lendacky dev_dbg(dev, "port property 0 = %#010x\n", pdata->pp0);
356b93c3ab6STom Lendacky dev_dbg(dev, "port property 1 = %#010x\n", pdata->pp1);
357b93c3ab6STom Lendacky dev_dbg(dev, "port property 2 = %#010x\n", pdata->pp2);
358b93c3ab6STom Lendacky dev_dbg(dev, "port property 3 = %#010x\n", pdata->pp3);
359b93c3ab6STom Lendacky dev_dbg(dev, "port property 4 = %#010x\n", pdata->pp4);
360b93c3ab6STom Lendacky }
361b93c3ab6STom Lendacky
36247f164deSLendacky, Thomas /* Set the maximum channels and queues */
363b93c3ab6STom Lendacky pdata->tx_max_channel_count = XP_GET_BITS(pdata->pp1, XP_PROP_1,
364b93c3ab6STom Lendacky MAX_TX_DMA);
365b93c3ab6STom Lendacky pdata->rx_max_channel_count = XP_GET_BITS(pdata->pp1, XP_PROP_1,
366b93c3ab6STom Lendacky MAX_RX_DMA);
367b93c3ab6STom Lendacky pdata->tx_max_q_count = XP_GET_BITS(pdata->pp1, XP_PROP_1,
368b93c3ab6STom Lendacky MAX_TX_QUEUES);
369b93c3ab6STom Lendacky pdata->rx_max_q_count = XP_GET_BITS(pdata->pp1, XP_PROP_1,
370b93c3ab6STom Lendacky MAX_RX_QUEUES);
37147f164deSLendacky, Thomas if (netif_msg_probe(pdata)) {
37247f164deSLendacky, Thomas dev_dbg(dev, "max tx/rx channel count = %u/%u\n",
37347f164deSLendacky, Thomas pdata->tx_max_channel_count,
3746c2799c1STom Lendacky pdata->rx_max_channel_count);
37547f164deSLendacky, Thomas dev_dbg(dev, "max tx/rx hw queue count = %u/%u\n",
37647f164deSLendacky, Thomas pdata->tx_max_q_count, pdata->rx_max_q_count);
37747f164deSLendacky, Thomas }
37847f164deSLendacky, Thomas
37947f164deSLendacky, Thomas /* Set the hardware channel and queue counts */
38047f164deSLendacky, Thomas xgbe_set_counts(pdata);
38147f164deSLendacky, Thomas
38247f164deSLendacky, Thomas /* Set the maximum fifo amounts */
383b93c3ab6STom Lendacky pdata->tx_max_fifo_size = XP_GET_BITS(pdata->pp2, XP_PROP_2,
384b93c3ab6STom Lendacky TX_FIFO_SIZE);
38547f164deSLendacky, Thomas pdata->tx_max_fifo_size *= 16384;
38647f164deSLendacky, Thomas pdata->tx_max_fifo_size = min(pdata->tx_max_fifo_size,
38747f164deSLendacky, Thomas pdata->vdata->tx_max_fifo_size);
388b93c3ab6STom Lendacky pdata->rx_max_fifo_size = XP_GET_BITS(pdata->pp2, XP_PROP_2,
389b93c3ab6STom Lendacky RX_FIFO_SIZE);
39047f164deSLendacky, Thomas pdata->rx_max_fifo_size *= 16384;
39147f164deSLendacky, Thomas pdata->rx_max_fifo_size = min(pdata->rx_max_fifo_size,
39247f164deSLendacky, Thomas pdata->vdata->rx_max_fifo_size);
39347f164deSLendacky, Thomas if (netif_msg_probe(pdata))
39447f164deSLendacky, Thomas dev_dbg(dev, "max tx/rx max fifo size = %u/%u\n",
39547f164deSLendacky, Thomas pdata->tx_max_fifo_size, pdata->rx_max_fifo_size);
39647f164deSLendacky, Thomas
39747f164deSLendacky, Thomas /* Configure interrupt support */
39847f164deSLendacky, Thomas ret = xgbe_config_irqs(pdata);
39947f164deSLendacky, Thomas if (ret)
40047f164deSLendacky, Thomas goto err_pci_enable;
40147f164deSLendacky, Thomas
40247f164deSLendacky, Thomas /* Configure the netdev resource */
40347f164deSLendacky, Thomas ret = xgbe_config_netdev(pdata);
40447f164deSLendacky, Thomas if (ret)
405e7537740STom Lendacky goto err_irq_vectors;
40647f164deSLendacky, Thomas
40747f164deSLendacky, Thomas netdev_notice(pdata->netdev, "net device enabled\n");
40847f164deSLendacky, Thomas
40947f164deSLendacky, Thomas return 0;
41047f164deSLendacky, Thomas
411e7537740STom Lendacky err_irq_vectors:
412e7537740STom Lendacky pci_free_irq_vectors(pdata->pcidev);
413e7537740STom Lendacky
41447f164deSLendacky, Thomas err_pci_enable:
41547f164deSLendacky, Thomas xgbe_free_pdata(pdata);
41647f164deSLendacky, Thomas
41747f164deSLendacky, Thomas err_alloc:
41847f164deSLendacky, Thomas dev_notice(dev, "net device not enabled\n");
41947f164deSLendacky, Thomas
42047f164deSLendacky, Thomas return ret;
42147f164deSLendacky, Thomas }
42247f164deSLendacky, Thomas
xgbe_pci_remove(struct pci_dev * pdev)42347f164deSLendacky, Thomas static void xgbe_pci_remove(struct pci_dev *pdev)
42447f164deSLendacky, Thomas {
42547f164deSLendacky, Thomas struct xgbe_prv_data *pdata = pci_get_drvdata(pdev);
42647f164deSLendacky, Thomas
42747f164deSLendacky, Thomas xgbe_deconfig_netdev(pdata);
42847f164deSLendacky, Thomas
429e7537740STom Lendacky pci_free_irq_vectors(pdata->pcidev);
430e7537740STom Lendacky
43168c2d6afSRaju Rangoju /* Disable all interrupts in the hardware */
43268c2d6afSRaju Rangoju XP_IOWRITE(pdata, XP_INT_EN, 0x0);
43368c2d6afSRaju Rangoju
43447f164deSLendacky, Thomas xgbe_free_pdata(pdata);
43547f164deSLendacky, Thomas }
43647f164deSLendacky, Thomas
xgbe_pci_suspend(struct device * dev)437c6f0fb5dSVaibhav Gupta static int __maybe_unused xgbe_pci_suspend(struct device *dev)
43847f164deSLendacky, Thomas {
439c6f0fb5dSVaibhav Gupta struct xgbe_prv_data *pdata = dev_get_drvdata(dev);
44047f164deSLendacky, Thomas struct net_device *netdev = pdata->netdev;
44147f164deSLendacky, Thomas int ret = 0;
44247f164deSLendacky, Thomas
44347f164deSLendacky, Thomas if (netif_running(netdev))
44447f164deSLendacky, Thomas ret = xgbe_powerdown(netdev, XGMAC_DRIVER_CONTEXT);
44547f164deSLendacky, Thomas
44647f164deSLendacky, Thomas pdata->lpm_ctrl = XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_CTRL1);
44747f164deSLendacky, Thomas pdata->lpm_ctrl |= MDIO_CTRL1_LPOWER;
44847f164deSLendacky, Thomas XMDIO_WRITE(pdata, MDIO_MMD_PCS, MDIO_CTRL1, pdata->lpm_ctrl);
44947f164deSLendacky, Thomas
45047f164deSLendacky, Thomas return ret;
45147f164deSLendacky, Thomas }
45247f164deSLendacky, Thomas
xgbe_pci_resume(struct device * dev)453c6f0fb5dSVaibhav Gupta static int __maybe_unused xgbe_pci_resume(struct device *dev)
45447f164deSLendacky, Thomas {
455c6f0fb5dSVaibhav Gupta struct xgbe_prv_data *pdata = dev_get_drvdata(dev);
45647f164deSLendacky, Thomas struct net_device *netdev = pdata->netdev;
45747f164deSLendacky, Thomas int ret = 0;
45847f164deSLendacky, Thomas
459cfd092f2STom Lendacky XP_IOWRITE(pdata, XP_INT_EN, 0x1fffff);
460cfd092f2STom Lendacky
46147f164deSLendacky, Thomas pdata->lpm_ctrl &= ~MDIO_CTRL1_LPOWER;
46247f164deSLendacky, Thomas XMDIO_WRITE(pdata, MDIO_MMD_PCS, MDIO_CTRL1, pdata->lpm_ctrl);
46347f164deSLendacky, Thomas
46447f164deSLendacky, Thomas if (netif_running(netdev)) {
46547f164deSLendacky, Thomas ret = xgbe_powerup(netdev, XGMAC_DRIVER_CONTEXT);
46647f164deSLendacky, Thomas
46747f164deSLendacky, Thomas /* Schedule a restart in case the link or phy state changed
46847f164deSLendacky, Thomas * while we were powered down.
46947f164deSLendacky, Thomas */
47047f164deSLendacky, Thomas schedule_work(&pdata->restart_work);
47147f164deSLendacky, Thomas }
47247f164deSLendacky, Thomas
47347f164deSLendacky, Thomas return ret;
47447f164deSLendacky, Thomas }
47547f164deSLendacky, Thomas
4766f60ecf2SRaju Rangoju static struct xgbe_version_data xgbe_v2a = {
47747f164deSLendacky, Thomas .init_function_ptrs_phy_impl = xgbe_init_function_ptrs_phy_v2,
47847f164deSLendacky, Thomas .xpcs_access = XGBE_XPCS_ACCESS_V2,
47947f164deSLendacky, Thomas .mmc_64bit = 1,
48047f164deSLendacky, Thomas .tx_max_fifo_size = 229376,
48147f164deSLendacky, Thomas .rx_max_fifo_size = 229376,
48247f164deSLendacky, Thomas .tx_tstamp_workaround = 1,
483e78332b2SLendacky, Thomas .ecc_support = 1,
4845ab1dcd5SLendacky, Thomas .i2c_support = 1,
48585b85c85SLendacky, Thomas .irq_reissue_support = 1,
4866f595959SLendacky, Thomas .tx_desc_prefetch = 5,
4876f595959SLendacky, Thomas .rx_desc_prefetch = 5,
48896f4d430STom Lendacky .an_cdr_workaround = 1,
489*f97fc7efSRaju Rangoju .enable_rrc = 1,
49047f164deSLendacky, Thomas };
49147f164deSLendacky, Thomas
4926f60ecf2SRaju Rangoju static struct xgbe_version_data xgbe_v2b = {
49347f164deSLendacky, Thomas .init_function_ptrs_phy_impl = xgbe_init_function_ptrs_phy_v2,
49447f164deSLendacky, Thomas .xpcs_access = XGBE_XPCS_ACCESS_V2,
49547f164deSLendacky, Thomas .mmc_64bit = 1,
49647f164deSLendacky, Thomas .tx_max_fifo_size = 65536,
49747f164deSLendacky, Thomas .rx_max_fifo_size = 65536,
49847f164deSLendacky, Thomas .tx_tstamp_workaround = 1,
499e78332b2SLendacky, Thomas .ecc_support = 1,
5005ab1dcd5SLendacky, Thomas .i2c_support = 1,
50185b85c85SLendacky, Thomas .irq_reissue_support = 1,
5026f595959SLendacky, Thomas .tx_desc_prefetch = 5,
5036f595959SLendacky, Thomas .rx_desc_prefetch = 5,
50496f4d430STom Lendacky .an_cdr_workaround = 1,
505*f97fc7efSRaju Rangoju .enable_rrc = 1,
50647f164deSLendacky, Thomas };
50747f164deSLendacky, Thomas
50847f164deSLendacky, Thomas static const struct pci_device_id xgbe_pci_table[] = {
50947f164deSLendacky, Thomas { PCI_VDEVICE(AMD, 0x1458),
51047f164deSLendacky, Thomas .driver_data = (kernel_ulong_t)&xgbe_v2a },
51147f164deSLendacky, Thomas { PCI_VDEVICE(AMD, 0x1459),
51247f164deSLendacky, Thomas .driver_data = (kernel_ulong_t)&xgbe_v2b },
51347f164deSLendacky, Thomas /* Last entry must be zero */
51447f164deSLendacky, Thomas { 0, }
51547f164deSLendacky, Thomas };
51647f164deSLendacky, Thomas MODULE_DEVICE_TABLE(pci, xgbe_pci_table);
51747f164deSLendacky, Thomas
518c6f0fb5dSVaibhav Gupta static SIMPLE_DEV_PM_OPS(xgbe_pci_pm_ops, xgbe_pci_suspend, xgbe_pci_resume);
519c6f0fb5dSVaibhav Gupta
52047f164deSLendacky, Thomas static struct pci_driver xgbe_driver = {
52147f164deSLendacky, Thomas .name = XGBE_DRV_NAME,
52247f164deSLendacky, Thomas .id_table = xgbe_pci_table,
52347f164deSLendacky, Thomas .probe = xgbe_pci_probe,
52447f164deSLendacky, Thomas .remove = xgbe_pci_remove,
525c6f0fb5dSVaibhav Gupta .driver = {
526c6f0fb5dSVaibhav Gupta .pm = &xgbe_pci_pm_ops,
527c6f0fb5dSVaibhav Gupta }
52847f164deSLendacky, Thomas };
52947f164deSLendacky, Thomas
xgbe_pci_init(void)53047f164deSLendacky, Thomas int xgbe_pci_init(void)
53147f164deSLendacky, Thomas {
53247f164deSLendacky, Thomas return pci_register_driver(&xgbe_driver);
53347f164deSLendacky, Thomas }
53447f164deSLendacky, Thomas
xgbe_pci_exit(void)53547f164deSLendacky, Thomas void xgbe_pci_exit(void)
53647f164deSLendacky, Thomas {
53747f164deSLendacky, Thomas pci_unregister_driver(&xgbe_driver);
53847f164deSLendacky, Thomas }
539