altera_tse.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * Altera 10/100/1000 triple speed ethernet mac
  3. *
  4. * Copyright (C) 2008 Altera Corporation.
  5. * Copyright (C) 2010 Thomas Chou <thomas@wytron.com.tw>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #ifndef _ALTERA_TSE_H_
  12. #define _ALTERA_TSE_H_
  13. #define __packed_1_ __packed __aligned(1)
  14. /* dma type */
  15. #define ALT_SGDMA 0
  16. /* SGDMA Stuff */
  17. #define ALT_SGDMA_STATUS_BUSY_MSK BIT(4)
  18. #define ALT_SGDMA_CONTROL_RUN_MSK BIT(5)
  19. #define ALT_SGDMA_CONTROL_STOP_DMA_ER_MSK BIT(6)
  20. #define ALT_SGDMA_CONTROL_SOFTWARERESET_MSK BIT(16)
  21. /*
  22. * Descriptor control bit masks & offsets
  23. *
  24. * Note: The control byte physically occupies bits [31:24] in memory.
  25. * The following bit-offsets are expressed relative to the LSB of
  26. * the control register bitfield.
  27. */
  28. #define ALT_SGDMA_DESCRIPTOR_CONTROL_GENERATE_EOP_MSK BIT(0)
  29. #define ALT_SGDMA_DESCRIPTOR_CONTROL_READ_FIXED_ADDRESS_MSK BIT(1)
  30. #define ALT_SGDMA_DESCRIPTOR_CONTROL_WRITE_FIXED_ADDRESS_MSK BIT(2)
  31. #define ALT_SGDMA_DESCRIPTOR_CONTROL_OWNED_BY_HW_MSK BIT(7)
  32. /*
  33. * Descriptor status bit masks & offsets
  34. *
  35. * Note: The status byte physically occupies bits [23:16] in memory.
  36. * The following bit-offsets are expressed relative to the LSB of
  37. * the status register bitfield.
  38. */
  39. #define ALT_SGDMA_DESCRIPTOR_STATUS_TERMINATED_BY_EOP_MSK BIT(7)
  40. /*
  41. * The SGDMA controller buffer descriptor allocates
  42. * 64 bits for each address. To support ANSI C, the
  43. * struct implementing a descriptor places 32-bits
  44. * of padding directly above each address; each pad must
  45. * be cleared when initializing a descriptor.
  46. */
  47. /*
  48. * Buffer Descriptor data structure
  49. *
  50. */
  51. struct alt_sgdma_descriptor {
  52. u32 source; /* the address of data to be read. */
  53. u32 source_pad;
  54. u32 destination; /* the address to write data */
  55. u32 destination_pad;
  56. u32 next; /* the next descriptor in the list. */
  57. u32 next_pad;
  58. u16 bytes_to_transfer; /* the number of bytes to transfer */
  59. u8 read_burst;
  60. u8 write_burst;
  61. u16 actual_bytes_transferred;/* bytes transferred by DMA */
  62. u8 descriptor_status;
  63. u8 descriptor_control;
  64. } __packed_1_;
  65. /* SG-DMA Control/Status Slave registers map */
  66. struct alt_sgdma_registers {
  67. u32 status;
  68. u32 status_pad[3];
  69. u32 control;
  70. u32 control_pad[3];
  71. u32 next_descriptor_pointer;
  72. u32 descriptor_pad[3];
  73. };
  74. /* TSE Stuff */
  75. #define ALTERA_TSE_CMD_TX_ENA_MSK BIT(0)
  76. #define ALTERA_TSE_CMD_RX_ENA_MSK BIT(1)
  77. #define ALTERA_TSE_CMD_ETH_SPEED_MSK BIT(3)
  78. #define ALTERA_TSE_CMD_HD_ENA_MSK BIT(10)
  79. #define ALTERA_TSE_CMD_SW_RESET_MSK BIT(13)
  80. #define ALTERA_TSE_CMD_ENA_10_MSK BIT(25)
  81. #define ALT_TSE_SW_RESET_TIMEOUT (3 * CONFIG_SYS_HZ)
  82. #define ALT_TSE_SGDMA_BUSY_TIMEOUT (3 * CONFIG_SYS_HZ)
  83. /* MAC register Space */
  84. struct alt_tse_mac {
  85. u32 megacore_revision;
  86. u32 scratch_pad;
  87. u32 command_config;
  88. u32 mac_addr_0;
  89. u32 mac_addr_1;
  90. u32 max_frame_length;
  91. u32 pause_quanta;
  92. u32 rx_sel_empty_threshold;
  93. u32 rx_sel_full_threshold;
  94. u32 tx_sel_empty_threshold;
  95. u32 tx_sel_full_threshold;
  96. u32 rx_almost_empty_threshold;
  97. u32 rx_almost_full_threshold;
  98. u32 tx_almost_empty_threshold;
  99. u32 tx_almost_full_threshold;
  100. u32 mdio_phy0_addr;
  101. u32 mdio_phy1_addr;
  102. u32 reserved1[0x29];
  103. /*FIFO control register. */
  104. u32 tx_cmd_stat;
  105. u32 rx_cmd_stat;
  106. u32 reserved2[0x44];
  107. /*Registers 0 to 31 within PHY device 0/1 */
  108. u32 mdio_phy0[0x20];
  109. u32 mdio_phy1[0x20];
  110. /*4 Supplemental MAC Addresses */
  111. u32 supp_mac_addr_0_0;
  112. u32 supp_mac_addr_0_1;
  113. u32 supp_mac_addr_1_0;
  114. u32 supp_mac_addr_1_1;
  115. u32 supp_mac_addr_2_0;
  116. u32 supp_mac_addr_2_1;
  117. u32 supp_mac_addr_3_0;
  118. u32 supp_mac_addr_3_1;
  119. u32 reserved3[0x38];
  120. };
  121. struct tse_ops {
  122. int (*send)(struct udevice *dev, void *packet, int length);
  123. int (*recv)(struct udevice *dev, int flags, uchar **packetp);
  124. int (*free_pkt)(struct udevice *dev, uchar *packet, int length);
  125. void (*stop)(struct udevice *dev);
  126. };
  127. struct altera_tse_priv {
  128. struct alt_tse_mac *mac_dev;
  129. void *sgdma_rx;
  130. void *sgdma_tx;
  131. unsigned int rx_fifo_depth;
  132. unsigned int tx_fifo_depth;
  133. void *rx_desc;
  134. void *tx_desc;
  135. unsigned char *rx_buf;
  136. unsigned int phyaddr;
  137. unsigned int interface;
  138. struct phy_device *phydev;
  139. struct mii_dev *bus;
  140. const struct tse_ops *ops;
  141. int dma_type;
  142. };
  143. #endif /* _ALTERA_TSE_H_ */