2
0

e1000e.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735
  1. /*
  2. * QEMU INTEL 82574 GbE NIC emulation
  3. *
  4. * Software developer's manuals:
  5. * http://www.intel.com/content/dam/doc/datasheet/82574l-gbe-controller-datasheet.pdf
  6. *
  7. * Copyright (c) 2015 Ravello Systems LTD (http://ravellosystems.com)
  8. * Developed by Daynix Computing LTD (http://www.daynix.com)
  9. *
  10. * Authors:
  11. * Dmitry Fleytman <dmitry@daynix.com>
  12. * Leonid Bloch <leonid@daynix.com>
  13. * Yan Vugenfirer <yan@daynix.com>
  14. *
  15. * Based on work done by:
  16. * Nir Peleg, Tutis Systems Ltd. for Qumranet Inc.
  17. * Copyright (c) 2008 Qumranet
  18. * Based on work done by:
  19. * Copyright (c) 2007 Dan Aloni
  20. * Copyright (c) 2004 Antony T Curtis
  21. *
  22. * This library is free software; you can redistribute it and/or
  23. * modify it under the terms of the GNU Lesser General Public
  24. * License as published by the Free Software Foundation; either
  25. * version 2.1 of the License, or (at your option) any later version.
  26. *
  27. * This library is distributed in the hope that it will be useful,
  28. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  29. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  30. * Lesser General Public License for more details.
  31. *
  32. * You should have received a copy of the GNU Lesser General Public
  33. * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  34. */
  35. #include "qemu/osdep.h"
  36. #include "qemu/units.h"
  37. #include "net/eth.h"
  38. #include "net/net.h"
  39. #include "net/tap.h"
  40. #include "qemu/module.h"
  41. #include "qemu/range.h"
  42. #include "system/system.h"
  43. #include "hw/hw.h"
  44. #include "hw/net/mii.h"
  45. #include "hw/pci/msi.h"
  46. #include "hw/pci/msix.h"
  47. #include "hw/qdev-properties.h"
  48. #include "migration/vmstate.h"
  49. #include "e1000_common.h"
  50. #include "e1000x_common.h"
  51. #include "e1000e_core.h"
  52. #include "trace.h"
  53. #include "qapi/error.h"
  54. #include "qom/object.h"
  55. #define TYPE_E1000E "e1000e"
  56. OBJECT_DECLARE_SIMPLE_TYPE(E1000EState, E1000E)
  57. struct E1000EState {
  58. PCIDevice parent_obj;
  59. NICState *nic;
  60. NICConf conf;
  61. MemoryRegion mmio;
  62. MemoryRegion flash;
  63. MemoryRegion io;
  64. MemoryRegion msix;
  65. uint32_t ioaddr;
  66. uint16_t subsys_ven;
  67. uint16_t subsys;
  68. uint16_t subsys_ven_used;
  69. uint16_t subsys_used;
  70. bool disable_vnet;
  71. E1000ECore core;
  72. bool init_vet;
  73. bool timadj;
  74. };
  75. #define E1000E_MMIO_IDX 0
  76. #define E1000E_FLASH_IDX 1
  77. #define E1000E_IO_IDX 2
  78. #define E1000E_MSIX_IDX 3
  79. #define E1000E_MMIO_SIZE (128 * KiB)
  80. #define E1000E_FLASH_SIZE (128 * KiB)
  81. #define E1000E_IO_SIZE (32)
  82. #define E1000E_MSIX_SIZE (16 * KiB)
  83. #define E1000E_MSIX_TABLE (0x0000)
  84. #define E1000E_MSIX_PBA (0x2000)
  85. static uint64_t
  86. e1000e_mmio_read(void *opaque, hwaddr addr, unsigned size)
  87. {
  88. E1000EState *s = opaque;
  89. return e1000e_core_read(&s->core, addr, size);
  90. }
  91. static void
  92. e1000e_mmio_write(void *opaque, hwaddr addr,
  93. uint64_t val, unsigned size)
  94. {
  95. E1000EState *s = opaque;
  96. e1000e_core_write(&s->core, addr, val, size);
  97. }
  98. static bool
  99. e1000e_io_get_reg_index(E1000EState *s, uint32_t *idx)
  100. {
  101. if (s->ioaddr < 0x1FFFF) {
  102. *idx = s->ioaddr;
  103. return true;
  104. }
  105. if (s->ioaddr < 0x7FFFF) {
  106. trace_e1000e_wrn_io_addr_undefined(s->ioaddr);
  107. return false;
  108. }
  109. if (s->ioaddr < 0xFFFFF) {
  110. trace_e1000e_wrn_io_addr_flash(s->ioaddr);
  111. return false;
  112. }
  113. trace_e1000e_wrn_io_addr_unknown(s->ioaddr);
  114. return false;
  115. }
  116. static uint64_t
  117. e1000e_io_read(void *opaque, hwaddr addr, unsigned size)
  118. {
  119. E1000EState *s = opaque;
  120. uint32_t idx = 0;
  121. uint64_t val;
  122. switch (addr) {
  123. case E1000_IOADDR:
  124. trace_e1000e_io_read_addr(s->ioaddr);
  125. return s->ioaddr;
  126. case E1000_IODATA:
  127. if (e1000e_io_get_reg_index(s, &idx)) {
  128. val = e1000e_core_read(&s->core, idx, sizeof(val));
  129. trace_e1000e_io_read_data(idx, val);
  130. return val;
  131. }
  132. return 0;
  133. default:
  134. trace_e1000e_wrn_io_read_unknown(addr);
  135. return 0;
  136. }
  137. }
  138. static void
  139. e1000e_io_write(void *opaque, hwaddr addr,
  140. uint64_t val, unsigned size)
  141. {
  142. E1000EState *s = opaque;
  143. uint32_t idx = 0;
  144. switch (addr) {
  145. case E1000_IOADDR:
  146. trace_e1000e_io_write_addr(val);
  147. s->ioaddr = (uint32_t) val;
  148. return;
  149. case E1000_IODATA:
  150. if (e1000e_io_get_reg_index(s, &idx)) {
  151. trace_e1000e_io_write_data(idx, val);
  152. e1000e_core_write(&s->core, idx, val, sizeof(val));
  153. }
  154. return;
  155. default:
  156. trace_e1000e_wrn_io_write_unknown(addr);
  157. return;
  158. }
  159. }
  160. static const MemoryRegionOps mmio_ops = {
  161. .read = e1000e_mmio_read,
  162. .write = e1000e_mmio_write,
  163. .endianness = DEVICE_LITTLE_ENDIAN,
  164. .impl = {
  165. .min_access_size = 4,
  166. .max_access_size = 4,
  167. },
  168. };
  169. static const MemoryRegionOps io_ops = {
  170. .read = e1000e_io_read,
  171. .write = e1000e_io_write,
  172. .endianness = DEVICE_LITTLE_ENDIAN,
  173. .impl = {
  174. .min_access_size = 4,
  175. .max_access_size = 4,
  176. },
  177. };
  178. static bool
  179. e1000e_nc_can_receive(NetClientState *nc)
  180. {
  181. E1000EState *s = qemu_get_nic_opaque(nc);
  182. return e1000e_can_receive(&s->core);
  183. }
  184. static ssize_t
  185. e1000e_nc_receive_iov(NetClientState *nc, const struct iovec *iov, int iovcnt)
  186. {
  187. E1000EState *s = qemu_get_nic_opaque(nc);
  188. return e1000e_receive_iov(&s->core, iov, iovcnt);
  189. }
  190. static ssize_t
  191. e1000e_nc_receive(NetClientState *nc, const uint8_t *buf, size_t size)
  192. {
  193. E1000EState *s = qemu_get_nic_opaque(nc);
  194. return e1000e_receive(&s->core, buf, size);
  195. }
  196. static void
  197. e1000e_set_link_status(NetClientState *nc)
  198. {
  199. E1000EState *s = qemu_get_nic_opaque(nc);
  200. e1000e_core_set_link_status(&s->core);
  201. }
  202. static NetClientInfo net_e1000e_info = {
  203. .type = NET_CLIENT_DRIVER_NIC,
  204. .size = sizeof(NICState),
  205. .can_receive = e1000e_nc_can_receive,
  206. .receive = e1000e_nc_receive,
  207. .receive_iov = e1000e_nc_receive_iov,
  208. .link_status_changed = e1000e_set_link_status,
  209. };
  210. /*
  211. * EEPROM (NVM) contents documented in Table 36, section 6.1
  212. * and generally 6.1.2 Software accessed words.
  213. */
  214. static const uint16_t e1000e_eeprom_template[64] = {
  215. /* Address | Compat. | ImVer | Compat. */
  216. 0x0000, 0x0000, 0x0000, 0x0420, 0xf746, 0x2010, 0xffff, 0xffff,
  217. /* PBA |ICtrl1 | SSID | SVID | DevID |-------|ICtrl2 */
  218. 0x0000, 0x0000, 0x026b, 0x0000, 0x8086, 0x0000, 0x0000, 0x8058,
  219. /* NVM words 1,2,3 |-------------------------------|PCI-EID*/
  220. 0x0000, 0x2001, 0x7e7c, 0xffff, 0x1000, 0x00c8, 0x0000, 0x2704,
  221. /* PCIe Init. Conf 1,2,3 |PCICtrl|PHY|LD1|-------| RevID | LD0,2 */
  222. 0x6cc9, 0x3150, 0x070e, 0x460b, 0x2d84, 0x0100, 0xf000, 0x0706,
  223. /* FLPAR |FLANADD|LAN-PWR|FlVndr |ICtrl3 |APTSMBA|APTRxEP|APTSMBC*/
  224. 0x6000, 0x0080, 0x0f04, 0x7fff, 0x4f01, 0xc600, 0x0000, 0x20ff,
  225. /* APTIF | APTMC |APTuCP |LSWFWID|MSWFWID|NC-SIMC|NC-SIC | VPDP */
  226. 0x0028, 0x0003, 0x0000, 0x0000, 0x0000, 0x0003, 0x0000, 0xffff,
  227. /* SW Section */
  228. 0x0100, 0xc000, 0x121c, 0xc007, 0xffff, 0xffff, 0xffff, 0xffff,
  229. /* SW Section |CHKSUM */
  230. 0xffff, 0xffff, 0xffff, 0xffff, 0x0000, 0x0120, 0xffff, 0x0000,
  231. };
  232. static void e1000e_core_realize(E1000EState *s)
  233. {
  234. s->core.owner = &s->parent_obj;
  235. s->core.owner_nic = s->nic;
  236. }
  237. static void
  238. e1000e_unuse_msix_vectors(E1000EState *s, int num_vectors)
  239. {
  240. int i;
  241. for (i = 0; i < num_vectors; i++) {
  242. msix_vector_unuse(PCI_DEVICE(s), i);
  243. }
  244. }
  245. static void
  246. e1000e_use_msix_vectors(E1000EState *s, int num_vectors)
  247. {
  248. int i;
  249. for (i = 0; i < num_vectors; i++) {
  250. msix_vector_use(PCI_DEVICE(s), i);
  251. }
  252. }
  253. static void
  254. e1000e_init_msix(E1000EState *s)
  255. {
  256. int res = msix_init(PCI_DEVICE(s), E1000E_MSIX_VEC_NUM,
  257. &s->msix,
  258. E1000E_MSIX_IDX, E1000E_MSIX_TABLE,
  259. &s->msix,
  260. E1000E_MSIX_IDX, E1000E_MSIX_PBA,
  261. 0xA0, NULL);
  262. if (res < 0) {
  263. trace_e1000e_msix_init_fail(res);
  264. } else {
  265. e1000e_use_msix_vectors(s, E1000E_MSIX_VEC_NUM);
  266. }
  267. }
  268. static void
  269. e1000e_cleanup_msix(E1000EState *s)
  270. {
  271. if (msix_present(PCI_DEVICE(s))) {
  272. e1000e_unuse_msix_vectors(s, E1000E_MSIX_VEC_NUM);
  273. msix_uninit(PCI_DEVICE(s), &s->msix, &s->msix);
  274. }
  275. }
  276. static void
  277. e1000e_init_net_peer(E1000EState *s, PCIDevice *pci_dev, uint8_t *macaddr)
  278. {
  279. DeviceState *dev = DEVICE(pci_dev);
  280. NetClientState *nc;
  281. int i;
  282. s->nic = qemu_new_nic(&net_e1000e_info, &s->conf,
  283. object_get_typename(OBJECT(s)), dev->id, &dev->mem_reentrancy_guard, s);
  284. s->core.max_queue_num = s->conf.peers.queues ? s->conf.peers.queues - 1 : 0;
  285. trace_e1000e_mac_set_permanent(MAC_ARG(macaddr));
  286. memcpy(s->core.permanent_mac, macaddr, sizeof(s->core.permanent_mac));
  287. qemu_format_nic_info_str(qemu_get_queue(s->nic), macaddr);
  288. /* Setup virtio headers */
  289. if (s->disable_vnet) {
  290. s->core.has_vnet = false;
  291. trace_e1000e_cfg_support_virtio(false);
  292. return;
  293. } else {
  294. s->core.has_vnet = true;
  295. }
  296. for (i = 0; i < s->conf.peers.queues; i++) {
  297. nc = qemu_get_subqueue(s->nic, i);
  298. if (!nc->peer || !qemu_has_vnet_hdr(nc->peer)) {
  299. s->core.has_vnet = false;
  300. trace_e1000e_cfg_support_virtio(false);
  301. return;
  302. }
  303. }
  304. trace_e1000e_cfg_support_virtio(true);
  305. for (i = 0; i < s->conf.peers.queues; i++) {
  306. nc = qemu_get_subqueue(s->nic, i);
  307. qemu_set_vnet_hdr_len(nc->peer, sizeof(struct virtio_net_hdr));
  308. }
  309. }
  310. static inline uint64_t
  311. e1000e_gen_dsn(uint8_t *mac)
  312. {
  313. return (uint64_t)(mac[5]) |
  314. (uint64_t)(mac[4]) << 8 |
  315. (uint64_t)(mac[3]) << 16 |
  316. (uint64_t)(0x00FF) << 24 |
  317. (uint64_t)(0x00FF) << 32 |
  318. (uint64_t)(mac[2]) << 40 |
  319. (uint64_t)(mac[1]) << 48 |
  320. (uint64_t)(mac[0]) << 56;
  321. }
  322. static int
  323. e1000e_add_pm_capability(PCIDevice *pdev, uint8_t offset, uint16_t pmc)
  324. {
  325. Error *local_err = NULL;
  326. int ret = pci_pm_init(pdev, offset, &local_err);
  327. if (local_err) {
  328. error_report_err(local_err);
  329. return ret;
  330. }
  331. pci_set_word(pdev->config + offset + PCI_PM_PMC,
  332. PCI_PM_CAP_VER_1_1 |
  333. pmc);
  334. pci_set_word(pdev->wmask + offset + PCI_PM_CTRL,
  335. PCI_PM_CTRL_STATE_MASK |
  336. PCI_PM_CTRL_PME_ENABLE |
  337. PCI_PM_CTRL_DATA_SEL_MASK);
  338. pci_set_word(pdev->w1cmask + offset + PCI_PM_CTRL,
  339. PCI_PM_CTRL_PME_STATUS);
  340. return ret;
  341. }
  342. static void e1000e_write_config(PCIDevice *pci_dev, uint32_t address,
  343. uint32_t val, int len)
  344. {
  345. E1000EState *s = E1000E(pci_dev);
  346. pci_default_write_config(pci_dev, address, val, len);
  347. if (range_covers_byte(address, len, PCI_COMMAND) &&
  348. (pci_dev->config[PCI_COMMAND] & PCI_COMMAND_MASTER)) {
  349. e1000e_start_recv(&s->core);
  350. }
  351. }
  352. static void e1000e_pci_realize(PCIDevice *pci_dev, Error **errp)
  353. {
  354. static const uint16_t e1000e_pmrb_offset = 0x0C8;
  355. static const uint16_t e1000e_pcie_offset = 0x0E0;
  356. static const uint16_t e1000e_aer_offset = 0x100;
  357. static const uint16_t e1000e_dsn_offset = 0x140;
  358. E1000EState *s = E1000E(pci_dev);
  359. uint8_t *macaddr;
  360. int ret;
  361. trace_e1000e_cb_pci_realize();
  362. pci_dev->config_write = e1000e_write_config;
  363. pci_dev->config[PCI_CACHE_LINE_SIZE] = 0x10;
  364. pci_dev->config[PCI_INTERRUPT_PIN] = 1;
  365. pci_set_word(pci_dev->config + PCI_SUBSYSTEM_VENDOR_ID, s->subsys_ven);
  366. pci_set_word(pci_dev->config + PCI_SUBSYSTEM_ID, s->subsys);
  367. s->subsys_ven_used = s->subsys_ven;
  368. s->subsys_used = s->subsys;
  369. /* Define IO/MMIO regions */
  370. memory_region_init_io(&s->mmio, OBJECT(s), &mmio_ops, s,
  371. "e1000e-mmio", E1000E_MMIO_SIZE);
  372. pci_register_bar(pci_dev, E1000E_MMIO_IDX,
  373. PCI_BASE_ADDRESS_SPACE_MEMORY, &s->mmio);
  374. /*
  375. * We provide a dummy implementation for the flash BAR
  376. * for drivers that may theoretically probe for its presence.
  377. */
  378. memory_region_init(&s->flash, OBJECT(s),
  379. "e1000e-flash", E1000E_FLASH_SIZE);
  380. pci_register_bar(pci_dev, E1000E_FLASH_IDX,
  381. PCI_BASE_ADDRESS_SPACE_MEMORY, &s->flash);
  382. memory_region_init_io(&s->io, OBJECT(s), &io_ops, s,
  383. "e1000e-io", E1000E_IO_SIZE);
  384. pci_register_bar(pci_dev, E1000E_IO_IDX,
  385. PCI_BASE_ADDRESS_SPACE_IO, &s->io);
  386. memory_region_init(&s->msix, OBJECT(s), "e1000e-msix",
  387. E1000E_MSIX_SIZE);
  388. pci_register_bar(pci_dev, E1000E_MSIX_IDX,
  389. PCI_BASE_ADDRESS_SPACE_MEMORY, &s->msix);
  390. /* Create networking backend */
  391. qemu_macaddr_default_if_unset(&s->conf.macaddr);
  392. macaddr = s->conf.macaddr.a;
  393. e1000e_init_msix(s);
  394. if (pcie_endpoint_cap_v1_init(pci_dev, e1000e_pcie_offset) < 0) {
  395. hw_error("Failed to initialize PCIe capability");
  396. }
  397. ret = msi_init(PCI_DEVICE(s), 0xD0, 1, true, false, NULL);
  398. if (ret) {
  399. trace_e1000e_msi_init_fail(ret);
  400. }
  401. if (e1000e_add_pm_capability(pci_dev, e1000e_pmrb_offset,
  402. PCI_PM_CAP_DSI) < 0) {
  403. hw_error("Failed to initialize PM capability");
  404. }
  405. if (pcie_aer_init(pci_dev, PCI_ERR_VER, e1000e_aer_offset,
  406. PCI_ERR_SIZEOF, NULL) < 0) {
  407. hw_error("Failed to initialize AER capability");
  408. }
  409. pcie_dev_ser_num_init(pci_dev, e1000e_dsn_offset,
  410. e1000e_gen_dsn(macaddr));
  411. e1000e_init_net_peer(s, pci_dev, macaddr);
  412. /* Initialize core */
  413. e1000e_core_realize(s);
  414. e1000e_core_pci_realize(&s->core,
  415. e1000e_eeprom_template,
  416. sizeof(e1000e_eeprom_template),
  417. macaddr);
  418. }
  419. static void e1000e_pci_uninit(PCIDevice *pci_dev)
  420. {
  421. E1000EState *s = E1000E(pci_dev);
  422. trace_e1000e_cb_pci_uninit();
  423. e1000e_core_pci_uninit(&s->core);
  424. pcie_aer_exit(pci_dev);
  425. pcie_cap_exit(pci_dev);
  426. qemu_del_nic(s->nic);
  427. e1000e_cleanup_msix(s);
  428. msi_uninit(pci_dev);
  429. }
  430. static void e1000e_qdev_reset_hold(Object *obj, ResetType type)
  431. {
  432. E1000EState *s = E1000E(obj);
  433. trace_e1000e_cb_qdev_reset_hold();
  434. e1000e_core_reset(&s->core);
  435. if (s->init_vet) {
  436. s->core.mac[VET] = ETH_P_VLAN;
  437. }
  438. }
  439. static int e1000e_pre_save(void *opaque)
  440. {
  441. E1000EState *s = opaque;
  442. trace_e1000e_cb_pre_save();
  443. e1000e_core_pre_save(&s->core);
  444. return 0;
  445. }
  446. static int e1000e_post_load(void *opaque, int version_id)
  447. {
  448. E1000EState *s = opaque;
  449. trace_e1000e_cb_post_load();
  450. if ((s->subsys != s->subsys_used) ||
  451. (s->subsys_ven != s->subsys_ven_used)) {
  452. fprintf(stderr,
  453. "ERROR: Cannot migrate while device properties "
  454. "(subsys/subsys_ven) differ");
  455. return -1;
  456. }
  457. return e1000e_core_post_load(&s->core);
  458. }
  459. static bool e1000e_migrate_timadj(void *opaque, int version_id)
  460. {
  461. E1000EState *s = opaque;
  462. return s->timadj;
  463. }
  464. static const VMStateDescription e1000e_vmstate_tx = {
  465. .name = "e1000e-tx",
  466. .version_id = 1,
  467. .minimum_version_id = 1,
  468. .fields = (const VMStateField[]) {
  469. VMSTATE_UINT8(sum_needed, struct e1000e_tx),
  470. VMSTATE_UINT8(props.ipcss, struct e1000e_tx),
  471. VMSTATE_UINT8(props.ipcso, struct e1000e_tx),
  472. VMSTATE_UINT16(props.ipcse, struct e1000e_tx),
  473. VMSTATE_UINT8(props.tucss, struct e1000e_tx),
  474. VMSTATE_UINT8(props.tucso, struct e1000e_tx),
  475. VMSTATE_UINT16(props.tucse, struct e1000e_tx),
  476. VMSTATE_UINT8(props.hdr_len, struct e1000e_tx),
  477. VMSTATE_UINT16(props.mss, struct e1000e_tx),
  478. VMSTATE_UINT32(props.paylen, struct e1000e_tx),
  479. VMSTATE_INT8(props.ip, struct e1000e_tx),
  480. VMSTATE_INT8(props.tcp, struct e1000e_tx),
  481. VMSTATE_BOOL(props.tse, struct e1000e_tx),
  482. VMSTATE_BOOL(cptse, struct e1000e_tx),
  483. VMSTATE_BOOL(skip_cp, struct e1000e_tx),
  484. VMSTATE_END_OF_LIST()
  485. }
  486. };
  487. static const VMStateDescription e1000e_vmstate_intr_timer = {
  488. .name = "e1000e-intr-timer",
  489. .version_id = 1,
  490. .minimum_version_id = 1,
  491. .fields = (const VMStateField[]) {
  492. VMSTATE_TIMER_PTR(timer, E1000IntrDelayTimer),
  493. VMSTATE_BOOL(running, E1000IntrDelayTimer),
  494. VMSTATE_END_OF_LIST()
  495. }
  496. };
  497. #define VMSTATE_E1000E_INTR_DELAY_TIMER(_f, _s) \
  498. VMSTATE_STRUCT(_f, _s, 0, \
  499. e1000e_vmstate_intr_timer, E1000IntrDelayTimer)
  500. #define VMSTATE_E1000E_INTR_DELAY_TIMER_ARRAY(_f, _s, _num) \
  501. VMSTATE_STRUCT_ARRAY(_f, _s, _num, 0, \
  502. e1000e_vmstate_intr_timer, E1000IntrDelayTimer)
  503. static const VMStateDescription e1000e_vmstate = {
  504. .name = "e1000e",
  505. .version_id = 1,
  506. .minimum_version_id = 1,
  507. .pre_save = e1000e_pre_save,
  508. .post_load = e1000e_post_load,
  509. .fields = (const VMStateField[]) {
  510. VMSTATE_PCI_DEVICE(parent_obj, E1000EState),
  511. VMSTATE_MSIX(parent_obj, E1000EState),
  512. VMSTATE_UINT32(ioaddr, E1000EState),
  513. VMSTATE_UINT32(core.rxbuf_min_shift, E1000EState),
  514. VMSTATE_UINT8(core.rx_desc_len, E1000EState),
  515. VMSTATE_UINT32_ARRAY(core.rxbuf_sizes, E1000EState,
  516. E1000_PSRCTL_BUFFS_PER_DESC),
  517. VMSTATE_UINT32(core.rx_desc_buf_size, E1000EState),
  518. VMSTATE_UINT16_ARRAY(core.eeprom, E1000EState, E1000E_EEPROM_SIZE),
  519. VMSTATE_UINT16_2DARRAY(core.phy, E1000EState,
  520. E1000E_PHY_PAGES, E1000E_PHY_PAGE_SIZE),
  521. VMSTATE_UINT32_ARRAY(core.mac, E1000EState, E1000E_MAC_SIZE),
  522. VMSTATE_UINT8_ARRAY(core.permanent_mac, E1000EState, ETH_ALEN),
  523. VMSTATE_UINT32(core.delayed_causes, E1000EState),
  524. VMSTATE_UINT16(subsys, E1000EState),
  525. VMSTATE_UINT16(subsys_ven, E1000EState),
  526. VMSTATE_E1000E_INTR_DELAY_TIMER(core.rdtr, E1000EState),
  527. VMSTATE_E1000E_INTR_DELAY_TIMER(core.radv, E1000EState),
  528. VMSTATE_E1000E_INTR_DELAY_TIMER(core.raid, E1000EState),
  529. VMSTATE_E1000E_INTR_DELAY_TIMER(core.tadv, E1000EState),
  530. VMSTATE_E1000E_INTR_DELAY_TIMER(core.tidv, E1000EState),
  531. VMSTATE_E1000E_INTR_DELAY_TIMER(core.itr, E1000EState),
  532. VMSTATE_UNUSED(1),
  533. VMSTATE_E1000E_INTR_DELAY_TIMER_ARRAY(core.eitr, E1000EState,
  534. E1000E_MSIX_VEC_NUM),
  535. VMSTATE_UNUSED(E1000E_MSIX_VEC_NUM),
  536. VMSTATE_UINT32(core.itr_guest_value, E1000EState),
  537. VMSTATE_UINT32_ARRAY(core.eitr_guest_value, E1000EState,
  538. E1000E_MSIX_VEC_NUM),
  539. VMSTATE_UINT16(core.vet, E1000EState),
  540. VMSTATE_STRUCT_ARRAY(core.tx, E1000EState, E1000E_NUM_QUEUES, 0,
  541. e1000e_vmstate_tx, struct e1000e_tx),
  542. VMSTATE_INT64_TEST(core.timadj, E1000EState, e1000e_migrate_timadj),
  543. VMSTATE_END_OF_LIST()
  544. }
  545. };
  546. static PropertyInfo e1000e_prop_disable_vnet,
  547. e1000e_prop_subsys_ven,
  548. e1000e_prop_subsys;
  549. static const Property e1000e_properties[] = {
  550. DEFINE_NIC_PROPERTIES(E1000EState, conf),
  551. DEFINE_PROP_SIGNED("disable_vnet_hdr", E1000EState, disable_vnet, false,
  552. e1000e_prop_disable_vnet, bool),
  553. DEFINE_PROP_SIGNED("subsys_ven", E1000EState, subsys_ven,
  554. PCI_VENDOR_ID_INTEL,
  555. e1000e_prop_subsys_ven, uint16_t),
  556. DEFINE_PROP_SIGNED("subsys", E1000EState, subsys, 0,
  557. e1000e_prop_subsys, uint16_t),
  558. DEFINE_PROP_BOOL("init-vet", E1000EState, init_vet, true),
  559. DEFINE_PROP_BOOL("migrate-timadj", E1000EState, timadj, true),
  560. };
  561. static void e1000e_class_init(ObjectClass *class, void *data)
  562. {
  563. DeviceClass *dc = DEVICE_CLASS(class);
  564. ResettableClass *rc = RESETTABLE_CLASS(class);
  565. PCIDeviceClass *c = PCI_DEVICE_CLASS(class);
  566. c->realize = e1000e_pci_realize;
  567. c->exit = e1000e_pci_uninit;
  568. c->vendor_id = PCI_VENDOR_ID_INTEL;
  569. c->device_id = E1000_DEV_ID_82574L;
  570. c->revision = 0;
  571. c->romfile = "efi-e1000e.rom";
  572. c->class_id = PCI_CLASS_NETWORK_ETHERNET;
  573. rc->phases.hold = e1000e_qdev_reset_hold;
  574. dc->desc = "Intel 82574L GbE Controller";
  575. dc->vmsd = &e1000e_vmstate;
  576. e1000e_prop_disable_vnet = qdev_prop_uint8;
  577. e1000e_prop_disable_vnet.description = "Do not use virtio headers, "
  578. "perform SW offloads emulation "
  579. "instead";
  580. e1000e_prop_subsys_ven = qdev_prop_uint16;
  581. e1000e_prop_subsys_ven.description = "PCI device Subsystem Vendor ID";
  582. e1000e_prop_subsys = qdev_prop_uint16;
  583. e1000e_prop_subsys.description = "PCI device Subsystem ID";
  584. device_class_set_props(dc, e1000e_properties);
  585. set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
  586. }
  587. static void e1000e_instance_init(Object *obj)
  588. {
  589. E1000EState *s = E1000E(obj);
  590. device_add_bootindex_property(obj, &s->conf.bootindex,
  591. "bootindex", "/ethernet-phy@0",
  592. DEVICE(obj));
  593. }
  594. static const TypeInfo e1000e_info = {
  595. .name = TYPE_E1000E,
  596. .parent = TYPE_PCI_DEVICE,
  597. .instance_size = sizeof(E1000EState),
  598. .class_init = e1000e_class_init,
  599. .instance_init = e1000e_instance_init,
  600. .interfaces = (InterfaceInfo[]) {
  601. { INTERFACE_PCIE_DEVICE },
  602. { }
  603. },
  604. };
  605. static void e1000e_register_types(void)
  606. {
  607. type_register_static(&e1000e_info);
  608. }
  609. type_init(e1000e_register_types)