diff options
author | Francois Romieu <romieu@fr.zoreil.com> | 2006-07-26 16:05:06 -0400 |
---|---|---|
committer | Francois Romieu <romieu@electric-eye.fr.zoreil.com> | 2006-07-26 17:23:14 -0400 |
commit | 4ff96fa67379c31ced69f193c7ffba17051f38e8 (patch) | |
tree | d552a84e48803533ea155e8b88f56c9b33865793 /drivers/net/r8169.c | |
parent | 623a1593c84afb86b2f496a56fb4ec37f82b5c78 (diff) |
r8169: remove rtl8169_init_board
Rationale:
- its signature is not exactly pretty;
- it has no knowledge of pci_device_id;
- kiss 23 lines good bye.
Signed-off-by: Francois Romieu <romieu@fr.zoreil.com>
Diffstat (limited to 'drivers/net/r8169.c')
-rw-r--r-- | drivers/net/r8169.c | 191 |
1 files changed, 86 insertions, 105 deletions
diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c index 3424b3c1083c..ca0f303a6b5d 100644 --- a/drivers/net/r8169.c +++ b/drivers/net/r8169.c | |||
@@ -1434,23 +1434,60 @@ static void rtl8169_release_board(struct pci_dev *pdev, struct net_device *dev, | |||
1434 | free_netdev(dev); | 1434 | free_netdev(dev); |
1435 | } | 1435 | } |
1436 | 1436 | ||
1437 | static void rtl8169_init_phy(struct net_device *dev, struct rtl8169_private *tp) | ||
1438 | { | ||
1439 | void __iomem *ioaddr = tp->mmio_addr; | ||
1440 | static int board_idx = -1; | ||
1441 | u8 autoneg, duplex; | ||
1442 | u16 speed; | ||
1443 | |||
1444 | board_idx++; | ||
1445 | |||
1446 | rtl8169_hw_phy_config(dev); | ||
1447 | |||
1448 | dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n"); | ||
1449 | RTL_W8(0x82, 0x01); | ||
1450 | |||
1451 | if (tp->mac_version < RTL_GIGA_MAC_VER_E) { | ||
1452 | dprintk("Set PCI Latency=0x40\n"); | ||
1453 | pci_write_config_byte(tp->pci_dev, PCI_LATENCY_TIMER, 0x40); | ||
1454 | } | ||
1455 | |||
1456 | if (tp->mac_version == RTL_GIGA_MAC_VER_D) { | ||
1457 | dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n"); | ||
1458 | RTL_W8(0x82, 0x01); | ||
1459 | dprintk("Set PHY Reg 0x0bh = 0x00h\n"); | ||
1460 | mdio_write(ioaddr, 0x0b, 0x0000); //w 0x0b 15 0 0 | ||
1461 | } | ||
1462 | |||
1463 | rtl8169_link_option(board_idx, &autoneg, &speed, &duplex); | ||
1464 | |||
1465 | rtl8169_set_speed(dev, autoneg, speed, duplex); | ||
1466 | |||
1467 | if ((RTL_R8(PHYstatus) & TBI_Enable) && netif_msg_link(tp)) | ||
1468 | printk(KERN_INFO PFX "%s: TBI auto-negotiating\n", dev->name); | ||
1469 | } | ||
1470 | |||
1437 | static int __devinit | 1471 | static int __devinit |
1438 | rtl8169_init_board(struct pci_dev *pdev, struct net_device **dev_out, | 1472 | rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) |
1439 | void __iomem **ioaddr_out) | ||
1440 | { | 1473 | { |
1441 | void __iomem *ioaddr; | ||
1442 | struct net_device *dev; | ||
1443 | struct rtl8169_private *tp; | 1474 | struct rtl8169_private *tp; |
1444 | int rc = -ENOMEM, i, acpi_idle_state = 0, pm_cap; | 1475 | struct net_device *dev; |
1476 | void __iomem *ioaddr; | ||
1477 | unsigned int i, pm_cap; | ||
1478 | int rc; | ||
1445 | 1479 | ||
1446 | assert(ioaddr_out != NULL); | 1480 | if (netif_msg_drv(&debug)) { |
1481 | printk(KERN_INFO "%s Gigabit Ethernet driver %s loaded\n", | ||
1482 | MODULENAME, RTL8169_VERSION); | ||
1483 | } | ||
1447 | 1484 | ||
1448 | /* dev zeroed in alloc_etherdev */ | ||
1449 | dev = alloc_etherdev(sizeof (*tp)); | 1485 | dev = alloc_etherdev(sizeof (*tp)); |
1450 | if (dev == NULL) { | 1486 | if (!dev) { |
1451 | if (netif_msg_drv(&debug)) | 1487 | if (netif_msg_drv(&debug)) |
1452 | dev_err(&pdev->dev, "unable to alloc new ethernet\n"); | 1488 | dev_err(&pdev->dev, "unable to alloc new ethernet\n"); |
1453 | goto err_out; | 1489 | rc = -ENOMEM; |
1490 | goto out; | ||
1454 | } | 1491 | } |
1455 | 1492 | ||
1456 | SET_MODULE_OWNER(dev); | 1493 | SET_MODULE_OWNER(dev); |
@@ -1463,48 +1500,52 @@ rtl8169_init_board(struct pci_dev *pdev, struct net_device **dev_out, | |||
1463 | if (rc < 0) { | 1500 | if (rc < 0) { |
1464 | if (netif_msg_probe(tp)) | 1501 | if (netif_msg_probe(tp)) |
1465 | dev_err(&pdev->dev, "enable failure\n"); | 1502 | dev_err(&pdev->dev, "enable failure\n"); |
1466 | goto err_out_free_dev; | 1503 | goto err_out_free_dev_1; |
1467 | } | 1504 | } |
1468 | 1505 | ||
1469 | rc = pci_set_mwi(pdev); | 1506 | rc = pci_set_mwi(pdev); |
1470 | if (rc < 0) | 1507 | if (rc < 0) |
1471 | goto err_out_disable; | 1508 | goto err_out_disable_2; |
1472 | 1509 | ||
1473 | /* save power state before pci_enable_device overwrites it */ | 1510 | /* save power state before pci_enable_device overwrites it */ |
1474 | pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM); | 1511 | pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM); |
1475 | if (pm_cap) { | 1512 | if (pm_cap) { |
1476 | u16 pwr_command; | 1513 | u16 pwr_command, acpi_idle_state; |
1477 | 1514 | ||
1478 | pci_read_config_word(pdev, pm_cap + PCI_PM_CTRL, &pwr_command); | 1515 | pci_read_config_word(pdev, pm_cap + PCI_PM_CTRL, &pwr_command); |
1479 | acpi_idle_state = pwr_command & PCI_PM_CTRL_STATE_MASK; | 1516 | acpi_idle_state = pwr_command & PCI_PM_CTRL_STATE_MASK; |
1480 | } else { | 1517 | } else { |
1481 | if (netif_msg_probe(tp)) | 1518 | if (netif_msg_probe(tp)) { |
1482 | dev_err(&pdev->dev, | 1519 | dev_err(&pdev->dev, |
1483 | "PowerManagement capability not found.\n"); | 1520 | "PowerManagement capability not found.\n"); |
1521 | } | ||
1484 | } | 1522 | } |
1485 | 1523 | ||
1486 | /* make sure PCI base addr 1 is MMIO */ | 1524 | /* make sure PCI base addr 1 is MMIO */ |
1487 | if (!(pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) { | 1525 | if (!(pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) { |
1488 | if (netif_msg_probe(tp)) | 1526 | if (netif_msg_probe(tp)) { |
1489 | dev_err(&pdev->dev, | 1527 | dev_err(&pdev->dev, |
1490 | "region #1 not an MMIO resource, aborting\n"); | 1528 | "region #1 not an MMIO resource, aborting\n"); |
1529 | } | ||
1491 | rc = -ENODEV; | 1530 | rc = -ENODEV; |
1492 | goto err_out_mwi; | 1531 | goto err_out_mwi_3; |
1493 | } | 1532 | } |
1533 | |||
1494 | /* check for weird/broken PCI region reporting */ | 1534 | /* check for weird/broken PCI region reporting */ |
1495 | if (pci_resource_len(pdev, 1) < R8169_REGS_SIZE) { | 1535 | if (pci_resource_len(pdev, 1) < R8169_REGS_SIZE) { |
1496 | if (netif_msg_probe(tp)) | 1536 | if (netif_msg_probe(tp)) { |
1497 | dev_err(&pdev->dev, | 1537 | dev_err(&pdev->dev, |
1498 | "Invalid PCI region size(s), aborting\n"); | 1538 | "Invalid PCI region size(s), aborting\n"); |
1539 | } | ||
1499 | rc = -ENODEV; | 1540 | rc = -ENODEV; |
1500 | goto err_out_mwi; | 1541 | goto err_out_mwi_3; |
1501 | } | 1542 | } |
1502 | 1543 | ||
1503 | rc = pci_request_regions(pdev, MODULENAME); | 1544 | rc = pci_request_regions(pdev, MODULENAME); |
1504 | if (rc < 0) { | 1545 | if (rc < 0) { |
1505 | if (netif_msg_probe(tp)) | 1546 | if (netif_msg_probe(tp)) |
1506 | dev_err(&pdev->dev, "could not request regions.\n"); | 1547 | dev_err(&pdev->dev, "could not request regions.\n"); |
1507 | goto err_out_mwi; | 1548 | goto err_out_mwi_3; |
1508 | } | 1549 | } |
1509 | 1550 | ||
1510 | tp->cp_cmd = PCIMulRW | RxChkSum; | 1551 | tp->cp_cmd = PCIMulRW | RxChkSum; |
@@ -1516,10 +1557,11 @@ rtl8169_init_board(struct pci_dev *pdev, struct net_device **dev_out, | |||
1516 | } else { | 1557 | } else { |
1517 | rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK); | 1558 | rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK); |
1518 | if (rc < 0) { | 1559 | if (rc < 0) { |
1519 | if (netif_msg_probe(tp)) | 1560 | if (netif_msg_probe(tp)) { |
1520 | dev_err(&pdev->dev, | 1561 | dev_err(&pdev->dev, |
1521 | "DMA configuration failed.\n"); | 1562 | "DMA configuration failed.\n"); |
1522 | goto err_out_free_res; | 1563 | } |
1564 | goto err_out_free_res_4; | ||
1523 | } | 1565 | } |
1524 | } | 1566 | } |
1525 | 1567 | ||
@@ -1527,11 +1569,11 @@ rtl8169_init_board(struct pci_dev *pdev, struct net_device **dev_out, | |||
1527 | 1569 | ||
1528 | /* ioremap MMIO region */ | 1570 | /* ioremap MMIO region */ |
1529 | ioaddr = ioremap(pci_resource_start(pdev, 1), R8169_REGS_SIZE); | 1571 | ioaddr = ioremap(pci_resource_start(pdev, 1), R8169_REGS_SIZE); |
1530 | if (ioaddr == NULL) { | 1572 | if (!ioaddr) { |
1531 | if (netif_msg_probe(tp)) | 1573 | if (netif_msg_probe(tp)) |
1532 | dev_err(&pdev->dev, "cannot remap MMIO, aborting\n"); | 1574 | dev_err(&pdev->dev, "cannot remap MMIO, aborting\n"); |
1533 | rc = -EIO; | 1575 | rc = -EIO; |
1534 | goto err_out_free_res; | 1576 | goto err_out_free_res_4; |
1535 | } | 1577 | } |
1536 | 1578 | ||
1537 | /* Unneeded ? Don't mess with Mrs. Murphy. */ | 1579 | /* Unneeded ? Don't mess with Mrs. Murphy. */ |
@@ -1562,8 +1604,8 @@ rtl8169_init_board(struct pci_dev *pdev, struct net_device **dev_out, | |||
1562 | /* Unknown chip: assume array element #0, original RTL-8169 */ | 1604 | /* Unknown chip: assume array element #0, original RTL-8169 */ |
1563 | if (netif_msg_probe(tp)) { | 1605 | if (netif_msg_probe(tp)) { |
1564 | dev_printk(KERN_DEBUG, &pdev->dev, | 1606 | dev_printk(KERN_DEBUG, &pdev->dev, |
1565 | "unknown chip version, assuming %s\n", | 1607 | "unknown chip version, assuming %s\n", |
1566 | rtl_chip_info[0].name); | 1608 | rtl_chip_info[0].name); |
1567 | } | 1609 | } |
1568 | i++; | 1610 | i++; |
1569 | } | 1611 | } |
@@ -1574,56 +1616,6 @@ rtl8169_init_board(struct pci_dev *pdev, struct net_device **dev_out, | |||
1574 | RTL_W8(Config5, RTL_R8(Config5) & PMEStatus); | 1616 | RTL_W8(Config5, RTL_R8(Config5) & PMEStatus); |
1575 | RTL_W8(Cfg9346, Cfg9346_Lock); | 1617 | RTL_W8(Cfg9346, Cfg9346_Lock); |
1576 | 1618 | ||
1577 | *ioaddr_out = ioaddr; | ||
1578 | *dev_out = dev; | ||
1579 | out: | ||
1580 | return rc; | ||
1581 | |||
1582 | err_out_free_res: | ||
1583 | pci_release_regions(pdev); | ||
1584 | |||
1585 | err_out_mwi: | ||
1586 | pci_clear_mwi(pdev); | ||
1587 | |||
1588 | err_out_disable: | ||
1589 | pci_disable_device(pdev); | ||
1590 | |||
1591 | err_out_free_dev: | ||
1592 | free_netdev(dev); | ||
1593 | err_out: | ||
1594 | *ioaddr_out = NULL; | ||
1595 | *dev_out = NULL; | ||
1596 | goto out; | ||
1597 | } | ||
1598 | |||
1599 | static int __devinit | ||
1600 | rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) | ||
1601 | { | ||
1602 | struct net_device *dev = NULL; | ||
1603 | struct rtl8169_private *tp; | ||
1604 | void __iomem *ioaddr = NULL; | ||
1605 | static int board_idx = -1; | ||
1606 | u8 autoneg, duplex; | ||
1607 | u16 speed; | ||
1608 | int i, rc; | ||
1609 | |||
1610 | assert(pdev != NULL); | ||
1611 | assert(ent != NULL); | ||
1612 | |||
1613 | board_idx++; | ||
1614 | |||
1615 | if (netif_msg_drv(&debug)) { | ||
1616 | printk(KERN_INFO "%s Gigabit Ethernet driver %s loaded\n", | ||
1617 | MODULENAME, RTL8169_VERSION); | ||
1618 | } | ||
1619 | |||
1620 | rc = rtl8169_init_board(pdev, &dev, &ioaddr); | ||
1621 | if (rc) | ||
1622 | return rc; | ||
1623 | |||
1624 | tp = netdev_priv(dev); | ||
1625 | assert(ioaddr != NULL); | ||
1626 | |||
1627 | if (RTL_R8(PHYstatus) & TBI_Enable) { | 1619 | if (RTL_R8(PHYstatus) & TBI_Enable) { |
1628 | tp->set_speed = rtl8169_set_speed_tbi; | 1620 | tp->set_speed = rtl8169_set_speed_tbi; |
1629 | tp->get_settings = rtl8169_gset_tbi; | 1621 | tp->get_settings = rtl8169_gset_tbi; |
@@ -1680,10 +1672,8 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) | |||
1680 | spin_lock_init(&tp->lock); | 1672 | spin_lock_init(&tp->lock); |
1681 | 1673 | ||
1682 | rc = register_netdev(dev); | 1674 | rc = register_netdev(dev); |
1683 | if (rc) { | 1675 | if (rc < 0) |
1684 | rtl8169_release_board(pdev, dev, ioaddr); | 1676 | goto err_out_unmap_5; |
1685 | return rc; | ||
1686 | } | ||
1687 | 1677 | ||
1688 | if (netif_msg_probe(tp)) { | 1678 | if (netif_msg_probe(tp)) { |
1689 | printk(KERN_DEBUG "%s: Identified chip type is '%s'.\n", | 1679 | printk(KERN_DEBUG "%s: Identified chip type is '%s'.\n", |
@@ -1704,31 +1694,22 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) | |||
1704 | dev->dev_addr[4], dev->dev_addr[5], dev->irq); | 1694 | dev->dev_addr[4], dev->dev_addr[5], dev->irq); |
1705 | } | 1695 | } |
1706 | 1696 | ||
1707 | rtl8169_hw_phy_config(dev); | 1697 | rtl8169_init_phy(dev, tp); |
1708 | |||
1709 | dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n"); | ||
1710 | RTL_W8(0x82, 0x01); | ||
1711 | |||
1712 | if (tp->mac_version < RTL_GIGA_MAC_VER_E) { | ||
1713 | dprintk("Set PCI Latency=0x40\n"); | ||
1714 | pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x40); | ||
1715 | } | ||
1716 | |||
1717 | if (tp->mac_version == RTL_GIGA_MAC_VER_D) { | ||
1718 | dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n"); | ||
1719 | RTL_W8(0x82, 0x01); | ||
1720 | dprintk("Set PHY Reg 0x0bh = 0x00h\n"); | ||
1721 | mdio_write(ioaddr, 0x0b, 0x0000); //w 0x0b 15 0 0 | ||
1722 | } | ||
1723 | 1698 | ||
1724 | rtl8169_link_option(board_idx, &autoneg, &speed, &duplex); | 1699 | out: |
1725 | 1700 | return rc; | |
1726 | rtl8169_set_speed(dev, autoneg, speed, duplex); | ||
1727 | |||
1728 | if ((RTL_R8(PHYstatus) & TBI_Enable) && netif_msg_link(tp)) | ||
1729 | printk(KERN_INFO PFX "%s: TBI auto-negotiating\n", dev->name); | ||
1730 | 1701 | ||
1731 | return 0; | 1702 | err_out_unmap_5: |
1703 | iounmap(ioaddr); | ||
1704 | err_out_free_res_4: | ||
1705 | pci_release_regions(pdev); | ||
1706 | err_out_mwi_3: | ||
1707 | pci_clear_mwi(pdev); | ||
1708 | err_out_disable_2: | ||
1709 | pci_disable_device(pdev); | ||
1710 | err_out_free_dev_1: | ||
1711 | free_netdev(dev); | ||
1712 | goto out; | ||
1732 | } | 1713 | } |
1733 | 1714 | ||
1734 | static void __devexit | 1715 | static void __devexit |