e1000x_common.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * QEMU e1000(e) emulation - shared code
  3. *
  4. * Copyright (c) 2008 Qumranet
  5. *
  6. * Based on work done by:
  7. * Nir Peleg, Tutis Systems Ltd. for Qumranet Inc.
  8. * Copyright (c) 2007 Dan Aloni
  9. * Copyright (c) 2004 Antony T Curtis
  10. *
  11. * This library is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU Lesser General Public
  13. * License as published by the Free Software Foundation; either
  14. * version 2.1 of the License, or (at your option) any later version.
  15. *
  16. * This library is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * Lesser General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Lesser General Public
  22. * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  23. */
  24. #ifndef HW_NET_E1000X_COMMON_H
  25. #define HW_NET_E1000X_COMMON_H
  26. static inline void
  27. e1000x_inc_reg_if_not_full(uint32_t *mac, int index)
  28. {
  29. if (mac[index] != UINT32_MAX) {
  30. mac[index]++;
  31. }
  32. }
  33. static inline void
  34. e1000x_grow_8reg_if_not_full(uint32_t *mac, int index, int size)
  35. {
  36. uint64_t sum = mac[index] | (uint64_t)mac[index + 1] << 32;
  37. if (sum + size < sum) {
  38. sum = ~0ULL;
  39. } else {
  40. sum += size;
  41. }
  42. mac[index] = sum;
  43. mac[index + 1] = sum >> 32;
  44. }
  45. static inline int
  46. e1000x_vlan_enabled(uint32_t *mac)
  47. {
  48. return ((mac[CTRL] & E1000_CTRL_VME) != 0);
  49. }
  50. static inline int
  51. e1000x_is_vlan_txd(uint32_t txd_lower)
  52. {
  53. return ((txd_lower & E1000_TXD_CMD_VLE) != 0);
  54. }
  55. static inline int
  56. e1000x_vlan_rx_filter_enabled(uint32_t *mac)
  57. {
  58. return ((mac[RCTL] & E1000_RCTL_VFE) != 0);
  59. }
  60. static inline int
  61. e1000x_fcs_len(uint32_t *mac)
  62. {
  63. /* FCS aka Ethernet CRC-32. We don't get it from backends and can't
  64. * fill it in, just pad descriptor length by 4 bytes unless guest
  65. * told us to strip it off the packet. */
  66. return (mac[RCTL] & E1000_RCTL_SECRC) ? 0 : 4;
  67. }
  68. static inline void
  69. e1000x_update_regs_on_link_down(uint32_t *mac, uint16_t *phy)
  70. {
  71. mac[STATUS] &= ~E1000_STATUS_LU;
  72. phy[MII_BMSR] &= ~MII_BMSR_LINK_ST;
  73. phy[MII_BMSR] &= ~MII_BMSR_AN_COMP;
  74. phy[MII_ANLPAR] &= ~MII_ANLPAR_ACK;
  75. }
  76. static inline void
  77. e1000x_update_regs_on_link_up(uint32_t *mac, uint16_t *phy)
  78. {
  79. mac[STATUS] |= E1000_STATUS_LU;
  80. phy[MII_BMSR] |= MII_BMSR_LINK_ST;
  81. }
  82. void e1000x_update_rx_total_stats(uint32_t *mac,
  83. eth_pkt_types_e pkt_type,
  84. size_t pkt_size,
  85. size_t pkt_fcs_size);
  86. void e1000x_core_prepare_eeprom(uint16_t *eeprom,
  87. const uint16_t *templ,
  88. uint32_t templ_size,
  89. uint16_t dev_id,
  90. const uint8_t *macaddr);
  91. uint32_t e1000x_rxbufsize(uint32_t rctl);
  92. bool e1000x_rx_ready(PCIDevice *d, uint32_t *mac);
  93. bool e1000x_is_vlan_packet(const void *buf, uint16_t vet);
  94. bool e1000x_rx_group_filter(uint32_t *mac, const uint8_t *buf);
  95. bool e1000x_hw_rx_enabled(uint32_t *mac);
  96. bool e1000x_is_oversized(uint32_t *mac, size_t size);
  97. void e1000x_restart_autoneg(uint32_t *mac, uint16_t *phy, QEMUTimer *timer);
  98. void e1000x_reset_mac_addr(NICState *nic, uint32_t *mac_regs,
  99. uint8_t *mac_addr);
  100. void e1000x_update_regs_on_autoneg_done(uint32_t *mac, uint16_t *phy);
  101. void e1000x_increase_size_stats(uint32_t *mac, const int *size_regs, int size);
  102. typedef struct e1000x_txd_props {
  103. uint8_t ipcss;
  104. uint8_t ipcso;
  105. uint16_t ipcse;
  106. uint8_t tucss;
  107. uint8_t tucso;
  108. uint16_t tucse;
  109. uint32_t paylen;
  110. uint8_t hdr_len;
  111. uint16_t mss;
  112. int8_t ip;
  113. int8_t tcp;
  114. bool tse;
  115. } e1000x_txd_props;
  116. void e1000x_read_tx_ctx_descr(struct e1000_context_desc *d,
  117. e1000x_txd_props *props);
  118. void e1000x_timestamp(uint32_t *mac, int64_t timadj, size_t lo, size_t hi);
  119. void e1000x_set_timinca(uint32_t *mac, int64_t *timadj, uint32_t val);
  120. #endif