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