e1000: use MII status register for link up/down

Some guests will use the standard MII status register
to verify link state.  They will not notice link changes
unless this register is updated.

Verified with Linux 3.0 and Windows XP guests.

Without this patch, ethtool will report speed and duplex as
unknown when the link is down, but still report the link as
up.  This is because the Linux e1000 driver checks the
mac_reg[STATUS] register link state before it checks speed
and duplex, but uses the phy_reg[PHY_STATUS] register for
the actual link state check.  Fix by updating both registers
on link state changes.

Linux guest before:

 (qemu) set_link e1000.0 off

 kvm-sid:~# ethtool eth0
 Settings for eth0:
        Supported ports: [ TP ]
        Supported link modes:   10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
        Supports auto-negotiation: Yes
        Advertised link modes:  10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
        Advertised pause frame use: No
        Advertised auto-negotiation: Yes
        Speed: Unknown!
        Duplex: Unknown! (255)
        Port: Twisted Pair
        PHYAD: 0
        Transceiver: internal
        Auto-negotiation: on
        MDI-X: Unknown
        Supports Wake-on: umbg
        Wake-on: d
        Current message level: 0x00000007 (7)
                               drv probe link
        Link detected: yes

 (qemu) set_link e1000.0 on

Linux guest after:

 (qemu) set_link e1000.0 off
 [   63.384221] e1000: eth0 NIC Link is Down

 kvm-sid:~# ethtool eth0
 Settings for eth0:
        Supported ports: [ TP ]
        Supported link modes:   10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
        Supports auto-negotiation: Yes
        Advertised link modes:  10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
        Advertised pause frame use: No
        Advertised auto-negotiation: Yes
        Speed: Unknown!
        Duplex: Unknown! (255)
        Port: Twisted Pair
        PHYAD: 0
        Transceiver: internal
        Auto-negotiation: on
        MDI-X: Unknown
        Supports Wake-on: umbg
        Wake-on: d
        Current message level: 0x00000007 (7)
                               drv probe link
        Link detected: no

 (qemu) set_link e1000.0 on
 [   84.304582] e1000: eth0 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: RX

Signed-off-by: Bjørn Mork <bjorn@mork.no>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2 files changed
tree: ae5699cbaefe863f224b27e4bfba0fcb241f5f7d
  1. audio/
  2. block/
  3. bsd-user/
  4. darwin-user/
  5. default-configs/
  6. docs/
  7. fpu/
  8. fsdev/
  9. gdb-xml/
  10. hw/
  11. libcacard/
  12. linux-headers/
  13. linux-user/
  14. net/
  15. pc-bios/
  16. qapi/
  17. qga/
  18. QMP/
  19. roms/
  20. scripts/
  21. slirp/
  22. sysconfigs/
  23. target-alpha/
  24. target-arm/
  25. target-cris/
  26. target-i386/
  27. target-lm32/
  28. target-m68k/
  29. target-microblaze/
  30. target-mips/
  31. target-ppc/
  32. target-s390x/
  33. target-sh4/
  34. target-sparc/
  35. target-unicore32/
  36. tcg/
  37. tests/
  38. ui/
  39. .gitignore
  40. .gitmodules
  41. a.out.h
  42. acl.c
  43. acl.h
  44. aes.c
  45. aes.h
  46. aio.c
  47. alpha-dis.c
  48. alpha.ld
  49. arch_init.c
  50. arch_init.h
  51. arm-dis.c
  52. arm-semi.c
  53. arm.ld
  54. async.c
  55. balloon.c
  56. balloon.h
  57. bitmap.c
  58. bitmap.h
  59. bitops.c
  60. bitops.h
  61. block-migration.c
  62. block-migration.h
  63. block.c
  64. block.h
  65. block_int.h
  66. blockdev.c
  67. blockdev.h
  68. bswap.h
  69. bt-host.c
  70. bt-host.h
  71. bt-vhci.c
  72. buffered_file.c
  73. buffered_file.h
  74. cache-utils.c
  75. cache-utils.h
  76. Changelog
  77. check-qdict.c
  78. check-qfloat.c
  79. check-qint.c
  80. check-qjson.c
  81. check-qlist.c
  82. check-qstring.c
  83. cmd.c
  84. cmd.h
  85. CODING_STYLE
  86. compatfd.c
  87. compatfd.h
  88. compiler.h
  89. config.h
  90. configure
  91. console.c
  92. console.h
  93. COPYING
  94. COPYING.LIB
  95. coroutine-gthread.c
  96. coroutine-ucontext.c
  97. coroutine-win32.c
  98. cpu-all.h
  99. cpu-common.h
  100. cpu-defs.h
  101. cpu-exec.c
  102. cpus.c
  103. cpus.h
  104. cris-dis.c
  105. cursor.c
  106. cursor_hidden.xpm
  107. cursor_left_ptr.xpm
  108. cutils.c
  109. def-helper.h
  110. device_tree.c
  111. device_tree.h
  112. dis-asm.h
  113. disas.c
  114. disas.h
  115. dma-helpers.c
  116. dma.h
  117. dyngen-exec.h
  118. elf.h
  119. envlist.c
  120. envlist.h
  121. error.c
  122. error.h
  123. error_int.h
  124. exec-all.h
  125. exec-memory.h
  126. exec.c
  127. gdbstub.c
  128. gdbstub.h
  129. gen-icount.h
  130. HACKING
  131. hmp-commands.hx
  132. host-utils.c
  133. host-utils.h
  134. hpet.h
  135. hppa-dis.c
  136. hppa.ld
  137. i386-dis.c
  138. i386.ld
  139. ia64-dis.c
  140. ia64.ld
  141. input.c
  142. iohandler.c
  143. ioport-user.c
  144. ioport.c
  145. ioport.h
  146. iorange.h
  147. iov.c
  148. iov.h
  149. json-lexer.c
  150. json-lexer.h
  151. json-parser.c
  152. json-parser.h
  153. json-streamer.c
  154. json-streamer.h
  155. kvm-all.c
  156. kvm-stub.c
  157. kvm.h
  158. libfdt_env.h
  159. LICENSE
  160. linux-aio.c
  161. m68k-dis.c
  162. m68k-semi.c
  163. m68k.ld
  164. MAINTAINERS
  165. Makefile
  166. Makefile.dis
  167. Makefile.hw
  168. Makefile.objs
  169. Makefile.target
  170. Makefile.user
  171. memory.c
  172. memory.h
  173. microblaze-dis.c
  174. migration-exec.c
  175. migration-fd.c
  176. migration-tcp.c
  177. migration-unix.c
  178. migration.c
  179. migration.h
  180. mips-dis.c
  181. mips.ld
  182. module.c
  183. module.h
  184. monitor.c
  185. monitor.h
  186. nbd.c
  187. nbd.h
  188. net.c
  189. net.h
  190. notify.c
  191. notify.h
  192. os-posix.c
  193. os-win32.c
  194. osdep.c
  195. osdep.h
  196. oslib-posix.c
  197. oslib-win32.c
  198. path.c
  199. pci-ids.txt
  200. pflib.c
  201. pflib.h
  202. poison.h
  203. posix-aio-compat.c
  204. ppc-dis.c
  205. ppc.ld
  206. ppc64.ld
  207. qapi-schema-guest.json
  208. qapi-schema-test.json
  209. qbool.c
  210. qbool.h
  211. qdict-test-data.txt
  212. qdict.c
  213. qdict.h
  214. qemu-aio.h
  215. qemu-barrier.h
  216. qemu-char.c
  217. qemu-char.h
  218. qemu-common.h
  219. qemu-config.c
  220. qemu-config.h
  221. qemu-coroutine-int.h
  222. qemu-coroutine-lock.c
  223. qemu-coroutine.c
  224. qemu-coroutine.h
  225. qemu-doc.texi
  226. qemu-error.c
  227. qemu-error.h
  228. qemu-ga.c
  229. qemu-img-cmds.hx
  230. qemu-img.c
  231. qemu-img.texi
  232. qemu-io.c
  233. qemu-lock.h
  234. qemu-log.h
  235. qemu-nbd.c
  236. qemu-nbd.texi
  237. qemu-objects.h
  238. qemu-option.c
  239. qemu-option.h
  240. qemu-options.h
  241. qemu-options.hx
  242. qemu-os-posix.h
  243. qemu-os-win32.h
  244. qemu-progress.c
  245. qemu-queue.h
  246. qemu-sockets.c
  247. qemu-tech.texi
  248. qemu-thread-posix.c
  249. qemu-thread-posix.h
  250. qemu-thread-win32.c
  251. qemu-thread-win32.h
  252. qemu-thread.h
  253. qemu-timer-common.c
  254. qemu-timer.c
  255. qemu-timer.h
  256. qemu-tool.c
  257. qemu-x509.h
  258. qemu.sasl
  259. qemu_socket.h
  260. qerror.c
  261. qerror.h
  262. qfloat.c
  263. qfloat.h
  264. qint.c
  265. qint.h
  266. qjson.c
  267. qjson.h
  268. qlist.c
  269. qlist.h
  270. qmp-commands.hx
  271. qobject.h
  272. qstring.c
  273. qstring.h
  274. range.h
  275. readline.c
  276. readline.h
  277. README
  278. rules.mak
  279. rwhandler.c
  280. rwhandler.h
  281. s390-dis.c
  282. s390.ld
  283. savevm.c
  284. sh4-dis.c
  285. simpletrace.c
  286. simpletrace.h
  287. softmmu-semi.h
  288. softmmu_defs.h
  289. softmmu_exec.h
  290. softmmu_header.h
  291. softmmu_template.h
  292. sparc-dis.c
  293. sparc.ld
  294. sparc64.ld
  295. spice-qemu-char.c
  296. sysemu.h
  297. targphys.h
  298. tcg-runtime.c
  299. test-coroutine.c
  300. test-qmp-commands.c
  301. test-visitor.c
  302. thunk.c
  303. thunk.h
  304. TODO
  305. trace-events
  306. translate-all.c
  307. uboot_image.h
  308. usb-bsd.c
  309. usb-linux.c
  310. usb-redir.c
  311. usb-stub.c
  312. user-exec.c
  313. VERSION
  314. version.rc
  315. vgafont.h
  316. vl.c
  317. x86_64.ld
  318. xen-all.c
  319. xen-mapcache.c
  320. xen-mapcache.h
  321. xen-stub.c