diff options
author | François Romieu <romieu@fr.zoreil.com> | 2011-04-24 11:38:48 -0400 |
---|---|---|
committer | Francois romieu <romieu@fr.zoreil.com> | 2011-04-24 11:42:57 -0400 |
commit | 953a12cc2889d1be92e80a2d0bab5ffef4942300 (patch) | |
tree | 4ebb736e88c5629c39a23509db4955f047f0f645 /drivers | |
parent | 0b0dc0f17f98b59772ca6380c7d5ce4cc593a974 (diff) |
r8169: don't request firmware when there's no userspace.
The firmware is cached during the first successfull call to open() and
released once the network device is unregistered. The driver uses the
cached firmware between open() and unregister_netdev().
So far the firmware is optional : a failure to load the firmware does
not prevent open() to success. It is thus necessary to 1) unregister
all 816x / 810[23] devices and 2) force a driver probe to issue a new
firmware load.
Signed-off-by: Francois Romieu <romieu@fr.zoreil.com>
Fixed-by: Ciprian Docan <docan@eden.rutgers.edu>
Cc: Realtek linux nic maintainers <nic_swsd@realtek.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/net/r8169.c | 99 |
1 files changed, 71 insertions, 28 deletions
diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c index 493b0de3848b..397c36810a15 100644 --- a/drivers/net/r8169.c +++ b/drivers/net/r8169.c | |||
@@ -170,6 +170,16 @@ static const struct { | |||
170 | }; | 170 | }; |
171 | #undef _R | 171 | #undef _R |
172 | 172 | ||
173 | static const struct rtl_firmware_info { | ||
174 | int mac_version; | ||
175 | const char *fw_name; | ||
176 | } rtl_firmware_infos[] = { | ||
177 | { .mac_version = RTL_GIGA_MAC_VER_25, .fw_name = FIRMWARE_8168D_1 }, | ||
178 | { .mac_version = RTL_GIGA_MAC_VER_26, .fw_name = FIRMWARE_8168D_2 }, | ||
179 | { .mac_version = RTL_GIGA_MAC_VER_29, .fw_name = FIRMWARE_8105E_1 }, | ||
180 | { .mac_version = RTL_GIGA_MAC_VER_30, .fw_name = FIRMWARE_8105E_1 } | ||
181 | }; | ||
182 | |||
173 | enum cfg_version { | 183 | enum cfg_version { |
174 | RTL_CFG_0 = 0x00, | 184 | RTL_CFG_0 = 0x00, |
175 | RTL_CFG_1, | 185 | RTL_CFG_1, |
@@ -565,6 +575,7 @@ struct rtl8169_private { | |||
565 | u32 saved_wolopts; | 575 | u32 saved_wolopts; |
566 | 576 | ||
567 | const struct firmware *fw; | 577 | const struct firmware *fw; |
578 | #define RTL_FIRMWARE_UNKNOWN ERR_PTR(-EAGAIN); | ||
568 | }; | 579 | }; |
569 | 580 | ||
570 | MODULE_AUTHOR("Realtek and the Linux r8169 crew <netdev@vger.kernel.org>"); | 581 | MODULE_AUTHOR("Realtek and the Linux r8169 crew <netdev@vger.kernel.org>"); |
@@ -1789,25 +1800,26 @@ rtl_phy_write_fw(struct rtl8169_private *tp, const struct firmware *fw) | |||
1789 | 1800 | ||
1790 | static void rtl_release_firmware(struct rtl8169_private *tp) | 1801 | static void rtl_release_firmware(struct rtl8169_private *tp) |
1791 | { | 1802 | { |
1792 | release_firmware(tp->fw); | 1803 | if (!IS_ERR_OR_NULL(tp->fw)) |
1793 | tp->fw = NULL; | 1804 | release_firmware(tp->fw); |
1805 | tp->fw = RTL_FIRMWARE_UNKNOWN; | ||
1794 | } | 1806 | } |
1795 | 1807 | ||
1796 | static int rtl_apply_firmware(struct rtl8169_private *tp, const char *fw_name) | 1808 | static void rtl_apply_firmware(struct rtl8169_private *tp) |
1797 | { | 1809 | { |
1798 | const struct firmware **fw = &tp->fw; | 1810 | const struct firmware *fw = tp->fw; |
1799 | int rc = !*fw; | ||
1800 | |||
1801 | if (rc) { | ||
1802 | rc = request_firmware(fw, fw_name, &tp->pci_dev->dev); | ||
1803 | if (rc < 0) | ||
1804 | goto out; | ||
1805 | } | ||
1806 | 1811 | ||
1807 | /* TODO: release firmware once rtl_phy_write_fw signals failures. */ | 1812 | /* TODO: release firmware once rtl_phy_write_fw signals failures. */ |
1808 | rtl_phy_write_fw(tp, *fw); | 1813 | if (!IS_ERR_OR_NULL(fw)) |
1809 | out: | 1814 | rtl_phy_write_fw(tp, fw); |
1810 | return rc; | 1815 | } |
1816 | |||
1817 | static void rtl_apply_firmware_cond(struct rtl8169_private *tp, u8 reg, u16 val) | ||
1818 | { | ||
1819 | if (rtl_readphy(tp, reg) != val) | ||
1820 | netif_warn(tp, hw, tp->dev, "chipset not ready for firmware\n"); | ||
1821 | else | ||
1822 | rtl_apply_firmware(tp); | ||
1811 | } | 1823 | } |
1812 | 1824 | ||
1813 | static void rtl8169s_hw_phy_config(struct rtl8169_private *tp) | 1825 | static void rtl8169s_hw_phy_config(struct rtl8169_private *tp) |
@@ -2246,10 +2258,8 @@ static void rtl8168d_1_hw_phy_config(struct rtl8169_private *tp) | |||
2246 | 2258 | ||
2247 | rtl_writephy(tp, 0x1f, 0x0005); | 2259 | rtl_writephy(tp, 0x1f, 0x0005); |
2248 | rtl_writephy(tp, 0x05, 0x001b); | 2260 | rtl_writephy(tp, 0x05, 0x001b); |
2249 | if ((rtl_readphy(tp, 0x06) != 0xbf00) || | 2261 | |
2250 | (rtl_apply_firmware(tp, FIRMWARE_8168D_1) < 0)) { | 2262 | rtl_apply_firmware_cond(tp, MII_EXPANSION, 0xbf00); |
2251 | netif_warn(tp, probe, tp->dev, "unable to apply firmware patch\n"); | ||
2252 | } | ||
2253 | 2263 | ||
2254 | rtl_writephy(tp, 0x1f, 0x0000); | 2264 | rtl_writephy(tp, 0x1f, 0x0000); |
2255 | } | 2265 | } |
@@ -2351,10 +2361,8 @@ static void rtl8168d_2_hw_phy_config(struct rtl8169_private *tp) | |||
2351 | 2361 | ||
2352 | rtl_writephy(tp, 0x1f, 0x0005); | 2362 | rtl_writephy(tp, 0x1f, 0x0005); |
2353 | rtl_writephy(tp, 0x05, 0x001b); | 2363 | rtl_writephy(tp, 0x05, 0x001b); |
2354 | if ((rtl_readphy(tp, 0x06) != 0xb300) || | 2364 | |
2355 | (rtl_apply_firmware(tp, FIRMWARE_8168D_2) < 0)) { | 2365 | rtl_apply_firmware_cond(tp, MII_EXPANSION, 0xb300); |
2356 | netif_warn(tp, probe, tp->dev, "unable to apply firmware patch\n"); | ||
2357 | } | ||
2358 | 2366 | ||
2359 | rtl_writephy(tp, 0x1f, 0x0000); | 2367 | rtl_writephy(tp, 0x1f, 0x0000); |
2360 | } | 2368 | } |
@@ -2474,8 +2482,7 @@ static void rtl8105e_hw_phy_config(struct rtl8169_private *tp) | |||
2474 | rtl_writephy(tp, 0x18, 0x0310); | 2482 | rtl_writephy(tp, 0x18, 0x0310); |
2475 | msleep(100); | 2483 | msleep(100); |
2476 | 2484 | ||
2477 | if (rtl_apply_firmware(tp, FIRMWARE_8105E_1) < 0) | 2485 | rtl_apply_firmware(tp); |
2478 | netif_warn(tp, probe, tp->dev, "unable to apply firmware patch\n"); | ||
2479 | 2486 | ||
2480 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); | 2487 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
2481 | } | 2488 | } |
@@ -3237,6 +3244,8 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) | |||
3237 | tp->timer.data = (unsigned long) dev; | 3244 | tp->timer.data = (unsigned long) dev; |
3238 | tp->timer.function = rtl8169_phy_timer; | 3245 | tp->timer.function = rtl8169_phy_timer; |
3239 | 3246 | ||
3247 | tp->fw = RTL_FIRMWARE_UNKNOWN; | ||
3248 | |||
3240 | rc = register_netdev(dev); | 3249 | rc = register_netdev(dev); |
3241 | if (rc < 0) | 3250 | if (rc < 0) |
3242 | goto err_out_msi_4; | 3251 | goto err_out_msi_4; |
@@ -3288,10 +3297,10 @@ static void __devexit rtl8169_remove_one(struct pci_dev *pdev) | |||
3288 | 3297 | ||
3289 | cancel_delayed_work_sync(&tp->task); | 3298 | cancel_delayed_work_sync(&tp->task); |
3290 | 3299 | ||
3291 | rtl_release_firmware(tp); | ||
3292 | |||
3293 | unregister_netdev(dev); | 3300 | unregister_netdev(dev); |
3294 | 3301 | ||
3302 | rtl_release_firmware(tp); | ||
3303 | |||
3295 | if (pci_dev_run_wake(pdev)) | 3304 | if (pci_dev_run_wake(pdev)) |
3296 | pm_runtime_get_noresume(&pdev->dev); | 3305 | pm_runtime_get_noresume(&pdev->dev); |
3297 | 3306 | ||
@@ -3303,6 +3312,37 @@ static void __devexit rtl8169_remove_one(struct pci_dev *pdev) | |||
3303 | pci_set_drvdata(pdev, NULL); | 3312 | pci_set_drvdata(pdev, NULL); |
3304 | } | 3313 | } |
3305 | 3314 | ||
3315 | static void rtl_request_firmware(struct rtl8169_private *tp) | ||
3316 | { | ||
3317 | int i; | ||
3318 | |||
3319 | /* Return early if the firmware is already loaded / cached. */ | ||
3320 | if (!IS_ERR(tp->fw)) | ||
3321 | goto out; | ||
3322 | |||
3323 | for (i = 0; i < ARRAY_SIZE(rtl_firmware_infos); i++) { | ||
3324 | const struct rtl_firmware_info *info = rtl_firmware_infos + i; | ||
3325 | |||
3326 | if (info->mac_version == tp->mac_version) { | ||
3327 | const char *name = info->fw_name; | ||
3328 | int rc; | ||
3329 | |||
3330 | rc = request_firmware(&tp->fw, name, &tp->pci_dev->dev); | ||
3331 | if (rc < 0) { | ||
3332 | netif_warn(tp, ifup, tp->dev, "unable to load " | ||
3333 | "firmware patch %s (%d)\n", name, rc); | ||
3334 | goto out_disable_request_firmware; | ||
3335 | } | ||
3336 | goto out; | ||
3337 | } | ||
3338 | } | ||
3339 | |||
3340 | out_disable_request_firmware: | ||
3341 | tp->fw = NULL; | ||
3342 | out: | ||
3343 | return; | ||
3344 | } | ||
3345 | |||
3306 | static int rtl8169_open(struct net_device *dev) | 3346 | static int rtl8169_open(struct net_device *dev) |
3307 | { | 3347 | { |
3308 | struct rtl8169_private *tp = netdev_priv(dev); | 3348 | struct rtl8169_private *tp = netdev_priv(dev); |
@@ -3334,11 +3374,13 @@ static int rtl8169_open(struct net_device *dev) | |||
3334 | 3374 | ||
3335 | smp_mb(); | 3375 | smp_mb(); |
3336 | 3376 | ||
3377 | rtl_request_firmware(tp); | ||
3378 | |||
3337 | retval = request_irq(dev->irq, rtl8169_interrupt, | 3379 | retval = request_irq(dev->irq, rtl8169_interrupt, |
3338 | (tp->features & RTL_FEATURE_MSI) ? 0 : IRQF_SHARED, | 3380 | (tp->features & RTL_FEATURE_MSI) ? 0 : IRQF_SHARED, |
3339 | dev->name, dev); | 3381 | dev->name, dev); |
3340 | if (retval < 0) | 3382 | if (retval < 0) |
3341 | goto err_release_ring_2; | 3383 | goto err_release_fw_2; |
3342 | 3384 | ||
3343 | napi_enable(&tp->napi); | 3385 | napi_enable(&tp->napi); |
3344 | 3386 | ||
@@ -3359,7 +3401,8 @@ static int rtl8169_open(struct net_device *dev) | |||
3359 | out: | 3401 | out: |
3360 | return retval; | 3402 | return retval; |
3361 | 3403 | ||
3362 | err_release_ring_2: | 3404 | err_release_fw_2: |
3405 | rtl_release_firmware(tp); | ||
3363 | rtl8169_rx_clear(tp); | 3406 | rtl8169_rx_clear(tp); |
3364 | err_free_rx_1: | 3407 | err_free_rx_1: |
3365 | dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, | 3408 | dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, |