2019-11-04 19:13:17 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2015-08-05 17:22:42 +02:00
|
|
|
/*
|
|
|
|
* ddbridge.c: Digital Devices PCIe bridge driver
|
|
|
|
*
|
2019-11-04 19:13:17 +01:00
|
|
|
* Copyright (C) 2010-2017 Digital Devices GmbH
|
2015-08-05 17:22:42 +02:00
|
|
|
* Ralph Metzler <rjkm@metzlerbros.de>
|
|
|
|
* Marcus Metzler <mocm@metzlerbros.de>
|
2016-02-12 18:28:00 +01:00
|
|
|
*
|
2015-08-05 17:22:42 +02:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* version 2 only, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2019-11-04 19:13:17 +01:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2015-08-05 17:22:42 +02:00
|
|
|
*/
|
2019-11-04 19:13:17 +01:00
|
|
|
|
2017-08-02 17:40:24 +02:00
|
|
|
#include "ddbridge.h"
|
2017-08-02 20:22:52 +02:00
|
|
|
#include "ddbridge-io.h"
|
2015-08-05 17:22:42 +02:00
|
|
|
|
2017-08-02 17:40:24 +02:00
|
|
|
#ifdef CONFIG_PCI_MSI
|
|
|
|
static int msi = 1;
|
|
|
|
module_param(msi, int, 0444);
|
|
|
|
MODULE_PARM_DESC(msi,
|
|
|
|
" Control MSI interrupts: 0-disable, 1-enable (default)");
|
|
|
|
#endif
|
2015-08-05 17:22:42 +02:00
|
|
|
|
2017-10-22 19:55:07 +02:00
|
|
|
#if (KERNEL_VERSION(4, 8, 0) > LINUX_VERSION_CODE)
|
2018-03-02 10:46:28 +01:00
|
|
|
#if (KERNEL_VERSION(3, 19, 0) > LINUX_VERSION_CODE)
|
|
|
|
#define msi_desc_to_dev(desc) (&(desc)->dev.dev)
|
|
|
|
#define dev_to_msi_list(dev) (&to_pci_dev((dev))->msi_list)
|
|
|
|
#define first_msi_entry(dev) \
|
|
|
|
list_first_entry(dev_to_msi_list((dev)), struct msi_desc, list)
|
|
|
|
#define for_each_msi_entry(desc, dev) \
|
|
|
|
list_for_each_entry((desc), dev_to_msi_list((dev)), list)
|
|
|
|
|
|
|
|
#ifdef CONFIG_PCI_MSI
|
|
|
|
#define first_pci_msi_entry(pdev) first_msi_entry(&(pdev)->dev)
|
|
|
|
#define for_each_pci_msi_entry(desc, pdev) \
|
|
|
|
for_each_msi_entry((desc), &(pdev)->dev)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2018-01-16 23:54:51 +01:00
|
|
|
#include <linux/msi.h>
|
|
|
|
|
2017-10-22 19:55:07 +02:00
|
|
|
int pci_irq_vector(struct pci_dev *dev, unsigned int nr)
|
|
|
|
{
|
2018-03-02 10:46:28 +01:00
|
|
|
#ifdef CONFIG_PCI_MSI
|
2017-10-22 19:55:07 +02:00
|
|
|
if (dev->msix_enabled) {
|
|
|
|
struct msi_desc *entry;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
for_each_pci_msi_entry(entry, dev) {
|
|
|
|
if (i == nr)
|
|
|
|
return entry->irq;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
WARN_ON_ONCE(1);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2018-03-02 10:46:28 +01:00
|
|
|
/* This does not work < 3.19 because nvec_used is used differently. */
|
|
|
|
#if (KERNEL_VERSION(3, 19, 0) <= LINUX_VERSION_CODE)
|
2017-10-22 19:55:07 +02:00
|
|
|
if (dev->msi_enabled) {
|
|
|
|
struct msi_desc *entry = first_pci_msi_entry(dev);
|
|
|
|
|
|
|
|
if (WARN_ON_ONCE(nr >= entry->nvec_used))
|
|
|
|
return -EINVAL;
|
|
|
|
} else {
|
|
|
|
if (WARN_ON_ONCE(nr > 0))
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2018-03-02 10:46:28 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
2017-10-22 19:55:07 +02:00
|
|
|
return dev->irq + nr;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-08-05 17:22:42 +02:00
|
|
|
/****************************************************************************/
|
|
|
|
/****************************************************************************/
|
|
|
|
/****************************************************************************/
|
|
|
|
|
2022-10-25 19:29:38 +02:00
|
|
|
static void ddb_irq_disable(struct ddb *dev)
|
2016-04-15 18:08:51 +02:00
|
|
|
{
|
2016-05-02 16:27:32 +02:00
|
|
|
if (dev->link[0].info->regmap->irq_version == 2) {
|
2016-05-03 22:05:29 +02:00
|
|
|
ddbwritel(dev, 0x00000000, INTERRUPT_V2_CONTROL);
|
2016-04-15 18:08:51 +02:00
|
|
|
ddbwritel(dev, 0x00000000, INTERRUPT_V2_ENABLE_1);
|
|
|
|
ddbwritel(dev, 0x00000000, INTERRUPT_V2_ENABLE_2);
|
|
|
|
ddbwritel(dev, 0x00000000, INTERRUPT_V2_ENABLE_3);
|
|
|
|
ddbwritel(dev, 0x00000000, INTERRUPT_V2_ENABLE_4);
|
|
|
|
ddbwritel(dev, 0x00000000, INTERRUPT_V2_ENABLE_5);
|
|
|
|
ddbwritel(dev, 0x00000000, INTERRUPT_V2_ENABLE_6);
|
|
|
|
ddbwritel(dev, 0x00000000, INTERRUPT_V2_ENABLE_7);
|
|
|
|
} else {
|
|
|
|
ddbwritel(dev, 0, INTERRUPT_ENABLE);
|
|
|
|
ddbwritel(dev, 0, MSI1_ENABLE);
|
|
|
|
}
|
2016-04-15 23:53:20 +02:00
|
|
|
}
|
|
|
|
|
2018-01-16 23:54:51 +01:00
|
|
|
static void __devexit ddb_msi_exit(struct ddb *dev)
|
2016-04-15 23:53:20 +02:00
|
|
|
{
|
2016-04-15 18:08:51 +02:00
|
|
|
#ifdef CONFIG_PCI_MSI
|
2017-10-22 19:55:07 +02:00
|
|
|
if (dev->msi) {
|
2018-01-16 23:54:51 +01:00
|
|
|
#if (KERNEL_VERSION(4, 8, 0) <= LINUX_VERSION_CODE)
|
2017-10-22 19:55:07 +02:00
|
|
|
pci_free_irq_vectors(dev->pdev);
|
2018-01-16 23:54:51 +01:00
|
|
|
#else
|
2016-04-15 18:08:51 +02:00
|
|
|
pci_disable_msi(dev->pdev);
|
2018-01-16 23:54:51 +01:00
|
|
|
#endif
|
2017-10-22 19:55:07 +02:00
|
|
|
}
|
2016-04-15 18:08:51 +02:00
|
|
|
#endif
|
|
|
|
}
|
2015-08-05 17:22:42 +02:00
|
|
|
|
2022-10-25 19:29:38 +02:00
|
|
|
static void ddb_irq_exit(struct ddb *dev)
|
2018-01-16 23:54:51 +01:00
|
|
|
{
|
|
|
|
ddb_irq_disable(dev);
|
|
|
|
if (dev->msi == 2)
|
|
|
|
free_irq(pci_irq_vector(dev->pdev, 1), dev);
|
|
|
|
free_irq(pci_irq_vector(dev->pdev, 0), dev);
|
|
|
|
}
|
|
|
|
|
2015-08-05 17:22:42 +02:00
|
|
|
static void __devexit ddb_remove(struct pci_dev *pdev)
|
|
|
|
{
|
2017-08-26 22:04:37 +02:00
|
|
|
struct ddb *dev = (struct ddb *)pci_get_drvdata(pdev);
|
2015-08-05 17:22:42 +02:00
|
|
|
|
2015-12-10 18:26:45 +01:00
|
|
|
ddb_device_destroy(dev);
|
2015-08-05 17:22:42 +02:00
|
|
|
ddb_nsd_detach(dev);
|
|
|
|
ddb_ports_detach(dev);
|
|
|
|
ddb_i2c_release(dev);
|
|
|
|
|
|
|
|
if (dev->link[0].info->ns_num)
|
|
|
|
ddbwritel(dev, 0, ETHER_CONTROL);
|
2016-04-15 18:08:51 +02:00
|
|
|
ddb_irq_exit(dev);
|
2018-01-16 23:54:51 +01:00
|
|
|
ddb_msi_exit(dev);
|
2015-08-05 17:22:42 +02:00
|
|
|
ddb_ports_release(dev);
|
|
|
|
ddb_buffers_free(dev);
|
|
|
|
|
|
|
|
ddb_unmap(dev);
|
2021-02-24 20:17:50 +01:00
|
|
|
pci_clear_master(pdev);
|
2015-12-21 13:48:44 +01:00
|
|
|
pci_set_drvdata(pdev, NULL);
|
2015-08-05 17:22:42 +02:00
|
|
|
pci_disable_device(pdev);
|
|
|
|
}
|
|
|
|
|
2017-09-25 19:20:17 +02:00
|
|
|
#if (KERNEL_VERSION(3, 8, 0) <= LINUX_VERSION_CODE)
|
2015-08-05 17:22:42 +02:00
|
|
|
#define __devinit
|
|
|
|
#define __devinitdata
|
|
|
|
#endif
|
|
|
|
|
2016-04-15 18:08:51 +02:00
|
|
|
static int __devinit ddb_irq_msi(struct ddb *dev, int nr)
|
|
|
|
{
|
2017-02-21 17:12:35 +01:00
|
|
|
int stat = 0;
|
2016-04-15 18:08:51 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_PCI_MSI
|
|
|
|
if (msi && pci_msi_enabled()) {
|
2017-09-25 19:20:17 +02:00
|
|
|
#if (KERNEL_VERSION(3, 15, 0) <= LINUX_VERSION_CODE)
|
2017-10-22 19:55:07 +02:00
|
|
|
#if (KERNEL_VERSION(4, 8, 0) <= LINUX_VERSION_CODE)
|
|
|
|
stat = pci_alloc_irq_vectors(dev->pdev, 1, nr,
|
|
|
|
PCI_IRQ_MSI | PCI_IRQ_MSIX);
|
2017-04-10 17:32:16 +02:00
|
|
|
#else
|
|
|
|
stat = pci_enable_msi_range(dev->pdev, 1, nr);
|
2017-04-10 11:45:43 +02:00
|
|
|
#endif
|
2016-04-15 18:08:51 +02:00
|
|
|
if (stat >= 1) {
|
|
|
|
dev->msi = stat;
|
2017-08-25 23:30:58 +02:00
|
|
|
dev_info(dev->dev, "using %d MSI interrupt(s)\n",
|
|
|
|
dev->msi);
|
2017-08-26 22:04:37 +02:00
|
|
|
} else {
|
2017-08-25 23:30:58 +02:00
|
|
|
dev_info(dev->dev, "MSI not available.\n");
|
2017-08-26 22:04:37 +02:00
|
|
|
}
|
2016-04-15 18:08:51 +02:00
|
|
|
#else
|
|
|
|
stat = pci_enable_msi_block(dev->pdev, nr);
|
|
|
|
if (stat == 0) {
|
2016-04-15 19:16:04 +02:00
|
|
|
dev->msi = nr;
|
2017-08-25 23:30:58 +02:00
|
|
|
dev_info(dev->dev, "using %d MSI interrupts\n", nr);
|
2016-05-02 16:27:32 +02:00
|
|
|
} else if (stat == 1) {
|
2016-04-15 18:08:51 +02:00
|
|
|
stat = pci_enable_msi(dev->pdev);
|
2016-05-02 16:27:32 +02:00
|
|
|
dev->msi = 1;
|
2016-04-15 18:08:51 +02:00
|
|
|
}
|
2017-04-16 21:20:52 +02:00
|
|
|
if (stat < 0)
|
2017-08-25 23:30:58 +02:00
|
|
|
dev_info(dev->dev, "MSI not available.\n");
|
2016-04-15 18:08:51 +02:00
|
|
|
#endif
|
|
|
|
}
|
2017-08-26 10:32:53 +02:00
|
|
|
#endif
|
2016-04-15 18:08:51 +02:00
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __devinit ddb_irq_init2(struct ddb *dev)
|
|
|
|
{
|
|
|
|
int stat;
|
|
|
|
int irq_flag = IRQF_SHARED;
|
|
|
|
|
2017-08-25 23:30:58 +02:00
|
|
|
dev_info(dev->dev, "init type 2 IRQ hardware block\n");
|
2016-04-15 18:08:51 +02:00
|
|
|
|
|
|
|
ddbwritel(dev, 0x00000000, INTERRUPT_V2_CONTROL);
|
|
|
|
ddbwritel(dev, 0x00000000, INTERRUPT_V2_ENABLE_1);
|
|
|
|
ddbwritel(dev, 0x00000000, INTERRUPT_V2_ENABLE_2);
|
|
|
|
ddbwritel(dev, 0x00000000, INTERRUPT_V2_ENABLE_3);
|
|
|
|
ddbwritel(dev, 0x00000000, INTERRUPT_V2_ENABLE_4);
|
|
|
|
ddbwritel(dev, 0x00000000, INTERRUPT_V2_ENABLE_5);
|
|
|
|
ddbwritel(dev, 0x00000000, INTERRUPT_V2_ENABLE_6);
|
|
|
|
ddbwritel(dev, 0x00000000, INTERRUPT_V2_ENABLE_7);
|
|
|
|
|
|
|
|
ddb_irq_msi(dev, 1);
|
|
|
|
if (dev->msi)
|
|
|
|
irq_flag = 0;
|
|
|
|
|
2017-10-22 19:55:07 +02:00
|
|
|
stat = request_irq(pci_irq_vector(dev->pdev, 0), ddb_irq_handler_v2,
|
2017-08-26 22:04:37 +02:00
|
|
|
irq_flag, "ddbridge", (void *)dev);
|
2016-04-15 18:08:51 +02:00
|
|
|
if (stat < 0)
|
|
|
|
return stat;
|
2017-04-16 21:20:52 +02:00
|
|
|
|
2016-05-03 22:05:29 +02:00
|
|
|
ddbwritel(dev, 0x0000ff7f, INTERRUPT_V2_CONTROL);
|
2016-04-15 18:08:51 +02:00
|
|
|
ddbwritel(dev, 0xffffffff, INTERRUPT_V2_ENABLE_1);
|
|
|
|
ddbwritel(dev, 0xffffffff, INTERRUPT_V2_ENABLE_2);
|
|
|
|
ddbwritel(dev, 0xffffffff, INTERRUPT_V2_ENABLE_3);
|
|
|
|
ddbwritel(dev, 0xffffffff, INTERRUPT_V2_ENABLE_4);
|
|
|
|
ddbwritel(dev, 0xffffffff, INTERRUPT_V2_ENABLE_5);
|
|
|
|
ddbwritel(dev, 0xffffffff, INTERRUPT_V2_ENABLE_6);
|
|
|
|
ddbwritel(dev, 0xffffffff, INTERRUPT_V2_ENABLE_7);
|
|
|
|
return stat;
|
|
|
|
}
|
2017-04-16 21:20:52 +02:00
|
|
|
|
2016-04-15 18:08:51 +02:00
|
|
|
static int __devinit ddb_irq_init(struct ddb *dev)
|
|
|
|
{
|
|
|
|
int stat;
|
|
|
|
int irq_flag = IRQF_SHARED;
|
2017-04-16 21:20:52 +02:00
|
|
|
|
2016-05-02 16:27:32 +02:00
|
|
|
if (dev->link[0].info->regmap->irq_version == 2)
|
2016-04-15 18:08:51 +02:00
|
|
|
return ddb_irq_init2(dev);
|
2017-04-16 21:20:52 +02:00
|
|
|
|
2016-04-15 18:08:51 +02:00
|
|
|
ddbwritel(dev, 0x00000000, INTERRUPT_ENABLE);
|
|
|
|
ddbwritel(dev, 0x00000000, MSI1_ENABLE);
|
|
|
|
ddbwritel(dev, 0x00000000, MSI2_ENABLE);
|
|
|
|
ddbwritel(dev, 0x00000000, MSI3_ENABLE);
|
|
|
|
ddbwritel(dev, 0x00000000, MSI4_ENABLE);
|
|
|
|
ddbwritel(dev, 0x00000000, MSI5_ENABLE);
|
|
|
|
ddbwritel(dev, 0x00000000, MSI6_ENABLE);
|
|
|
|
ddbwritel(dev, 0x00000000, MSI7_ENABLE);
|
|
|
|
|
|
|
|
ddb_irq_msi(dev, 2);
|
|
|
|
|
|
|
|
if (dev->msi)
|
|
|
|
irq_flag = 0;
|
|
|
|
if (dev->msi == 2) {
|
2017-10-22 19:55:07 +02:00
|
|
|
stat = request_irq(pci_irq_vector(dev->pdev, 0), ddb_irq_handler0,
|
2017-08-26 22:04:37 +02:00
|
|
|
irq_flag, "ddbridge", (void *)dev);
|
2016-04-15 18:08:51 +02:00
|
|
|
if (stat < 0)
|
|
|
|
return stat;
|
2017-10-22 19:55:07 +02:00
|
|
|
stat = request_irq(pci_irq_vector(dev->pdev, 1), ddb_irq_handler1,
|
2017-08-26 22:04:37 +02:00
|
|
|
irq_flag, "ddbridge", (void *)dev);
|
2016-04-15 18:08:51 +02:00
|
|
|
if (stat < 0) {
|
2017-10-22 19:55:07 +02:00
|
|
|
free_irq(pci_irq_vector(dev->pdev, 0), dev);
|
2016-04-15 18:08:51 +02:00
|
|
|
return stat;
|
|
|
|
}
|
2017-07-18 01:25:55 +02:00
|
|
|
} else {
|
2017-10-22 19:55:07 +02:00
|
|
|
stat = request_irq(pci_irq_vector(dev->pdev, 0),
|
|
|
|
ddb_irq_handler,
|
2017-08-26 22:04:37 +02:00
|
|
|
irq_flag, "ddbridge", (void *)dev);
|
2016-04-15 18:08:51 +02:00
|
|
|
if (stat < 0)
|
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
/*ddbwritel(dev, 0xffffffff, INTERRUPT_ACK);*/
|
|
|
|
if (dev->msi == 2) {
|
|
|
|
ddbwritel(dev, 0x0fffff00, INTERRUPT_ENABLE);
|
|
|
|
ddbwritel(dev, 0x0000000f, MSI1_ENABLE);
|
|
|
|
} else {
|
|
|
|
ddbwritel(dev, 0x0fffff0f, INTERRUPT_ENABLE);
|
|
|
|
ddbwritel(dev, 0x00000000, MSI1_ENABLE);
|
|
|
|
}
|
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
|
2015-08-05 17:22:42 +02:00
|
|
|
static int __devinit ddb_probe(struct pci_dev *pdev,
|
|
|
|
const struct pci_device_id *id)
|
|
|
|
{
|
|
|
|
struct ddb *dev;
|
|
|
|
int stat = 0;
|
|
|
|
|
|
|
|
if (pci_enable_device(pdev) < 0)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2016-04-21 20:11:09 +02:00
|
|
|
pci_set_master(pdev);
|
|
|
|
|
2022-06-07 16:12:19 +02:00
|
|
|
#if (KERNEL_VERSION(5, 18, 0) <= LINUX_VERSION_CODE)
|
|
|
|
if (dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)))
|
|
|
|
if (dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)))
|
|
|
|
#else
|
2020-12-01 15:57:31 +01:00
|
|
|
if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
|
|
|
|
pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
|
|
|
|
} else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
|
|
|
|
pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
|
2022-06-07 16:12:19 +02:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
return -ENODEV;
|
2017-04-16 21:20:52 +02:00
|
|
|
|
2017-08-26 22:04:37 +02:00
|
|
|
dev = vzalloc(sizeof(*dev));
|
|
|
|
if (!dev)
|
2015-08-05 17:22:42 +02:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
mutex_init(&dev->mutex);
|
|
|
|
dev->has_dma = 1;
|
|
|
|
dev->pdev = pdev;
|
|
|
|
dev->dev = &pdev->dev;
|
|
|
|
pci_set_drvdata(pdev, dev);
|
|
|
|
|
2015-09-06 19:08:57 +02:00
|
|
|
dev->link[0].ids.vendor = id->vendor;
|
|
|
|
dev->link[0].ids.device = id->device;
|
|
|
|
dev->link[0].ids.subvendor = id->subvendor;
|
2017-07-24 22:24:47 +02:00
|
|
|
dev->link[0].ids.subdevice = pdev->subsystem_device;
|
2018-02-12 22:43:45 +01:00
|
|
|
dev->link[0].ids.devid = (id->device << 16) | id->vendor;
|
2021-04-07 19:21:24 +02:00
|
|
|
dev->link[0].ids.revision = pdev->revision;
|
2017-08-26 10:32:53 +02:00
|
|
|
|
2015-08-05 17:22:42 +02:00
|
|
|
dev->link[0].dev = dev;
|
2017-07-24 22:24:47 +02:00
|
|
|
dev->link[0].info = get_ddb_info(id->vendor, id->device,
|
|
|
|
id->subvendor, pdev->subsystem_device);
|
2015-08-05 17:22:42 +02:00
|
|
|
|
|
|
|
dev->regs_len = pci_resource_len(dev->pdev, 0);
|
|
|
|
dev->regs = ioremap(pci_resource_start(dev->pdev, 0),
|
|
|
|
pci_resource_len(dev->pdev, 0));
|
|
|
|
|
|
|
|
if (!dev->regs) {
|
2017-08-25 23:30:58 +02:00
|
|
|
dev_err(dev->dev, "not enough memory for register map\n");
|
2015-08-05 17:22:42 +02:00
|
|
|
stat = -ENOMEM;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
if (ddbreadl(dev, 0) == 0xffffffff) {
|
2017-08-25 23:30:58 +02:00
|
|
|
dev_err(dev->dev, "cannot read registers\n");
|
2015-08-05 17:22:42 +02:00
|
|
|
stat = -ENODEV;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2015-09-06 19:08:57 +02:00
|
|
|
dev->link[0].ids.hwid = ddbreadl(dev, 0);
|
|
|
|
dev->link[0].ids.regmapid = ddbreadl(dev, 4);
|
2015-08-05 17:22:42 +02:00
|
|
|
|
2018-05-02 15:39:09 +02:00
|
|
|
if ((dev->link[0].ids.hwid & 0xffffff) <
|
|
|
|
dev->link[0].info->hw_min) {
|
|
|
|
u32 min = dev->link[0].info->hw_min;
|
|
|
|
|
|
|
|
dev_err(dev->dev, "Update firmware to at least version %u.%u to ensure full functionality!\n",
|
2022-06-07 16:37:10 +02:00
|
|
|
(min & 0xff0000) >> 16, min & 0xffff);
|
2018-05-02 15:39:09 +02:00
|
|
|
}
|
2015-08-05 17:22:42 +02:00
|
|
|
|
|
|
|
if (dev->link[0].info->ns_num) {
|
|
|
|
ddbwritel(dev, 0, ETHER_CONTROL);
|
2016-05-02 16:27:32 +02:00
|
|
|
ddb_reset_ios(dev);
|
2015-08-05 17:22:42 +02:00
|
|
|
}
|
|
|
|
ddbwritel(dev, 0, DMA_BASE_READ);
|
|
|
|
if (dev->link[0].info->type != DDB_MOD)
|
|
|
|
ddbwritel(dev, 0, DMA_BASE_WRITE);
|
2016-02-12 18:28:00 +01:00
|
|
|
|
2022-06-07 16:37:10 +02:00
|
|
|
if (dev->link[0].info->type == DDB_MOD &&
|
|
|
|
dev->link[0].info->version <= 1) {
|
2017-09-08 14:47:14 +02:00
|
|
|
if (ddbreadl(dev, 0x1c) == 4)
|
|
|
|
dev->link[0].info =
|
2017-09-10 22:25:02 +02:00
|
|
|
get_ddb_info(0xdd01, 0x0201, 0xdd01, 0x0004);
|
|
|
|
}
|
2022-12-12 11:24:45 +01:00
|
|
|
|
2022-06-07 16:37:10 +02:00
|
|
|
if (dev->link[0].info->type == DDB_MOD &&
|
2022-12-12 11:24:45 +01:00
|
|
|
dev->link[0].info->version == 2) {
|
|
|
|
if (dev->link[0].ids.revision == 1)
|
|
|
|
dev->link[0].info = get_ddb_info(0xdd01, 0x0210, 0xdd01, 0x0004);
|
|
|
|
else if ((ddbreadl(dev, 0x1c) & 7) != 7)
|
|
|
|
dev->link[0].info = get_ddb_info(0xdd01, 0x0210, 0xdd01, 0x0004);
|
|
|
|
}
|
2020-08-29 15:32:42 +02:00
|
|
|
|
2022-10-30 23:23:44 +01:00
|
|
|
dev_info(dev->dev, "%s\n", dev->link[0].info->name);
|
2022-02-12 15:49:53 +01:00
|
|
|
dev_info(dev->dev, "HW %08x REGMAP %08x FW %u.%u\n",
|
|
|
|
dev->link[0].ids.hwid, dev->link[0].ids.regmapid,
|
|
|
|
(dev->link[0].ids.hwid & 0xff0000) >> 16,
|
|
|
|
dev->link[0].ids.hwid & 0xffff);
|
|
|
|
|
2016-04-15 18:08:51 +02:00
|
|
|
stat = ddb_irq_init(dev);
|
|
|
|
if (stat < 0)
|
|
|
|
goto fail0;
|
2017-04-16 21:20:52 +02:00
|
|
|
|
2015-08-05 17:22:42 +02:00
|
|
|
if (ddb_init(dev) == 0)
|
|
|
|
return 0;
|
2016-02-12 18:28:00 +01:00
|
|
|
|
2017-02-21 17:12:35 +01:00
|
|
|
ddb_irq_exit(dev);
|
2015-08-05 17:22:42 +02:00
|
|
|
fail0:
|
2017-08-25 23:30:58 +02:00
|
|
|
dev_err(dev->dev, "fail0\n");
|
2018-01-16 23:54:51 +01:00
|
|
|
ddb_msi_exit(dev);
|
2015-08-05 17:22:42 +02:00
|
|
|
fail:
|
2017-08-25 23:30:58 +02:00
|
|
|
dev_err(dev->dev, "fail\n");
|
2015-08-05 17:22:42 +02:00
|
|
|
|
|
|
|
ddb_unmap(dev);
|
2015-12-21 13:48:44 +01:00
|
|
|
pci_set_drvdata(pdev, NULL);
|
2015-08-05 17:22:42 +02:00
|
|
|
pci_disable_device(pdev);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
/****************************************************************************/
|
|
|
|
/****************************************************************************/
|
|
|
|
|
2021-12-06 15:40:05 +01:00
|
|
|
#ifndef PCI_DEVICE_SUB
|
|
|
|
#define PCI_DEVICE_SUB(vend, dev, subvend, subdev) \
|
|
|
|
.vendor = (vend), .device = (dev), \
|
|
|
|
.subvendor = (subvend), .subdevice = (subdev)
|
|
|
|
#endif
|
|
|
|
|
2017-08-26 10:32:53 +02:00
|
|
|
#define DDB_DEVICE_ANY(_device) \
|
|
|
|
{ PCI_DEVICE_SUB(0xdd01, _device, 0xdd01, PCI_ANY_ID) }
|
2017-04-07 12:28:55 +02:00
|
|
|
|
|
|
|
static const struct pci_device_id ddb_id_table[] __devinitconst = {
|
2017-07-24 22:24:47 +02:00
|
|
|
DDB_DEVICE_ANY(0x0002),
|
2017-04-07 12:28:55 +02:00
|
|
|
DDB_DEVICE_ANY(0x0003),
|
|
|
|
DDB_DEVICE_ANY(0x0005),
|
|
|
|
DDB_DEVICE_ANY(0x0006),
|
|
|
|
DDB_DEVICE_ANY(0x0007),
|
|
|
|
DDB_DEVICE_ANY(0x0008),
|
2017-12-05 19:26:26 +01:00
|
|
|
DDB_DEVICE_ANY(0x0009),
|
2018-06-23 16:47:10 +02:00
|
|
|
DDB_DEVICE_ANY(0x000a),
|
2019-11-12 18:16:39 +01:00
|
|
|
DDB_DEVICE_ANY(0x000b),
|
2017-04-07 12:28:55 +02:00
|
|
|
DDB_DEVICE_ANY(0x0011),
|
|
|
|
DDB_DEVICE_ANY(0x0012),
|
|
|
|
DDB_DEVICE_ANY(0x0013),
|
2018-08-13 15:05:43 +02:00
|
|
|
DDB_DEVICE_ANY(0x0020),
|
2017-04-07 12:28:55 +02:00
|
|
|
DDB_DEVICE_ANY(0x0201),
|
|
|
|
DDB_DEVICE_ANY(0x0203),
|
|
|
|
DDB_DEVICE_ANY(0x0210),
|
|
|
|
DDB_DEVICE_ANY(0x0220),
|
2018-10-07 18:07:14 +02:00
|
|
|
DDB_DEVICE_ANY(0x0221),
|
2019-01-17 19:08:07 +01:00
|
|
|
DDB_DEVICE_ANY(0x0222),
|
2020-12-01 15:58:35 +01:00
|
|
|
DDB_DEVICE_ANY(0x0223),
|
2017-04-07 12:28:55 +02:00
|
|
|
DDB_DEVICE_ANY(0x0320),
|
|
|
|
DDB_DEVICE_ANY(0x0321),
|
|
|
|
DDB_DEVICE_ANY(0x0322),
|
|
|
|
DDB_DEVICE_ANY(0x0323),
|
|
|
|
DDB_DEVICE_ANY(0x0328),
|
|
|
|
DDB_DEVICE_ANY(0x0329),
|
2015-08-05 17:22:42 +02:00
|
|
|
{0}
|
|
|
|
};
|
2017-04-07 12:28:55 +02:00
|
|
|
MODULE_DEVICE_TABLE(pci, ddb_id_table);
|
2015-08-05 17:22:42 +02:00
|
|
|
|
2019-08-12 21:40:09 +02:00
|
|
|
static pci_ers_result_t ddb_pci_slot_reset(struct pci_dev *dev)
|
|
|
|
{
|
|
|
|
pr_info("pci_slot_reset\n");
|
|
|
|
return PCI_ERS_RESULT_RECOVERED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ddb_pci_resume(struct pci_dev *dev)
|
|
|
|
{
|
|
|
|
pr_info("pci_resume\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static pci_ers_result_t ddb_pci_mmio_enabled(struct pci_dev *pdev)
|
|
|
|
{
|
|
|
|
pr_info("pci_mmio_enabled\n");
|
|
|
|
return PCI_ERS_RESULT_NEED_RESET;
|
|
|
|
}
|
|
|
|
|
|
|
|
static pci_ers_result_t ddb_pci_error_detected(struct pci_dev *pdev,
|
|
|
|
pci_channel_state_t state)
|
|
|
|
{
|
|
|
|
switch (state) {
|
|
|
|
case pci_channel_io_frozen:
|
|
|
|
return PCI_ERS_RESULT_CAN_RECOVER;
|
|
|
|
case pci_channel_io_perm_failure:
|
|
|
|
return PCI_ERS_RESULT_DISCONNECT;
|
|
|
|
case pci_channel_io_normal:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return PCI_ERS_RESULT_NEED_RESET;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct pci_error_handlers ddb_error = {
|
|
|
|
.error_detected = ddb_pci_error_detected,
|
|
|
|
.mmio_enabled = ddb_pci_mmio_enabled,
|
|
|
|
.slot_reset = ddb_pci_slot_reset,
|
|
|
|
.resume = ddb_pci_resume,
|
|
|
|
};
|
|
|
|
|
2015-08-05 17:22:42 +02:00
|
|
|
static struct pci_driver ddb_pci_driver = {
|
|
|
|
.name = "ddbridge",
|
2017-04-07 12:28:55 +02:00
|
|
|
.id_table = ddb_id_table,
|
2015-08-05 17:22:42 +02:00
|
|
|
.probe = ddb_probe,
|
|
|
|
.remove = ddb_remove,
|
2019-08-12 21:40:09 +02:00
|
|
|
.err_handler = &ddb_error,
|
2015-08-05 17:22:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static __init int module_init_ddbridge(void)
|
|
|
|
{
|
2017-10-22 20:58:58 +02:00
|
|
|
int stat;
|
2015-08-05 17:22:42 +02:00
|
|
|
|
2017-08-25 23:30:58 +02:00
|
|
|
pr_info("Digital Devices PCIE bridge driver "
|
2015-08-05 17:22:42 +02:00
|
|
|
DDBRIDGE_VERSION
|
2019-08-12 21:39:33 +02:00
|
|
|
", Copyright (C) 2010-19 Digital Devices GmbH\n");
|
2017-10-22 20:58:58 +02:00
|
|
|
stat = ddb_init_ddbridge();
|
|
|
|
if (stat < 0)
|
|
|
|
return stat;
|
2015-08-05 17:22:42 +02:00
|
|
|
stat = pci_register_driver(&ddb_pci_driver);
|
|
|
|
if (stat < 0)
|
2017-10-22 20:58:58 +02:00
|
|
|
ddb_exit_ddbridge(0, stat);
|
2015-08-05 17:22:42 +02:00
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
|
|
|
|
static __exit void module_exit_ddbridge(void)
|
|
|
|
{
|
|
|
|
pci_unregister_driver(&ddb_pci_driver);
|
2017-10-22 20:58:58 +02:00
|
|
|
ddb_exit_ddbridge(0, 0);
|
2015-08-05 17:22:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(module_init_ddbridge);
|
|
|
|
module_exit(module_exit_ddbridge);
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("Digital Devices PCIe Bridge");
|
|
|
|
MODULE_AUTHOR("Ralph and Marcus Metzler, Metzler Brothers Systementwicklung GbR");
|
2018-03-22 19:32:17 +01:00
|
|
|
MODULE_LICENSE("GPL v2");
|
2015-08-05 17:22:42 +02:00
|
|
|
MODULE_VERSION(DDBRIDGE_VERSION);
|