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" 37872a2b7cSPhilippe Mathieu-Daudé #include "qemu/units.h" 386f3fbe4eSDmitry Fleytman #include "net/net.h" 396f3fbe4eSDmitry Fleytman #include "net/tap.h" 400b8fa32fSMarkus Armbruster #include "qemu/module.h" 416f3fbe4eSDmitry Fleytman #include "qemu/range.h" 426f3fbe4eSDmitry Fleytman #include "sysemu/sysemu.h" 436f3fbe4eSDmitry Fleytman #include "hw/pci/msi.h" 446f3fbe4eSDmitry Fleytman #include "hw/pci/msix.h" 45*d6454270SMarkus Armbruster #include "migration/vmstate.h" 466f3fbe4eSDmitry Fleytman 47e703a5a1SMichael S. Tsirkin #include "e1000_regs.h" 486f3fbe4eSDmitry Fleytman 496f3fbe4eSDmitry Fleytman #include "e1000x_common.h" 506f3fbe4eSDmitry Fleytman #include "e1000e_core.h" 516f3fbe4eSDmitry Fleytman 526f3fbe4eSDmitry Fleytman #include "trace.h" 539a7c2a59SMao Zhongyi #include "qapi/error.h" 546f3fbe4eSDmitry Fleytman 556f3fbe4eSDmitry Fleytman #define TYPE_E1000E "e1000e" 566f3fbe4eSDmitry Fleytman #define E1000E(obj) OBJECT_CHECK(E1000EState, (obj), TYPE_E1000E) 576f3fbe4eSDmitry Fleytman 586f3fbe4eSDmitry Fleytman typedef struct E1000EState { 596f3fbe4eSDmitry Fleytman PCIDevice parent_obj; 606f3fbe4eSDmitry Fleytman NICState *nic; 616f3fbe4eSDmitry Fleytman NICConf conf; 626f3fbe4eSDmitry Fleytman 636f3fbe4eSDmitry Fleytman MemoryRegion mmio; 646f3fbe4eSDmitry Fleytman MemoryRegion flash; 656f3fbe4eSDmitry Fleytman MemoryRegion io; 666f3fbe4eSDmitry Fleytman MemoryRegion msix; 676f3fbe4eSDmitry Fleytman 686f3fbe4eSDmitry Fleytman uint32_t ioaddr; 696f3fbe4eSDmitry Fleytman 706f3fbe4eSDmitry Fleytman uint16_t subsys_ven; 716f3fbe4eSDmitry Fleytman uint16_t subsys; 726f3fbe4eSDmitry Fleytman 736f3fbe4eSDmitry Fleytman uint16_t subsys_ven_used; 746f3fbe4eSDmitry Fleytman uint16_t subsys_used; 756f3fbe4eSDmitry Fleytman 766f3fbe4eSDmitry Fleytman bool disable_vnet; 776f3fbe4eSDmitry Fleytman 786f3fbe4eSDmitry Fleytman E1000ECore core; 796f3fbe4eSDmitry Fleytman 806f3fbe4eSDmitry Fleytman } E1000EState; 816f3fbe4eSDmitry Fleytman 826f3fbe4eSDmitry Fleytman #define E1000E_MMIO_IDX 0 836f3fbe4eSDmitry Fleytman #define E1000E_FLASH_IDX 1 846f3fbe4eSDmitry Fleytman #define E1000E_IO_IDX 2 856f3fbe4eSDmitry Fleytman #define E1000E_MSIX_IDX 3 866f3fbe4eSDmitry Fleytman 87872a2b7cSPhilippe Mathieu-Daudé #define E1000E_MMIO_SIZE (128 * KiB) 88872a2b7cSPhilippe Mathieu-Daudé #define E1000E_FLASH_SIZE (128 * KiB) 896f3fbe4eSDmitry Fleytman #define E1000E_IO_SIZE (32) 90872a2b7cSPhilippe Mathieu-Daudé #define E1000E_MSIX_SIZE (16 * KiB) 916f3fbe4eSDmitry Fleytman 926f3fbe4eSDmitry Fleytman #define E1000E_MSIX_TABLE (0x0000) 936f3fbe4eSDmitry Fleytman #define E1000E_MSIX_PBA (0x2000) 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 = { 229f394b2e2SEric Blake .type = NET_CLIENT_DRIVER_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_unuse_msix_vectors(E1000EState *s, int num_vectors) 2686f3fbe4eSDmitry Fleytman { 2696f3fbe4eSDmitry Fleytman int i; 2706f3fbe4eSDmitry Fleytman for (i = 0; i < num_vectors; i++) { 2716f3fbe4eSDmitry Fleytman msix_vector_unuse(PCI_DEVICE(s), i); 2726f3fbe4eSDmitry Fleytman } 2736f3fbe4eSDmitry Fleytman } 2746f3fbe4eSDmitry Fleytman 2756f3fbe4eSDmitry Fleytman static bool 2766f3fbe4eSDmitry Fleytman e1000e_use_msix_vectors(E1000EState *s, int num_vectors) 2776f3fbe4eSDmitry Fleytman { 2786f3fbe4eSDmitry Fleytman int i; 2796f3fbe4eSDmitry Fleytman for (i = 0; i < num_vectors; i++) { 2806f3fbe4eSDmitry Fleytman int res = msix_vector_use(PCI_DEVICE(s), i); 2816f3fbe4eSDmitry Fleytman if (res < 0) { 2826f3fbe4eSDmitry Fleytman trace_e1000e_msix_use_vector_fail(i, res); 2836f3fbe4eSDmitry Fleytman e1000e_unuse_msix_vectors(s, i); 2846f3fbe4eSDmitry Fleytman return false; 2856f3fbe4eSDmitry Fleytman } 2866f3fbe4eSDmitry Fleytman } 2876f3fbe4eSDmitry Fleytman return true; 2886f3fbe4eSDmitry Fleytman } 2896f3fbe4eSDmitry Fleytman 2906f3fbe4eSDmitry Fleytman static void 2916f3fbe4eSDmitry Fleytman e1000e_init_msix(E1000EState *s) 2926f3fbe4eSDmitry Fleytman { 2936f3fbe4eSDmitry Fleytman PCIDevice *d = PCI_DEVICE(s); 2946f3fbe4eSDmitry Fleytman int res = msix_init(PCI_DEVICE(s), E1000E_MSIX_VEC_NUM, 2956f3fbe4eSDmitry Fleytman &s->msix, 2966f3fbe4eSDmitry Fleytman E1000E_MSIX_IDX, E1000E_MSIX_TABLE, 2976f3fbe4eSDmitry Fleytman &s->msix, 2986f3fbe4eSDmitry Fleytman E1000E_MSIX_IDX, E1000E_MSIX_PBA, 299ee640c62SCao jin 0xA0, NULL); 3006f3fbe4eSDmitry Fleytman 3016f3fbe4eSDmitry Fleytman if (res < 0) { 3026f3fbe4eSDmitry Fleytman trace_e1000e_msix_init_fail(res); 3036f3fbe4eSDmitry Fleytman } else { 3046f3fbe4eSDmitry Fleytman if (!e1000e_use_msix_vectors(s, E1000E_MSIX_VEC_NUM)) { 3056f3fbe4eSDmitry Fleytman msix_uninit(d, &s->msix, &s->msix); 3066f3fbe4eSDmitry Fleytman } 3076f3fbe4eSDmitry Fleytman } 3086f3fbe4eSDmitry Fleytman } 3096f3fbe4eSDmitry Fleytman 3106f3fbe4eSDmitry Fleytman static void 3116f3fbe4eSDmitry Fleytman e1000e_cleanup_msix(E1000EState *s) 3126f3fbe4eSDmitry Fleytman { 3137ec7ae4bSPaolo Bonzini if (msix_present(PCI_DEVICE(s))) { 3146f3fbe4eSDmitry Fleytman e1000e_unuse_msix_vectors(s, E1000E_MSIX_VEC_NUM); 3156f3fbe4eSDmitry Fleytman msix_uninit(PCI_DEVICE(s), &s->msix, &s->msix); 3166f3fbe4eSDmitry Fleytman } 3176f3fbe4eSDmitry Fleytman } 3186f3fbe4eSDmitry Fleytman 3196f3fbe4eSDmitry Fleytman static void 3206f3fbe4eSDmitry Fleytman e1000e_init_net_peer(E1000EState *s, PCIDevice *pci_dev, uint8_t *macaddr) 3216f3fbe4eSDmitry Fleytman { 3226f3fbe4eSDmitry Fleytman DeviceState *dev = DEVICE(pci_dev); 3236f3fbe4eSDmitry Fleytman NetClientState *nc; 3246f3fbe4eSDmitry Fleytman int i; 3256f3fbe4eSDmitry Fleytman 3266f3fbe4eSDmitry Fleytman s->nic = qemu_new_nic(&net_e1000e_info, &s->conf, 3276f3fbe4eSDmitry Fleytman object_get_typename(OBJECT(s)), dev->id, s); 3286f3fbe4eSDmitry Fleytman 3296f3fbe4eSDmitry Fleytman s->core.max_queue_num = s->conf.peers.queues - 1; 3306f3fbe4eSDmitry Fleytman 3316f3fbe4eSDmitry Fleytman trace_e1000e_mac_set_permanent(MAC_ARG(macaddr)); 3326f3fbe4eSDmitry Fleytman memcpy(s->core.permanent_mac, macaddr, sizeof(s->core.permanent_mac)); 3336f3fbe4eSDmitry Fleytman 3346f3fbe4eSDmitry Fleytman qemu_format_nic_info_str(qemu_get_queue(s->nic), macaddr); 3356f3fbe4eSDmitry Fleytman 3366f3fbe4eSDmitry Fleytman /* Setup virtio headers */ 3376f3fbe4eSDmitry Fleytman if (s->disable_vnet) { 3386f3fbe4eSDmitry Fleytman s->core.has_vnet = false; 3396f3fbe4eSDmitry Fleytman trace_e1000e_cfg_support_virtio(false); 3406f3fbe4eSDmitry Fleytman return; 3416f3fbe4eSDmitry Fleytman } else { 3426f3fbe4eSDmitry Fleytman s->core.has_vnet = true; 3436f3fbe4eSDmitry Fleytman } 3446f3fbe4eSDmitry Fleytman 3456f3fbe4eSDmitry Fleytman for (i = 0; i < s->conf.peers.queues; i++) { 3466f3fbe4eSDmitry Fleytman nc = qemu_get_subqueue(s->nic, i); 3476f3fbe4eSDmitry Fleytman if (!nc->peer || !qemu_has_vnet_hdr(nc->peer)) { 3486f3fbe4eSDmitry Fleytman s->core.has_vnet = false; 3496f3fbe4eSDmitry Fleytman trace_e1000e_cfg_support_virtio(false); 3506f3fbe4eSDmitry Fleytman return; 3516f3fbe4eSDmitry Fleytman } 3526f3fbe4eSDmitry Fleytman } 3536f3fbe4eSDmitry Fleytman 3546f3fbe4eSDmitry Fleytman trace_e1000e_cfg_support_virtio(true); 3556f3fbe4eSDmitry Fleytman 3566f3fbe4eSDmitry Fleytman for (i = 0; i < s->conf.peers.queues; i++) { 3576f3fbe4eSDmitry Fleytman nc = qemu_get_subqueue(s->nic, i); 3586f3fbe4eSDmitry Fleytman qemu_set_vnet_hdr_len(nc->peer, sizeof(struct virtio_net_hdr)); 3596f3fbe4eSDmitry Fleytman qemu_using_vnet_hdr(nc->peer, true); 3606f3fbe4eSDmitry Fleytman } 3616f3fbe4eSDmitry Fleytman } 3626f3fbe4eSDmitry Fleytman 3636f3fbe4eSDmitry Fleytman static inline uint64_t 3646f3fbe4eSDmitry Fleytman e1000e_gen_dsn(uint8_t *mac) 3656f3fbe4eSDmitry Fleytman { 3666f3fbe4eSDmitry Fleytman return (uint64_t)(mac[5]) | 3676f3fbe4eSDmitry Fleytman (uint64_t)(mac[4]) << 8 | 3686f3fbe4eSDmitry Fleytman (uint64_t)(mac[3]) << 16 | 3696f3fbe4eSDmitry Fleytman (uint64_t)(0x00FF) << 24 | 3706f3fbe4eSDmitry Fleytman (uint64_t)(0x00FF) << 32 | 3716f3fbe4eSDmitry Fleytman (uint64_t)(mac[2]) << 40 | 3726f3fbe4eSDmitry Fleytman (uint64_t)(mac[1]) << 48 | 3736f3fbe4eSDmitry Fleytman (uint64_t)(mac[0]) << 56; 3746f3fbe4eSDmitry Fleytman } 3756f3fbe4eSDmitry Fleytman 3766f3fbe4eSDmitry Fleytman static int 3776f3fbe4eSDmitry Fleytman e1000e_add_pm_capability(PCIDevice *pdev, uint8_t offset, uint16_t pmc) 3786f3fbe4eSDmitry Fleytman { 3799a7c2a59SMao Zhongyi Error *local_err = NULL; 3809a7c2a59SMao Zhongyi int ret = pci_add_capability(pdev, PCI_CAP_ID_PM, offset, 3819a7c2a59SMao Zhongyi PCI_PM_SIZEOF, &local_err); 3826f3fbe4eSDmitry Fleytman 3839a7c2a59SMao Zhongyi if (local_err) { 3849a7c2a59SMao Zhongyi error_report_err(local_err); 3859a7c2a59SMao Zhongyi return ret; 3869a7c2a59SMao Zhongyi } 3879a7c2a59SMao Zhongyi 3886f3fbe4eSDmitry Fleytman pci_set_word(pdev->config + offset + PCI_PM_PMC, 3896f3fbe4eSDmitry Fleytman PCI_PM_CAP_VER_1_1 | 3906f3fbe4eSDmitry Fleytman pmc); 3916f3fbe4eSDmitry Fleytman 3926f3fbe4eSDmitry Fleytman pci_set_word(pdev->wmask + offset + PCI_PM_CTRL, 3936f3fbe4eSDmitry Fleytman PCI_PM_CTRL_STATE_MASK | 3946f3fbe4eSDmitry Fleytman PCI_PM_CTRL_PME_ENABLE | 3956f3fbe4eSDmitry Fleytman PCI_PM_CTRL_DATA_SEL_MASK); 3966f3fbe4eSDmitry Fleytman 3976f3fbe4eSDmitry Fleytman pci_set_word(pdev->w1cmask + offset + PCI_PM_CTRL, 3986f3fbe4eSDmitry Fleytman PCI_PM_CTRL_PME_STATUS); 3996f3fbe4eSDmitry Fleytman 4006f3fbe4eSDmitry Fleytman return ret; 4016f3fbe4eSDmitry Fleytman } 4026f3fbe4eSDmitry Fleytman 4036f3fbe4eSDmitry Fleytman static void e1000e_write_config(PCIDevice *pci_dev, uint32_t address, 4046f3fbe4eSDmitry Fleytman uint32_t val, int len) 4056f3fbe4eSDmitry Fleytman { 4066f3fbe4eSDmitry Fleytman E1000EState *s = E1000E(pci_dev); 4076f3fbe4eSDmitry Fleytman 4086f3fbe4eSDmitry Fleytman pci_default_write_config(pci_dev, address, val, len); 4096f3fbe4eSDmitry Fleytman 4106f3fbe4eSDmitry Fleytman if (range_covers_byte(address, len, PCI_COMMAND) && 4116f3fbe4eSDmitry Fleytman (pci_dev->config[PCI_COMMAND] & PCI_COMMAND_MASTER)) { 4126ee0e20bSDmitry Fleytman e1000e_start_recv(&s->core); 4136f3fbe4eSDmitry Fleytman } 4146f3fbe4eSDmitry Fleytman } 4156f3fbe4eSDmitry Fleytman 4166f3fbe4eSDmitry Fleytman static void e1000e_pci_realize(PCIDevice *pci_dev, Error **errp) 4176f3fbe4eSDmitry Fleytman { 4186f3fbe4eSDmitry Fleytman static const uint16_t e1000e_pmrb_offset = 0x0C8; 4196f3fbe4eSDmitry Fleytman static const uint16_t e1000e_pcie_offset = 0x0E0; 4206f3fbe4eSDmitry Fleytman static const uint16_t e1000e_aer_offset = 0x100; 4216f3fbe4eSDmitry Fleytman static const uint16_t e1000e_dsn_offset = 0x140; 4226f3fbe4eSDmitry Fleytman E1000EState *s = E1000E(pci_dev); 4236f3fbe4eSDmitry Fleytman uint8_t *macaddr; 42466bf7d58SCao jin int ret; 4256f3fbe4eSDmitry Fleytman 4266f3fbe4eSDmitry Fleytman trace_e1000e_cb_pci_realize(); 4276f3fbe4eSDmitry Fleytman 4286f3fbe4eSDmitry Fleytman pci_dev->config_write = e1000e_write_config; 4296f3fbe4eSDmitry Fleytman 4306f3fbe4eSDmitry Fleytman pci_dev->config[PCI_CACHE_LINE_SIZE] = 0x10; 4316f3fbe4eSDmitry Fleytman pci_dev->config[PCI_INTERRUPT_PIN] = 1; 4326f3fbe4eSDmitry Fleytman 4336f3fbe4eSDmitry Fleytman pci_set_word(pci_dev->config + PCI_SUBSYSTEM_VENDOR_ID, s->subsys_ven); 4346f3fbe4eSDmitry Fleytman pci_set_word(pci_dev->config + PCI_SUBSYSTEM_ID, s->subsys); 4356f3fbe4eSDmitry Fleytman 4366f3fbe4eSDmitry Fleytman s->subsys_ven_used = s->subsys_ven; 4376f3fbe4eSDmitry Fleytman s->subsys_used = s->subsys; 4386f3fbe4eSDmitry Fleytman 4396f3fbe4eSDmitry Fleytman /* Define IO/MMIO regions */ 4406f3fbe4eSDmitry Fleytman memory_region_init_io(&s->mmio, OBJECT(s), &mmio_ops, s, 4416f3fbe4eSDmitry Fleytman "e1000e-mmio", E1000E_MMIO_SIZE); 4426f3fbe4eSDmitry Fleytman pci_register_bar(pci_dev, E1000E_MMIO_IDX, 4436f3fbe4eSDmitry Fleytman PCI_BASE_ADDRESS_SPACE_MEMORY, &s->mmio); 4446f3fbe4eSDmitry Fleytman 4456f3fbe4eSDmitry Fleytman /* 4466f3fbe4eSDmitry Fleytman * We provide a dummy implementation for the flash BAR 4476f3fbe4eSDmitry Fleytman * for drivers that may theoretically probe for its presence. 4486f3fbe4eSDmitry Fleytman */ 4496f3fbe4eSDmitry Fleytman memory_region_init(&s->flash, OBJECT(s), 4506f3fbe4eSDmitry Fleytman "e1000e-flash", E1000E_FLASH_SIZE); 4516f3fbe4eSDmitry Fleytman pci_register_bar(pci_dev, E1000E_FLASH_IDX, 4526f3fbe4eSDmitry Fleytman PCI_BASE_ADDRESS_SPACE_MEMORY, &s->flash); 4536f3fbe4eSDmitry Fleytman 4546f3fbe4eSDmitry Fleytman memory_region_init_io(&s->io, OBJECT(s), &io_ops, s, 4556f3fbe4eSDmitry Fleytman "e1000e-io", E1000E_IO_SIZE); 4566f3fbe4eSDmitry Fleytman pci_register_bar(pci_dev, E1000E_IO_IDX, 4576f3fbe4eSDmitry Fleytman PCI_BASE_ADDRESS_SPACE_IO, &s->io); 4586f3fbe4eSDmitry Fleytman 4596f3fbe4eSDmitry Fleytman memory_region_init(&s->msix, OBJECT(s), "e1000e-msix", 4606f3fbe4eSDmitry Fleytman E1000E_MSIX_SIZE); 4616f3fbe4eSDmitry Fleytman pci_register_bar(pci_dev, E1000E_MSIX_IDX, 4626f3fbe4eSDmitry Fleytman PCI_BASE_ADDRESS_SPACE_MEMORY, &s->msix); 4636f3fbe4eSDmitry Fleytman 4646f3fbe4eSDmitry Fleytman /* Create networking backend */ 4656f3fbe4eSDmitry Fleytman qemu_macaddr_default_if_unset(&s->conf.macaddr); 4666f3fbe4eSDmitry Fleytman macaddr = s->conf.macaddr.a; 4676f3fbe4eSDmitry Fleytman 4686f3fbe4eSDmitry Fleytman e1000e_init_msix(s); 4696f3fbe4eSDmitry Fleytman 4706f3fbe4eSDmitry Fleytman if (pcie_endpoint_cap_v1_init(pci_dev, e1000e_pcie_offset) < 0) { 4716f3fbe4eSDmitry Fleytman hw_error("Failed to initialize PCIe capability"); 4726f3fbe4eSDmitry Fleytman } 4736f3fbe4eSDmitry Fleytman 47466bf7d58SCao jin ret = msi_init(PCI_DEVICE(s), 0xD0, 1, true, false, NULL); 47566bf7d58SCao jin if (ret) { 47666bf7d58SCao jin trace_e1000e_msi_init_fail(ret); 47766bf7d58SCao jin } 4786f3fbe4eSDmitry Fleytman 4796f3fbe4eSDmitry Fleytman if (e1000e_add_pm_capability(pci_dev, e1000e_pmrb_offset, 4806f3fbe4eSDmitry Fleytman PCI_PM_CAP_DSI) < 0) { 4816f3fbe4eSDmitry Fleytman hw_error("Failed to initialize PM capability"); 4826f3fbe4eSDmitry Fleytman } 4836f3fbe4eSDmitry Fleytman 484f18c697bSDou Liyang if (pcie_aer_init(pci_dev, PCI_ERR_VER, e1000e_aer_offset, 485f18c697bSDou Liyang PCI_ERR_SIZEOF, NULL) < 0) { 4866f3fbe4eSDmitry Fleytman hw_error("Failed to initialize AER capability"); 4876f3fbe4eSDmitry Fleytman } 4886f3fbe4eSDmitry Fleytman 4896f3fbe4eSDmitry Fleytman pcie_dev_ser_num_init(pci_dev, e1000e_dsn_offset, 4906f3fbe4eSDmitry Fleytman e1000e_gen_dsn(macaddr)); 4916f3fbe4eSDmitry Fleytman 4926f3fbe4eSDmitry Fleytman e1000e_init_net_peer(s, pci_dev, macaddr); 4936f3fbe4eSDmitry Fleytman 4946f3fbe4eSDmitry Fleytman /* Initialize core */ 4956f3fbe4eSDmitry Fleytman e1000e_core_realize(s); 4966f3fbe4eSDmitry Fleytman 4976f3fbe4eSDmitry Fleytman e1000e_core_pci_realize(&s->core, 4986f3fbe4eSDmitry Fleytman e1000e_eeprom_template, 4996f3fbe4eSDmitry Fleytman sizeof(e1000e_eeprom_template), 5006f3fbe4eSDmitry Fleytman macaddr); 5016f3fbe4eSDmitry Fleytman } 5026f3fbe4eSDmitry Fleytman 5036f3fbe4eSDmitry Fleytman static void e1000e_pci_uninit(PCIDevice *pci_dev) 5046f3fbe4eSDmitry Fleytman { 5056f3fbe4eSDmitry Fleytman E1000EState *s = E1000E(pci_dev); 5066f3fbe4eSDmitry Fleytman 5076f3fbe4eSDmitry Fleytman trace_e1000e_cb_pci_uninit(); 5086f3fbe4eSDmitry Fleytman 5096f3fbe4eSDmitry Fleytman e1000e_core_pci_uninit(&s->core); 5106f3fbe4eSDmitry Fleytman 5116f3fbe4eSDmitry Fleytman pcie_aer_exit(pci_dev); 5126f3fbe4eSDmitry Fleytman pcie_cap_exit(pci_dev); 5136f3fbe4eSDmitry Fleytman 5146f3fbe4eSDmitry Fleytman qemu_del_nic(s->nic); 5156f3fbe4eSDmitry Fleytman 5166f3fbe4eSDmitry Fleytman e1000e_cleanup_msix(s); 51766bf7d58SCao jin msi_uninit(pci_dev); 5186f3fbe4eSDmitry Fleytman } 5196f3fbe4eSDmitry Fleytman 5206f3fbe4eSDmitry Fleytman static void e1000e_qdev_reset(DeviceState *dev) 5216f3fbe4eSDmitry Fleytman { 5226f3fbe4eSDmitry Fleytman E1000EState *s = E1000E(dev); 5236f3fbe4eSDmitry Fleytman 5246f3fbe4eSDmitry Fleytman trace_e1000e_cb_qdev_reset(); 5256f3fbe4eSDmitry Fleytman 5266f3fbe4eSDmitry Fleytman e1000e_core_reset(&s->core); 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), 6666f3fbe4eSDmitry Fleytman DEFINE_PROP_END_OF_LIST(), 6676f3fbe4eSDmitry Fleytman }; 6686f3fbe4eSDmitry Fleytman 6696f3fbe4eSDmitry Fleytman static void e1000e_class_init(ObjectClass *class, void *data) 6706f3fbe4eSDmitry Fleytman { 6716f3fbe4eSDmitry Fleytman DeviceClass *dc = DEVICE_CLASS(class); 6726f3fbe4eSDmitry Fleytman PCIDeviceClass *c = PCI_DEVICE_CLASS(class); 6736f3fbe4eSDmitry Fleytman 6746f3fbe4eSDmitry Fleytman c->realize = e1000e_pci_realize; 6756f3fbe4eSDmitry Fleytman c->exit = e1000e_pci_uninit; 6766f3fbe4eSDmitry Fleytman c->vendor_id = PCI_VENDOR_ID_INTEL; 6776f3fbe4eSDmitry Fleytman c->device_id = E1000_DEV_ID_82574L; 6786f3fbe4eSDmitry Fleytman c->revision = 0; 6791676103dSGerd Hoffmann c->romfile = "efi-e1000e.rom"; 6806f3fbe4eSDmitry Fleytman c->class_id = PCI_CLASS_NETWORK_ETHERNET; 6816f3fbe4eSDmitry Fleytman 6826f3fbe4eSDmitry Fleytman dc->desc = "Intel 82574L GbE Controller"; 6836f3fbe4eSDmitry Fleytman dc->reset = e1000e_qdev_reset; 6846f3fbe4eSDmitry Fleytman dc->vmsd = &e1000e_vmstate; 6856f3fbe4eSDmitry Fleytman dc->props = e1000e_properties; 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 6986f3fbe4eSDmitry Fleytman set_bit(DEVICE_CATEGORY_NETWORK, dc->categories); 6996f3fbe4eSDmitry Fleytman } 7006f3fbe4eSDmitry Fleytman 7016f3fbe4eSDmitry Fleytman static void e1000e_instance_init(Object *obj) 7026f3fbe4eSDmitry Fleytman { 7036f3fbe4eSDmitry Fleytman E1000EState *s = E1000E(obj); 7046f3fbe4eSDmitry Fleytman device_add_bootindex_property(obj, &s->conf.bootindex, 7056f3fbe4eSDmitry Fleytman "bootindex", "/ethernet-phy@0", 7066f3fbe4eSDmitry Fleytman DEVICE(obj), NULL); 7076f3fbe4eSDmitry Fleytman } 7086f3fbe4eSDmitry Fleytman 7096f3fbe4eSDmitry Fleytman static const TypeInfo e1000e_info = { 7106f3fbe4eSDmitry Fleytman .name = TYPE_E1000E, 7116f3fbe4eSDmitry Fleytman .parent = TYPE_PCI_DEVICE, 7126f3fbe4eSDmitry Fleytman .instance_size = sizeof(E1000EState), 7136f3fbe4eSDmitry Fleytman .class_init = e1000e_class_init, 7146f3fbe4eSDmitry Fleytman .instance_init = e1000e_instance_init, 71571d78767SEduardo Habkost .interfaces = (InterfaceInfo[]) { 71671d78767SEduardo Habkost { INTERFACE_PCIE_DEVICE }, 71771d78767SEduardo Habkost { } 71871d78767SEduardo Habkost }, 7196f3fbe4eSDmitry Fleytman }; 7206f3fbe4eSDmitry Fleytman 7216f3fbe4eSDmitry Fleytman static void e1000e_register_types(void) 7226f3fbe4eSDmitry Fleytman { 7236f3fbe4eSDmitry Fleytman type_register_static(&e1000e_info); 7246f3fbe4eSDmitry Fleytman } 7256f3fbe4eSDmitry Fleytman 7266f3fbe4eSDmitry Fleytman type_init(e1000e_register_types) 727