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"
45b7728c9fSAkihiko 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
51c9653b77SAkihiko Odaki #include "e1000_common.h"
526f3fbe4eSDmitry Fleytman #include "e1000x_common.h"
536f3fbe4eSDmitry Fleytman #include "e1000e_core.h"
546f3fbe4eSDmitry Fleytman
556f3fbe4eSDmitry Fleytman #include "trace.h"
569a7c2a59SMao Zhongyi #include "qapi/error.h"
57db1015e9SEduardo Habkost #include "qom/object.h"
586f3fbe4eSDmitry Fleytman
596f3fbe4eSDmitry Fleytman #define TYPE_E1000E "e1000e"
608063396bSEduardo Habkost OBJECT_DECLARE_SIMPLE_TYPE(E1000EState, E1000E)
616f3fbe4eSDmitry Fleytman
62db1015e9SEduardo Habkost struct E1000EState {
636f3fbe4eSDmitry Fleytman PCIDevice parent_obj;
646f3fbe4eSDmitry Fleytman NICState *nic;
656f3fbe4eSDmitry Fleytman NICConf conf;
666f3fbe4eSDmitry Fleytman
676f3fbe4eSDmitry Fleytman MemoryRegion mmio;
686f3fbe4eSDmitry Fleytman MemoryRegion flash;
696f3fbe4eSDmitry Fleytman MemoryRegion io;
706f3fbe4eSDmitry Fleytman MemoryRegion msix;
716f3fbe4eSDmitry Fleytman
726f3fbe4eSDmitry Fleytman uint32_t ioaddr;
736f3fbe4eSDmitry Fleytman
746f3fbe4eSDmitry Fleytman uint16_t subsys_ven;
756f3fbe4eSDmitry Fleytman uint16_t subsys;
766f3fbe4eSDmitry Fleytman
776f3fbe4eSDmitry Fleytman uint16_t subsys_ven_used;
786f3fbe4eSDmitry Fleytman uint16_t subsys_used;
796f3fbe4eSDmitry Fleytman
806f3fbe4eSDmitry Fleytman bool disable_vnet;
816f3fbe4eSDmitry Fleytman
826f3fbe4eSDmitry Fleytman E1000ECore core;
83d8970569SChristina Wang bool init_vet;
845fb7d149SAkihiko Odaki bool timadj;
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
e1000e_mmio_read(void * opaque,hwaddr addr,unsigned size)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
e1000e_mmio_write(void * opaque,hwaddr addr,uint64_t val,unsigned size)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
e1000e_io_get_reg_index(E1000EState * s,uint32_t * idx)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
e1000e_io_read(void * opaque,hwaddr addr,unsigned size)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
e1000e_io_write(void * opaque,hwaddr addr,uint64_t val,unsigned size)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
e1000e_nc_can_receive(NetClientState * nc)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
e1000e_nc_receive_iov(NetClientState * nc,const struct iovec * iov,int iovcnt)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
e1000e_nc_receive(NetClientState * nc,const uint8_t * buf,size_t size)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
e1000e_set_link_status(NetClientState * nc)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
e1000e_core_realize(E1000EState * s)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
e1000e_unuse_msix_vectors(E1000EState * s,int num_vectors)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
e1000e_use_msix_vectors(E1000EState * s,int num_vectors)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
e1000e_init_msix(E1000EState * s)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
e1000e_cleanup_msix(E1000EState * s)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
e1000e_init_net_peer(E1000EState * s,PCIDevice * pci_dev,uint8_t * macaddr)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,
3237d0fefdfSAkihiko Odaki object_get_typename(OBJECT(s)), dev->id, &dev->mem_reentrancy_guard, 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 }
3566f3fbe4eSDmitry Fleytman }
3576f3fbe4eSDmitry Fleytman
3586f3fbe4eSDmitry Fleytman static inline uint64_t
e1000e_gen_dsn(uint8_t * mac)3596f3fbe4eSDmitry Fleytman e1000e_gen_dsn(uint8_t *mac)
3606f3fbe4eSDmitry Fleytman {
3616f3fbe4eSDmitry Fleytman return (uint64_t)(mac[5]) |
3626f3fbe4eSDmitry Fleytman (uint64_t)(mac[4]) << 8 |
3636f3fbe4eSDmitry Fleytman (uint64_t)(mac[3]) << 16 |
3646f3fbe4eSDmitry Fleytman (uint64_t)(0x00FF) << 24 |
3656f3fbe4eSDmitry Fleytman (uint64_t)(0x00FF) << 32 |
3666f3fbe4eSDmitry Fleytman (uint64_t)(mac[2]) << 40 |
3676f3fbe4eSDmitry Fleytman (uint64_t)(mac[1]) << 48 |
3686f3fbe4eSDmitry Fleytman (uint64_t)(mac[0]) << 56;
3696f3fbe4eSDmitry Fleytman }
3706f3fbe4eSDmitry Fleytman
3716f3fbe4eSDmitry Fleytman static int
e1000e_add_pm_capability(PCIDevice * pdev,uint8_t offset,uint16_t pmc)3726f3fbe4eSDmitry Fleytman e1000e_add_pm_capability(PCIDevice *pdev, uint8_t offset, uint16_t pmc)
3736f3fbe4eSDmitry Fleytman {
3749a7c2a59SMao Zhongyi Error *local_err = NULL;
3759a7c2a59SMao Zhongyi int ret = pci_add_capability(pdev, PCI_CAP_ID_PM, offset,
3769a7c2a59SMao Zhongyi PCI_PM_SIZEOF, &local_err);
3776f3fbe4eSDmitry Fleytman
3789a7c2a59SMao Zhongyi if (local_err) {
3799a7c2a59SMao Zhongyi error_report_err(local_err);
3809a7c2a59SMao Zhongyi return ret;
3819a7c2a59SMao Zhongyi }
3829a7c2a59SMao Zhongyi
3836f3fbe4eSDmitry Fleytman pci_set_word(pdev->config + offset + PCI_PM_PMC,
3846f3fbe4eSDmitry Fleytman PCI_PM_CAP_VER_1_1 |
3856f3fbe4eSDmitry Fleytman pmc);
3866f3fbe4eSDmitry Fleytman
3876f3fbe4eSDmitry Fleytman pci_set_word(pdev->wmask + offset + PCI_PM_CTRL,
3886f3fbe4eSDmitry Fleytman PCI_PM_CTRL_STATE_MASK |
3896f3fbe4eSDmitry Fleytman PCI_PM_CTRL_PME_ENABLE |
3906f3fbe4eSDmitry Fleytman PCI_PM_CTRL_DATA_SEL_MASK);
3916f3fbe4eSDmitry Fleytman
3926f3fbe4eSDmitry Fleytman pci_set_word(pdev->w1cmask + offset + PCI_PM_CTRL,
3936f3fbe4eSDmitry Fleytman PCI_PM_CTRL_PME_STATUS);
3946f3fbe4eSDmitry Fleytman
3956f3fbe4eSDmitry Fleytman return ret;
3966f3fbe4eSDmitry Fleytman }
3976f3fbe4eSDmitry Fleytman
e1000e_write_config(PCIDevice * pci_dev,uint32_t address,uint32_t val,int len)3986f3fbe4eSDmitry Fleytman static void e1000e_write_config(PCIDevice *pci_dev, uint32_t address,
3996f3fbe4eSDmitry Fleytman uint32_t val, int len)
4006f3fbe4eSDmitry Fleytman {
4016f3fbe4eSDmitry Fleytman E1000EState *s = E1000E(pci_dev);
4026f3fbe4eSDmitry Fleytman
4036f3fbe4eSDmitry Fleytman pci_default_write_config(pci_dev, address, val, len);
4046f3fbe4eSDmitry Fleytman
4056f3fbe4eSDmitry Fleytman if (range_covers_byte(address, len, PCI_COMMAND) &&
4066f3fbe4eSDmitry Fleytman (pci_dev->config[PCI_COMMAND] & PCI_COMMAND_MASTER)) {
4076ee0e20bSDmitry Fleytman e1000e_start_recv(&s->core);
4086f3fbe4eSDmitry Fleytman }
4096f3fbe4eSDmitry Fleytman }
4106f3fbe4eSDmitry Fleytman
e1000e_pci_realize(PCIDevice * pci_dev,Error ** errp)4116f3fbe4eSDmitry Fleytman static void e1000e_pci_realize(PCIDevice *pci_dev, Error **errp)
4126f3fbe4eSDmitry Fleytman {
4136f3fbe4eSDmitry Fleytman static const uint16_t e1000e_pmrb_offset = 0x0C8;
4146f3fbe4eSDmitry Fleytman static const uint16_t e1000e_pcie_offset = 0x0E0;
4156f3fbe4eSDmitry Fleytman static const uint16_t e1000e_aer_offset = 0x100;
4166f3fbe4eSDmitry Fleytman static const uint16_t e1000e_dsn_offset = 0x140;
4176f3fbe4eSDmitry Fleytman E1000EState *s = E1000E(pci_dev);
4186f3fbe4eSDmitry Fleytman uint8_t *macaddr;
41966bf7d58SCao jin int ret;
4206f3fbe4eSDmitry Fleytman
4216f3fbe4eSDmitry Fleytman trace_e1000e_cb_pci_realize();
4226f3fbe4eSDmitry Fleytman
4236f3fbe4eSDmitry Fleytman pci_dev->config_write = e1000e_write_config;
4246f3fbe4eSDmitry Fleytman
4256f3fbe4eSDmitry Fleytman pci_dev->config[PCI_CACHE_LINE_SIZE] = 0x10;
4266f3fbe4eSDmitry Fleytman pci_dev->config[PCI_INTERRUPT_PIN] = 1;
4276f3fbe4eSDmitry Fleytman
4286f3fbe4eSDmitry Fleytman pci_set_word(pci_dev->config + PCI_SUBSYSTEM_VENDOR_ID, s->subsys_ven);
4296f3fbe4eSDmitry Fleytman pci_set_word(pci_dev->config + PCI_SUBSYSTEM_ID, s->subsys);
4306f3fbe4eSDmitry Fleytman
4316f3fbe4eSDmitry Fleytman s->subsys_ven_used = s->subsys_ven;
4326f3fbe4eSDmitry Fleytman s->subsys_used = s->subsys;
4336f3fbe4eSDmitry Fleytman
4346f3fbe4eSDmitry Fleytman /* Define IO/MMIO regions */
4356f3fbe4eSDmitry Fleytman memory_region_init_io(&s->mmio, OBJECT(s), &mmio_ops, s,
4366f3fbe4eSDmitry Fleytman "e1000e-mmio", E1000E_MMIO_SIZE);
4376f3fbe4eSDmitry Fleytman pci_register_bar(pci_dev, E1000E_MMIO_IDX,
4386f3fbe4eSDmitry Fleytman PCI_BASE_ADDRESS_SPACE_MEMORY, &s->mmio);
4396f3fbe4eSDmitry Fleytman
4406f3fbe4eSDmitry Fleytman /*
4416f3fbe4eSDmitry Fleytman * We provide a dummy implementation for the flash BAR
4426f3fbe4eSDmitry Fleytman * for drivers that may theoretically probe for its presence.
4436f3fbe4eSDmitry Fleytman */
4446f3fbe4eSDmitry Fleytman memory_region_init(&s->flash, OBJECT(s),
4456f3fbe4eSDmitry Fleytman "e1000e-flash", E1000E_FLASH_SIZE);
4466f3fbe4eSDmitry Fleytman pci_register_bar(pci_dev, E1000E_FLASH_IDX,
4476f3fbe4eSDmitry Fleytman PCI_BASE_ADDRESS_SPACE_MEMORY, &s->flash);
4486f3fbe4eSDmitry Fleytman
4496f3fbe4eSDmitry Fleytman memory_region_init_io(&s->io, OBJECT(s), &io_ops, s,
4506f3fbe4eSDmitry Fleytman "e1000e-io", E1000E_IO_SIZE);
4516f3fbe4eSDmitry Fleytman pci_register_bar(pci_dev, E1000E_IO_IDX,
4526f3fbe4eSDmitry Fleytman PCI_BASE_ADDRESS_SPACE_IO, &s->io);
4536f3fbe4eSDmitry Fleytman
4546f3fbe4eSDmitry Fleytman memory_region_init(&s->msix, OBJECT(s), "e1000e-msix",
4556f3fbe4eSDmitry Fleytman E1000E_MSIX_SIZE);
4566f3fbe4eSDmitry Fleytman pci_register_bar(pci_dev, E1000E_MSIX_IDX,
4576f3fbe4eSDmitry Fleytman PCI_BASE_ADDRESS_SPACE_MEMORY, &s->msix);
4586f3fbe4eSDmitry Fleytman
4596f3fbe4eSDmitry Fleytman /* Create networking backend */
4606f3fbe4eSDmitry Fleytman qemu_macaddr_default_if_unset(&s->conf.macaddr);
4616f3fbe4eSDmitry Fleytman macaddr = s->conf.macaddr.a;
4626f3fbe4eSDmitry Fleytman
4636f3fbe4eSDmitry Fleytman e1000e_init_msix(s);
4646f3fbe4eSDmitry Fleytman
4656f3fbe4eSDmitry Fleytman if (pcie_endpoint_cap_v1_init(pci_dev, e1000e_pcie_offset) < 0) {
4666f3fbe4eSDmitry Fleytman hw_error("Failed to initialize PCIe capability");
4676f3fbe4eSDmitry Fleytman }
4686f3fbe4eSDmitry Fleytman
46966bf7d58SCao jin ret = msi_init(PCI_DEVICE(s), 0xD0, 1, true, false, NULL);
47066bf7d58SCao jin if (ret) {
47166bf7d58SCao jin trace_e1000e_msi_init_fail(ret);
47266bf7d58SCao jin }
4736f3fbe4eSDmitry Fleytman
4746f3fbe4eSDmitry Fleytman if (e1000e_add_pm_capability(pci_dev, e1000e_pmrb_offset,
4756f3fbe4eSDmitry Fleytman PCI_PM_CAP_DSI) < 0) {
4766f3fbe4eSDmitry Fleytman hw_error("Failed to initialize PM capability");
4776f3fbe4eSDmitry Fleytman }
4786f3fbe4eSDmitry Fleytman
479f18c697bSDou Liyang if (pcie_aer_init(pci_dev, PCI_ERR_VER, e1000e_aer_offset,
480f18c697bSDou Liyang PCI_ERR_SIZEOF, NULL) < 0) {
4816f3fbe4eSDmitry Fleytman hw_error("Failed to initialize AER capability");
4826f3fbe4eSDmitry Fleytman }
4836f3fbe4eSDmitry Fleytman
4846f3fbe4eSDmitry Fleytman pcie_dev_ser_num_init(pci_dev, e1000e_dsn_offset,
4856f3fbe4eSDmitry Fleytman e1000e_gen_dsn(macaddr));
4866f3fbe4eSDmitry Fleytman
4876f3fbe4eSDmitry Fleytman e1000e_init_net_peer(s, pci_dev, macaddr);
4886f3fbe4eSDmitry Fleytman
4896f3fbe4eSDmitry Fleytman /* Initialize core */
4906f3fbe4eSDmitry Fleytman e1000e_core_realize(s);
4916f3fbe4eSDmitry Fleytman
4926f3fbe4eSDmitry Fleytman e1000e_core_pci_realize(&s->core,
4936f3fbe4eSDmitry Fleytman e1000e_eeprom_template,
4946f3fbe4eSDmitry Fleytman sizeof(e1000e_eeprom_template),
4956f3fbe4eSDmitry Fleytman macaddr);
4966f3fbe4eSDmitry Fleytman }
4976f3fbe4eSDmitry Fleytman
e1000e_pci_uninit(PCIDevice * pci_dev)4986f3fbe4eSDmitry Fleytman static void e1000e_pci_uninit(PCIDevice *pci_dev)
4996f3fbe4eSDmitry Fleytman {
5006f3fbe4eSDmitry Fleytman E1000EState *s = E1000E(pci_dev);
5016f3fbe4eSDmitry Fleytman
5026f3fbe4eSDmitry Fleytman trace_e1000e_cb_pci_uninit();
5036f3fbe4eSDmitry Fleytman
5046f3fbe4eSDmitry Fleytman e1000e_core_pci_uninit(&s->core);
5056f3fbe4eSDmitry Fleytman
5066f3fbe4eSDmitry Fleytman pcie_aer_exit(pci_dev);
5076f3fbe4eSDmitry Fleytman pcie_cap_exit(pci_dev);
5086f3fbe4eSDmitry Fleytman
5096f3fbe4eSDmitry Fleytman qemu_del_nic(s->nic);
5106f3fbe4eSDmitry Fleytman
5116f3fbe4eSDmitry Fleytman e1000e_cleanup_msix(s);
51266bf7d58SCao jin msi_uninit(pci_dev);
5136f3fbe4eSDmitry Fleytman }
5146f3fbe4eSDmitry Fleytman
e1000e_qdev_reset_hold(Object * obj,ResetType type)515*ad80e367SPeter Maydell static void e1000e_qdev_reset_hold(Object *obj, ResetType type)
5166f3fbe4eSDmitry Fleytman {
5178a35c648SAkihiko Odaki E1000EState *s = E1000E(obj);
5186f3fbe4eSDmitry Fleytman
5198a35c648SAkihiko Odaki trace_e1000e_cb_qdev_reset_hold();
5206f3fbe4eSDmitry Fleytman
5216f3fbe4eSDmitry Fleytman e1000e_core_reset(&s->core);
522d8970569SChristina Wang
523d8970569SChristina Wang if (s->init_vet) {
524d8970569SChristina Wang s->core.mac[VET] = ETH_P_VLAN;
525d8970569SChristina Wang }
5266f3fbe4eSDmitry Fleytman }
5276f3fbe4eSDmitry Fleytman
e1000e_pre_save(void * opaque)52844b1ff31SDr. David Alan Gilbert static int e1000e_pre_save(void *opaque)
5296f3fbe4eSDmitry Fleytman {
5306f3fbe4eSDmitry Fleytman E1000EState *s = opaque;
5316f3fbe4eSDmitry Fleytman
5326f3fbe4eSDmitry Fleytman trace_e1000e_cb_pre_save();
5336f3fbe4eSDmitry Fleytman
5346f3fbe4eSDmitry Fleytman e1000e_core_pre_save(&s->core);
53544b1ff31SDr. David Alan Gilbert
53644b1ff31SDr. David Alan Gilbert return 0;
5376f3fbe4eSDmitry Fleytman }
5386f3fbe4eSDmitry Fleytman
e1000e_post_load(void * opaque,int version_id)5396f3fbe4eSDmitry Fleytman static int e1000e_post_load(void *opaque, int version_id)
5406f3fbe4eSDmitry Fleytman {
5416f3fbe4eSDmitry Fleytman E1000EState *s = opaque;
5426f3fbe4eSDmitry Fleytman
5436f3fbe4eSDmitry Fleytman trace_e1000e_cb_post_load();
5446f3fbe4eSDmitry Fleytman
5456f3fbe4eSDmitry Fleytman if ((s->subsys != s->subsys_used) ||
5466f3fbe4eSDmitry Fleytman (s->subsys_ven != s->subsys_ven_used)) {
5476f3fbe4eSDmitry Fleytman fprintf(stderr,
5486f3fbe4eSDmitry Fleytman "ERROR: Cannot migrate while device properties "
5496f3fbe4eSDmitry Fleytman "(subsys/subsys_ven) differ");
5506f3fbe4eSDmitry Fleytman return -1;
5516f3fbe4eSDmitry Fleytman }
5526f3fbe4eSDmitry Fleytman
5536f3fbe4eSDmitry Fleytman return e1000e_core_post_load(&s->core);
5546f3fbe4eSDmitry Fleytman }
5556f3fbe4eSDmitry Fleytman
e1000e_migrate_timadj(void * opaque,int version_id)5565fb7d149SAkihiko Odaki static bool e1000e_migrate_timadj(void *opaque, int version_id)
5575fb7d149SAkihiko Odaki {
5585fb7d149SAkihiko Odaki E1000EState *s = opaque;
5595fb7d149SAkihiko Odaki return s->timadj;
5605fb7d149SAkihiko Odaki }
5615fb7d149SAkihiko Odaki
5626f3fbe4eSDmitry Fleytman static const VMStateDescription e1000e_vmstate_tx = {
5636f3fbe4eSDmitry Fleytman .name = "e1000e-tx",
5646f3fbe4eSDmitry Fleytman .version_id = 1,
5656f3fbe4eSDmitry Fleytman .minimum_version_id = 1,
5661de81b42SRichard Henderson .fields = (const VMStateField[]) {
5677d08c73eSEd Swierk via Qemu-devel VMSTATE_UINT8(sum_needed, struct e1000e_tx),
5686f3fbe4eSDmitry Fleytman VMSTATE_UINT8(props.ipcss, struct e1000e_tx),
5696f3fbe4eSDmitry Fleytman VMSTATE_UINT8(props.ipcso, struct e1000e_tx),
5706f3fbe4eSDmitry Fleytman VMSTATE_UINT16(props.ipcse, struct e1000e_tx),
5716f3fbe4eSDmitry Fleytman VMSTATE_UINT8(props.tucss, struct e1000e_tx),
5726f3fbe4eSDmitry Fleytman VMSTATE_UINT8(props.tucso, struct e1000e_tx),
5736f3fbe4eSDmitry Fleytman VMSTATE_UINT16(props.tucse, struct e1000e_tx),
5746f3fbe4eSDmitry Fleytman VMSTATE_UINT8(props.hdr_len, struct e1000e_tx),
5756f3fbe4eSDmitry Fleytman VMSTATE_UINT16(props.mss, struct e1000e_tx),
5766f3fbe4eSDmitry Fleytman VMSTATE_UINT32(props.paylen, struct e1000e_tx),
5776f3fbe4eSDmitry Fleytman VMSTATE_INT8(props.ip, struct e1000e_tx),
5786f3fbe4eSDmitry Fleytman VMSTATE_INT8(props.tcp, struct e1000e_tx),
5796f3fbe4eSDmitry Fleytman VMSTATE_BOOL(props.tse, struct e1000e_tx),
5807d08c73eSEd Swierk via Qemu-devel VMSTATE_BOOL(cptse, struct e1000e_tx),
5816f3fbe4eSDmitry Fleytman VMSTATE_BOOL(skip_cp, struct e1000e_tx),
5826f3fbe4eSDmitry Fleytman VMSTATE_END_OF_LIST()
5836f3fbe4eSDmitry Fleytman }
5846f3fbe4eSDmitry Fleytman };
5856f3fbe4eSDmitry Fleytman
5866f3fbe4eSDmitry Fleytman static const VMStateDescription e1000e_vmstate_intr_timer = {
5876f3fbe4eSDmitry Fleytman .name = "e1000e-intr-timer",
5886f3fbe4eSDmitry Fleytman .version_id = 1,
5896f3fbe4eSDmitry Fleytman .minimum_version_id = 1,
5901de81b42SRichard Henderson .fields = (const VMStateField[]) {
5916f3fbe4eSDmitry Fleytman VMSTATE_TIMER_PTR(timer, E1000IntrDelayTimer),
5926f3fbe4eSDmitry Fleytman VMSTATE_BOOL(running, E1000IntrDelayTimer),
5936f3fbe4eSDmitry Fleytman VMSTATE_END_OF_LIST()
5946f3fbe4eSDmitry Fleytman }
5956f3fbe4eSDmitry Fleytman };
5966f3fbe4eSDmitry Fleytman
5976f3fbe4eSDmitry Fleytman #define VMSTATE_E1000E_INTR_DELAY_TIMER(_f, _s) \
5986f3fbe4eSDmitry Fleytman VMSTATE_STRUCT(_f, _s, 0, \
5996f3fbe4eSDmitry Fleytman e1000e_vmstate_intr_timer, E1000IntrDelayTimer)
6006f3fbe4eSDmitry Fleytman
6016f3fbe4eSDmitry Fleytman #define VMSTATE_E1000E_INTR_DELAY_TIMER_ARRAY(_f, _s, _num) \
6026f3fbe4eSDmitry Fleytman VMSTATE_STRUCT_ARRAY(_f, _s, _num, 0, \
6036f3fbe4eSDmitry Fleytman e1000e_vmstate_intr_timer, E1000IntrDelayTimer)
6046f3fbe4eSDmitry Fleytman
6056f3fbe4eSDmitry Fleytman static const VMStateDescription e1000e_vmstate = {
6066f3fbe4eSDmitry Fleytman .name = "e1000e",
6076f3fbe4eSDmitry Fleytman .version_id = 1,
6086f3fbe4eSDmitry Fleytman .minimum_version_id = 1,
6096f3fbe4eSDmitry Fleytman .pre_save = e1000e_pre_save,
6106f3fbe4eSDmitry Fleytman .post_load = e1000e_post_load,
6111de81b42SRichard Henderson .fields = (const VMStateField[]) {
61220daa90aSDr. David Alan Gilbert VMSTATE_PCI_DEVICE(parent_obj, E1000EState),
6136f3fbe4eSDmitry Fleytman VMSTATE_MSIX(parent_obj, E1000EState),
6146f3fbe4eSDmitry Fleytman
6156f3fbe4eSDmitry Fleytman VMSTATE_UINT32(ioaddr, E1000EState),
6166f3fbe4eSDmitry Fleytman VMSTATE_UINT32(core.rxbuf_min_shift, E1000EState),
6176f3fbe4eSDmitry Fleytman VMSTATE_UINT8(core.rx_desc_len, E1000EState),
6186f3fbe4eSDmitry Fleytman VMSTATE_UINT32_ARRAY(core.rxbuf_sizes, E1000EState,
6196f3fbe4eSDmitry Fleytman E1000_PSRCTL_BUFFS_PER_DESC),
6206f3fbe4eSDmitry Fleytman VMSTATE_UINT32(core.rx_desc_buf_size, E1000EState),
6216f3fbe4eSDmitry Fleytman VMSTATE_UINT16_ARRAY(core.eeprom, E1000EState, E1000E_EEPROM_SIZE),
6226f3fbe4eSDmitry Fleytman VMSTATE_UINT16_2DARRAY(core.phy, E1000EState,
6236f3fbe4eSDmitry Fleytman E1000E_PHY_PAGES, E1000E_PHY_PAGE_SIZE),
6246f3fbe4eSDmitry Fleytman VMSTATE_UINT32_ARRAY(core.mac, E1000EState, E1000E_MAC_SIZE),
6256f3fbe4eSDmitry Fleytman VMSTATE_UINT8_ARRAY(core.permanent_mac, E1000EState, ETH_ALEN),
6266f3fbe4eSDmitry Fleytman
6276f3fbe4eSDmitry Fleytman VMSTATE_UINT32(core.delayed_causes, E1000EState),
6286f3fbe4eSDmitry Fleytman
6296f3fbe4eSDmitry Fleytman VMSTATE_UINT16(subsys, E1000EState),
6306f3fbe4eSDmitry Fleytman VMSTATE_UINT16(subsys_ven, E1000EState),
6316f3fbe4eSDmitry Fleytman
6326f3fbe4eSDmitry Fleytman VMSTATE_E1000E_INTR_DELAY_TIMER(core.rdtr, E1000EState),
6336f3fbe4eSDmitry Fleytman VMSTATE_E1000E_INTR_DELAY_TIMER(core.radv, E1000EState),
6346f3fbe4eSDmitry Fleytman VMSTATE_E1000E_INTR_DELAY_TIMER(core.raid, E1000EState),
6356f3fbe4eSDmitry Fleytman VMSTATE_E1000E_INTR_DELAY_TIMER(core.tadv, E1000EState),
6366f3fbe4eSDmitry Fleytman VMSTATE_E1000E_INTR_DELAY_TIMER(core.tidv, E1000EState),
6376f3fbe4eSDmitry Fleytman
6386f3fbe4eSDmitry Fleytman VMSTATE_E1000E_INTR_DELAY_TIMER(core.itr, E1000EState),
63931e3f318SAkihiko Odaki VMSTATE_UNUSED(1),
6406f3fbe4eSDmitry Fleytman
6416f3fbe4eSDmitry Fleytman VMSTATE_E1000E_INTR_DELAY_TIMER_ARRAY(core.eitr, E1000EState,
6426f3fbe4eSDmitry Fleytman E1000E_MSIX_VEC_NUM),
64331e3f318SAkihiko Odaki VMSTATE_UNUSED(E1000E_MSIX_VEC_NUM),
6446f3fbe4eSDmitry Fleytman
6456f3fbe4eSDmitry Fleytman VMSTATE_UINT32(core.itr_guest_value, E1000EState),
6466f3fbe4eSDmitry Fleytman VMSTATE_UINT32_ARRAY(core.eitr_guest_value, E1000EState,
6476f3fbe4eSDmitry Fleytman E1000E_MSIX_VEC_NUM),
6486f3fbe4eSDmitry Fleytman
6496f3fbe4eSDmitry Fleytman VMSTATE_UINT16(core.vet, E1000EState),
6506f3fbe4eSDmitry Fleytman
6516f3fbe4eSDmitry Fleytman VMSTATE_STRUCT_ARRAY(core.tx, E1000EState, E1000E_NUM_QUEUES, 0,
6526f3fbe4eSDmitry Fleytman e1000e_vmstate_tx, struct e1000e_tx),
6535fb7d149SAkihiko Odaki
6545fb7d149SAkihiko Odaki VMSTATE_INT64_TEST(core.timadj, E1000EState, e1000e_migrate_timadj),
6555fb7d149SAkihiko Odaki
6566f3fbe4eSDmitry Fleytman VMSTATE_END_OF_LIST()
6576f3fbe4eSDmitry Fleytman }
6586f3fbe4eSDmitry Fleytman };
6596f3fbe4eSDmitry Fleytman
6606f3fbe4eSDmitry Fleytman static PropertyInfo e1000e_prop_disable_vnet,
6616f3fbe4eSDmitry Fleytman e1000e_prop_subsys_ven,
6626f3fbe4eSDmitry Fleytman e1000e_prop_subsys;
6636f3fbe4eSDmitry Fleytman
6646f3fbe4eSDmitry Fleytman static Property e1000e_properties[] = {
6656f3fbe4eSDmitry Fleytman DEFINE_NIC_PROPERTIES(E1000EState, conf),
66685bbd1e7SMarc-André Lureau DEFINE_PROP_SIGNED("disable_vnet_hdr", E1000EState, disable_vnet, false,
6676f3fbe4eSDmitry Fleytman e1000e_prop_disable_vnet, bool),
66885bbd1e7SMarc-André Lureau DEFINE_PROP_SIGNED("subsys_ven", E1000EState, subsys_ven,
6696f3fbe4eSDmitry Fleytman PCI_VENDOR_ID_INTEL,
6706f3fbe4eSDmitry Fleytman e1000e_prop_subsys_ven, uint16_t),
67185bbd1e7SMarc-André Lureau DEFINE_PROP_SIGNED("subsys", E1000EState, subsys, 0,
6726f3fbe4eSDmitry Fleytman e1000e_prop_subsys, uint16_t),
673d8970569SChristina Wang DEFINE_PROP_BOOL("init-vet", E1000EState, init_vet, true),
6745fb7d149SAkihiko Odaki DEFINE_PROP_BOOL("migrate-timadj", E1000EState, timadj, true),
6756f3fbe4eSDmitry Fleytman DEFINE_PROP_END_OF_LIST(),
6766f3fbe4eSDmitry Fleytman };
6776f3fbe4eSDmitry Fleytman
e1000e_class_init(ObjectClass * class,void * data)6786f3fbe4eSDmitry Fleytman static void e1000e_class_init(ObjectClass *class, void *data)
6796f3fbe4eSDmitry Fleytman {
6806f3fbe4eSDmitry Fleytman DeviceClass *dc = DEVICE_CLASS(class);
6818a35c648SAkihiko Odaki ResettableClass *rc = RESETTABLE_CLASS(class);
6826f3fbe4eSDmitry Fleytman PCIDeviceClass *c = PCI_DEVICE_CLASS(class);
6836f3fbe4eSDmitry Fleytman
6846f3fbe4eSDmitry Fleytman c->realize = e1000e_pci_realize;
6856f3fbe4eSDmitry Fleytman c->exit = e1000e_pci_uninit;
6866f3fbe4eSDmitry Fleytman c->vendor_id = PCI_VENDOR_ID_INTEL;
6876f3fbe4eSDmitry Fleytman c->device_id = E1000_DEV_ID_82574L;
6886f3fbe4eSDmitry Fleytman c->revision = 0;
6891676103dSGerd Hoffmann c->romfile = "efi-e1000e.rom";
6906f3fbe4eSDmitry Fleytman c->class_id = PCI_CLASS_NETWORK_ETHERNET;
6916f3fbe4eSDmitry Fleytman
6928a35c648SAkihiko Odaki rc->phases.hold = e1000e_qdev_reset_hold;
6938a35c648SAkihiko Odaki
6946f3fbe4eSDmitry Fleytman dc->desc = "Intel 82574L GbE Controller";
6956f3fbe4eSDmitry Fleytman dc->vmsd = &e1000e_vmstate;
6966f3fbe4eSDmitry Fleytman
6976f3fbe4eSDmitry Fleytman e1000e_prop_disable_vnet = qdev_prop_uint8;
6986f3fbe4eSDmitry Fleytman e1000e_prop_disable_vnet.description = "Do not use virtio headers, "
6996f3fbe4eSDmitry Fleytman "perform SW offloads emulation "
7006f3fbe4eSDmitry Fleytman "instead";
7016f3fbe4eSDmitry Fleytman
7026f3fbe4eSDmitry Fleytman e1000e_prop_subsys_ven = qdev_prop_uint16;
7036f3fbe4eSDmitry Fleytman e1000e_prop_subsys_ven.description = "PCI device Subsystem Vendor ID";
7046f3fbe4eSDmitry Fleytman
7056f3fbe4eSDmitry Fleytman e1000e_prop_subsys = qdev_prop_uint16;
7066f3fbe4eSDmitry Fleytman e1000e_prop_subsys.description = "PCI device Subsystem ID";
7076f3fbe4eSDmitry Fleytman
7084f67d30bSMarc-André Lureau device_class_set_props(dc, e1000e_properties);
7096f3fbe4eSDmitry Fleytman set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
7106f3fbe4eSDmitry Fleytman }
7116f3fbe4eSDmitry Fleytman
e1000e_instance_init(Object * obj)7126f3fbe4eSDmitry Fleytman static void e1000e_instance_init(Object *obj)
7136f3fbe4eSDmitry Fleytman {
7146f3fbe4eSDmitry Fleytman E1000EState *s = E1000E(obj);
7156f3fbe4eSDmitry Fleytman device_add_bootindex_property(obj, &s->conf.bootindex,
7166f3fbe4eSDmitry Fleytman "bootindex", "/ethernet-phy@0",
71740c2281cSMarkus Armbruster DEVICE(obj));
7186f3fbe4eSDmitry Fleytman }
7196f3fbe4eSDmitry Fleytman
7206f3fbe4eSDmitry Fleytman static const TypeInfo e1000e_info = {
7216f3fbe4eSDmitry Fleytman .name = TYPE_E1000E,
7226f3fbe4eSDmitry Fleytman .parent = TYPE_PCI_DEVICE,
7236f3fbe4eSDmitry Fleytman .instance_size = sizeof(E1000EState),
7246f3fbe4eSDmitry Fleytman .class_init = e1000e_class_init,
7256f3fbe4eSDmitry Fleytman .instance_init = e1000e_instance_init,
72671d78767SEduardo Habkost .interfaces = (InterfaceInfo[]) {
72771d78767SEduardo Habkost { INTERFACE_PCIE_DEVICE },
72871d78767SEduardo Habkost { }
72971d78767SEduardo Habkost },
7306f3fbe4eSDmitry Fleytman };
7316f3fbe4eSDmitry Fleytman
e1000e_register_types(void)7326f3fbe4eSDmitry Fleytman static void e1000e_register_types(void)
7336f3fbe4eSDmitry Fleytman {
7346f3fbe4eSDmitry Fleytman type_register_static(&e1000e_info);
7356f3fbe4eSDmitry Fleytman }
7366f3fbe4eSDmitry Fleytman
7376f3fbe4eSDmitry Fleytman type_init(e1000e_register_types)
738