diff mbox

Suspend/resume - slow resume

Message ID 20110420181602.GA18740@electric-eye.fr.zoreil.com
State RFC, archived
Delegated to: David Miller
Headers show

Commit Message

Francois Romieu April 20, 2011, 6:16 p.m. UTC
Linus Torvalds <torvalds@linux-foundation.org> :
[...]
> Francois' patch is fine and improves on things, I only had a few
> arguments with it. The problems I think it had were really about some
> rather special cases.

They may be addressed by the patch below.

I'll test it as soon as my 2.6.39-rc stops softlocking and I have a
working suspend / resume. No joke.

Subject: [PATCH] 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>
---
 drivers/net/r8169.c |   92 ++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 65 insertions(+), 27 deletions(-)

Comments

Ciprian Docan April 20, 2011, 6:51 p.m. UTC | #1
Hello Francois,

I tried your patch and my machine resumes properly.

> 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().

Here is what I did to test it: I compiled the patched module, unloaded the 
previous module, loaded the new one, and then suspend & resume. Output of 
dmesg attached. Please let me know if you need any other information.

Regards,
--
 	Ciprian
[74001.664088] r8169 0000:02:00.0: PCI INT A disabled
[74033.821473] r8169 Gigabit Ethernet driver 2.3LK-NAPI loaded
[74033.821497] r8169 0000:02:00.0: PCI INT A -> GSI 16 (level, low) -> IRQ 16
[74033.822310] r8169 0000:02:00.0: setting latency timer to 64
[74033.822364] r8169 0000:02:00.0: irq 45 for MSI/MSI-X
[74033.822572] r8169 0000:02:00.0: eth0: RTL8168d/8111d at 0xffffc90027e2e000, 64:31:50:69:2c:61, XID 083000c0 IRQ 45
[74058.429717] wl_ops_bss_info_changed: qos enabled: false (implement)
[74058.429729] brcmsmac: wl_ops_bss_info_changed: disassociated
[74058.429735] wl_ops_bss_info_changed: use_cts_prot: false (implement)
[74058.429741] wl_ops_bss_info_changed: short preamble: false (implement)
[74058.429754] wl_ops_bss_info_changed: arp filtering: enabled false, count 1 (implement)
[74058.429764] wlan0: deauthenticating from 00:1e:2a:01:3e:bb by local choice (reason=3)
[74058.455026] wl_ops_bss_info_changed: BSS idle: true (implement)
[74058.455046] cfg80211: All devices are disconnected, going to restore regulatory settings
[74058.455055] cfg80211: Restoring regulatory settings
[74058.455064] cfg80211: Calling CRDA to update world regulatory domain
[74058.455069] wl_ops_bss_info_changed: BSS idle: false (implement)
[74058.460281] cfg80211: Updating information on frequency 2412 MHz for a 20 MHz width channel with regulatory rule:
[74058.460291] cfg80211: 2402000 KHz - 2472000 KHz @  KHz), (300 mBi, 2700 mBm)
[74058.460297] cfg80211: Updating information on frequency 2417 MHz for a 20 MHz width channel with regulatory rule:
[74058.460305] cfg80211: 2402000 KHz - 2472000 KHz @  KHz), (300 mBi, 2700 mBm)
[74058.460311] cfg80211: Updating information on frequency 2422 MHz for a 20 MHz width channel with regulatory rule:
[74058.460319] cfg80211: 2402000 KHz - 2472000 KHz @  KHz), (300 mBi, 2700 mBm)
[74058.460325] cfg80211: Updating information on frequency 2427 MHz for a 20 MHz width channel with regulatory rule:
[74058.460330] cfg80211: 2402000 KHz - 2472000 KHz @  KHz), (300 mBi, 2700 mBm)
[74058.460334] cfg80211: Updating information on frequency 2432 MHz for a 20 MHz width channel with regulatory rule:
[74058.460339] cfg80211: 2402000 KHz - 2472000 KHz @  KHz), (300 mBi, 2700 mBm)
[74058.460344] cfg80211: Updating information on frequency 2437 MHz for a 20 MHz width channel with regulatory rule:
[74058.460349] cfg80211: 2402000 KHz - 2472000 KHz @  KHz), (300 mBi, 2700 mBm)
[74058.460353] cfg80211: Updating information on frequency 2442 MHz for a 20 MHz width channel with regulatory rule:
[74058.460358] cfg80211: 2402000 KHz - 2472000 KHz @  KHz), (300 mBi, 2700 mBm)
[74058.460363] cfg80211: Updating information on frequency 2447 MHz for a 20 MHz width channel with regulatory rule:
[74058.460368] cfg80211: 2402000 KHz - 2472000 KHz @  KHz), (300 mBi, 2700 mBm)
[74058.460372] cfg80211: Updating information on frequency 2452 MHz for a 20 MHz width channel with regulatory rule:
[74058.460377] cfg80211: 2402000 KHz - 2472000 KHz @  KHz), (300 mBi, 2700 mBm)
[74058.460382] cfg80211: Updating information on frequency 2457 MHz for a 20 MHz width channel with regulatory rule:
[74058.460387] cfg80211: 2402000 KHz - 2472000 KHz @  KHz), (300 mBi, 2700 mBm)
[74058.460391] cfg80211: Updating information on frequency 2462 MHz for a 20 MHz width channel with regulatory rule:
[74058.460396] cfg80211: 2402000 KHz - 2472000 KHz @  KHz), (300 mBi, 2700 mBm)
[74058.460400] cfg80211: Disabling freq 2467 MHz
[74058.460403] cfg80211: Disabling freq 2472 MHz
[74058.460405] cfg80211: Disabling freq 2484 MHz
[74058.460410] cfg80211: World regulatory domain updated:
[74058.460413] cfg80211:     (start_freq - end_freq @ bandwidth), (max_antenna_gain, max_eirp)
[74058.460418] cfg80211:     (2402000 KHz - 2472000 KHz @ 40000 KHz), (300 mBi, 2000 mBm)
[74058.460423] cfg80211:     (2457000 KHz - 2482000 KHz @ 20000 KHz), (300 mBi, 2000 mBm)
[74058.460427] cfg80211:     (2474000 KHz - 2494000 KHz @ 20000 KHz), (300 mBi, 2000 mBm)
[74058.460432] cfg80211:     (5170000 KHz - 5250000 KHz @ 40000 KHz), (300 mBi, 2000 mBm)
[74058.460437] cfg80211:     (5735000 KHz - 5835000 KHz @ 40000 KHz), (300 mBi, 2000 mBm)
[74058.464926] wl_ops_bss_info_changed: BSS idle: true (implement)
[74059.892010] PM: Syncing filesystems ... done.
[74059.909543] PM: Preparing system for mem sleep
[74060.072757] Freezing user space processes ... (elapsed 0.01 seconds) done.
[74060.084607] Freezing remaining freezable tasks ... (elapsed 0.01 seconds) done.
[74060.095548] PM: Entering mem sleep
[74060.095712] Suspending console(s) (use no_console_suspend to debug)
[74060.107943] sd 0:0:0:0: [sda] Synchronizing SCSI cache
[74060.108024] sd 0:0:0:0: [sda] Stopping disk
[74060.147028] HDA Intel 0000:01:00.1: PCI INT B disabled
[74060.147031] brcmsmac 0000:03:00.0: PCI INT A disabled
[74060.147064] ACPI handle has no context!
[74060.157421] ehci_hcd 0000:00:1d.0: PCI INT A disabled
[74060.157444] ehci_hcd 0000:00:1a.0: PCI INT A disabled
[74060.248878] HDA Intel 0000:00:1b.0: PCI INT A disabled
[74062.612741] PM: suspend of devices complete after 2512.037 msecs
[74062.612949] r8169 0000:02:00.0: PME# enabled
[74062.621666] r8169 0000:02:00.0: wake-up capability enabled by ACPI
[74062.654658] PM: late suspend of devices complete after 42.007 msecs
[74062.654817] ACPI: Preparing to enter system sleep state S3
[74062.700627] PM: Saving platform NVS memory
[74062.704367] Disabling non-boot CPUs ...
[74062.706846] CPU 1 is now offline
[74062.724771] CPU 2 is now offline
[74062.734603] CPU 3 is now offline
[74062.734969] Extended CMOS year: 2000
[74062.735165] ACPI: Low-level resume complete
[74062.735220] PM: Restoring platform NVS memory
[74062.735780] Extended CMOS year: 2000
[74062.735802] Enabling non-boot CPUs ...
[74062.735923] Booting Node 0 Processor 1 APIC 0x1
[74062.735924] smpboot cpu 1: start_ip = 98000
[74062.826473] CPU1 is up
[74062.826637] Booting Node 0 Processor 2 APIC 0x4
[74062.826641] smpboot cpu 2: start_ip = 98000
[74062.826826] Switched to NOHz mode on CPU #1
[74062.917217] CPU2 is up
[74062.917382] Booting Node 0 Processor 3 APIC 0x5
[74062.917386] smpboot cpu 3: start_ip = 98000
[74062.917580] Switched to NOHz mode on CPU #2
[74063.008091] CPU3 is up
[74063.009302] Switched to NOHz mode on CPU #3
[74063.009672] ACPI: Waking up from system sleep state S3
[74063.090894] pcieport 0000:00:01.0: restoring config space at offset 0x1 (was 0x100007, writing 0x100407)
[74063.090915] i915 0000:00:02.0: restoring config space at offset 0x1 (was 0x900007, writing 0x900407)
[74063.090974] ehci_hcd 0000:00:1a.0: restoring config space at offset 0x1 (was 0x2900006, writing 0x2900002)
[74063.091009] HDA Intel 0000:00:1b.0: restoring config space at offset 0x1 (was 0x100006, writing 0x100002)
[74063.091117] ehci_hcd 0000:00:1d.0: restoring config space at offset 0x1 (was 0x2900006, writing 0x2900002)
[74063.091140] pci 0000:00:1e.0: restoring config space at offset 0xa (was 0xffffffff, writing 0x0)
[74063.091213] ahci 0000:00:1f.2: restoring config space at offset 0x1 (was 0x2b00007, writing 0x2b00407)
[74063.091336] HDA Intel 0000:01:00.1: restoring config space at offset 0x1 (was 0x100007, writing 0x100003)
[74063.091389] r8169 0000:02:00.0: restoring config space at offset 0x1 (was 0x100007, writing 0x100407)
[74063.091477] brcmsmac 0000:03:00.0: restoring config space at offset 0xf (was 0x100, writing 0x10a)
[74063.091496] brcmsmac 0000:03:00.0: restoring config space at offset 0x4 (was 0x4, writing 0xc2400004)
[74063.091502] brcmsmac 0000:03:00.0: restoring config space at offset 0x3 (was 0x0, writing 0x10)
[74063.091508] brcmsmac 0000:03:00.0: restoring config space at offset 0x1 (was 0x100000, writing 0x100006)
[74063.091655] PM: early resume of devices complete after 0.826 msecs
[74063.091803] i915 0000:00:02.0: setting latency timer to 64
[74063.091883] HDA Intel 0000:01:00.1: PCI INT B -> GSI 17 (level, low) -> IRQ 17
[74063.091888] ehci_hcd 0000:00:1a.0: PCI INT A -> GSI 16 (level, low) -> IRQ 16
[74063.091890] HDA Intel 0000:01:00.1: setting latency timer to 64
[74063.091895] ehci_hcd 0000:00:1a.0: setting latency timer to 64
[74063.091938] HDA Intel 0000:01:00.1: irq 46 for MSI/MSI-X
[74063.091945] HDA Intel 0000:00:1b.0: PCI INT A -> GSI 22 (level, low) -> IRQ 22
[74063.091953] HDA Intel 0000:00:1b.0: setting latency timer to 64
[74063.091987] HDA Intel 0000:00:1b.0: irq 47 for MSI/MSI-X
[74063.091990] ehci_hcd 0000:00:1d.0: PCI INT A -> GSI 20 (level, low) -> IRQ 20
[74063.091996] ehci_hcd 0000:00:1d.0: setting latency timer to 64
[74063.092023] pci 0000:00:1e.0: setting latency timer to 64
[74063.092088] ahci 0000:00:1f.2: setting latency timer to 64
[74063.092096] brcmsmac 0000:03:00.0: PCI INT A -> GSI 17 (level, low) -> IRQ 17
[74063.092107] brcmsmac 0000:03:00.0: setting latency timer to 64
[74063.102150] sd 0:0:0:0: [sda] Starting disk
[74063.105668] r8169 0000:02:00.0: wake-up capability disabled by ACPI
[74063.105674] r8169 0000:02:00.0: PME# disabled
[74063.322691] usb 1-1.4: reset full speed USB device number 3 using ehci_hcd
[74063.406321] ata2: SATA link up 1.5 Gbps (SStatus 113 SControl 300)
[74063.410296] ata5: SATA link down (SStatus 0 SControl 300)
[74063.440225] ata2.00: configured for UDMA/100
[74063.480281] usb 2-1.3: reset full speed USB device number 3 using ehci_hcd
[74063.566915] btusb 2-1.3:1.0: no reset_resume for driver btusb?
[74063.566921] btusb 2-1.3:1.1: no reset_resume for driver btusb?
[74063.637853] usb 2-1.6: reset high speed USB device number 5 using ehci_hcd
[74064.566218] hci_cmd_timer: hci0 command tx timeout
[74065.849747] ata1: SATA link up 3.0 Gbps (SStatus 123 SControl 300)
[74065.861688] ata1.00: configured for UDMA/133
[74066.466771] PM: resume of devices complete after 3384.208 msecs
[74066.467065] PM: Finishing wakeup.
[74066.467067] Restarting tasks ... done.
[74066.475211] video LNXVIDEO:00: Restoring backlight state
[74066.475339] video LNXVIDEO:01: Restoring backlight state
[74066.740330] wl_ops_bss_info_changed: use_cts_prot: false (implement)
[74066.740334] wl_ops_bss_info_changed: short preamble: false (implement)
[74066.740349] wl_ops_config: change monitor mode: false (implement)
[74066.740350] wl_ops_config: change power-save mode: false (implement)
[74066.742592] wl_ops_bss_info_changed: qos enabled: false (implement)
[74066.743416] wl_ops_bss_info_changed: BSS idle: false (implement)
[74066.743435] ADDRCONF(NETDEV_UP): wlan0: link is not ready
[74066.833025] wl_ops_bss_info_changed: BSS idle: true (implement)
[74066.833049] wl_ops_bss_info_changed: BSS idle: false (implement)
[74066.922738] wl_ops_bss_info_changed: BSS idle: true (implement)
[74067.470305] hci_cmd_timer: hci0 command tx timeout
[74071.913773] wl_ops_bss_info_changed: BSS idle: false (implement)
[74072.813906] wl_ops_bss_info_changed: BSS idle: true (implement)
[74072.813930] wl_ops_bss_info_changed: BSS idle: false (implement)
[74072.813990] wlan0: deauthenticating from 00:1e:2a:00:2d:fe by local choice (reason=3)
[74072.903591] wlan0: authenticate with 00:1e:2a:00:2d:fe (try 1)
[74072.913250] wlan0: authenticated
[74072.913271] wl_ops_bss_info_changed: BSS idle: true (implement)
[74072.913304] wl_ops_bss_info_changed: BSS idle: false (implement)
[74072.913312] wlan0: associate with 00:1e:2a:00:2d:fe (try 1)
[74072.916142] wlan0: RX AssocResp from 00:1e:2a:00:2d:fe (capab=0x411 status=0 aid=1)
[74072.916147] wlan0: associated
[74072.917091] wl_ops_bss_info_changed: qos enabled: true (implement)
[74072.917096] brcmsmac: wl_ops_bss_info_changed: associated
[74072.917100] wl_ops_bss_info_changed: use_cts_prot: true (implement)
[74072.917103] wl_ops_bss_info_changed: short preamble: true (implement)
[74072.917111] wl_ops_bss_info_changed: Need to change Basic Rates: 0xf (implement)
[74072.917118] wl_ops_bss_info_changed: arp filtering: enabled true, count 0 (implement)
[74072.918403] ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready
[74073.806196] wl_ops_bss_info_changed: arp filtering: enabled true, count 1 (implement)
Ciprian Docan April 20, 2011, 7:10 p.m. UTC | #2
Hello Francois,

I tried to unload the module, but it crashed. I re-booted the machine and 
tried to unload the module again. I got the output from dmesg; please see 
attached.

Regards,
--
 	Ciprian
[    7.007361] r8169 Gigabit Ethernet driver 2.3LK-NAPI loaded
[    7.007383] r8169 0000:02:00.0: PCI INT A -> GSI 16 (level, low) -> IRQ 16
[    7.007454] r8169 0000:02:00.0: setting latency timer to 64
[    7.007506] r8169 0000:02:00.0: irq 45 for MSI/MSI-X
[    7.007628] r8169 0000:02:00.0: eth0: RTL8168d/8111d at 0xffffc90011810000, 64:31:50:69:2c:61, XID 083000c0 IRQ 45

...

[  109.216074] r8169 0000:02:00.0: PCI INT A disabled
[  116.748813] EXT4-fs (dm-1): mounted filesystem with ordered data mode. Opts: (null)
[  166.963998] r8169 Gigabit Ethernet driver 2.3LK-NAPI loaded
[  166.964100] r8169 0000:02:00.0: PCI INT A -> GSI 16 (level, low) -> IRQ 16
[  166.964319] r8169 0000:02:00.0: setting latency timer to 64
[  166.964379] r8169 0000:02:00.0: irq 45 for MSI/MSI-X
[  166.964593] r8169 0000:02:00.0: eth0: RTL8168d/8111d at 0xffffc90022fc4000, 64:31:50:69:2c:61, XID 083000c0 IRQ 45
[  174.917306] BUG: unable to handle kernel paging request at fffffffffffffffd
[  174.919573] IP: [<ffffffff8127b267>] firmware_free_data+0xf/0x55
[  174.921828] PGD 1605067 PUD 1606067 PMD 0 
[  174.924088] Oops: 0000 [#1] SMP 
[  174.926323] last sysfs file: /sys/devices/pci0000:00/0000:00:1c.1/0000:03:00.0/ieee80211/phy0/rfkill0/uevent
[  174.928649] CPU 2 
[  174.928670] Modules linked in: r8169(-) aes_x86_64 aes_generic fuse hidp fbcon tileblit font bitblit softcursor rfcomm bnep acpi_cpufreq mperf ip6t_REJECT nf_conntrack_ipv6 nf_defrag_ipv6 ip6table_filter ip6_tables ipv6 snd_hda_codec_hdmi snd_hda_codec_idt snd_hda_intel snd_hda_codec snd_hwdep snd_seq snd_seq_device snd_pcm arc4 snd_timer snd soundcore ecb btusb processor thermal uvcvideo hp_wmi psmouse fan videodev i2c_i801 sparse_keymap snd_page_alloc pcspkr brcmsmac(C) hp_accel iTCO_wdt mac80211 iTCO_vendor_support bluetooth lis3lv02d mii input_polldev serio_raw wmi v4l2_compat_ioctl32 cfg80211 rfkill microcode i915 drm_kms_helper drm fb fbdev intel_agp i2c_algo_bit cfbcopyarea intel_gtt agpgart i2c_core video cfbimgblt cfbfillrect [last unloaded: r8169]
[  174.944284] 
[  174.946871] Pid: 2003, comm: rmmod Tainted: G         C  2.6.39-rc3+ #13 Hewlett-Packard HP Pavilion dm4 Notebook PC     /1603
[  174.949618] RIP: 0010:[<ffffffff8127b267>]  [<ffffffff8127b267>] firmware_free_data+0xf/0x55
[  174.952348] RSP: 0018:ffff88023ad45d48  EFLAGS: 00010246
[  174.954988] RAX: ffffffff815be000 RBX: fffffffffffffff5 RCX: ffff88024b1c0398
[  174.957707] RDX: 0000000000000000 RSI: 0000000000000037 RDI: fffffffffffffff5
[  174.960417] RBP: ffff88023ad45d58 R08: 0000000000000100 R09: ffffffff8172f690
[  174.963039] R10: 000000000000000f R11: ffff88024b1c0000 R12: ffff88024f790000
[  174.965662] R13: ffff88024b1c0000 R14: ffff88024f790090 R15: 0000000000000001
[  174.968194] FS:  00007faaa8774720(0000) GS:ffff88025bc80000(0000) knlGS:0000000000000000
[  174.970806] CS:  0010 DS: 0000 ES: 0000 CR0: 000000008005003b
[  174.973388] CR2: fffffffffffffffd CR3: 000000024b828000 CR4: 00000000000006e0
[  174.973392] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
[  174.973396] DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400
[  174.973400] Process rmmod (pid: 2003, threadinfo ffff88023ad44000, task ffff88023adb8000)
[  174.973403] Stack:
[  174.973405]  fffffffffffffff5 ffff88024f790000 ffff88023ad45d78 ffffffff8127b2f6
[  174.973410]  ffff88023ad45d78 ffff88024b1c0740 ffff88023ad45db8 ffffffffa046e21e
[  174.973415]  ffff88024f7900f0 ffff88024f790090 ffffffffa0470030 ffff88024f790000
[  174.973420] Call Trace:
[  174.973427]  [<ffffffff8127b2f6>] release_firmware+0x49/0x4f
[  174.973437]  [<ffffffffa046e21e>] rtl8169_remove_one+0x8f/0x118 [r8169]
[  174.973446]  [<ffffffff8120435c>] pci_device_remove+0x3f/0x91
[  174.973453]  [<ffffffff8127209c>] __device_release_driver+0x83/0xd9
[  174.973458]  [<ffffffff8127278c>] driver_detach+0x86/0xae
[  174.973464]  [<ffffffff81271f4e>] bus_remove_driver+0xb9/0xdf
[  174.973469]  [<ffffffff81272af7>] driver_unregister+0x6c/0x74
[  174.973474]  [<ffffffff8120463a>] pci_unregister_driver+0x44/0x89
[  174.973482]  [<ffffffffa046e2bc>] rtl8169_cleanup_module+0x15/0x17 [r8169]
[  174.973491]  [<ffffffff8106e474>] sys_delete_module+0x1ca/0x23b
[  174.973498]  [<ffffffff81109445>] ? path_put+0x22/0x27
[  174.973505]  [<ffffffff813d43eb>] system_call_fastpath+0x16/0x1b
[  174.973508] Code: c4 18 5b 41 5c 41 5d 41 5e 41 5f c9 c3 4c 89 e7 e8 4d 8d e7 ff b8 f2 ff ff ff eb e2 55 48 89 e5 41 54 53 0f 1f 44 00 00 48 89 fb 
[  174.973529]  8b 7f 08 e8 e5 79 e6 ff 48 83 7b 10 00 74 31 45 31 e4 eb 0e 
[  174.973539] RIP  [<ffffffff8127b267>] firmware_free_data+0xf/0x55
[  174.973545]  RSP <ffff88023ad45d48>
[  174.973547] CR2: fffffffffffffffd
[  174.973551] ---[ end trace 4aa4e169865c5c0c ]---
[  174.973557] BUG: sleeping function called from invalid context at kernel/rwsem.c:21
[  174.973561] in_atomic(): 0, irqs_disabled(): 1, pid: 2003, name: rmmod
[  174.973565] Pid: 2003, comm: rmmod Tainted: G      D  C  2.6.39-rc3+ #13
[  174.973569] Call Trace:
[  174.973576]  [<ffffffff8102dd7b>] __might_sleep+0xeb/0xf0
[  174.973583]  [<ffffffff813cd632>] down_read+0x24/0x3b
[  174.973589]  [<ffffffff810768f9>] acct_collect+0x4d/0x181
[  174.973595]  [<ffffffff81041ccd>] do_exit+0x22d/0x70a
[  174.973600]  [<ffffffff813cde9a>] ? _raw_spin_lock_irqsave+0x12/0x2f
[  174.973605]  [<ffffffff8103fc36>] ? kmsg_dump+0x49/0xdb
[  174.973610]  [<ffffffff813ceeea>] oops_end+0xb7/0xbf
[  174.973616]  [<ffffffff81022b3b>] no_context+0x1f9/0x208
[  174.973620]  [<ffffffff813cc815>] ? schedule+0x664/0x67e
[  174.973626]  [<ffffffff81022cd2>] __bad_area_nosemaphore+0x188/0x1ab
[  174.973631]  [<ffffffff81022d08>] bad_area_nosemaphore+0x13/0x15
[  174.973636]  [<ffffffff813d0d9d>] do_page_fault+0x16f/0x342
[  174.973643]  [<ffffffff8101c67b>] ? flat_send_IPI_allbutself+0x73/0x7e
[  174.973649]  [<ffffffff81018300>] ? native_send_call_func_ipi+0x76/0x96
[  174.973655]  [<ffffffff8106b119>] ? smp_call_function_many+0x1de/0x1ed
[  174.973661]  [<ffffffff813ce49f>] page_fault+0x1f/0x30
[  174.973667]  [<ffffffff8127b267>] ? firmware_free_data+0xf/0x55
[  174.973672]  [<ffffffff8127b2f6>] release_firmware+0x49/0x4f
[  174.973679]  [<ffffffffa046e21e>] rtl8169_remove_one+0x8f/0x118 [r8169]
[  174.973685]  [<ffffffff8120435c>] pci_device_remove+0x3f/0x91
[  174.973691]  [<ffffffff8127209c>] __device_release_driver+0x83/0xd9
[  174.973696]  [<ffffffff8127278c>] driver_detach+0x86/0xae
[  174.973701]  [<ffffffff81271f4e>] bus_remove_driver+0xb9/0xdf
[  174.973706]  [<ffffffff81272af7>] driver_unregister+0x6c/0x74
[  174.973711]  [<ffffffff8120463a>] pci_unregister_driver+0x44/0x89
[  174.973719]  [<ffffffffa046e2bc>] rtl8169_cleanup_module+0x15/0x17 [r8169]
[  174.973724]  [<ffffffff8106e474>] sys_delete_module+0x1ca/0x23b
[  174.973729]  [<ffffffff81109445>] ? path_put+0x22/0x27
[  174.973735]  [<ffffffff813d43eb>] system_call_fastpath+0x16/0x1b
Francois Romieu April 20, 2011, 7:52 p.m. UTC | #3
Ciprian Docan <docan@eden.rutgers.edu> :
[...]
> Here is what I did to test it: I compiled the patched module,
> unloaded the previous module, loaded the new one, and then suspend &
> resume. Output of dmesg attached. Please let me know if you need any
> other information.

Thanks.

You can remove the firmware and try the same test.

Then you try again with a non-modular r8169 driver, with and without
firmware.

You should see a few extra messages but suffer no extra delay during
resume.
diff mbox

Patch

diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c
index 493b0de..fceb954 100644
--- a/drivers/net/r8169.c
+++ b/drivers/net/r8169.c
@@ -170,6 +170,16 @@  static const struct {
 };
 #undef _R
 
+static const struct rtl_firmware_info {
+	int mac_version;
+	const char *fw_name;
+} rtl_firmware_infos[] = {
+	{ .mac_version = RTL_GIGA_MAC_VER_25, .fw_name = FIRMWARE_8168D_1 },
+	{ .mac_version = RTL_GIGA_MAC_VER_26, .fw_name = FIRMWARE_8168D_2 },
+	{ .mac_version = RTL_GIGA_MAC_VER_29, .fw_name = FIRMWARE_8105E_1 },
+	{ .mac_version = RTL_GIGA_MAC_VER_30, .fw_name = FIRMWARE_8105E_1 }
+};
+
 enum cfg_version {
 	RTL_CFG_0 = 0x00,
 	RTL_CFG_1,
@@ -565,6 +575,7 @@  struct rtl8169_private {
 	u32 saved_wolopts;
 
 	const struct firmware *fw;
+#define RTL_FIRMWARE_UNKNOWN	ERR_PTR(-EAGAIN);
 };
 
 MODULE_AUTHOR("Realtek and the Linux r8169 crew <netdev@vger.kernel.org>");
@@ -1790,24 +1801,24 @@  rtl_phy_write_fw(struct rtl8169_private *tp, const struct firmware *fw)
 static void rtl_release_firmware(struct rtl8169_private *tp)
 {
 	release_firmware(tp->fw);
-	tp->fw = NULL;
+	tp->fw = RTL_FIRMWARE_UNKNOWN;
 }
 
-static int rtl_apply_firmware(struct rtl8169_private *tp, const char *fw_name)
+static void rtl_apply_firmware(struct rtl8169_private *tp)
 {
-	const struct firmware **fw = &tp->fw;
-	int rc = !*fw;
-
-	if (rc) {
-		rc = request_firmware(fw, fw_name, &tp->pci_dev->dev);
-		if (rc < 0)
-			goto out;
-	}
+	const struct firmware *fw = tp->fw;
 
 	/* TODO: release firmware once rtl_phy_write_fw signals failures. */
-	rtl_phy_write_fw(tp, *fw);
-out:
-	return rc;
+	if (!IS_ERR_OR_NULL(fw))
+		rtl_phy_write_fw(tp, fw);
+}
+
+static void rtl_apply_firmware_cond(struct rtl8169_private *tp, u8 reg, u16 val)
+{
+	if (rtl_readphy(tp, reg) != val)
+		netif_warn(tp, hw, tp->dev, "chipset not ready for firmware\n");
+	else
+		rtl_apply_firmware(tp);
 }
 
 static void rtl8169s_hw_phy_config(struct rtl8169_private *tp)
@@ -2246,10 +2257,8 @@  static void rtl8168d_1_hw_phy_config(struct rtl8169_private *tp)
 
 	rtl_writephy(tp, 0x1f, 0x0005);
 	rtl_writephy(tp, 0x05, 0x001b);
-	if ((rtl_readphy(tp, 0x06) != 0xbf00) ||
-	    (rtl_apply_firmware(tp, FIRMWARE_8168D_1) < 0)) {
-		netif_warn(tp, probe, tp->dev, "unable to apply firmware patch\n");
-	}
+
+	rtl_apply_firmware_cond(tp, MII_EXPANSION, 0xbf00);
 
 	rtl_writephy(tp, 0x1f, 0x0000);
 }
@@ -2351,10 +2360,8 @@  static void rtl8168d_2_hw_phy_config(struct rtl8169_private *tp)
 
 	rtl_writephy(tp, 0x1f, 0x0005);
 	rtl_writephy(tp, 0x05, 0x001b);
-	if ((rtl_readphy(tp, 0x06) != 0xb300) ||
-	    (rtl_apply_firmware(tp, FIRMWARE_8168D_2) < 0)) {
-		netif_warn(tp, probe, tp->dev, "unable to apply firmware patch\n");
-	}
+
+	rtl_apply_firmware_cond(tp, MII_EXPANSION, 0xb300);
 
 	rtl_writephy(tp, 0x1f, 0x0000);
 }
@@ -2474,8 +2481,7 @@  static void rtl8105e_hw_phy_config(struct rtl8169_private *tp)
 	rtl_writephy(tp, 0x18, 0x0310);
 	msleep(100);
 
-	if (rtl_apply_firmware(tp, FIRMWARE_8105E_1) < 0)
-		netif_warn(tp, probe, tp->dev, "unable to apply firmware patch\n");
+	rtl_apply_firmware(tp);
 
 	rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init));
 }
@@ -3237,6 +3243,8 @@  rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	tp->timer.data = (unsigned long) dev;
 	tp->timer.function = rtl8169_phy_timer;
 
+	tp->fw = RTL_FIRMWARE_UNKNOWN;
+
 	rc = register_netdev(dev);
 	if (rc < 0)
 		goto err_out_msi_4;
@@ -3288,10 +3296,10 @@  static void __devexit rtl8169_remove_one(struct pci_dev *pdev)
 
 	cancel_delayed_work_sync(&tp->task);
 
-	rtl_release_firmware(tp);
-
 	unregister_netdev(dev);
 
+	rtl_release_firmware(tp);
+
 	if (pci_dev_run_wake(pdev))
 		pm_runtime_get_noresume(&pdev->dev);
 
@@ -3303,6 +3311,33 @@  static void __devexit rtl8169_remove_one(struct pci_dev *pdev)
 	pci_set_drvdata(pdev, NULL);
 }
 
+static void rtl_request_firmware(struct rtl8169_private *tp)
+{
+	int i;
+
+	/* Return early if the firmware is already loaded / cached. */
+	if (!IS_ERR(tp->fw))
+		return;
+
+	for (i = 0; i < ARRAY_SIZE(rtl_firmware_infos); i++) {
+		const struct rtl_firmware_info *info = rtl_firmware_infos + i;
+
+		if (info->mac_version == tp->mac_version) {
+			const char *name = info->fw_name;
+			int rc;
+
+			rc = request_firmware(&tp->fw, name, &tp->pci_dev->dev);
+			if (rc < 0) {
+				netif_warn(tp, ifup, tp->dev, "unable to load "
+					"firmware patch %s (%d)\n", name, rc);
+			}
+			return;
+		}
+	}
+
+	tp->fw = NULL;
+}
+
 static int rtl8169_open(struct net_device *dev)
 {
 	struct rtl8169_private *tp = netdev_priv(dev);
@@ -3334,11 +3369,13 @@  static int rtl8169_open(struct net_device *dev)
 
 	smp_mb();
 
+	rtl_request_firmware(tp);
+
 	retval = request_irq(dev->irq, rtl8169_interrupt,
 			     (tp->features & RTL_FEATURE_MSI) ? 0 : IRQF_SHARED,
 			     dev->name, dev);
 	if (retval < 0)
-		goto err_release_ring_2;
+		goto err_release_fw_2;
 
 	napi_enable(&tp->napi);
 
@@ -3359,7 +3396,8 @@  static int rtl8169_open(struct net_device *dev)
 out:
 	return retval;
 
-err_release_ring_2:
+err_release_fw_2:
+	rtl_release_firmware(tp);
 	rtl8169_rx_clear(tp);
 err_free_rx_1:
 	dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray,