2
0

e1000e_core.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. * Core code for QEMU e1000e emulation
  3. *
  4. * Software developer's manuals:
  5. * http://www.intel.com/content/dam/doc/datasheet/82574l-gbe-controller-datasheet.pdf
  6. *
  7. * Copyright (c) 2015 Ravello Systems LTD (http://ravellosystems.com)
  8. * Developed by Daynix Computing LTD (http://www.daynix.com)
  9. *
  10. * Authors:
  11. * Dmitry Fleytman <dmitry@daynix.com>
  12. * Leonid Bloch <leonid@daynix.com>
  13. * Yan Vugenfirer <yan@daynix.com>
  14. *
  15. * Based on work done by:
  16. * Nir Peleg, Tutis Systems Ltd. for Qumranet Inc.
  17. * Copyright (c) 2008 Qumranet
  18. * Based on work done by:
  19. * Copyright (c) 2007 Dan Aloni
  20. * Copyright (c) 2004 Antony T Curtis
  21. *
  22. * This library is free software; you can redistribute it and/or
  23. * modify it under the terms of the GNU Lesser General Public
  24. * License as published by the Free Software Foundation; either
  25. * version 2 of the License, or (at your option) any later version.
  26. *
  27. * This library is distributed in the hope that it will be useful,
  28. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  29. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  30. * Lesser General Public License for more details.
  31. *
  32. * You should have received a copy of the GNU Lesser General Public
  33. * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  34. */
  35. #ifndef HW_NET_E1000E_CORE_H
  36. #define HW_NET_E1000E_CORE_H
  37. #define E1000E_PHY_PAGE_SIZE (0x20)
  38. #define E1000E_PHY_PAGES (0x07)
  39. #define E1000E_MAC_SIZE (0x8000)
  40. #define E1000E_EEPROM_SIZE (64)
  41. #define E1000E_MSIX_VEC_NUM (5)
  42. #define E1000E_NUM_QUEUES (2)
  43. typedef struct E1000Core E1000ECore;
  44. enum { PHY_R = BIT(0),
  45. PHY_W = BIT(1),
  46. PHY_RW = PHY_R | PHY_W,
  47. PHY_ANYPAGE = BIT(2) };
  48. typedef struct E1000IntrDelayTimer_st {
  49. QEMUTimer *timer;
  50. bool running;
  51. uint32_t delay_reg;
  52. uint32_t delay_resolution_ns;
  53. E1000ECore *core;
  54. } E1000IntrDelayTimer;
  55. struct E1000Core {
  56. uint32_t mac[E1000E_MAC_SIZE];
  57. uint16_t phy[E1000E_PHY_PAGES][E1000E_PHY_PAGE_SIZE];
  58. uint16_t eeprom[E1000E_EEPROM_SIZE];
  59. uint32_t rxbuf_sizes[E1000_PSRCTL_BUFFS_PER_DESC];
  60. uint32_t rx_desc_buf_size;
  61. uint32_t rxbuf_min_shift;
  62. uint8_t rx_desc_len;
  63. QEMUTimer *autoneg_timer;
  64. struct e1000e_tx {
  65. e1000x_txd_props props;
  66. bool skip_cp;
  67. unsigned char sum_needed;
  68. bool cptse;
  69. struct NetTxPkt *tx_pkt;
  70. } tx[E1000E_NUM_QUEUES];
  71. struct NetRxPkt *rx_pkt;
  72. bool has_vnet;
  73. int max_queue_num;
  74. /* Interrupt moderation management */
  75. uint32_t delayed_causes;
  76. E1000IntrDelayTimer radv;
  77. E1000IntrDelayTimer rdtr;
  78. E1000IntrDelayTimer raid;
  79. E1000IntrDelayTimer tadv;
  80. E1000IntrDelayTimer tidv;
  81. E1000IntrDelayTimer itr;
  82. bool itr_intr_pending;
  83. E1000IntrDelayTimer eitr[E1000E_MSIX_VEC_NUM];
  84. bool eitr_intr_pending[E1000E_MSIX_VEC_NUM];
  85. VMChangeStateEntry *vmstate;
  86. uint32_t itr_guest_value;
  87. uint32_t eitr_guest_value[E1000E_MSIX_VEC_NUM];
  88. uint16_t vet;
  89. uint8_t permanent_mac[ETH_ALEN];
  90. NICState *owner_nic;
  91. PCIDevice *owner;
  92. void (*owner_start_recv)(PCIDevice *d);
  93. uint32_t msi_causes_pending;
  94. };
  95. void
  96. e1000e_core_write(E1000ECore *core, hwaddr addr, uint64_t val, unsigned size);
  97. uint64_t
  98. e1000e_core_read(E1000ECore *core, hwaddr addr, unsigned size);
  99. void
  100. e1000e_core_pci_realize(E1000ECore *regs,
  101. const uint16_t *eeprom_templ,
  102. uint32_t eeprom_size,
  103. const uint8_t *macaddr);
  104. void
  105. e1000e_core_reset(E1000ECore *core);
  106. void
  107. e1000e_core_pre_save(E1000ECore *core);
  108. int
  109. e1000e_core_post_load(E1000ECore *core);
  110. void
  111. e1000e_core_set_link_status(E1000ECore *core);
  112. void
  113. e1000e_core_pci_uninit(E1000ECore *core);
  114. int
  115. e1000e_can_receive(E1000ECore *core);
  116. ssize_t
  117. e1000e_receive(E1000ECore *core, const uint8_t *buf, size_t size);
  118. ssize_t
  119. e1000e_receive_iov(E1000ECore *core, const struct iovec *iov, int iovcnt);
  120. void
  121. e1000e_start_recv(E1000ECore *core);
  122. #endif