コード例 #1
0
static int __devinit pci200_pci_init_one(struct pci_dev *pdev,
					 const struct pci_device_id *ent)
{
	card_t *card;
	u32 __iomem *p;
	int i;
	u32 ramsize;
	u32 ramphys;		/* buffer memory base */
	u32 scaphys;		/* SCA memory base */
	u32 plxphys;		/* PLX registers memory base */

	i = pci_enable_device(pdev);
	if (i)
		return i;

	i = pci_request_regions(pdev, "PCI200SYN");
	if (i) {
		pci_disable_device(pdev);
		return i;
	}

	card = kzalloc(sizeof(card_t), GFP_KERNEL);
	if (card == NULL) {
		printk(KERN_ERR "pci200syn: unable to allocate memory\n");
		pci_release_regions(pdev);
		pci_disable_device(pdev);
		return -ENOBUFS;
	}
	pci_set_drvdata(pdev, card);
	card->ports[0].netdev = alloc_hdlcdev(&card->ports[0]);
	card->ports[1].netdev = alloc_hdlcdev(&card->ports[1]);
	if (!card->ports[0].netdev || !card->ports[1].netdev) {
		printk(KERN_ERR "pci200syn: unable to allocate memory\n");
		pci200_pci_remove_one(pdev);
		return -ENOMEM;
	}

	if (pci_resource_len(pdev, 0) != PCI200SYN_PLX_SIZE ||
	    pci_resource_len(pdev, 2) != PCI200SYN_SCA_SIZE ||
	    pci_resource_len(pdev, 3) < 16384) {
		printk(KERN_ERR "pci200syn: invalid card EEPROM parameters\n");
		pci200_pci_remove_one(pdev);
		return -EFAULT;
	}

	plxphys = pci_resource_start(pdev,0) & PCI_BASE_ADDRESS_MEM_MASK;
	card->plxbase = ioremap(plxphys, PCI200SYN_PLX_SIZE);

	scaphys = pci_resource_start(pdev,2) & PCI_BASE_ADDRESS_MEM_MASK;
	card->scabase = ioremap(scaphys, PCI200SYN_SCA_SIZE);

	ramphys = pci_resource_start(pdev,3) & PCI_BASE_ADDRESS_MEM_MASK;
	card->rambase = pci_ioremap_bar(pdev, 3);

	if (card->plxbase == NULL ||
	    card->scabase == NULL ||
	    card->rambase == NULL) {
		printk(KERN_ERR "pci200syn: ioremap() failed\n");
		pci200_pci_remove_one(pdev);
		return -EFAULT;
	}

	/* Reset PLX */
	p = &card->plxbase->init_ctrl;
	writel(readl(p) | 0x40000000, p);
	readl(p);		/* Flush the write - do not use sca_flush */
	udelay(1);

	writel(readl(p) & ~0x40000000, p);
	readl(p);		/* Flush the write - do not use sca_flush */
	udelay(1);

	ramsize = sca_detect_ram(card, card->rambase,
				 pci_resource_len(pdev, 3));

	/* number of TX + RX buffers for one port - this is dual port card */
	i = ramsize / (2 * (sizeof(pkt_desc) + HDLC_MAX_MRU));
	card->tx_ring_buffers = min(i / 2, MAX_TX_BUFFERS);
	card->rx_ring_buffers = i - card->tx_ring_buffers;

	card->buff_offset = 2 * sizeof(pkt_desc) * (card->tx_ring_buffers +
						    card->rx_ring_buffers);

	printk(KERN_INFO "pci200syn: %u KB RAM at 0x%x, IRQ%u, using %u TX +"
	       " %u RX packets rings\n", ramsize / 1024, ramphys,
	       pdev->irq, card->tx_ring_buffers, card->rx_ring_buffers);

	if (card->tx_ring_buffers < 1) {
		printk(KERN_ERR "pci200syn: RAM test failed\n");
		pci200_pci_remove_one(pdev);
		return -EFAULT;
	}

	/* Enable interrupts on the PCI bridge */
	p = &card->plxbase->intr_ctrl_stat;
	writew(readw(p) | 0x0040, p);

	/* Allocate IRQ */
	if (request_irq(pdev->irq, sca_intr, IRQF_SHARED, "pci200syn", card)) {
		printk(KERN_WARNING "pci200syn: could not allocate IRQ%d.\n",
		       pdev->irq);
		pci200_pci_remove_one(pdev);
		return -EBUSY;
	}
	card->irq = pdev->irq;

	sca_init(card, 0);

	for (i = 0; i < 2; i++) {
		port_t *port = &card->ports[i];
		struct net_device *dev = port->netdev;
		hdlc_device *hdlc = dev_to_hdlc(dev);
		port->chan = i;

		spin_lock_init(&port->lock);
		dev->irq = card->irq;
		dev->mem_start = ramphys;
		dev->mem_end = ramphys + ramsize - 1;
		dev->tx_queue_len = 50;
		dev->netdev_ops = &pci200_ops;
		hdlc->attach = sca_attach;
		hdlc->xmit = sca_xmit;
		port->settings.clock_type = CLOCK_EXT;
		port->card = card;
		sca_init_port(port);
		if (register_hdlc_device(dev)) {
			printk(KERN_ERR "pci200syn: unable to register hdlc "
			       "device\n");
			port->card = NULL;
			pci200_pci_remove_one(pdev);
			return -ENOBUFS;
		}

		printk(KERN_INFO "%s: PCI200SYN channel %d\n",
		       dev->name, port->chan);
	}

	sca_flush(card);
	return 0;
}
コード例 #2
0
static int __devinit pci200_pci_init_one(struct pci_dev *pdev,
        const struct pci_device_id *ent)
{
    card_t *card;
    u8 rev_id;
    u32 __iomem *p;
    int i;
    u32 ramsize;
    u32 ramphys;		/* buffer memory base */
    u32 scaphys;		/* SCA memory base */
    u32 plxphys;		/* PLX registers memory base */

#ifndef MODULE
    static int printed_version;
    if (!printed_version++)
        printk(KERN_INFO "%s\n", version);
#endif

    i = pci_enable_device(pdev);
    if (i)
        return i;

    i = pci_request_regions(pdev, "PCI200SYN");
    if (i) {
        pci_disable_device(pdev);
        return i;
    }

    card = kzalloc(sizeof(card_t), GFP_KERNEL);
    if (card == NULL) {
        printk(KERN_ERR "pci200syn: unable to allocate memory\n");
        pci_release_regions(pdev);
        pci_disable_device(pdev);
        return -ENOBUFS;
    }
    pci_set_drvdata(pdev, card);
    card->ports[0].dev = alloc_hdlcdev(&card->ports[0]);
    card->ports[1].dev = alloc_hdlcdev(&card->ports[1]);
    if (!card->ports[0].dev || !card->ports[1].dev) {
        printk(KERN_ERR "pci200syn: unable to allocate memory\n");
        pci200_pci_remove_one(pdev);
        return -ENOMEM;
    }

    pci_read_config_byte(pdev, PCI_REVISION_ID, &rev_id);
    if (pci_resource_len(pdev, 0) != PCI200SYN_PLX_SIZE ||
            pci_resource_len(pdev, 2) != PCI200SYN_SCA_SIZE ||
            pci_resource_len(pdev, 3) < 16384) {
        printk(KERN_ERR "pci200syn: invalid card EEPROM parameters\n");
        pci200_pci_remove_one(pdev);
        return -EFAULT;
    }

    plxphys = pci_resource_start(pdev,0) & PCI_BASE_ADDRESS_MEM_MASK;
    card->plxbase = ioremap(plxphys, PCI200SYN_PLX_SIZE);

    scaphys = pci_resource_start(pdev,2) & PCI_BASE_ADDRESS_MEM_MASK;
    card->scabase = ioremap(scaphys, PCI200SYN_SCA_SIZE);

    ramphys = pci_resource_start(pdev,3) & PCI_BASE_ADDRESS_MEM_MASK;
    card->rambase = ioremap(ramphys, pci_resource_len(pdev,3));

    if (card->plxbase == NULL ||
            card->scabase == NULL ||
            card->rambase == NULL) {
        printk(KERN_ERR "pci200syn: ioremap() failed\n");
        pci200_pci_remove_one(pdev);
        return -EFAULT;
    }

    /* Reset PLX */
    p = &card->plxbase->init_ctrl;
    writel(readl(p) | 0x40000000, p);
    readl(p);		/* Flush the write - do not use sca_flush */
    udelay(1);

    writel(readl(p) & ~0x40000000, p);
    readl(p);		/* Flush the write - do not use sca_flush */
    udelay(1);

    ramsize = sca_detect_ram(card, card->rambase,
                             pci_resource_len(pdev, 3));

    /* number of TX + RX buffers for one port - this is dual port card */
    i = ramsize / (2 * (sizeof(pkt_desc) + HDLC_MAX_MRU));
    card->tx_ring_buffers = min(i / 2, MAX_TX_BUFFERS);
    card->rx_ring_buffers = i - card->tx_ring_buffers;

    card->buff_offset = 2 * sizeof(pkt_desc) * (card->tx_ring_buffers +
                        card->rx_ring_buffers);

    printk(KERN_INFO "pci200syn: %u KB RAM at 0x%x, IRQ%u, using %u TX +"
           " %u RX packets rings\n", ramsize / 1024, ramphys,
           pdev->irq, card->tx_ring_buffers, card->rx_ring_buffers);

    if (pdev->subsystem_device == PCI_DEVICE_ID_PLX_9050) {
        printk(KERN_ERR "Detected PCI200SYN card with old "
               "configuration data.\n");
        printk(KERN_ERR "See <http://www.kernel.org/pub/"
               "linux/utils/net/hdlc/pci200syn/> for update.\n");
        printk(KERN_ERR "The card will stop working with"
               " future versions of Linux if not updated.\n");
    }

    if (card->tx_ring_buffers < 1) {
        printk(KERN_ERR "pci200syn: RAM test failed\n");
        pci200_pci_remove_one(pdev);
        return -EFAULT;
    }

    /* Enable interrupts on the PCI bridge */
    p = &card->plxbase->intr_ctrl_stat;
    writew(readw(p) | 0x0040, p);

    /* Allocate IRQ */
    if (request_irq(pdev->irq, sca_intr, IRQF_SHARED, devname, card)) {
        printk(KERN_WARNING "pci200syn: could not allocate IRQ%d.\n",
               pdev->irq);
        pci200_pci_remove_one(pdev);
        return -EBUSY;
    }
    card->irq = pdev->irq;

    sca_init(card, 0);

    for (i = 0; i < 2; i++) {
        port_t *port = &card->ports[i];
        struct net_device *dev = port_to_dev(port);
        hdlc_device *hdlc = dev_to_hdlc(dev);
        port->phy_node = i;

        spin_lock_init(&port->lock);
        dev->irq = card->irq;
        dev->mem_start = ramphys;
        dev->mem_end = ramphys + ramsize - 1;
        dev->tx_queue_len = 50;
        dev->do_ioctl = pci200_ioctl;
        dev->open = pci200_open;
        dev->stop = pci200_close;
        hdlc->attach = sca_attach;
        hdlc->xmit = sca_xmit;
        port->settings.clock_type = CLOCK_EXT;
        port->card = card;
        if (register_hdlc_device(dev)) {
            printk(KERN_ERR "pci200syn: unable to register hdlc "
                   "device\n");
            port->card = NULL;
            pci200_pci_remove_one(pdev);
            return -ENOBUFS;
        }
        sca_init_sync_port(port);	/* Set up SCA memory */

        printk(KERN_INFO "%s: PCI200SYN node %d\n",
               dev->name, port->phy_node);
    }

    sca_flush(card);
    return 0;
}
コード例 #3
0
ファイル: pc300too.c プロジェクト: andi34/Dhollmen_Kernel
static int __devinit pc300_pci_init_one(struct pci_dev *pdev,
					const struct pci_device_id *ent)
{
	card_t *card;
	u32 __iomem *p;
	int i;
	u32 ramsize;
	u32 ramphys;		/* buffer memory base */
	u32 scaphys;		/* SCA memory base */
	u32 plxphys;		/* PLX registers memory base */

	i = pci_enable_device(pdev);
	if (i)
		return i;

	i = pci_request_regions(pdev, "PC300");
	if (i) {
		pci_disable_device(pdev);
		return i;
	}

	card = kzalloc(sizeof(card_t), GFP_KERNEL);
	if (card == NULL) {
		printk(KERN_ERR "pc300: unable to allocate memory\n");
		pci_release_regions(pdev);
		pci_disable_device(pdev);
		return -ENOBUFS;
	}
	pci_set_drvdata(pdev, card);

	if (pci_resource_len(pdev, 0) != PC300_PLX_SIZE ||
	    pci_resource_len(pdev, 2) != PC300_SCA_SIZE ||
	    pci_resource_len(pdev, 3) < 16384) {
		printk(KERN_ERR "pc300: invalid card EEPROM parameters\n");
		pc300_pci_remove_one(pdev);
		return -EFAULT;
	}

	plxphys = pci_resource_start(pdev, 0) & PCI_BASE_ADDRESS_MEM_MASK;
	card->plxbase = ioremap(plxphys, PC300_PLX_SIZE);

	scaphys = pci_resource_start(pdev, 2) & PCI_BASE_ADDRESS_MEM_MASK;
	card->scabase = ioremap(scaphys, PC300_SCA_SIZE);

	ramphys = pci_resource_start(pdev, 3) & PCI_BASE_ADDRESS_MEM_MASK;
	card->rambase = pci_ioremap_bar(pdev, 3);

	if (card->plxbase == NULL ||
	    card->scabase == NULL ||
	    card->rambase == NULL) {
		printk(KERN_ERR "pc300: ioremap() failed\n");
		pc300_pci_remove_one(pdev);
	}

	/* PLX PCI 9050 workaround for local configuration register read bug */
	pci_write_config_dword(pdev, PCI_BASE_ADDRESS_0, scaphys);
	card->init_ctrl_value = readl(&((plx9050 __iomem *)card->scabase)->init_ctrl);
	pci_write_config_dword(pdev, PCI_BASE_ADDRESS_0, plxphys);

	if (pdev->device == PCI_DEVICE_ID_PC300_TE_1 ||
	    pdev->device == PCI_DEVICE_ID_PC300_TE_2)
		card->type = PC300_TE; /* not fully supported */
	else if (card->init_ctrl_value & PC300_CTYPE_MASK)
		card->type = PC300_X21;
	else
		card->type = PC300_RSV;

	if (pdev->device == PCI_DEVICE_ID_PC300_RX_1 ||
	    pdev->device == PCI_DEVICE_ID_PC300_TE_1)
		card->n_ports = 1;
	else
		card->n_ports = 2;

	for (i = 0; i < card->n_ports; i++)
		if (!(card->ports[i].netdev = alloc_hdlcdev(&card->ports[i]))) {
			printk(KERN_ERR "pc300: unable to allocate memory\n");
			pc300_pci_remove_one(pdev);
			return -ENOMEM;
		}

	/* Reset PLX */
	p = &card->plxbase->init_ctrl;
	writel(card->init_ctrl_value | 0x40000000, p);
	readl(p);		/* Flush the write - do not use sca_flush */
	udelay(1);

	writel(card->init_ctrl_value, p);
	readl(p);		/* Flush the write - do not use sca_flush */
	udelay(1);

	/* Reload Config. Registers from EEPROM */
	writel(card->init_ctrl_value | 0x20000000, p);
	readl(p);		/* Flush the write - do not use sca_flush */
	udelay(1);

	writel(card->init_ctrl_value, p);
	readl(p);		/* Flush the write - do not use sca_flush */
	udelay(1);

	ramsize = sca_detect_ram(card, card->rambase,
				 pci_resource_len(pdev, 3));

	if (use_crystal_clock)
		card->init_ctrl_value &= ~PC300_CLKSEL_MASK;
	else
		card->init_ctrl_value |= PC300_CLKSEL_MASK;

	writel(card->init_ctrl_value, &card->plxbase->init_ctrl);
	/* number of TX + RX buffers for one port */
	i = ramsize / (card->n_ports * (sizeof(pkt_desc) + HDLC_MAX_MRU));
	card->tx_ring_buffers = min(i / 2, MAX_TX_BUFFERS);
	card->rx_ring_buffers = i - card->tx_ring_buffers;

	card->buff_offset = card->n_ports * sizeof(pkt_desc) *
		(card->tx_ring_buffers + card->rx_ring_buffers);

	printk(KERN_INFO "pc300: PC300/%s, %u KB RAM at 0x%x, IRQ%u, "
	       "using %u TX + %u RX packets rings\n",
	       card->type == PC300_X21 ? "X21" :
	       card->type == PC300_TE ? "TE" : "RSV",
	       ramsize / 1024, ramphys, pdev->irq,
	       card->tx_ring_buffers, card->rx_ring_buffers);

	if (card->tx_ring_buffers < 1) {
		printk(KERN_ERR "pc300: RAM test failed\n");
		pc300_pci_remove_one(pdev);
		return -EFAULT;
	}

	/* Enable interrupts on the PCI bridge, LINTi1 active low */
	writew(0x0041, &card->plxbase->intr_ctrl_stat);

	/* Allocate IRQ */
	if (request_irq(pdev->irq, sca_intr, IRQF_SHARED, "pc300", card)) {
		printk(KERN_WARNING "pc300: could not allocate IRQ%d.\n",
		       pdev->irq);
		pc300_pci_remove_one(pdev);
		return -EBUSY;
	}
	card->irq = pdev->irq;

	sca_init(card, 0);

	// COTE not set - allows better TX DMA settings
	// sca_out(sca_in(PCR, card) | PCR_COTE, PCR, card);

	sca_out(0x10, BTCR, card);

	for (i = 0; i < card->n_ports; i++) {
		port_t *port = &card->ports[i];
		struct net_device *dev = port->netdev;
		hdlc_device *hdlc = dev_to_hdlc(dev);
		port->chan = i;

		spin_lock_init(&port->lock);
		dev->irq = card->irq;
		dev->mem_start = ramphys;
		dev->mem_end = ramphys + ramsize - 1;
		dev->tx_queue_len = 50;
		dev->netdev_ops = &pc300_ops;
		hdlc->attach = sca_attach;
		hdlc->xmit = sca_xmit;
		port->settings.clock_type = CLOCK_EXT;
		port->card = card;
		if (card->type == PC300_X21)
			port->iface = IF_IFACE_X21;
		else
			port->iface = IF_IFACE_V35;

		sca_init_port(port);
		if (register_hdlc_device(dev)) {
			printk(KERN_ERR "pc300: unable to register hdlc "
			       "device\n");
			port->card = NULL;
			pc300_pci_remove_one(pdev);
			return -ENOBUFS;
		}

		printk(KERN_INFO "%s: PC300 channel %d\n",
		       dev->name, port->chan);
	}
	return 0;
}
コード例 #4
0
ファイル: n2.c プロジェクト: mrtos/Logitech-Revue
static int __init n2_run(unsigned long io, unsigned long irq,
                         unsigned long winbase, long valid0, long valid1)
{
    card_t *card;
    u8 cnt, pcr;
    int i;

    if (io < 0x200 || io > 0x3FF || (io % N2_IOPORTS) != 0) {
        printk(KERN_ERR "n2: invalid I/O port value\n");
        return -ENODEV;
    }

    if (irq < 3 || irq > 15 || irq == 6) { /* FIXME */
        printk(KERN_ERR "n2: invalid IRQ value\n");
        return -ENODEV;
    }

    if (winbase < 0xA0000 || winbase > 0xFFFFF || (winbase & 0xFFF) != 0) {
        printk(KERN_ERR "n2: invalid RAM value\n");
        return -ENODEV;
    }

    card = kzalloc(sizeof(card_t), GFP_KERNEL);
    if (card == NULL) {
        printk(KERN_ERR "n2: unable to allocate memory\n");
        return -ENOBUFS;
    }

    card->ports[0].dev = alloc_hdlcdev(&card->ports[0]);
    card->ports[1].dev = alloc_hdlcdev(&card->ports[1]);
    if (!card->ports[0].dev || !card->ports[1].dev) {
        printk(KERN_ERR "n2: unable to allocate memory\n");
        n2_destroy_card(card);
        return -ENOMEM;
    }

    if (!request_region(io, N2_IOPORTS, devname)) {
        printk(KERN_ERR "n2: I/O port region in use\n");
        n2_destroy_card(card);
        return -EBUSY;
    }
    card->io = io;

    if (request_irq(irq, &sca_intr, 0, devname, card)) {
        printk(KERN_ERR "n2: could not allocate IRQ\n");
        n2_destroy_card(card);
        return(-EBUSY);
    }
    card->irq = irq;

    if (!request_mem_region(winbase, USE_WINDOWSIZE, devname)) {
        printk(KERN_ERR "n2: could not request RAM window\n");
        n2_destroy_card(card);
        return(-EBUSY);
    }
    card->phy_winbase = winbase;
    card->winbase = ioremap(winbase, USE_WINDOWSIZE);
    if (!card->winbase) {
        printk(KERN_ERR "n2: ioremap() failed\n");
        n2_destroy_card(card);
        return -EFAULT;
    }

    outb(0, io + N2_PCR);
    outb(winbase >> 12, io + N2_BAR);

    switch (USE_WINDOWSIZE) {
    case 16384:
        outb(WIN16K, io + N2_PSR);
        break;

    case 32768:
        outb(WIN32K, io + N2_PSR);
        break;

    case 65536:
        outb(WIN64K, io + N2_PSR);
        break;

    default:
        printk(KERN_ERR "n2: invalid window size\n");
        n2_destroy_card(card);
        return -ENODEV;
    }

    pcr = PCR_ENWIN | PCR_VPM | (USE_BUS16BITS ? PCR_BUS16 : 0);
    outb(pcr, io + N2_PCR);

    card->ram_size = sca_detect_ram(card, card->winbase, MAX_RAM_SIZE);

    /* number of TX + RX buffers for one port */
    i = card->ram_size / ((valid0 + valid1) * (sizeof(pkt_desc) +
                          HDLC_MAX_MRU));

    card->tx_ring_buffers = min(i / 2, MAX_TX_BUFFERS);
    card->rx_ring_buffers = i - card->tx_ring_buffers;

    card->buff_offset = (valid0 + valid1) * sizeof(pkt_desc) *
                        (card->tx_ring_buffers + card->rx_ring_buffers);

    printk(KERN_INFO "n2: RISCom/N2 %u KB RAM, IRQ%u, "
           "using %u TX + %u RX packets rings\n", card->ram_size / 1024,
           card->irq, card->tx_ring_buffers, card->rx_ring_buffers);

    if (card->tx_ring_buffers < 1) {
        printk(KERN_ERR "n2: RAM test failed\n");
        n2_destroy_card(card);
        return -EIO;
    }

    pcr |= PCR_RUNSCA;		/* run SCA */
    outb(pcr, io + N2_PCR);
    outb(0, io + N2_MCR);

    sca_init(card, 0);
    for (cnt = 0; cnt < 2; cnt++) {
        port_t *port = &card->ports[cnt];
        struct net_device *dev = port_to_dev(port);
        hdlc_device *hdlc = dev_to_hdlc(dev);

        if ((cnt == 0 && !valid0) || (cnt == 1 && !valid1))
            continue;

        port->phy_node = cnt;
        port->valid = 1;

        if ((cnt == 1) && valid0)
            port->log_node = 1;

        spin_lock_init(&port->lock);
        SET_MODULE_OWNER(dev);
        dev->irq = irq;
        dev->mem_start = winbase;
        dev->mem_end = winbase + USE_WINDOWSIZE - 1;
        dev->tx_queue_len = 50;
        dev->do_ioctl = n2_ioctl;
        dev->open = n2_open;
        dev->stop = n2_close;
        hdlc->attach = sca_attach;
        hdlc->xmit = sca_xmit;
        port->settings.clock_type = CLOCK_EXT;
        port->card = card;

        if (register_hdlc_device(dev)) {
            printk(KERN_WARNING "n2: unable to register hdlc "
                   "device\n");
            port->card = NULL;
            n2_destroy_card(card);
            return -ENOBUFS;
        }
        sca_init_sync_port(port); /* Set up SCA memory */

        printk(KERN_INFO "%s: RISCom/N2 node %d\n",
               dev->name, port->phy_node);
    }

    *new_card = card;
    new_card = &card->next_card;

    return 0;
}