igb_core.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * Core code for QEMU igb 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. #ifndef HW_NET_IGB_CORE_H
  40. #define HW_NET_IGB_CORE_H
  41. #define E1000E_MAC_SIZE (0x8000)
  42. #define IGB_EEPROM_SIZE (1024)
  43. #define IGB_INTR_NUM (25)
  44. #define IGB_MSIX_VEC_NUM (10)
  45. #define IGBVF_MSIX_VEC_NUM (3)
  46. #define IGB_NUM_QUEUES (16)
  47. #define IGB_NUM_VM_POOLS (8)
  48. typedef struct IGBCore IGBCore;
  49. enum { PHY_R = BIT(0),
  50. PHY_W = BIT(1),
  51. PHY_RW = PHY_R | PHY_W };
  52. typedef struct IGBIntrDelayTimer_st {
  53. QEMUTimer *timer;
  54. bool running;
  55. uint32_t delay_reg;
  56. uint32_t delay_resolution_ns;
  57. IGBCore *core;
  58. } IGBIntrDelayTimer;
  59. struct IGBCore {
  60. uint32_t mac[E1000E_MAC_SIZE];
  61. uint16_t phy[MAX_PHY_REG_ADDRESS + 1];
  62. uint16_t eeprom[IGB_EEPROM_SIZE];
  63. uint8_t rx_desc_len;
  64. QEMUTimer *autoneg_timer;
  65. struct igb_tx {
  66. struct e1000_adv_tx_context_desc ctx[2];
  67. uint32_t first_cmd_type_len;
  68. uint32_t first_olinfo_status;
  69. bool first;
  70. bool skip_cp;
  71. struct NetTxPkt *tx_pkt;
  72. } tx[IGB_NUM_QUEUES];
  73. struct NetRxPkt *rx_pkt;
  74. bool has_vnet;
  75. int max_queue_num;
  76. IGBIntrDelayTimer eitr[IGB_INTR_NUM];
  77. VMChangeStateEntry *vmstate;
  78. uint32_t eitr_guest_value[IGB_INTR_NUM];
  79. uint8_t permanent_mac[ETH_ALEN];
  80. NICState *owner_nic;
  81. PCIDevice *owner;
  82. void (*owner_start_recv)(PCIDevice *d);
  83. int64_t timadj;
  84. };
  85. void
  86. igb_core_write(IGBCore *core, hwaddr addr, uint64_t val, unsigned size);
  87. uint64_t
  88. igb_core_read(IGBCore *core, hwaddr addr, unsigned size);
  89. void
  90. igb_core_pci_realize(IGBCore *regs,
  91. const uint16_t *eeprom_templ,
  92. uint32_t eeprom_size,
  93. const uint8_t *macaddr);
  94. void
  95. igb_core_reset(IGBCore *core);
  96. void
  97. igb_core_pre_save(IGBCore *core);
  98. int
  99. igb_core_post_load(IGBCore *core);
  100. void
  101. igb_core_set_link_status(IGBCore *core);
  102. void
  103. igb_core_pci_uninit(IGBCore *core);
  104. bool
  105. igb_can_receive(IGBCore *core);
  106. ssize_t
  107. igb_receive(IGBCore *core, const uint8_t *buf, size_t size);
  108. ssize_t
  109. igb_receive_iov(IGBCore *core, const struct iovec *iov, int iovcnt);
  110. void
  111. igb_start_recv(IGBCore *core);
  112. #endif