You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

myson.h 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. #ifndef _MYSON_H
  2. #define _MYSON_H
  3. /** @file
  4. *
  5. * Myson Technology network card driver
  6. *
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  9. #include <stdint.h>
  10. #include <ipxe/if_ether.h>
  11. /** BAR size */
  12. #define MYSON_BAR_SIZE 256
  13. /** A packet descriptor */
  14. struct myson_descriptor {
  15. /** Status */
  16. uint32_t status;
  17. /** Control */
  18. uint32_t control;
  19. /** Buffer start address */
  20. uint32_t address;
  21. /** Next descriptor address */
  22. uint32_t next;
  23. } __attribute__ (( packed ));
  24. /* Transmit status */
  25. #define MYSON_TX_STAT_OWN 0x80000000UL /**< Owner */
  26. #define MYSON_TX_STAT_ABORT 0x00002000UL /**< Abort */
  27. #define MYSON_TX_STAT_CSL 0x00001000UL /**< Carrier sense lost */
  28. /* Transmit control */
  29. #define MYSON_TX_CTRL_IC 0x80000000UL /**< Interrupt control */
  30. #define MYSON_TX_CTRL_LD 0x20000000UL /**< Last descriptor */
  31. #define MYSON_TX_CTRL_FD 0x10000000UL /**< First descriptor */
  32. #define MYSON_TX_CTRL_CRC 0x08000000UL /**< CRC append */
  33. #define MYSON_TX_CTRL_PAD 0x04000000UL /**< Pad control */
  34. #define MYSON_TX_CTRL_RTLC 0x02000000UL /**< Retry late collision */
  35. #define MYSON_TX_CTRL_PKTS(x) ( (x) << 11 ) /**< Packet size */
  36. #define MYSON_TX_CTRL_TBS(x) ( (x) << 0 ) /**< Transmit buffer size */
  37. /* Receive status */
  38. #define MYSON_RX_STAT_OWN 0x80000000UL /**< Owner */
  39. #define MYSON_RX_STAT_FLNG(status) ( ( (status) >> 16 ) & 0xfff )
  40. #define MYSON_RX_STAT_ES 0x00000080UL /**< Error summary */
  41. /* Receive control */
  42. #define MYSON_RX_CTRL_RBS(x) ( (x) << 0 ) /**< Receive buffer size */
  43. /** Descriptor ring alignment */
  44. #define MYSON_RING_ALIGN 4
  45. /** Physical Address Register 0 */
  46. #define MYSON_PAR0 0x00
  47. /** Physical Address Register 4 */
  48. #define MYSON_PAR4 0x04
  49. /** Physical address */
  50. union myson_physical_address {
  51. struct {
  52. uint32_t low;
  53. uint32_t high;
  54. } __attribute__ (( packed )) reg;
  55. uint8_t raw[ETH_ALEN];
  56. };
  57. /** Transmit and Receive Configuration Register */
  58. #define MYSON_TCR_RCR 0x18
  59. #define MYSON_TCR_TXS 0x80000000UL /**< Transmit status */
  60. #define MYSON_TCR_TE 0x00040000UL /**< Transmit enable */
  61. #define MYSON_RCR_RXS 0x00008000UL /**< Receive status */
  62. #define MYSON_RCR_PROM 0x00000080UL /**< Promiscuous mode */
  63. #define MYSON_RCR_AB 0x00000040UL /**< Accept broadcast */
  64. #define MYSON_RCR_AM 0x00000020UL /**< Accept multicast */
  65. #define MYSON_RCR_ARP 0x00000008UL /**< Accept runt packet */
  66. #define MYSON_RCR_ALP 0x00000004UL /**< Accept long packet */
  67. #define MYSON_RCR_RE 0x00000001UL /**< Receive enable */
  68. /** Maximum time to wait for transmit and receive to be idle, in milliseconds */
  69. #define MYSON_IDLE_MAX_WAIT_MS 100
  70. /** Bus Command Register */
  71. #define MYSON_BCR 0x1c
  72. #define MYSON_BCR_RLE 0x00000100UL /**< Read line enable */
  73. #define MYSON_BCR_RME 0x00000080UL /**< Read multiple enable */
  74. #define MYSON_BCR_WIE 0x00000040UL /**< Write and invalidate */
  75. #define MYSON_BCR_PBL(x) ( (x) << 3 ) /**< Burst length */
  76. #define MYSON_BCR_PBL_MASK MYSON_BCR_PBL ( 0x7 )
  77. #define MYSON_BCR_PBL_DEFAULT MYSON_BCR_PBL ( 0x6 )
  78. #define MYSON_BCR_SWR 0x00000001UL /**< Software reset */
  79. /** Maximum time to wait for a reset, in milliseconds */
  80. #define MYSON_RESET_MAX_WAIT_MS 100
  81. /** Transmit Poll Demand Register */
  82. #define MYSON_TXPDR 0x20
  83. /** Receive Poll Demand Register */
  84. #define MYSON_RXPDR 0x24
  85. /** Transmit List Base Address */
  86. #define MYSON_TXLBA 0x2c
  87. /** Number of transmit descriptors */
  88. #define MYSON_NUM_TX_DESC 4
  89. /** Receive List Base Address */
  90. #define MYSON_RXLBA 0x30
  91. /** Number of receive descriptors */
  92. #define MYSON_NUM_RX_DESC 4
  93. /** Receive buffer length */
  94. #define MYSON_RX_MAX_LEN ( ETH_FRAME_LEN + 4 /* VLAN */ + 4 /* CRC */ )
  95. /** Interrupt Status Register */
  96. #define MYSON_ISR 0x34
  97. #define MYSON_IRQ_TI 0x00000008UL /**< Transmit interrupt */
  98. #define MYSON_IRQ_RI 0x00000004UL /**< Receive interrupt */
  99. /** Number of I/O delays between ISR reads */
  100. #define MYSON_ISR_IODELAY_COUNT 4
  101. /** Interrupt Mask Register */
  102. #define MYSON_IMR 0x38
  103. /** Boot ROM / EEPROM / MII Management Register */
  104. #define MYSON_ROM_MII 0x40
  105. #define MYSON_ROM_AUTOLD 0x00100000UL /**< Auto load */
  106. /** Maximum time to wait for a configuration reload, in milliseconds */
  107. #define MYSON_AUTOLD_MAX_WAIT_MS 100
  108. /** A Myson descriptor ring */
  109. struct myson_ring {
  110. /** Descriptors */
  111. struct myson_descriptor *desc;
  112. /** Producer index */
  113. unsigned int prod;
  114. /** Consumer index */
  115. unsigned int cons;
  116. /** Number of descriptors */
  117. unsigned int count;
  118. /** Descriptor start address register */
  119. unsigned int reg;
  120. };
  121. /**
  122. * Initialise descriptor ring
  123. *
  124. * @v ring Descriptor ring
  125. * @v count Number of descriptors
  126. * @v reg Descriptor base address register
  127. */
  128. static inline __attribute__ (( always_inline)) void
  129. myson_init_ring ( struct myson_ring *ring, unsigned int count,
  130. unsigned int reg ) {
  131. ring->count = count;
  132. ring->reg = reg;
  133. }
  134. /** A myson network card */
  135. struct myson_nic {
  136. /** Registers */
  137. void *regs;
  138. /** Transmit descriptor ring */
  139. struct myson_ring tx;
  140. /** Receive descriptor ring */
  141. struct myson_ring rx;
  142. /** Receive I/O buffers */
  143. struct io_buffer *rx_iobuf[MYSON_NUM_RX_DESC];
  144. };
  145. /**
  146. * Check if card can access physical address
  147. *
  148. * @v address Physical address
  149. * @v address_ok Card can access physical address
  150. */
  151. static inline __attribute__ (( always_inline )) int
  152. myson_address_ok ( physaddr_t address ) {
  153. /* In a 32-bit build, all addresses can be accessed */
  154. if ( sizeof ( physaddr_t ) <= sizeof ( uint32_t ) )
  155. return 1;
  156. /* Card can access all addresses below 4GB */
  157. if ( ( address & ~0xffffffffULL ) == 0 )
  158. return 1;
  159. return 0;
  160. }
  161. #endif /* _MYSON_H */