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 257cd2a9faSChetan Pant * version 2.1 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" 37872a2b7cSPhilippe Mathieu-Daudé #include "qemu/units.h" 38d8970569SChristina Wang #include "net/eth.h" 396f3fbe4eSDmitry Fleytman #include "net/net.h" 406f3fbe4eSDmitry Fleytman #include "net/tap.h" 410b8fa32fSMarkus Armbruster #include "qemu/module.h" 426f3fbe4eSDmitry Fleytman #include "qemu/range.h" 436f3fbe4eSDmitry Fleytman #include "sysemu/sysemu.h" 44650d103dSMarkus Armbruster #include "hw/hw.h" 45*b7728c9fSAkihiko Odaki #include "hw/net/mii.h" 466f3fbe4eSDmitry Fleytman #include "hw/pci/msi.h" 476f3fbe4eSDmitry Fleytman #include "hw/pci/msix.h" 48a27bd6c7SMarkus Armbruster #include "hw/qdev-properties.h" 49d6454270SMarkus Armbruster #include "migration/vmstate.h" 506f3fbe4eSDmitry Fleytman 51e703a5a1SMichael S. Tsirkin #include "e1000_regs.h" 526f3fbe4eSDmitry Fleytman 536f3fbe4eSDmitry Fleytman #include "e1000x_common.h" 546f3fbe4eSDmitry Fleytman #include "e1000e_core.h" 556f3fbe4eSDmitry Fleytman 566f3fbe4eSDmitry Fleytman #include "trace.h" 579a7c2a59SMao Zhongyi #include "qapi/error.h" 58db1015e9SEduardo Habkost #include "qom/object.h" 596f3fbe4eSDmitry Fleytman 606f3fbe4eSDmitry Fleytman #define TYPE_E1000E "e1000e" 618063396bSEduardo Habkost OBJECT_DECLARE_SIMPLE_TYPE(E1000EState, E1000E) 626f3fbe4eSDmitry Fleytman 63db1015e9SEduardo Habkost struct E1000EState { 646f3fbe4eSDmitry Fleytman PCIDevice parent_obj; 656f3fbe4eSDmitry Fleytman NICState *nic; 666f3fbe4eSDmitry Fleytman NICConf conf; 676f3fbe4eSDmitry Fleytman 686f3fbe4eSDmitry Fleytman MemoryRegion mmio; 696f3fbe4eSDmitry Fleytman MemoryRegion flash; 706f3fbe4eSDmitry Fleytman MemoryRegion io; 716f3fbe4eSDmitry Fleytman MemoryRegion msix; 726f3fbe4eSDmitry Fleytman 736f3fbe4eSDmitry Fleytman uint32_t ioaddr; 746f3fbe4eSDmitry Fleytman 756f3fbe4eSDmitry Fleytman uint16_t subsys_ven; 766f3fbe4eSDmitry Fleytman uint16_t subsys; 776f3fbe4eSDmitry Fleytman 786f3fbe4eSDmitry Fleytman uint16_t subsys_ven_used; 796f3fbe4eSDmitry Fleytman uint16_t subsys_used; 806f3fbe4eSDmitry Fleytman 816f3fbe4eSDmitry Fleytman bool disable_vnet; 826f3fbe4eSDmitry Fleytman 836f3fbe4eSDmitry Fleytman E1000ECore core; 84d8970569SChristina Wang bool init_vet; 85db1015e9SEduardo Habkost }; 866f3fbe4eSDmitry Fleytman 876f3fbe4eSDmitry Fleytman #define E1000E_MMIO_IDX 0 886f3fbe4eSDmitry Fleytman #define E1000E_FLASH_IDX 1 896f3fbe4eSDmitry Fleytman #define E1000E_IO_IDX 2 906f3fbe4eSDmitry Fleytman #define E1000E_MSIX_IDX 3 916f3fbe4eSDmitry Fleytman 92872a2b7cSPhilippe Mathieu-Daudé #define E1000E_MMIO_SIZE (128 * KiB) 93872a2b7cSPhilippe Mathieu-Daudé #define E1000E_FLASH_SIZE (128 * KiB) 946f3fbe4eSDmitry Fleytman #define E1000E_IO_SIZE (32) 95872a2b7cSPhilippe Mathieu-Daudé #define E1000E_MSIX_SIZE (16 * KiB) 966f3fbe4eSDmitry Fleytman 976f3fbe4eSDmitry Fleytman #define E1000E_MSIX_TABLE (0x0000) 986f3fbe4eSDmitry Fleytman #define E1000E_MSIX_PBA (0x2000) 996f3fbe4eSDmitry Fleytman 1006f3fbe4eSDmitry Fleytman static uint64_t 1016f3fbe4eSDmitry Fleytman e1000e_mmio_read(void *opaque, hwaddr addr, unsigned size) 1026f3fbe4eSDmitry Fleytman { 1036f3fbe4eSDmitry Fleytman E1000EState *s = opaque; 1046f3fbe4eSDmitry Fleytman return e1000e_core_read(&s->core, addr, size); 1056f3fbe4eSDmitry Fleytman } 1066f3fbe4eSDmitry Fleytman 1076f3fbe4eSDmitry Fleytman static void 1086f3fbe4eSDmitry Fleytman e1000e_mmio_write(void *opaque, hwaddr addr, 1096f3fbe4eSDmitry Fleytman uint64_t val, unsigned size) 1106f3fbe4eSDmitry Fleytman { 1116f3fbe4eSDmitry Fleytman E1000EState *s = opaque; 1126f3fbe4eSDmitry Fleytman e1000e_core_write(&s->core, addr, val, size); 1136f3fbe4eSDmitry Fleytman } 1146f3fbe4eSDmitry Fleytman 1156f3fbe4eSDmitry Fleytman static bool 1166f3fbe4eSDmitry Fleytman e1000e_io_get_reg_index(E1000EState *s, uint32_t *idx) 1176f3fbe4eSDmitry Fleytman { 1186f3fbe4eSDmitry Fleytman if (s->ioaddr < 0x1FFFF) { 1196f3fbe4eSDmitry Fleytman *idx = s->ioaddr; 1206f3fbe4eSDmitry Fleytman return true; 1216f3fbe4eSDmitry Fleytman } 1226f3fbe4eSDmitry Fleytman 1236f3fbe4eSDmitry Fleytman if (s->ioaddr < 0x7FFFF) { 1246f3fbe4eSDmitry Fleytman trace_e1000e_wrn_io_addr_undefined(s->ioaddr); 1256f3fbe4eSDmitry Fleytman return false; 1266f3fbe4eSDmitry Fleytman } 1276f3fbe4eSDmitry Fleytman 1286f3fbe4eSDmitry Fleytman if (s->ioaddr < 0xFFFFF) { 1296f3fbe4eSDmitry Fleytman trace_e1000e_wrn_io_addr_flash(s->ioaddr); 1306f3fbe4eSDmitry Fleytman return false; 1316f3fbe4eSDmitry Fleytman } 1326f3fbe4eSDmitry Fleytman 1336f3fbe4eSDmitry Fleytman trace_e1000e_wrn_io_addr_unknown(s->ioaddr); 1346f3fbe4eSDmitry Fleytman return false; 1356f3fbe4eSDmitry Fleytman } 1366f3fbe4eSDmitry Fleytman 1376f3fbe4eSDmitry Fleytman static uint64_t 1386f3fbe4eSDmitry Fleytman e1000e_io_read(void *opaque, hwaddr addr, unsigned size) 1396f3fbe4eSDmitry Fleytman { 1406f3fbe4eSDmitry Fleytman E1000EState *s = opaque; 141de5dca1bSDmitry Fleytman uint32_t idx = 0; 1426f3fbe4eSDmitry Fleytman uint64_t val; 1436f3fbe4eSDmitry Fleytman 1446f3fbe4eSDmitry Fleytman switch (addr) { 1456f3fbe4eSDmitry Fleytman case E1000_IOADDR: 1466f3fbe4eSDmitry Fleytman trace_e1000e_io_read_addr(s->ioaddr); 1476f3fbe4eSDmitry Fleytman return s->ioaddr; 1486f3fbe4eSDmitry Fleytman case E1000_IODATA: 1496f3fbe4eSDmitry Fleytman if (e1000e_io_get_reg_index(s, &idx)) { 1506f3fbe4eSDmitry Fleytman val = e1000e_core_read(&s->core, idx, sizeof(val)); 1516f3fbe4eSDmitry Fleytman trace_e1000e_io_read_data(idx, val); 1526f3fbe4eSDmitry Fleytman return val; 1536f3fbe4eSDmitry Fleytman } 1546f3fbe4eSDmitry Fleytman return 0; 1556f3fbe4eSDmitry Fleytman default: 1566f3fbe4eSDmitry Fleytman trace_e1000e_wrn_io_read_unknown(addr); 1576f3fbe4eSDmitry Fleytman return 0; 1586f3fbe4eSDmitry Fleytman } 1596f3fbe4eSDmitry Fleytman } 1606f3fbe4eSDmitry Fleytman 1616f3fbe4eSDmitry Fleytman static void 1626f3fbe4eSDmitry Fleytman e1000e_io_write(void *opaque, hwaddr addr, 1636f3fbe4eSDmitry Fleytman uint64_t val, unsigned size) 1646f3fbe4eSDmitry Fleytman { 1656f3fbe4eSDmitry Fleytman E1000EState *s = opaque; 166de5dca1bSDmitry Fleytman uint32_t idx = 0; 1676f3fbe4eSDmitry Fleytman 1686f3fbe4eSDmitry Fleytman switch (addr) { 1696f3fbe4eSDmitry Fleytman case E1000_IOADDR: 1706f3fbe4eSDmitry Fleytman trace_e1000e_io_write_addr(val); 1716f3fbe4eSDmitry Fleytman s->ioaddr = (uint32_t) val; 1726f3fbe4eSDmitry Fleytman return; 1736f3fbe4eSDmitry Fleytman case E1000_IODATA: 1746f3fbe4eSDmitry Fleytman if (e1000e_io_get_reg_index(s, &idx)) { 1756f3fbe4eSDmitry Fleytman trace_e1000e_io_write_data(idx, val); 1766f3fbe4eSDmitry Fleytman e1000e_core_write(&s->core, idx, val, sizeof(val)); 1776f3fbe4eSDmitry Fleytman } 1786f3fbe4eSDmitry Fleytman return; 1796f3fbe4eSDmitry Fleytman default: 1806f3fbe4eSDmitry Fleytman trace_e1000e_wrn_io_write_unknown(addr); 1816f3fbe4eSDmitry Fleytman return; 1826f3fbe4eSDmitry Fleytman } 1836f3fbe4eSDmitry Fleytman } 1846f3fbe4eSDmitry Fleytman 1856f3fbe4eSDmitry Fleytman static const MemoryRegionOps mmio_ops = { 1866f3fbe4eSDmitry Fleytman .read = e1000e_mmio_read, 1876f3fbe4eSDmitry Fleytman .write = e1000e_mmio_write, 1886f3fbe4eSDmitry Fleytman .endianness = DEVICE_LITTLE_ENDIAN, 1896f3fbe4eSDmitry Fleytman .impl = { 1906f3fbe4eSDmitry Fleytman .min_access_size = 4, 1916f3fbe4eSDmitry Fleytman .max_access_size = 4, 1926f3fbe4eSDmitry Fleytman }, 1936f3fbe4eSDmitry Fleytman }; 1946f3fbe4eSDmitry Fleytman 1956f3fbe4eSDmitry Fleytman static const MemoryRegionOps io_ops = { 1966f3fbe4eSDmitry Fleytman .read = e1000e_io_read, 1976f3fbe4eSDmitry Fleytman .write = e1000e_io_write, 1986f3fbe4eSDmitry Fleytman .endianness = DEVICE_LITTLE_ENDIAN, 1996f3fbe4eSDmitry Fleytman .impl = { 2006f3fbe4eSDmitry Fleytman .min_access_size = 4, 2016f3fbe4eSDmitry Fleytman .max_access_size = 4, 2026f3fbe4eSDmitry Fleytman }, 2036f3fbe4eSDmitry Fleytman }; 2046f3fbe4eSDmitry Fleytman 205b8c4b67eSPhilippe Mathieu-Daudé static bool 2066f3fbe4eSDmitry Fleytman e1000e_nc_can_receive(NetClientState *nc) 2076f3fbe4eSDmitry Fleytman { 2086f3fbe4eSDmitry Fleytman E1000EState *s = qemu_get_nic_opaque(nc); 2096f3fbe4eSDmitry Fleytman return e1000e_can_receive(&s->core); 2106f3fbe4eSDmitry Fleytman } 2116f3fbe4eSDmitry Fleytman 2126f3fbe4eSDmitry Fleytman static ssize_t 2136f3fbe4eSDmitry Fleytman e1000e_nc_receive_iov(NetClientState *nc, const struct iovec *iov, int iovcnt) 2146f3fbe4eSDmitry Fleytman { 2156f3fbe4eSDmitry Fleytman E1000EState *s = qemu_get_nic_opaque(nc); 2166f3fbe4eSDmitry Fleytman return e1000e_receive_iov(&s->core, iov, iovcnt); 2176f3fbe4eSDmitry Fleytman } 2186f3fbe4eSDmitry Fleytman 2196f3fbe4eSDmitry Fleytman static ssize_t 2206f3fbe4eSDmitry Fleytman e1000e_nc_receive(NetClientState *nc, const uint8_t *buf, size_t size) 2216f3fbe4eSDmitry Fleytman { 2226f3fbe4eSDmitry Fleytman E1000EState *s = qemu_get_nic_opaque(nc); 2236f3fbe4eSDmitry Fleytman return e1000e_receive(&s->core, buf, size); 2246f3fbe4eSDmitry Fleytman } 2256f3fbe4eSDmitry Fleytman 2266f3fbe4eSDmitry Fleytman static void 2276f3fbe4eSDmitry Fleytman e1000e_set_link_status(NetClientState *nc) 2286f3fbe4eSDmitry Fleytman { 2296f3fbe4eSDmitry Fleytman E1000EState *s = qemu_get_nic_opaque(nc); 2306f3fbe4eSDmitry Fleytman e1000e_core_set_link_status(&s->core); 2316f3fbe4eSDmitry Fleytman } 2326f3fbe4eSDmitry Fleytman 2336f3fbe4eSDmitry Fleytman static NetClientInfo net_e1000e_info = { 234f394b2e2SEric Blake .type = NET_CLIENT_DRIVER_NIC, 2356f3fbe4eSDmitry Fleytman .size = sizeof(NICState), 2366f3fbe4eSDmitry Fleytman .can_receive = e1000e_nc_can_receive, 2376f3fbe4eSDmitry Fleytman .receive = e1000e_nc_receive, 2386f3fbe4eSDmitry Fleytman .receive_iov = e1000e_nc_receive_iov, 2396f3fbe4eSDmitry Fleytman .link_status_changed = e1000e_set_link_status, 2406f3fbe4eSDmitry Fleytman }; 2416f3fbe4eSDmitry Fleytman 2426f3fbe4eSDmitry Fleytman /* 2436f3fbe4eSDmitry Fleytman * EEPROM (NVM) contents documented in Table 36, section 6.1 2446f3fbe4eSDmitry Fleytman * and generally 6.1.2 Software accessed words. 2456f3fbe4eSDmitry Fleytman */ 2466f3fbe4eSDmitry Fleytman static const uint16_t e1000e_eeprom_template[64] = { 2476f3fbe4eSDmitry Fleytman /* Address | Compat. | ImVer | Compat. */ 2486f3fbe4eSDmitry Fleytman 0x0000, 0x0000, 0x0000, 0x0420, 0xf746, 0x2010, 0xffff, 0xffff, 2496f3fbe4eSDmitry Fleytman /* PBA |ICtrl1 | SSID | SVID | DevID |-------|ICtrl2 */ 2506f3fbe4eSDmitry Fleytman 0x0000, 0x0000, 0x026b, 0x0000, 0x8086, 0x0000, 0x0000, 0x8058, 2516f3fbe4eSDmitry Fleytman /* NVM words 1,2,3 |-------------------------------|PCI-EID*/ 2526f3fbe4eSDmitry Fleytman 0x0000, 0x2001, 0x7e7c, 0xffff, 0x1000, 0x00c8, 0x0000, 0x2704, 2536f3fbe4eSDmitry Fleytman /* PCIe Init. Conf 1,2,3 |PCICtrl|PHY|LD1|-------| RevID | LD0,2 */ 2546f3fbe4eSDmitry Fleytman 0x6cc9, 0x3150, 0x070e, 0x460b, 0x2d84, 0x0100, 0xf000, 0x0706, 2556f3fbe4eSDmitry Fleytman /* FLPAR |FLANADD|LAN-PWR|FlVndr |ICtrl3 |APTSMBA|APTRxEP|APTSMBC*/ 2566f3fbe4eSDmitry Fleytman 0x6000, 0x0080, 0x0f04, 0x7fff, 0x4f01, 0xc600, 0x0000, 0x20ff, 2576f3fbe4eSDmitry Fleytman /* APTIF | APTMC |APTuCP |LSWFWID|MSWFWID|NC-SIMC|NC-SIC | VPDP */ 2586f3fbe4eSDmitry Fleytman 0x0028, 0x0003, 0x0000, 0x0000, 0x0000, 0x0003, 0x0000, 0xffff, 2596f3fbe4eSDmitry Fleytman /* SW Section */ 2606f3fbe4eSDmitry Fleytman 0x0100, 0xc000, 0x121c, 0xc007, 0xffff, 0xffff, 0xffff, 0xffff, 2616f3fbe4eSDmitry Fleytman /* SW Section |CHKSUM */ 2626f3fbe4eSDmitry Fleytman 0xffff, 0xffff, 0xffff, 0xffff, 0x0000, 0x0120, 0xffff, 0x0000, 2636f3fbe4eSDmitry Fleytman }; 2646f3fbe4eSDmitry Fleytman 2656f3fbe4eSDmitry Fleytman static void e1000e_core_realize(E1000EState *s) 2666f3fbe4eSDmitry Fleytman { 2676f3fbe4eSDmitry Fleytman s->core.owner = &s->parent_obj; 2686f3fbe4eSDmitry Fleytman s->core.owner_nic = s->nic; 2696f3fbe4eSDmitry Fleytman } 2706f3fbe4eSDmitry Fleytman 2716f3fbe4eSDmitry Fleytman static void 2726f3fbe4eSDmitry Fleytman e1000e_unuse_msix_vectors(E1000EState *s, int num_vectors) 2736f3fbe4eSDmitry Fleytman { 2746f3fbe4eSDmitry Fleytman int i; 2756f3fbe4eSDmitry Fleytman for (i = 0; i < num_vectors; i++) { 2766f3fbe4eSDmitry Fleytman msix_vector_unuse(PCI_DEVICE(s), i); 2776f3fbe4eSDmitry Fleytman } 2786f3fbe4eSDmitry Fleytman } 2796f3fbe4eSDmitry Fleytman 28015377f6eSAkihiko Odaki static void 2816f3fbe4eSDmitry Fleytman e1000e_use_msix_vectors(E1000EState *s, int num_vectors) 2826f3fbe4eSDmitry Fleytman { 2836f3fbe4eSDmitry Fleytman int i; 2846f3fbe4eSDmitry Fleytman for (i = 0; i < num_vectors; i++) { 28515377f6eSAkihiko Odaki msix_vector_use(PCI_DEVICE(s), i); 2866f3fbe4eSDmitry Fleytman } 2876f3fbe4eSDmitry Fleytman } 2886f3fbe4eSDmitry Fleytman 2896f3fbe4eSDmitry Fleytman static void 2906f3fbe4eSDmitry Fleytman e1000e_init_msix(E1000EState *s) 2916f3fbe4eSDmitry Fleytman { 2926f3fbe4eSDmitry Fleytman int res = msix_init(PCI_DEVICE(s), E1000E_MSIX_VEC_NUM, 2936f3fbe4eSDmitry Fleytman &s->msix, 2946f3fbe4eSDmitry Fleytman E1000E_MSIX_IDX, E1000E_MSIX_TABLE, 2956f3fbe4eSDmitry Fleytman &s->msix, 2966f3fbe4eSDmitry Fleytman E1000E_MSIX_IDX, E1000E_MSIX_PBA, 297ee640c62SCao jin 0xA0, NULL); 2986f3fbe4eSDmitry Fleytman 2996f3fbe4eSDmitry Fleytman if (res < 0) { 3006f3fbe4eSDmitry Fleytman trace_e1000e_msix_init_fail(res); 3016f3fbe4eSDmitry Fleytman } else { 30215377f6eSAkihiko Odaki e1000e_use_msix_vectors(s, E1000E_MSIX_VEC_NUM); 3036f3fbe4eSDmitry Fleytman } 3046f3fbe4eSDmitry Fleytman } 3056f3fbe4eSDmitry Fleytman 3066f3fbe4eSDmitry Fleytman static void 3076f3fbe4eSDmitry Fleytman e1000e_cleanup_msix(E1000EState *s) 3086f3fbe4eSDmitry Fleytman { 3097ec7ae4bSPaolo Bonzini if (msix_present(PCI_DEVICE(s))) { 3106f3fbe4eSDmitry Fleytman e1000e_unuse_msix_vectors(s, E1000E_MSIX_VEC_NUM); 3116f3fbe4eSDmitry Fleytman msix_uninit(PCI_DEVICE(s), &s->msix, &s->msix); 3126f3fbe4eSDmitry Fleytman } 3136f3fbe4eSDmitry Fleytman } 3146f3fbe4eSDmitry Fleytman 3156f3fbe4eSDmitry Fleytman static void 3166f3fbe4eSDmitry Fleytman e1000e_init_net_peer(E1000EState *s, PCIDevice *pci_dev, uint8_t *macaddr) 3176f3fbe4eSDmitry Fleytman { 3186f3fbe4eSDmitry Fleytman DeviceState *dev = DEVICE(pci_dev); 3196f3fbe4eSDmitry Fleytman NetClientState *nc; 3206f3fbe4eSDmitry Fleytman int i; 3216f3fbe4eSDmitry Fleytman 3226f3fbe4eSDmitry Fleytman s->nic = qemu_new_nic(&net_e1000e_info, &s->conf, 3236f3fbe4eSDmitry Fleytman object_get_typename(OBJECT(s)), dev->id, s); 3246f3fbe4eSDmitry Fleytman 325f22a57acSAndrew Melnychenko s->core.max_queue_num = s->conf.peers.queues ? s->conf.peers.queues - 1 : 0; 3266f3fbe4eSDmitry Fleytman 3276f3fbe4eSDmitry Fleytman trace_e1000e_mac_set_permanent(MAC_ARG(macaddr)); 3286f3fbe4eSDmitry Fleytman memcpy(s->core.permanent_mac, macaddr, sizeof(s->core.permanent_mac)); 3296f3fbe4eSDmitry Fleytman 3306f3fbe4eSDmitry Fleytman qemu_format_nic_info_str(qemu_get_queue(s->nic), macaddr); 3316f3fbe4eSDmitry Fleytman 3326f3fbe4eSDmitry Fleytman /* Setup virtio headers */ 3336f3fbe4eSDmitry Fleytman if (s->disable_vnet) { 3346f3fbe4eSDmitry Fleytman s->core.has_vnet = false; 3356f3fbe4eSDmitry Fleytman trace_e1000e_cfg_support_virtio(false); 3366f3fbe4eSDmitry Fleytman return; 3376f3fbe4eSDmitry Fleytman } else { 3386f3fbe4eSDmitry Fleytman s->core.has_vnet = true; 3396f3fbe4eSDmitry Fleytman } 3406f3fbe4eSDmitry Fleytman 3416f3fbe4eSDmitry Fleytman for (i = 0; i < s->conf.peers.queues; i++) { 3426f3fbe4eSDmitry Fleytman nc = qemu_get_subqueue(s->nic, i); 3436f3fbe4eSDmitry Fleytman if (!nc->peer || !qemu_has_vnet_hdr(nc->peer)) { 3446f3fbe4eSDmitry Fleytman s->core.has_vnet = false; 3456f3fbe4eSDmitry Fleytman trace_e1000e_cfg_support_virtio(false); 3466f3fbe4eSDmitry Fleytman return; 3476f3fbe4eSDmitry Fleytman } 3486f3fbe4eSDmitry Fleytman } 3496f3fbe4eSDmitry Fleytman 3506f3fbe4eSDmitry Fleytman trace_e1000e_cfg_support_virtio(true); 3516f3fbe4eSDmitry Fleytman 3526f3fbe4eSDmitry Fleytman for (i = 0; i < s->conf.peers.queues; i++) { 3536f3fbe4eSDmitry Fleytman nc = qemu_get_subqueue(s->nic, i); 3546f3fbe4eSDmitry Fleytman qemu_set_vnet_hdr_len(nc->peer, sizeof(struct virtio_net_hdr)); 3556f3fbe4eSDmitry Fleytman qemu_using_vnet_hdr(nc->peer, true); 3566f3fbe4eSDmitry Fleytman } 3576f3fbe4eSDmitry Fleytman } 3586f3fbe4eSDmitry Fleytman 3596f3fbe4eSDmitry Fleytman static inline uint64_t 3606f3fbe4eSDmitry Fleytman e1000e_gen_dsn(uint8_t *mac) 3616f3fbe4eSDmitry Fleytman { 3626f3fbe4eSDmitry Fleytman return (uint64_t)(mac[5]) | 3636f3fbe4eSDmitry Fleytman (uint64_t)(mac[4]) << 8 | 3646f3fbe4eSDmitry Fleytman (uint64_t)(mac[3]) << 16 | 3656f3fbe4eSDmitry Fleytman (uint64_t)(0x00FF) << 24 | 3666f3fbe4eSDmitry Fleytman (uint64_t)(0x00FF) << 32 | 3676f3fbe4eSDmitry Fleytman (uint64_t)(mac[2]) << 40 | 3686f3fbe4eSDmitry Fleytman (uint64_t)(mac[1]) << 48 | 3696f3fbe4eSDmitry Fleytman (uint64_t)(mac[0]) << 56; 3706f3fbe4eSDmitry Fleytman } 3716f3fbe4eSDmitry Fleytman 3726f3fbe4eSDmitry Fleytman static int 3736f3fbe4eSDmitry Fleytman e1000e_add_pm_capability(PCIDevice *pdev, uint8_t offset, uint16_t pmc) 3746f3fbe4eSDmitry Fleytman { 3759a7c2a59SMao Zhongyi Error *local_err = NULL; 3769a7c2a59SMao Zhongyi int ret = pci_add_capability(pdev, PCI_CAP_ID_PM, offset, 3779a7c2a59SMao Zhongyi PCI_PM_SIZEOF, &local_err); 3786f3fbe4eSDmitry Fleytman 3799a7c2a59SMao Zhongyi if (local_err) { 3809a7c2a59SMao Zhongyi error_report_err(local_err); 3819a7c2a59SMao Zhongyi return ret; 3829a7c2a59SMao Zhongyi } 3839a7c2a59SMao Zhongyi 3846f3fbe4eSDmitry Fleytman pci_set_word(pdev->config + offset + PCI_PM_PMC, 3856f3fbe4eSDmitry Fleytman PCI_PM_CAP_VER_1_1 | 3866f3fbe4eSDmitry Fleytman pmc); 3876f3fbe4eSDmitry Fleytman 3886f3fbe4eSDmitry Fleytman pci_set_word(pdev->wmask + offset + PCI_PM_CTRL, 3896f3fbe4eSDmitry Fleytman PCI_PM_CTRL_STATE_MASK | 3906f3fbe4eSDmitry Fleytman PCI_PM_CTRL_PME_ENABLE | 3916f3fbe4eSDmitry Fleytman PCI_PM_CTRL_DATA_SEL_MASK); 3926f3fbe4eSDmitry Fleytman 3936f3fbe4eSDmitry Fleytman pci_set_word(pdev->w1cmask + offset + PCI_PM_CTRL, 3946f3fbe4eSDmitry Fleytman PCI_PM_CTRL_PME_STATUS); 3956f3fbe4eSDmitry Fleytman 3966f3fbe4eSDmitry Fleytman return ret; 3976f3fbe4eSDmitry Fleytman } 3986f3fbe4eSDmitry Fleytman 3996f3fbe4eSDmitry Fleytman static void e1000e_write_config(PCIDevice *pci_dev, uint32_t address, 4006f3fbe4eSDmitry Fleytman uint32_t val, int len) 4016f3fbe4eSDmitry Fleytman { 4026f3fbe4eSDmitry Fleytman E1000EState *s = E1000E(pci_dev); 4036f3fbe4eSDmitry Fleytman 4046f3fbe4eSDmitry Fleytman pci_default_write_config(pci_dev, address, val, len); 4056f3fbe4eSDmitry Fleytman 4066f3fbe4eSDmitry Fleytman if (range_covers_byte(address, len, PCI_COMMAND) && 4076f3fbe4eSDmitry Fleytman (pci_dev->config[PCI_COMMAND] & PCI_COMMAND_MASTER)) { 4086ee0e20bSDmitry Fleytman e1000e_start_recv(&s->core); 4096f3fbe4eSDmitry Fleytman } 4106f3fbe4eSDmitry Fleytman } 4116f3fbe4eSDmitry Fleytman 4126f3fbe4eSDmitry Fleytman static void e1000e_pci_realize(PCIDevice *pci_dev, Error **errp) 4136f3fbe4eSDmitry Fleytman { 4146f3fbe4eSDmitry Fleytman static const uint16_t e1000e_pmrb_offset = 0x0C8; 4156f3fbe4eSDmitry Fleytman static const uint16_t e1000e_pcie_offset = 0x0E0; 4166f3fbe4eSDmitry Fleytman static const uint16_t e1000e_aer_offset = 0x100; 4176f3fbe4eSDmitry Fleytman static const uint16_t e1000e_dsn_offset = 0x140; 4186f3fbe4eSDmitry Fleytman E1000EState *s = E1000E(pci_dev); 4196f3fbe4eSDmitry Fleytman uint8_t *macaddr; 42066bf7d58SCao jin int ret; 4216f3fbe4eSDmitry Fleytman 4226f3fbe4eSDmitry Fleytman trace_e1000e_cb_pci_realize(); 4236f3fbe4eSDmitry Fleytman 4246f3fbe4eSDmitry Fleytman pci_dev->config_write = e1000e_write_config; 4256f3fbe4eSDmitry Fleytman 4266f3fbe4eSDmitry Fleytman pci_dev->config[PCI_CACHE_LINE_SIZE] = 0x10; 4276f3fbe4eSDmitry Fleytman pci_dev->config[PCI_INTERRUPT_PIN] = 1; 4286f3fbe4eSDmitry Fleytman 4296f3fbe4eSDmitry Fleytman pci_set_word(pci_dev->config + PCI_SUBSYSTEM_VENDOR_ID, s->subsys_ven); 4306f3fbe4eSDmitry Fleytman pci_set_word(pci_dev->config + PCI_SUBSYSTEM_ID, s->subsys); 4316f3fbe4eSDmitry Fleytman 4326f3fbe4eSDmitry Fleytman s->subsys_ven_used = s->subsys_ven; 4336f3fbe4eSDmitry Fleytman s->subsys_used = s->subsys; 4346f3fbe4eSDmitry Fleytman 4356f3fbe4eSDmitry Fleytman /* Define IO/MMIO regions */ 4366f3fbe4eSDmitry Fleytman memory_region_init_io(&s->mmio, OBJECT(s), &mmio_ops, s, 4376f3fbe4eSDmitry Fleytman "e1000e-mmio", E1000E_MMIO_SIZE); 4386f3fbe4eSDmitry Fleytman pci_register_bar(pci_dev, E1000E_MMIO_IDX, 4396f3fbe4eSDmitry Fleytman PCI_BASE_ADDRESS_SPACE_MEMORY, &s->mmio); 4406f3fbe4eSDmitry Fleytman 4416f3fbe4eSDmitry Fleytman /* 4426f3fbe4eSDmitry Fleytman * We provide a dummy implementation for the flash BAR 4436f3fbe4eSDmitry Fleytman * for drivers that may theoretically probe for its presence. 4446f3fbe4eSDmitry Fleytman */ 4456f3fbe4eSDmitry Fleytman memory_region_init(&s->flash, OBJECT(s), 4466f3fbe4eSDmitry Fleytman "e1000e-flash", E1000E_FLASH_SIZE); 4476f3fbe4eSDmitry Fleytman pci_register_bar(pci_dev, E1000E_FLASH_IDX, 4486f3fbe4eSDmitry Fleytman PCI_BASE_ADDRESS_SPACE_MEMORY, &s->flash); 4496f3fbe4eSDmitry Fleytman 4506f3fbe4eSDmitry Fleytman memory_region_init_io(&s->io, OBJECT(s), &io_ops, s, 4516f3fbe4eSDmitry Fleytman "e1000e-io", E1000E_IO_SIZE); 4526f3fbe4eSDmitry Fleytman pci_register_bar(pci_dev, E1000E_IO_IDX, 4536f3fbe4eSDmitry Fleytman PCI_BASE_ADDRESS_SPACE_IO, &s->io); 4546f3fbe4eSDmitry Fleytman 4556f3fbe4eSDmitry Fleytman memory_region_init(&s->msix, OBJECT(s), "e1000e-msix", 4566f3fbe4eSDmitry Fleytman E1000E_MSIX_SIZE); 4576f3fbe4eSDmitry Fleytman pci_register_bar(pci_dev, E1000E_MSIX_IDX, 4586f3fbe4eSDmitry Fleytman PCI_BASE_ADDRESS_SPACE_MEMORY, &s->msix); 4596f3fbe4eSDmitry Fleytman 4606f3fbe4eSDmitry Fleytman /* Create networking backend */ 4616f3fbe4eSDmitry Fleytman qemu_macaddr_default_if_unset(&s->conf.macaddr); 4626f3fbe4eSDmitry Fleytman macaddr = s->conf.macaddr.a; 4636f3fbe4eSDmitry Fleytman 4646f3fbe4eSDmitry Fleytman e1000e_init_msix(s); 4656f3fbe4eSDmitry Fleytman 4666f3fbe4eSDmitry Fleytman if (pcie_endpoint_cap_v1_init(pci_dev, e1000e_pcie_offset) < 0) { 4676f3fbe4eSDmitry Fleytman hw_error("Failed to initialize PCIe capability"); 4686f3fbe4eSDmitry Fleytman } 4696f3fbe4eSDmitry Fleytman 47066bf7d58SCao jin ret = msi_init(PCI_DEVICE(s), 0xD0, 1, true, false, NULL); 47166bf7d58SCao jin if (ret) { 47266bf7d58SCao jin trace_e1000e_msi_init_fail(ret); 47366bf7d58SCao jin } 4746f3fbe4eSDmitry Fleytman 4756f3fbe4eSDmitry Fleytman if (e1000e_add_pm_capability(pci_dev, e1000e_pmrb_offset, 4766f3fbe4eSDmitry Fleytman PCI_PM_CAP_DSI) < 0) { 4776f3fbe4eSDmitry Fleytman hw_error("Failed to initialize PM capability"); 4786f3fbe4eSDmitry Fleytman } 4796f3fbe4eSDmitry Fleytman 480f18c697bSDou Liyang if (pcie_aer_init(pci_dev, PCI_ERR_VER, e1000e_aer_offset, 481f18c697bSDou Liyang PCI_ERR_SIZEOF, NULL) < 0) { 4826f3fbe4eSDmitry Fleytman hw_error("Failed to initialize AER capability"); 4836f3fbe4eSDmitry Fleytman } 4846f3fbe4eSDmitry Fleytman 4856f3fbe4eSDmitry Fleytman pcie_dev_ser_num_init(pci_dev, e1000e_dsn_offset, 4866f3fbe4eSDmitry Fleytman e1000e_gen_dsn(macaddr)); 4876f3fbe4eSDmitry Fleytman 4886f3fbe4eSDmitry Fleytman e1000e_init_net_peer(s, pci_dev, macaddr); 4896f3fbe4eSDmitry Fleytman 4906f3fbe4eSDmitry Fleytman /* Initialize core */ 4916f3fbe4eSDmitry Fleytman e1000e_core_realize(s); 4926f3fbe4eSDmitry Fleytman 4936f3fbe4eSDmitry Fleytman e1000e_core_pci_realize(&s->core, 4946f3fbe4eSDmitry Fleytman e1000e_eeprom_template, 4956f3fbe4eSDmitry Fleytman sizeof(e1000e_eeprom_template), 4966f3fbe4eSDmitry Fleytman macaddr); 4976f3fbe4eSDmitry Fleytman } 4986f3fbe4eSDmitry Fleytman 4996f3fbe4eSDmitry Fleytman static void e1000e_pci_uninit(PCIDevice *pci_dev) 5006f3fbe4eSDmitry Fleytman { 5016f3fbe4eSDmitry Fleytman E1000EState *s = E1000E(pci_dev); 5026f3fbe4eSDmitry Fleytman 5036f3fbe4eSDmitry Fleytman trace_e1000e_cb_pci_uninit(); 5046f3fbe4eSDmitry Fleytman 5056f3fbe4eSDmitry Fleytman e1000e_core_pci_uninit(&s->core); 5066f3fbe4eSDmitry Fleytman 5076f3fbe4eSDmitry Fleytman pcie_aer_exit(pci_dev); 5086f3fbe4eSDmitry Fleytman pcie_cap_exit(pci_dev); 5096f3fbe4eSDmitry Fleytman 5106f3fbe4eSDmitry Fleytman qemu_del_nic(s->nic); 5116f3fbe4eSDmitry Fleytman 5126f3fbe4eSDmitry Fleytman e1000e_cleanup_msix(s); 51366bf7d58SCao jin msi_uninit(pci_dev); 5146f3fbe4eSDmitry Fleytman } 5156f3fbe4eSDmitry Fleytman 5166f3fbe4eSDmitry Fleytman static void e1000e_qdev_reset(DeviceState *dev) 5176f3fbe4eSDmitry Fleytman { 5186f3fbe4eSDmitry Fleytman E1000EState *s = E1000E(dev); 5196f3fbe4eSDmitry Fleytman 5206f3fbe4eSDmitry Fleytman trace_e1000e_cb_qdev_reset(); 5216f3fbe4eSDmitry Fleytman 5226f3fbe4eSDmitry Fleytman e1000e_core_reset(&s->core); 523d8970569SChristina Wang 524d8970569SChristina Wang if (s->init_vet) { 525d8970569SChristina Wang s->core.mac[VET] = ETH_P_VLAN; 526d8970569SChristina Wang } 5276f3fbe4eSDmitry Fleytman } 5286f3fbe4eSDmitry Fleytman 52944b1ff31SDr. David Alan Gilbert static int e1000e_pre_save(void *opaque) 5306f3fbe4eSDmitry Fleytman { 5316f3fbe4eSDmitry Fleytman E1000EState *s = opaque; 5326f3fbe4eSDmitry Fleytman 5336f3fbe4eSDmitry Fleytman trace_e1000e_cb_pre_save(); 5346f3fbe4eSDmitry Fleytman 5356f3fbe4eSDmitry Fleytman e1000e_core_pre_save(&s->core); 53644b1ff31SDr. David Alan Gilbert 53744b1ff31SDr. David Alan Gilbert return 0; 5386f3fbe4eSDmitry Fleytman } 5396f3fbe4eSDmitry Fleytman 5406f3fbe4eSDmitry Fleytman static int e1000e_post_load(void *opaque, int version_id) 5416f3fbe4eSDmitry Fleytman { 5426f3fbe4eSDmitry Fleytman E1000EState *s = opaque; 5436f3fbe4eSDmitry Fleytman 5446f3fbe4eSDmitry Fleytman trace_e1000e_cb_post_load(); 5456f3fbe4eSDmitry Fleytman 5466f3fbe4eSDmitry Fleytman if ((s->subsys != s->subsys_used) || 5476f3fbe4eSDmitry Fleytman (s->subsys_ven != s->subsys_ven_used)) { 5486f3fbe4eSDmitry Fleytman fprintf(stderr, 5496f3fbe4eSDmitry Fleytman "ERROR: Cannot migrate while device properties " 5506f3fbe4eSDmitry Fleytman "(subsys/subsys_ven) differ"); 5516f3fbe4eSDmitry Fleytman return -1; 5526f3fbe4eSDmitry Fleytman } 5536f3fbe4eSDmitry Fleytman 5546f3fbe4eSDmitry Fleytman return e1000e_core_post_load(&s->core); 5556f3fbe4eSDmitry Fleytman } 5566f3fbe4eSDmitry Fleytman 5576f3fbe4eSDmitry Fleytman static const VMStateDescription e1000e_vmstate_tx = { 5586f3fbe4eSDmitry Fleytman .name = "e1000e-tx", 5596f3fbe4eSDmitry Fleytman .version_id = 1, 5606f3fbe4eSDmitry Fleytman .minimum_version_id = 1, 5616f3fbe4eSDmitry Fleytman .fields = (VMStateField[]) { 5627d08c73eSEd Swierk via Qemu-devel VMSTATE_UINT8(sum_needed, struct e1000e_tx), 5636f3fbe4eSDmitry Fleytman VMSTATE_UINT8(props.ipcss, struct e1000e_tx), 5646f3fbe4eSDmitry Fleytman VMSTATE_UINT8(props.ipcso, struct e1000e_tx), 5656f3fbe4eSDmitry Fleytman VMSTATE_UINT16(props.ipcse, struct e1000e_tx), 5666f3fbe4eSDmitry Fleytman VMSTATE_UINT8(props.tucss, struct e1000e_tx), 5676f3fbe4eSDmitry Fleytman VMSTATE_UINT8(props.tucso, struct e1000e_tx), 5686f3fbe4eSDmitry Fleytman VMSTATE_UINT16(props.tucse, struct e1000e_tx), 5696f3fbe4eSDmitry Fleytman VMSTATE_UINT8(props.hdr_len, struct e1000e_tx), 5706f3fbe4eSDmitry Fleytman VMSTATE_UINT16(props.mss, struct e1000e_tx), 5716f3fbe4eSDmitry Fleytman VMSTATE_UINT32(props.paylen, struct e1000e_tx), 5726f3fbe4eSDmitry Fleytman VMSTATE_INT8(props.ip, struct e1000e_tx), 5736f3fbe4eSDmitry Fleytman VMSTATE_INT8(props.tcp, struct e1000e_tx), 5746f3fbe4eSDmitry Fleytman VMSTATE_BOOL(props.tse, struct e1000e_tx), 5757d08c73eSEd Swierk via Qemu-devel VMSTATE_BOOL(cptse, struct e1000e_tx), 5766f3fbe4eSDmitry Fleytman VMSTATE_BOOL(skip_cp, struct e1000e_tx), 5776f3fbe4eSDmitry Fleytman VMSTATE_END_OF_LIST() 5786f3fbe4eSDmitry Fleytman } 5796f3fbe4eSDmitry Fleytman }; 5806f3fbe4eSDmitry Fleytman 5816f3fbe4eSDmitry Fleytman static const VMStateDescription e1000e_vmstate_intr_timer = { 5826f3fbe4eSDmitry Fleytman .name = "e1000e-intr-timer", 5836f3fbe4eSDmitry Fleytman .version_id = 1, 5846f3fbe4eSDmitry Fleytman .minimum_version_id = 1, 5856f3fbe4eSDmitry Fleytman .fields = (VMStateField[]) { 5866f3fbe4eSDmitry Fleytman VMSTATE_TIMER_PTR(timer, E1000IntrDelayTimer), 5876f3fbe4eSDmitry Fleytman VMSTATE_BOOL(running, E1000IntrDelayTimer), 5886f3fbe4eSDmitry Fleytman VMSTATE_END_OF_LIST() 5896f3fbe4eSDmitry Fleytman } 5906f3fbe4eSDmitry Fleytman }; 5916f3fbe4eSDmitry Fleytman 5926f3fbe4eSDmitry Fleytman #define VMSTATE_E1000E_INTR_DELAY_TIMER(_f, _s) \ 5936f3fbe4eSDmitry Fleytman VMSTATE_STRUCT(_f, _s, 0, \ 5946f3fbe4eSDmitry Fleytman e1000e_vmstate_intr_timer, E1000IntrDelayTimer) 5956f3fbe4eSDmitry Fleytman 5966f3fbe4eSDmitry Fleytman #define VMSTATE_E1000E_INTR_DELAY_TIMER_ARRAY(_f, _s, _num) \ 5976f3fbe4eSDmitry Fleytman VMSTATE_STRUCT_ARRAY(_f, _s, _num, 0, \ 5986f3fbe4eSDmitry Fleytman e1000e_vmstate_intr_timer, E1000IntrDelayTimer) 5996f3fbe4eSDmitry Fleytman 6006f3fbe4eSDmitry Fleytman static const VMStateDescription e1000e_vmstate = { 6016f3fbe4eSDmitry Fleytman .name = "e1000e", 6026f3fbe4eSDmitry Fleytman .version_id = 1, 6036f3fbe4eSDmitry Fleytman .minimum_version_id = 1, 6046f3fbe4eSDmitry Fleytman .pre_save = e1000e_pre_save, 6056f3fbe4eSDmitry Fleytman .post_load = e1000e_post_load, 6066f3fbe4eSDmitry Fleytman .fields = (VMStateField[]) { 60720daa90aSDr. David Alan Gilbert VMSTATE_PCI_DEVICE(parent_obj, E1000EState), 6086f3fbe4eSDmitry Fleytman VMSTATE_MSIX(parent_obj, E1000EState), 6096f3fbe4eSDmitry Fleytman 6106f3fbe4eSDmitry Fleytman VMSTATE_UINT32(ioaddr, E1000EState), 6116f3fbe4eSDmitry Fleytman VMSTATE_UINT32(core.rxbuf_min_shift, E1000EState), 6126f3fbe4eSDmitry Fleytman VMSTATE_UINT8(core.rx_desc_len, E1000EState), 6136f3fbe4eSDmitry Fleytman VMSTATE_UINT32_ARRAY(core.rxbuf_sizes, E1000EState, 6146f3fbe4eSDmitry Fleytman E1000_PSRCTL_BUFFS_PER_DESC), 6156f3fbe4eSDmitry Fleytman VMSTATE_UINT32(core.rx_desc_buf_size, E1000EState), 6166f3fbe4eSDmitry Fleytman VMSTATE_UINT16_ARRAY(core.eeprom, E1000EState, E1000E_EEPROM_SIZE), 6176f3fbe4eSDmitry Fleytman VMSTATE_UINT16_2DARRAY(core.phy, E1000EState, 6186f3fbe4eSDmitry Fleytman E1000E_PHY_PAGES, E1000E_PHY_PAGE_SIZE), 6196f3fbe4eSDmitry Fleytman VMSTATE_UINT32_ARRAY(core.mac, E1000EState, E1000E_MAC_SIZE), 6206f3fbe4eSDmitry Fleytman VMSTATE_UINT8_ARRAY(core.permanent_mac, E1000EState, ETH_ALEN), 6216f3fbe4eSDmitry Fleytman 6226f3fbe4eSDmitry Fleytman VMSTATE_UINT32(core.delayed_causes, E1000EState), 6236f3fbe4eSDmitry Fleytman 6246f3fbe4eSDmitry Fleytman VMSTATE_UINT16(subsys, E1000EState), 6256f3fbe4eSDmitry Fleytman VMSTATE_UINT16(subsys_ven, E1000EState), 6266f3fbe4eSDmitry Fleytman 6276f3fbe4eSDmitry Fleytman VMSTATE_E1000E_INTR_DELAY_TIMER(core.rdtr, E1000EState), 6286f3fbe4eSDmitry Fleytman VMSTATE_E1000E_INTR_DELAY_TIMER(core.radv, E1000EState), 6296f3fbe4eSDmitry Fleytman VMSTATE_E1000E_INTR_DELAY_TIMER(core.raid, E1000EState), 6306f3fbe4eSDmitry Fleytman VMSTATE_E1000E_INTR_DELAY_TIMER(core.tadv, E1000EState), 6316f3fbe4eSDmitry Fleytman VMSTATE_E1000E_INTR_DELAY_TIMER(core.tidv, E1000EState), 6326f3fbe4eSDmitry Fleytman 6336f3fbe4eSDmitry Fleytman VMSTATE_E1000E_INTR_DELAY_TIMER(core.itr, E1000EState), 6346f3fbe4eSDmitry Fleytman VMSTATE_BOOL(core.itr_intr_pending, E1000EState), 6356f3fbe4eSDmitry Fleytman 6366f3fbe4eSDmitry Fleytman VMSTATE_E1000E_INTR_DELAY_TIMER_ARRAY(core.eitr, E1000EState, 6376f3fbe4eSDmitry Fleytman E1000E_MSIX_VEC_NUM), 6386f3fbe4eSDmitry Fleytman VMSTATE_BOOL_ARRAY(core.eitr_intr_pending, E1000EState, 6396f3fbe4eSDmitry Fleytman E1000E_MSIX_VEC_NUM), 6406f3fbe4eSDmitry Fleytman 6416f3fbe4eSDmitry Fleytman VMSTATE_UINT32(core.itr_guest_value, E1000EState), 6426f3fbe4eSDmitry Fleytman VMSTATE_UINT32_ARRAY(core.eitr_guest_value, E1000EState, 6436f3fbe4eSDmitry Fleytman E1000E_MSIX_VEC_NUM), 6446f3fbe4eSDmitry Fleytman 6456f3fbe4eSDmitry Fleytman VMSTATE_UINT16(core.vet, E1000EState), 6466f3fbe4eSDmitry Fleytman 6476f3fbe4eSDmitry Fleytman VMSTATE_STRUCT_ARRAY(core.tx, E1000EState, E1000E_NUM_QUEUES, 0, 6486f3fbe4eSDmitry Fleytman e1000e_vmstate_tx, struct e1000e_tx), 6496f3fbe4eSDmitry Fleytman VMSTATE_END_OF_LIST() 6506f3fbe4eSDmitry Fleytman } 6516f3fbe4eSDmitry Fleytman }; 6526f3fbe4eSDmitry Fleytman 6536f3fbe4eSDmitry Fleytman static PropertyInfo e1000e_prop_disable_vnet, 6546f3fbe4eSDmitry Fleytman e1000e_prop_subsys_ven, 6556f3fbe4eSDmitry Fleytman e1000e_prop_subsys; 6566f3fbe4eSDmitry Fleytman 6576f3fbe4eSDmitry Fleytman static Property e1000e_properties[] = { 6586f3fbe4eSDmitry Fleytman DEFINE_NIC_PROPERTIES(E1000EState, conf), 65985bbd1e7SMarc-André Lureau DEFINE_PROP_SIGNED("disable_vnet_hdr", E1000EState, disable_vnet, false, 6606f3fbe4eSDmitry Fleytman e1000e_prop_disable_vnet, bool), 66185bbd1e7SMarc-André Lureau DEFINE_PROP_SIGNED("subsys_ven", E1000EState, subsys_ven, 6626f3fbe4eSDmitry Fleytman PCI_VENDOR_ID_INTEL, 6636f3fbe4eSDmitry Fleytman e1000e_prop_subsys_ven, uint16_t), 66485bbd1e7SMarc-André Lureau DEFINE_PROP_SIGNED("subsys", E1000EState, subsys, 0, 6656f3fbe4eSDmitry Fleytman e1000e_prop_subsys, uint16_t), 666d8970569SChristina Wang DEFINE_PROP_BOOL("init-vet", E1000EState, init_vet, true), 6676f3fbe4eSDmitry Fleytman DEFINE_PROP_END_OF_LIST(), 6686f3fbe4eSDmitry Fleytman }; 6696f3fbe4eSDmitry Fleytman 6706f3fbe4eSDmitry Fleytman static void e1000e_class_init(ObjectClass *class, void *data) 6716f3fbe4eSDmitry Fleytman { 6726f3fbe4eSDmitry Fleytman DeviceClass *dc = DEVICE_CLASS(class); 6736f3fbe4eSDmitry Fleytman PCIDeviceClass *c = PCI_DEVICE_CLASS(class); 6746f3fbe4eSDmitry Fleytman 6756f3fbe4eSDmitry Fleytman c->realize = e1000e_pci_realize; 6766f3fbe4eSDmitry Fleytman c->exit = e1000e_pci_uninit; 6776f3fbe4eSDmitry Fleytman c->vendor_id = PCI_VENDOR_ID_INTEL; 6786f3fbe4eSDmitry Fleytman c->device_id = E1000_DEV_ID_82574L; 6796f3fbe4eSDmitry Fleytman c->revision = 0; 6801676103dSGerd Hoffmann c->romfile = "efi-e1000e.rom"; 6816f3fbe4eSDmitry Fleytman c->class_id = PCI_CLASS_NETWORK_ETHERNET; 6826f3fbe4eSDmitry Fleytman 6836f3fbe4eSDmitry Fleytman dc->desc = "Intel 82574L GbE Controller"; 6846f3fbe4eSDmitry Fleytman dc->reset = e1000e_qdev_reset; 6856f3fbe4eSDmitry Fleytman dc->vmsd = &e1000e_vmstate; 6866f3fbe4eSDmitry Fleytman 6876f3fbe4eSDmitry Fleytman e1000e_prop_disable_vnet = qdev_prop_uint8; 6886f3fbe4eSDmitry Fleytman e1000e_prop_disable_vnet.description = "Do not use virtio headers, " 6896f3fbe4eSDmitry Fleytman "perform SW offloads emulation " 6906f3fbe4eSDmitry Fleytman "instead"; 6916f3fbe4eSDmitry Fleytman 6926f3fbe4eSDmitry Fleytman e1000e_prop_subsys_ven = qdev_prop_uint16; 6936f3fbe4eSDmitry Fleytman e1000e_prop_subsys_ven.description = "PCI device Subsystem Vendor ID"; 6946f3fbe4eSDmitry Fleytman 6956f3fbe4eSDmitry Fleytman e1000e_prop_subsys = qdev_prop_uint16; 6966f3fbe4eSDmitry Fleytman e1000e_prop_subsys.description = "PCI device Subsystem ID"; 6976f3fbe4eSDmitry Fleytman 6984f67d30bSMarc-André Lureau device_class_set_props(dc, e1000e_properties); 6996f3fbe4eSDmitry Fleytman set_bit(DEVICE_CATEGORY_NETWORK, dc->categories); 7006f3fbe4eSDmitry Fleytman } 7016f3fbe4eSDmitry Fleytman 7026f3fbe4eSDmitry Fleytman static void e1000e_instance_init(Object *obj) 7036f3fbe4eSDmitry Fleytman { 7046f3fbe4eSDmitry Fleytman E1000EState *s = E1000E(obj); 7056f3fbe4eSDmitry Fleytman device_add_bootindex_property(obj, &s->conf.bootindex, 7066f3fbe4eSDmitry Fleytman "bootindex", "/ethernet-phy@0", 70740c2281cSMarkus Armbruster DEVICE(obj)); 7086f3fbe4eSDmitry Fleytman } 7096f3fbe4eSDmitry Fleytman 7106f3fbe4eSDmitry Fleytman static const TypeInfo e1000e_info = { 7116f3fbe4eSDmitry Fleytman .name = TYPE_E1000E, 7126f3fbe4eSDmitry Fleytman .parent = TYPE_PCI_DEVICE, 7136f3fbe4eSDmitry Fleytman .instance_size = sizeof(E1000EState), 7146f3fbe4eSDmitry Fleytman .class_init = e1000e_class_init, 7156f3fbe4eSDmitry Fleytman .instance_init = e1000e_instance_init, 71671d78767SEduardo Habkost .interfaces = (InterfaceInfo[]) { 71771d78767SEduardo Habkost { INTERFACE_PCIE_DEVICE }, 71871d78767SEduardo Habkost { } 71971d78767SEduardo Habkost }, 7206f3fbe4eSDmitry Fleytman }; 7216f3fbe4eSDmitry Fleytman 7226f3fbe4eSDmitry Fleytman static void e1000e_register_types(void) 7236f3fbe4eSDmitry Fleytman { 7246f3fbe4eSDmitry Fleytman type_register_static(&e1000e_info); 7256f3fbe4eSDmitry Fleytman } 7266f3fbe4eSDmitry Fleytman 7276f3fbe4eSDmitry Fleytman type_init(e1000e_register_types) 728