etsec.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * QEMU Freescale eTSEC Emulator
  3. *
  4. * Copyright (c) 2011-2013 AdaCore
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. */
  24. #ifndef ETSEC_H
  25. #define ETSEC_H
  26. #include "hw/sysbus.h"
  27. #include "net/net.h"
  28. #include "hw/ptimer.h"
  29. /* Buffer Descriptors */
  30. typedef struct eTSEC_rxtx_bd {
  31. uint16_t flags;
  32. uint16_t length;
  33. uint32_t bufptr;
  34. } eTSEC_rxtx_bd;
  35. #define BD_WRAP (1 << 13)
  36. #define BD_INTERRUPT (1 << 12)
  37. #define BD_LAST (1 << 11)
  38. #define BD_TX_READY (1 << 15)
  39. #define BD_TX_PADCRC (1 << 14)
  40. #define BD_TX_TC (1 << 10)
  41. #define BD_TX_PREDEF (1 << 9)
  42. #define BD_TX_HFELC (1 << 7)
  43. #define BD_TX_CFRL (1 << 6)
  44. #define BD_TX_RC_MASK 0xF
  45. #define BD_TX_RC_OFFSET 0x2
  46. #define BD_TX_TOEUN (1 << 1)
  47. #define BD_TX_TR (1 << 0)
  48. #define BD_RX_EMPTY (1 << 15)
  49. #define BD_RX_RO1 (1 << 14)
  50. #define BD_RX_FIRST (1 << 10)
  51. #define BD_RX_MISS (1 << 8)
  52. #define BD_RX_BROADCAST (1 << 7)
  53. #define BD_RX_MULTICAST (1 << 6)
  54. #define BD_RX_LG (1 << 5)
  55. #define BD_RX_NO (1 << 4)
  56. #define BD_RX_SH (1 << 3)
  57. #define BD_RX_CR (1 << 2)
  58. #define BD_RX_OV (1 << 1)
  59. #define BD_RX_TR (1 << 0)
  60. /* Tx FCB flags */
  61. #define FCB_TX_VLN (1 << 7)
  62. #define FCB_TX_IP (1 << 6)
  63. #define FCB_TX_IP6 (1 << 5)
  64. #define FCB_TX_TUP (1 << 4)
  65. #define FCB_TX_UDP (1 << 3)
  66. #define FCB_TX_CIP (1 << 2)
  67. #define FCB_TX_CTU (1 << 1)
  68. #define FCB_TX_NPH (1 << 0)
  69. /* PHY Status Register */
  70. #define MII_SR_EXTENDED_CAPS 0x0001 /* Extended register capabilities */
  71. #define MII_SR_JABBER_DETECT 0x0002 /* Jabber Detected */
  72. #define MII_SR_LINK_STATUS 0x0004 /* Link Status 1 = link */
  73. #define MII_SR_AUTONEG_CAPS 0x0008 /* Auto Neg Capable */
  74. #define MII_SR_REMOTE_FAULT 0x0010 /* Remote Fault Detect */
  75. #define MII_SR_AUTONEG_COMPLETE 0x0020 /* Auto Neg Complete */
  76. #define MII_SR_PREAMBLE_SUPPRESS 0x0040 /* Preamble may be suppressed */
  77. #define MII_SR_EXTENDED_STATUS 0x0100 /* Ext. status info in Reg 0x0F */
  78. #define MII_SR_100T2_HD_CAPS 0x0200 /* 100T2 Half Duplex Capable */
  79. #define MII_SR_100T2_FD_CAPS 0x0400 /* 100T2 Full Duplex Capable */
  80. #define MII_SR_10T_HD_CAPS 0x0800 /* 10T Half Duplex Capable */
  81. #define MII_SR_10T_FD_CAPS 0x1000 /* 10T Full Duplex Capable */
  82. #define MII_SR_100X_HD_CAPS 0x2000 /* 100X Half Duplex Capable */
  83. #define MII_SR_100X_FD_CAPS 0x4000 /* 100X Full Duplex Capable */
  84. #define MII_SR_100T4_CAPS 0x8000 /* 100T4 Capable */
  85. /* eTSEC */
  86. /* Number of register in the device */
  87. #define ETSEC_REG_NUMBER 1024
  88. typedef struct eTSEC_Register {
  89. const char *name;
  90. const char *desc;
  91. uint32_t access;
  92. uint32_t value;
  93. } eTSEC_Register;
  94. typedef struct eTSEC {
  95. SysBusDevice busdev;
  96. MemoryRegion io_area;
  97. eTSEC_Register regs[ETSEC_REG_NUMBER];
  98. NICState *nic;
  99. NICConf conf;
  100. /* Tx */
  101. uint8_t *tx_buffer;
  102. uint32_t tx_buffer_len;
  103. eTSEC_rxtx_bd first_bd;
  104. /* Rx */
  105. uint8_t *rx_buffer;
  106. uint32_t rx_buffer_len;
  107. uint32_t rx_remaining_data;
  108. uint8_t rx_first_in_frame;
  109. uint8_t rx_fcb_size;
  110. eTSEC_rxtx_bd rx_first_bd;
  111. uint8_t rx_fcb[10];
  112. uint32_t rx_padding;
  113. /* IRQs */
  114. qemu_irq tx_irq;
  115. qemu_irq rx_irq;
  116. qemu_irq err_irq;
  117. uint16_t phy_status;
  118. uint16_t phy_control;
  119. /* Polling */
  120. struct ptimer_state *ptimer;
  121. /* Whether we should flush the rx queue when buffer becomes available. */
  122. bool need_flush;
  123. } eTSEC;
  124. #define TYPE_ETSEC_COMMON "eTSEC"
  125. #define ETSEC_COMMON(obj) \
  126. OBJECT_CHECK(eTSEC, (obj), TYPE_ETSEC_COMMON)
  127. #define eTSEC_TRANSMIT 1
  128. #define eTSEC_RECEIVE 2
  129. DeviceState *etsec_create(hwaddr base,
  130. MemoryRegion *mr,
  131. NICInfo *nd,
  132. qemu_irq tx_irq,
  133. qemu_irq rx_irq,
  134. qemu_irq err_irq);
  135. void etsec_update_irq(eTSEC *etsec);
  136. void etsec_walk_tx_ring(eTSEC *etsec, int ring_nbr);
  137. void etsec_walk_rx_ring(eTSEC *etsec, int ring_nbr);
  138. ssize_t etsec_rx_ring_write(eTSEC *etsec, const uint8_t *buf, size_t size);
  139. void etsec_write_miim(eTSEC *etsec,
  140. eTSEC_Register *reg,
  141. uint32_t reg_index,
  142. uint32_t value);
  143. void etsec_miim_link_status(eTSEC *etsec, NetClientState *nc);
  144. #endif /* ETSEC_H */