16f3fbe4eSDmitry Fleytman /* 26f3fbe4eSDmitry Fleytman * QEMU INTEL 82574 GbE NIC emulation 36f3fbe4eSDmitry Fleytman * 46f3fbe4eSDmitry Fleytman * Software developer's manuals: 56f3fbe4eSDmitry Fleytman * http://www.intel.com/content/dam/doc/datasheet/82574l-gbe-controller-datasheet.pdf 66f3fbe4eSDmitry Fleytman * 76f3fbe4eSDmitry Fleytman * Copyright (c) 2015 Ravello Systems LTD (http://ravellosystems.com) 86f3fbe4eSDmitry Fleytman * Developed by Daynix Computing LTD (http://www.daynix.com) 96f3fbe4eSDmitry Fleytman * 106f3fbe4eSDmitry Fleytman * Authors: 116f3fbe4eSDmitry Fleytman * Dmitry Fleytman <dmitry@daynix.com> 126f3fbe4eSDmitry Fleytman * Leonid Bloch <leonid@daynix.com> 136f3fbe4eSDmitry Fleytman * Yan Vugenfirer <yan@daynix.com> 146f3fbe4eSDmitry Fleytman * 156f3fbe4eSDmitry Fleytman * Based on work done by: 166f3fbe4eSDmitry Fleytman * Nir Peleg, Tutis Systems Ltd. for Qumranet Inc. 176f3fbe4eSDmitry Fleytman * Copyright (c) 2008 Qumranet 186f3fbe4eSDmitry Fleytman * Based on work done by: 196f3fbe4eSDmitry Fleytman * Copyright (c) 2007 Dan Aloni 206f3fbe4eSDmitry Fleytman * Copyright (c) 2004 Antony T Curtis 216f3fbe4eSDmitry Fleytman * 226f3fbe4eSDmitry Fleytman * This library is free software; you can redistribute it and/or 236f3fbe4eSDmitry Fleytman * modify it under the terms of the GNU Lesser General Public 246f3fbe4eSDmitry Fleytman * License as published by the Free Software Foundation; either 256f3fbe4eSDmitry Fleytman * version 2 of the License, or (at your option) any later version. 266f3fbe4eSDmitry Fleytman * 276f3fbe4eSDmitry Fleytman * This library is distributed in the hope that it will be useful, 286f3fbe4eSDmitry Fleytman * but WITHOUT ANY WARRANTY; without even the implied warranty of 296f3fbe4eSDmitry Fleytman * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 306f3fbe4eSDmitry Fleytman * Lesser General Public License for more details. 316f3fbe4eSDmitry Fleytman * 326f3fbe4eSDmitry Fleytman * You should have received a copy of the GNU Lesser General Public 336f3fbe4eSDmitry Fleytman * License along with this library; if not, see <http://www.gnu.org/licenses/>. 346f3fbe4eSDmitry Fleytman */ 356f3fbe4eSDmitry Fleytman 366f3fbe4eSDmitry Fleytman #include "qemu/osdep.h" 376f3fbe4eSDmitry Fleytman #include "net/net.h" 386f3fbe4eSDmitry Fleytman #include "net/tap.h" 396f3fbe4eSDmitry Fleytman #include "qemu/range.h" 406f3fbe4eSDmitry Fleytman #include "sysemu/sysemu.h" 416f3fbe4eSDmitry Fleytman #include "hw/pci/msi.h" 426f3fbe4eSDmitry Fleytman #include "hw/pci/msix.h" 436f3fbe4eSDmitry Fleytman 446f3fbe4eSDmitry Fleytman #include "hw/net/e1000_regs.h" 456f3fbe4eSDmitry Fleytman 466f3fbe4eSDmitry Fleytman #include "e1000x_common.h" 476f3fbe4eSDmitry Fleytman #include "e1000e_core.h" 486f3fbe4eSDmitry Fleytman 496f3fbe4eSDmitry Fleytman #include "trace.h" 506f3fbe4eSDmitry Fleytman 516f3fbe4eSDmitry Fleytman #define TYPE_E1000E "e1000e" 526f3fbe4eSDmitry Fleytman #define E1000E(obj) OBJECT_CHECK(E1000EState, (obj), TYPE_E1000E) 536f3fbe4eSDmitry Fleytman 546f3fbe4eSDmitry Fleytman typedef struct E1000EState { 556f3fbe4eSDmitry Fleytman PCIDevice parent_obj; 566f3fbe4eSDmitry Fleytman NICState *nic; 576f3fbe4eSDmitry Fleytman NICConf conf; 586f3fbe4eSDmitry Fleytman 596f3fbe4eSDmitry Fleytman MemoryRegion mmio; 606f3fbe4eSDmitry Fleytman MemoryRegion flash; 616f3fbe4eSDmitry Fleytman MemoryRegion io; 626f3fbe4eSDmitry Fleytman MemoryRegion msix; 636f3fbe4eSDmitry Fleytman 646f3fbe4eSDmitry Fleytman uint32_t ioaddr; 656f3fbe4eSDmitry Fleytman 666f3fbe4eSDmitry Fleytman uint16_t subsys_ven; 676f3fbe4eSDmitry Fleytman uint16_t subsys; 686f3fbe4eSDmitry Fleytman 696f3fbe4eSDmitry Fleytman uint16_t subsys_ven_used; 706f3fbe4eSDmitry Fleytman uint16_t subsys_used; 716f3fbe4eSDmitry Fleytman 726f3fbe4eSDmitry Fleytman uint32_t intr_state; 736f3fbe4eSDmitry Fleytman bool disable_vnet; 746f3fbe4eSDmitry Fleytman 756f3fbe4eSDmitry Fleytman E1000ECore core; 766f3fbe4eSDmitry Fleytman 776f3fbe4eSDmitry Fleytman } E1000EState; 786f3fbe4eSDmitry Fleytman 796f3fbe4eSDmitry Fleytman #define E1000E_MMIO_IDX 0 806f3fbe4eSDmitry Fleytman #define E1000E_FLASH_IDX 1 816f3fbe4eSDmitry Fleytman #define E1000E_IO_IDX 2 826f3fbe4eSDmitry Fleytman #define E1000E_MSIX_IDX 3 836f3fbe4eSDmitry Fleytman 846f3fbe4eSDmitry Fleytman #define E1000E_MMIO_SIZE (128 * 1024) 856f3fbe4eSDmitry Fleytman #define E1000E_FLASH_SIZE (128 * 1024) 866f3fbe4eSDmitry Fleytman #define E1000E_IO_SIZE (32) 876f3fbe4eSDmitry Fleytman #define E1000E_MSIX_SIZE (16 * 1024) 886f3fbe4eSDmitry Fleytman 896f3fbe4eSDmitry Fleytman #define E1000E_MSIX_TABLE (0x0000) 906f3fbe4eSDmitry Fleytman #define E1000E_MSIX_PBA (0x2000) 916f3fbe4eSDmitry Fleytman 926f3fbe4eSDmitry Fleytman #define E1000E_USE_MSI BIT(0) 936f3fbe4eSDmitry Fleytman #define E1000E_USE_MSIX BIT(1) 946f3fbe4eSDmitry Fleytman 956f3fbe4eSDmitry Fleytman static uint64_t 966f3fbe4eSDmitry Fleytman e1000e_mmio_read(void *opaque, hwaddr addr, unsigned size) 976f3fbe4eSDmitry Fleytman { 986f3fbe4eSDmitry Fleytman E1000EState *s = opaque; 996f3fbe4eSDmitry Fleytman return e1000e_core_read(&s->core, addr, size); 1006f3fbe4eSDmitry Fleytman } 1016f3fbe4eSDmitry Fleytman 1026f3fbe4eSDmitry Fleytman static void 1036f3fbe4eSDmitry Fleytman e1000e_mmio_write(void *opaque, hwaddr addr, 1046f3fbe4eSDmitry Fleytman uint64_t val, unsigned size) 1056f3fbe4eSDmitry Fleytman { 1066f3fbe4eSDmitry Fleytman E1000EState *s = opaque; 1076f3fbe4eSDmitry Fleytman e1000e_core_write(&s->core, addr, val, size); 1086f3fbe4eSDmitry Fleytman } 1096f3fbe4eSDmitry Fleytman 1106f3fbe4eSDmitry Fleytman static bool 1116f3fbe4eSDmitry Fleytman e1000e_io_get_reg_index(E1000EState *s, uint32_t *idx) 1126f3fbe4eSDmitry Fleytman { 1136f3fbe4eSDmitry Fleytman if (s->ioaddr < 0x1FFFF) { 1146f3fbe4eSDmitry Fleytman *idx = s->ioaddr; 1156f3fbe4eSDmitry Fleytman return true; 1166f3fbe4eSDmitry Fleytman } 1176f3fbe4eSDmitry Fleytman 1186f3fbe4eSDmitry Fleytman if (s->ioaddr < 0x7FFFF) { 1196f3fbe4eSDmitry Fleytman trace_e1000e_wrn_io_addr_undefined(s->ioaddr); 1206f3fbe4eSDmitry Fleytman return false; 1216f3fbe4eSDmitry Fleytman } 1226f3fbe4eSDmitry Fleytman 1236f3fbe4eSDmitry Fleytman if (s->ioaddr < 0xFFFFF) { 1246f3fbe4eSDmitry Fleytman trace_e1000e_wrn_io_addr_flash(s->ioaddr); 1256f3fbe4eSDmitry Fleytman return false; 1266f3fbe4eSDmitry Fleytman } 1276f3fbe4eSDmitry Fleytman 1286f3fbe4eSDmitry Fleytman trace_e1000e_wrn_io_addr_unknown(s->ioaddr); 1296f3fbe4eSDmitry Fleytman return false; 1306f3fbe4eSDmitry Fleytman } 1316f3fbe4eSDmitry Fleytman 1326f3fbe4eSDmitry Fleytman static uint64_t 1336f3fbe4eSDmitry Fleytman e1000e_io_read(void *opaque, hwaddr addr, unsigned size) 1346f3fbe4eSDmitry Fleytman { 1356f3fbe4eSDmitry Fleytman E1000EState *s = opaque; 136de5dca1bSDmitry Fleytman uint32_t idx = 0; 1376f3fbe4eSDmitry Fleytman uint64_t val; 1386f3fbe4eSDmitry Fleytman 1396f3fbe4eSDmitry Fleytman switch (addr) { 1406f3fbe4eSDmitry Fleytman case E1000_IOADDR: 1416f3fbe4eSDmitry Fleytman trace_e1000e_io_read_addr(s->ioaddr); 1426f3fbe4eSDmitry Fleytman return s->ioaddr; 1436f3fbe4eSDmitry Fleytman case E1000_IODATA: 1446f3fbe4eSDmitry Fleytman if (e1000e_io_get_reg_index(s, &idx)) { 1456f3fbe4eSDmitry Fleytman val = e1000e_core_read(&s->core, idx, sizeof(val)); 1466f3fbe4eSDmitry Fleytman trace_e1000e_io_read_data(idx, val); 1476f3fbe4eSDmitry Fleytman return val; 1486f3fbe4eSDmitry Fleytman } 1496f3fbe4eSDmitry Fleytman return 0; 1506f3fbe4eSDmitry Fleytman default: 1516f3fbe4eSDmitry Fleytman trace_e1000e_wrn_io_read_unknown(addr); 1526f3fbe4eSDmitry Fleytman return 0; 1536f3fbe4eSDmitry Fleytman } 1546f3fbe4eSDmitry Fleytman } 1556f3fbe4eSDmitry Fleytman 1566f3fbe4eSDmitry Fleytman static void 1576f3fbe4eSDmitry Fleytman e1000e_io_write(void *opaque, hwaddr addr, 1586f3fbe4eSDmitry Fleytman uint64_t val, unsigned size) 1596f3fbe4eSDmitry Fleytman { 1606f3fbe4eSDmitry Fleytman E1000EState *s = opaque; 161de5dca1bSDmitry Fleytman uint32_t idx = 0; 1626f3fbe4eSDmitry Fleytman 1636f3fbe4eSDmitry Fleytman switch (addr) { 1646f3fbe4eSDmitry Fleytman case E1000_IOADDR: 1656f3fbe4eSDmitry Fleytman trace_e1000e_io_write_addr(val); 1666f3fbe4eSDmitry Fleytman s->ioaddr = (uint32_t) val; 1676f3fbe4eSDmitry Fleytman return; 1686f3fbe4eSDmitry Fleytman case E1000_IODATA: 1696f3fbe4eSDmitry Fleytman if (e1000e_io_get_reg_index(s, &idx)) { 1706f3fbe4eSDmitry Fleytman trace_e1000e_io_write_data(idx, val); 1716f3fbe4eSDmitry Fleytman e1000e_core_write(&s->core, idx, val, sizeof(val)); 1726f3fbe4eSDmitry Fleytman } 1736f3fbe4eSDmitry Fleytman return; 1746f3fbe4eSDmitry Fleytman default: 1756f3fbe4eSDmitry Fleytman trace_e1000e_wrn_io_write_unknown(addr); 1766f3fbe4eSDmitry Fleytman return; 1776f3fbe4eSDmitry Fleytman } 1786f3fbe4eSDmitry Fleytman } 1796f3fbe4eSDmitry Fleytman 1806f3fbe4eSDmitry Fleytman static const MemoryRegionOps mmio_ops = { 1816f3fbe4eSDmitry Fleytman .read = e1000e_mmio_read, 1826f3fbe4eSDmitry Fleytman .write = e1000e_mmio_write, 1836f3fbe4eSDmitry Fleytman .endianness = DEVICE_LITTLE_ENDIAN, 1846f3fbe4eSDmitry Fleytman .impl = { 1856f3fbe4eSDmitry Fleytman .min_access_size = 4, 1866f3fbe4eSDmitry Fleytman .max_access_size = 4, 1876f3fbe4eSDmitry Fleytman }, 1886f3fbe4eSDmitry Fleytman }; 1896f3fbe4eSDmitry Fleytman 1906f3fbe4eSDmitry Fleytman static const MemoryRegionOps io_ops = { 1916f3fbe4eSDmitry Fleytman .read = e1000e_io_read, 1926f3fbe4eSDmitry Fleytman .write = e1000e_io_write, 1936f3fbe4eSDmitry Fleytman .endianness = DEVICE_LITTLE_ENDIAN, 1946f3fbe4eSDmitry Fleytman .impl = { 1956f3fbe4eSDmitry Fleytman .min_access_size = 4, 1966f3fbe4eSDmitry Fleytman .max_access_size = 4, 1976f3fbe4eSDmitry Fleytman }, 1986f3fbe4eSDmitry Fleytman }; 1996f3fbe4eSDmitry Fleytman 2006f3fbe4eSDmitry Fleytman static int 2016f3fbe4eSDmitry Fleytman e1000e_nc_can_receive(NetClientState *nc) 2026f3fbe4eSDmitry Fleytman { 2036f3fbe4eSDmitry Fleytman E1000EState *s = qemu_get_nic_opaque(nc); 2046f3fbe4eSDmitry Fleytman return e1000e_can_receive(&s->core); 2056f3fbe4eSDmitry Fleytman } 2066f3fbe4eSDmitry Fleytman 2076f3fbe4eSDmitry Fleytman static ssize_t 2086f3fbe4eSDmitry Fleytman e1000e_nc_receive_iov(NetClientState *nc, const struct iovec *iov, int iovcnt) 2096f3fbe4eSDmitry Fleytman { 2106f3fbe4eSDmitry Fleytman E1000EState *s = qemu_get_nic_opaque(nc); 2116f3fbe4eSDmitry Fleytman return e1000e_receive_iov(&s->core, iov, iovcnt); 2126f3fbe4eSDmitry Fleytman } 2136f3fbe4eSDmitry Fleytman 2146f3fbe4eSDmitry Fleytman static ssize_t 2156f3fbe4eSDmitry Fleytman e1000e_nc_receive(NetClientState *nc, const uint8_t *buf, size_t size) 2166f3fbe4eSDmitry Fleytman { 2176f3fbe4eSDmitry Fleytman E1000EState *s = qemu_get_nic_opaque(nc); 2186f3fbe4eSDmitry Fleytman return e1000e_receive(&s->core, buf, size); 2196f3fbe4eSDmitry Fleytman } 2206f3fbe4eSDmitry Fleytman 2216f3fbe4eSDmitry Fleytman static void 2226f3fbe4eSDmitry Fleytman e1000e_set_link_status(NetClientState *nc) 2236f3fbe4eSDmitry Fleytman { 2246f3fbe4eSDmitry Fleytman E1000EState *s = qemu_get_nic_opaque(nc); 2256f3fbe4eSDmitry Fleytman e1000e_core_set_link_status(&s->core); 2266f3fbe4eSDmitry Fleytman } 2276f3fbe4eSDmitry Fleytman 2286f3fbe4eSDmitry Fleytman static NetClientInfo net_e1000e_info = { 2296f3fbe4eSDmitry Fleytman .type = NET_CLIENT_OPTIONS_KIND_NIC, 2306f3fbe4eSDmitry Fleytman .size = sizeof(NICState), 2316f3fbe4eSDmitry Fleytman .can_receive = e1000e_nc_can_receive, 2326f3fbe4eSDmitry Fleytman .receive = e1000e_nc_receive, 2336f3fbe4eSDmitry Fleytman .receive_iov = e1000e_nc_receive_iov, 2346f3fbe4eSDmitry Fleytman .link_status_changed = e1000e_set_link_status, 2356f3fbe4eSDmitry Fleytman }; 2366f3fbe4eSDmitry Fleytman 2376f3fbe4eSDmitry Fleytman /* 2386f3fbe4eSDmitry Fleytman * EEPROM (NVM) contents documented in Table 36, section 6.1 2396f3fbe4eSDmitry Fleytman * and generally 6.1.2 Software accessed words. 2406f3fbe4eSDmitry Fleytman */ 2416f3fbe4eSDmitry Fleytman static const uint16_t e1000e_eeprom_template[64] = { 2426f3fbe4eSDmitry Fleytman /* Address | Compat. | ImVer | Compat. */ 2436f3fbe4eSDmitry Fleytman 0x0000, 0x0000, 0x0000, 0x0420, 0xf746, 0x2010, 0xffff, 0xffff, 2446f3fbe4eSDmitry Fleytman /* PBA |ICtrl1 | SSID | SVID | DevID |-------|ICtrl2 */ 2456f3fbe4eSDmitry Fleytman 0x0000, 0x0000, 0x026b, 0x0000, 0x8086, 0x0000, 0x0000, 0x8058, 2466f3fbe4eSDmitry Fleytman /* NVM words 1,2,3 |-------------------------------|PCI-EID*/ 2476f3fbe4eSDmitry Fleytman 0x0000, 0x2001, 0x7e7c, 0xffff, 0x1000, 0x00c8, 0x0000, 0x2704, 2486f3fbe4eSDmitry Fleytman /* PCIe Init. Conf 1,2,3 |PCICtrl|PHY|LD1|-------| RevID | LD0,2 */ 2496f3fbe4eSDmitry Fleytman 0x6cc9, 0x3150, 0x070e, 0x460b, 0x2d84, 0x0100, 0xf000, 0x0706, 2506f3fbe4eSDmitry Fleytman /* FLPAR |FLANADD|LAN-PWR|FlVndr |ICtrl3 |APTSMBA|APTRxEP|APTSMBC*/ 2516f3fbe4eSDmitry Fleytman 0x6000, 0x0080, 0x0f04, 0x7fff, 0x4f01, 0xc600, 0x0000, 0x20ff, 2526f3fbe4eSDmitry Fleytman /* APTIF | APTMC |APTuCP |LSWFWID|MSWFWID|NC-SIMC|NC-SIC | VPDP */ 2536f3fbe4eSDmitry Fleytman 0x0028, 0x0003, 0x0000, 0x0000, 0x0000, 0x0003, 0x0000, 0xffff, 2546f3fbe4eSDmitry Fleytman /* SW Section */ 2556f3fbe4eSDmitry Fleytman 0x0100, 0xc000, 0x121c, 0xc007, 0xffff, 0xffff, 0xffff, 0xffff, 2566f3fbe4eSDmitry Fleytman /* SW Section |CHKSUM */ 2576f3fbe4eSDmitry Fleytman 0xffff, 0xffff, 0xffff, 0xffff, 0x0000, 0x0120, 0xffff, 0x0000, 2586f3fbe4eSDmitry Fleytman }; 2596f3fbe4eSDmitry Fleytman 2606f3fbe4eSDmitry Fleytman static void e1000e_core_realize(E1000EState *s) 2616f3fbe4eSDmitry Fleytman { 2626f3fbe4eSDmitry Fleytman s->core.owner = &s->parent_obj; 2636f3fbe4eSDmitry Fleytman s->core.owner_nic = s->nic; 2646f3fbe4eSDmitry Fleytman } 2656f3fbe4eSDmitry Fleytman 2666f3fbe4eSDmitry Fleytman static void 2676f3fbe4eSDmitry Fleytman e1000e_init_msi(E1000EState *s) 2686f3fbe4eSDmitry Fleytman { 2696f3fbe4eSDmitry Fleytman int res; 2706f3fbe4eSDmitry Fleytman 2716f3fbe4eSDmitry Fleytman res = msi_init(PCI_DEVICE(s), 2726f3fbe4eSDmitry Fleytman 0xD0, /* MSI capability offset */ 2736f3fbe4eSDmitry Fleytman 1, /* MAC MSI interrupts */ 2746f3fbe4eSDmitry Fleytman true, /* 64-bit message addresses supported */ 2756f3fbe4eSDmitry Fleytman false); /* Per vector mask supported */ 2766f3fbe4eSDmitry Fleytman 2776f3fbe4eSDmitry Fleytman if (res > 0) { 2786f3fbe4eSDmitry Fleytman s->intr_state |= E1000E_USE_MSI; 2796f3fbe4eSDmitry Fleytman } else { 2806f3fbe4eSDmitry Fleytman trace_e1000e_msi_init_fail(res); 2816f3fbe4eSDmitry Fleytman } 2826f3fbe4eSDmitry Fleytman } 2836f3fbe4eSDmitry Fleytman 2846f3fbe4eSDmitry Fleytman static void 2856f3fbe4eSDmitry Fleytman e1000e_cleanup_msi(E1000EState *s) 2866f3fbe4eSDmitry Fleytman { 2876f3fbe4eSDmitry Fleytman if (s->intr_state & E1000E_USE_MSI) { 2886f3fbe4eSDmitry Fleytman msi_uninit(PCI_DEVICE(s)); 2896f3fbe4eSDmitry Fleytman } 2906f3fbe4eSDmitry Fleytman } 2916f3fbe4eSDmitry Fleytman 2926f3fbe4eSDmitry Fleytman static void 2936f3fbe4eSDmitry Fleytman e1000e_unuse_msix_vectors(E1000EState *s, int num_vectors) 2946f3fbe4eSDmitry Fleytman { 2956f3fbe4eSDmitry Fleytman int i; 2966f3fbe4eSDmitry Fleytman for (i = 0; i < num_vectors; i++) { 2976f3fbe4eSDmitry Fleytman msix_vector_unuse(PCI_DEVICE(s), i); 2986f3fbe4eSDmitry Fleytman } 2996f3fbe4eSDmitry Fleytman } 3006f3fbe4eSDmitry Fleytman 3016f3fbe4eSDmitry Fleytman static bool 3026f3fbe4eSDmitry Fleytman e1000e_use_msix_vectors(E1000EState *s, int num_vectors) 3036f3fbe4eSDmitry Fleytman { 3046f3fbe4eSDmitry Fleytman int i; 3056f3fbe4eSDmitry Fleytman for (i = 0; i < num_vectors; i++) { 3066f3fbe4eSDmitry Fleytman int res = msix_vector_use(PCI_DEVICE(s), i); 3076f3fbe4eSDmitry Fleytman if (res < 0) { 3086f3fbe4eSDmitry Fleytman trace_e1000e_msix_use_vector_fail(i, res); 3096f3fbe4eSDmitry Fleytman e1000e_unuse_msix_vectors(s, i); 3106f3fbe4eSDmitry Fleytman return false; 3116f3fbe4eSDmitry Fleytman } 3126f3fbe4eSDmitry Fleytman } 3136f3fbe4eSDmitry Fleytman return true; 3146f3fbe4eSDmitry Fleytman } 3156f3fbe4eSDmitry Fleytman 3166f3fbe4eSDmitry Fleytman static void 3176f3fbe4eSDmitry Fleytman e1000e_init_msix(E1000EState *s) 3186f3fbe4eSDmitry Fleytman { 3196f3fbe4eSDmitry Fleytman PCIDevice *d = PCI_DEVICE(s); 3206f3fbe4eSDmitry Fleytman int res = msix_init(PCI_DEVICE(s), E1000E_MSIX_VEC_NUM, 3216f3fbe4eSDmitry Fleytman &s->msix, 3226f3fbe4eSDmitry Fleytman E1000E_MSIX_IDX, E1000E_MSIX_TABLE, 3236f3fbe4eSDmitry Fleytman &s->msix, 3246f3fbe4eSDmitry Fleytman E1000E_MSIX_IDX, E1000E_MSIX_PBA, 3256f3fbe4eSDmitry Fleytman 0xA0); 3266f3fbe4eSDmitry Fleytman 3276f3fbe4eSDmitry Fleytman if (res < 0) { 3286f3fbe4eSDmitry Fleytman trace_e1000e_msix_init_fail(res); 3296f3fbe4eSDmitry Fleytman } else { 3306f3fbe4eSDmitry Fleytman if (!e1000e_use_msix_vectors(s, E1000E_MSIX_VEC_NUM)) { 3316f3fbe4eSDmitry Fleytman msix_uninit(d, &s->msix, &s->msix); 3326f3fbe4eSDmitry Fleytman } else { 3336f3fbe4eSDmitry Fleytman s->intr_state |= E1000E_USE_MSIX; 3346f3fbe4eSDmitry Fleytman } 3356f3fbe4eSDmitry Fleytman } 3366f3fbe4eSDmitry Fleytman } 3376f3fbe4eSDmitry Fleytman 3386f3fbe4eSDmitry Fleytman static void 3396f3fbe4eSDmitry Fleytman e1000e_cleanup_msix(E1000EState *s) 3406f3fbe4eSDmitry Fleytman { 3416f3fbe4eSDmitry Fleytman if (s->intr_state & E1000E_USE_MSIX) { 3426f3fbe4eSDmitry Fleytman e1000e_unuse_msix_vectors(s, E1000E_MSIX_VEC_NUM); 3436f3fbe4eSDmitry Fleytman msix_uninit(PCI_DEVICE(s), &s->msix, &s->msix); 3446f3fbe4eSDmitry Fleytman } 3456f3fbe4eSDmitry Fleytman } 3466f3fbe4eSDmitry Fleytman 3476f3fbe4eSDmitry Fleytman static void 3486f3fbe4eSDmitry Fleytman e1000e_init_net_peer(E1000EState *s, PCIDevice *pci_dev, uint8_t *macaddr) 3496f3fbe4eSDmitry Fleytman { 3506f3fbe4eSDmitry Fleytman DeviceState *dev = DEVICE(pci_dev); 3516f3fbe4eSDmitry Fleytman NetClientState *nc; 3526f3fbe4eSDmitry Fleytman int i; 3536f3fbe4eSDmitry Fleytman 3546f3fbe4eSDmitry Fleytman s->nic = qemu_new_nic(&net_e1000e_info, &s->conf, 3556f3fbe4eSDmitry Fleytman object_get_typename(OBJECT(s)), dev->id, s); 3566f3fbe4eSDmitry Fleytman 3576f3fbe4eSDmitry Fleytman s->core.max_queue_num = s->conf.peers.queues - 1; 3586f3fbe4eSDmitry Fleytman 3596f3fbe4eSDmitry Fleytman trace_e1000e_mac_set_permanent(MAC_ARG(macaddr)); 3606f3fbe4eSDmitry Fleytman memcpy(s->core.permanent_mac, macaddr, sizeof(s->core.permanent_mac)); 3616f3fbe4eSDmitry Fleytman 3626f3fbe4eSDmitry Fleytman qemu_format_nic_info_str(qemu_get_queue(s->nic), macaddr); 3636f3fbe4eSDmitry Fleytman 3646f3fbe4eSDmitry Fleytman /* Setup virtio headers */ 3656f3fbe4eSDmitry Fleytman if (s->disable_vnet) { 3666f3fbe4eSDmitry Fleytman s->core.has_vnet = false; 3676f3fbe4eSDmitry Fleytman trace_e1000e_cfg_support_virtio(false); 3686f3fbe4eSDmitry Fleytman return; 3696f3fbe4eSDmitry Fleytman } else { 3706f3fbe4eSDmitry Fleytman s->core.has_vnet = true; 3716f3fbe4eSDmitry Fleytman } 3726f3fbe4eSDmitry Fleytman 3736f3fbe4eSDmitry Fleytman for (i = 0; i < s->conf.peers.queues; i++) { 3746f3fbe4eSDmitry Fleytman nc = qemu_get_subqueue(s->nic, i); 3756f3fbe4eSDmitry Fleytman if (!nc->peer || !qemu_has_vnet_hdr(nc->peer)) { 3766f3fbe4eSDmitry Fleytman s->core.has_vnet = false; 3776f3fbe4eSDmitry Fleytman trace_e1000e_cfg_support_virtio(false); 3786f3fbe4eSDmitry Fleytman return; 3796f3fbe4eSDmitry Fleytman } 3806f3fbe4eSDmitry Fleytman } 3816f3fbe4eSDmitry Fleytman 3826f3fbe4eSDmitry Fleytman trace_e1000e_cfg_support_virtio(true); 3836f3fbe4eSDmitry Fleytman 3846f3fbe4eSDmitry Fleytman for (i = 0; i < s->conf.peers.queues; i++) { 3856f3fbe4eSDmitry Fleytman nc = qemu_get_subqueue(s->nic, i); 3866f3fbe4eSDmitry Fleytman qemu_set_vnet_hdr_len(nc->peer, sizeof(struct virtio_net_hdr)); 3876f3fbe4eSDmitry Fleytman qemu_using_vnet_hdr(nc->peer, true); 3886f3fbe4eSDmitry Fleytman } 3896f3fbe4eSDmitry Fleytman } 3906f3fbe4eSDmitry Fleytman 3916f3fbe4eSDmitry Fleytman static inline uint64_t 3926f3fbe4eSDmitry Fleytman e1000e_gen_dsn(uint8_t *mac) 3936f3fbe4eSDmitry Fleytman { 3946f3fbe4eSDmitry Fleytman return (uint64_t)(mac[5]) | 3956f3fbe4eSDmitry Fleytman (uint64_t)(mac[4]) << 8 | 3966f3fbe4eSDmitry Fleytman (uint64_t)(mac[3]) << 16 | 3976f3fbe4eSDmitry Fleytman (uint64_t)(0x00FF) << 24 | 3986f3fbe4eSDmitry Fleytman (uint64_t)(0x00FF) << 32 | 3996f3fbe4eSDmitry Fleytman (uint64_t)(mac[2]) << 40 | 4006f3fbe4eSDmitry Fleytman (uint64_t)(mac[1]) << 48 | 4016f3fbe4eSDmitry Fleytman (uint64_t)(mac[0]) << 56; 4026f3fbe4eSDmitry Fleytman } 4036f3fbe4eSDmitry Fleytman 4046f3fbe4eSDmitry Fleytman static int 4056f3fbe4eSDmitry Fleytman e1000e_add_pm_capability(PCIDevice *pdev, uint8_t offset, uint16_t pmc) 4066f3fbe4eSDmitry Fleytman { 4076f3fbe4eSDmitry Fleytman int ret = pci_add_capability(pdev, PCI_CAP_ID_PM, offset, PCI_PM_SIZEOF); 4086f3fbe4eSDmitry Fleytman 4096f3fbe4eSDmitry Fleytman if (ret >= 0) { 4106f3fbe4eSDmitry Fleytman pci_set_word(pdev->config + offset + PCI_PM_PMC, 4116f3fbe4eSDmitry Fleytman PCI_PM_CAP_VER_1_1 | 4126f3fbe4eSDmitry Fleytman pmc); 4136f3fbe4eSDmitry Fleytman 4146f3fbe4eSDmitry Fleytman pci_set_word(pdev->wmask + offset + PCI_PM_CTRL, 4156f3fbe4eSDmitry Fleytman PCI_PM_CTRL_STATE_MASK | 4166f3fbe4eSDmitry Fleytman PCI_PM_CTRL_PME_ENABLE | 4176f3fbe4eSDmitry Fleytman PCI_PM_CTRL_DATA_SEL_MASK); 4186f3fbe4eSDmitry Fleytman 4196f3fbe4eSDmitry Fleytman pci_set_word(pdev->w1cmask + offset + PCI_PM_CTRL, 4206f3fbe4eSDmitry Fleytman PCI_PM_CTRL_PME_STATUS); 4216f3fbe4eSDmitry Fleytman } 4226f3fbe4eSDmitry Fleytman 4236f3fbe4eSDmitry Fleytman return ret; 4246f3fbe4eSDmitry Fleytman } 4256f3fbe4eSDmitry Fleytman 4266f3fbe4eSDmitry Fleytman static void e1000e_write_config(PCIDevice *pci_dev, uint32_t address, 4276f3fbe4eSDmitry Fleytman uint32_t val, int len) 4286f3fbe4eSDmitry Fleytman { 4296f3fbe4eSDmitry Fleytman E1000EState *s = E1000E(pci_dev); 4306f3fbe4eSDmitry Fleytman 4316f3fbe4eSDmitry Fleytman pci_default_write_config(pci_dev, address, val, len); 4326f3fbe4eSDmitry Fleytman 4336f3fbe4eSDmitry Fleytman if (range_covers_byte(address, len, PCI_COMMAND) && 4346f3fbe4eSDmitry Fleytman (pci_dev->config[PCI_COMMAND] & PCI_COMMAND_MASTER)) { 4356f3fbe4eSDmitry Fleytman qemu_flush_queued_packets(qemu_get_queue(s->nic)); 4366f3fbe4eSDmitry Fleytman } 4376f3fbe4eSDmitry Fleytman } 4386f3fbe4eSDmitry Fleytman 4396f3fbe4eSDmitry Fleytman static void e1000e_pci_realize(PCIDevice *pci_dev, Error **errp) 4406f3fbe4eSDmitry Fleytman { 4416f3fbe4eSDmitry Fleytman static const uint16_t e1000e_pmrb_offset = 0x0C8; 4426f3fbe4eSDmitry Fleytman static const uint16_t e1000e_pcie_offset = 0x0E0; 4436f3fbe4eSDmitry Fleytman static const uint16_t e1000e_aer_offset = 0x100; 4446f3fbe4eSDmitry Fleytman static const uint16_t e1000e_dsn_offset = 0x140; 4456f3fbe4eSDmitry Fleytman E1000EState *s = E1000E(pci_dev); 4466f3fbe4eSDmitry Fleytman uint8_t *macaddr; 4476f3fbe4eSDmitry Fleytman 4486f3fbe4eSDmitry Fleytman trace_e1000e_cb_pci_realize(); 4496f3fbe4eSDmitry Fleytman 4506f3fbe4eSDmitry Fleytman pci_dev->config_write = e1000e_write_config; 4516f3fbe4eSDmitry Fleytman 4526f3fbe4eSDmitry Fleytman pci_dev->config[PCI_CACHE_LINE_SIZE] = 0x10; 4536f3fbe4eSDmitry Fleytman pci_dev->config[PCI_INTERRUPT_PIN] = 1; 4546f3fbe4eSDmitry Fleytman 4556f3fbe4eSDmitry Fleytman pci_set_word(pci_dev->config + PCI_SUBSYSTEM_VENDOR_ID, s->subsys_ven); 4566f3fbe4eSDmitry Fleytman pci_set_word(pci_dev->config + PCI_SUBSYSTEM_ID, s->subsys); 4576f3fbe4eSDmitry Fleytman 4586f3fbe4eSDmitry Fleytman s->subsys_ven_used = s->subsys_ven; 4596f3fbe4eSDmitry Fleytman s->subsys_used = s->subsys; 4606f3fbe4eSDmitry Fleytman 4616f3fbe4eSDmitry Fleytman /* Define IO/MMIO regions */ 4626f3fbe4eSDmitry Fleytman memory_region_init_io(&s->mmio, OBJECT(s), &mmio_ops, s, 4636f3fbe4eSDmitry Fleytman "e1000e-mmio", E1000E_MMIO_SIZE); 4646f3fbe4eSDmitry Fleytman pci_register_bar(pci_dev, E1000E_MMIO_IDX, 4656f3fbe4eSDmitry Fleytman PCI_BASE_ADDRESS_SPACE_MEMORY, &s->mmio); 4666f3fbe4eSDmitry Fleytman 4676f3fbe4eSDmitry Fleytman /* 4686f3fbe4eSDmitry Fleytman * We provide a dummy implementation for the flash BAR 4696f3fbe4eSDmitry Fleytman * for drivers that may theoretically probe for its presence. 4706f3fbe4eSDmitry Fleytman */ 4716f3fbe4eSDmitry Fleytman memory_region_init(&s->flash, OBJECT(s), 4726f3fbe4eSDmitry Fleytman "e1000e-flash", E1000E_FLASH_SIZE); 4736f3fbe4eSDmitry Fleytman pci_register_bar(pci_dev, E1000E_FLASH_IDX, 4746f3fbe4eSDmitry Fleytman PCI_BASE_ADDRESS_SPACE_MEMORY, &s->flash); 4756f3fbe4eSDmitry Fleytman 4766f3fbe4eSDmitry Fleytman memory_region_init_io(&s->io, OBJECT(s), &io_ops, s, 4776f3fbe4eSDmitry Fleytman "e1000e-io", E1000E_IO_SIZE); 4786f3fbe4eSDmitry Fleytman pci_register_bar(pci_dev, E1000E_IO_IDX, 4796f3fbe4eSDmitry Fleytman PCI_BASE_ADDRESS_SPACE_IO, &s->io); 4806f3fbe4eSDmitry Fleytman 4816f3fbe4eSDmitry Fleytman memory_region_init(&s->msix, OBJECT(s), "e1000e-msix", 4826f3fbe4eSDmitry Fleytman E1000E_MSIX_SIZE); 4836f3fbe4eSDmitry Fleytman pci_register_bar(pci_dev, E1000E_MSIX_IDX, 4846f3fbe4eSDmitry Fleytman PCI_BASE_ADDRESS_SPACE_MEMORY, &s->msix); 4856f3fbe4eSDmitry Fleytman 4866f3fbe4eSDmitry Fleytman /* Create networking backend */ 4876f3fbe4eSDmitry Fleytman qemu_macaddr_default_if_unset(&s->conf.macaddr); 4886f3fbe4eSDmitry Fleytman macaddr = s->conf.macaddr.a; 4896f3fbe4eSDmitry Fleytman 4906f3fbe4eSDmitry Fleytman e1000e_init_msix(s); 4916f3fbe4eSDmitry Fleytman 4926f3fbe4eSDmitry Fleytman if (pcie_endpoint_cap_v1_init(pci_dev, e1000e_pcie_offset) < 0) { 4936f3fbe4eSDmitry Fleytman hw_error("Failed to initialize PCIe capability"); 4946f3fbe4eSDmitry Fleytman } 4956f3fbe4eSDmitry Fleytman 4966f3fbe4eSDmitry Fleytman e1000e_init_msi(s); 4976f3fbe4eSDmitry Fleytman 4986f3fbe4eSDmitry Fleytman if (e1000e_add_pm_capability(pci_dev, e1000e_pmrb_offset, 4996f3fbe4eSDmitry Fleytman PCI_PM_CAP_DSI) < 0) { 5006f3fbe4eSDmitry Fleytman hw_error("Failed to initialize PM capability"); 5016f3fbe4eSDmitry Fleytman } 5026f3fbe4eSDmitry Fleytman 5036f3fbe4eSDmitry Fleytman if (pcie_aer_init(pci_dev, e1000e_aer_offset, PCI_ERR_SIZEOF) < 0) { 5046f3fbe4eSDmitry Fleytman hw_error("Failed to initialize AER capability"); 5056f3fbe4eSDmitry Fleytman } 5066f3fbe4eSDmitry Fleytman 5076f3fbe4eSDmitry Fleytman pcie_dev_ser_num_init(pci_dev, e1000e_dsn_offset, 5086f3fbe4eSDmitry Fleytman e1000e_gen_dsn(macaddr)); 5096f3fbe4eSDmitry Fleytman 5106f3fbe4eSDmitry Fleytman e1000e_init_net_peer(s, pci_dev, macaddr); 5116f3fbe4eSDmitry Fleytman 5126f3fbe4eSDmitry Fleytman /* Initialize core */ 5136f3fbe4eSDmitry Fleytman e1000e_core_realize(s); 5146f3fbe4eSDmitry Fleytman 5156f3fbe4eSDmitry Fleytman e1000e_core_pci_realize(&s->core, 5166f3fbe4eSDmitry Fleytman e1000e_eeprom_template, 5176f3fbe4eSDmitry Fleytman sizeof(e1000e_eeprom_template), 5186f3fbe4eSDmitry Fleytman macaddr); 5196f3fbe4eSDmitry Fleytman } 5206f3fbe4eSDmitry Fleytman 5216f3fbe4eSDmitry Fleytman static void e1000e_pci_uninit(PCIDevice *pci_dev) 5226f3fbe4eSDmitry Fleytman { 5236f3fbe4eSDmitry Fleytman E1000EState *s = E1000E(pci_dev); 5246f3fbe4eSDmitry Fleytman 5256f3fbe4eSDmitry Fleytman trace_e1000e_cb_pci_uninit(); 5266f3fbe4eSDmitry Fleytman 5276f3fbe4eSDmitry Fleytman e1000e_core_pci_uninit(&s->core); 5286f3fbe4eSDmitry Fleytman 5296f3fbe4eSDmitry Fleytman pcie_aer_exit(pci_dev); 5306f3fbe4eSDmitry Fleytman pcie_cap_exit(pci_dev); 5316f3fbe4eSDmitry Fleytman 5326f3fbe4eSDmitry Fleytman qemu_del_nic(s->nic); 5336f3fbe4eSDmitry Fleytman 5346f3fbe4eSDmitry Fleytman e1000e_cleanup_msix(s); 5356f3fbe4eSDmitry Fleytman e1000e_cleanup_msi(s); 5366f3fbe4eSDmitry Fleytman } 5376f3fbe4eSDmitry Fleytman 5386f3fbe4eSDmitry Fleytman static void e1000e_qdev_reset(DeviceState *dev) 5396f3fbe4eSDmitry Fleytman { 5406f3fbe4eSDmitry Fleytman E1000EState *s = E1000E(dev); 5416f3fbe4eSDmitry Fleytman 5426f3fbe4eSDmitry Fleytman trace_e1000e_cb_qdev_reset(); 5436f3fbe4eSDmitry Fleytman 5446f3fbe4eSDmitry Fleytman e1000e_core_reset(&s->core); 5456f3fbe4eSDmitry Fleytman } 5466f3fbe4eSDmitry Fleytman 5476f3fbe4eSDmitry Fleytman static void e1000e_pre_save(void *opaque) 5486f3fbe4eSDmitry Fleytman { 5496f3fbe4eSDmitry Fleytman E1000EState *s = opaque; 5506f3fbe4eSDmitry Fleytman 5516f3fbe4eSDmitry Fleytman trace_e1000e_cb_pre_save(); 5526f3fbe4eSDmitry Fleytman 5536f3fbe4eSDmitry Fleytman e1000e_core_pre_save(&s->core); 5546f3fbe4eSDmitry Fleytman } 5556f3fbe4eSDmitry Fleytman 5566f3fbe4eSDmitry Fleytman static int e1000e_post_load(void *opaque, int version_id) 5576f3fbe4eSDmitry Fleytman { 5586f3fbe4eSDmitry Fleytman E1000EState *s = opaque; 5596f3fbe4eSDmitry Fleytman 5606f3fbe4eSDmitry Fleytman trace_e1000e_cb_post_load(); 5616f3fbe4eSDmitry Fleytman 5626f3fbe4eSDmitry Fleytman if ((s->subsys != s->subsys_used) || 5636f3fbe4eSDmitry Fleytman (s->subsys_ven != s->subsys_ven_used)) { 5646f3fbe4eSDmitry Fleytman fprintf(stderr, 5656f3fbe4eSDmitry Fleytman "ERROR: Cannot migrate while device properties " 5666f3fbe4eSDmitry Fleytman "(subsys/subsys_ven) differ"); 5676f3fbe4eSDmitry Fleytman return -1; 5686f3fbe4eSDmitry Fleytman } 5696f3fbe4eSDmitry Fleytman 5706f3fbe4eSDmitry Fleytman return e1000e_core_post_load(&s->core); 5716f3fbe4eSDmitry Fleytman } 5726f3fbe4eSDmitry Fleytman 5736f3fbe4eSDmitry Fleytman static const VMStateDescription e1000e_vmstate_tx = { 5746f3fbe4eSDmitry Fleytman .name = "e1000e-tx", 5756f3fbe4eSDmitry Fleytman .version_id = 1, 5766f3fbe4eSDmitry Fleytman .minimum_version_id = 1, 5776f3fbe4eSDmitry Fleytman .fields = (VMStateField[]) { 5786f3fbe4eSDmitry Fleytman VMSTATE_UINT8(props.sum_needed, struct e1000e_tx), 5796f3fbe4eSDmitry Fleytman VMSTATE_UINT8(props.ipcss, struct e1000e_tx), 5806f3fbe4eSDmitry Fleytman VMSTATE_UINT8(props.ipcso, struct e1000e_tx), 5816f3fbe4eSDmitry Fleytman VMSTATE_UINT16(props.ipcse, struct e1000e_tx), 5826f3fbe4eSDmitry Fleytman VMSTATE_UINT8(props.tucss, struct e1000e_tx), 5836f3fbe4eSDmitry Fleytman VMSTATE_UINT8(props.tucso, struct e1000e_tx), 5846f3fbe4eSDmitry Fleytman VMSTATE_UINT16(props.tucse, struct e1000e_tx), 5856f3fbe4eSDmitry Fleytman VMSTATE_UINT8(props.hdr_len, struct e1000e_tx), 5866f3fbe4eSDmitry Fleytman VMSTATE_UINT16(props.mss, struct e1000e_tx), 5876f3fbe4eSDmitry Fleytman VMSTATE_UINT32(props.paylen, struct e1000e_tx), 5886f3fbe4eSDmitry Fleytman VMSTATE_INT8(props.ip, struct e1000e_tx), 5896f3fbe4eSDmitry Fleytman VMSTATE_INT8(props.tcp, struct e1000e_tx), 5906f3fbe4eSDmitry Fleytman VMSTATE_BOOL(props.tse, struct e1000e_tx), 5916f3fbe4eSDmitry Fleytman VMSTATE_BOOL(props.cptse, struct e1000e_tx), 5926f3fbe4eSDmitry Fleytman VMSTATE_BOOL(skip_cp, struct e1000e_tx), 5936f3fbe4eSDmitry Fleytman VMSTATE_END_OF_LIST() 5946f3fbe4eSDmitry Fleytman } 5956f3fbe4eSDmitry Fleytman }; 5966f3fbe4eSDmitry Fleytman 5976f3fbe4eSDmitry Fleytman static const VMStateDescription e1000e_vmstate_intr_timer = { 5986f3fbe4eSDmitry Fleytman .name = "e1000e-intr-timer", 5996f3fbe4eSDmitry Fleytman .version_id = 1, 6006f3fbe4eSDmitry Fleytman .minimum_version_id = 1, 6016f3fbe4eSDmitry Fleytman .fields = (VMStateField[]) { 6026f3fbe4eSDmitry Fleytman VMSTATE_TIMER_PTR(timer, E1000IntrDelayTimer), 6036f3fbe4eSDmitry Fleytman VMSTATE_BOOL(running, E1000IntrDelayTimer), 6046f3fbe4eSDmitry Fleytman VMSTATE_END_OF_LIST() 6056f3fbe4eSDmitry Fleytman } 6066f3fbe4eSDmitry Fleytman }; 6076f3fbe4eSDmitry Fleytman 6086f3fbe4eSDmitry Fleytman #define VMSTATE_E1000E_INTR_DELAY_TIMER(_f, _s) \ 6096f3fbe4eSDmitry Fleytman VMSTATE_STRUCT(_f, _s, 0, \ 6106f3fbe4eSDmitry Fleytman e1000e_vmstate_intr_timer, E1000IntrDelayTimer) 6116f3fbe4eSDmitry Fleytman 6126f3fbe4eSDmitry Fleytman #define VMSTATE_E1000E_INTR_DELAY_TIMER_ARRAY(_f, _s, _num) \ 6136f3fbe4eSDmitry Fleytman VMSTATE_STRUCT_ARRAY(_f, _s, _num, 0, \ 6146f3fbe4eSDmitry Fleytman e1000e_vmstate_intr_timer, E1000IntrDelayTimer) 6156f3fbe4eSDmitry Fleytman 6166f3fbe4eSDmitry Fleytman static const VMStateDescription e1000e_vmstate = { 6176f3fbe4eSDmitry Fleytman .name = "e1000e", 6186f3fbe4eSDmitry Fleytman .version_id = 1, 6196f3fbe4eSDmitry Fleytman .minimum_version_id = 1, 6206f3fbe4eSDmitry Fleytman .pre_save = e1000e_pre_save, 6216f3fbe4eSDmitry Fleytman .post_load = e1000e_post_load, 6226f3fbe4eSDmitry Fleytman .fields = (VMStateField[]) { 6236f3fbe4eSDmitry Fleytman VMSTATE_PCIE_DEVICE(parent_obj, E1000EState), 6246f3fbe4eSDmitry Fleytman VMSTATE_MSIX(parent_obj, E1000EState), 6256f3fbe4eSDmitry Fleytman 6266f3fbe4eSDmitry Fleytman VMSTATE_UINT32(ioaddr, E1000EState), 6276f3fbe4eSDmitry Fleytman VMSTATE_UINT32(intr_state, E1000EState), 6286f3fbe4eSDmitry Fleytman VMSTATE_UINT32(core.rxbuf_min_shift, E1000EState), 6296f3fbe4eSDmitry Fleytman VMSTATE_UINT8(core.rx_desc_len, E1000EState), 6306f3fbe4eSDmitry Fleytman VMSTATE_UINT32_ARRAY(core.rxbuf_sizes, E1000EState, 6316f3fbe4eSDmitry Fleytman E1000_PSRCTL_BUFFS_PER_DESC), 6326f3fbe4eSDmitry Fleytman VMSTATE_UINT32(core.rx_desc_buf_size, E1000EState), 6336f3fbe4eSDmitry Fleytman VMSTATE_UINT16_ARRAY(core.eeprom, E1000EState, E1000E_EEPROM_SIZE), 6346f3fbe4eSDmitry Fleytman VMSTATE_UINT16_2DARRAY(core.phy, E1000EState, 6356f3fbe4eSDmitry Fleytman E1000E_PHY_PAGES, E1000E_PHY_PAGE_SIZE), 6366f3fbe4eSDmitry Fleytman VMSTATE_UINT32_ARRAY(core.mac, E1000EState, E1000E_MAC_SIZE), 6376f3fbe4eSDmitry Fleytman VMSTATE_UINT8_ARRAY(core.permanent_mac, E1000EState, ETH_ALEN), 6386f3fbe4eSDmitry Fleytman 6396f3fbe4eSDmitry Fleytman VMSTATE_UINT32(core.delayed_causes, E1000EState), 6406f3fbe4eSDmitry Fleytman 6416f3fbe4eSDmitry Fleytman VMSTATE_UINT16(subsys, E1000EState), 6426f3fbe4eSDmitry Fleytman VMSTATE_UINT16(subsys_ven, E1000EState), 6436f3fbe4eSDmitry Fleytman 6446f3fbe4eSDmitry Fleytman VMSTATE_E1000E_INTR_DELAY_TIMER(core.rdtr, E1000EState), 6456f3fbe4eSDmitry Fleytman VMSTATE_E1000E_INTR_DELAY_TIMER(core.radv, E1000EState), 6466f3fbe4eSDmitry Fleytman VMSTATE_E1000E_INTR_DELAY_TIMER(core.raid, E1000EState), 6476f3fbe4eSDmitry Fleytman VMSTATE_E1000E_INTR_DELAY_TIMER(core.tadv, E1000EState), 6486f3fbe4eSDmitry Fleytman VMSTATE_E1000E_INTR_DELAY_TIMER(core.tidv, E1000EState), 6496f3fbe4eSDmitry Fleytman 6506f3fbe4eSDmitry Fleytman VMSTATE_E1000E_INTR_DELAY_TIMER(core.itr, E1000EState), 6516f3fbe4eSDmitry Fleytman VMSTATE_BOOL(core.itr_intr_pending, E1000EState), 6526f3fbe4eSDmitry Fleytman 6536f3fbe4eSDmitry Fleytman VMSTATE_E1000E_INTR_DELAY_TIMER_ARRAY(core.eitr, E1000EState, 6546f3fbe4eSDmitry Fleytman E1000E_MSIX_VEC_NUM), 6556f3fbe4eSDmitry Fleytman VMSTATE_BOOL_ARRAY(core.eitr_intr_pending, E1000EState, 6566f3fbe4eSDmitry Fleytman E1000E_MSIX_VEC_NUM), 6576f3fbe4eSDmitry Fleytman 6586f3fbe4eSDmitry Fleytman VMSTATE_UINT32(core.itr_guest_value, E1000EState), 6596f3fbe4eSDmitry Fleytman VMSTATE_UINT32_ARRAY(core.eitr_guest_value, E1000EState, 6606f3fbe4eSDmitry Fleytman E1000E_MSIX_VEC_NUM), 6616f3fbe4eSDmitry Fleytman 6626f3fbe4eSDmitry Fleytman VMSTATE_UINT16(core.vet, E1000EState), 6636f3fbe4eSDmitry Fleytman 6646f3fbe4eSDmitry Fleytman VMSTATE_STRUCT_ARRAY(core.tx, E1000EState, E1000E_NUM_QUEUES, 0, 6656f3fbe4eSDmitry Fleytman e1000e_vmstate_tx, struct e1000e_tx), 6666f3fbe4eSDmitry Fleytman VMSTATE_END_OF_LIST() 6676f3fbe4eSDmitry Fleytman } 6686f3fbe4eSDmitry Fleytman }; 6696f3fbe4eSDmitry Fleytman 6706f3fbe4eSDmitry Fleytman static PropertyInfo e1000e_prop_disable_vnet, 6716f3fbe4eSDmitry Fleytman e1000e_prop_subsys_ven, 6726f3fbe4eSDmitry Fleytman e1000e_prop_subsys; 6736f3fbe4eSDmitry Fleytman 6746f3fbe4eSDmitry Fleytman static Property e1000e_properties[] = { 6756f3fbe4eSDmitry Fleytman DEFINE_NIC_PROPERTIES(E1000EState, conf), 6766f3fbe4eSDmitry Fleytman DEFINE_PROP_DEFAULT("disable_vnet_hdr", E1000EState, disable_vnet, false, 6776f3fbe4eSDmitry Fleytman e1000e_prop_disable_vnet, bool), 6786f3fbe4eSDmitry Fleytman DEFINE_PROP_DEFAULT("subsys_ven", E1000EState, subsys_ven, 6796f3fbe4eSDmitry Fleytman PCI_VENDOR_ID_INTEL, 6806f3fbe4eSDmitry Fleytman e1000e_prop_subsys_ven, uint16_t), 6816f3fbe4eSDmitry Fleytman DEFINE_PROP_DEFAULT("subsys", E1000EState, subsys, 0, 6826f3fbe4eSDmitry Fleytman e1000e_prop_subsys, uint16_t), 6836f3fbe4eSDmitry Fleytman DEFINE_PROP_END_OF_LIST(), 6846f3fbe4eSDmitry Fleytman }; 6856f3fbe4eSDmitry Fleytman 6866f3fbe4eSDmitry Fleytman static void e1000e_class_init(ObjectClass *class, void *data) 6876f3fbe4eSDmitry Fleytman { 6886f3fbe4eSDmitry Fleytman DeviceClass *dc = DEVICE_CLASS(class); 6896f3fbe4eSDmitry Fleytman PCIDeviceClass *c = PCI_DEVICE_CLASS(class); 6906f3fbe4eSDmitry Fleytman 6916f3fbe4eSDmitry Fleytman c->realize = e1000e_pci_realize; 6926f3fbe4eSDmitry Fleytman c->exit = e1000e_pci_uninit; 6936f3fbe4eSDmitry Fleytman c->vendor_id = PCI_VENDOR_ID_INTEL; 6946f3fbe4eSDmitry Fleytman c->device_id = E1000_DEV_ID_82574L; 6956f3fbe4eSDmitry Fleytman c->revision = 0; 696*1676103dSGerd Hoffmann c->romfile = "efi-e1000e.rom"; 6976f3fbe4eSDmitry Fleytman c->class_id = PCI_CLASS_NETWORK_ETHERNET; 6986f3fbe4eSDmitry Fleytman c->is_express = 1; 6996f3fbe4eSDmitry Fleytman 7006f3fbe4eSDmitry Fleytman dc->desc = "Intel 82574L GbE Controller"; 7016f3fbe4eSDmitry Fleytman dc->reset = e1000e_qdev_reset; 7026f3fbe4eSDmitry Fleytman dc->vmsd = &e1000e_vmstate; 7036f3fbe4eSDmitry Fleytman dc->props = e1000e_properties; 7046f3fbe4eSDmitry Fleytman 7056f3fbe4eSDmitry Fleytman e1000e_prop_disable_vnet = qdev_prop_uint8; 7066f3fbe4eSDmitry Fleytman e1000e_prop_disable_vnet.description = "Do not use virtio headers, " 7076f3fbe4eSDmitry Fleytman "perform SW offloads emulation " 7086f3fbe4eSDmitry Fleytman "instead"; 7096f3fbe4eSDmitry Fleytman 7106f3fbe4eSDmitry Fleytman e1000e_prop_subsys_ven = qdev_prop_uint16; 7116f3fbe4eSDmitry Fleytman e1000e_prop_subsys_ven.description = "PCI device Subsystem Vendor ID"; 7126f3fbe4eSDmitry Fleytman 7136f3fbe4eSDmitry Fleytman e1000e_prop_subsys = qdev_prop_uint16; 7146f3fbe4eSDmitry Fleytman e1000e_prop_subsys.description = "PCI device Subsystem ID"; 7156f3fbe4eSDmitry Fleytman 7166f3fbe4eSDmitry Fleytman set_bit(DEVICE_CATEGORY_NETWORK, dc->categories); 7176f3fbe4eSDmitry Fleytman } 7186f3fbe4eSDmitry Fleytman 7196f3fbe4eSDmitry Fleytman static void e1000e_instance_init(Object *obj) 7206f3fbe4eSDmitry Fleytman { 7216f3fbe4eSDmitry Fleytman E1000EState *s = E1000E(obj); 7226f3fbe4eSDmitry Fleytman device_add_bootindex_property(obj, &s->conf.bootindex, 7236f3fbe4eSDmitry Fleytman "bootindex", "/ethernet-phy@0", 7246f3fbe4eSDmitry Fleytman DEVICE(obj), NULL); 7256f3fbe4eSDmitry Fleytman } 7266f3fbe4eSDmitry Fleytman 7276f3fbe4eSDmitry Fleytman static const TypeInfo e1000e_info = { 7286f3fbe4eSDmitry Fleytman .name = TYPE_E1000E, 7296f3fbe4eSDmitry Fleytman .parent = TYPE_PCI_DEVICE, 7306f3fbe4eSDmitry Fleytman .instance_size = sizeof(E1000EState), 7316f3fbe4eSDmitry Fleytman .class_init = e1000e_class_init, 7326f3fbe4eSDmitry Fleytman .instance_init = e1000e_instance_init, 7336f3fbe4eSDmitry Fleytman }; 7346f3fbe4eSDmitry Fleytman 7356f3fbe4eSDmitry Fleytman static void e1000e_register_types(void) 7366f3fbe4eSDmitry Fleytman { 7376f3fbe4eSDmitry Fleytman type_register_static(&e1000e_info); 7386f3fbe4eSDmitry Fleytman } 7396f3fbe4eSDmitry Fleytman 7406f3fbe4eSDmitry Fleytman type_init(e1000e_register_types) 741