summaryrefslogtreecommitdiffstats
path: root/drivers/net/r8169.c
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2011-04-26 15:16:46 -0400
committerDavid S. Miller <davem@davemloft.net>2011-04-26 15:16:46 -0400
commit2bd93d7af1581d40e3c4b25242472661cb7c637a (patch)
tree43c638422d20857339d8d908d6b65ebb8045edc0 /drivers/net/r8169.c
parent64cad2ade1e6f890531a58318ca9ee013f92ef2f (diff)
parent0972ddb2373d5e127aabdcabd8305eff0242cd0b (diff)
Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6
Resolved logic conflicts causing a build failure due to drivers/net/r8169.c changes using a patch from Stephen Rothwell. Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/r8169.c')
-rw-r--r--drivers/net/r8169.c108
1 files changed, 76 insertions, 32 deletions
diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c
index fb03e6ff3716..025dedda40a0 100644
--- a/drivers/net/r8169.c
+++ b/drivers/net/r8169.c
@@ -183,6 +183,19 @@ static const struct {
183}; 183};
184#undef _R 184#undef _R
185 185
186static const struct rtl_firmware_info {
187 int mac_version;
188 const char *fw_name;
189} rtl_firmware_infos[] = {
190 { .mac_version = RTL_GIGA_MAC_VER_25, .fw_name = FIRMWARE_8168D_1 },
191 { .mac_version = RTL_GIGA_MAC_VER_26, .fw_name = FIRMWARE_8168D_2 },
192 { .mac_version = RTL_GIGA_MAC_VER_29, .fw_name = FIRMWARE_8105E_1 },
193 { .mac_version = RTL_GIGA_MAC_VER_30, .fw_name = FIRMWARE_8105E_1 },
194 { .mac_version = RTL_GIGA_MAC_VER_30, .fw_name = FIRMWARE_8105E_1 },
195 { .mac_version = RTL_GIGA_MAC_VER_31, .fw_name = FIRMWARE_8168E_1 },
196 { .mac_version = RTL_GIGA_MAC_VER_32, .fw_name = FIRMWARE_8168E_2 }
197};
198
186enum cfg_version { 199enum cfg_version {
187 RTL_CFG_0 = 0x00, 200 RTL_CFG_0 = 0x00,
188 RTL_CFG_1, 201 RTL_CFG_1,
@@ -632,6 +645,7 @@ struct rtl8169_private {
632 u32 saved_wolopts; 645 u32 saved_wolopts;
633 646
634 const struct firmware *fw; 647 const struct firmware *fw;
648#define RTL_FIRMWARE_UNKNOWN ERR_PTR(-EAGAIN);
635}; 649};
636 650
637MODULE_AUTHOR("Realtek and the Linux r8169 crew <netdev@vger.kernel.org>"); 651MODULE_AUTHOR("Realtek and the Linux r8169 crew <netdev@vger.kernel.org>");
@@ -1847,25 +1861,26 @@ rtl_phy_write_fw(struct rtl8169_private *tp, const struct firmware *fw)
1847 1861
1848static void rtl_release_firmware(struct rtl8169_private *tp) 1862static void rtl_release_firmware(struct rtl8169_private *tp)
1849{ 1863{
1850 release_firmware(tp->fw); 1864 if (!IS_ERR_OR_NULL(tp->fw))
1851 tp->fw = NULL; 1865 release_firmware(tp->fw);
1866 tp->fw = RTL_FIRMWARE_UNKNOWN;
1852} 1867}
1853 1868
1854static int rtl_apply_firmware(struct rtl8169_private *tp, const char *fw_name) 1869static void rtl_apply_firmware(struct rtl8169_private *tp)
1855{ 1870{
1856 const struct firmware **fw = &tp->fw; 1871 const struct firmware *fw = tp->fw;
1857 int rc = !*fw;
1858
1859 if (rc) {
1860 rc = request_firmware(fw, fw_name, &tp->pci_dev->dev);
1861 if (rc < 0)
1862 goto out;
1863 }
1864 1872
1865 /* TODO: release firmware once rtl_phy_write_fw signals failures. */ 1873 /* TODO: release firmware once rtl_phy_write_fw signals failures. */
1866 rtl_phy_write_fw(tp, *fw); 1874 if (!IS_ERR_OR_NULL(fw))
1867out: 1875 rtl_phy_write_fw(tp, fw);
1868 return rc; 1876}
1877
1878static void rtl_apply_firmware_cond(struct rtl8169_private *tp, u8 reg, u16 val)
1879{
1880 if (rtl_readphy(tp, reg) != val)
1881 netif_warn(tp, hw, tp->dev, "chipset not ready for firmware\n");
1882 else
1883 rtl_apply_firmware(tp);
1869} 1884}
1870 1885
1871static void rtl8169s_hw_phy_config(struct rtl8169_private *tp) 1886static void rtl8169s_hw_phy_config(struct rtl8169_private *tp)
@@ -2304,10 +2319,8 @@ static void rtl8168d_1_hw_phy_config(struct rtl8169_private *tp)
2304 2319
2305 rtl_writephy(tp, 0x1f, 0x0005); 2320 rtl_writephy(tp, 0x1f, 0x0005);
2306 rtl_writephy(tp, 0x05, 0x001b); 2321 rtl_writephy(tp, 0x05, 0x001b);
2307 if ((rtl_readphy(tp, 0x06) != 0xbf00) || 2322
2308 (rtl_apply_firmware(tp, FIRMWARE_8168D_1) < 0)) { 2323 rtl_apply_firmware_cond(tp, MII_EXPANSION, 0xbf00);
2309 netif_warn(tp, probe, tp->dev, "unable to apply firmware patch\n");
2310 }
2311 2324
2312 rtl_writephy(tp, 0x1f, 0x0000); 2325 rtl_writephy(tp, 0x1f, 0x0000);
2313} 2326}
@@ -2409,10 +2422,8 @@ static void rtl8168d_2_hw_phy_config(struct rtl8169_private *tp)
2409 2422
2410 rtl_writephy(tp, 0x1f, 0x0005); 2423 rtl_writephy(tp, 0x1f, 0x0005);
2411 rtl_writephy(tp, 0x05, 0x001b); 2424 rtl_writephy(tp, 0x05, 0x001b);
2412 if ((rtl_readphy(tp, 0x06) != 0xb300) || 2425
2413 (rtl_apply_firmware(tp, FIRMWARE_8168D_2) < 0)) { 2426 rtl_apply_firmware_cond(tp, MII_EXPANSION, 0xb300);
2414 netif_warn(tp, probe, tp->dev, "unable to apply firmware patch\n");
2415 }
2416 2427
2417 rtl_writephy(tp, 0x1f, 0x0000); 2428 rtl_writephy(tp, 0x1f, 0x0000);
2418} 2429}
@@ -2567,16 +2578,14 @@ static void rtl8168e_hw_phy_config(struct rtl8169_private *tp)
2567 2578
2568static void rtl8168e_1_hw_phy_config(struct rtl8169_private *tp) 2579static void rtl8168e_1_hw_phy_config(struct rtl8169_private *tp)
2569{ 2580{
2570 if (rtl_apply_firmware(tp, FIRMWARE_8168E_1) < 0) 2581 rtl_apply_firmware(tp);
2571 netif_warn(tp, probe, tp->dev, "unable to apply firmware patch\n");
2572 2582
2573 rtl8168e_hw_phy_config(tp); 2583 rtl8168e_hw_phy_config(tp);
2574} 2584}
2575 2585
2576static void rtl8168e_2_hw_phy_config(struct rtl8169_private *tp) 2586static void rtl8168e_2_hw_phy_config(struct rtl8169_private *tp)
2577{ 2587{
2578 if (rtl_apply_firmware(tp, FIRMWARE_8168E_2) < 0) 2588 rtl_apply_firmware(tp);
2579 netif_warn(tp, probe, tp->dev, "unable to apply firmware patch\n");
2580 2589
2581 rtl8168e_hw_phy_config(tp); 2590 rtl8168e_hw_phy_config(tp);
2582} 2591}
@@ -2619,8 +2628,7 @@ static void rtl8105e_hw_phy_config(struct rtl8169_private *tp)
2619 rtl_writephy(tp, 0x18, 0x0310); 2628 rtl_writephy(tp, 0x18, 0x0310);
2620 msleep(100); 2629 msleep(100);
2621 2630
2622 if (rtl_apply_firmware(tp, FIRMWARE_8105E_1) < 0) 2631 rtl_apply_firmware(tp);
2623 netif_warn(tp, probe, tp->dev, "unable to apply firmware patch\n");
2624 2632
2625 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); 2633 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init));
2626} 2634}
@@ -3463,6 +3471,8 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
3463 tp->timer.data = (unsigned long) dev; 3471 tp->timer.data = (unsigned long) dev;
3464 tp->timer.function = rtl8169_phy_timer; 3472 tp->timer.function = rtl8169_phy_timer;
3465 3473
3474 tp->fw = RTL_FIRMWARE_UNKNOWN;
3475
3466 rc = register_netdev(dev); 3476 rc = register_netdev(dev);
3467 if (rc < 0) 3477 if (rc < 0)
3468 goto err_out_msi_4; 3478 goto err_out_msi_4;
@@ -3515,10 +3525,10 @@ static void __devexit rtl8169_remove_one(struct pci_dev *pdev)
3515 3525
3516 cancel_delayed_work_sync(&tp->task); 3526 cancel_delayed_work_sync(&tp->task);
3517 3527
3518 rtl_release_firmware(tp);
3519
3520 unregister_netdev(dev); 3528 unregister_netdev(dev);
3521 3529
3530 rtl_release_firmware(tp);
3531
3522 if (pci_dev_run_wake(pdev)) 3532 if (pci_dev_run_wake(pdev))
3523 pm_runtime_get_noresume(&pdev->dev); 3533 pm_runtime_get_noresume(&pdev->dev);
3524 3534
@@ -3530,6 +3540,37 @@ static void __devexit rtl8169_remove_one(struct pci_dev *pdev)
3530 pci_set_drvdata(pdev, NULL); 3540 pci_set_drvdata(pdev, NULL);
3531} 3541}
3532 3542
3543static void rtl_request_firmware(struct rtl8169_private *tp)
3544{
3545 int i;
3546
3547 /* Return early if the firmware is already loaded / cached. */
3548 if (!IS_ERR(tp->fw))
3549 goto out;
3550
3551 for (i = 0; i < ARRAY_SIZE(rtl_firmware_infos); i++) {
3552 const struct rtl_firmware_info *info = rtl_firmware_infos + i;
3553
3554 if (info->mac_version == tp->mac_version) {
3555 const char *name = info->fw_name;
3556 int rc;
3557
3558 rc = request_firmware(&tp->fw, name, &tp->pci_dev->dev);
3559 if (rc < 0) {
3560 netif_warn(tp, ifup, tp->dev, "unable to load "
3561 "firmware patch %s (%d)\n", name, rc);
3562 goto out_disable_request_firmware;
3563 }
3564 goto out;
3565 }
3566 }
3567
3568out_disable_request_firmware:
3569 tp->fw = NULL;
3570out:
3571 return;
3572}
3573
3533static int rtl8169_open(struct net_device *dev) 3574static int rtl8169_open(struct net_device *dev)
3534{ 3575{
3535 struct rtl8169_private *tp = netdev_priv(dev); 3576 struct rtl8169_private *tp = netdev_priv(dev);
@@ -3561,11 +3602,13 @@ static int rtl8169_open(struct net_device *dev)
3561 3602
3562 smp_mb(); 3603 smp_mb();
3563 3604
3605 rtl_request_firmware(tp);
3606
3564 retval = request_irq(dev->irq, rtl8169_interrupt, 3607 retval = request_irq(dev->irq, rtl8169_interrupt,
3565 (tp->features & RTL_FEATURE_MSI) ? 0 : IRQF_SHARED, 3608 (tp->features & RTL_FEATURE_MSI) ? 0 : IRQF_SHARED,
3566 dev->name, dev); 3609 dev->name, dev);
3567 if (retval < 0) 3610 if (retval < 0)
3568 goto err_release_ring_2; 3611 goto err_release_fw_2;
3569 3612
3570 napi_enable(&tp->napi); 3613 napi_enable(&tp->napi);
3571 3614
@@ -3586,7 +3629,8 @@ static int rtl8169_open(struct net_device *dev)
3586out: 3629out:
3587 return retval; 3630 return retval;
3588 3631
3589err_release_ring_2: 3632err_release_fw_2:
3633 rtl_release_firmware(tp);
3590 rtl8169_rx_clear(tp); 3634 rtl8169_rx_clear(tp);
3591err_free_rx_1: 3635err_free_rx_1:
3592 dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, 3636 dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray,