2
0

e1000e.c 21 KB

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