2
0

igb.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  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 "sysemu/sysemu.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. };
  74. #define IGB_CAP_SRIOV_OFFSET (0x160)
  75. #define IGB_VF_OFFSET (0x80)
  76. #define IGB_VF_STRIDE (2)
  77. #define E1000E_MMIO_IDX 0
  78. #define E1000E_FLASH_IDX 1
  79. #define E1000E_IO_IDX 2
  80. #define E1000E_MSIX_IDX 3
  81. #define E1000E_MMIO_SIZE (128 * KiB)
  82. #define E1000E_FLASH_SIZE (128 * KiB)
  83. #define E1000E_IO_SIZE (32)
  84. #define E1000E_MSIX_SIZE (16 * KiB)
  85. static void igb_write_config(PCIDevice *dev, uint32_t addr,
  86. uint32_t val, int len)
  87. {
  88. IGBState *s = IGB(dev);
  89. trace_igb_write_config(addr, val, len);
  90. pci_default_write_config(dev, addr, val, len);
  91. if (range_covers_byte(addr, len, PCI_COMMAND) &&
  92. (dev->config[PCI_COMMAND] & PCI_COMMAND_MASTER)) {
  93. igb_start_recv(&s->core);
  94. }
  95. }
  96. uint64_t
  97. igb_mmio_read(void *opaque, hwaddr addr, unsigned size)
  98. {
  99. IGBState *s = opaque;
  100. return igb_core_read(&s->core, addr, size);
  101. }
  102. void
  103. igb_mmio_write(void *opaque, hwaddr addr, uint64_t val, unsigned size)
  104. {
  105. IGBState *s = opaque;
  106. igb_core_write(&s->core, addr, val, size);
  107. }
  108. static bool
  109. igb_io_get_reg_index(IGBState *s, uint32_t *idx)
  110. {
  111. if (s->ioaddr < 0x1FFFF) {
  112. *idx = s->ioaddr;
  113. return true;
  114. }
  115. if (s->ioaddr < 0x7FFFF) {
  116. trace_e1000e_wrn_io_addr_undefined(s->ioaddr);
  117. return false;
  118. }
  119. if (s->ioaddr < 0xFFFFF) {
  120. trace_e1000e_wrn_io_addr_flash(s->ioaddr);
  121. return false;
  122. }
  123. trace_e1000e_wrn_io_addr_unknown(s->ioaddr);
  124. return false;
  125. }
  126. static uint64_t
  127. igb_io_read(void *opaque, hwaddr addr, unsigned size)
  128. {
  129. IGBState *s = opaque;
  130. uint32_t idx = 0;
  131. uint64_t val;
  132. switch (addr) {
  133. case E1000_IOADDR:
  134. trace_e1000e_io_read_addr(s->ioaddr);
  135. return s->ioaddr;
  136. case E1000_IODATA:
  137. if (igb_io_get_reg_index(s, &idx)) {
  138. val = igb_core_read(&s->core, idx, sizeof(val));
  139. trace_e1000e_io_read_data(idx, val);
  140. return val;
  141. }
  142. return 0;
  143. default:
  144. trace_e1000e_wrn_io_read_unknown(addr);
  145. return 0;
  146. }
  147. }
  148. static void
  149. igb_io_write(void *opaque, hwaddr addr, uint64_t val, unsigned size)
  150. {
  151. IGBState *s = opaque;
  152. uint32_t idx = 0;
  153. switch (addr) {
  154. case E1000_IOADDR:
  155. trace_e1000e_io_write_addr(val);
  156. s->ioaddr = (uint32_t) val;
  157. return;
  158. case E1000_IODATA:
  159. if (igb_io_get_reg_index(s, &idx)) {
  160. trace_e1000e_io_write_data(idx, val);
  161. igb_core_write(&s->core, idx, val, sizeof(val));
  162. }
  163. return;
  164. default:
  165. trace_e1000e_wrn_io_write_unknown(addr);
  166. return;
  167. }
  168. }
  169. static const MemoryRegionOps mmio_ops = {
  170. .read = igb_mmio_read,
  171. .write = igb_mmio_write,
  172. .endianness = DEVICE_LITTLE_ENDIAN,
  173. .impl = {
  174. .min_access_size = 4,
  175. .max_access_size = 4,
  176. },
  177. };
  178. static const MemoryRegionOps io_ops = {
  179. .read = igb_io_read,
  180. .write = igb_io_write,
  181. .endianness = DEVICE_LITTLE_ENDIAN,
  182. .impl = {
  183. .min_access_size = 4,
  184. .max_access_size = 4,
  185. },
  186. };
  187. static bool
  188. igb_nc_can_receive(NetClientState *nc)
  189. {
  190. IGBState *s = qemu_get_nic_opaque(nc);
  191. return igb_can_receive(&s->core);
  192. }
  193. static ssize_t
  194. igb_nc_receive_iov(NetClientState *nc, const struct iovec *iov, int iovcnt)
  195. {
  196. IGBState *s = qemu_get_nic_opaque(nc);
  197. return igb_receive_iov(&s->core, iov, iovcnt);
  198. }
  199. static ssize_t
  200. igb_nc_receive(NetClientState *nc, const uint8_t *buf, size_t size)
  201. {
  202. IGBState *s = qemu_get_nic_opaque(nc);
  203. return igb_receive(&s->core, buf, size);
  204. }
  205. static void
  206. igb_set_link_status(NetClientState *nc)
  207. {
  208. IGBState *s = qemu_get_nic_opaque(nc);
  209. igb_core_set_link_status(&s->core);
  210. }
  211. static NetClientInfo net_igb_info = {
  212. .type = NET_CLIENT_DRIVER_NIC,
  213. .size = sizeof(NICState),
  214. .can_receive = igb_nc_can_receive,
  215. .receive = igb_nc_receive,
  216. .receive_iov = igb_nc_receive_iov,
  217. .link_status_changed = igb_set_link_status,
  218. };
  219. /*
  220. * EEPROM (NVM) contents documented in section 6.1, table 6-1:
  221. * and in 6.10 Software accessed words.
  222. */
  223. static const uint16_t igb_eeprom_template[] = {
  224. /* Address |Compat.|OEM sp.| ImRev | OEM sp. */
  225. 0x0000, 0x0000, 0x0000, 0x0d34, 0xffff, 0x2010, 0xffff, 0xffff,
  226. /* PBA |ICtrl1 | SSID | SVID | DevID |-------|ICtrl2 */
  227. 0x1040, 0xffff, 0x002b, 0x0000, 0x8086, 0x10c9, 0x0000, 0x70c3,
  228. /* SwPin0| DevID | EESZ |-------|ICtrl3 |PCI-tc | MSIX | APtr */
  229. 0x0004, 0x10c9, 0x5c00, 0x0000, 0x2880, 0x0014, 0x4a40, 0x0060,
  230. /* PCIe Init. Conf 1,2,3 |PCICtrl| LD1,3 |DDevID |DevRev | LD0,2 */
  231. 0x6cfb, 0xc7b0, 0x0abe, 0x0403, 0x0783, 0x10a6, 0x0001, 0x0602,
  232. /* SwPin1| FunC |LAN-PWR|ManHwC |ICtrl3 | IOVct |VDevID |-------*/
  233. 0x0004, 0x0020, 0x0000, 0x004a, 0x2080, 0x00f5, 0x10ca, 0x0000,
  234. /*---------------| LD1,3 | LD0,2 | ROEnd | ROSta | Wdog | VPD */
  235. 0x0000, 0x0000, 0x4784, 0x4602, 0x0000, 0x0000, 0x1000, 0xffff,
  236. /* PCSet0| Ccfg0 |PXEver |IBAcap |PCSet1 | Ccfg1 |iSCVer | ?? */
  237. 0x0100, 0x4000, 0x131f, 0x4013, 0x0100, 0x4000, 0xffff, 0xffff,
  238. /* PCSet2| Ccfg2 |PCSet3 | Ccfg3 | ?? |AltMacP| ?? |CHKSUM */
  239. 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x00e0, 0xffff, 0x0000,
  240. /* NC-SIC */
  241. 0x0003,
  242. };
  243. static void igb_core_realize(IGBState *s)
  244. {
  245. s->core.owner = &s->parent_obj;
  246. s->core.owner_nic = s->nic;
  247. }
  248. static void
  249. igb_init_msix(IGBState *s)
  250. {
  251. int i, res;
  252. res = msix_init(PCI_DEVICE(s), IGB_MSIX_VEC_NUM,
  253. &s->msix,
  254. E1000E_MSIX_IDX, 0,
  255. &s->msix,
  256. E1000E_MSIX_IDX, 0x2000,
  257. 0x70, NULL);
  258. if (res < 0) {
  259. trace_e1000e_msix_init_fail(res);
  260. } else {
  261. for (i = 0; i < IGB_MSIX_VEC_NUM; i++) {
  262. msix_vector_use(PCI_DEVICE(s), i);
  263. }
  264. }
  265. }
  266. static void
  267. igb_cleanup_msix(IGBState *s)
  268. {
  269. msix_unuse_all_vectors(PCI_DEVICE(s));
  270. msix_uninit(PCI_DEVICE(s), &s->msix, &s->msix);
  271. }
  272. static void
  273. igb_init_net_peer(IGBState *s, PCIDevice *pci_dev, uint8_t *macaddr)
  274. {
  275. DeviceState *dev = DEVICE(pci_dev);
  276. NetClientState *nc;
  277. int i;
  278. s->nic = qemu_new_nic(&net_igb_info, &s->conf,
  279. object_get_typename(OBJECT(s)), dev->id, s);
  280. s->core.max_queue_num = s->conf.peers.queues ? s->conf.peers.queues - 1 : 0;
  281. trace_e1000e_mac_set_permanent(MAC_ARG(macaddr));
  282. memcpy(s->core.permanent_mac, macaddr, sizeof(s->core.permanent_mac));
  283. qemu_format_nic_info_str(qemu_get_queue(s->nic), macaddr);
  284. /* Setup virtio headers */
  285. for (i = 0; i < s->conf.peers.queues; i++) {
  286. nc = qemu_get_subqueue(s->nic, i);
  287. if (!nc->peer || !qemu_has_vnet_hdr(nc->peer)) {
  288. trace_e1000e_cfg_support_virtio(false);
  289. return;
  290. }
  291. }
  292. trace_e1000e_cfg_support_virtio(true);
  293. s->core.has_vnet = true;
  294. for (i = 0; i < s->conf.peers.queues; i++) {
  295. nc = qemu_get_subqueue(s->nic, i);
  296. qemu_set_vnet_hdr_len(nc->peer, sizeof(struct virtio_net_hdr));
  297. qemu_using_vnet_hdr(nc->peer, true);
  298. }
  299. }
  300. static int
  301. igb_add_pm_capability(PCIDevice *pdev, uint8_t offset, uint16_t pmc)
  302. {
  303. Error *local_err = NULL;
  304. int ret = pci_add_capability(pdev, PCI_CAP_ID_PM, offset,
  305. PCI_PM_SIZEOF, &local_err);
  306. if (local_err) {
  307. error_report_err(local_err);
  308. return ret;
  309. }
  310. pci_set_word(pdev->config + offset + PCI_PM_PMC,
  311. PCI_PM_CAP_VER_1_1 |
  312. pmc);
  313. pci_set_word(pdev->wmask + offset + PCI_PM_CTRL,
  314. PCI_PM_CTRL_STATE_MASK |
  315. PCI_PM_CTRL_PME_ENABLE |
  316. PCI_PM_CTRL_DATA_SEL_MASK);
  317. pci_set_word(pdev->w1cmask + offset + PCI_PM_CTRL,
  318. PCI_PM_CTRL_PME_STATUS);
  319. return ret;
  320. }
  321. static void igb_pci_realize(PCIDevice *pci_dev, Error **errp)
  322. {
  323. IGBState *s = IGB(pci_dev);
  324. uint8_t *macaddr;
  325. int ret;
  326. trace_e1000e_cb_pci_realize();
  327. pci_dev->config_write = igb_write_config;
  328. pci_dev->config[PCI_CACHE_LINE_SIZE] = 0x10;
  329. pci_dev->config[PCI_INTERRUPT_PIN] = 1;
  330. /* Define IO/MMIO regions */
  331. memory_region_init_io(&s->mmio, OBJECT(s), &mmio_ops, s,
  332. "igb-mmio", E1000E_MMIO_SIZE);
  333. pci_register_bar(pci_dev, E1000E_MMIO_IDX,
  334. PCI_BASE_ADDRESS_SPACE_MEMORY, &s->mmio);
  335. /*
  336. * We provide a dummy implementation for the flash BAR
  337. * for drivers that may theoretically probe for its presence.
  338. */
  339. memory_region_init(&s->flash, OBJECT(s),
  340. "igb-flash", E1000E_FLASH_SIZE);
  341. pci_register_bar(pci_dev, E1000E_FLASH_IDX,
  342. PCI_BASE_ADDRESS_SPACE_MEMORY, &s->flash);
  343. memory_region_init_io(&s->io, OBJECT(s), &io_ops, s,
  344. "igb-io", E1000E_IO_SIZE);
  345. pci_register_bar(pci_dev, E1000E_IO_IDX,
  346. PCI_BASE_ADDRESS_SPACE_IO, &s->io);
  347. memory_region_init(&s->msix, OBJECT(s), "igb-msix",
  348. E1000E_MSIX_SIZE);
  349. pci_register_bar(pci_dev, E1000E_MSIX_IDX,
  350. PCI_BASE_ADDRESS_MEM_TYPE_64, &s->msix);
  351. /* Create networking backend */
  352. qemu_macaddr_default_if_unset(&s->conf.macaddr);
  353. macaddr = s->conf.macaddr.a;
  354. /* Add PCI capabilities in reverse order */
  355. assert(pcie_endpoint_cap_init(pci_dev, 0xa0) > 0);
  356. igb_init_msix(s);
  357. ret = msi_init(pci_dev, 0x50, 1, true, true, NULL);
  358. if (ret) {
  359. trace_e1000e_msi_init_fail(ret);
  360. }
  361. if (igb_add_pm_capability(pci_dev, 0x40, PCI_PM_CAP_DSI) < 0) {
  362. hw_error("Failed to initialize PM capability");
  363. }
  364. /* PCIe extended capabilities (in order) */
  365. if (pcie_aer_init(pci_dev, 1, 0x100, 0x40, errp) < 0) {
  366. hw_error("Failed to initialize AER capability");
  367. }
  368. pcie_ari_init(pci_dev, 0x150, 1);
  369. pcie_sriov_pf_init(pci_dev, IGB_CAP_SRIOV_OFFSET, "igbvf",
  370. IGB_82576_VF_DEV_ID, IGB_MAX_VF_FUNCTIONS, IGB_MAX_VF_FUNCTIONS,
  371. IGB_VF_OFFSET, IGB_VF_STRIDE);
  372. pcie_sriov_pf_init_vf_bar(pci_dev, 0,
  373. PCI_BASE_ADDRESS_MEM_TYPE_64 | PCI_BASE_ADDRESS_MEM_PREFETCH,
  374. 16 * KiB);
  375. pcie_sriov_pf_init_vf_bar(pci_dev, 3,
  376. PCI_BASE_ADDRESS_MEM_TYPE_64 | PCI_BASE_ADDRESS_MEM_PREFETCH,
  377. 16 * KiB);
  378. igb_init_net_peer(s, pci_dev, macaddr);
  379. /* Initialize core */
  380. igb_core_realize(s);
  381. igb_core_pci_realize(&s->core,
  382. igb_eeprom_template,
  383. sizeof(igb_eeprom_template),
  384. macaddr);
  385. }
  386. static void igb_pci_uninit(PCIDevice *pci_dev)
  387. {
  388. IGBState *s = IGB(pci_dev);
  389. trace_e1000e_cb_pci_uninit();
  390. igb_core_pci_uninit(&s->core);
  391. pcie_sriov_pf_exit(pci_dev);
  392. pcie_cap_exit(pci_dev);
  393. qemu_del_nic(s->nic);
  394. igb_cleanup_msix(s);
  395. msi_uninit(pci_dev);
  396. }
  397. static void igb_qdev_reset_hold(Object *obj)
  398. {
  399. PCIDevice *d = PCI_DEVICE(obj);
  400. IGBState *s = IGB(obj);
  401. trace_e1000e_cb_qdev_reset_hold();
  402. pcie_sriov_pf_disable_vfs(d);
  403. igb_core_reset(&s->core);
  404. }
  405. static int igb_pre_save(void *opaque)
  406. {
  407. IGBState *s = opaque;
  408. trace_e1000e_cb_pre_save();
  409. igb_core_pre_save(&s->core);
  410. return 0;
  411. }
  412. static int igb_post_load(void *opaque, int version_id)
  413. {
  414. IGBState *s = opaque;
  415. trace_e1000e_cb_post_load();
  416. return igb_core_post_load(&s->core);
  417. }
  418. static const VMStateDescription igb_vmstate_tx_ctx = {
  419. .name = "igb-tx-ctx",
  420. .version_id = 1,
  421. .minimum_version_id = 1,
  422. .fields = (VMStateField[]) {
  423. VMSTATE_UINT32(vlan_macip_lens, struct e1000_adv_tx_context_desc),
  424. VMSTATE_UINT32(seqnum_seed, struct e1000_adv_tx_context_desc),
  425. VMSTATE_UINT32(type_tucmd_mlhl, struct e1000_adv_tx_context_desc),
  426. VMSTATE_UINT32(mss_l4len_idx, struct e1000_adv_tx_context_desc),
  427. VMSTATE_END_OF_LIST()
  428. }
  429. };
  430. static const VMStateDescription igb_vmstate_tx = {
  431. .name = "igb-tx",
  432. .version_id = 2,
  433. .minimum_version_id = 2,
  434. .fields = (VMStateField[]) {
  435. VMSTATE_STRUCT_ARRAY(ctx, struct igb_tx, 2, 0, igb_vmstate_tx_ctx,
  436. struct e1000_adv_tx_context_desc),
  437. VMSTATE_UINT32(first_cmd_type_len, struct igb_tx),
  438. VMSTATE_UINT32(first_olinfo_status, struct igb_tx),
  439. VMSTATE_BOOL(first, struct igb_tx),
  440. VMSTATE_BOOL(skip_cp, struct igb_tx),
  441. VMSTATE_END_OF_LIST()
  442. }
  443. };
  444. static const VMStateDescription igb_vmstate_intr_timer = {
  445. .name = "igb-intr-timer",
  446. .version_id = 1,
  447. .minimum_version_id = 1,
  448. .fields = (VMStateField[]) {
  449. VMSTATE_TIMER_PTR(timer, IGBIntrDelayTimer),
  450. VMSTATE_BOOL(running, IGBIntrDelayTimer),
  451. VMSTATE_END_OF_LIST()
  452. }
  453. };
  454. #define VMSTATE_IGB_INTR_DELAY_TIMER(_f, _s) \
  455. VMSTATE_STRUCT(_f, _s, 0, \
  456. igb_vmstate_intr_timer, IGBIntrDelayTimer)
  457. #define VMSTATE_IGB_INTR_DELAY_TIMER_ARRAY(_f, _s, _num) \
  458. VMSTATE_STRUCT_ARRAY(_f, _s, _num, 0, \
  459. igb_vmstate_intr_timer, IGBIntrDelayTimer)
  460. static const VMStateDescription igb_vmstate = {
  461. .name = "igb",
  462. .version_id = 1,
  463. .minimum_version_id = 1,
  464. .pre_save = igb_pre_save,
  465. .post_load = igb_post_load,
  466. .fields = (VMStateField[]) {
  467. VMSTATE_PCI_DEVICE(parent_obj, IGBState),
  468. VMSTATE_MSIX(parent_obj, IGBState),
  469. VMSTATE_UINT32(ioaddr, IGBState),
  470. VMSTATE_UINT8(core.rx_desc_len, IGBState),
  471. VMSTATE_UINT16_ARRAY(core.eeprom, IGBState, IGB_EEPROM_SIZE),
  472. VMSTATE_UINT16_ARRAY(core.phy, IGBState, MAX_PHY_REG_ADDRESS + 1),
  473. VMSTATE_UINT32_ARRAY(core.mac, IGBState, E1000E_MAC_SIZE),
  474. VMSTATE_UINT8_ARRAY(core.permanent_mac, IGBState, ETH_ALEN),
  475. VMSTATE_IGB_INTR_DELAY_TIMER_ARRAY(core.eitr, IGBState,
  476. IGB_INTR_NUM),
  477. VMSTATE_UINT32_ARRAY(core.eitr_guest_value, IGBState, IGB_INTR_NUM),
  478. VMSTATE_STRUCT_ARRAY(core.tx, IGBState, IGB_NUM_QUEUES, 0,
  479. igb_vmstate_tx, struct igb_tx),
  480. VMSTATE_INT64(core.timadj, IGBState),
  481. VMSTATE_END_OF_LIST()
  482. }
  483. };
  484. static Property igb_properties[] = {
  485. DEFINE_NIC_PROPERTIES(IGBState, conf),
  486. DEFINE_PROP_END_OF_LIST(),
  487. };
  488. static void igb_class_init(ObjectClass *class, void *data)
  489. {
  490. DeviceClass *dc = DEVICE_CLASS(class);
  491. ResettableClass *rc = RESETTABLE_CLASS(class);
  492. PCIDeviceClass *c = PCI_DEVICE_CLASS(class);
  493. c->realize = igb_pci_realize;
  494. c->exit = igb_pci_uninit;
  495. c->vendor_id = PCI_VENDOR_ID_INTEL;
  496. c->device_id = E1000_DEV_ID_82576;
  497. c->revision = 1;
  498. c->class_id = PCI_CLASS_NETWORK_ETHERNET;
  499. rc->phases.hold = igb_qdev_reset_hold;
  500. dc->desc = "Intel 82576 Gigabit Ethernet Controller";
  501. dc->vmsd = &igb_vmstate;
  502. device_class_set_props(dc, igb_properties);
  503. set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
  504. }
  505. static void igb_instance_init(Object *obj)
  506. {
  507. IGBState *s = IGB(obj);
  508. device_add_bootindex_property(obj, &s->conf.bootindex,
  509. "bootindex", "/ethernet-phy@0",
  510. DEVICE(obj));
  511. }
  512. static const TypeInfo igb_info = {
  513. .name = TYPE_IGB,
  514. .parent = TYPE_PCI_DEVICE,
  515. .instance_size = sizeof(IGBState),
  516. .class_init = igb_class_init,
  517. .instance_init = igb_instance_init,
  518. .interfaces = (InterfaceInfo[]) {
  519. { INTERFACE_PCIE_DEVICE },
  520. { }
  521. },
  522. };
  523. static void igb_register_types(void)
  524. {
  525. type_register_static(&igb_info);
  526. }
  527. type_init(igb_register_types)