From a2b98a697fa4e7564f78905b83db122824916cf9 Mon Sep 17 00:00:00 2001 From: Francois Romieu Date: Sun, 14 May 2006 12:18:44 +0200 Subject: r8169: mac address change support Fix for http://bugzilla.kernel.org/show_bug.cgi?id=6032. Cc: Tim Mattox Signed-off-by: Francois Romieu --- drivers/net/r8169.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'drivers/net') diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c index 4c2f575faad7..e8786c4fcac2 100644 --- a/drivers/net/r8169.c +++ b/drivers/net/r8169.c @@ -1382,6 +1382,41 @@ static void rtl8169_netpoll(struct net_device *dev) } #endif +static void __rtl8169_set_mac_addr(struct net_device *dev, void __iomem *ioaddr) +{ + unsigned int i, j; + + RTL_W8(Cfg9346, Cfg9346_Unlock); + for (i = 0; i < 2; i++) { + __le32 l = 0; + + for (j = 0; j < 4; j++) { + l <<= 8; + l |= dev->dev_addr[4*i + j]; + } + RTL_W32(MAC0 + 4*i, cpu_to_be32(l)); + } + RTL_W8(Cfg9346, Cfg9346_Lock); +} + +static int rtl8169_set_mac_addr(struct net_device *dev, void *p) +{ + struct rtl8169_private *tp = netdev_priv(dev); + struct sockaddr *addr = p; + + if (!is_valid_ether_addr(addr->sa_data)) + return -EINVAL; + + memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); + + if (netif_running(dev)) { + spin_lock_irq(&tp->lock); + __rtl8169_set_mac_addr(dev, tp->mmio_addr); + spin_unlock_irq(&tp->lock); + } + return 0; +} + static void rtl8169_release_board(struct pci_dev *pdev, struct net_device *dev, void __iomem *ioaddr) { @@ -1609,6 +1644,7 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) dev->stop = rtl8169_close; dev->tx_timeout = rtl8169_tx_timeout; dev->set_multicast_list = rtl8169_set_rx_mode; + dev->set_mac_address = rtl8169_set_mac_addr; dev->watchdog_timeo = RTL8169_TX_TIMEOUT; dev->irq = pdev->irq; dev->base_addr = (unsigned long) ioaddr; @@ -1842,6 +1878,8 @@ rtl8169_hw_start(struct net_device *dev) /* Enable all known interrupts by setting the interrupt mask. */ RTL_W16(IntrMask, rtl8169_intr_mask); + __rtl8169_set_mac_addr(dev, ioaddr); + netif_start_queue(dev); } -- cgit v1.2.3 From 9dccf61112e6755f4e6f154c1794bab3c509bc71 Mon Sep 17 00:00:00 2001 From: Francois Romieu Date: Sun, 14 May 2006 12:31:17 +0200 Subject: r8169: RX fifo overflow recovery Signed-off-by: Francois Romieu --- drivers/net/r8169.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'drivers/net') diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c index e8786c4fcac2..ea4f9f7bd071 100644 --- a/drivers/net/r8169.c +++ b/drivers/net/r8169.c @@ -257,10 +257,11 @@ enum RTL8169_register_content { RxOK = 0x01, /* RxStatusDesc */ - RxRES = 0x00200000, - RxCRC = 0x00080000, - RxRUNT = 0x00100000, - RxRWT = 0x00400000, + RxFOVF = (1 << 23), + RxRWT = (1 << 22), + RxRES = (1 << 21), + RxRUNT = (1 << 20), + RxCRC = (1 << 19), /* ChipCmdBits */ CmdReset = 0x10, @@ -2465,6 +2466,10 @@ rtl8169_rx_interrupt(struct net_device *dev, struct rtl8169_private *tp, tp->stats.rx_length_errors++; if (status & RxCRC) tp->stats.rx_crc_errors++; + if (status & RxFOVF) { + rtl8169_schedule_work(dev, rtl8169_reset_task); + tp->stats.rx_fifo_errors++; + } rtl8169_mark_to_asic(desc, tp->rx_buf_sz); } else { struct sk_buff *skb = tp->Rx_skbuff[entry]; -- cgit v1.2.3 From 623a1593c84afb86b2f496a56fb4ec37f82b5c78 Mon Sep 17 00:00:00 2001 From: Francois Romieu Date: Sun, 14 May 2006 12:42:14 +0200 Subject: r8169: hardware flow control The datasheet suggests that the device handles the hardware flow control almost automagically. User report a different story, so let's try to twiddle the mii registers. Signed-off-by: Francois Romieu --- drivers/net/r8169.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'drivers/net') diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c index ea4f9f7bd071..3424b3c1083c 100644 --- a/drivers/net/r8169.c +++ b/drivers/net/r8169.c @@ -771,6 +771,8 @@ static int rtl8169_set_speed_xmii(struct net_device *dev, auto_nego &= ~(PHY_Cap_10_Half | PHY_Cap_100_Half); } + auto_nego |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM; + tp->phy_auto_nego_reg = auto_nego; tp->phy_1000_ctrl_reg = giga_ctrl; @@ -962,6 +964,11 @@ static void rtl8169_gset_xmii(struct net_device *dev, struct ethtool_cmd *cmd) else if (status & _10bps) cmd->speed = SPEED_10; + if (status & TxFlowCtrl) + cmd->advertising |= ADVERTISED_Asym_Pause; + if (status & RxFlowCtrl) + cmd->advertising |= ADVERTISED_Pause; + cmd->duplex = ((status & _1000bpsF) || (status & FullDup)) ? DUPLEX_FULL : DUPLEX_HALF; } -- cgit v1.2.3 From 4ff96fa67379c31ced69f193c7ffba17051f38e8 Mon Sep 17 00:00:00 2001 From: Francois Romieu Date: Wed, 26 Jul 2006 22:05:06 +0200 Subject: 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 --- drivers/net/r8169.c | 191 +++++++++++++++++++++++----------------------------- 1 file changed, 86 insertions(+), 105 deletions(-) (limited to 'drivers/net') 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, free_netdev(dev); } +static void rtl8169_init_phy(struct net_device *dev, struct rtl8169_private *tp) +{ + void __iomem *ioaddr = tp->mmio_addr; + static int board_idx = -1; + u8 autoneg, duplex; + u16 speed; + + board_idx++; + + rtl8169_hw_phy_config(dev); + + dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n"); + RTL_W8(0x82, 0x01); + + if (tp->mac_version < RTL_GIGA_MAC_VER_E) { + dprintk("Set PCI Latency=0x40\n"); + pci_write_config_byte(tp->pci_dev, PCI_LATENCY_TIMER, 0x40); + } + + if (tp->mac_version == RTL_GIGA_MAC_VER_D) { + dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n"); + RTL_W8(0x82, 0x01); + dprintk("Set PHY Reg 0x0bh = 0x00h\n"); + mdio_write(ioaddr, 0x0b, 0x0000); //w 0x0b 15 0 0 + } + + rtl8169_link_option(board_idx, &autoneg, &speed, &duplex); + + rtl8169_set_speed(dev, autoneg, speed, duplex); + + if ((RTL_R8(PHYstatus) & TBI_Enable) && netif_msg_link(tp)) + printk(KERN_INFO PFX "%s: TBI auto-negotiating\n", dev->name); +} + static int __devinit -rtl8169_init_board(struct pci_dev *pdev, struct net_device **dev_out, - void __iomem **ioaddr_out) +rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) { - void __iomem *ioaddr; - struct net_device *dev; struct rtl8169_private *tp; - int rc = -ENOMEM, i, acpi_idle_state = 0, pm_cap; + struct net_device *dev; + void __iomem *ioaddr; + unsigned int i, pm_cap; + int rc; - assert(ioaddr_out != NULL); + if (netif_msg_drv(&debug)) { + printk(KERN_INFO "%s Gigabit Ethernet driver %s loaded\n", + MODULENAME, RTL8169_VERSION); + } - /* dev zeroed in alloc_etherdev */ dev = alloc_etherdev(sizeof (*tp)); - if (dev == NULL) { + if (!dev) { if (netif_msg_drv(&debug)) dev_err(&pdev->dev, "unable to alloc new ethernet\n"); - goto err_out; + rc = -ENOMEM; + goto out; } SET_MODULE_OWNER(dev); @@ -1463,48 +1500,52 @@ rtl8169_init_board(struct pci_dev *pdev, struct net_device **dev_out, if (rc < 0) { if (netif_msg_probe(tp)) dev_err(&pdev->dev, "enable failure\n"); - goto err_out_free_dev; + goto err_out_free_dev_1; } rc = pci_set_mwi(pdev); if (rc < 0) - goto err_out_disable; + goto err_out_disable_2; /* save power state before pci_enable_device overwrites it */ pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM); if (pm_cap) { - u16 pwr_command; + u16 pwr_command, acpi_idle_state; pci_read_config_word(pdev, pm_cap + PCI_PM_CTRL, &pwr_command); acpi_idle_state = pwr_command & PCI_PM_CTRL_STATE_MASK; } else { - if (netif_msg_probe(tp)) + if (netif_msg_probe(tp)) { dev_err(&pdev->dev, - "PowerManagement capability not found.\n"); + "PowerManagement capability not found.\n"); + } } /* make sure PCI base addr 1 is MMIO */ if (!(pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) { - if (netif_msg_probe(tp)) + if (netif_msg_probe(tp)) { dev_err(&pdev->dev, - "region #1 not an MMIO resource, aborting\n"); + "region #1 not an MMIO resource, aborting\n"); + } rc = -ENODEV; - goto err_out_mwi; + goto err_out_mwi_3; } + /* check for weird/broken PCI region reporting */ if (pci_resource_len(pdev, 1) < R8169_REGS_SIZE) { - if (netif_msg_probe(tp)) + if (netif_msg_probe(tp)) { dev_err(&pdev->dev, - "Invalid PCI region size(s), aborting\n"); + "Invalid PCI region size(s), aborting\n"); + } rc = -ENODEV; - goto err_out_mwi; + goto err_out_mwi_3; } rc = pci_request_regions(pdev, MODULENAME); if (rc < 0) { if (netif_msg_probe(tp)) dev_err(&pdev->dev, "could not request regions.\n"); - goto err_out_mwi; + goto err_out_mwi_3; } tp->cp_cmd = PCIMulRW | RxChkSum; @@ -1516,10 +1557,11 @@ rtl8169_init_board(struct pci_dev *pdev, struct net_device **dev_out, } else { rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK); if (rc < 0) { - if (netif_msg_probe(tp)) + if (netif_msg_probe(tp)) { dev_err(&pdev->dev, - "DMA configuration failed.\n"); - goto err_out_free_res; + "DMA configuration failed.\n"); + } + goto err_out_free_res_4; } } @@ -1527,11 +1569,11 @@ rtl8169_init_board(struct pci_dev *pdev, struct net_device **dev_out, /* ioremap MMIO region */ ioaddr = ioremap(pci_resource_start(pdev, 1), R8169_REGS_SIZE); - if (ioaddr == NULL) { + if (!ioaddr) { if (netif_msg_probe(tp)) dev_err(&pdev->dev, "cannot remap MMIO, aborting\n"); rc = -EIO; - goto err_out_free_res; + goto err_out_free_res_4; } /* Unneeded ? Don't mess with Mrs. Murphy. */ @@ -1562,8 +1604,8 @@ rtl8169_init_board(struct pci_dev *pdev, struct net_device **dev_out, /* Unknown chip: assume array element #0, original RTL-8169 */ if (netif_msg_probe(tp)) { dev_printk(KERN_DEBUG, &pdev->dev, - "unknown chip version, assuming %s\n", - rtl_chip_info[0].name); + "unknown chip version, assuming %s\n", + rtl_chip_info[0].name); } i++; } @@ -1574,56 +1616,6 @@ rtl8169_init_board(struct pci_dev *pdev, struct net_device **dev_out, RTL_W8(Config5, RTL_R8(Config5) & PMEStatus); RTL_W8(Cfg9346, Cfg9346_Lock); - *ioaddr_out = ioaddr; - *dev_out = dev; -out: - return rc; - -err_out_free_res: - pci_release_regions(pdev); - -err_out_mwi: - pci_clear_mwi(pdev); - -err_out_disable: - pci_disable_device(pdev); - -err_out_free_dev: - free_netdev(dev); -err_out: - *ioaddr_out = NULL; - *dev_out = NULL; - goto out; -} - -static int __devinit -rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) -{ - struct net_device *dev = NULL; - struct rtl8169_private *tp; - void __iomem *ioaddr = NULL; - static int board_idx = -1; - u8 autoneg, duplex; - u16 speed; - int i, rc; - - assert(pdev != NULL); - assert(ent != NULL); - - board_idx++; - - if (netif_msg_drv(&debug)) { - printk(KERN_INFO "%s Gigabit Ethernet driver %s loaded\n", - MODULENAME, RTL8169_VERSION); - } - - rc = rtl8169_init_board(pdev, &dev, &ioaddr); - if (rc) - return rc; - - tp = netdev_priv(dev); - assert(ioaddr != NULL); - if (RTL_R8(PHYstatus) & TBI_Enable) { tp->set_speed = rtl8169_set_speed_tbi; tp->get_settings = rtl8169_gset_tbi; @@ -1680,10 +1672,8 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) spin_lock_init(&tp->lock); rc = register_netdev(dev); - if (rc) { - rtl8169_release_board(pdev, dev, ioaddr); - return rc; - } + if (rc < 0) + goto err_out_unmap_5; if (netif_msg_probe(tp)) { 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) dev->dev_addr[4], dev->dev_addr[5], dev->irq); } - rtl8169_hw_phy_config(dev); - - dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n"); - RTL_W8(0x82, 0x01); - - if (tp->mac_version < RTL_GIGA_MAC_VER_E) { - dprintk("Set PCI Latency=0x40\n"); - pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x40); - } - - if (tp->mac_version == RTL_GIGA_MAC_VER_D) { - dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n"); - RTL_W8(0x82, 0x01); - dprintk("Set PHY Reg 0x0bh = 0x00h\n"); - mdio_write(ioaddr, 0x0b, 0x0000); //w 0x0b 15 0 0 - } + rtl8169_init_phy(dev, tp); - rtl8169_link_option(board_idx, &autoneg, &speed, &duplex); - - rtl8169_set_speed(dev, autoneg, speed, duplex); - - if ((RTL_R8(PHYstatus) & TBI_Enable) && netif_msg_link(tp)) - printk(KERN_INFO PFX "%s: TBI auto-negotiating\n", dev->name); +out: + return rc; - return 0; +err_out_unmap_5: + iounmap(ioaddr); +err_out_free_res_4: + pci_release_regions(pdev); +err_out_mwi_3: + pci_clear_mwi(pdev); +err_out_disable_2: + pci_disable_device(pdev); +err_out_free_dev_1: + free_netdev(dev); + goto out; } static void __devexit -- cgit v1.2.3 From bcf0bf90cd9e9242b66e0563b6a8c8db2e4c262c Mon Sep 17 00:00:00 2001 From: Francois Romieu Date: Wed, 26 Jul 2006 23:14:13 +0200 Subject: r8169: sync with vendor's driver - add several PCI ID for the PCI-E adapters ; - new identification strings ; - the RTL_GIGA_MAC_VER_ defines have been renamed to closely match the out-of-tree driver. It makes the comparison less hairy ; - various magic ; - the PCI region for the device with PCI ID 0x8136 is guessed. Explanation: the in-kernel Linux driver is written to allow MM register accesses and avoid the IO tax. The relevant BAR register was found at base address 1 for the plain-old PCI 8169. User reported lspci show that it is found at base address 2 for the new Gigabit PCI-E 816{8/9}. Typically: 01:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd.: Unknown device 8168 (rev 01) Subsystem: Unknown device 1631:e015 Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- Status: Cap+ 66Mhz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- SERR- --- drivers/net/r8169.c | 218 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 144 insertions(+), 74 deletions(-) (limited to 'drivers/net') diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c index ca0f303a6b5d..d0bfe4c8950d 100644 --- a/drivers/net/r8169.c +++ b/drivers/net/r8169.c @@ -150,11 +150,16 @@ static const int multicast_filter_limit = 32; #define RTL_R32(reg) ((unsigned long) readl (ioaddr + (reg))) enum mac_version { - RTL_GIGA_MAC_VER_B = 0x00, - /* RTL_GIGA_MAC_VER_C = 0x03, */ - RTL_GIGA_MAC_VER_D = 0x01, - RTL_GIGA_MAC_VER_E = 0x02, - RTL_GIGA_MAC_VER_X = 0x04 /* Greater than RTL_GIGA_MAC_VER_E */ + RTL_GIGA_MAC_VER_01 = 0x00, + RTL_GIGA_MAC_VER_02 = 0x01, + RTL_GIGA_MAC_VER_03 = 0x02, + RTL_GIGA_MAC_VER_04 = 0x03, + RTL_GIGA_MAC_VER_05 = 0x04, + RTL_GIGA_MAC_VER_11 = 0x0b, + RTL_GIGA_MAC_VER_12 = 0x0c, + RTL_GIGA_MAC_VER_13 = 0x0d, + RTL_GIGA_MAC_VER_14 = 0x0e, + RTL_GIGA_MAC_VER_15 = 0x0f }; enum phy_version { @@ -166,7 +171,6 @@ enum phy_version { RTL_GIGA_PHY_VER_H = 0x08, /* PHY Reg 0x03 bit0-3 == 0x0003 */ }; - #define _R(NAME,MAC,MASK) \ { .name = NAME, .mac_version = MAC, .RxConfigMask = MASK } @@ -175,19 +179,44 @@ static const struct { u8 mac_version; u32 RxConfigMask; /* Clears the bits supported by this chip */ } rtl_chip_info[] = { - _R("RTL8169", RTL_GIGA_MAC_VER_B, 0xff7e1880), - _R("RTL8169s/8110s", RTL_GIGA_MAC_VER_D, 0xff7e1880), - _R("RTL8169s/8110s", RTL_GIGA_MAC_VER_E, 0xff7e1880), - _R("RTL8169s/8110s", RTL_GIGA_MAC_VER_X, 0xff7e1880), + _R("RTL8169", RTL_GIGA_MAC_VER_01, 0xff7e1880), + _R("RTL8169s/8110s", RTL_GIGA_MAC_VER_02, 0xff7e1880), + _R("RTL8169s/8110s", RTL_GIGA_MAC_VER_03, 0xff7e1880), + _R("RTL8169sb/8110sb", RTL_GIGA_MAC_VER_04, 0xff7e1880), + _R("RTL8169sc/8110sc", RTL_GIGA_MAC_VER_05, 0xff7e1880), + _R("RTL8168b/8111b", RTL_GIGA_MAC_VER_11, 0xff7e1880), // PCI-E + _R("RTL8168b/8111b", RTL_GIGA_MAC_VER_12, 0xff7e1880), // PCI-E + _R("RTL8101e", RTL_GIGA_MAC_VER_13, 0xff7e1880), // PCI-E 8139 + _R("RTL8100e", RTL_GIGA_MAC_VER_14, 0xff7e1880), // PCI-E 8139 + _R("RTL8100e", RTL_GIGA_MAC_VER_15, 0xff7e1880) // PCI-E 8139 }; #undef _R +enum cfg_version { + RTL_CFG_0 = 0x00, + RTL_CFG_1, + RTL_CFG_2 +}; + +static const struct { + unsigned int region; + unsigned int align; +} rtl_cfg_info[] = { + [RTL_CFG_0] = { 1, NET_IP_ALIGN }, + [RTL_CFG_1] = { 2, NET_IP_ALIGN }, + [RTL_CFG_2] = { 2, 8 } +}; + static struct pci_device_id rtl8169_pci_tbl[] = { - { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8169), }, - { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8129), }, - { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4300), }, - { PCI_DEVICE(0x16ec, 0x0116), }, - { PCI_VENDOR_ID_LINKSYS, 0x1032, PCI_ANY_ID, 0x0024, }, + { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8129), 0, 0, RTL_CFG_0 }, + { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8136), 0, 0, RTL_CFG_1 }, + { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8167), 0, 0, RTL_CFG_1 }, + { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8168), 0, 0, RTL_CFG_2 }, + { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8169), 0, 0, RTL_CFG_0 }, + { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4300), 0, 0, RTL_CFG_0 }, + { PCI_DEVICE(0x16ec, 0x0116), 0, 0, RTL_CFG_0 }, + { PCI_VENDOR_ID_LINKSYS, 0x1032, + PCI_ANY_ID, 0x0024, 0, 0, RTL_CFG_0 }, {0,}, }; @@ -347,6 +376,7 @@ enum RTL8169_register_content { PHY_Cap_100_Full = 0x0100, /* PHY_1000_CTRL_REG = 9 */ + PHY_Cap_1000_Half = 0x0100, PHY_Cap_1000_Full = 0x0200, PHY_Cap_Null = 0x0, @@ -434,6 +464,7 @@ struct rtl8169_private { dma_addr_t RxPhyAddr; struct sk_buff *Rx_skbuff[NUM_RX_DESC]; /* Rx data buffers */ struct ring_info tx_skb[NUM_TX_DESC]; /* Tx data buffers */ + unsigned align; unsigned rx_buf_sz; struct timer_list timer; u16 cp_cmd; @@ -750,25 +781,43 @@ static int rtl8169_set_speed_xmii(struct net_device *dev, auto_nego &= ~(PHY_Cap_10_Half | PHY_Cap_10_Full | PHY_Cap_100_Half | PHY_Cap_100_Full); giga_ctrl = mdio_read(ioaddr, PHY_1000_CTRL_REG); - giga_ctrl &= ~(PHY_Cap_1000_Full | PHY_Cap_Null); + giga_ctrl &= ~(PHY_Cap_1000_Full | PHY_Cap_1000_Half | PHY_Cap_Null); if (autoneg == AUTONEG_ENABLE) { auto_nego |= (PHY_Cap_10_Half | PHY_Cap_10_Full | PHY_Cap_100_Half | PHY_Cap_100_Full); - giga_ctrl |= PHY_Cap_1000_Full; + giga_ctrl |= PHY_Cap_1000_Full | PHY_Cap_1000_Half; } else { if (speed == SPEED_10) auto_nego |= PHY_Cap_10_Half | PHY_Cap_10_Full; else if (speed == SPEED_100) auto_nego |= PHY_Cap_100_Half | PHY_Cap_100_Full; else if (speed == SPEED_1000) - giga_ctrl |= PHY_Cap_1000_Full; + giga_ctrl |= PHY_Cap_1000_Full | PHY_Cap_1000_Half; if (duplex == DUPLEX_HALF) auto_nego &= ~(PHY_Cap_10_Full | PHY_Cap_100_Full); if (duplex == DUPLEX_FULL) auto_nego &= ~(PHY_Cap_10_Half | PHY_Cap_100_Half); + + /* This tweak comes straight from Realtek's driver. */ + if ((speed == SPEED_100) && (duplex == DUPLEX_HALF) && + (tp->mac_version == RTL_GIGA_MAC_VER_13)) { + auto_nego = PHY_Cap_100_Half | 0x01; + } + } + + /* The 8100e/8101e do Fast Ethernet only. */ + if ((tp->mac_version == RTL_GIGA_MAC_VER_13) || + (tp->mac_version == RTL_GIGA_MAC_VER_14) || + (tp->mac_version == RTL_GIGA_MAC_VER_15)) { + if ((giga_ctrl & (PHY_Cap_1000_Full | PHY_Cap_1000_Half)) && + netif_msg_link(tp)) { + printk(KERN_INFO "%s: PHY does not support 1000Mbps.\n", + dev->name); + } + giga_ctrl &= ~(PHY_Cap_1000_Full | PHY_Cap_1000_Half); } auto_nego |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM; @@ -1148,10 +1197,16 @@ static void rtl8169_get_mac_version(struct rtl8169_private *tp, void __iomem *io u32 mask; int mac_version; } mac_info[] = { - { 0x1 << 28, RTL_GIGA_MAC_VER_X }, - { 0x1 << 26, RTL_GIGA_MAC_VER_E }, - { 0x1 << 23, RTL_GIGA_MAC_VER_D }, - { 0x00000000, RTL_GIGA_MAC_VER_B } /* Catch-all */ + { 0x38800000, RTL_GIGA_MAC_VER_15 }, + { 0x38000000, RTL_GIGA_MAC_VER_12 }, + { 0x34000000, RTL_GIGA_MAC_VER_13 }, + { 0x30800000, RTL_GIGA_MAC_VER_14 }, + { 0x30000000, RTL_GIGA_MAC_VER_11 }, + { 0x18000000, RTL_GIGA_MAC_VER_05 }, + { 0x10000000, RTL_GIGA_MAC_VER_04 }, + { 0x04000000, RTL_GIGA_MAC_VER_03 }, + { 0x00800000, RTL_GIGA_MAC_VER_02 }, + { 0x00000000, RTL_GIGA_MAC_VER_01 } /* Catch-all */ }, *p = mac_info; u32 reg; @@ -1163,24 +1218,7 @@ static void rtl8169_get_mac_version(struct rtl8169_private *tp, void __iomem *io static void rtl8169_print_mac_version(struct rtl8169_private *tp) { - struct { - int version; - char *msg; - } mac_print[] = { - { RTL_GIGA_MAC_VER_E, "RTL_GIGA_MAC_VER_E" }, - { RTL_GIGA_MAC_VER_D, "RTL_GIGA_MAC_VER_D" }, - { RTL_GIGA_MAC_VER_B, "RTL_GIGA_MAC_VER_B" }, - { 0, NULL } - }, *p; - - for (p = mac_print; p->msg; p++) { - if (tp->mac_version == p->version) { - dprintk("mac_version == %s (%04d)\n", p->msg, - p->version); - return; - } - } - dprintk("mac_version == Unknown\n"); + dprintk("mac_version = 0x%02x\n", tp->mac_version); } static void rtl8169_get_phy_version(struct rtl8169_private *tp, void __iomem *ioaddr) @@ -1265,7 +1303,7 @@ static void rtl8169_hw_phy_config(struct net_device *dev) rtl8169_print_mac_version(tp); rtl8169_print_phy_version(tp); - if (tp->mac_version <= RTL_GIGA_MAC_VER_B) + if (tp->mac_version <= RTL_GIGA_MAC_VER_01) return; if (tp->phy_version >= RTL_GIGA_PHY_VER_H) return; @@ -1275,7 +1313,7 @@ static void rtl8169_hw_phy_config(struct net_device *dev) /* Shazam ! */ - if (tp->mac_version == RTL_GIGA_MAC_VER_X) { + if (tp->mac_version == RTL_GIGA_MAC_VER_04) { mdio_write(ioaddr, 31, 0x0001); mdio_write(ioaddr, 9, 0x273a); mdio_write(ioaddr, 14, 0x7bfb); @@ -1314,7 +1352,7 @@ static void rtl8169_phy_timer(unsigned long __opaque) void __iomem *ioaddr = tp->mmio_addr; unsigned long timeout = RTL8169_PHY_TIMEOUT; - assert(tp->mac_version > RTL_GIGA_MAC_VER_B); + assert(tp->mac_version > RTL_GIGA_MAC_VER_01); assert(tp->phy_version < RTL_GIGA_PHY_VER_H); if (!(tp->phy_1000_ctrl_reg & PHY_Cap_1000_Full)) @@ -1350,7 +1388,7 @@ static inline void rtl8169_delete_timer(struct net_device *dev) struct rtl8169_private *tp = netdev_priv(dev); struct timer_list *timer = &tp->timer; - if ((tp->mac_version <= RTL_GIGA_MAC_VER_B) || + if ((tp->mac_version <= RTL_GIGA_MAC_VER_01) || (tp->phy_version >= RTL_GIGA_PHY_VER_H)) return; @@ -1362,7 +1400,7 @@ static inline void rtl8169_request_timer(struct net_device *dev) struct rtl8169_private *tp = netdev_priv(dev); struct timer_list *timer = &tp->timer; - if ((tp->mac_version <= RTL_GIGA_MAC_VER_B) || + if ((tp->mac_version <= RTL_GIGA_MAC_VER_01) || (tp->phy_version >= RTL_GIGA_PHY_VER_H)) return; @@ -1448,12 +1486,12 @@ static void rtl8169_init_phy(struct net_device *dev, struct rtl8169_private *tp) dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n"); RTL_W8(0x82, 0x01); - if (tp->mac_version < RTL_GIGA_MAC_VER_E) { + if (tp->mac_version < RTL_GIGA_MAC_VER_03) { dprintk("Set PCI Latency=0x40\n"); pci_write_config_byte(tp->pci_dev, PCI_LATENCY_TIMER, 0x40); } - if (tp->mac_version == RTL_GIGA_MAC_VER_D) { + if (tp->mac_version == RTL_GIGA_MAC_VER_02) { dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n"); RTL_W8(0x82, 0x01); dprintk("Set PHY Reg 0x0bh = 0x00h\n"); @@ -1471,6 +1509,7 @@ static void rtl8169_init_phy(struct net_device *dev, struct rtl8169_private *tp) static int __devinit rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) { + const unsigned int region = rtl_cfg_info[ent->driver_data].region; struct rtl8169_private *tp; struct net_device *dev; void __iomem *ioaddr; @@ -1522,17 +1561,18 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) } /* make sure PCI base addr 1 is MMIO */ - if (!(pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) { + if (!(pci_resource_flags(pdev, region) & IORESOURCE_MEM)) { if (netif_msg_probe(tp)) { dev_err(&pdev->dev, - "region #1 not an MMIO resource, aborting\n"); + "region #%d not an MMIO resource, aborting\n", + region); } rc = -ENODEV; goto err_out_mwi_3; } /* check for weird/broken PCI region reporting */ - if (pci_resource_len(pdev, 1) < R8169_REGS_SIZE) { + if (pci_resource_len(pdev, region) < R8169_REGS_SIZE) { if (netif_msg_probe(tp)) { dev_err(&pdev->dev, "Invalid PCI region size(s), aborting\n"); @@ -1568,7 +1608,7 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) pci_set_master(pdev); /* ioremap MMIO region */ - ioaddr = ioremap(pci_resource_start(pdev, 1), R8169_REGS_SIZE); + ioaddr = ioremap(pci_resource_start(pdev, region), R8169_REGS_SIZE); if (!ioaddr) { if (netif_msg_probe(tp)) dev_err(&pdev->dev, "cannot remap MMIO, aborting\n"); @@ -1668,6 +1708,7 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) tp->intr_mask = 0xffff; tp->pci_dev = pdev; tp->mmio_addr = ioaddr; + tp->align = rtl_cfg_info[ent->driver_data].align; spin_lock_init(&tp->lock); @@ -1675,11 +1716,6 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) if (rc < 0) goto err_out_unmap_5; - if (netif_msg_probe(tp)) { - printk(KERN_DEBUG "%s: Identified chip type is '%s'.\n", - dev->name, rtl_chip_info[tp->chipset].name); - } - pci_set_drvdata(pdev, dev); if (netif_msg_probe(tp)) { @@ -1687,7 +1723,7 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x, " "IRQ %d\n", dev->name, - rtl_chip_info[ent->driver_data].name, + rtl_chip_info[tp->chipset].name, dev->base_addr, dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2], dev->dev_addr[3], @@ -1805,6 +1841,7 @@ rtl8169_hw_start(struct net_device *dev) { struct rtl8169_private *tp = netdev_priv(dev); void __iomem *ioaddr = tp->mmio_addr; + struct pci_dev *pdev = tp->pci_dev; u32 i; /* Soft reset the chip. */ @@ -1817,8 +1854,28 @@ rtl8169_hw_start(struct net_device *dev) udelay(10); } + if (tp->mac_version == RTL_GIGA_MAC_VER_13) { + pci_write_config_word(pdev, 0x68, 0x00); + pci_write_config_word(pdev, 0x69, 0x08); + } + + /* Undocumented stuff. */ + if (tp->mac_version == RTL_GIGA_MAC_VER_05) { + u16 cmd; + + /* Realtek's r1000_n.c driver uses '&& 0x01' here. Well... */ + if ((RTL_R8(Config2) & 0x07) & 0x01) + RTL_W32(0x7c, 0x0007ffff); + + RTL_W32(0x7c, 0x0007ff00); + + pci_read_config_word(pdev, PCI_COMMAND, &cmd); + cmd = cmd & 0xef; + pci_write_config_word(pdev, PCI_COMMAND, cmd); + } + + RTL_W8(Cfg9346, Cfg9346_Unlock); - RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); RTL_W8(EarlyTxThres, EarlyTxThld); /* Low hurts. Let's disable the filtering. */ @@ -1833,17 +1890,18 @@ rtl8169_hw_start(struct net_device *dev) RTL_W32(TxConfig, (TX_DMA_BURST << TxDMAShift) | (InterFrameGap << TxInterFrameGapShift)); - tp->cp_cmd |= RTL_R16(CPlusCmd); - RTL_W16(CPlusCmd, tp->cp_cmd); - if ((tp->mac_version == RTL_GIGA_MAC_VER_D) || - (tp->mac_version == RTL_GIGA_MAC_VER_E)) { + tp->cp_cmd |= RTL_R16(CPlusCmd) | PCIMulRW; + + if ((tp->mac_version == RTL_GIGA_MAC_VER_02) || + (tp->mac_version == RTL_GIGA_MAC_VER_03)) { dprintk(KERN_INFO PFX "Set MAC Reg C+CR Offset 0xE0. " "Bit-3 and bit-14 MUST be 1\n"); - tp->cp_cmd |= (1 << 14) | PCIMulRW; - RTL_W16(CPlusCmd, tp->cp_cmd); + tp->cp_cmd |= (1 << 14); } + RTL_W16(CPlusCmd, tp->cp_cmd); + /* * Undocumented corner. Supposedly: * (TxTimer << 12) | (TxPackets << 8) | (RxTimer << 4) | RxPackets @@ -1854,6 +1912,7 @@ rtl8169_hw_start(struct net_device *dev) RTL_W32(TxDescStartAddrHigh, ((u64) tp->TxPhyAddr >> 32)); RTL_W32(RxDescAddrLow, ((u64) tp->RxPhyAddr & DMA_32BIT_MASK)); RTL_W32(RxDescAddrHigh, ((u64) tp->RxPhyAddr >> 32)); + RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); RTL_W8(Cfg9346, Cfg9346_Lock); udelay(10); @@ -1937,17 +1996,18 @@ static inline void rtl8169_map_to_asic(struct RxDesc *desc, dma_addr_t mapping, } static int rtl8169_alloc_rx_skb(struct pci_dev *pdev, struct sk_buff **sk_buff, - struct RxDesc *desc, int rx_buf_sz) + struct RxDesc *desc, int rx_buf_sz, + unsigned int align) { struct sk_buff *skb; dma_addr_t mapping; int ret = 0; - skb = dev_alloc_skb(rx_buf_sz + NET_IP_ALIGN); + skb = dev_alloc_skb(rx_buf_sz + align); if (!skb) goto err_out; - skb_reserve(skb, NET_IP_ALIGN); + skb_reserve(skb, align); *sk_buff = skb; mapping = pci_map_single(pdev, skb->data, rx_buf_sz, @@ -1986,9 +2046,9 @@ static u32 rtl8169_rx_fill(struct rtl8169_private *tp, struct net_device *dev, if (tp->Rx_skbuff[i]) continue; - + ret = rtl8169_alloc_rx_skb(tp->pci_dev, tp->Rx_skbuff + i, - tp->RxDescArray + i, tp->rx_buf_sz); + tp->RxDescArray + i, tp->rx_buf_sz, tp->align); if (ret < 0) break; } @@ -2399,16 +2459,17 @@ static inline void rtl8169_rx_csum(struct sk_buff *skb, struct RxDesc *desc) } static inline int rtl8169_try_rx_copy(struct sk_buff **sk_buff, int pkt_size, - struct RxDesc *desc, int rx_buf_sz) + struct RxDesc *desc, int rx_buf_sz, + unsigned int align) { int ret = -1; if (pkt_size < rx_copybreak) { struct sk_buff *skb; - skb = dev_alloc_skb(pkt_size + NET_IP_ALIGN); + skb = dev_alloc_skb(pkt_size + align); if (skb) { - skb_reserve(skb, NET_IP_ALIGN); + skb_reserve(skb, align); eth_copy_and_sum(skb, sk_buff[0]->data, pkt_size, 0); *sk_buff = skb; rtl8169_mark_to_asic(desc, rx_buf_sz); @@ -2478,13 +2539,13 @@ rtl8169_rx_interrupt(struct net_device *dev, struct rtl8169_private *tp, } rtl8169_rx_csum(skb, desc); - + pci_dma_sync_single_for_cpu(tp->pci_dev, le64_to_cpu(desc->addr), tp->rx_buf_sz, PCI_DMA_FROMDEVICE); if (rtl8169_try_rx_copy(&skb, pkt_size, desc, - tp->rx_buf_sz)) { + tp->rx_buf_sz, tp->align)) { pci_action = pci_unmap_single; tp->Rx_skbuff[entry] = NULL; } @@ -2747,6 +2808,15 @@ rtl8169_set_rx_mode(struct net_device *dev) tmp = rtl8169_rx_config | rx_mode | (RTL_R32(RxConfig) & rtl_chip_info[tp->chipset].RxConfigMask); + if ((tp->mac_version == RTL_GIGA_MAC_VER_11) || + (tp->mac_version == RTL_GIGA_MAC_VER_12) || + (tp->mac_version == RTL_GIGA_MAC_VER_13) || + (tp->mac_version == RTL_GIGA_MAC_VER_14) || + (tp->mac_version == RTL_GIGA_MAC_VER_15)) { + mc_filter[0] = 0xffffffff; + mc_filter[1] = 0xffffffff; + } + RTL_W32(RxConfig, tmp); RTL_W32(MAR0 + 0, mc_filter[0]); RTL_W32(MAR0 + 4, mc_filter[1]); -- cgit v1.2.3 From 188f4af04618b32b8ec7c630a3f18201c81ce70c Mon Sep 17 00:00:00 2001 From: Francois Romieu Date: Wed, 16 Aug 2006 14:51:52 +0200 Subject: r8169: use NETDEV_TX_{BUSY/OK} Signed-off-by: Francois Romieu --- drivers/net/r8169.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/net') diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c index d0bfe4c8950d..b07d2eadeae6 100644 --- a/drivers/net/r8169.c +++ b/drivers/net/r8169.c @@ -2277,7 +2277,7 @@ static int rtl8169_start_xmit(struct sk_buff *skb, struct net_device *dev) dma_addr_t mapping; u32 status, len; u32 opts1; - int ret = 0; + int ret = NETDEV_TX_OK; if (unlikely(TX_BUFFS_AVAIL(tp) < skb_shinfo(skb)->nr_frags)) { if (netif_msg_drv(tp)) { @@ -2342,7 +2342,7 @@ out: err_stop: netif_stop_queue(dev); - ret = 1; + ret = NETDEV_TX_BUSY; err_update_stats: tp->stats.tx_dropped++; goto out; -- cgit v1.2.3 From b518fa8eac2d0ac497c0fdb27e4cec68d0249bb7 Mon Sep 17 00:00:00 2001 From: Francois Romieu Date: Wed, 16 Aug 2006 15:23:13 +0200 Subject: r8169: udelay() removal No need to chew CPU cycles as there is no heavy timing requirement and the delays are always requested from a sleepable context. Signed-off-by: Francois Romieu --- drivers/net/r8169.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'drivers/net') diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c index b07d2eadeae6..653b9a7a4178 100644 --- a/drivers/net/r8169.c +++ b/drivers/net/r8169.c @@ -1623,10 +1623,10 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) RTL_W8(ChipCmd, CmdReset); /* Check that the chip has finished the reset. */ - for (i = 1000; i > 0; i--) { + for (i = 100; i > 0; i--) { if ((RTL_R8(ChipCmd) & CmdReset) == 0) break; - udelay(10); + msleep_interruptible(1); } /* Identify chip attached to board */ @@ -1848,10 +1848,10 @@ rtl8169_hw_start(struct net_device *dev) RTL_W8(ChipCmd, CmdReset); /* Check that the chip has finished the reset. */ - for (i = 1000; i > 0; i--) { + for (i = 100; i > 0; i--) { if ((RTL_R8(ChipCmd) & CmdReset) == 0) break; - udelay(10); + msleep_interruptible(1); } if (tp->mac_version == RTL_GIGA_MAC_VER_13) { @@ -1914,7 +1914,9 @@ rtl8169_hw_start(struct net_device *dev) RTL_W32(RxDescAddrHigh, ((u64) tp->RxPhyAddr >> 32)); RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); RTL_W8(Cfg9346, Cfg9346_Lock); - udelay(10); + + /* Initially a 10 us delay. Turned it into a PCI commit. - FR */ + RTL_R8(IntrMask); RTL_W32(RxMissed, 0); -- cgit v1.2.3 From 5b0384f4fd079c24b976ee333e6d1f0c95cf14de Mon Sep 17 00:00:00 2001 From: Francois Romieu Date: Wed, 16 Aug 2006 16:00:01 +0200 Subject: r8169: trim trailing whitespaces and convert whitespaces to tabs Signed-off-by: Francois Romieu --- drivers/net/r8169.c | 65 ++++++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 33 deletions(-) (limited to 'drivers/net') diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c index 653b9a7a4178..5d620d81e8cb 100644 --- a/drivers/net/r8169.c +++ b/drivers/net/r8169.c @@ -6,26 +6,26 @@ History: Feb 4 2002 - created initially by ShuChen . May 20 2002 - Add link status force-mode and TBI mode support. - 2004 - Massive updates. See kernel SCM system for details. + 2004 - Massive updates. See kernel SCM system for details. ========================================================================= 1. [DEPRECATED: use ethtool instead] The media can be forced in 5 modes. Command: 'insmod r8169 media = SET_MEDIA' Ex: 'insmod r8169 media = 0x04' will force PHY to operate in 100Mpbs Half-duplex. - + SET_MEDIA can be: _10_Half = 0x01 _10_Full = 0x02 _100_Half = 0x04 _100_Full = 0x08 _1000_Full = 0x10 - + 2. Support TBI mode. ========================================================================= VERSION 1.1 <2002/10/4> The bit4:0 of MII register 4 is called "selector field", and have to be 00001b to indicate support of IEEE std 802.3 during NWay process of - exchanging Link Code Word (FLP). + exchanging Link Code Word (FLP). VERSION 1.2 <2002/11/30> @@ -81,10 +81,10 @@ VERSION 2.2LK <2005/01/25> #ifdef RTL8169_DEBUG #define assert(expr) \ - if(!(expr)) { \ - printk( "Assertion failed! %s,%s,%s,line=%d\n", \ - #expr,__FILE__,__FUNCTION__,__LINE__); \ - } + if (!(expr)) { \ + printk( "Assertion failed! %s,%s,%s,line=%d\n", \ + #expr,__FILE__,__FUNCTION__,__LINE__); \ + } #define dprintk(fmt, args...) do { printk(PFX fmt, ## args); } while (0) #else #define assert(expr) do {} while (0) @@ -520,7 +520,7 @@ static const u16 rtl8169_intr_mask = static const u16 rtl8169_napi_event = RxOK | RxOverflow | RxFIFOOver | TxOK | TxErr; static const unsigned int rtl8169_rx_config = - (RX_FIFO_THRESH << RxCfgFIFOShift) | (RX_DMA_BURST << RxCfgDMAShift); + (RX_FIFO_THRESH << RxCfgFIFOShift) | (RX_DMA_BURST << RxCfgDMAShift); #define PHY_Cap_10_Half_Or_Less PHY_Cap_10_Half #define PHY_Cap_10_Full_Or_Less PHY_Cap_10_Full | PHY_Cap_10_Half_Or_Less @@ -535,7 +535,7 @@ static void mdio_write(void __iomem *ioaddr, int RegAddr, int value) for (i = 20; i > 0; i--) { /* Check if the RTL8169 has completed writing to the specified MII register */ - if (!(RTL_R32(PHYAR) & 0x80000000)) + if (!(RTL_R32(PHYAR) & 0x80000000)) break; udelay(25); } @@ -640,7 +640,7 @@ static void rtl8169_link_option(int idx, u8 *autoneg, u16 *speed, u8 *duplex) { SPEED_1000, DUPLEX_FULL, AUTONEG_ENABLE, 0xff } }, *p; unsigned char option; - + option = ((idx < MAX_UNITS) && (idx >= 0)) ? media[idx] : 0xff; if ((option != 0xff) && !idx && netif_msg_drv(&debug)) @@ -682,9 +682,9 @@ static void rtl8169_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) if (options & UWF) wol->wolopts |= WAKE_UCAST; if (options & BWF) - wol->wolopts |= WAKE_BCAST; + wol->wolopts |= WAKE_BCAST; if (options & MWF) - wol->wolopts |= WAKE_MCAST; + wol->wolopts |= WAKE_MCAST; out_unlock: spin_unlock_irq(&tp->lock); @@ -855,7 +855,7 @@ static int rtl8169_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) spin_lock_irqsave(&tp->lock, flags); ret = rtl8169_set_speed(dev, cmd->autoneg, cmd->speed, cmd->duplex); spin_unlock_irqrestore(&tp->lock, flags); - + return ret; } @@ -988,7 +988,7 @@ static void rtl8169_gset_xmii(struct net_device *dev, struct ethtool_cmd *cmd) SUPPORTED_100baseT_Full | SUPPORTED_1000baseT_Full | SUPPORTED_Autoneg | - SUPPORTED_TP; + SUPPORTED_TP; cmd->autoneg = 1; cmd->advertising = ADVERTISED_TP | ADVERTISED_Autoneg; @@ -1038,15 +1038,15 @@ static int rtl8169_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) static void rtl8169_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p) { - struct rtl8169_private *tp = netdev_priv(dev); - unsigned long flags; + struct rtl8169_private *tp = netdev_priv(dev); + unsigned long flags; - if (regs->len > R8169_REGS_SIZE) - regs->len = R8169_REGS_SIZE; + if (regs->len > R8169_REGS_SIZE) + regs->len = R8169_REGS_SIZE; - spin_lock_irqsave(&tp->lock, flags); - memcpy_fromio(p, tp->mmio_addr, regs->len); - spin_unlock_irqrestore(&tp->lock, flags); + spin_lock_irqsave(&tp->lock, flags); + memcpy_fromio(p, tp->mmio_addr, regs->len); + spin_unlock_irqrestore(&tp->lock, flags); } static u32 rtl8169_get_msglevel(struct net_device *dev) @@ -1128,7 +1128,7 @@ static void rtl8169_get_ethtool_stats(struct net_device *dev, RTL_W32(CounterAddrLow, 0); RTL_W32(CounterAddrHigh, 0); - data[0] = le64_to_cpu(counters->tx_packets); + data[0] = le64_to_cpu(counters->tx_packets); data[1] = le64_to_cpu(counters->rx_packets); data[2] = le64_to_cpu(counters->tx_errors); data[3] = le32_to_cpu(counters->rx_errors); @@ -1188,7 +1188,7 @@ static void rtl8169_write_gmii_reg_bit(void __iomem *ioaddr, int reg, int bitnum val = mdio_read(ioaddr, reg); val = (bitval == 1) ? val | (bitval << bitnum) : val & ~(0x0001 << bitnum); - mdio_write(ioaddr, reg, val & 0xffff); + mdio_write(ioaddr, reg, val & 0xffff); } static void rtl8169_get_mac_version(struct rtl8169_private *tp, void __iomem *ioaddr) @@ -1201,7 +1201,7 @@ static void rtl8169_get_mac_version(struct rtl8169_private *tp, void __iomem *io { 0x38000000, RTL_GIGA_MAC_VER_12 }, { 0x34000000, RTL_GIGA_MAC_VER_13 }, { 0x30800000, RTL_GIGA_MAC_VER_14 }, - { 0x30000000, RTL_GIGA_MAC_VER_11 }, + { 0x30000000, RTL_GIGA_MAC_VER_11 }, { 0x18000000, RTL_GIGA_MAC_VER_05 }, { 0x10000000, RTL_GIGA_MAC_VER_04 }, { 0x04000000, RTL_GIGA_MAC_VER_03 }, @@ -1361,7 +1361,7 @@ static void rtl8169_phy_timer(unsigned long __opaque) spin_lock_irq(&tp->lock); if (tp->phy_reset_pending(ioaddr)) { - /* + /* * A busy loop could burn quite a few cycles on nowadays CPU. * Let's delay the execution of the timer for a few ticks. */ @@ -1887,9 +1887,8 @@ rtl8169_hw_start(struct net_device *dev) RTL_W32(RxConfig, i); /* Set DMA burst size and Interframe Gap Time */ - RTL_W32(TxConfig, - (TX_DMA_BURST << TxDMAShift) | (InterFrameGap << - TxInterFrameGapShift)); + RTL_W32(TxConfig, (TX_DMA_BURST << TxDMAShift) | + (InterFrameGap << TxInterFrameGapShift)); tp->cp_cmd |= RTL_R16(CPlusCmd) | PCIMulRW; @@ -2042,7 +2041,7 @@ static u32 rtl8169_rx_fill(struct rtl8169_private *tp, struct net_device *dev, u32 start, u32 end) { u32 cur; - + for (cur = start; end - cur > 0; cur++) { int ret, i = cur % NUM_RX_DESC; @@ -2280,7 +2279,7 @@ static int rtl8169_start_xmit(struct sk_buff *skb, struct net_device *dev) u32 status, len; u32 opts1; int ret = NETDEV_TX_OK; - + if (unlikely(TX_BUFFS_AVAIL(tp) < skb_shinfo(skb)->nr_frags)) { if (netif_msg_drv(tp)) { printk(KERN_ERR @@ -2637,7 +2636,7 @@ rtl8169_interrupt(int irq, void *dev_instance, struct pt_regs *regs) __netif_rx_schedule(dev); else if (netif_msg_intr(tp)) { printk(KERN_INFO "%s: interrupt %04x taken in poll\n", - dev->name, status); + dev->name, status); } break; #else @@ -2844,7 +2843,7 @@ static struct net_device_stats *rtl8169_get_stats(struct net_device *dev) RTL_W32(RxMissed, 0); spin_unlock_irqrestore(&tp->lock, flags); } - + return &tp->stats; } -- cgit v1.2.3 From 64e4bfb40c9d07a48c1c7e5b8556e92e7cd7406a Mon Sep 17 00:00:00 2001 From: Francois Romieu Date: Thu, 17 Aug 2006 12:43:06 +0200 Subject: r8169: use standard #defines from mii.h instead of declaring private ones Some unused stuff goes away btw. Signed-off-by: Francois Romieu --- drivers/net/r8169.c | 93 ++++++++++++++++++----------------------------------- 1 file changed, 31 insertions(+), 62 deletions(-) (limited to 'drivers/net') diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c index 5d620d81e8cb..0025b8367ece 100644 --- a/drivers/net/r8169.c +++ b/drivers/net/r8169.c @@ -356,31 +356,6 @@ enum RTL8169_register_content { LinkStatus = 0x02, FullDup = 0x01, - /* GIGABIT_PHY_registers */ - PHY_CTRL_REG = 0, - PHY_STAT_REG = 1, - PHY_AUTO_NEGO_REG = 4, - PHY_1000_CTRL_REG = 9, - - /* GIGABIT_PHY_REG_BIT */ - PHY_Restart_Auto_Nego = 0x0200, - PHY_Enable_Auto_Nego = 0x1000, - - /* PHY_STAT_REG = 1 */ - PHY_Auto_Neco_Comp = 0x0020, - - /* PHY_AUTO_NEGO_REG = 4 */ - PHY_Cap_10_Half = 0x0020, - PHY_Cap_10_Full = 0x0040, - PHY_Cap_100_Half = 0x0080, - PHY_Cap_100_Full = 0x0100, - - /* PHY_1000_CTRL_REG = 9 */ - PHY_Cap_1000_Half = 0x0100, - PHY_Cap_1000_Full = 0x0200, - - PHY_Cap_Null = 0x0, - /* _MediaType */ _10_Half = 0x01, _10_Full = 0x02, @@ -522,11 +497,6 @@ static const u16 rtl8169_napi_event = static const unsigned int rtl8169_rx_config = (RX_FIFO_THRESH << RxCfgFIFOShift) | (RX_DMA_BURST << RxCfgDMAShift); -#define PHY_Cap_10_Half_Or_Less PHY_Cap_10_Half -#define PHY_Cap_10_Full_Or_Less PHY_Cap_10_Full | PHY_Cap_10_Half_Or_Less -#define PHY_Cap_100_Half_Or_Less PHY_Cap_100_Half | PHY_Cap_10_Full_Or_Less -#define PHY_Cap_100_Full_Or_Less PHY_Cap_100_Full | PHY_Cap_100_Half_Or_Less - static void mdio_write(void __iomem *ioaddr, int RegAddr, int value) { int i; @@ -579,7 +549,7 @@ static unsigned int rtl8169_tbi_reset_pending(void __iomem *ioaddr) static unsigned int rtl8169_xmii_reset_pending(void __iomem *ioaddr) { - return mdio_read(ioaddr, 0) & 0x8000; + return mdio_read(ioaddr, MII_BMCR) & BMCR_RESET; } static unsigned int rtl8169_tbi_link_ok(void __iomem *ioaddr) @@ -601,8 +571,8 @@ static void rtl8169_xmii_reset_enable(void __iomem *ioaddr) { unsigned int val; - val = (mdio_read(ioaddr, PHY_CTRL_REG) | 0x8000) & 0xffff; - mdio_write(ioaddr, PHY_CTRL_REG, val); + val = (mdio_read(ioaddr, MII_BMCR) | BMCR_RESET) & 0xffff; + mdio_write(ioaddr, MII_BMCR, val); } static void rtl8169_check_link_status(struct net_device *dev, @@ -777,34 +747,34 @@ static int rtl8169_set_speed_xmii(struct net_device *dev, void __iomem *ioaddr = tp->mmio_addr; int auto_nego, giga_ctrl; - auto_nego = mdio_read(ioaddr, PHY_AUTO_NEGO_REG); - auto_nego &= ~(PHY_Cap_10_Half | PHY_Cap_10_Full | - PHY_Cap_100_Half | PHY_Cap_100_Full); - giga_ctrl = mdio_read(ioaddr, PHY_1000_CTRL_REG); - giga_ctrl &= ~(PHY_Cap_1000_Full | PHY_Cap_1000_Half | PHY_Cap_Null); + auto_nego = mdio_read(ioaddr, MII_ADVERTISE); + auto_nego &= ~(ADVERTISE_10HALF | ADVERTISE_10FULL | + ADVERTISE_100HALF | ADVERTISE_100FULL); + giga_ctrl = mdio_read(ioaddr, MII_CTRL1000); + giga_ctrl &= ~(ADVERTISE_1000FULL | ADVERTISE_1000HALF); if (autoneg == AUTONEG_ENABLE) { - auto_nego |= (PHY_Cap_10_Half | PHY_Cap_10_Full | - PHY_Cap_100_Half | PHY_Cap_100_Full); - giga_ctrl |= PHY_Cap_1000_Full | PHY_Cap_1000_Half; + auto_nego |= (ADVERTISE_10HALF | ADVERTISE_10FULL | + ADVERTISE_100HALF | ADVERTISE_100FULL); + giga_ctrl |= ADVERTISE_1000FULL | ADVERTISE_1000HALF; } else { if (speed == SPEED_10) - auto_nego |= PHY_Cap_10_Half | PHY_Cap_10_Full; + auto_nego |= ADVERTISE_10HALF | ADVERTISE_10FULL; else if (speed == SPEED_100) - auto_nego |= PHY_Cap_100_Half | PHY_Cap_100_Full; + auto_nego |= ADVERTISE_100HALF | ADVERTISE_100FULL; else if (speed == SPEED_1000) - giga_ctrl |= PHY_Cap_1000_Full | PHY_Cap_1000_Half; + giga_ctrl |= ADVERTISE_1000FULL | ADVERTISE_1000HALF; if (duplex == DUPLEX_HALF) - auto_nego &= ~(PHY_Cap_10_Full | PHY_Cap_100_Full); + auto_nego &= ~(ADVERTISE_10FULL | ADVERTISE_100FULL); if (duplex == DUPLEX_FULL) - auto_nego &= ~(PHY_Cap_10_Half | PHY_Cap_100_Half); + auto_nego &= ~(ADVERTISE_10HALF | ADVERTISE_100HALF); /* This tweak comes straight from Realtek's driver. */ if ((speed == SPEED_100) && (duplex == DUPLEX_HALF) && (tp->mac_version == RTL_GIGA_MAC_VER_13)) { - auto_nego = PHY_Cap_100_Half | 0x01; + auto_nego = ADVERTISE_100HALF | ADVERTISE_CSMA; } } @@ -812,12 +782,12 @@ static int rtl8169_set_speed_xmii(struct net_device *dev, if ((tp->mac_version == RTL_GIGA_MAC_VER_13) || (tp->mac_version == RTL_GIGA_MAC_VER_14) || (tp->mac_version == RTL_GIGA_MAC_VER_15)) { - if ((giga_ctrl & (PHY_Cap_1000_Full | PHY_Cap_1000_Half)) && + if ((giga_ctrl & (ADVERTISE_1000FULL | ADVERTISE_1000HALF)) && netif_msg_link(tp)) { printk(KERN_INFO "%s: PHY does not support 1000Mbps.\n", dev->name); } - giga_ctrl &= ~(PHY_Cap_1000_Full | PHY_Cap_1000_Half); + giga_ctrl &= ~(ADVERTISE_1000FULL | ADVERTISE_1000HALF); } auto_nego |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM; @@ -825,10 +795,9 @@ static int rtl8169_set_speed_xmii(struct net_device *dev, tp->phy_auto_nego_reg = auto_nego; tp->phy_1000_ctrl_reg = giga_ctrl; - mdio_write(ioaddr, PHY_AUTO_NEGO_REG, auto_nego); - mdio_write(ioaddr, PHY_1000_CTRL_REG, giga_ctrl); - mdio_write(ioaddr, PHY_CTRL_REG, PHY_Enable_Auto_Nego | - PHY_Restart_Auto_Nego); + mdio_write(ioaddr, MII_ADVERTISE, auto_nego); + mdio_write(ioaddr, MII_CTRL1000, giga_ctrl); + mdio_write(ioaddr, MII_BMCR, BMCR_ANENABLE | BMCR_ANRESTART); return 0; } @@ -840,7 +809,7 @@ static int rtl8169_set_speed(struct net_device *dev, ret = tp->set_speed(dev, autoneg, speed, duplex); - if (netif_running(dev) && (tp->phy_1000_ctrl_reg & PHY_Cap_1000_Full)) + if (netif_running(dev) && (tp->phy_1000_ctrl_reg & ADVERTISE_1000FULL)) mod_timer(&tp->timer, jiffies + RTL8169_PHY_TIMEOUT); return ret; @@ -993,15 +962,15 @@ static void rtl8169_gset_xmii(struct net_device *dev, struct ethtool_cmd *cmd) cmd->autoneg = 1; cmd->advertising = ADVERTISED_TP | ADVERTISED_Autoneg; - if (tp->phy_auto_nego_reg & PHY_Cap_10_Half) + if (tp->phy_auto_nego_reg & ADVERTISE_10HALF) cmd->advertising |= ADVERTISED_10baseT_Half; - if (tp->phy_auto_nego_reg & PHY_Cap_10_Full) + if (tp->phy_auto_nego_reg & ADVERTISE_10FULL) cmd->advertising |= ADVERTISED_10baseT_Full; - if (tp->phy_auto_nego_reg & PHY_Cap_100_Half) + if (tp->phy_auto_nego_reg & ADVERTISE_100HALF) cmd->advertising |= ADVERTISED_100baseT_Half; - if (tp->phy_auto_nego_reg & PHY_Cap_100_Full) + if (tp->phy_auto_nego_reg & ADVERTISE_100FULL) cmd->advertising |= ADVERTISED_100baseT_Full; - if (tp->phy_1000_ctrl_reg & PHY_Cap_1000_Full) + if (tp->phy_1000_ctrl_reg & ADVERTISE_1000FULL) cmd->advertising |= ADVERTISED_1000baseT_Full; status = RTL_R8(PHYstatus); @@ -1235,7 +1204,7 @@ static void rtl8169_get_phy_version(struct rtl8169_private *tp, void __iomem *io }, *p = phy_info; u16 reg; - reg = mdio_read(ioaddr, 3) & 0xffff; + reg = mdio_read(ioaddr, MII_PHYSID2) & 0xffff; while ((reg & p->mask) != p->set) p++; tp->phy_version = p->phy_version; @@ -1355,7 +1324,7 @@ static void rtl8169_phy_timer(unsigned long __opaque) assert(tp->mac_version > RTL_GIGA_MAC_VER_01); assert(tp->phy_version < RTL_GIGA_PHY_VER_H); - if (!(tp->phy_1000_ctrl_reg & PHY_Cap_1000_Full)) + if (!(tp->phy_1000_ctrl_reg & ADVERTISE_1000FULL)) return; spin_lock_irq(&tp->lock); @@ -1663,7 +1632,7 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) tp->phy_reset_pending = rtl8169_tbi_reset_pending; tp->link_ok = rtl8169_tbi_link_ok; - tp->phy_1000_ctrl_reg = PHY_Cap_1000_Full; /* Implied by TBI */ + tp->phy_1000_ctrl_reg = ADVERTISE_1000FULL; /* Implied by TBI */ } else { tp->set_speed = rtl8169_set_speed_xmii; tp->get_settings = rtl8169_gset_xmii; -- cgit v1.2.3 From 5f787a1aca3705bdc6adbda36f8d6446380e85a6 Mon Sep 17 00:00:00 2001 From: Francois Romieu Date: Thu, 17 Aug 2006 13:02:36 +0200 Subject: r8169: add basic MII ioctl support Signed-off-by: Francois Romieu --- drivers/net/r8169.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'drivers/net') diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c index 0025b8367ece..ace895b2e221 100644 --- a/drivers/net/r8169.c +++ b/drivers/net/r8169.c @@ -1475,6 +1475,32 @@ static void rtl8169_init_phy(struct net_device *dev, struct rtl8169_private *tp) printk(KERN_INFO PFX "%s: TBI auto-negotiating\n", dev->name); } +static int rtl8169_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) +{ + struct rtl8169_private *tp = netdev_priv(dev); + struct mii_ioctl_data *data = if_mii(ifr); + + if (!netif_running(dev)) + return -ENODEV; + + switch (cmd) { + case SIOCGMIIPHY: + data->phy_id = 32; /* Internal PHY */ + return 0; + + case SIOCGMIIREG: + data->val_out = mdio_read(tp->mmio_addr, data->reg_num & 0x1f); + return 0; + + case SIOCSMIIREG: + if (!capable(CAP_NET_ADMIN)) + return -EPERM; + mdio_write(tp->mmio_addr, data->reg_num & 0x1f, data->val_in); + return 0; + } + return -EOPNOTSUPP; +} + static int __devinit rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) { @@ -1639,6 +1665,8 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) tp->phy_reset_enable = rtl8169_xmii_reset_enable; tp->phy_reset_pending = rtl8169_xmii_reset_pending; tp->link_ok = rtl8169_xmii_link_ok; + + dev->do_ioctl = rtl8169_ioctl; } /* Get MAC address. FIXME: read EEPROM */ -- cgit v1.2.3 From d2eed8cff9a1a5d7e12ec9ddf71432c466b104d0 Mon Sep 17 00:00:00 2001 From: Francois Romieu Date: Thu, 31 Aug 2006 22:01:07 +0200 Subject: r8169: the 0x8136 needs a 8 bytes alignment Reported by Darren Salt. Signed-off-by: Francois Romieu --- drivers/net/r8169.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/net') diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c index ace895b2e221..93228c518ae7 100644 --- a/drivers/net/r8169.c +++ b/drivers/net/r8169.c @@ -209,7 +209,7 @@ static const struct { static struct pci_device_id rtl8169_pci_tbl[] = { { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8129), 0, 0, RTL_CFG_0 }, - { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8136), 0, 0, RTL_CFG_1 }, + { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8136), 0, 0, RTL_CFG_2 }, { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8167), 0, 0, RTL_CFG_1 }, { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8168), 0, 0, RTL_CFG_2 }, { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8169), 0, 0, RTL_CFG_0 }, -- cgit v1.2.3 From b39fe41f481d20c201012e4483e76c203802dda7 Mon Sep 17 00:00:00 2001 From: Francois Romieu Date: Mon, 11 Sep 2006 20:10:58 +0200 Subject: r8169: quirk for the 8110sb on arm platform Inverting the write ordering of the TxDescAddr{High/Low} registers suffices to trigger a sabbat of PCI errors which make the device completely dysfunctional. The issue has not been reported on a different platform. Switching from MMIO accesses to I/O ones as done in Realtek's own driver fixes (papers over ?) the bug as well but I am not thrilled to see everyone pay the I/O price for an obscure bug. This is the minimal change to handle the issue. Signed-off-by: Francois Romieu Reported-by: Lennert Buytenhek --- drivers/net/r8169.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'drivers/net') diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c index 93228c518ae7..805562b8624e 100644 --- a/drivers/net/r8169.c +++ b/drivers/net/r8169.c @@ -1904,10 +1904,15 @@ rtl8169_hw_start(struct net_device *dev) */ RTL_W16(IntrMitigate, 0x0000); - RTL_W32(TxDescStartAddrLow, ((u64) tp->TxPhyAddr & DMA_32BIT_MASK)); + /* + * Magic spell: some iop3xx ARM board needs the TxDescAddrHigh + * register to be written before TxDescAddrLow to work. + * Switching from MMIO to I/O access fixes the issue as well. + */ RTL_W32(TxDescStartAddrHigh, ((u64) tp->TxPhyAddr >> 32)); - RTL_W32(RxDescAddrLow, ((u64) tp->RxPhyAddr & DMA_32BIT_MASK)); + RTL_W32(TxDescStartAddrLow, ((u64) tp->TxPhyAddr & DMA_32BIT_MASK)); RTL_W32(RxDescAddrHigh, ((u64) tp->RxPhyAddr >> 32)); + RTL_W32(RxDescAddrLow, ((u64) tp->RxPhyAddr & DMA_32BIT_MASK)); RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); RTL_W8(Cfg9346, Cfg9346_Lock); -- cgit v1.2.3