e1000e.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  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 "sysemu/sysemu.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, 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. qemu_using_vnet_hdr(nc->peer, true);
  309. }
  310. }
  311. static inline uint64_t
  312. e1000e_gen_dsn(uint8_t *mac)
  313. {
  314. return (uint64_t)(mac[5]) |
  315. (uint64_t)(mac[4]) << 8 |
  316. (uint64_t)(mac[3]) << 16 |
  317. (uint64_t)(0x00FF) << 24 |
  318. (uint64_t)(0x00FF) << 32 |
  319. (uint64_t)(mac[2]) << 40 |
  320. (uint64_t)(mac[1]) << 48 |
  321. (uint64_t)(mac[0]) << 56;
  322. }
  323. static int
  324. e1000e_add_pm_capability(PCIDevice *pdev, uint8_t offset, uint16_t pmc)
  325. {
  326. Error *local_err = NULL;
  327. int ret = pci_add_capability(pdev, PCI_CAP_ID_PM, offset,
  328. PCI_PM_SIZEOF, &local_err);
  329. if (local_err) {
  330. error_report_err(local_err);
  331. return ret;
  332. }
  333. pci_set_word(pdev->config + offset + PCI_PM_PMC,
  334. PCI_PM_CAP_VER_1_1 |
  335. pmc);
  336. pci_set_word(pdev->wmask + offset + PCI_PM_CTRL,
  337. PCI_PM_CTRL_STATE_MASK |
  338. PCI_PM_CTRL_PME_ENABLE |
  339. PCI_PM_CTRL_DATA_SEL_MASK);
  340. pci_set_word(pdev->w1cmask + offset + PCI_PM_CTRL,
  341. PCI_PM_CTRL_PME_STATUS);
  342. return ret;
  343. }
  344. static void e1000e_write_config(PCIDevice *pci_dev, uint32_t address,
  345. uint32_t val, int len)
  346. {
  347. E1000EState *s = E1000E(pci_dev);
  348. pci_default_write_config(pci_dev, address, val, len);
  349. if (range_covers_byte(address, len, PCI_COMMAND) &&
  350. (pci_dev->config[PCI_COMMAND] & PCI_COMMAND_MASTER)) {
  351. e1000e_start_recv(&s->core);
  352. }
  353. }
  354. static void e1000e_pci_realize(PCIDevice *pci_dev, Error **errp)
  355. {
  356. static const uint16_t e1000e_pmrb_offset = 0x0C8;
  357. static const uint16_t e1000e_pcie_offset = 0x0E0;
  358. static const uint16_t e1000e_aer_offset = 0x100;
  359. static const uint16_t e1000e_dsn_offset = 0x140;
  360. E1000EState *s = E1000E(pci_dev);
  361. uint8_t *macaddr;
  362. int ret;
  363. trace_e1000e_cb_pci_realize();
  364. pci_dev->config_write = e1000e_write_config;
  365. pci_dev->config[PCI_CACHE_LINE_SIZE] = 0x10;
  366. pci_dev->config[PCI_INTERRUPT_PIN] = 1;
  367. pci_set_word(pci_dev->config + PCI_SUBSYSTEM_VENDOR_ID, s->subsys_ven);
  368. pci_set_word(pci_dev->config + PCI_SUBSYSTEM_ID, s->subsys);
  369. s->subsys_ven_used = s->subsys_ven;
  370. s->subsys_used = s->subsys;
  371. /* Define IO/MMIO regions */
  372. memory_region_init_io(&s->mmio, OBJECT(s), &mmio_ops, s,
  373. "e1000e-mmio", E1000E_MMIO_SIZE);
  374. pci_register_bar(pci_dev, E1000E_MMIO_IDX,
  375. PCI_BASE_ADDRESS_SPACE_MEMORY, &s->mmio);
  376. /*
  377. * We provide a dummy implementation for the flash BAR
  378. * for drivers that may theoretically probe for its presence.
  379. */
  380. memory_region_init(&s->flash, OBJECT(s),
  381. "e1000e-flash", E1000E_FLASH_SIZE);
  382. pci_register_bar(pci_dev, E1000E_FLASH_IDX,
  383. PCI_BASE_ADDRESS_SPACE_MEMORY, &s->flash);
  384. memory_region_init_io(&s->io, OBJECT(s), &io_ops, s,
  385. "e1000e-io", E1000E_IO_SIZE);
  386. pci_register_bar(pci_dev, E1000E_IO_IDX,
  387. PCI_BASE_ADDRESS_SPACE_IO, &s->io);
  388. memory_region_init(&s->msix, OBJECT(s), "e1000e-msix",
  389. E1000E_MSIX_SIZE);
  390. pci_register_bar(pci_dev, E1000E_MSIX_IDX,
  391. PCI_BASE_ADDRESS_SPACE_MEMORY, &s->msix);
  392. /* Create networking backend */
  393. qemu_macaddr_default_if_unset(&s->conf.macaddr);
  394. macaddr = s->conf.macaddr.a;
  395. e1000e_init_msix(s);
  396. if (pcie_endpoint_cap_v1_init(pci_dev, e1000e_pcie_offset) < 0) {
  397. hw_error("Failed to initialize PCIe capability");
  398. }
  399. ret = msi_init(PCI_DEVICE(s), 0xD0, 1, true, false, NULL);
  400. if (ret) {
  401. trace_e1000e_msi_init_fail(ret);
  402. }
  403. if (e1000e_add_pm_capability(pci_dev, e1000e_pmrb_offset,
  404. PCI_PM_CAP_DSI) < 0) {
  405. hw_error("Failed to initialize PM capability");
  406. }
  407. if (pcie_aer_init(pci_dev, PCI_ERR_VER, e1000e_aer_offset,
  408. PCI_ERR_SIZEOF, NULL) < 0) {
  409. hw_error("Failed to initialize AER capability");
  410. }
  411. pcie_dev_ser_num_init(pci_dev, e1000e_dsn_offset,
  412. e1000e_gen_dsn(macaddr));
  413. e1000e_init_net_peer(s, pci_dev, macaddr);
  414. /* Initialize core */
  415. e1000e_core_realize(s);
  416. e1000e_core_pci_realize(&s->core,
  417. e1000e_eeprom_template,
  418. sizeof(e1000e_eeprom_template),
  419. macaddr);
  420. }
  421. static void e1000e_pci_uninit(PCIDevice *pci_dev)
  422. {
  423. E1000EState *s = E1000E(pci_dev);
  424. trace_e1000e_cb_pci_uninit();
  425. e1000e_core_pci_uninit(&s->core);
  426. pcie_aer_exit(pci_dev);
  427. pcie_cap_exit(pci_dev);
  428. qemu_del_nic(s->nic);
  429. e1000e_cleanup_msix(s);
  430. msi_uninit(pci_dev);
  431. }
  432. static void e1000e_qdev_reset_hold(Object *obj)
  433. {
  434. E1000EState *s = E1000E(obj);
  435. trace_e1000e_cb_qdev_reset_hold();
  436. e1000e_core_reset(&s->core);
  437. if (s->init_vet) {
  438. s->core.mac[VET] = ETH_P_VLAN;
  439. }
  440. }
  441. static int e1000e_pre_save(void *opaque)
  442. {
  443. E1000EState *s = opaque;
  444. trace_e1000e_cb_pre_save();
  445. e1000e_core_pre_save(&s->core);
  446. return 0;
  447. }
  448. static int e1000e_post_load(void *opaque, int version_id)
  449. {
  450. E1000EState *s = opaque;
  451. trace_e1000e_cb_post_load();
  452. if ((s->subsys != s->subsys_used) ||
  453. (s->subsys_ven != s->subsys_ven_used)) {
  454. fprintf(stderr,
  455. "ERROR: Cannot migrate while device properties "
  456. "(subsys/subsys_ven) differ");
  457. return -1;
  458. }
  459. return e1000e_core_post_load(&s->core);
  460. }
  461. static bool e1000e_migrate_timadj(void *opaque, int version_id)
  462. {
  463. E1000EState *s = opaque;
  464. return s->timadj;
  465. }
  466. static const VMStateDescription e1000e_vmstate_tx = {
  467. .name = "e1000e-tx",
  468. .version_id = 1,
  469. .minimum_version_id = 1,
  470. .fields = (VMStateField[]) {
  471. VMSTATE_UINT8(sum_needed, struct e1000e_tx),
  472. VMSTATE_UINT8(props.ipcss, struct e1000e_tx),
  473. VMSTATE_UINT8(props.ipcso, struct e1000e_tx),
  474. VMSTATE_UINT16(props.ipcse, struct e1000e_tx),
  475. VMSTATE_UINT8(props.tucss, struct e1000e_tx),
  476. VMSTATE_UINT8(props.tucso, struct e1000e_tx),
  477. VMSTATE_UINT16(props.tucse, struct e1000e_tx),
  478. VMSTATE_UINT8(props.hdr_len, struct e1000e_tx),
  479. VMSTATE_UINT16(props.mss, struct e1000e_tx),
  480. VMSTATE_UINT32(props.paylen, struct e1000e_tx),
  481. VMSTATE_INT8(props.ip, struct e1000e_tx),
  482. VMSTATE_INT8(props.tcp, struct e1000e_tx),
  483. VMSTATE_BOOL(props.tse, struct e1000e_tx),
  484. VMSTATE_BOOL(cptse, struct e1000e_tx),
  485. VMSTATE_BOOL(skip_cp, struct e1000e_tx),
  486. VMSTATE_END_OF_LIST()
  487. }
  488. };
  489. static const VMStateDescription e1000e_vmstate_intr_timer = {
  490. .name = "e1000e-intr-timer",
  491. .version_id = 1,
  492. .minimum_version_id = 1,
  493. .fields = (VMStateField[]) {
  494. VMSTATE_TIMER_PTR(timer, E1000IntrDelayTimer),
  495. VMSTATE_BOOL(running, E1000IntrDelayTimer),
  496. VMSTATE_END_OF_LIST()
  497. }
  498. };
  499. #define VMSTATE_E1000E_INTR_DELAY_TIMER(_f, _s) \
  500. VMSTATE_STRUCT(_f, _s, 0, \
  501. e1000e_vmstate_intr_timer, E1000IntrDelayTimer)
  502. #define VMSTATE_E1000E_INTR_DELAY_TIMER_ARRAY(_f, _s, _num) \
  503. VMSTATE_STRUCT_ARRAY(_f, _s, _num, 0, \
  504. e1000e_vmstate_intr_timer, E1000IntrDelayTimer)
  505. static const VMStateDescription e1000e_vmstate = {
  506. .name = "e1000e",
  507. .version_id = 1,
  508. .minimum_version_id = 1,
  509. .pre_save = e1000e_pre_save,
  510. .post_load = e1000e_post_load,
  511. .fields = (VMStateField[]) {
  512. VMSTATE_PCI_DEVICE(parent_obj, E1000EState),
  513. VMSTATE_MSIX(parent_obj, E1000EState),
  514. VMSTATE_UINT32(ioaddr, E1000EState),
  515. VMSTATE_UINT32(core.rxbuf_min_shift, E1000EState),
  516. VMSTATE_UINT8(core.rx_desc_len, E1000EState),
  517. VMSTATE_UINT32_ARRAY(core.rxbuf_sizes, E1000EState,
  518. E1000_PSRCTL_BUFFS_PER_DESC),
  519. VMSTATE_UINT32(core.rx_desc_buf_size, E1000EState),
  520. VMSTATE_UINT16_ARRAY(core.eeprom, E1000EState, E1000E_EEPROM_SIZE),
  521. VMSTATE_UINT16_2DARRAY(core.phy, E1000EState,
  522. E1000E_PHY_PAGES, E1000E_PHY_PAGE_SIZE),
  523. VMSTATE_UINT32_ARRAY(core.mac, E1000EState, E1000E_MAC_SIZE),
  524. VMSTATE_UINT8_ARRAY(core.permanent_mac, E1000EState, ETH_ALEN),
  525. VMSTATE_UINT32(core.delayed_causes, E1000EState),
  526. VMSTATE_UINT16(subsys, E1000EState),
  527. VMSTATE_UINT16(subsys_ven, E1000EState),
  528. VMSTATE_E1000E_INTR_DELAY_TIMER(core.rdtr, E1000EState),
  529. VMSTATE_E1000E_INTR_DELAY_TIMER(core.radv, E1000EState),
  530. VMSTATE_E1000E_INTR_DELAY_TIMER(core.raid, E1000EState),
  531. VMSTATE_E1000E_INTR_DELAY_TIMER(core.tadv, E1000EState),
  532. VMSTATE_E1000E_INTR_DELAY_TIMER(core.tidv, E1000EState),
  533. VMSTATE_E1000E_INTR_DELAY_TIMER(core.itr, E1000EState),
  534. VMSTATE_UNUSED(1),
  535. VMSTATE_E1000E_INTR_DELAY_TIMER_ARRAY(core.eitr, E1000EState,
  536. E1000E_MSIX_VEC_NUM),
  537. VMSTATE_UNUSED(E1000E_MSIX_VEC_NUM),
  538. VMSTATE_UINT32(core.itr_guest_value, E1000EState),
  539. VMSTATE_UINT32_ARRAY(core.eitr_guest_value, E1000EState,
  540. E1000E_MSIX_VEC_NUM),
  541. VMSTATE_UINT16(core.vet, E1000EState),
  542. VMSTATE_STRUCT_ARRAY(core.tx, E1000EState, E1000E_NUM_QUEUES, 0,
  543. e1000e_vmstate_tx, struct e1000e_tx),
  544. VMSTATE_INT64_TEST(core.timadj, E1000EState, e1000e_migrate_timadj),
  545. VMSTATE_END_OF_LIST()
  546. }
  547. };
  548. static PropertyInfo e1000e_prop_disable_vnet,
  549. e1000e_prop_subsys_ven,
  550. e1000e_prop_subsys;
  551. static Property e1000e_properties[] = {
  552. DEFINE_NIC_PROPERTIES(E1000EState, conf),
  553. DEFINE_PROP_SIGNED("disable_vnet_hdr", E1000EState, disable_vnet, false,
  554. e1000e_prop_disable_vnet, bool),
  555. DEFINE_PROP_SIGNED("subsys_ven", E1000EState, subsys_ven,
  556. PCI_VENDOR_ID_INTEL,
  557. e1000e_prop_subsys_ven, uint16_t),
  558. DEFINE_PROP_SIGNED("subsys", E1000EState, subsys, 0,
  559. e1000e_prop_subsys, uint16_t),
  560. DEFINE_PROP_BOOL("init-vet", E1000EState, init_vet, true),
  561. DEFINE_PROP_BOOL("migrate-timadj", E1000EState, timadj, true),
  562. DEFINE_PROP_END_OF_LIST(),
  563. };
  564. static void e1000e_class_init(ObjectClass *class, void *data)
  565. {
  566. DeviceClass *dc = DEVICE_CLASS(class);
  567. ResettableClass *rc = RESETTABLE_CLASS(class);
  568. PCIDeviceClass *c = PCI_DEVICE_CLASS(class);
  569. c->realize = e1000e_pci_realize;
  570. c->exit = e1000e_pci_uninit;
  571. c->vendor_id = PCI_VENDOR_ID_INTEL;
  572. c->device_id = E1000_DEV_ID_82574L;
  573. c->revision = 0;
  574. c->romfile = "efi-e1000e.rom";
  575. c->class_id = PCI_CLASS_NETWORK_ETHERNET;
  576. rc->phases.hold = e1000e_qdev_reset_hold;
  577. dc->desc = "Intel 82574L GbE Controller";
  578. dc->vmsd = &e1000e_vmstate;
  579. e1000e_prop_disable_vnet = qdev_prop_uint8;
  580. e1000e_prop_disable_vnet.description = "Do not use virtio headers, "
  581. "perform SW offloads emulation "
  582. "instead";
  583. e1000e_prop_subsys_ven = qdev_prop_uint16;
  584. e1000e_prop_subsys_ven.description = "PCI device Subsystem Vendor ID";
  585. e1000e_prop_subsys = qdev_prop_uint16;
  586. e1000e_prop_subsys.description = "PCI device Subsystem ID";
  587. device_class_set_props(dc, e1000e_properties);
  588. set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
  589. }
  590. static void e1000e_instance_init(Object *obj)
  591. {
  592. E1000EState *s = E1000E(obj);
  593. device_add_bootindex_property(obj, &s->conf.bootindex,
  594. "bootindex", "/ethernet-phy@0",
  595. DEVICE(obj));
  596. }
  597. static const TypeInfo e1000e_info = {
  598. .name = TYPE_E1000E,
  599. .parent = TYPE_PCI_DEVICE,
  600. .instance_size = sizeof(E1000EState),
  601. .class_init = e1000e_class_init,
  602. .instance_init = e1000e_instance_init,
  603. .interfaces = (InterfaceInfo[]) {
  604. { INTERFACE_PCIE_DEVICE },
  605. { }
  606. },
  607. };
  608. static void e1000e_register_types(void)
  609. {
  610. type_register_static(&e1000e_info);
  611. }
  612. type_init(e1000e_register_types)