igb.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. /*
  2. * QEMU Intel 82576 SR/IOV Ethernet Controller Emulation
  3. *
  4. * Datasheet:
  5. * https://www.intel.com/content/dam/www/public/us/en/documents/datasheets/82576eg-gbe-datasheet.pdf
  6. *
  7. * Copyright (c) 2020-2023 Red Hat, Inc.
  8. * Copyright (c) 2015 Ravello Systems LTD (http://ravellosystems.com)
  9. * Developed by Daynix Computing LTD (http://www.daynix.com)
  10. *
  11. * Authors:
  12. * Akihiko Odaki <akihiko.odaki@daynix.com>
  13. * Gal Hammmer <gal.hammer@sap.com>
  14. * Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
  15. * Dmitry Fleytman <dmitry@daynix.com>
  16. * Leonid Bloch <leonid@daynix.com>
  17. * Yan Vugenfirer <yan@daynix.com>
  18. *
  19. * Based on work done by:
  20. * Nir Peleg, Tutis Systems Ltd. for Qumranet Inc.
  21. * Copyright (c) 2008 Qumranet
  22. * Based on work done by:
  23. * Copyright (c) 2007 Dan Aloni
  24. * Copyright (c) 2004 Antony T Curtis
  25. *
  26. * This library is free software; you can redistribute it and/or
  27. * modify it under the terms of the GNU Lesser General Public
  28. * License as published by the Free Software Foundation; either
  29. * version 2.1 of the License, or (at your option) any later version.
  30. *
  31. * This library is distributed in the hope that it will be useful,
  32. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  33. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  34. * Lesser General Public License for more details.
  35. *
  36. * You should have received a copy of the GNU Lesser General Public
  37. * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  38. */
  39. #include "qemu/osdep.h"
  40. #include "qemu/units.h"
  41. #include "net/eth.h"
  42. #include "net/net.h"
  43. #include "net/tap.h"
  44. #include "qemu/module.h"
  45. #include "qemu/range.h"
  46. #include "system/system.h"
  47. #include "hw/hw.h"
  48. #include "hw/net/mii.h"
  49. #include "hw/pci/pci.h"
  50. #include "hw/pci/pcie.h"
  51. #include "hw/pci/pcie_sriov.h"
  52. #include "hw/pci/msi.h"
  53. #include "hw/pci/msix.h"
  54. #include "hw/qdev-properties.h"
  55. #include "migration/vmstate.h"
  56. #include "igb_common.h"
  57. #include "igb_core.h"
  58. #include "trace.h"
  59. #include "qapi/error.h"
  60. #include "qom/object.h"
  61. #define TYPE_IGB "igb"
  62. OBJECT_DECLARE_SIMPLE_TYPE(IGBState, IGB)
  63. struct IGBState {
  64. PCIDevice parent_obj;
  65. NICState *nic;
  66. NICConf conf;
  67. MemoryRegion mmio;
  68. MemoryRegion flash;
  69. MemoryRegion io;
  70. MemoryRegion msix;
  71. uint32_t ioaddr;
  72. IGBCore core;
  73. bool has_flr;
  74. };
  75. #define IGB_CAP_SRIOV_OFFSET (0x160)
  76. #define IGB_VF_OFFSET (0x80)
  77. #define IGB_VF_STRIDE (2)
  78. #define E1000E_MMIO_IDX 0
  79. #define E1000E_FLASH_IDX 1
  80. #define E1000E_IO_IDX 2
  81. #define E1000E_MSIX_IDX 3
  82. #define E1000E_MMIO_SIZE (128 * KiB)
  83. #define E1000E_FLASH_SIZE (128 * KiB)
  84. #define E1000E_IO_SIZE (32)
  85. #define E1000E_MSIX_SIZE (16 * KiB)
  86. static void igb_write_config(PCIDevice *dev, uint32_t addr,
  87. uint32_t val, int len)
  88. {
  89. IGBState *s = IGB(dev);
  90. trace_igb_write_config(addr, val, len);
  91. pci_default_write_config(dev, addr, val, len);
  92. if (s->has_flr) {
  93. pcie_cap_flr_write_config(dev, addr, val, len);
  94. }
  95. if (range_covers_byte(addr, len, PCI_COMMAND) &&
  96. (dev->config[PCI_COMMAND] & PCI_COMMAND_MASTER)) {
  97. igb_start_recv(&s->core);
  98. }
  99. }
  100. uint64_t
  101. igb_mmio_read(void *opaque, hwaddr addr, unsigned size)
  102. {
  103. IGBState *s = opaque;
  104. return igb_core_read(&s->core, addr, size);
  105. }
  106. void
  107. igb_mmio_write(void *opaque, hwaddr addr, uint64_t val, unsigned size)
  108. {
  109. IGBState *s = opaque;
  110. igb_core_write(&s->core, addr, val, size);
  111. }
  112. void igb_vf_reset(void *opaque, uint16_t vfn)
  113. {
  114. IGBState *s = opaque;
  115. igb_core_vf_reset(&s->core, vfn);
  116. }
  117. static bool
  118. igb_io_get_reg_index(IGBState *s, uint32_t *idx)
  119. {
  120. if (s->ioaddr < 0x1FFFF) {
  121. *idx = s->ioaddr;
  122. return true;
  123. }
  124. if (s->ioaddr < 0x7FFFF) {
  125. trace_e1000e_wrn_io_addr_undefined(s->ioaddr);
  126. return false;
  127. }
  128. if (s->ioaddr < 0xFFFFF) {
  129. trace_e1000e_wrn_io_addr_flash(s->ioaddr);
  130. return false;
  131. }
  132. trace_e1000e_wrn_io_addr_unknown(s->ioaddr);
  133. return false;
  134. }
  135. static uint64_t
  136. igb_io_read(void *opaque, hwaddr addr, unsigned size)
  137. {
  138. IGBState *s = opaque;
  139. uint32_t idx = 0;
  140. uint64_t val;
  141. switch (addr) {
  142. case E1000_IOADDR:
  143. trace_e1000e_io_read_addr(s->ioaddr);
  144. return s->ioaddr;
  145. case E1000_IODATA:
  146. if (igb_io_get_reg_index(s, &idx)) {
  147. val = igb_core_read(&s->core, idx, sizeof(val));
  148. trace_e1000e_io_read_data(idx, val);
  149. return val;
  150. }
  151. return 0;
  152. default:
  153. trace_e1000e_wrn_io_read_unknown(addr);
  154. return 0;
  155. }
  156. }
  157. static void
  158. igb_io_write(void *opaque, hwaddr addr, uint64_t val, unsigned size)
  159. {
  160. IGBState *s = opaque;
  161. uint32_t idx = 0;
  162. switch (addr) {
  163. case E1000_IOADDR:
  164. trace_e1000e_io_write_addr(val);
  165. s->ioaddr = (uint32_t) val;
  166. return;
  167. case E1000_IODATA:
  168. if (igb_io_get_reg_index(s, &idx)) {
  169. trace_e1000e_io_write_data(idx, val);
  170. igb_core_write(&s->core, idx, val, sizeof(val));
  171. }
  172. return;
  173. default:
  174. trace_e1000e_wrn_io_write_unknown(addr);
  175. return;
  176. }
  177. }
  178. static const MemoryRegionOps mmio_ops = {
  179. .read = igb_mmio_read,
  180. .write = igb_mmio_write,
  181. .endianness = DEVICE_LITTLE_ENDIAN,
  182. .impl = {
  183. .min_access_size = 4,
  184. .max_access_size = 4,
  185. },
  186. };
  187. static const MemoryRegionOps io_ops = {
  188. .read = igb_io_read,
  189. .write = igb_io_write,
  190. .endianness = DEVICE_LITTLE_ENDIAN,
  191. .impl = {
  192. .min_access_size = 4,
  193. .max_access_size = 4,
  194. },
  195. };
  196. static bool
  197. igb_nc_can_receive(NetClientState *nc)
  198. {
  199. IGBState *s = qemu_get_nic_opaque(nc);
  200. return igb_can_receive(&s->core);
  201. }
  202. static ssize_t
  203. igb_nc_receive_iov(NetClientState *nc, const struct iovec *iov, int iovcnt)
  204. {
  205. IGBState *s = qemu_get_nic_opaque(nc);
  206. return igb_receive_iov(&s->core, iov, iovcnt);
  207. }
  208. static ssize_t
  209. igb_nc_receive(NetClientState *nc, const uint8_t *buf, size_t size)
  210. {
  211. IGBState *s = qemu_get_nic_opaque(nc);
  212. return igb_receive(&s->core, buf, size);
  213. }
  214. static void
  215. igb_set_link_status(NetClientState *nc)
  216. {
  217. IGBState *s = qemu_get_nic_opaque(nc);
  218. igb_core_set_link_status(&s->core);
  219. }
  220. static NetClientInfo net_igb_info = {
  221. .type = NET_CLIENT_DRIVER_NIC,
  222. .size = sizeof(NICState),
  223. .can_receive = igb_nc_can_receive,
  224. .receive = igb_nc_receive,
  225. .receive_iov = igb_nc_receive_iov,
  226. .link_status_changed = igb_set_link_status,
  227. };
  228. /*
  229. * EEPROM (NVM) contents documented in section 6.1, table 6-1:
  230. * and in 6.10 Software accessed words.
  231. */
  232. static const uint16_t igb_eeprom_template[] = {
  233. /* Address |Compat.|OEM sp.| ImRev | OEM sp. */
  234. 0x0000, 0x0000, 0x0000, 0x0d34, 0xffff, 0x2010, 0xffff, 0xffff,
  235. /* PBA |ICtrl1 | SSID | SVID | DevID |-------|ICtrl2 */
  236. 0x1040, 0xffff, 0x002b, 0x0000, 0x8086, 0x10c9, 0x0000, 0x70c3,
  237. /* SwPin0| DevID | EESZ |-------|ICtrl3 |PCI-tc | MSIX | APtr */
  238. 0x0004, 0x10c9, 0x5c00, 0x0000, 0x2880, 0x0014, 0x4a40, 0x0060,
  239. /* PCIe Init. Conf 1,2,3 |PCICtrl| LD1,3 |DDevID |DevRev | LD0,2 */
  240. 0x6cfb, 0xc7b0, 0x0abe, 0x0403, 0x0783, 0x10a6, 0x0001, 0x0602,
  241. /* SwPin1| FunC |LAN-PWR|ManHwC |ICtrl3 | IOVct |VDevID |-------*/
  242. 0x0004, 0x0020, 0x0000, 0x004a, 0x2080, 0x00f5, 0x10ca, 0x0000,
  243. /*---------------| LD1,3 | LD0,2 | ROEnd | ROSta | Wdog | VPD */
  244. 0x0000, 0x0000, 0x4784, 0x4602, 0x0000, 0x0000, 0x1000, 0xffff,
  245. /* PCSet0| Ccfg0 |PXEver |IBAcap |PCSet1 | Ccfg1 |iSCVer | ?? */
  246. 0x0100, 0x4000, 0x131f, 0x4013, 0x0100, 0x4000, 0xffff, 0xffff,
  247. /* PCSet2| Ccfg2 |PCSet3 | Ccfg3 | ?? |AltMacP| ?? |CHKSUM */
  248. 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x00e0, 0xffff, 0x0000,
  249. /* NC-SIC */
  250. 0x0003,
  251. };
  252. static void igb_core_realize(IGBState *s)
  253. {
  254. s->core.owner = &s->parent_obj;
  255. s->core.owner_nic = s->nic;
  256. }
  257. static void
  258. igb_init_msix(IGBState *s)
  259. {
  260. int i, res;
  261. res = msix_init(PCI_DEVICE(s), IGB_MSIX_VEC_NUM,
  262. &s->msix,
  263. E1000E_MSIX_IDX, 0,
  264. &s->msix,
  265. E1000E_MSIX_IDX, 0x2000,
  266. 0x70, NULL);
  267. if (res < 0) {
  268. trace_e1000e_msix_init_fail(res);
  269. } else {
  270. for (i = 0; i < IGB_MSIX_VEC_NUM; i++) {
  271. msix_vector_use(PCI_DEVICE(s), i);
  272. }
  273. }
  274. }
  275. static void
  276. igb_cleanup_msix(IGBState *s)
  277. {
  278. msix_unuse_all_vectors(PCI_DEVICE(s));
  279. msix_uninit(PCI_DEVICE(s), &s->msix, &s->msix);
  280. }
  281. static void
  282. igb_init_net_peer(IGBState *s, PCIDevice *pci_dev, uint8_t *macaddr)
  283. {
  284. DeviceState *dev = DEVICE(pci_dev);
  285. NetClientState *nc;
  286. int i;
  287. s->nic = qemu_new_nic(&net_igb_info, &s->conf,
  288. object_get_typename(OBJECT(s)), dev->id, &dev->mem_reentrancy_guard, s);
  289. s->core.max_queue_num = s->conf.peers.queues ? s->conf.peers.queues - 1 : 0;
  290. trace_e1000e_mac_set_permanent(MAC_ARG(macaddr));
  291. memcpy(s->core.permanent_mac, macaddr, sizeof(s->core.permanent_mac));
  292. qemu_format_nic_info_str(qemu_get_queue(s->nic), macaddr);
  293. /* Setup virtio headers */
  294. for (i = 0; i < s->conf.peers.queues; i++) {
  295. nc = qemu_get_subqueue(s->nic, i);
  296. if (!nc->peer || !qemu_has_vnet_hdr(nc->peer)) {
  297. trace_e1000e_cfg_support_virtio(false);
  298. return;
  299. }
  300. }
  301. trace_e1000e_cfg_support_virtio(true);
  302. s->core.has_vnet = true;
  303. for (i = 0; i < s->conf.peers.queues; i++) {
  304. nc = qemu_get_subqueue(s->nic, i);
  305. qemu_set_vnet_hdr_len(nc->peer, sizeof(struct virtio_net_hdr));
  306. }
  307. }
  308. static int
  309. igb_add_pm_capability(PCIDevice *pdev, uint8_t offset, uint16_t pmc)
  310. {
  311. Error *local_err = NULL;
  312. int ret = pci_pm_init(pdev, offset, &local_err);
  313. if (local_err) {
  314. error_report_err(local_err);
  315. return ret;
  316. }
  317. pci_set_word(pdev->config + offset + PCI_PM_PMC,
  318. PCI_PM_CAP_VER_1_1 |
  319. pmc);
  320. pci_set_word(pdev->wmask + offset + PCI_PM_CTRL,
  321. PCI_PM_CTRL_STATE_MASK |
  322. PCI_PM_CTRL_PME_ENABLE |
  323. PCI_PM_CTRL_DATA_SEL_MASK);
  324. pci_set_word(pdev->w1cmask + offset + PCI_PM_CTRL,
  325. PCI_PM_CTRL_PME_STATUS);
  326. return ret;
  327. }
  328. static void igb_pci_realize(PCIDevice *pci_dev, Error **errp)
  329. {
  330. IGBState *s = IGB(pci_dev);
  331. uint8_t *macaddr;
  332. int ret;
  333. trace_e1000e_cb_pci_realize();
  334. pci_dev->config_write = igb_write_config;
  335. pci_dev->config[PCI_CACHE_LINE_SIZE] = 0x10;
  336. pci_dev->config[PCI_INTERRUPT_PIN] = 1;
  337. /* Define IO/MMIO regions */
  338. memory_region_init_io(&s->mmio, OBJECT(s), &mmio_ops, s,
  339. "igb-mmio", E1000E_MMIO_SIZE);
  340. pci_register_bar(pci_dev, E1000E_MMIO_IDX,
  341. PCI_BASE_ADDRESS_SPACE_MEMORY, &s->mmio);
  342. /*
  343. * We provide a dummy implementation for the flash BAR
  344. * for drivers that may theoretically probe for its presence.
  345. */
  346. memory_region_init(&s->flash, OBJECT(s),
  347. "igb-flash", E1000E_FLASH_SIZE);
  348. pci_register_bar(pci_dev, E1000E_FLASH_IDX,
  349. PCI_BASE_ADDRESS_SPACE_MEMORY, &s->flash);
  350. memory_region_init_io(&s->io, OBJECT(s), &io_ops, s,
  351. "igb-io", E1000E_IO_SIZE);
  352. pci_register_bar(pci_dev, E1000E_IO_IDX,
  353. PCI_BASE_ADDRESS_SPACE_IO, &s->io);
  354. memory_region_init(&s->msix, OBJECT(s), "igb-msix",
  355. E1000E_MSIX_SIZE);
  356. pci_register_bar(pci_dev, E1000E_MSIX_IDX,
  357. PCI_BASE_ADDRESS_MEM_TYPE_64, &s->msix);
  358. /* Create networking backend */
  359. qemu_macaddr_default_if_unset(&s->conf.macaddr);
  360. macaddr = s->conf.macaddr.a;
  361. /* Add PCI capabilities in reverse order */
  362. assert(pcie_endpoint_cap_init(pci_dev, 0xa0) > 0);
  363. igb_init_msix(s);
  364. ret = msi_init(pci_dev, 0x50, 1, true, true, NULL);
  365. if (ret) {
  366. trace_e1000e_msi_init_fail(ret);
  367. }
  368. if (igb_add_pm_capability(pci_dev, 0x40, PCI_PM_CAP_DSI) < 0) {
  369. hw_error("Failed to initialize PM capability");
  370. }
  371. /* PCIe extended capabilities (in order) */
  372. if (s->has_flr) {
  373. pcie_cap_flr_init(pci_dev);
  374. }
  375. if (pcie_aer_init(pci_dev, 1, 0x100, 0x40, errp) < 0) {
  376. hw_error("Failed to initialize AER capability");
  377. }
  378. pcie_ari_init(pci_dev, 0x150);
  379. if (!pcie_sriov_pf_init(pci_dev, IGB_CAP_SRIOV_OFFSET, TYPE_IGBVF,
  380. IGB_82576_VF_DEV_ID, IGB_MAX_VF_FUNCTIONS,
  381. IGB_MAX_VF_FUNCTIONS, IGB_VF_OFFSET, IGB_VF_STRIDE,
  382. errp)) {
  383. igb_cleanup_msix(s);
  384. return;
  385. }
  386. pcie_sriov_pf_init_vf_bar(pci_dev, IGBVF_MMIO_BAR_IDX,
  387. PCI_BASE_ADDRESS_MEM_TYPE_64 | PCI_BASE_ADDRESS_MEM_PREFETCH,
  388. IGBVF_MMIO_SIZE);
  389. pcie_sriov_pf_init_vf_bar(pci_dev, IGBVF_MSIX_BAR_IDX,
  390. PCI_BASE_ADDRESS_MEM_TYPE_64 | PCI_BASE_ADDRESS_MEM_PREFETCH,
  391. IGBVF_MSIX_SIZE);
  392. igb_init_net_peer(s, pci_dev, macaddr);
  393. /* Initialize core */
  394. igb_core_realize(s);
  395. igb_core_pci_realize(&s->core,
  396. igb_eeprom_template,
  397. sizeof(igb_eeprom_template),
  398. macaddr);
  399. }
  400. static void igb_pci_uninit(PCIDevice *pci_dev)
  401. {
  402. IGBState *s = IGB(pci_dev);
  403. trace_e1000e_cb_pci_uninit();
  404. igb_core_pci_uninit(&s->core);
  405. pcie_sriov_pf_exit(pci_dev);
  406. pcie_cap_exit(pci_dev);
  407. qemu_del_nic(s->nic);
  408. igb_cleanup_msix(s);
  409. msi_uninit(pci_dev);
  410. }
  411. static void igb_qdev_reset_hold(Object *obj, ResetType type)
  412. {
  413. IGBState *s = IGB(obj);
  414. trace_e1000e_cb_qdev_reset_hold();
  415. igb_core_reset(&s->core);
  416. }
  417. static int igb_pre_save(void *opaque)
  418. {
  419. IGBState *s = opaque;
  420. trace_e1000e_cb_pre_save();
  421. igb_core_pre_save(&s->core);
  422. return 0;
  423. }
  424. static int igb_post_load(void *opaque, int version_id)
  425. {
  426. IGBState *s = opaque;
  427. trace_e1000e_cb_post_load();
  428. return igb_core_post_load(&s->core);
  429. }
  430. static const VMStateDescription igb_vmstate_tx_ctx = {
  431. .name = "igb-tx-ctx",
  432. .version_id = 1,
  433. .minimum_version_id = 1,
  434. .fields = (const VMStateField[]) {
  435. VMSTATE_UINT32(vlan_macip_lens, struct e1000_adv_tx_context_desc),
  436. VMSTATE_UINT32(seqnum_seed, struct e1000_adv_tx_context_desc),
  437. VMSTATE_UINT32(type_tucmd_mlhl, struct e1000_adv_tx_context_desc),
  438. VMSTATE_UINT32(mss_l4len_idx, struct e1000_adv_tx_context_desc),
  439. VMSTATE_END_OF_LIST()
  440. }
  441. };
  442. static const VMStateDescription igb_vmstate_tx = {
  443. .name = "igb-tx",
  444. .version_id = 2,
  445. .minimum_version_id = 2,
  446. .fields = (const VMStateField[]) {
  447. VMSTATE_STRUCT_ARRAY(ctx, struct igb_tx, 2, 0, igb_vmstate_tx_ctx,
  448. struct e1000_adv_tx_context_desc),
  449. VMSTATE_UINT32(first_cmd_type_len, struct igb_tx),
  450. VMSTATE_UINT32(first_olinfo_status, struct igb_tx),
  451. VMSTATE_BOOL(first, struct igb_tx),
  452. VMSTATE_BOOL(skip_cp, struct igb_tx),
  453. VMSTATE_END_OF_LIST()
  454. }
  455. };
  456. static const VMStateDescription igb_vmstate_intr_timer = {
  457. .name = "igb-intr-timer",
  458. .version_id = 1,
  459. .minimum_version_id = 1,
  460. .fields = (const VMStateField[]) {
  461. VMSTATE_TIMER_PTR(timer, IGBIntrDelayTimer),
  462. VMSTATE_BOOL(running, IGBIntrDelayTimer),
  463. VMSTATE_END_OF_LIST()
  464. }
  465. };
  466. #define VMSTATE_IGB_INTR_DELAY_TIMER(_f, _s) \
  467. VMSTATE_STRUCT(_f, _s, 0, \
  468. igb_vmstate_intr_timer, IGBIntrDelayTimer)
  469. #define VMSTATE_IGB_INTR_DELAY_TIMER_ARRAY(_f, _s, _num) \
  470. VMSTATE_STRUCT_ARRAY(_f, _s, _num, 0, \
  471. igb_vmstate_intr_timer, IGBIntrDelayTimer)
  472. static const VMStateDescription igb_vmstate = {
  473. .name = "igb",
  474. .version_id = 1,
  475. .minimum_version_id = 1,
  476. .pre_save = igb_pre_save,
  477. .post_load = igb_post_load,
  478. .fields = (const VMStateField[]) {
  479. VMSTATE_PCI_DEVICE(parent_obj, IGBState),
  480. VMSTATE_MSIX(parent_obj, IGBState),
  481. VMSTATE_UINT32(ioaddr, IGBState),
  482. VMSTATE_UINT8(core.rx_desc_len, IGBState),
  483. VMSTATE_UINT16_ARRAY(core.eeprom, IGBState, IGB_EEPROM_SIZE),
  484. VMSTATE_UINT16_ARRAY(core.phy, IGBState, MAX_PHY_REG_ADDRESS + 1),
  485. VMSTATE_UINT32_ARRAY(core.mac, IGBState, E1000E_MAC_SIZE),
  486. VMSTATE_UINT8_ARRAY(core.permanent_mac, IGBState, ETH_ALEN),
  487. VMSTATE_IGB_INTR_DELAY_TIMER_ARRAY(core.eitr, IGBState,
  488. IGB_INTR_NUM),
  489. VMSTATE_UINT32_ARRAY(core.eitr_guest_value, IGBState, IGB_INTR_NUM),
  490. VMSTATE_STRUCT_ARRAY(core.tx, IGBState, IGB_NUM_QUEUES, 0,
  491. igb_vmstate_tx, struct igb_tx),
  492. VMSTATE_INT64(core.timadj, IGBState),
  493. VMSTATE_END_OF_LIST()
  494. }
  495. };
  496. static const Property igb_properties[] = {
  497. DEFINE_NIC_PROPERTIES(IGBState, conf),
  498. DEFINE_PROP_BOOL("x-pcie-flr-init", IGBState, has_flr, true),
  499. };
  500. static void igb_class_init(ObjectClass *class, void *data)
  501. {
  502. DeviceClass *dc = DEVICE_CLASS(class);
  503. ResettableClass *rc = RESETTABLE_CLASS(class);
  504. PCIDeviceClass *c = PCI_DEVICE_CLASS(class);
  505. c->realize = igb_pci_realize;
  506. c->exit = igb_pci_uninit;
  507. c->vendor_id = PCI_VENDOR_ID_INTEL;
  508. c->device_id = E1000_DEV_ID_82576;
  509. c->revision = 1;
  510. c->class_id = PCI_CLASS_NETWORK_ETHERNET;
  511. rc->phases.hold = igb_qdev_reset_hold;
  512. dc->desc = "Intel 82576 Gigabit Ethernet Controller";
  513. dc->vmsd = &igb_vmstate;
  514. device_class_set_props(dc, igb_properties);
  515. set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
  516. }
  517. static void igb_instance_init(Object *obj)
  518. {
  519. IGBState *s = IGB(obj);
  520. device_add_bootindex_property(obj, &s->conf.bootindex,
  521. "bootindex", "/ethernet-phy@0",
  522. DEVICE(obj));
  523. }
  524. static const TypeInfo igb_info = {
  525. .name = TYPE_IGB,
  526. .parent = TYPE_PCI_DEVICE,
  527. .instance_size = sizeof(IGBState),
  528. .class_init = igb_class_init,
  529. .instance_init = igb_instance_init,
  530. .interfaces = (InterfaceInfo[]) {
  531. { INTERFACE_PCIE_DEVICE },
  532. { }
  533. },
  534. };
  535. static void igb_register_types(void)
  536. {
  537. type_register_static(&igb_info);
  538. }
  539. type_init(igb_register_types)